@bitpay-labs/bitcore-client 11.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +131 -0
  2. package/bin/multi-sig/wallet-derive-address +149 -0
  3. package/bin/wallet +31 -0
  4. package/bin/wallet-balance +62 -0
  5. package/bin/wallet-balance-all +77 -0
  6. package/bin/wallet-broadcast +35 -0
  7. package/bin/wallet-bump-tx +65 -0
  8. package/bin/wallet-check +62 -0
  9. package/bin/wallet-create +46 -0
  10. package/bin/wallet-decrypt +31 -0
  11. package/bin/wallet-delete +21 -0
  12. package/bin/wallet-derive +70 -0
  13. package/bin/wallet-flags +84 -0
  14. package/bin/wallet-import +80 -0
  15. package/bin/wallet-list +31 -0
  16. package/bin/wallet-paypro +175 -0
  17. package/bin/wallet-register +29 -0
  18. package/bin/wallet-send +146 -0
  19. package/bin/wallet-sign +64 -0
  20. package/bin/wallet-sign-message +55 -0
  21. package/bin/wallet-storage +79 -0
  22. package/bin/wallet-token +73 -0
  23. package/bin/wallet-token-rm +33 -0
  24. package/bin/wallet-tx +106 -0
  25. package/bin/wallet-tx-list +92 -0
  26. package/bin/wallet-utxos +28 -0
  27. package/package.json +71 -0
  28. package/src/client.ts +271 -0
  29. package/src/encryption.ts +139 -0
  30. package/src/index.ts +21 -0
  31. package/src/storage/level.ts +171 -0
  32. package/src/storage/mongo.ts +187 -0
  33. package/src/storage/textFile.ts +250 -0
  34. package/src/storage.ts +192 -0
  35. package/src/stream-util.ts +80 -0
  36. package/src/types/index.d.ts +2 -0
  37. package/src/types/storage.d.ts +1 -0
  38. package/src/types/wallet.d.ts +36 -0
  39. package/src/utils.ts +35 -0
  40. package/src/wallet.ts +983 -0
  41. package/test/unit/wallet.test.ts +552 -0
  42. package/ts_build/src/client.d.ts +77 -0
  43. package/ts_build/src/client.d.ts.map +1 -0
  44. package/ts_build/src/client.js +280 -0
  45. package/ts_build/src/client.js.map +1 -0
  46. package/ts_build/src/encryption.d.ts +27 -0
  47. package/ts_build/src/encryption.d.ts.map +1 -0
  48. package/ts_build/src/encryption.js +130 -0
  49. package/ts_build/src/encryption.js.map +1 -0
  50. package/ts_build/src/index.d.ts +11 -0
  51. package/ts_build/src/index.d.ts.map +1 -0
  52. package/ts_build/src/index.js +55 -0
  53. package/ts_build/src/index.js.map +1 -0
  54. package/ts_build/src/storage/level.d.ts +48 -0
  55. package/ts_build/src/storage/level.d.ts.map +1 -0
  56. package/ts_build/src/storage/level.js +194 -0
  57. package/ts_build/src/storage/level.js.map +1 -0
  58. package/ts_build/src/storage/mongo.d.ts +62 -0
  59. package/ts_build/src/storage/mongo.d.ts.map +1 -0
  60. package/ts_build/src/storage/mongo.js +173 -0
  61. package/ts_build/src/storage/mongo.js.map +1 -0
  62. package/ts_build/src/storage/textFile.d.ts +53 -0
  63. package/ts_build/src/storage/textFile.d.ts.map +1 -0
  64. package/ts_build/src/storage/textFile.js +268 -0
  65. package/ts_build/src/storage/textFile.js.map +1 -0
  66. package/ts_build/src/storage.d.ts +63 -0
  67. package/ts_build/src/storage.d.ts.map +1 -0
  68. package/ts_build/src/storage.js +172 -0
  69. package/ts_build/src/storage.js.map +1 -0
  70. package/ts_build/src/stream-util.d.ts +15 -0
  71. package/ts_build/src/stream-util.d.ts.map +1 -0
  72. package/ts_build/src/stream-util.js +81 -0
  73. package/ts_build/src/stream-util.js.map +1 -0
  74. package/ts_build/src/utils.d.ts +8 -0
  75. package/ts_build/src/utils.d.ts.map +1 -0
  76. package/ts_build/src/utils.js +37 -0
  77. package/ts_build/src/utils.js.map +1 -0
  78. package/ts_build/src/wallet.d.ts +229 -0
  79. package/ts_build/src/wallet.d.ts.map +1 -0
  80. package/ts_build/src/wallet.js +806 -0
  81. package/ts_build/src/wallet.js.map +1 -0
  82. package/ts_build/test/unit/wallet.test.d.ts +2 -0
  83. package/ts_build/test/unit/wallet.test.d.ts.map +1 -0
  84. package/ts_build/test/unit/wallet.test.js +533 -0
  85. package/ts_build/test/unit/wallet.test.js.map +1 -0
  86. package/tsconfig.json +40 -0
  87. package/tsconfig.prod.json +6 -0
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # Bitcore Client
2
+
3
+ **A helper to create a wallet using the bitcore-v8 infrastructure.**
4
+
5
+ ## Purpose
6
+
7
+ This repo should allow you to create a wallet using the bitcore-v8 infrastructure.
8
+
9
+ Currently we have the following features
10
+
11
+ - Wallet Creation
12
+ - Importing Addresses to the Wallet
13
+ - View Only
14
+ - Send Enabled by including the privKey
15
+ - Instant balance checking
16
+ - Transaction Creation
17
+ - Transaction Signing
18
+ - Transaction Broadcasting
19
+ - Multi-Sig address derive/importing
20
+
21
+ ## Commands
22
+
23
+ ### Wallet Create
24
+
25
+ No baseUrl flag will automatically create a wallet that points to https://api.bitcore.io/api.
26
+
27
+ ```sh
28
+ ./wallet-create --name TestWalletBTC --chain BTC --network mainnet
29
+ ```
30
+
31
+ To create a wallet to point to local bitcore-node.
32
+
33
+ ```sh
34
+ ./wallet-create --name myregtestwallet --chain BCH --network regtest --baseUrl http://localhost:3000/api
35
+ ```
36
+
37
+ ### Register an Existing Wallet
38
+
39
+ Register an existing wallet to point to custom Bitcore API url.
40
+
41
+ ```sh
42
+ ./wallet-register --name myregtestwallet --baseUrl https://api.bitcore.io/api
43
+ ```
44
+
45
+ Or a local Bitcore-node
46
+
47
+ ```sh
48
+ ./wallet-register --name myregtestwallet --baseUrl http://localhost:3000/api
49
+ ```
50
+
51
+ ### Wallet Address Import
52
+
53
+ You can import a jsonl file. privKey and pubKey are optional.
54
+ If you provide privKey, pubKey must be provided as well.
55
+
56
+ ```sh
57
+ //~/Desktop/export.jsonl
58
+ {"address": "mXy1234", privKey: "xxxxxxx", pubKey: "yyyyyyyy"}
59
+ {"address": "mXy1234", privKey: "xxxxxxx", pubKey: "yyyyyyyy"}
60
+ {"address": "mXy1234", privKey: "xxxxxxx", pubKey: "yyyyyyyy"}
61
+ ```
62
+
63
+ ```sh
64
+ ./wallet-import --name TestWalletBTC --file ~/Desktop/export.jsonl
65
+ ```
66
+
67
+ You can also import an address in json format in the command line.
68
+
69
+ ```sh
70
+ ./wallet-import --name myregtestwallet --parse '[{"address":"mXy1234"}]'
71
+ ```
72
+
73
+ ### Balance Checking
74
+
75
+ ```sh
76
+ ./wallet-balance --name TestWalletBTC
77
+ ```
78
+
79
+ ### Balance Checking at Specific Date or Time
80
+
81
+ ```sh
82
+ ./wallet-balance --name TestWalletBTC --time 01-15-2019
83
+ ```
84
+
85
+ Valid types of time (no slash marks allowed):
86
+
87
+ ```sh
88
+ 1-14-2019
89
+ "Wed Jan 16 2019 13:34:20 GMT-0500 (Eastern Standard Time)"
90
+ "2019-01-16T18:47:33.396Z"
91
+ ```
92
+
93
+ ### Wallet UTXOS
94
+
95
+ ```sh
96
+ ./bin/wallet-utxos --name TestWalletBTC
97
+ ```
98
+
99
+ ### Transaction Creation
100
+
101
+ ```sh
102
+ ./bin/wallet-tx --addresses '[{"address": "moVf5Rf1r4Dn3URQHumEzvq3vtrFbaRvNr", "satoshis": 2500000000}]' --fee 100 --utxos '[{"txid":"28321f501ce47db1fd40d9ad461624bf9fe6cb581ac0177d17304ff128b86d61","vout":0,"address":"mhwfzHhBdpUKLTzGkUEUpJWa3ipTYZHjF8","script":"21033a3c1aa3fb35e07fe7ff44423c8d378c2d4610ffac8b08c4e6747d7573566937ac","value":5000000000}]' --change "mz21R16FYXfA6G4EJdCrTsduvX9BHHecvv" --name TestWalletBTC --amount 2500000000
103
+ ```
104
+
105
+ ### Transaction Signing
106
+
107
+ ```sh
108
+ ./bin/wallet-sign --name TestWalletBTC --tx 0100000001616db828f14f30177d17c01a58cbe69fbf241646add940fdb17de41c501f32280000000000ffffffff0200f90295000000001976a914578237b9848cc709ced0e098417e0494415add1488ac9cf80295000000001976a914caf0ee682de3daa9b3640da1f6d47cc04ce2c99e88ac00000000
109
+ ```
110
+
111
+ ### Transaction Broadcast
112
+
113
+ ```sh
114
+ ./bin/wallet-broadcast --name TestWalletBTC --tx 0100000001616db828f14f30177d17c01a58cbe69fbf241646add940fdb17de41c501f32280000000048473044022052cf595274c422c37d140989c8cc31c95b39d326b5eac8d4feb8bcceebdebc3f02205635c798c24ae1d44d0871e6938dbfd76293e695131d890838654816f28b942401ffffffff0200f90295000000001976a914578237b9848cc709ced0e098417e0494415add1488ac9cf80295000000001976a914caf0ee682de3daa9b3640da1f6d47cc04ce2c99e88ac00000000
115
+ ```
116
+
117
+ ### Paypro Payment
118
+
119
+ ```sh
120
+ ./bin/wallet-paypro --name TestWalletBTC --payProUri 'https://bitpay.com/i/Dd8q13AnnVyYM7pcMBHfv'
121
+ ```
122
+
123
+ ## Contributing
124
+
125
+ See [CONTRIBUTING.md](https://github.com/bitpay/bitcore/blob/master/CONTRIBUTING.md) on the main bitcore repo for information about how to contribute.
126
+
127
+ ## License
128
+
129
+ Code released under [the MIT license](https://github.com/bitpay/bitcore/blob/master/LICENSE).
130
+
131
+ Copyright 2013-2019 BitPay, Inc. Bitcore is a trademark maintained by BitPay, Inc.
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const CWC = require('@bitpay-labs/crypto-wallet-core');
5
+ const program = require('commander');
6
+ const { Wallet } = require('../../ts_build/src/wallet');
7
+ const promptly = require('promptly');
8
+ const bitcoreLibs = {
9
+ BTC: CWC.BitcoreLib,
10
+ DOGE: CWC.BitcoreLibDoge,
11
+ LTC: CWC.BitcoreLibLtc,
12
+ BCH: CWC.BitcoreLibCash
13
+ };
14
+
15
+ program
16
+ .version(require('../../package.json').version)
17
+ .requiredOption('--path <path>', 'REQUIRED - Filepath where wallet is stored')
18
+ .requiredOption('--m <m>', 'REQUIRED - Number of signers required')
19
+ .requiredOption('--currency <currency>', 'REQUIRED - currency. [BTC, DOGE, LTC, BCH]')
20
+ .requiredOption('--depth <depth>', 'REQUIRED - Number of addresses to derive (will derive that many change addresses too)')
21
+ .requiredOption('--network <network>', 'REQUIRED - Network to derive for')
22
+ .option('--input <input>', 'optional - A json string to parse in the form {"xpubkey": "mXy1234"}')
23
+ .option('--file <file>', 'optional - A jsonl file with {"xpubkey": "mXy1234"} in it')
24
+ .option('--prompt', 'optional - Ask for the xpubkeys to derive from')
25
+ .option('--exportToFile <file>', 'optional flag - Export addresses')
26
+ .option('--importFromFile <file>', 'optional flag - Import exported addresses')
27
+ .option('--bech32', 'optional - Use this flag if you need bech32 addresses')
28
+ .parse(process.argv);
29
+
30
+ const getFileKeys = file => {
31
+ let contents = fs.readFileSync(file).toString();
32
+ let fileKeys = contents
33
+ .split('\n')
34
+ .filter(line => line !== '')
35
+ .map(line => JSON.parse(line));
36
+ return fileKeys;
37
+ };
38
+
39
+ const parseKeys = keys => {
40
+ let parsed = JSON.parse(keys);
41
+ if (typeof parsed === 'object') {
42
+ return [parsed];
43
+ } else {
44
+ return parsed;
45
+ }
46
+ };
47
+
48
+ function getAddress(publicKeyRing, addressIndex, isChange, m, network, currency) {
49
+ const publicKeys = publicKeyRing.map(function(key) {
50
+ const xpub = new bitcoreLibs[currency].HDPublicKey(key.xpubkey);
51
+ const changeNum = isChange ? 1 : 0;
52
+ let path = key.path ? key.path : `m/${changeNum}/${addressIndex}`;
53
+ if (key.path) {
54
+ let split = path.split('/');
55
+ split[split.length -1] = Number(split[split.length - 1]) + addressIndex;
56
+ path = split.join('/');
57
+ }
58
+ if (isChange && key.changePath) {
59
+ path = key.changePath
60
+ let split = path.split('/');
61
+ split[split.length -1] = Number(split[split.length - 1]) + addressIndex;
62
+ path = split.join('/');
63
+ }
64
+ return xpub.derive(path).publicKey;
65
+ });
66
+ let nestedWitness;
67
+ let type;
68
+ if (program.opts().bech32) {
69
+ nestedWitness = false;
70
+ type = 'witnessscripthash';
71
+ }
72
+ return bitcoreLibs[currency].Address.createMultisig(publicKeys, m, network, nestedWitness, type);
73
+ }
74
+
75
+ function getAllAddresses(publicKeyRing, numberOfAddresses, isChange, m, network, currency) {
76
+ let addresses = [];
77
+ for (let i = 0; i < numberOfAddresses; i++) {
78
+ const address = getAddress(publicKeyRing, i, isChange, m, network, currency);
79
+ addresses.push({ address: address.toString() });
80
+ console.log('address', address.toString(), i);
81
+ }
82
+ return addresses;
83
+ }
84
+
85
+ async function readFromPrompt() {
86
+ let counter = 1;
87
+ let xpubkey = await promptly.prompt(`Enter xpubkey ${counter} `);
88
+ let promptResults = [];
89
+ while (xpubkey.trim() != '') {
90
+ promptResults.push(xpubkey);
91
+ counter++;
92
+ xpubkey = await promptly.prompt(`Enter xpubkey ${counter} `, { default: '' });
93
+ }
94
+ return promptResults;
95
+ }
96
+
97
+ async function importAddressesToWallet(path, addresses) {
98
+ const password = await promptly.password('Wallet Password:');
99
+ if (!password) {
100
+ throw new Error('No password provided. Keys can\'t be imported without unlocking the wallet');
101
+ }
102
+ wallet = await Wallet.loadWallet({ path });
103
+ wallet = await wallet.unlock(password);
104
+ await wallet.importKeys({ keys: addresses });
105
+ console.log(`${addresses.length} Adresses Imported`);
106
+ }
107
+
108
+ let wallet;
109
+
110
+ const main = async () => {
111
+ const { file, input, prompt, importFromFile, m, network, exportToFile, depth, currency } = program.opts();
112
+ if (!currency || !['BTC', 'DOGE', 'LTC', 'BCH'].includes(currency)) {
113
+ throw new Error('Invalid currency. Currency must be BTC, DOGE, LTC, or BCH');
114
+ }
115
+ let keyInput = [];
116
+ try {
117
+ if (file) {
118
+ keyInput = getFileKeys(file);
119
+ } else if (input) {
120
+ keyInput = parseKeys(input);
121
+ } else if (prompt) {
122
+ keyInput = await readFromPrompt();
123
+ }
124
+ const mOfN = Number(m);
125
+ let results = getAllAddresses(keyInput, depth, false, mOfN, network, currency);
126
+ let changeResult = getAllAddresses(keyInput, depth, true, mOfN, network, currency);
127
+ const allAddresses = [].concat(results, changeResult);
128
+ if (keyInput.length < mOfN) {
129
+ throw new Error(`You must enter at least ${m} xpubkeys`);
130
+ }
131
+
132
+ if (exportToFile) {
133
+ allAddresses.forEach(function(result) {
134
+ fs.appendFileSync(exportToFile, `${JSON.stringify(result)}\n`, 'utf8');
135
+ });
136
+ console.log(`Exported Addresses to ${exportToFile}`);
137
+ }
138
+
139
+ if (importFromFile) {
140
+ await importAddressesToWallet(importAddresses, allAddresses);
141
+ }
142
+ } catch (e) {
143
+ console.error(e);
144
+ }
145
+ };
146
+
147
+ main()
148
+ .catch(console.error)
149
+ .finally(() => wallet?.storage?.close());
package/bin/wallet ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ const program = require('commander');
4
+
5
+ program
6
+ .version(require('../package.json').version)
7
+ .description('CLI wallet utility for Bitcore-node')
8
+ .command('balance', 'check wallet balance').alias('b')
9
+ .command('broadcast', 'broadcast transaction')
10
+ .command('bump-tx', 'increase transaction fee')
11
+ .command('check', 'check if wallet is registered and print last address').alias('h')
12
+ .command('create', 'create a wallet').alias('c')
13
+ .command('derive', 'derive an address').alias('d')
14
+ .command('flags', 'check or set wallet flags (XRP only)')
15
+ .command('import', 'import addresses/keys').alias('i')
16
+ .command('list', 'list wallets').alias('l')
17
+ .command('paypro', 'pay using payment protocol').alias('p')
18
+ .command('register', 'register a wallet with bitcore-node').alias('r')
19
+ .command('send', 'simple send from wallet to an address').alias('s')
20
+ .command('sign', 'sign a transaction')
21
+ .command('sign-message', 'sign a message with an address')
22
+ .command('storage', 'storage util for wallets')
23
+ .command('token', 'add an ERC20 token to an EVM wallet')
24
+ .command('token-rm', 'remove an ERC20 token from an EVM wallet')
25
+ .command('tx', 'create transaction').alias('t')
26
+ .command('tx-list', 'list wallet transactions').alias('txns')
27
+ .command('utxos', 'get wallet utxos').alias('u')
28
+ .parse(process.argv);
29
+
30
+
31
+
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+
3
+ const program = require('commander');
4
+ const { Wallet } = require('../ts_build/src/wallet');
5
+ const { utils } = require('../ts_build/src/utils');
6
+
7
+ try {
8
+ program
9
+ .version(require('../package.json').version)
10
+ .requiredOption('--name <name>', 'REQUIRED - Wallet name')
11
+ .option('--token <tokenName>', 'Get balance of an ERC20 token using token name')
12
+ .option('--time <time>', 'Get balance at specific time')
13
+ .option('--account <index>', 'EVM Account index to use (default 0). `all` for all accounts')
14
+ .option('--normalize', 'Display the balance in the smallest denomination (e.g. sats, wei, etc.)')
15
+ .option('--path <path>', 'Custom wallet storage path')
16
+ .option('--storageType <storageType>', 'name of the database to use (default level)')
17
+ .parse(process.argv);
18
+ } catch (e) {
19
+ console.log(e.message);
20
+ return program.help();
21
+ }
22
+
23
+ let wallet;
24
+
25
+ async function main() {
26
+ const { name, path, time, storageType, token: tokenName, account = 0, normalize } = program.opts();
27
+ wallet = await Wallet.loadWallet({ name, path, storageType });
28
+ const tokenObj = wallet.getTokenObj({ tokenName }); // null if no tokenName provided
29
+ const currencyObj = await utils.getCurrencyObj(wallet.chain, tokenObj?.address, !wallet.isMainnet());
30
+ const currency = currencyObj?.displayCode || tokenName || wallet.chain;
31
+ const decimals = Number(tokenObj?.decimals || currencyObj?.decimals || 0);
32
+ let accountAddress;
33
+ if (!wallet.isUtxoChain() && account !== 'all') {
34
+ accountAddress = await wallet.deriveAddress(account);
35
+ }
36
+ const balance = await wallet.getBalance({ time, tokenName, address: accountAddress, hex: true });
37
+ const formatBal = (bal) => {
38
+ if (bal == 0) { return '0'; }
39
+ const balString = BigInt(bal).toString(10).padStart(decimals + 1, '0');
40
+ return balString.slice(0, -decimals) + '.' + balString.slice(-decimals);
41
+ };
42
+ const metaData = {
43
+ ...balance,
44
+ balance: normalize ? BigInt(balance.balance) : formatBal(balance.balance),
45
+ unconfirmed: normalize ? BigInt(balance.unconfirmed) : formatBal(balance.unconfirmed),
46
+ confirmed: normalize ? BigInt(balance.confirmed) : formatBal(balance.confirmed),
47
+ currency,
48
+ chain: wallet.chain,
49
+ network: wallet.network,
50
+ };
51
+ if (accountAddress) {
52
+ metaData.account = `#${account} - ${accountAddress}`;
53
+ } else if (account === 'all') {
54
+ metaData.account = '(All accounts)';
55
+ }
56
+ return metaData;
57
+ }
58
+
59
+ main()
60
+ .then(res => console.log(res))
61
+ .catch(err => console.error(err))
62
+ .finally(() => wallet?.storage?.close());
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const program = require('commander');
5
+ const { Transform } = require('stream');
6
+ const { Storage } = require('../ts_build/src/storage');
7
+ const { Wallet } = require('../ts_build/src/wallet');
8
+
9
+ program
10
+ .version(require('../package.json').version)
11
+ .option('--chain <chain>', 'optional - Chain to get balances from')
12
+ .option('--network <network>', 'optional - Network to get balances from')
13
+ .option('--name <name>', 'optregex matching wallet name')
14
+ .option('--time <time>', 'optional - Get balance at specific time')
15
+ .option('--storageType <storageType>', 'optional - the name of the database (default Level)')
16
+ .option('--path <path>', 'optional - Where wallets are stored')
17
+ .parse(process.argv);
18
+
19
+ const { path, chain, network, time, name: regex, storageType = 'Level' } = program.opts();
20
+ const regExp = new RegExp(regex);
21
+
22
+ const parser = new Transform({
23
+ writableObjectMode: false,
24
+ readableObjectMode: true,
25
+ transform(chunk, encoding, callback) {
26
+ try {
27
+ const wallet = JSON.parse(chunk.toString());
28
+ callback(null, wallet);
29
+ } catch (e) {
30
+ callback(e);
31
+ }
32
+ }
33
+ });
34
+
35
+ const filterStream = new Transform({
36
+ objectMode: true,
37
+ transform(wallet, encoding, callback) {
38
+ const { name, chain: walletChain, network: walletNetwork } = wallet;
39
+ if (chain && walletChain !== chain) {
40
+ return callback();
41
+ }
42
+ if (network && walletNetwork !== network) {
43
+ return callback();
44
+ }
45
+ if (regExp && !regExp.test(name)) {
46
+ return callback();
47
+ }
48
+ return callback(null, { name, chain: walletChain, network: walletNetwork });
49
+ }
50
+ });
51
+
52
+ const getBalance = new Transform({
53
+ writableObjectMode: true,
54
+ readableObjectMode: false,
55
+ transform (wallet, encoding, callback) {
56
+ const { name, chain, network, storageType } = wallet;
57
+ Wallet.loadWallet({ name, path, storageType })
58
+ .then(wallet => wallet.getBalance({ time }))
59
+ .then(balance => {
60
+ const { confirmed } = balance;
61
+ callback(null, `${name}: ${confirmed / 1e8} ${chain} (${network})\n`);
62
+ })
63
+ .catch(err => callback(err));
64
+ }
65
+ });
66
+
67
+ const storage = new Storage({createIfMissing: false, errorIfExists: false, path, storageType});
68
+ storage.listWallets()
69
+ .then(stream => {
70
+ stream
71
+ .pipe(parser)
72
+ .on('error', err => console.log(err))
73
+ .pipe(filterStream)
74
+ .pipe(getBalance)
75
+ .on('error', err => console.log(err))
76
+ .pipe(process.stdout);
77
+ });
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+
3
+ const program = require('commander');
4
+ const { Wallet } = require('../ts_build/src/wallet');
5
+
6
+ program
7
+ .version(require('../package.json').version)
8
+ .requiredOption('--name <name>', 'REQUIRED - Wallet name')
9
+ .requiredOption('--tx <tx>', 'REQUIRED - Signed transaction to broadcast')
10
+ .option('--storageType <storageType>', 'optional - name of the database to use (default Level)')
11
+ .option('--path <path>', 'optional - Custom wallet storage path')
12
+ .parse(process.argv);
13
+
14
+ let wallet;
15
+
16
+ const main = async () => {
17
+ const { tx, name, path, storageType = 'Level' } = program.opts();
18
+ try {
19
+ wallet = await Wallet.loadWallet({ name, path, storageType });
20
+ const transaction = await wallet.broadcast({ tx });
21
+
22
+ console.log('Transaction broadcasted');
23
+ console.log(
24
+ JSON.stringify({
25
+ txid: transaction.txid
26
+ })
27
+ );
28
+ } catch (e) {
29
+ console.error(e);
30
+ }
31
+ };
32
+
33
+ main()
34
+ .catch(console.error)
35
+ .finally(() => wallet?.storage?.close());
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const program = require('commander');
6
+ const { Wallet } = require('../ts_build/src/wallet');
7
+ const promptly = require('promptly');
8
+
9
+ program
10
+ .version(require('../package.json').version)
11
+ .description('Bump the fee of a transaction. If it\'s a UTXO chain, it will deduct from the change output.')
12
+ .requiredOption('--name <name>', 'REQUIRED - Wallet Name')
13
+ .option('-t, --txid <txid>', 'Transaction id (either this or --raw are required)')
14
+ .option('-r, --raw <hex>', 'Raw transaction (either this or --txid are required)')
15
+ .option('-c, --change <index>', 'Specify the change output index to deduct the new fee from (REQUIRED for UTXO chains)')
16
+ .option('-f, --feeRate <rate>', 'optional - Rate in sats/byte or Gwei')
17
+ .option('-T, --feeTarget <nBlocks>', 'optional - Number of blocks to confirm in (defaults to 2)')
18
+ .option('-P, --feePriority <rate>', 'optional - Priority fee for EVM type 2 txs in Gwei')
19
+ .option('-q, --quiet', 'optional - Do not prompt for confirmation or show raw tx data')
20
+ .option('--noRbf', 'optional - Disable replace-by-fee')
21
+ .option('--isSweep', 'optional - Treat the transaction as a sweep/max send which ensures all UTXOs are used (defaults to true if there is only one output)')
22
+ .option('--storageType <storageType>', 'optional - Name of the database to use (default Level)')
23
+ .option('--path <path>', 'optional - Custom wallet storage path')
24
+ .parse(process.argv);
25
+
26
+ let wallet;
27
+
28
+ const main = async () => {
29
+ const { name, path, storageType = 'Level', raw: rawTx, change, feeRate, feeTarget = 2, feePriority, quiet, noRbf, isSweep } = program.opts();
30
+ let { txid } = program.opts();
31
+
32
+ if (!txid && !rawTx) {
33
+ return console.log('Must provide either --raw or --txid');
34
+ }
35
+
36
+ try {
37
+ wallet = await Wallet.loadWallet({ name, path, storageType });
38
+
39
+ if (change == null && wallet.isUtxoChain()) {
40
+ return console.log('Must provide --change for UTXO chains');
41
+ }
42
+
43
+ const { tx, params } = await wallet.bumpTxFee({ txid, rawTx, changeIdx: change, feeRate, feeTarget, feePriority, noRbf, isSweep });
44
+ !quiet && console.log('UnsignedRawTx: ', tx);
45
+ const passphrase = await promptly.password('Wallet Password:');
46
+ wallet = await wallet.unlock(passphrase);
47
+ const signedTx = await wallet.signTx({ tx, passphrase, utxos: params.utxos });
48
+ if (!quiet) {
49
+ console.log('SignedRawTx: ', signedTx);
50
+ const confirmed = await promptly.confirm('Broadcast? (y/n)');
51
+ if (!confirmed) {
52
+ return;
53
+ }
54
+ }
55
+ const transaction = await wallet.broadcast({ tx: signedTx });
56
+ console.log('Txid: ', transaction.txid);
57
+ console.log('Transaction broadcasted');
58
+ } catch (e) {
59
+ console.error(e);
60
+ }
61
+ };
62
+
63
+ main()
64
+ .catch(console.error)
65
+ .finally(() => wallet?.storage?.close());
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+
3
+ const program = require('commander');
4
+ const { Wallet } = require('../ts_build/src/wallet');
5
+
6
+ program
7
+ .version(require('../package.json').version)
8
+ .requiredOption('--name <name>', 'REQUIRED - Wallet name')
9
+ .option('--index <index>', 'optional - index of an address to check in local storage (default: last address)')
10
+ .option('--storageType <storageType>', 'optional - name of the database to use (default Level)')
11
+ .option('--path <path>', 'optional - Custom wallet storage path')
12
+ .parse(process.argv);
13
+
14
+ let wallet;
15
+
16
+ const main = async () => {
17
+ const { name, path, index, storageType = 'Level' } = program.opts();
18
+ try {
19
+ wallet = await Wallet.loadWallet({ name, path, storageType });
20
+ await wallet.syncAddresses();
21
+ const registered = await wallet.checkWallet();
22
+ console.log(`Last server address: ${registered.lastAddress} (checksum: ${registered.sum})`);
23
+
24
+ if (!wallet.addressIndex) {
25
+ console.log('No local addresses. Derive an address with `wallet derive --name <name> --gap 1`');
26
+ return;
27
+ } else {
28
+ const address = wallet.deriveAddress(wallet.addressIndex - 1, false);
29
+ const addressObj = await wallet.getLocalAddress(address);
30
+ if (!addressObj) {
31
+ console.log('Local address not found at index ' + (wallet.addressIndex - 1));
32
+ console.log(`Run \`wallet derive --name <name> --startIdx ${wallet.addressIndex - 1}\` and try again.`);
33
+ } else {
34
+ console.log(`Last local address: ${address} (${addressObj?.path || `m/0/${wallet.addressIndex - 1}`})`);
35
+ }
36
+ }
37
+
38
+ if (index) {
39
+ console.log();
40
+ const address = wallet.deriveAddress(index, false);
41
+ const chgAddress = wallet.deriveAddress(index, true);
42
+ const addressObj = await wallet.getLocalAddress(address);
43
+ const chgAddressObj = await wallet.getLocalAddress(chgAddress);
44
+ const path = addressObj?.path || `m/0/${index}`;
45
+ if (!addressObj) {
46
+ console.log('Local address not found at index ' + index);
47
+ return;
48
+ }
49
+ console.log(`Address ${index}: ${address} (${path} - ${addressObj.pubKey})`)
50
+ if (chgAddressObj) {
51
+ const chgPath = chgAddressObj.path || `m/1/${index}`;
52
+ console.log(` - Change: ${chgAddress} (${chgPath} - ${chgAddressObj.pubKey})`);
53
+ }
54
+ }
55
+ } catch (e) {
56
+ console.error(e);
57
+ }
58
+ };
59
+
60
+ main()
61
+ .catch(console.error)
62
+ .finally(() => wallet?.storage?.close());
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const program = require('commander');
6
+ const { Wallet } = require('../ts_build/src/wallet');
7
+ const promptly = require('promptly');
8
+
9
+ program
10
+ .version(require('../package.json').version)
11
+ .requiredOption('--name <name>', 'REQUIRED - Wallet Name')
12
+ .requiredOption('--chain <chain>', 'REQUIRED - Chain (BTC/BCH/ETH, etc)')
13
+ .requiredOption('--network <network>', 'REQUIRED - Network (livenet/testnet/regtest, etc)')
14
+ .option('--addressType <type>', 'optional - Specify the address type (default: pubkeyhash)')
15
+ .option('--baseUrl <host>', 'optional - Specify custom Bitcore API URL')
16
+ .option('--phrase <phrase>', 'optional - Seed using existing backup phrase')
17
+ .option('--xpriv <xpriv>', 'optional - Create using an extended private key')
18
+ .option('--lite', 'optional - Create a read-only wallet')
19
+ .option('--storageType <storageType>', 'optional - name of the database to use (Mongo | Level | TextFile)')
20
+ .option('--path <path>', 'optional - Custom wallet storage path')
21
+ .parse(process.argv);
22
+
23
+ const main = async () => {
24
+ const { name, baseUrl, chain, network, path, phrase, xpriv, storageType = 'Level', lite, addressType } = program.opts();
25
+ try {
26
+ const password = await promptly.password('Wallet Password:');
27
+ await Wallet.create({
28
+ name,
29
+ baseUrl,
30
+ chain,
31
+ network,
32
+ path,
33
+ phrase,
34
+ xpriv,
35
+ password,
36
+ storageType,
37
+ lite,
38
+ addressType
39
+ });
40
+ console.log('Wallet created!');
41
+ } catch (e) {
42
+ console.error(e);
43
+ }
44
+ };
45
+
46
+ main();