|
| 1 | +/** |
| 2 | + * Create a multi-sig wallet at BitGo. |
| 3 | + * This makes use of the convenience function generateWallet |
| 4 | + * |
| 5 | + * This tool will help you see how to use the BitGo API to easily create a wallet. |
| 6 | + * In this form, it creates 2 keys on the host which runs this example. |
| 7 | + * It is HIGHLY RECOMMENDED that you GENERATE THE KEYS ON SEPARATE MACHINES for real money wallets! |
| 8 | + * |
| 9 | + * To perform more advanced features, such as encrypting keys yourself, please look at createWalletAdvanced.js |
| 10 | + * |
| 11 | + * Copyright 2022, BitGo, Inc. All Rights Reserved. |
| 12 | + */ |
| 13 | + |
| 14 | +/** |
| 15 | + * Add Low Fee webhook to a wallet. |
| 16 | + * |
| 17 | + * Copyright 2022 BitGo, Inc. All Rights Reserved. |
| 18 | + */ |
| 19 | + |
| 20 | +import { BitGoAPI } from '@bitgo/sdk-api'; |
| 21 | +import { Tbtc } from '@bitgo/sdk-coin-btc'; // Replace with your given coin (e.g. Ltc, Tltc) |
| 22 | +import { AbstractUtxoCoin, descriptor } from '@bitgo/abstract-utxo'; |
| 23 | +require('dotenv').config({ path: '../../.env' }); |
| 24 | + |
| 25 | +const bitgo = new BitGoAPI({ |
| 26 | + accessToken: process.env.TESTNET_ACCESS_TOKEN, |
| 27 | + env: 'test', // Change this to env: 'production' when you are ready for production |
| 28 | +}); |
| 29 | + |
| 30 | +// Set the coin name to match the blockchain and network |
| 31 | +// btc = bitcoin, tbtc = testnet bitcoin |
| 32 | +const coin = 'tbtc'; |
| 33 | +bitgo.register(coin, Tbtc.createInstance); |
| 34 | + |
| 35 | +// TODO: set a label for your new wallet here |
| 36 | +const label = 'Example Descriptor Wallet'; |
| 37 | + |
| 38 | +// TODO: set your passphrase for your new wallet here |
| 39 | +const passphrase = 'test_wallet_passphrase'; |
| 40 | + |
| 41 | +// TODO: set your enterprise ID for your new wallet here |
| 42 | +const enterprise = 'your_enterprise_id'; |
| 43 | + |
| 44 | +async function main() { |
| 45 | + console.log( |
| 46 | + // this wrapper creates three keys: userKey, backupKey, and bitgoKey |
| 47 | + // at the moment, this is a somewhat artificial requirement from wallet platform |
| 48 | + // in the future, we will allow for more flexible key generation |
| 49 | + await descriptor.createWallet.createDescriptorWalletWithWalletPassphrase( |
| 50 | + bitgo, |
| 51 | + bitgo.coin(coin) as AbstractUtxoCoin, |
| 52 | + { |
| 53 | + label, |
| 54 | + walletPassphrase: passphrase, |
| 55 | + enterprise, |
| 56 | + descriptorsFromKeys(userKey, cosigners) { |
| 57 | + // userKey is backed up at BitGo with the wallet passphrase |
| 58 | + // cosigners are backup key and BitGo key |
| 59 | + const xpubs = [userKey, ...cosigners].map((key) => key.neutered().toBase58()); |
| 60 | + |
| 61 | + return [ |
| 62 | + // here is a single-sig descriptor for the user key |
| 63 | + descriptor.createNamedDescriptorWithSignature('SingleSigWpkh', `wpkh(${xpubs[0]}/*)`, userKey), |
| 64 | + // here is a 2of3 multisig descriptor for the backup key and BitGo key |
| 65 | + descriptor.createNamedDescriptorWithSignature( |
| 66 | + 'MultiSigWsh', |
| 67 | + `wsh(multi(2,${xpubs.map((xpub) => `${xpub}/*`).join(',')})`, |
| 68 | + userKey |
| 69 | + ), |
| 70 | + // equivalent to the above, but returns two descriptors (external and internal) |
| 71 | + ...descriptor.createWallet.DefaultWsh2Of3(userKey, cosigners), |
| 72 | + ]; |
| 73 | + }, |
| 74 | + } |
| 75 | + ) |
| 76 | + ); |
| 77 | +} |
| 78 | + |
| 79 | +main().catch((e) => console.log(e)); |
0 commit comments