-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbcoin-verifyAddress.js
More file actions
54 lines (41 loc) · 1.61 KB
/
bcoin-verifyAddress.js
File metadata and controls
54 lines (41 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
const bledger = require('../lib/bledger');
const {LedgerBcoin} = bledger;
const {Device} = bledger.USB;
const {addressFlags} = LedgerBcoin;
const KeyRing = require('bcoin/lib/primitives/keyring');
(async () => {
// get first device available.
const device = await Device.requestDevice();
device.set({ timeout: 60000 });
await device.open();
const purpose = 44;
const coinType = 0;
const account = 0;
const receivePath = `m/${purpose}'/${coinType}'/${account}'/0/0`;
const ledgerBcoin = new LedgerBcoin({ device });
const hdpub = await ledgerBcoin.getPublicKey(receivePath);
const ring = KeyRing.fromPublic(hdpub.publicKey);
const addr = ring.getAddress();
console.log('Verify legacy address is the same: ', addr.toString());
const verifyLegacy = addressFlags.VERIFY | addressFlags.LEGACY;
await ledgerBcoin.getPublicKey(receivePath, verifyLegacy);
ring.refresh();
ring.witness = true;
ring.nested = true;
const nestedAddr = ring.getAddress();
const verifyNested = addressFlags.VERIFY | addressFlags.NESTED_WITNESS;
console.log('Verify nested address is the same: ', nestedAddr.toString());
console.log(await ledgerBcoin.getPublicKey(receivePath, verifyNested));
ring.refresh();
ring.witness = true;
ring.nested = false;
const bech32Addr = ring.getAddress();
const verifyWitness = addressFlags.VERIFY | addressFlags.WITNESS;
console.log('Verify bech32 address is the same: ', bech32Addr.toString());
console.log(await ledgerBcoin.getPublicKey(receivePath, verifyWitness));
await device.close();
})().catch((e) => {
console.error(e);
process.exit(1);
});