Skip to content

Commit 4be78d5

Browse files
author
Darren Nelsen
committed
merge in lastest from upstream
2 parents 728f416 + 6d89775 commit 4be78d5

File tree

109 files changed

+7528
-8826
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+7528
-8826
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ COPY package*.json ./
44
RUN npm install
55
COPY lerna.json ./
66

7+
COPY ./packages/bitcore-mnemonic/package.json ./packages/bitcore-mnemonic/package.json
78
COPY ./packages/bitcore-lib/package.json ./packages/bitcore-lib/package.json
89
COPY ./packages/bitcore-lib-cash/package.json ./packages/bitcore-lib-cash/package.json
910
COPY ./packages/bitcore-p2p/package.json ./packages/bitcore-p2p/package.json
@@ -16,7 +17,7 @@ COPY ./packages/insight/app/package.json ./packages/insight/app/package.json
1617

1718
RUN ./node_modules/.bin/lerna bootstrap
1819

19-
COPY . .
20+
COPY . .
2021
EXPOSE 3000
2122
EXPOSE 8100
2223
CMD ["./node_modules/.bin/lerna", "run", "start"]

docker-compose.test.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
- 8100:8100
1111
- 3000:3000
1212
environment:
13-
- DB_HOST=db:27017
13+
- DB_HOST=db
1414
- DB_NAME=bitcore-test
1515
- BITCORE_CONFIG_PATH=/bitcore/bitcore-test.config.json
1616
depends_on:
@@ -19,13 +19,8 @@ services:
1919

2020
db:
2121
image: mongo
22-
ports:
23-
- 27018:27017
2422

2523
bitcoin:
26-
ports:
27-
- 8332:8332
28-
- 8333:8333
2924
image: ruimarinho/bitcoin-core:0.16.0-alpine
3025
command:
3126
-printtoconsole

packages/bitcore-client/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wallet.config.json

packages/bitcore-client/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Purpose
2+
This repo should allow you to create a wallet using the bitcore-v8 infrastructure.
3+
4+
Currently we have the following features
5+
* Wallet Creation
6+
* Importing Addresses to the Wallet
7+
* View Only
8+
* Send Enabled by including the privKey
9+
* Instant balance checking
10+
* Transaction Creation
11+
* Transaction Signing
12+
* Transaction Broadcasting
13+
* Multi-Sig address derive/importing
14+
15+
# Commands
16+
17+
### Wallet Create
18+
```
19+
./wallet-create --name TestWalletBTC --chain BTC --network mainnet
20+
```
21+
22+
### Wallet Import
23+
You can import a jsonl file. privKey and pubKey are optional.
24+
If you provide privKey, pubKey must be provided as well
25+
```
26+
//~/Desktop/export.jsonl
27+
{"address": "mXy1234", privKey: "xxxxxxx", pubKey: "yyyyyyyy"}
28+
{"address": "mXy1234", privKey: "xxxxxxx", pubKey: "yyyyyyyy"}
29+
{"address": "mXy1234", privKey: "xxxxxxx", pubKey: "yyyyyyyy"}
30+
```
31+
```
32+
./wallet-import --name TestWalletBTC --file ~/Desktop/export.jsonl
33+
```
34+
35+
### Balance Checking
36+
```
37+
./wallet-balance --name TestWalletBTC
38+
```
39+
40+
### Wallet UTXOS
41+
```
42+
./bin/wallet-utxos --name TestWalletBTC
43+
```
44+
45+
### Transaction Creation
46+
```
47+
./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
48+
```
49+
50+
### Transaction Signing
51+
```
52+
./bin/wallet-sign --name TestWalletBTC --tx 0100000001616db828f14f30177d17c01a58cbe69fbf241646add940fdb17de41c501f32280000000000ffffffff0200f90295000000001976a914578237b9848cc709ced0e098417e0494415add1488ac9cf80295000000001976a914caf0ee682de3daa9b3640da1f6d47cc04ce2c99e88ac00000000
53+
```
54+
55+
### Transaction Broadcast
56+
```
57+
./bin/wallet-broadcast --name TestWalletBTC --tx 0100000001616db828f14f30177d17c01a58cbe69fbf241646add940fdb17de41c501f32280000000048473044022052cf595274c422c37d140989c8cc31c95b39d326b5eac8d4feb8bcceebdebc3f02205635c798c24ae1d44d0871e6938dbfd76293e695131d890838654816f28b942401ffffffff0200f90295000000001976a914578237b9848cc709ced0e098417e0494415add1488ac9cf80295000000001976a914caf0ee682de3daa9b3640da1f6d47cc04ce2c99e88ac00000000
58+
```

packages/bitcore-client/bin/wallet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ program
66
.version(require('../package.json').version)
77
.description('CLI wallet utility for Bitcore-node')
88
.command('create', 'create a wallet').alias('c')
9+
.command('list', 'list wallets').alias('l')
910
.command('import', 'import addresses/keys').alias('i')
1011
.command('register', 'register a wallet with bitcore-node').alias('r')
1112
.command('balance', 'check wallet balance').alias('b')

packages/bitcore-client/bin/wallet-balance

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
#!/usr/bin/env node
22

3-
const program = require('commander');
3+
const program = require('../lib/program');
44
const Wallet = require('../lib/wallet');
5-
const promptly = require('promptly');
65

76
program
87
.version(require('../package.json').version)
9-
.option('--path <path>', 'REQUIRED - Where wallet is stored')
8+
.option('--name <name>', 'REQUIRED - Wallet name')
9+
.option('--path [path]', 'optional - Custom wallet storage path')
1010
.parse(process.argv);
1111

1212
const main = async () => {
13-
const { path } = program;
14-
let wallet;
13+
const { name, path } = program;
1514
try {
16-
const password = await promptly.password('Wallet Password:');
17-
wallet = await Wallet.loadWallet({ path });
18-
wallet = await wallet.unlock(password);
15+
const wallet = await Wallet.loadWallet({ name, path });
1916
const balance = await wallet.getBalance();
2017
console.log(
2118
Object.assign(balance, {
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
#!/usr/bin/env node
22

3-
const program = require('commander');
3+
const program = require('../lib/program');
44
const Wallet = require('../lib/wallet');
55

66
program
77
.version(require('../package.json').version)
8+
.option('--name <name>', 'REQUIRED - Wallet name')
89
.option('--tx <tx>', 'REQUIRED - Signed transaction to broadcast')
9-
.option('--path <path>', 'REQUIRED - Where wallet is stored')
10+
.option('--path [path]', 'optional - Custom wallet storage path')
1011
.parse(process.argv);
1112

1213
const main = async () => {
13-
const {tx, path} = program;
14+
const { tx, name, path } = program;
1415
let wallet;
1516
try {
16-
wallet = await Wallet.loadWallet({ path });
17-
await wallet.broadcast({ tx });
18-
console.log('Transaction broadcasted');
17+
wallet = await Wallet.loadWallet({ name, path });
18+
const transaction = await wallet.broadcast({ tx });
19+
console.log(`Transaction broadcasted, txid: ${transaction.txid}`);
1920
} catch (e) {
2021
console.error(e);
2122
}
22-
}
23+
};
2324

2425
main();

packages/bitcore-client/bin/wallet-create

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
const program = require('commander');
3+
const program = require('../lib/program');
44
const Wallet = require('../lib/wallet');
55
const promptly = require('promptly');
66

@@ -12,17 +12,18 @@ program
1212
'--network <network>',
1313
'REQUIRED - Network (livenet/testnet/regtest, etc)'
1414
)
15-
.option('--path <path>', 'REQUIRED - Where wallet should be stored')
16-
.option('--mnemonic <phrase>', 'optional - Seed using existing backup phrase')
15+
.option('--baseUrl [host]', 'optional - Specify custom Bitcore API URL')
16+
.option('--path [path]', 'optional - Custom wallet storage path')
17+
.option('--mnemonic [phrase]', 'optional - Seed using existing backup phrase')
1718
.parse(process.argv);
1819

1920
const main = async () => {
20-
const { name, chain, network, path, phrase } = program;
21-
const password = await promptly.password('Wallet Password:');
22-
let wallet;
21+
const { name, baseUrl, chain, network, path, phrase } = program;
2322
try {
24-
wallet = await Wallet.create({
23+
const password = await promptly.password('Wallet Password:');
24+
await Wallet.create({
2525
name,
26+
baseUrl,
2627
chain,
2728
network,
2829
path,

packages/bitcore-client/bin/wallet-decrypt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#!/usr/bin/env node
22

3-
const program = require('commander');
3+
const program = require('../lib/program');
44
const Wallet = require('../lib/wallet');
55
const promptly = require('promptly');
66

77
program
88
.version(require('../package.json').version)
9-
.option('--path <path>', 'REQUIRED - Wallet Path')
9+
.option('--name <name>', 'REQUIRED - Wallet Name')
10+
.option('--path [path]', 'optional - Custom wallet storage path')
1011
.parse(process.argv);
1112

1213
const main = async () => {
13-
const { path } = program;
14+
const { name, path } = program;
1415
try {
1516
const password = await promptly.password('Wallet Password:');
16-
let wallet = await Wallet.loadWallet({ path });
17+
let wallet = await Wallet.loadWallet({ name, path });
1718
await wallet.unlock(password);
1819
console.log(wallet);
1920
} catch (e) {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env node
2+
3+
const bitcoreLibs = {
4+
BTC: require('bitcore-lib'),
5+
BCH: require('bitcore-lib-cash')
6+
};
7+
const program = require('../lib/program');
8+
const Wallet = require('../lib/wallet');
9+
const promptly = require('promptly');
10+
11+
program
12+
.version(require('../package.json').version)
13+
.option('--name <name>', 'REQUIRED - Wallet Name')
14+
.option('--gap [gap]', 'optional - Number of addresses to derive (will derive that many change addresses too)')
15+
.option('--change [change]', 'optional - should derive change addresses')
16+
.option('--path [path]', 'optional - Custom wallet storage path')
17+
.parse(process.argv);
18+
19+
function derivePrivateKey(addressIndex, isChange, key) {
20+
const changeNum = isChange ? 1 : 0;
21+
const path = `m/${changeNum}/${addressIndex}`;
22+
return key.derive(path);
23+
}
24+
25+
const main = async () => {
26+
const { name, path, gap=20, change=false } = program;
27+
let wallet;
28+
try {
29+
const password = await promptly.password('Wallet Password:');
30+
wallet = await Wallet.loadWallet({ name, path });
31+
wallet = await wallet.unlock(password);
32+
33+
const { chain, network } = wallet;
34+
let unusedAddressCounter = 0;
35+
36+
let index = 0;
37+
38+
if (change) {
39+
index = wallet.changeAddressIndex || 0;
40+
}
41+
42+
const xprivkey = wallet.unlocked.masterKey.xprivkey;
43+
const HDPrivateKey = new bitcoreLibs[chain].HDPrivateKey(xprivkey);
44+
45+
while (unusedAddressCounter < gap) {
46+
const derived = derivePrivateKey(index, change, HDPrivateKey);
47+
const privKey = derived.privateKey.toString();
48+
const address = derived.privateKey.toAddress(network).toString(true);
49+
await wallet.importKeys({ keys: [{ privKey, address }] });
50+
51+
const hasTransactions = await wallet.client.getAddressTxos({ address });
52+
53+
if (!hasTransactions.length) {
54+
unusedAddressCounter++;
55+
} else {
56+
unusedAddressCounter = 0;
57+
}
58+
index++;
59+
if (change) {
60+
wallet.changeAddressIndex = index;
61+
console.log('Current change index: ', index);
62+
} else {
63+
wallet.addressIndex = index;
64+
console.log(`Current address index: ${index}: ${address}`);
65+
}
66+
}
67+
wallet.saveWallet();
68+
} catch (e) {
69+
console.error(e);
70+
}
71+
};
72+
73+
main();

packages/bitcore-client/bin/wallet-import

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#!/usr/bin/env node
22

33
const fs = require('fs');
4-
const program = require('commander');
4+
const program = require('../lib/program');
55
const Wallet = require('../lib/wallet');
66
const promptly = require('promptly');
77

88
program
99
.version(require('../package.json').version)
10-
.option('--path <path>', 'REQUIRED - Where wallet is stored')
10+
.option('--name <name>', 'REQUIRED - Wallet Name')
1111
.option(
1212
'--parse [parse]',
13-
'OPTIONAL - A json string to parse in the form {"address": "mXy1234", privKey: "xxxxxxx"}'
13+
'OPTIONAL - A json string to parse in the form {"address": "mXy1234", "privKey": "xxxxxxx", "pubKey": "yyyyyyyy"}'
1414
)
1515
.option(
1616
'--file [file]',
17-
'OPTIONAL - A jsonl file with {"address": "mXy1234", privKey: "xxxxxxx"} in it'
17+
'OPTIONAL - A jsonl file with {"address": "mXy1234", "privKey": "xxxxxxx", "pubKey": "yyyyyyyy"} in it'
1818
)
19+
.option('--path [path]', 'optional - Custom wallet storage path')
1920
.parse(process.argv);
2021

2122
const getFileKeys = file => {
@@ -37,16 +38,12 @@ const parseKeys = keys => {
3738
};
3839

3940
const main = async () => {
40-
const { path, file, parse } = program;
41+
const { name, path, file, parse } = program;
4142
let wallet;
4243
try {
4344
const password = await promptly.password('Wallet Password:');
44-
if (!password) {
45-
throw new Error(
46-
'No password provided. Keys can\'t be imported without unlocking the wallet'
47-
);
48-
}
4945
wallet = await Wallet.loadWallet({ path });
46+
wallet = await Wallet.loadWallet({ name, path });
5047
wallet = await wallet.unlock(password);
5148
let keyInput = [];
5249
if (file) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const Storage = require('../lib/storage');
5+
const program = require('../lib/program');
6+
7+
program
8+
.version(require('../package.json').version)
9+
.option('--path [path]', 'optional - Where wallets are stored')
10+
.parse(process.argv);
11+
12+
const main = async () => {
13+
const { path } = program;
14+
const storage = new Storage({createIfMissing: false, errorIfExists: false, path});
15+
const walletStream = storage.listWallets();
16+
walletStream.on('data', (wallet) => {
17+
const { name, chain, network } = JSON.parse(wallet.toString());
18+
console.log({name, chain, network});
19+
});
20+
};
21+
22+
main();

packages/bitcore-client/bin/wallet-register

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
#!/usr/bin/env node
22

3-
const program = require('commander');
3+
const program = require('../lib/program');
44
const Wallet = require('../lib/wallet');
5-
const promptly = require('promptly');
65

76
program
87
.version(require('../package.json').version)
9-
.option('--path <path>', 'REQUIRED - Where wallet is stored')
8+
.option('--name <name>', 'REQUIRED - Wallet Name')
9+
.option('--path [path]', 'optional - Custom wallet storage path')
1010
.option('--baseUrl <url>', 'optional - Change configured wallet baseUrl')
1111
.parse(process.argv);
1212

1313
const main = async () => {
14-
const { path, baseUrl } = program;
14+
const { name, path, baseUrl } = program;
1515
let wallet;
1616
try {
17-
const password = await promptly.password('Wallet Password:');
18-
wallet = await Wallet.loadWallet({ path });
19-
wallet = await wallet.unlock(password);
17+
wallet = await Wallet.loadWallet({ name, path });
2018
await wallet.register({ baseUrl });
2119
console.log('Wallet registered!');
2220
} catch (e) {

0 commit comments

Comments
 (0)