@bitboxswiss/bitbox-api 0.1.0 → 0.1.1
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.
- package/dist/index.d.ts +334 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +451 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/connect-simulator.d.ts +2 -0
- package/dist/internal/connect-simulator.d.ts.map +1 -0
- package/dist/internal/connect-simulator.js +25 -0
- package/dist/internal/connect-simulator.js.map +1 -0
- package/dist/internal/connect.d.ts +2 -0
- package/dist/internal/connect.d.ts.map +1 -0
- package/dist/internal/connect.js +54 -0
- package/dist/internal/connect.js.map +1 -0
- package/dist/internal/constants.d.ts +2 -0
- package/dist/internal/constants.d.ts.map +1 -0
- package/dist/internal/constants.js +16 -0
- package/dist/internal/constants.js.map +1 -0
- package/dist/internal/device.d.ts +5 -0
- package/dist/internal/device.d.ts.map +1 -0
- package/dist/internal/device.js +40 -0
- package/dist/internal/device.js.map +1 -0
- package/dist/internal/errors.d.ts +2 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +220 -0
- package/dist/internal/errors.js.map +1 -0
- package/dist/internal/eth/antiklepto.d.ts +5 -0
- package/dist/internal/eth/antiklepto.d.ts.map +1 -0
- package/dist/internal/eth/antiklepto.js +59 -0
- package/dist/internal/eth/antiklepto.js.map +1 -0
- package/dist/internal/eth/eip712.d.ts +25 -0
- package/dist/internal/eth/eip712.d.ts.map +1 -0
- package/dist/internal/eth/eip712.js +303 -0
- package/dist/internal/eth/eip712.js.map +1 -0
- package/dist/internal/eth/keypath.d.ts +4 -0
- package/dist/internal/eth/keypath.d.ts.map +1 -0
- package/dist/internal/eth/keypath.js +47 -0
- package/dist/internal/eth/keypath.js.map +1 -0
- package/dist/internal/eth/methods.d.ts +10 -0
- package/dist/internal/eth/methods.d.ts.map +1 -0
- package/dist/internal/eth/methods.js +250 -0
- package/dist/internal/eth/methods.js.map +1 -0
- package/dist/internal/eth/query.d.ts +7 -0
- package/dist/internal/eth/query.d.ts.map +1 -0
- package/dist/internal/eth/query.js +43 -0
- package/dist/internal/eth/query.js.map +1 -0
- package/dist/internal/eth/streaming.d.ts +4 -0
- package/dist/internal/eth/streaming.d.ts.map +1 -0
- package/dist/internal/eth/streaming.js +21 -0
- package/dist/internal/eth/streaming.js.map +1 -0
- package/dist/internal/eth/version.d.ts +9 -0
- package/dist/internal/eth/version.d.ts.map +1 -0
- package/dist/internal/eth/version.js +10 -0
- package/dist/internal/eth/version.js.map +1 -0
- package/dist/internal/hww.d.ts +2 -0
- package/dist/internal/hww.d.ts.map +1 -0
- package/dist/internal/hww.js +236 -0
- package/dist/internal/hww.js.map +1 -0
- package/dist/internal/message-queue.d.ts +2 -0
- package/dist/internal/message-queue.d.ts.map +1 -0
- package/dist/internal/message-queue.js +29 -0
- package/dist/internal/message-queue.js.map +1 -0
- package/dist/internal/noise-config.d.ts +2 -0
- package/dist/internal/noise-config.d.ts.map +1 -0
- package/dist/internal/noise-config.js +160 -0
- package/dist/internal/noise-config.js.map +1 -0
- package/dist/internal/noise.d.ts +2 -0
- package/dist/internal/noise.d.ts.map +1 -0
- package/dist/internal/noise.js +270 -0
- package/dist/internal/noise.js.map +1 -0
- package/dist/internal/pairing.d.ts +2 -0
- package/dist/internal/pairing.d.ts.map +1 -0
- package/dist/internal/pairing.js +130 -0
- package/dist/internal/pairing.js.map +1 -0
- package/dist/internal/read-write.d.ts +2 -0
- package/dist/internal/read-write.d.ts.map +1 -0
- package/dist/internal/read-write.js +40 -0
- package/dist/internal/read-write.js.map +1 -0
- package/dist/internal/restore.d.ts +3 -0
- package/dist/internal/restore.d.ts.map +1 -0
- package/dist/internal/restore.js +27 -0
- package/dist/internal/restore.js.map +1 -0
- package/dist/internal/transport-bridge.d.ts +2 -0
- package/dist/internal/transport-bridge.d.ts.map +1 -0
- package/dist/internal/transport-bridge.js +97 -0
- package/dist/internal/transport-bridge.js.map +1 -0
- package/dist/internal/transport-simulator.d.ts +2 -0
- package/dist/internal/transport-simulator.d.ts.map +1 -0
- package/dist/internal/transport-simulator.js +83 -0
- package/dist/internal/transport-simulator.js.map +1 -0
- package/dist/internal/transport-webhid.d.ts +2 -0
- package/dist/internal/transport-webhid.d.ts.map +1 -0
- package/dist/internal/transport-webhid.js +69 -0
- package/dist/internal/transport-webhid.js.map +1 -0
- package/dist/internal/u2f-framing.d.ts +2 -0
- package/dist/internal/u2f-framing.d.ts.map +1 -0
- package/dist/internal/u2f-framing.js +155 -0
- package/dist/internal/u2f-framing.js.map +1 -0
- package/dist/internal/utils.d.ts +2 -0
- package/dist/internal/utils.d.ts.map +1 -0
- package/dist/internal/utils.js +71 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/proto/gen/antiklepto_pb.d.ts +49 -0
- package/dist/proto/gen/antiklepto_pb.d.ts.map +1 -0
- package/dist/proto/gen/antiklepto_pb.js +22 -0
- package/dist/proto/gen/antiklepto_pb.js.map +1 -0
- package/dist/proto/gen/backup_commands_pb.d.ts +124 -0
- package/dist/proto/gen/backup_commands_pb.d.ts.map +1 -0
- package/dist/proto/gen/backup_commands_pb.js +42 -0
- package/dist/proto/gen/backup_commands_pb.js.map +1 -0
- package/dist/proto/gen/backup_pb.d.ts +150 -0
- package/dist/proto/gen/backup_pb.d.ts.map +1 -0
- package/dist/proto/gen/backup_pb.js +46 -0
- package/dist/proto/gen/backup_pb.js.map +1 -0
- package/dist/proto/gen/bitbox02_system_pb.d.ts +207 -0
- package/dist/proto/gen/bitbox02_system_pb.d.ts.map +1 -0
- package/dist/proto/gen/bitbox02_system_pb.js +80 -0
- package/dist/proto/gen/bitbox02_system_pb.js.map +1 -0
- package/dist/proto/gen/bluetooth_pb.d.ts +135 -0
- package/dist/proto/gen/bluetooth_pb.d.ts.map +1 -0
- package/dist/proto/gen/bluetooth_pb.js +42 -0
- package/dist/proto/gen/bluetooth_pb.js.map +1 -0
- package/dist/proto/gen/btc_pb.d.ts +1166 -0
- package/dist/proto/gen/btc_pb.d.ts.map +1 -0
- package/dist/proto/gen/btc_pb.js +442 -0
- package/dist/proto/gen/btc_pb.js.map +1 -0
- package/dist/proto/gen/cardano_pb.d.ts +504 -0
- package/dist/proto/gen/cardano_pb.d.ts.map +1 -0
- package/dist/proto/gen/cardano_pb.js +142 -0
- package/dist/proto/gen/cardano_pb.js.map +1 -0
- package/dist/proto/gen/common_pb.d.ts +129 -0
- package/dist/proto/gen/common_pb.d.ts.map +1 -0
- package/dist/proto/gen/common_pb.js +42 -0
- package/dist/proto/gen/common_pb.js.map +1 -0
- package/dist/proto/gen/eth_pb.d.ts +662 -0
- package/dist/proto/gen/eth_pb.d.ts.map +1 -0
- package/dist/proto/gen/eth_pb.js +221 -0
- package/dist/proto/gen/eth_pb.js.map +1 -0
- package/dist/proto/gen/hww_pb.d.ts +349 -0
- package/dist/proto/gen/hww_pb.d.ts.map +1 -0
- package/dist/proto/gen/hww_pb.js +38 -0
- package/dist/proto/gen/hww_pb.js.map +1 -0
- package/dist/proto/gen/keystore_pb.d.ts +108 -0
- package/dist/proto/gen/keystore_pb.d.ts.map +1 -0
- package/dist/proto/gen/keystore_pb.js +33 -0
- package/dist/proto/gen/keystore_pb.js.map +1 -0
- package/dist/proto/gen/mnemonic_pb.d.ts +48 -0
- package/dist/proto/gen/mnemonic_pb.d.ts.map +1 -0
- package/dist/proto/gen/mnemonic_pb.js +22 -0
- package/dist/proto/gen/mnemonic_pb.js.map +1 -0
- package/dist/proto/gen/perform_attestation_pb.d.ts +57 -0
- package/dist/proto/gen/perform_attestation_pb.d.ts.map +1 -0
- package/dist/proto/gen/perform_attestation_pb.js +17 -0
- package/dist/proto/gen/perform_attestation_pb.js.map +1 -0
- package/dist/proto/gen/system_pb.d.ts +38 -0
- package/dist/proto/gen/system_pb.d.ts.map +1 -0
- package/dist/proto/gen/system_pb.js +30 -0
- package/dist/proto/gen/system_pb.js.map +1 -0
- package/package.json +2 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { connectAuto, connectBridge, connectWebHID, } from './internal/connect.js';
|
|
3
|
+
import { CODE_INVALID_STATE, CODE_NOT_IMPLEMENTED, CODE_UNSUPPORTED, CODE_USER_ABORT, CODE_BITBOX_USER_ABORT, ensureTyped, toPublicError, } from './internal/errors.js';
|
|
4
|
+
import { deviceInfo as deviceInfoImpl, rootFingerprint as rootFingerprintImpl, } from './internal/device.js';
|
|
5
|
+
import { ethAddress as ethAddressImpl, ethSign1559Transaction as ethSign1559TransactionImpl, ethSignMessage as ethSignMessageImpl, ethSignTransaction as ethSignTransactionImpl, ethSignTypedMessage as ethSignTypedMessageImpl, ethXpub as ethXpubImpl, } from './internal/eth/methods.js';
|
|
6
|
+
import { completePairing, performHandshake, } from './internal/pairing.js';
|
|
7
|
+
function unsupportedError(method) {
|
|
8
|
+
return {
|
|
9
|
+
code: CODE_UNSUPPORTED,
|
|
10
|
+
message: `${method} is not supported in @bitboxswiss/bitbox-api`,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function notImplementedError(method) {
|
|
14
|
+
return {
|
|
15
|
+
code: CODE_NOT_IMPLEMENTED,
|
|
16
|
+
message: `${method} is not yet implemented in @bitboxswiss/bitbox-api`,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function invalidStateError(method) {
|
|
20
|
+
return {
|
|
21
|
+
code: CODE_INVALID_STATE,
|
|
22
|
+
message: `${method}: object is not in a usable state (uninitialized, consumed, or closed)`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Connect to a BitBox02 using WebHID.
|
|
27
|
+
*
|
|
28
|
+
* WebHID is available in Chromium-based browsers in secure contexts. Call this
|
|
29
|
+
* from a user action so the browser can show the device chooser.
|
|
30
|
+
*/
|
|
31
|
+
export async function bitbox02ConnectWebHID(onCloseCb) {
|
|
32
|
+
try {
|
|
33
|
+
return new BitBox(await connectWebHID(onCloseCb));
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
throw toPublicError(err);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Connect to a BitBox02 through the local BitBoxBridge service.
|
|
41
|
+
*/
|
|
42
|
+
export async function bitbox02ConnectBridge(onCloseCb) {
|
|
43
|
+
try {
|
|
44
|
+
return new BitBox(await connectBridge(onCloseCb));
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
throw toPublicError(err);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Connect to a BitBox02 using WebHID when available, otherwise BitBoxBridge.
|
|
52
|
+
*/
|
|
53
|
+
export async function bitbox02ConnectAuto(onCloseCb) {
|
|
54
|
+
try {
|
|
55
|
+
return new BitBox(await connectAuto(onCloseCb));
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
throw toPublicError(err);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Normalize any thrown value to the public typed error shape.
|
|
63
|
+
*
|
|
64
|
+
* If the input already looks like a typed `{ code: string, message: string }`, it is returned
|
|
65
|
+
* as-is. Otherwise it is wrapped as `{ code: 'unknown-js', message: 'Unknown Javascript error',
|
|
66
|
+
* err: <original> }`.
|
|
67
|
+
*/
|
|
68
|
+
export function ensureError(err) {
|
|
69
|
+
return ensureTyped(err);
|
|
70
|
+
}
|
|
71
|
+
/** Returns true if the user cancelled an operation. */
|
|
72
|
+
export function isUserAbort(err) {
|
|
73
|
+
return err.code === CODE_USER_ABORT || err.code === CODE_BITBOX_USER_ABORT;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Identifies the case of the recipient address given as hexadecimal string.
|
|
77
|
+
* Returns 'upper' if every alphabetic char is uppercase, 'lower' if every
|
|
78
|
+
* alphabetic char is lowercase, 'mixed' otherwise. Non-alphabetic characters
|
|
79
|
+
* are ignored.
|
|
80
|
+
*/
|
|
81
|
+
export function ethIdentifyCase(recipientAddress) {
|
|
82
|
+
let hasUpper = false;
|
|
83
|
+
let hasLower = false;
|
|
84
|
+
for (const c of recipientAddress) {
|
|
85
|
+
if (c >= 'A' && c <= 'Z') {
|
|
86
|
+
hasUpper = true;
|
|
87
|
+
}
|
|
88
|
+
else if (c >= 'a' && c <= 'z') {
|
|
89
|
+
hasLower = true;
|
|
90
|
+
}
|
|
91
|
+
if (hasUpper && hasLower) {
|
|
92
|
+
return 'mixed';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (hasLower) {
|
|
96
|
+
return 'lower';
|
|
97
|
+
}
|
|
98
|
+
return 'upper';
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Unpaired BitBox client.
|
|
102
|
+
*
|
|
103
|
+
* Create initialized instances with `bitbox02ConnectAuto()`, `bitbox02ConnectWebHID()`, or
|
|
104
|
+
* `bitbox02ConnectBridge()`. Direct constructors are retained for compatibility and create an
|
|
105
|
+
* inert object whose methods throw `code: 'invalid-state'`.
|
|
106
|
+
*/
|
|
107
|
+
export class BitBox {
|
|
108
|
+
#state = { kind: 'uninitialized' };
|
|
109
|
+
/** @internal */
|
|
110
|
+
constructor(session) {
|
|
111
|
+
if (session !== undefined) {
|
|
112
|
+
this.#state = {
|
|
113
|
+
kind: 'open',
|
|
114
|
+
hww: session.hww,
|
|
115
|
+
close: session.close,
|
|
116
|
+
config: session.config,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
#consumeOpen() {
|
|
121
|
+
const state = this.#state;
|
|
122
|
+
if (state.kind !== 'open') {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
this.#state = { kind: 'consumed' };
|
|
126
|
+
return state;
|
|
127
|
+
}
|
|
128
|
+
/** No-op; retained for ABI compatibility with the wasm-bindgen output. */
|
|
129
|
+
free() { }
|
|
130
|
+
/**
|
|
131
|
+
* Invokes the device unlock and pairing. After this, stop using this instance and continue
|
|
132
|
+
* with the returned instance of type `PairingBitBox`.
|
|
133
|
+
*
|
|
134
|
+
* This consumes the `BitBox` synchronously. A second call, including a concurrent call while
|
|
135
|
+
* the first is still running, rejects with `code: 'invalid-state'`. If pairing setup fails, the
|
|
136
|
+
* transport is closed and callers must reconnect before retrying.
|
|
137
|
+
*/
|
|
138
|
+
async unlockAndPair() {
|
|
139
|
+
const open = this.#consumeOpen();
|
|
140
|
+
if (open === undefined) {
|
|
141
|
+
throw invalidStateError('unlockAndPair');
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const pairing = await performHandshake(open.hww, open.config);
|
|
145
|
+
return makePairingBitBox(pairing, open.close);
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
bestEffortClose(open.close);
|
|
149
|
+
throw toPublicError(err);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* BitBox in the pairing state. Use `getPairingCode()` to display the pairing code to the user and
|
|
155
|
+
* `waitConfirm()` to proceed to the paired state. Direct constructors create an inert object.
|
|
156
|
+
*/
|
|
157
|
+
export class PairingBitBox {
|
|
158
|
+
#state = { kind: 'uninitialized' };
|
|
159
|
+
/** @internal */
|
|
160
|
+
constructor(init) {
|
|
161
|
+
if (init !== undefined) {
|
|
162
|
+
this.#state = { kind: 'open', ...init };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
#readOpen() {
|
|
166
|
+
return this.#state.kind === 'open' ? this.#state : undefined;
|
|
167
|
+
}
|
|
168
|
+
#consumeOpen() {
|
|
169
|
+
const state = this.#state;
|
|
170
|
+
if (state.kind !== 'open') {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
this.#state = { kind: 'consumed' };
|
|
174
|
+
return state;
|
|
175
|
+
}
|
|
176
|
+
/** No-op; retained for ABI compatibility with the wasm-bindgen output. */
|
|
177
|
+
free() { }
|
|
178
|
+
/**
|
|
179
|
+
* If a pairing code confirmation is required, this returns the pairing code. You must display
|
|
180
|
+
* it to the user and then call `waitConfirm()` to wait until the user confirms the code on
|
|
181
|
+
* the BitBox.
|
|
182
|
+
*
|
|
183
|
+
* If the BitBox was paired before and the pairing was persisted, the pairing step is
|
|
184
|
+
* skipped. In this case, `undefined` is returned. Also in this case, call `waitConfirm()` to
|
|
185
|
+
* establish the encrypted connection.
|
|
186
|
+
*
|
|
187
|
+
* Call this before `waitConfirm()`, because `waitConfirm()` consumes the pairing object.
|
|
188
|
+
*/
|
|
189
|
+
getPairingCode() {
|
|
190
|
+
const open = this.#readOpen();
|
|
191
|
+
if (open === undefined) {
|
|
192
|
+
throw invalidStateError('getPairingCode');
|
|
193
|
+
}
|
|
194
|
+
return open.state.pairingCode;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Proceed to the paired state. After this, stop using this instance and continue with the
|
|
198
|
+
* returned instance of type `PairedBitBox`.
|
|
199
|
+
*
|
|
200
|
+
* This consumes the `PairingBitBox` synchronously. A second call, including a concurrent call
|
|
201
|
+
* while the first is still running, rejects with `code: 'invalid-state'`. If confirmation fails,
|
|
202
|
+
* the transport is closed and callers must reconnect before retrying.
|
|
203
|
+
*/
|
|
204
|
+
async waitConfirm() {
|
|
205
|
+
const open = this.#consumeOpen();
|
|
206
|
+
if (open === undefined) {
|
|
207
|
+
throw invalidStateError('waitConfirm');
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const channel = await completePairing(open.state);
|
|
211
|
+
return makePairedBitBox(channel, open.state.hww.info, open.close);
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
bestEffortClose(open.close);
|
|
215
|
+
throw toPublicError(err);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function makePairingBitBox(state, close) {
|
|
220
|
+
return new PairingBitBox({ state, close });
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Paired BitBox. This is where you can invoke most API functions like getting xpubs, displaying
|
|
224
|
+
* receive addresses, and signing transactions. Direct constructors create an inert object.
|
|
225
|
+
*/
|
|
226
|
+
export class PairedBitBox {
|
|
227
|
+
#state = { kind: 'uninitialized' };
|
|
228
|
+
#queue = Promise.resolve();
|
|
229
|
+
/** @internal */
|
|
230
|
+
constructor(init) {
|
|
231
|
+
if (init !== undefined) {
|
|
232
|
+
this.#state = { kind: 'open', ...init };
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
#requireOpen(method) {
|
|
236
|
+
if (this.#state.kind !== 'open') {
|
|
237
|
+
throw invalidStateError(method);
|
|
238
|
+
}
|
|
239
|
+
return this.#state;
|
|
240
|
+
}
|
|
241
|
+
#closeOpen() {
|
|
242
|
+
const state = this.#state;
|
|
243
|
+
if (state.kind !== 'open') {
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
this.#state = { kind: 'closed' };
|
|
247
|
+
return state;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Serializes all device-touching public methods on this paired connection.
|
|
251
|
+
*
|
|
252
|
+
* The BitBox protocol and Noise channel are ordered streams, not multiplexed
|
|
253
|
+
* request/response transports. Some public methods also perform multi-step
|
|
254
|
+
* conversations (for example ETH streaming or anti-klepto signing), so the
|
|
255
|
+
* lock must cover the whole public method, not only one encrypted query.
|
|
256
|
+
*
|
|
257
|
+
* Calls made after close fail before joining the queue, so they do not wait
|
|
258
|
+
* behind a stuck transport read. The open state is checked again when the
|
|
259
|
+
* queued operation starts, so calls queued before close still fail if they
|
|
260
|
+
* did not already enter the device conversation.
|
|
261
|
+
*
|
|
262
|
+
* Each call chains onto the previous queue tail and then replaces the tail
|
|
263
|
+
* with a settled `void` promise, so a rejected call does not poison later
|
|
264
|
+
* queued operations.
|
|
265
|
+
*/
|
|
266
|
+
#runExclusive(method, fn) {
|
|
267
|
+
this.#requireOpen(method);
|
|
268
|
+
const run = this.#queue.catch(() => undefined).then(async () => {
|
|
269
|
+
const open = this.#requireOpen(method);
|
|
270
|
+
try {
|
|
271
|
+
return await fn(open);
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
throw toPublicError(err);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
this.#queue = run.then(() => undefined, () => undefined);
|
|
278
|
+
return run;
|
|
279
|
+
}
|
|
280
|
+
/** No-op; retained for ABI compatibility with the wasm-bindgen output. */
|
|
281
|
+
free() { }
|
|
282
|
+
/**
|
|
283
|
+
* Closes the BitBox connection. This also invokes the `on_close_cb` callback which was
|
|
284
|
+
* provided to the connect method creating the connection. Idempotent: calling close() on an
|
|
285
|
+
* already-closed or uninitialized instance is a no-op.
|
|
286
|
+
*
|
|
287
|
+
* After `close()`, all other methods throw `code: 'invalid-state'`.
|
|
288
|
+
*/
|
|
289
|
+
close() {
|
|
290
|
+
const open = this.#closeOpen();
|
|
291
|
+
if (open === undefined) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
open.close();
|
|
295
|
+
}
|
|
296
|
+
/** Query device metadata. */
|
|
297
|
+
async deviceInfo() {
|
|
298
|
+
return this.#runExclusive('deviceInfo', open => deviceInfoImpl(open.channel));
|
|
299
|
+
}
|
|
300
|
+
/** Returns which product we are connected to. */
|
|
301
|
+
product() {
|
|
302
|
+
return this.#requireOpen('product').info.product;
|
|
303
|
+
}
|
|
304
|
+
/** Returns the firmware version, e.g. "9.18.0". */
|
|
305
|
+
version() {
|
|
306
|
+
return this.#requireOpen('version').info.version;
|
|
307
|
+
}
|
|
308
|
+
/** Returns the hex-encoded 4-byte root fingerprint. */
|
|
309
|
+
async rootFingerprint() {
|
|
310
|
+
return this.#runExclusive('rootFingerprint', open => rootFingerprintImpl(open.channel));
|
|
311
|
+
}
|
|
312
|
+
/** Not implemented in this TypeScript iteration. */
|
|
313
|
+
async showMnemonic() {
|
|
314
|
+
this.#requireOpen('showMnemonic');
|
|
315
|
+
throw notImplementedError('showMnemonic');
|
|
316
|
+
}
|
|
317
|
+
/** Not implemented in this TypeScript iteration. */
|
|
318
|
+
async changePassword() {
|
|
319
|
+
this.#requireOpen('changePassword');
|
|
320
|
+
throw notImplementedError('changePassword');
|
|
321
|
+
}
|
|
322
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
323
|
+
async btcXpub(_coin, _keypath, _xpub_type, _display) {
|
|
324
|
+
this.#requireOpen('btcXpub');
|
|
325
|
+
throw unsupportedError('btcXpub');
|
|
326
|
+
}
|
|
327
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
328
|
+
async btcXpubs(_coin, _keypaths, _xpub_type) {
|
|
329
|
+
this.#requireOpen('btcXpubs');
|
|
330
|
+
throw unsupportedError('btcXpubs');
|
|
331
|
+
}
|
|
332
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
333
|
+
async btcIsScriptConfigRegistered(_coin, _script_config, _keypath_account) {
|
|
334
|
+
this.#requireOpen('btcIsScriptConfigRegistered');
|
|
335
|
+
throw unsupportedError('btcIsScriptConfigRegistered');
|
|
336
|
+
}
|
|
337
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
338
|
+
async btcRegisterScriptConfig(_coin, _script_config, _keypath_account, _xpub_type, _name) {
|
|
339
|
+
this.#requireOpen('btcRegisterScriptConfig');
|
|
340
|
+
throw unsupportedError('btcRegisterScriptConfig');
|
|
341
|
+
}
|
|
342
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
343
|
+
async btcAddress(_coin, _keypath, _script_config, _display) {
|
|
344
|
+
this.#requireOpen('btcAddress');
|
|
345
|
+
throw unsupportedError('btcAddress');
|
|
346
|
+
}
|
|
347
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
348
|
+
async btcSignPSBT(_coin, _psbt, _force_script_config, _format_unit) {
|
|
349
|
+
this.#requireOpen('btcSignPSBT');
|
|
350
|
+
throw unsupportedError('btcSignPSBT');
|
|
351
|
+
}
|
|
352
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
353
|
+
async btcSignMessage(_coin, _script_config, _msg) {
|
|
354
|
+
this.#requireOpen('btcSignMessage');
|
|
355
|
+
throw unsupportedError('btcSignMessage');
|
|
356
|
+
}
|
|
357
|
+
/** Does this device support ETH functionality? Currently this means BitBox02 Multi or Nova Multi. */
|
|
358
|
+
ethSupported() {
|
|
359
|
+
const product = this.#requireOpen('ethSupported').info.product;
|
|
360
|
+
return product === 'bitbox02-multi' || product === 'bitbox02-nova-multi';
|
|
361
|
+
}
|
|
362
|
+
/** Query the device for an Ethereum account xpub. */
|
|
363
|
+
async ethXpub(keypath) {
|
|
364
|
+
return this.#runExclusive('ethXpub', open => ethXpubImpl(open.channel, keypath));
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Query the device for an Ethereum address.
|
|
368
|
+
*
|
|
369
|
+
* Set `display` to `true` to require on-device confirmation.
|
|
370
|
+
*/
|
|
371
|
+
async ethAddress(chain_id, keypath, display) {
|
|
372
|
+
return this.#runExclusive('ethAddress', open => ethAddressImpl(open.channel, chain_id, keypath, display));
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Sign a legacy Ethereum transaction.
|
|
376
|
+
*
|
|
377
|
+
* Transaction fields are unsigned big-endian byte arrays. The returned `v` includes the EIP-155
|
|
378
|
+
* chain ID offset.
|
|
379
|
+
*/
|
|
380
|
+
async ethSignTransaction(chain_id, keypath, tx, address_case) {
|
|
381
|
+
return this.#runExclusive('ethSignTransaction', open => ethSignTransactionImpl(open.channel, open.info, chain_id, keypath, tx, address_case));
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Sign an EIP-1559 type 2 Ethereum transaction.
|
|
385
|
+
*
|
|
386
|
+
* Transaction fields are unsigned big-endian byte arrays. The returned `v` is the recovery ID.
|
|
387
|
+
*/
|
|
388
|
+
async ethSign1559Transaction(keypath, tx, address_case) {
|
|
389
|
+
return this.#runExclusive('ethSign1559Transaction', open => ethSign1559TransactionImpl(open.channel, open.info, keypath, tx, address_case));
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Sign an Ethereum personal message.
|
|
393
|
+
*
|
|
394
|
+
* The device applies the standard Ethereum message prefix before signing. The returned `v`
|
|
395
|
+
* includes the +27 offset.
|
|
396
|
+
*/
|
|
397
|
+
async ethSignMessage(chain_id, keypath, msg) {
|
|
398
|
+
return this.#runExclusive('ethSignMessage', open => ethSignMessageImpl(open.channel, open.info, chain_id, keypath, msg));
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Sign an EIP-712 typed message.
|
|
402
|
+
*
|
|
403
|
+
* `use_antiklepto` defaults to `true` when omitted.
|
|
404
|
+
*/
|
|
405
|
+
async ethSignTypedMessage(chain_id, keypath, msg, use_antiklepto) {
|
|
406
|
+
return this.#runExclusive('ethSignTypedMessage', open => ethSignTypedMessageImpl(open.channel, open.info, chain_id, keypath, msg, use_antiklepto));
|
|
407
|
+
}
|
|
408
|
+
/** Cardano support is not implemented in this TypeScript iteration. */
|
|
409
|
+
cardanoSupported() {
|
|
410
|
+
this.#requireOpen('cardanoSupported');
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
/** Compatibility stub: Cardano support is not implemented in this TypeScript iteration. */
|
|
414
|
+
async cardanoXpubs(_keypaths) {
|
|
415
|
+
this.#requireOpen('cardanoXpubs');
|
|
416
|
+
throw unsupportedError('cardanoXpubs');
|
|
417
|
+
}
|
|
418
|
+
/** Compatibility stub: Cardano support is not implemented in this TypeScript iteration. */
|
|
419
|
+
async cardanoAddress(_network, _script_config, _display) {
|
|
420
|
+
this.#requireOpen('cardanoAddress');
|
|
421
|
+
throw unsupportedError('cardanoAddress');
|
|
422
|
+
}
|
|
423
|
+
/** Compatibility stub: Cardano support is not implemented in this TypeScript iteration. */
|
|
424
|
+
async cardanoSignTransaction(_transaction) {
|
|
425
|
+
this.#requireOpen('cardanoSignTransaction');
|
|
426
|
+
throw unsupportedError('cardanoSignTransaction');
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Invokes the BIP85-BIP39 workflow on the device, letting the user select the number of words
|
|
430
|
+
* (12, 18, 24) and an index and display a derived BIP-39 mnemonic.
|
|
431
|
+
*
|
|
432
|
+
* Compatibility stub: BIP85 support is not implemented in this TypeScript iteration.
|
|
433
|
+
*/
|
|
434
|
+
async bip85AppBip39() {
|
|
435
|
+
this.#requireOpen('bip85AppBip39');
|
|
436
|
+
throw unsupportedError('bip85AppBip39');
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function makePairedBitBox(channel, info, close) {
|
|
440
|
+
return new PairedBitBox({ channel, info, close });
|
|
441
|
+
}
|
|
442
|
+
function bestEffortClose(close) {
|
|
443
|
+
try {
|
|
444
|
+
close();
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
// Swallow teardown errors so the original handshake/pairing failure
|
|
448
|
+
// remains the rejection reason.
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EACL,WAAW,EACX,aAAa,EACb,aAAa,GAEd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,WAAW,EACX,aAAa,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,UAAU,IAAI,cAAc,EAC5B,eAAe,IAAI,mBAAmB,GACvC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,UAAU,IAAI,cAAc,EAC5B,sBAAsB,IAAI,0BAA0B,EACpD,cAAc,IAAI,kBAAkB,EACpC,kBAAkB,IAAI,sBAAsB,EAC5C,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,MAAM,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IAC3C,CAAC;IAED,2FAA2F;IAC3F,KAAK,CAAC,sBAAsB,CAC1B,YAAgC;QAEhC,IAAI,CAAC,YAAY,CAAC,wBAAwB,CAAC,CAAC;QAC5C,MAAM,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa;QACjB,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;QACnC,MAAM,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAC1C,CAAC;CACF;AAED,SAAS,gBAAgB,CACvB,OAAyB,EACzB,IAAU,EACV,KAAiB;IAEjB,OAAO,IAAI,YAAY,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,eAAe,CAAC,KAAiB;IACxC,IAAI,CAAC;QACH,KAAK,EAAE,CAAC;IACV,CAAC;IAAC,MAAM,CAAC;QACP,oEAAoE;QACpE,gCAAgC;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-simulator.d.ts","sourceRoot":"","sources":["../../src/internal/connect-simulator.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Node-only, test-only entry point. Lives in its own module so the simulator
|
|
3
|
+
// transport (which imports `node:net`) is never reachable from the main
|
|
4
|
+
// `index.ts` dependency graph. Browser bundlers (webpack, Rollup, Vite) walk
|
|
5
|
+
// the static `import` graph from the package main; nothing here is touched
|
|
6
|
+
// unless a consumer explicitly imports this file.
|
|
7
|
+
import { FIRMWARE_CMD } from './constants.js';
|
|
8
|
+
import { openSession } from './connect.js';
|
|
9
|
+
import { U2fHidCommunication } from './hww.js';
|
|
10
|
+
import { NoiseConfigNoCache } from './noise-config.js';
|
|
11
|
+
import { openSimulator } from './transport-simulator.js';
|
|
12
|
+
/** @internal */
|
|
13
|
+
export async function connectSimulator(endpoint, onCloseCb, config = new NoiseConfigNoCache()) {
|
|
14
|
+
const session = await openSession((closeCb) => openSimulator(endpoint, closeCb), (lower) => new U2fHidCommunication(lower, FIRMWARE_CMD), onCloseCb);
|
|
15
|
+
return { ...session, config };
|
|
16
|
+
}
|
|
17
|
+
/** @internal */
|
|
18
|
+
export async function probeSimulatorInfo(endpoint, onCloseCb) {
|
|
19
|
+
const session = await openSession((closeCb) => openSimulator(endpoint, closeCb), (lower) => new U2fHidCommunication(lower, FIRMWARE_CMD), onCloseCb);
|
|
20
|
+
return {
|
|
21
|
+
info: session.hww.info,
|
|
22
|
+
close: session.close,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=connect-simulator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-simulator.js","sourceRoot":"","sources":["../../src/internal/connect-simulator.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,6EAA6E;AAC7E,wEAAwE;AACxE,6EAA6E;AAC7E,2EAA2E;AAC3E,kDAAkD;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAuB,MAAM,cAAc,CAAC;AAChE,OAAO,EAAa,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAoB,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAQzD,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAAiB,EACjB,SAAsB,EACtB,SAAsB,IAAI,kBAAkB,EAAE;IAE9C,MAAM,OAAO,GAAG,MAAM,WAAW,CAC/B,CAAC,OAAO,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,EAC7C,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,KAAK,EAAE,YAAY,CAAC,EACvD,SAAS,CACV,CAAC;IACF,OAAO,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC;AAChC,CAAC;AAED,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAAiB,EACjB,SAAsB;IAEtB,MAAM,OAAO,GAAG,MAAM,WAAW,CAC/B,CAAC,OAAO,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,EAC7C,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,KAAK,EAAE,YAAY,CAAC,EACvD,SAAS,CACV,CAAC;IACF,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI;QACtB,KAAK,EAAE,OAAO,CAAC,KAAK;KACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/internal/connect.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { FIRMWARE_CMD } from './constants.js';
|
|
3
|
+
import { HwwCommunication, U2fHidCommunication, U2fWsCommunication } from './hww.js';
|
|
4
|
+
import { defaultNoiseConfig } from './noise-config.js';
|
|
5
|
+
import { openBridge } from './transport-bridge.js';
|
|
6
|
+
import { openWebHID } from './transport-webhid.js';
|
|
7
|
+
const createHwwDefault = (comm) => HwwCommunication.create(comm);
|
|
8
|
+
/** @internal */
|
|
9
|
+
export async function openSession(openLower, wrapCommunication, onCloseCb, createHww = createHwwDefault) {
|
|
10
|
+
let armed = false;
|
|
11
|
+
const lower = await openLower(() => {
|
|
12
|
+
if (armed) {
|
|
13
|
+
onCloseCb?.();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
const hww = await createHww(wrapCommunication(lower));
|
|
18
|
+
armed = true;
|
|
19
|
+
return {
|
|
20
|
+
hww,
|
|
21
|
+
close() {
|
|
22
|
+
lower.close();
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
try {
|
|
28
|
+
lower.close();
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Preserve the original startup error if cleanup itself fails.
|
|
32
|
+
}
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** @internal */
|
|
37
|
+
export async function connectWebHID(onCloseCb) {
|
|
38
|
+
const session = await openSession(openWebHID, (lower) => new U2fHidCommunication(lower, FIRMWARE_CMD), onCloseCb);
|
|
39
|
+
return { ...session, config: defaultNoiseConfig() };
|
|
40
|
+
}
|
|
41
|
+
/** @internal */
|
|
42
|
+
export async function connectBridge(onCloseCb) {
|
|
43
|
+
const session = await openSession(openBridge, (lower) => new U2fWsCommunication(lower, FIRMWARE_CMD), onCloseCb);
|
|
44
|
+
return { ...session, config: defaultNoiseConfig() };
|
|
45
|
+
}
|
|
46
|
+
/** @internal */
|
|
47
|
+
export function connectAuto(onCloseCb) {
|
|
48
|
+
const nav = globalThis.navigator;
|
|
49
|
+
if (nav?.hid !== undefined) {
|
|
50
|
+
return connectWebHID(onCloseCb);
|
|
51
|
+
}
|
|
52
|
+
return connectBridge(onCloseCb);
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/internal/connect.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAoB,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAA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,KAAK,UAAU,aAAa,CAAC,SAAsB;IACxD,MAAM,OAAO,GAAG,MAAM,WAAW,CAC/B,UAAU,EACV,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,EACtD,SAAS,CACV,CAAC;IACF,OAAO,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,EAAE,CAAC;AACtD,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,WAAW,CAAC,SAAsB;IAChD,MAAM,GAAG,GAAI,UAAgD,CAAC,SAAS,CAAC;IACxE,IAAI,GAAG,EAAE,GAAG,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/internal/constants.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/** @internal */
|
|
3
|
+
export const VENDOR_ID = 0x03eb;
|
|
4
|
+
/** @internal */
|
|
5
|
+
export const PRODUCT_ID = 0x2403;
|
|
6
|
+
/** @internal */
|
|
7
|
+
export const FIRMWARE_CMD = 0x80 | 0x40 | 0x01;
|
|
8
|
+
/** @internal */
|
|
9
|
+
export const BRIDGE_BASE_URL = 'http://127.0.0.1:8178/api/v1';
|
|
10
|
+
/** @internal */
|
|
11
|
+
export const BRIDGE_WS_BASE_URL = 'ws://127.0.0.1:8178/api/v1/socket/';
|
|
12
|
+
/** @internal */
|
|
13
|
+
export const SIMULATOR_DEFAULT_ENDPOINT = '127.0.0.1:15423';
|
|
14
|
+
/** @internal */
|
|
15
|
+
export const BITBOX02_PRODUCT_PREFIX = 'BitBox02';
|
|
16
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/internal/constants.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,gBAAgB;AAChB,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC;AAChC,gBAAgB;AAChB,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC;AAEjC,gBAAgB;AAChB,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE/C,gBAAgB;AAChB,MAAM,CAAC,MAAM,eAAe,GAAG,8BAA8B,CAAC;AAC9D,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,oCAAoC,CAAC;AAEvE,gBAAgB;AAChB,MAAM,CAAC,MAAM,0BAA0B,GAAG,iBAAiB,CAAC;AAE5D,gBAAgB;AAChB,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DeviceInfo } from '../index.js';
|
|
2
|
+
import type { EncryptedChannel } from './pairing.js';
|
|
3
|
+
export declare function deviceInfo(channel: EncryptedChannel): Promise<DeviceInfo>;
|
|
4
|
+
export declare function rootFingerprint(channel: EncryptedChannel): Promise<string>;
|
|
5
|
+
//# sourceMappingURL=device.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/internal/device.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAI9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrD,wBAAsB,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAmB/E;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAWhF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { create } from '@bufbuild/protobuf';
|
|
3
|
+
import { bytesToHex } from '@noble/hashes/utils';
|
|
4
|
+
import { DeviceInfoRequestSchema } from '../proto/gen/bitbox02_system_pb.js';
|
|
5
|
+
import { RootFingerprintRequestSchema } from '../proto/gen/common_pb.js';
|
|
6
|
+
import { RequestSchema } from '../proto/gen/hww_pb.js';
|
|
7
|
+
import { query, unexpectedResponse } from './eth/query.js';
|
|
8
|
+
export async function deviceInfo(channel) {
|
|
9
|
+
const response = await query(channel, create(RequestSchema, {
|
|
10
|
+
request: {
|
|
11
|
+
case: 'deviceInfo',
|
|
12
|
+
value: create(DeviceInfoRequestSchema),
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
15
|
+
if (response.response.case !== 'deviceInfo') {
|
|
16
|
+
throw unexpectedResponse();
|
|
17
|
+
}
|
|
18
|
+
const value = response.response.value;
|
|
19
|
+
return {
|
|
20
|
+
name: value.name,
|
|
21
|
+
initialized: value.initialized,
|
|
22
|
+
version: value.version,
|
|
23
|
+
mnemonicPassphraseEnabled: value.mnemonicPassphraseEnabled,
|
|
24
|
+
securechipModel: value.securechipModel,
|
|
25
|
+
monotonicIncrementsRemaining: value.monotonicIncrementsRemaining,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export async function rootFingerprint(channel) {
|
|
29
|
+
const response = await query(channel, create(RequestSchema, {
|
|
30
|
+
request: {
|
|
31
|
+
case: 'fingerprint',
|
|
32
|
+
value: create(RootFingerprintRequestSchema),
|
|
33
|
+
},
|
|
34
|
+
}));
|
|
35
|
+
if (response.response.case !== 'fingerprint') {
|
|
36
|
+
throw unexpectedResponse();
|
|
37
|
+
}
|
|
38
|
+
return bytesToHex(response.response.value.fingerprint);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=device.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.js","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