Skip to content

Commit

Permalink
Merge branch 'bccAddressType' of github.com:kajoseph/bitcore
Browse files Browse the repository at this point in the history
  • Loading branch information
kajoseph committed Oct 18, 2023
2 parents f9693cf + 575338e commit 67a2c03
Show file tree
Hide file tree
Showing 50 changed files with 38,009 additions and 41,201 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ jobs:
steps:
- run_test:
package: bitcore-p2p
bitcore-client:
executor: main
steps:
- run_test:
package: bitcore-client

workflows:
version: 2
Expand Down Expand Up @@ -201,3 +206,6 @@ workflows:
- bitcore-p2p:
requires:
- build
- bitcore-client:
requires:
- build
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"lerna": "2.9.1",
"version": "10.0.12",
"packages": [
"packages/*"
"packages/[^insight]*"
]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"ci:bitcore-p2p-doge": "./ci.sh 'npm run test:bitcore-p2p-doge'",
"test:bitcore-mnemonic": "cd ./packages/bitcore-mnemonic && npm run test",
"ci:bitcore-mnemonic": "./ci.sh 'npm run test:bitcore-mnemonic'",
"test:bitcore-client": "cd ./packages/bitcore-client && npm run test",
"ci:bitcore-client": "./ci.sh 'npm run test:bitcore-client'",
"lerna:ci:all": "npx lerna run test:ci --concurrency 1 --stream",
"lerna:ci:unit": "npx run test:ci:unit --concurrency 1 --stream",
"lerna:ci:integration": "npx run test:ci:integration --concurrency 1 --stream",
Expand Down
32 changes: 16 additions & 16 deletions packages/bitcore-client/bin/multi-sig/wallet-derive-address
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require('fs');
const CWC = require('crypto-wallet-core');
const program = require('commander');
const { Wallet } = require('../../ts_build/wallet');
const { Wallet } = require('../../ts_build/src/wallet');
const promptly = require('promptly');
const bitcoreLibs = {
BTC: CWC.BitcoreLib,
Expand All @@ -14,17 +14,17 @@ const bitcoreLibs = {

program
.version(require('../../package.json').version)
.option('--path <path>', 'REQUIRED - Filepath where wallet is stored')
.option('--m <m>', 'REQUIRED - Number of signers required')
.option('--currency <currency>', 'REQUIRED - currency. [BTC, DOGE, LTC, BCH]')
.option('--depth <depth>', 'REQUIRED - Number of addresses to derive (will derive that many change addresses too)')
.option('--network <network>', 'REQUIRED - Network to derive for')
.option('--input [input]', 'OPTIONAL - A json string to parse in the form {"xpubkey": "mXy1234"}')
.option('--file [file]', 'OPTIONAL - A jsonl file with {"xpubkey": "mXy1234"} in it')
.option('--prompt', 'OPTIONAL - Ask for the xpubkeys to derive from')
.option('--importToWallet [importToWallet]', 'OPTIONAL flag - import the derived addresses. Requires path')
.option('--exportToFile [export]', 'OPTIONAL flag - File path to save derived addresses to')
.option('--bech32', 'OPTIONAL - Use this flag if you need bech32 addresses')
.requiredOption('--path <path>', 'REQUIRED - Filepath where wallet is stored')
.requiredOption('--m <m>', 'REQUIRED - Number of signers required')
.requiredOption('--currency <currency>', 'REQUIRED - currency. [BTC, DOGE, LTC, BCH]')
.requiredOption('--depth <depth>', 'REQUIRED - Number of addresses to derive (will derive that many change addresses too)')
.requiredOption('--network <network>', 'REQUIRED - Network to derive for')
.option('--input <input>', 'optional - A json string to parse in the form {"xpubkey": "mXy1234"}')
.option('--file <file>', 'optional - A jsonl file with {"xpubkey": "mXy1234"} in it')
.option('--prompt', 'optional - Ask for the xpubkeys to derive from')
.option('--exportToFile <file>', 'optional flag - Export addresses')
.option('--importFromFile <file>', 'optional flag - Import exported addresses')
.option('--bech32', 'optional - Use this flag if you need bech32 addresses')
.parse(process.argv);

const getFileKeys = file => {
Expand Down Expand Up @@ -65,7 +65,7 @@ function getAddress(publicKeyRing, addressIndex, isChange, m, network, currency)
});
let nestedWitness;
let type;
if (program.bech32) {
if (program.opts().bech32) {
nestedWitness = false;
type = 'witnessscripthash';
}
Expand Down Expand Up @@ -106,7 +106,7 @@ async function importAddressesToWallet(path, addresses) {
}

const main = async () => {
const { path, file, input, prompt, importToWallet, m, network, exportToFile, depth, currency } = program;
const { file, input, prompt, importFromFile, m, network, exportToFile, depth, currency } = program.opts();
if (!currency || !['BTC', 'DOGE', 'LTC', 'BCH'].includes(currency)) {
throw new Error('Invalid currency. Currency must be BTC, DOGE, LTC, or BCH');
}
Expand Down Expand Up @@ -134,8 +134,8 @@ const main = async () => {
console.log(`Exported Addresses to ${exportToFile}`);
}

if (path && importToWallet) {
await importAddressesToWallet(path, allAddresses);
if (importFromFile) {
await importAddressesToWallet(importAddresses, allAddresses);
}
} catch (e) {
console.error(e);
Expand Down
16 changes: 8 additions & 8 deletions packages/bitcore-client/bin/wallet-balance
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/usr/bin/env node

const program = require('../ts_build/program');
const { Wallet } = require('../ts_build/wallet');
const program = require('commander');
const { Wallet } = require('../ts_build/src/wallet');

try {
program
.version(require('../package.json').version)
.option('--name <name>', 'REQUIRED - Wallet name')
.option('--time [time]', 'optional - Get balance at specific time')
.option('--path [path]', 'optional - Custom wallet storage path')
.option('--storageType [storageType]', 'optional - name of the database to use (default level)')
.option('--token [token]', 'optional - Get balance of an ERC20 token')
.requiredOption('--name <name>', 'REQUIRED - Wallet name')
.option('--time <time>', 'optional - Get balance at specific time')
.option('--path <path>', 'optional - Custom wallet storage path')
.option('--storageType <storageType>', 'optional - name of the database to use (default level)')
.option('--token <token>', 'optional - Get balance of an ERC20 token')
.parse(process.argv);
} catch (e) {
console.log(e.message);
return program.help();
}

async function main() {
const { name, path, time, storageType, token } = program;
const { name, path, time, storageType, token } = program.opts();
const wallet = await Wallet.loadWallet({ name, path, storageType });
const balance = await wallet.getBalance(time, token);
return Object.assign(balance, {
Expand Down
20 changes: 10 additions & 10 deletions packages/bitcore-client/bin/wallet-balance-all
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/usr/bin/env node
'use strict';

const program = require('commander');
const { Transform } = require('stream');
const { Storage } = require('../ts_build/storage');
const { Wallet } = require('../ts_build/wallet');
const program = require('../ts_build/program');
const { Storage } = require('../ts_build/src/storage');
const { Wallet } = require('../ts_build/src/wallet');

program
.version(require('../package.json').version)
.option('--path [path]', 'optional - Where wallets are stored')
.option('--chain [chain]', 'Chain to get balances from')
.option('--network [network]', 'Network to get balances from')
.option('--name [name]', 'regex matching wallet name')
.option('--time [time]', 'optional - Get balance at specific time')
.option('--storageType [storageType]', 'optional - the name of the database (default Level)')
.option('--chain <chain>', 'optional - Chain to get balances from')
.option('--network <network>', 'optional - Network to get balances from')
.option('--name <name>', 'optregex matching wallet name')
.option('--time <time>', 'optional - Get balance at specific time')
.option('--storageType <storageType>', 'optional - the name of the database (default Level)')
.option('--path <path>', 'optional - Where wallets are stored')
.parse(process.argv);

const { path, chain, network, time, name: regex, storageType } = program;
const { path, chain, network, time, name: regex, storageType = 'Level' } = program.opts();
const regExp = new RegExp(regex);

const parser = new Transform({
Expand Down
14 changes: 7 additions & 7 deletions packages/bitcore-client/bin/wallet-broadcast
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env node

const program = require('../ts_build/program');
const { Wallet } = require('../ts_build/wallet');
const program = require('commander');
const { Wallet } = require('../ts_build/src/wallet');

program
.version(require('../package.json').version)
.option('--name <name>', 'REQUIRED - Wallet name')
.option('--tx <tx>', 'REQUIRED - Signed transaction to broadcast')
.option('--path [path]', 'optional - Custom wallet storage path')
.option('--storageType [storageType]', 'optional - name of the database to use (default Level)')
.requiredOption('--name <name>', 'REQUIRED - Wallet name')
.requiredOption('--tx <tx>', 'REQUIRED - Signed transaction to broadcast')
.option('--storageType <storageType>', 'optional - name of the database to use (default Level)')
.option('--path <path>', 'optional - Custom wallet storage path')
.parse(process.argv);

const main = async () => {
const { tx, name, path, storageType } = program;
const { tx, name, path, storageType = 'Level' } = program.opts();
let wallet;
try {
wallet = await Wallet.loadWallet({ name, path, storageType });
Expand Down
25 changes: 14 additions & 11 deletions packages/bitcore-client/bin/wallet-bump-tx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

'use strict';

const program = require('../ts_build/program');
const { Wallet } = require('../ts_build/wallet');
const program = require('commander');
const { Wallet } = require('../ts_build/src/wallet');
const promptly = require('promptly');
const ethers = require('ethers');

program
.version(require('../package.json').version)
.option('--name <name>', 'REQUIRED - Wallet Name')
.option('--txid [txid]', 'Transaction id (either this or --rawtx are required)')
.option('--rawtx [rawtx]', 'Raw transaction (either this or --txid are required)')
.option('--gwei [gwei]', 'For use with EVM based chains (defaults to current market rate)')
.option('--path [path]', 'Custom wallet storage path')
.option('--storageType [storageType]', 'Name of the database to use (default Level)')
.requiredOption('--name <name>', 'REQUIRED - Wallet Name')
.option('--txid <txid>', 'Transaction id (either this or --rawtx are required)')
.option('--rawtx <rawtx>', 'Raw transaction (either this or --txid are required)')
.option('--gwei <gwei>', 'optional - For use with EVM based chains (defaults to current market rate)')
.option('--storageType <storageType>', 'optional - Name of the database to use (default Level)')
.option('--path <path>', 'optional - Custom wallet storage path')
.parse(process.argv);

const main = async () => {
const { name, path, storageType, txid, rawtx, gwei } = program;
const { name, path, storageType = 'Level', txid, rawtx, gwei } = program.opts();
let wallet;
const weiInGwei = 1000000000;

Expand Down Expand Up @@ -57,17 +57,20 @@ const main = async () => {
// converting gasLimit and value with toString avoids a bigNumber warning
const params = { nonce, gasLimit: gasLimit.toString(), gasPrice, data, chainId, recipients: [{ address: to, amount: value.toString() }] };

const noChange = ['ETH', 'MATIC'].includes(wallet.chain);
params.change = noChange ? null : wallet.deriveAddress(wallet.addressIndex, true);
const changeIdx = params.change ? wallet.addressIndex : null;
const tx = await wallet.newTx(params);
console.log('UnsignedRawTx: ', tx);
const passphrase = await promptly.password('Wallet Password:');
wallet = await wallet.unlock(passphrase);
const signedTx = await wallet.signTx({ tx, passphrase });
const signedTx = await wallet.signTx({ tx, passphrase, changeAddressIdx: changeIdx });
console.log('SignedRawTx: ', signedTx);
const confirmed = await promptly.confirm('Broadcast? (y/n)');
if (!confirmed) {
return;
}
const transaction = await wallet.broadcast({ tx: signedTx, ignoreNonce: true });
const transaction = await wallet.broadcast({ tx: signedTx });
console.log('Txid: ', transaction.txid);
console.log('Transaction broadcasted');
} catch (e) {
Expand Down
12 changes: 6 additions & 6 deletions packages/bitcore-client/bin/wallet-check
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env node

const program = require('../ts_build/program');
const { Wallet } = require('../ts_build/wallet');
const program = require('commander');
const { Wallet } = require('../ts_build/src/wallet');

program
.version(require('../package.json').version)
.option('--name <name>', 'REQUIRED - Wallet name')
.option('--path [path]', 'optional - Custom wallet storage path')
.option('--storageType [storageType]', 'optional - name of the database to use (default Level)')
.requiredOption('--name <name>', 'REQUIRED - Wallet name')
.option('--storageType <storageType>', 'optional - name of the database to use (default Level)')
.option('--path <path>', 'optional - Custom wallet storage path')
.parse(process.argv);

const main = async () => {
const { name, path, storageType } = program;
const { name, path, storageType = 'Level' } = program.opts();
try {
const wallet = await Wallet.loadWallet({ name, path, storageType });
await wallet.syncAddresses();
Expand Down
31 changes: 15 additions & 16 deletions packages/bitcore-client/bin/wallet-create
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@

'use strict';

const program = require('../ts_build/program');
const { Wallet } = require('../ts_build/wallet');
const program = require('commander');
const { Wallet } = require('../ts_build/src/wallet');
const promptly = require('promptly');

program
.version(require('../package.json').version)
.option('--name <name>', 'REQUIRED - Wallet Name')
.option('--chain <chain>', 'REQUIRED - Chain (BTC/BCH/ETH, etc)')
.option(
'--network <network>',
'REQUIRED - Network (livenet/testnet/regtest, etc)'
)
.option('--baseUrl [host]', 'optional - Specify custom Bitcore API URL')
.option('--path [path]', 'optional - Custom wallet storage path')
.option('--storageType [storageType]', 'optional - name of the database to use (Mongo | Level | TextFile)')
.option('--phrase [phrase]', 'optional - Seed using existing backup phrase')
.option('--xpriv [xpriv]', 'optional - Create using an extended private key')
.option('--lite [lite]', 'optional - Create a wallet lite')
.requiredOption('--name <name>', 'REQUIRED - Wallet Name')
.requiredOption('--chain <chain>', 'REQUIRED - Chain (BTC/BCH/ETH, etc)')
.requiredOption('--network <network>', 'REQUIRED - Network (livenet/testnet/regtest, etc)')
.option('--addressType <type>', 'optional - Specify the address type (default: pubkeyhash)')
.option('--baseUrl <host>', 'optional - Specify custom Bitcore API URL')
.option('--phrase <phrase>', 'optional - Seed using existing backup phrase')
.option('--xpriv <xpriv>', 'optional - Create using an extended private key')
.option('--lite', 'optional - Create a read-only wallet')
.option('--storageType <storageType>', 'optional - name of the database to use (Mongo | Level | TextFile)')
.option('--path <path>', 'optional - Custom wallet storage path')
.parse(process.argv);

const main = async () => {
const { name, baseUrl, chain, network, path, phrase, xpriv, storageType, lite } = program;
const { name, baseUrl, chain, network, path, phrase, xpriv, storageType = 'Level', lite, addressType } = program.opts();
try {
const password = await promptly.password('Wallet Password:');
await Wallet.create({
Expand All @@ -36,7 +34,8 @@ const main = async () => {
xpriv,
password,
storageType,
lite
lite,
addressType
});
console.log('Wallet created!');
} catch (e) {
Expand Down
12 changes: 6 additions & 6 deletions packages/bitcore-client/bin/wallet-decrypt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env node

const program = require('../ts_build/program');
const { Wallet } = require('../ts_build/wallet');
const program = require('commander');
const { Wallet } = require('../ts_build/src/wallet');
const promptly = require('promptly');

program
.version(require('../package.json').version)
.option('--name <name>', 'REQUIRED - Wallet Name')
.option('--path [path]', 'optional - Custom wallet storage path')
.option('--storageType [storageType]', 'optional - name of the databse to use (default Level)')
.requiredOption('--name <name>', 'REQUIRED - Wallet Name')
.option('--storageType <storageType>', 'optional - name of the database to use (default Level)')
.option('--path <path>', 'optional - Custom wallet storage path')
.parse(process.argv);

const main = async () => {
const { name, path, storageType } = program;
const { name, path, storageType = 'Level' } = program.opts();
try {
const password = await promptly.password('Wallet Password:');
let wallet = await Wallet.loadWallet({ name, path, storageType });
Expand Down
12 changes: 6 additions & 6 deletions packages/bitcore-client/bin/wallet-delete
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/usr/bin/env node

const program = require('../ts_build/program');
const { Wallet } = require('../ts_build/wallet');
const program = require('commander');
const { Wallet } = require('../ts_build/src/wallet');

try {
program
.version(require('../package.json').version)
.option('--name <name>', 'REQUIRED - Wallet name')
.option('--path [path]', 'optional - Custom wallet storage path')
.option('--storageType [storageType]', 'optional - name of the database to use (default level)')
.requiredOption('--name <name>', 'REQUIRED - Wallet name')
.option('--storageType <storageType>', 'optional - name of the database to use (default level)')
.option('--path <path>', 'optional - Custom wallet storage path')
.parse(process.argv);
} catch (e) {
console.log(e.message);
return program.help();
}

async function main() {
const { name, path, time, storageType, token } = program;
const { name, path, storageType } = program.opts();
const wallet = await Wallet.deleteWallet({ name, path, storageType });
return "Deleted";
}
Expand Down
Loading

0 comments on commit 67a2c03

Please sign in to comment.