-
Notifications
You must be signed in to change notification settings - Fork 7
/
getAccountXPUB.js
48 lines (39 loc) · 1.05 KB
/
getAccountXPUB.js
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
'use strict';
const Logger = require('blgr');
const {HID, LedgerHSD} = require('../lib/hsd-ledger');
const {Device} = HID;
(async () => {
// Create logger.
const logger = new Logger({
console: true,
level: 'info'
});
// Get first device available and
// set optional properties.
const device = await Device.requestDevice();
device.set({
timeout: 15000, // optional (default is 5mins)
logger: logger // optional
});
// Create ledger client object.
const ledger = new LedgerHSD({
device: device,
network: 'regtest',
logger: logger // optional
});
// Open logger and device.
await logger.open();
await device.open();
// Do not confirm on-device.
const xpub = await ledger.getAccountXPUB(0);
// Log to console for on-device confirmation.
logger.info('XPUB: %s', xpub.xpubkey('regtest'));
// Confirm on-device.
await ledger.getAccountXPUB(0, { confirm: true });
// Close logger and device.
await device.close();
await logger.close();
})().catch((e) => {
console.error(e);
process.exit(1);
});