Skip to content

Instantly share code, notes, and snippets.

@gaurav21
Last active May 27, 2022 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaurav21/971364a8e4c2e64b048a4d361823d1eb to your computer and use it in GitHub Desktop.
Save gaurav21/971364a8e4c2e64b048a4d361823d1eb to your computer and use it in GitHub Desktop.
Solutions Architect - gaurav sharma
# 1. On BitGo’s TEST environment, using the credentials and information above (BitGo’s account), perform the following operations and send us the results:
# a) Check the wallet’s balance, and send us the value
# b) Create a new address on that wallet, and send us the new address
# c) Send us the label of the wallet.
##1.a : 73921693
##1.b : 2N14jHWc6dJCxPzpF5BUSC8yMD9PATmrkkS
##1.c : Solutions Engineering Candidate Technical Challenge Wallet - TBTC
#a. Using your own account, create a testnet Bitcoin wallet, with the label/name of “BitGo Solutions Engineering Challange Challenge - <YOUR NAME>”.
3.a
```
const BitGoJS = require('bitgo');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');
const coin = 'tbtc';
const basecoin = bitgo.coin(coin);
const accessToken = '5c3b789929ad4b7aa2ea69c6c9cecb0488561839e84db507d5db192b1e966a64';
//use the access token to create a new wallet
// TODO: set a label for your new wallet here
const label = 'BitGo Solutions Engineering Challange Challenge - Gaurav Sharma';
// TODO: set your passphrase for your new wallet here
const passphrase = 'guarav_test_wallet_passphrase';
// Create the wallet
Promise.coroutine(function *() {
bitgo.authenticateWithAccessToken({ accessToken });
// bitgo.authenticate({ username: "gauravaddress@yahoo.com", password: "x5D5hyfzfGmKkSp", otp: '0000000' });
const walletOptions = {
label,
passphrase,
};
const wallet = yield bitgo.coin(coin).wallets().generateWallet(walletOptions);
const walletInstance = wallet.wallet;
console.log(`Wallet ID: ${walletInstance.id()}`);
console.log(`Receive address: ${walletInstance.receiveAddress()}`);
console.log('BACK THIS UP: ');
console.log(`User keychain encrypted xPrv: ${wallet.userKeychain.encryptedPrv}`);
console.log(`Backup keychain xPrv: ${wallet.backupKeychain.prv}`);
})();
```
#3.b. Using the BitGo account and credentials provided in the introduction above, send a new transaction from BitGo’s existing wallet to your new wallet for the amount of 0.01 testnet bitcoin (TBTC).
3.b
```
/**
* Send a transaction from a multi-sig wallet at BitGo.
*
* Copyright 2022, BitGo, Inc. All Rights Reserved.
*/
const BitGoJS = require('bitgo');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');
const coin = 'tbtc';
const basecoin = bitgo.coin(coin);
// TODO: set your access token here
const accessToken = "35b7e8680f2e4813cb2f6c3df860394aab2249d33035125138bedffbec733b8e";
const walletId = "60e6246deeff35000686b29d123df1f7";
// TODO: set your passphrase here
const walletPassphrase = '6ood%7uck!';
Promise.coroutine(function *() {
bitgo.authenticateWithAccessToken({ accessToken: accessToken });
const walletInstance = yield basecoin.wallets().get({ id: walletId });
// wallet address created for the new account for gauravaddress@yahoo.com
const newReceiveAddress1 = "2N14jHWc6dJCxPzpF5BUSC8yMD9PATmrkkS";
const transaction = yield walletInstance.sendMany({
recipients: [
{
amount: "1000000",
address: newReceiveAddress1,
}
],
walletPassphrase: walletPassphrase,
});
const explanation = yield basecoin.explainTransaction({ txHex: transaction.tx });
console.log('Wallet ID:', walletInstance.id());
console.log('Current Receive Address:', walletInstance.receiveAddress());
console.log('New Transaction:', JSON.stringify(transaction, null, 4));
console.log('Transaction Explanation:', JSON.stringify(explanation, null, 4));
})();
```
#3.c Using your own account, get the transaction object for the received testnet bitcoin, and provide the transaction information to us, including:
#i. Your user and wallet ID
#ii. The transaction ID
#iii. The blockchain fee paid for the transaction
3.c
```
const BitGoJS = require('bitgo');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');
const coin = 'tbtc';
const basecoin = bitgo.coin(coin);
// TODO: set your access token here
const accessToken = '5c3b789929ad4b7aa2ea69c6c9cecb0488561839e84db507d5db192b1e966a64';
const walletId = '62904ebcfe3978000811863cfa8b2225';
Promise.coroutine(function *() {
bitgo.authenticateWithAccessToken({ accessToken: accessToken });
const walletInstance = yield basecoin.wallets().get({ id: walletId });
const transfers = yield walletInstance.transfers();
console.log('Wallet ID:', walletInstance.id());
console.log('Current Receive Address:', walletInstance.receiveAddress());
console.log('Wallet Transactions:', JSON.stringify(transfers, null, 4));
})();
```
##3.c.i : User id : 628f7f6c6e937a0007dd159e719a386c wallet id : 62904ebcfe3978000811863cfa8b2225
##3.c.ii : transaction ids : c505dd4530f19bbe9bda26c899b40ab46864e05a1b7ee1db4ed6a5a2ee9bdbb7,
##3.c.iii : Fee paid : 174 for all transactions
# 3.d Register a transfer webhook on the testnet bitcoin wallet, and use a common HTTP request bin URL as the destination. Send money from a testnet faucet to the wallet, and send us the HTTP request body JSON from the triggered webhook notification.
3.d
```
{
"event": {
"method": "POST",
"path": "/",
"query": {},
"client_ip": "34.218.55.207",
"url": "https://eo1nzm9ozv9grsj.m.pipedream.net/",
"headers": {
"host": "eo1nzm9ozv9grsj.m.pipedream.net",
"content-length": "217",
"traceparent": "00-5a67f952f05ce69dc10c0ad6478118ed-17892728e4da593e-01",
"uber-trace-id": "5a67f952f05ce69dc10c0ad6478118ed:17892728e4da593e:0:01",
"accept-encoding": "gzip, deflate",
"user-agent": "bitgo-webhook/1.0.0",
"content-type": "application/json"
},
"body": {
"hash": "a27c08072f5d65cd591f32ae4cc054b9e9b7ab7a84a2cb4282dd97f9629ebe3b",
"transfer": "62906d6e4a6ac400078bacb41c5cce69",
"coin": "tbtc",
"type": "transfer",
"state": "confirmed",
"wallet": "62904ebcfe3978000811863cfa8b2225"
}
},
"context": {
"id": "29jhX9n5QJPsRxZ3FBHd9hsnIae",
"ts": "2022-05-27T06:20:38.950Z",
"pipeline_id": null,
"workflow_id": "p_YyCrJ5y",
"deployment_id": "d_QAsV7W8",
"source_type": "COMPONENT",
"verified": false,
"hops": null,
"test": false,
"replay": false,
"owner_id": "u_ZZhQj5m",
"platform_version": "3.28.0",
"workflow_name": "RequestBin",
"resume": null,
"trace_id": "29jhX7SVE6P5L283WJLixB78XS2"
}
}
```
5: The wallet transfer leads to some amount used as gas fee
7.
# Bitgo and use of Keys for security
##
BitGo stores your private keys too, in an encrypted form which is protected by your password so they can't access the private keys.
Private keys are generated offline and are never exposed to an online network, reducing risk
When you login, the passpharse is used to load your wallet in your browser locally and it contains one set of your private keys.
When you make a transaction, it is made in your browser and signed in your browser using the private keys that were loaded. This transaction is then sent off to BitGo who also signs the transaction, after you use 2FA in our case it is 0000000 to authenticate the send. Then it is broadcast to the network.
The third set of private keys are ones that only you have. These are downoaded when the wallet is created. That set of keys also lets you create transactions without BitGo being involved.
BitGo’s Self-Managed Custody solution was build to allow clients the ability to ensure both their keys and back-up keys are generated, stored, and managed in country
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment