@bitboxswiss/bitbox-api 0.1.0 → 0.2.0
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/CONTRIBUTING.md +4 -2
- package/README.md +69 -9
- package/dist/index.d.ts +337 -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/cardano/methods.d.ts +7 -0
- package/dist/internal/cardano/methods.d.ts.map +1 -0
- package/dist/internal/cardano/methods.js +199 -0
- package/dist/internal/cardano/methods.js.map +1 -0
- package/dist/internal/cardano/query.d.ts +4 -0
- package/dist/internal/cardano/query.d.ts.map +1 -0
- package/dist/internal/cardano/query.js +20 -0
- package/dist/internal/cardano/query.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/methods.d.ts +10 -0
- package/dist/internal/eth/methods.d.ts.map +1 -0
- package/dist/internal/eth/methods.js +245 -0
- package/dist/internal/eth/methods.js.map +1 -0
- package/dist/internal/eth/query.d.ts +4 -0
- package/dist/internal/eth/query.d.ts.map +1 -0
- package/dist/internal/eth/query.js +20 -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 +22 -0
- package/dist/internal/eth/streaming.js.map +1 -0
- package/dist/internal/eth/version.d.ts +2 -0
- package/dist/internal/eth/version.d.ts.map +1 -0
- package/dist/internal/eth/version.js +3 -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 +240 -0
- package/dist/internal/hww.js.map +1 -0
- package/dist/internal/keypath.d.ts +4 -0
- package/dist/internal/keypath.d.ts.map +1 -0
- package/dist/internal/keypath.js +47 -0
- package/dist/internal/keypath.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/proto-query.d.ts +5 -0
- package/dist/internal/proto-query.d.ts.map +1 -0
- package/dist/internal/proto-query.js +28 -0
- package/dist/internal/proto-query.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 +90 -0
- package/dist/internal/utils.js.map +1 -0
- package/dist/internal/version.d.ts +8 -0
- package/dist/internal/version.d.ts.map +1 -0
- package/dist/internal/version.js +9 -0
- package/dist/internal/version.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 { cardanoAddress as cardanoAddressImpl, cardanoSignTransaction as cardanoSignTransactionImpl, cardanoXpubs as cardanoXpubsImpl, } from './internal/cardano/methods.js';
|
|
6
|
+
import { ethAddress as ethAddressImpl, ethSign1559Transaction as ethSign1559TransactionImpl, ethSignMessage as ethSignMessageImpl, ethSignTransaction as ethSignTransactionImpl, ethSignTypedMessage as ethSignTypedMessageImpl, ethXpub as ethXpubImpl, } from './internal/eth/methods.js';
|
|
7
|
+
import { isMultiEdition } from './internal/hww.js';
|
|
8
|
+
import { completePairing, performHandshake, } from './internal/pairing.js';
|
|
9
|
+
function unsupportedError(method) {
|
|
10
|
+
return {
|
|
11
|
+
code: CODE_UNSUPPORTED,
|
|
12
|
+
message: `${method} is not supported in @bitboxswiss/bitbox-api`,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function notImplementedError(method) {
|
|
16
|
+
return {
|
|
17
|
+
code: CODE_NOT_IMPLEMENTED,
|
|
18
|
+
message: `${method} is not yet implemented in @bitboxswiss/bitbox-api`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function invalidStateError(method) {
|
|
22
|
+
return {
|
|
23
|
+
code: CODE_INVALID_STATE,
|
|
24
|
+
message: `${method}: object is not in a usable state (uninitialized, consumed, or closed)`,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Connect to a BitBox02 using WebHID.
|
|
29
|
+
*
|
|
30
|
+
* WebHID is available in Chromium-based browsers in secure contexts. Call this
|
|
31
|
+
* from a user action so the browser can show the device chooser.
|
|
32
|
+
*/
|
|
33
|
+
export async function bitbox02ConnectWebHID(onCloseCb) {
|
|
34
|
+
try {
|
|
35
|
+
return new BitBox(await connectWebHID(onCloseCb));
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
throw toPublicError(err);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Connect to a BitBox02 through the local BitBoxBridge service.
|
|
43
|
+
*/
|
|
44
|
+
export async function bitbox02ConnectBridge(onCloseCb) {
|
|
45
|
+
try {
|
|
46
|
+
return new BitBox(await connectBridge(onCloseCb));
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
throw toPublicError(err);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Connect to a BitBox02 using WebHID when available, otherwise BitBoxBridge.
|
|
54
|
+
*/
|
|
55
|
+
export async function bitbox02ConnectAuto(onCloseCb) {
|
|
56
|
+
try {
|
|
57
|
+
return new BitBox(await connectAuto(onCloseCb));
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
throw toPublicError(err);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Normalize any thrown value to the public typed error shape.
|
|
65
|
+
*
|
|
66
|
+
* If the input already looks like a typed `{ code: string, message: string }`, it is returned
|
|
67
|
+
* as-is. Otherwise it is wrapped as `{ code: 'unknown-js', message: 'Unknown Javascript error',
|
|
68
|
+
* err: <original> }`.
|
|
69
|
+
*/
|
|
70
|
+
export function ensureError(err) {
|
|
71
|
+
return ensureTyped(err);
|
|
72
|
+
}
|
|
73
|
+
/** Returns true if the user cancelled an operation. */
|
|
74
|
+
export function isUserAbort(err) {
|
|
75
|
+
return err.code === CODE_USER_ABORT || err.code === CODE_BITBOX_USER_ABORT;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Identifies the case of the recipient address given as hexadecimal string.
|
|
79
|
+
* Returns 'upper' if every alphabetic char is uppercase, 'lower' if every
|
|
80
|
+
* alphabetic char is lowercase, 'mixed' otherwise. Non-alphabetic characters
|
|
81
|
+
* are ignored.
|
|
82
|
+
*/
|
|
83
|
+
export function ethIdentifyCase(recipientAddress) {
|
|
84
|
+
let hasUpper = false;
|
|
85
|
+
let hasLower = false;
|
|
86
|
+
for (const c of recipientAddress) {
|
|
87
|
+
if (c >= 'A' && c <= 'Z') {
|
|
88
|
+
hasUpper = true;
|
|
89
|
+
}
|
|
90
|
+
else if (c >= 'a' && c <= 'z') {
|
|
91
|
+
hasLower = true;
|
|
92
|
+
}
|
|
93
|
+
if (hasUpper && hasLower) {
|
|
94
|
+
return 'mixed';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (hasLower) {
|
|
98
|
+
return 'lower';
|
|
99
|
+
}
|
|
100
|
+
return 'upper';
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Unpaired BitBox client.
|
|
104
|
+
*
|
|
105
|
+
* Create initialized instances with `bitbox02ConnectAuto()`, `bitbox02ConnectWebHID()`, or
|
|
106
|
+
* `bitbox02ConnectBridge()`. Direct constructors are retained for compatibility and create an
|
|
107
|
+
* inert object whose methods throw `code: 'invalid-state'`.
|
|
108
|
+
*/
|
|
109
|
+
export class BitBox {
|
|
110
|
+
#state = { kind: 'uninitialized' };
|
|
111
|
+
/** @internal */
|
|
112
|
+
constructor(session) {
|
|
113
|
+
if (session !== undefined) {
|
|
114
|
+
this.#state = {
|
|
115
|
+
kind: 'open',
|
|
116
|
+
hww: session.hww,
|
|
117
|
+
close: session.close,
|
|
118
|
+
config: session.config,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
#consumeOpen() {
|
|
123
|
+
const state = this.#state;
|
|
124
|
+
if (state.kind !== 'open') {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
this.#state = { kind: 'consumed' };
|
|
128
|
+
return state;
|
|
129
|
+
}
|
|
130
|
+
/** No-op; retained for ABI compatibility with the wasm-bindgen output. */
|
|
131
|
+
free() { }
|
|
132
|
+
/**
|
|
133
|
+
* Invokes the device unlock and pairing. After this, stop using this instance and continue
|
|
134
|
+
* with the returned instance of type `PairingBitBox`.
|
|
135
|
+
*
|
|
136
|
+
* This consumes the `BitBox` synchronously. A second call, including a concurrent call while
|
|
137
|
+
* the first is still running, rejects with `code: 'invalid-state'`. If pairing setup fails, the
|
|
138
|
+
* transport is closed and callers must reconnect before retrying.
|
|
139
|
+
*/
|
|
140
|
+
async unlockAndPair() {
|
|
141
|
+
const open = this.#consumeOpen();
|
|
142
|
+
if (open === undefined) {
|
|
143
|
+
throw invalidStateError('unlockAndPair');
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const pairing = await performHandshake(open.hww, open.config);
|
|
147
|
+
return makePairingBitBox(pairing, open.close);
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
bestEffortClose(open.close);
|
|
151
|
+
throw toPublicError(err);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* BitBox in the pairing state. Use `getPairingCode()` to display the pairing code to the user and
|
|
157
|
+
* `waitConfirm()` to proceed to the paired state. Direct constructors create an inert object.
|
|
158
|
+
*/
|
|
159
|
+
export class PairingBitBox {
|
|
160
|
+
#state = { kind: 'uninitialized' };
|
|
161
|
+
/** @internal */
|
|
162
|
+
constructor(init) {
|
|
163
|
+
if (init !== undefined) {
|
|
164
|
+
this.#state = { kind: 'open', ...init };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
#readOpen() {
|
|
168
|
+
return this.#state.kind === 'open' ? this.#state : undefined;
|
|
169
|
+
}
|
|
170
|
+
#consumeOpen() {
|
|
171
|
+
const state = this.#state;
|
|
172
|
+
if (state.kind !== 'open') {
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
this.#state = { kind: 'consumed' };
|
|
176
|
+
return state;
|
|
177
|
+
}
|
|
178
|
+
/** No-op; retained for ABI compatibility with the wasm-bindgen output. */
|
|
179
|
+
free() { }
|
|
180
|
+
/**
|
|
181
|
+
* If a pairing code confirmation is required, this returns the pairing code. You must display
|
|
182
|
+
* it to the user and then call `waitConfirm()` to wait until the user confirms the code on
|
|
183
|
+
* the BitBox.
|
|
184
|
+
*
|
|
185
|
+
* If the BitBox was paired before and the pairing was persisted, the pairing step is
|
|
186
|
+
* skipped. In this case, `undefined` is returned. Also in this case, call `waitConfirm()` to
|
|
187
|
+
* establish the encrypted connection.
|
|
188
|
+
*
|
|
189
|
+
* Call this before `waitConfirm()`, because `waitConfirm()` consumes the pairing object.
|
|
190
|
+
*/
|
|
191
|
+
getPairingCode() {
|
|
192
|
+
const open = this.#readOpen();
|
|
193
|
+
if (open === undefined) {
|
|
194
|
+
throw invalidStateError('getPairingCode');
|
|
195
|
+
}
|
|
196
|
+
return open.state.pairingCode;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Proceed to the paired state. After this, stop using this instance and continue with the
|
|
200
|
+
* returned instance of type `PairedBitBox`.
|
|
201
|
+
*
|
|
202
|
+
* This consumes the `PairingBitBox` synchronously. A second call, including a concurrent call
|
|
203
|
+
* while the first is still running, rejects with `code: 'invalid-state'`. If confirmation fails,
|
|
204
|
+
* the transport is closed and callers must reconnect before retrying.
|
|
205
|
+
*/
|
|
206
|
+
async waitConfirm() {
|
|
207
|
+
const open = this.#consumeOpen();
|
|
208
|
+
if (open === undefined) {
|
|
209
|
+
throw invalidStateError('waitConfirm');
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
const channel = await completePairing(open.state);
|
|
213
|
+
return makePairedBitBox(channel, open.state.hww.info, open.close);
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
bestEffortClose(open.close);
|
|
217
|
+
throw toPublicError(err);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function makePairingBitBox(state, close) {
|
|
222
|
+
return new PairingBitBox({ state, close });
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Paired BitBox. This is where you can invoke most API functions like getting xpubs, displaying
|
|
226
|
+
* receive addresses, and signing transactions. Direct constructors create an inert object.
|
|
227
|
+
*/
|
|
228
|
+
export class PairedBitBox {
|
|
229
|
+
#state = { kind: 'uninitialized' };
|
|
230
|
+
#queue = Promise.resolve();
|
|
231
|
+
/** @internal */
|
|
232
|
+
constructor(init) {
|
|
233
|
+
if (init !== undefined) {
|
|
234
|
+
this.#state = { kind: 'open', ...init };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
#requireOpen(method) {
|
|
238
|
+
if (this.#state.kind !== 'open') {
|
|
239
|
+
throw invalidStateError(method);
|
|
240
|
+
}
|
|
241
|
+
return this.#state;
|
|
242
|
+
}
|
|
243
|
+
#closeOpen() {
|
|
244
|
+
const state = this.#state;
|
|
245
|
+
if (state.kind !== 'open') {
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
this.#state = { kind: 'closed' };
|
|
249
|
+
return state;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Serializes all device-touching public methods on this paired connection.
|
|
253
|
+
*
|
|
254
|
+
* The BitBox protocol and Noise channel are ordered streams, not multiplexed
|
|
255
|
+
* request/response transports. Some public methods also perform multi-step
|
|
256
|
+
* conversations (for example ETH streaming or anti-klepto signing), so the
|
|
257
|
+
* lock must cover the whole public method, not only one encrypted query.
|
|
258
|
+
*
|
|
259
|
+
* Calls made after close fail before joining the queue, so they do not wait
|
|
260
|
+
* behind a stuck transport read. The open state is checked again when the
|
|
261
|
+
* queued operation starts, so calls queued before close still fail if they
|
|
262
|
+
* did not already enter the device conversation.
|
|
263
|
+
*
|
|
264
|
+
* Each call chains onto the previous queue tail and then replaces the tail
|
|
265
|
+
* with a settled `void` promise, so a rejected call does not poison later
|
|
266
|
+
* queued operations.
|
|
267
|
+
*/
|
|
268
|
+
#runExclusive(method, fn) {
|
|
269
|
+
this.#requireOpen(method);
|
|
270
|
+
const run = this.#queue.catch(() => undefined).then(async () => {
|
|
271
|
+
const open = this.#requireOpen(method);
|
|
272
|
+
try {
|
|
273
|
+
return await fn(open);
|
|
274
|
+
}
|
|
275
|
+
catch (err) {
|
|
276
|
+
throw toPublicError(err);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
this.#queue = run.then(() => undefined, () => undefined);
|
|
280
|
+
return run;
|
|
281
|
+
}
|
|
282
|
+
/** No-op; retained for ABI compatibility with the wasm-bindgen output. */
|
|
283
|
+
free() { }
|
|
284
|
+
/**
|
|
285
|
+
* Closes the BitBox connection. This also invokes the `on_close_cb` callback which was
|
|
286
|
+
* provided to the connect method creating the connection. Idempotent: calling close() on an
|
|
287
|
+
* already-closed or uninitialized instance is a no-op.
|
|
288
|
+
*
|
|
289
|
+
* After `close()`, all other methods throw `code: 'invalid-state'`.
|
|
290
|
+
*/
|
|
291
|
+
close() {
|
|
292
|
+
const open = this.#closeOpen();
|
|
293
|
+
if (open === undefined) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
open.close();
|
|
297
|
+
}
|
|
298
|
+
/** Query device metadata. */
|
|
299
|
+
async deviceInfo() {
|
|
300
|
+
return this.#runExclusive('deviceInfo', open => deviceInfoImpl(open.channel));
|
|
301
|
+
}
|
|
302
|
+
/** Returns which product we are connected to. */
|
|
303
|
+
product() {
|
|
304
|
+
return this.#requireOpen('product').info.product;
|
|
305
|
+
}
|
|
306
|
+
/** Returns the firmware version, e.g. "9.18.0". */
|
|
307
|
+
version() {
|
|
308
|
+
return this.#requireOpen('version').info.version;
|
|
309
|
+
}
|
|
310
|
+
/** Returns the hex-encoded 4-byte root fingerprint. */
|
|
311
|
+
async rootFingerprint() {
|
|
312
|
+
return this.#runExclusive('rootFingerprint', open => rootFingerprintImpl(open.channel));
|
|
313
|
+
}
|
|
314
|
+
/** Not implemented in this TypeScript iteration. */
|
|
315
|
+
async showMnemonic() {
|
|
316
|
+
this.#requireOpen('showMnemonic');
|
|
317
|
+
throw notImplementedError('showMnemonic');
|
|
318
|
+
}
|
|
319
|
+
/** Not implemented in this TypeScript iteration. */
|
|
320
|
+
async changePassword() {
|
|
321
|
+
this.#requireOpen('changePassword');
|
|
322
|
+
throw notImplementedError('changePassword');
|
|
323
|
+
}
|
|
324
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
325
|
+
async btcXpub(_coin, _keypath, _xpub_type, _display) {
|
|
326
|
+
this.#requireOpen('btcXpub');
|
|
327
|
+
throw unsupportedError('btcXpub');
|
|
328
|
+
}
|
|
329
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
330
|
+
async btcXpubs(_coin, _keypaths, _xpub_type) {
|
|
331
|
+
this.#requireOpen('btcXpubs');
|
|
332
|
+
throw unsupportedError('btcXpubs');
|
|
333
|
+
}
|
|
334
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
335
|
+
async btcIsScriptConfigRegistered(_coin, _script_config, _keypath_account) {
|
|
336
|
+
this.#requireOpen('btcIsScriptConfigRegistered');
|
|
337
|
+
throw unsupportedError('btcIsScriptConfigRegistered');
|
|
338
|
+
}
|
|
339
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
340
|
+
async btcRegisterScriptConfig(_coin, _script_config, _keypath_account, _xpub_type, _name) {
|
|
341
|
+
this.#requireOpen('btcRegisterScriptConfig');
|
|
342
|
+
throw unsupportedError('btcRegisterScriptConfig');
|
|
343
|
+
}
|
|
344
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
345
|
+
async btcAddress(_coin, _keypath, _script_config, _display) {
|
|
346
|
+
this.#requireOpen('btcAddress');
|
|
347
|
+
throw unsupportedError('btcAddress');
|
|
348
|
+
}
|
|
349
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
350
|
+
async btcSignPSBT(_coin, _psbt, _force_script_config, _format_unit) {
|
|
351
|
+
this.#requireOpen('btcSignPSBT');
|
|
352
|
+
throw unsupportedError('btcSignPSBT');
|
|
353
|
+
}
|
|
354
|
+
/** Compatibility stub: Bitcoin support is not implemented in this TypeScript iteration. */
|
|
355
|
+
async btcSignMessage(_coin, _script_config, _msg) {
|
|
356
|
+
this.#requireOpen('btcSignMessage');
|
|
357
|
+
throw unsupportedError('btcSignMessage');
|
|
358
|
+
}
|
|
359
|
+
/** Does this device support ETH functionality? Currently this means BitBox02 Multi or Nova Multi. */
|
|
360
|
+
ethSupported() {
|
|
361
|
+
return isMultiEdition(this.#requireOpen('ethSupported').info);
|
|
362
|
+
}
|
|
363
|
+
/** Query the device for an Ethereum account xpub. */
|
|
364
|
+
async ethXpub(keypath) {
|
|
365
|
+
return this.#runExclusive('ethXpub', open => ethXpubImpl(open.channel, keypath));
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Query the device for an Ethereum address.
|
|
369
|
+
*
|
|
370
|
+
* Set `display` to `true` to require on-device confirmation.
|
|
371
|
+
*/
|
|
372
|
+
async ethAddress(chain_id, keypath, display) {
|
|
373
|
+
return this.#runExclusive('ethAddress', open => ethAddressImpl(open.channel, chain_id, keypath, display));
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Sign a legacy Ethereum transaction.
|
|
377
|
+
*
|
|
378
|
+
* Transaction fields are unsigned big-endian byte arrays. The returned `v` includes the EIP-155
|
|
379
|
+
* chain ID offset.
|
|
380
|
+
*/
|
|
381
|
+
async ethSignTransaction(chain_id, keypath, tx, address_case) {
|
|
382
|
+
return this.#runExclusive('ethSignTransaction', open => ethSignTransactionImpl(open.channel, open.info, chain_id, keypath, tx, address_case));
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Sign an EIP-1559 type 2 Ethereum transaction.
|
|
386
|
+
*
|
|
387
|
+
* Transaction fields are unsigned big-endian byte arrays. The returned `v` is the recovery ID.
|
|
388
|
+
*/
|
|
389
|
+
async ethSign1559Transaction(keypath, tx, address_case) {
|
|
390
|
+
return this.#runExclusive('ethSign1559Transaction', open => ethSign1559TransactionImpl(open.channel, open.info, keypath, tx, address_case));
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Sign an Ethereum personal message.
|
|
394
|
+
*
|
|
395
|
+
* The device applies the standard Ethereum message prefix before signing. The returned `v`
|
|
396
|
+
* includes the +27 offset.
|
|
397
|
+
*/
|
|
398
|
+
async ethSignMessage(chain_id, keypath, msg) {
|
|
399
|
+
return this.#runExclusive('ethSignMessage', open => ethSignMessageImpl(open.channel, open.info, chain_id, keypath, msg));
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Sign an EIP-712 typed message.
|
|
403
|
+
*
|
|
404
|
+
* `use_antiklepto` defaults to `true` when omitted.
|
|
405
|
+
*/
|
|
406
|
+
async ethSignTypedMessage(chain_id, keypath, msg, use_antiklepto) {
|
|
407
|
+
return this.#runExclusive('ethSignTypedMessage', open => ethSignTypedMessageImpl(open.channel, open.info, chain_id, keypath, msg, use_antiklepto));
|
|
408
|
+
}
|
|
409
|
+
/** Does this device support Cardano functionality? Currently this means BitBox02 Multi or Nova Multi. */
|
|
410
|
+
cardanoSupported() {
|
|
411
|
+
return isMultiEdition(this.#requireOpen('cardanoSupported').info);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Query the device for xpubs. The result contains one xpub per requested keypath. Each xpub is
|
|
415
|
+
* 64 bytes: 32 byte chain code + 32 byte pubkey.
|
|
416
|
+
*/
|
|
417
|
+
async cardanoXpubs(keypaths) {
|
|
418
|
+
return this.#runExclusive('cardanoXpubs', open => cardanoXpubsImpl(open.channel, open.info, keypaths));
|
|
419
|
+
}
|
|
420
|
+
/** Query the device for a Cardano address. */
|
|
421
|
+
async cardanoAddress(network, script_config, display) {
|
|
422
|
+
return this.#runExclusive('cardanoAddress', open => cardanoAddressImpl(open.channel, open.info, network, script_config, display));
|
|
423
|
+
}
|
|
424
|
+
/** Sign a Cardano transaction. */
|
|
425
|
+
async cardanoSignTransaction(transaction) {
|
|
426
|
+
return this.#runExclusive('cardanoSignTransaction', open => cardanoSignTransactionImpl(open.channel, open.info, transaction));
|
|
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,cAAc,IAAI,kBAAkB,EACpC,sBAAsB,IAAI,0BAA0B,EACpD,YAAY,IAAI,gBAAgB,GACjC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,UAAU,IAAI,cAAc,EAC5B,sBAAsB,IAAI,0BAA0B,EACpD,cAAc,IAAI,kBAAkB,EACpC,kBAAkB,IAAI,sBAAsB,EAC5C,mBAAmB,IAAI,uBAAuB,EAC9C,OAAO,IAAI,WAAW,GACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAoC,MAAM,mBAAmB,CAAC;AAErF,OAAO,EACL,eAAe,EACf,gBAAgB,GAGjB,MAAM,uBAAuB,CAAC;AAE/B,SAAS,gBAAgB,CAAC,MAAc;IACtC,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,GAAG,MAAM,8CAA8C;KACjE,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAc;IACzC,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,GAAG,MAAM,oDAAoD;KACvE,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;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AY,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,7 @@
|
|
|
1
|
+
import type { CardanoNetwork, CardanoScriptConfig, CardanoSignTransactionResult, CardanoTransaction, CardanoXpubs, Keypath } from '../../index.js';
|
|
2
|
+
import type { Info } from '../hww.js';
|
|
3
|
+
import type { EncryptedChannel } from '../pairing.js';
|
|
4
|
+
export declare function cardanoXpubs(channel: EncryptedChannel, info: Info, keypaths: Keypath[]): Promise<CardanoXpubs>;
|
|
5
|
+
export declare function cardanoAddress(channel: EncryptedChannel, info: Info, network: CardanoNetwork, scriptConfig: CardanoScriptConfig, display: boolean): Promise<string>;
|
|
6
|
+
export declare function cardanoSignTransaction(channel: EncryptedChannel, info: Info, transaction: CardanoTransaction): Promise<CardanoSignTransactionResult>;
|
|
7
|
+
//# sourceMappingURL=methods.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"methods.d.ts","sourceRoot":"","sources":["../../../src/internal/cardano/methods.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAMV,cAAc,EAEd,mBAAmB,EACnB,4BAA4B,EAC5B,kBAAkB,EAElB,YAAY,EACZ,OAAO,EACR,MAAM,gBAAgB,CAAC;AAwBxB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAkKtD,wBAAsB,YAAY,CAChC,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,OAAO,EAAE,GAClB,OAAO,CAAC,YAAY,CAAC,CAYvB;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,EACvB,YAAY,EAAE,mBAAmB,EACjC,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,CAAC,CAcjB;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,kBAAkB,GAC9B,OAAO,CAAC,4BAA4B,CAAC,CAmBvC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { create } from '@bufbuild/protobuf';
|
|
3
|
+
import { KeypathSchema, } from '../../proto/gen/common_pb.js';
|
|
4
|
+
import { CardanoAddressRequestSchema, CardanoNetwork as PbCardanoNetwork, CardanoScriptConfigSchema, CardanoScriptConfig_PkhSkhSchema, CardanoSignTransactionRequestSchema, CardanoSignTransactionRequest_AssetGroupSchema, CardanoSignTransactionRequest_AssetGroup_TokenSchema, CardanoSignTransactionRequest_CertificateSchema, CardanoSignTransactionRequest_Certificate_StakeDelegationSchema, CardanoSignTransactionRequest_Certificate_VoteDelegationSchema, CardanoSignTransactionRequest_Certificate_VoteDelegation_CardanoDRepType as PbDRepType, CardanoSignTransactionRequest_InputSchema, CardanoSignTransactionRequest_OutputSchema, CardanoSignTransactionRequest_WithdrawalSchema, CardanoXpubsRequestSchema, } from '../../proto/gen/cardano_pb.js';
|
|
5
|
+
import { invalidTypeError } from '../errors.js';
|
|
6
|
+
import { unexpectedResponse } from '../proto-query.js';
|
|
7
|
+
import { parseKeypath } from '../keypath.js';
|
|
8
|
+
import { validateUint32, validateUint64 } from '../utils.js';
|
|
9
|
+
import { requireVersion } from '../version.js';
|
|
10
|
+
import { queryCardano } from './query.js';
|
|
11
|
+
const CARDANO_TRANSACTION_DETAIL = 'wrong type for CardanoTransaction';
|
|
12
|
+
function mapNetwork(network) {
|
|
13
|
+
switch (network) {
|
|
14
|
+
case 'mainnet':
|
|
15
|
+
return PbCardanoNetwork.CardanoMainnet;
|
|
16
|
+
case 'testnet':
|
|
17
|
+
return PbCardanoNetwork.CardanoTestnet;
|
|
18
|
+
default:
|
|
19
|
+
throw invalidTypeError('wrong type for CardanoNetwork');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function mapScriptConfig(config) {
|
|
23
|
+
return create(CardanoScriptConfigSchema, {
|
|
24
|
+
config: {
|
|
25
|
+
case: 'pkhSkh',
|
|
26
|
+
value: create(CardanoScriptConfig_PkhSkhSchema, {
|
|
27
|
+
keypathPayment: parseKeypath(config.pkhSkh.keypathPayment),
|
|
28
|
+
keypathStake: parseKeypath(config.pkhSkh.keypathStake),
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function mapDrepType(value) {
|
|
34
|
+
switch (value) {
|
|
35
|
+
case 'keyHash':
|
|
36
|
+
return PbDRepType.KEY_HASH;
|
|
37
|
+
case 'scriptHash':
|
|
38
|
+
return PbDRepType.SCRIPT_HASH;
|
|
39
|
+
case 'alwaysAbstain':
|
|
40
|
+
return PbDRepType.ALWAYS_ABSTAIN;
|
|
41
|
+
case 'alwaysNoConfidence':
|
|
42
|
+
return PbDRepType.ALWAYS_NO_CONFIDENCE;
|
|
43
|
+
default:
|
|
44
|
+
throw invalidTypeError('wrong type for CardanoDrepType');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function mapKeypathMessage(keypath) {
|
|
48
|
+
return create(KeypathSchema, {
|
|
49
|
+
keypath: parseKeypath(keypath),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function mapCertificate(cert) {
|
|
53
|
+
if ('stakeRegistration' in cert) {
|
|
54
|
+
return create(CardanoSignTransactionRequest_CertificateSchema, {
|
|
55
|
+
cert: {
|
|
56
|
+
case: 'stakeRegistration',
|
|
57
|
+
value: mapKeypathMessage(cert.stakeRegistration.keypath),
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if ('stakeDeregistration' in cert) {
|
|
62
|
+
return create(CardanoSignTransactionRequest_CertificateSchema, {
|
|
63
|
+
cert: {
|
|
64
|
+
case: 'stakeDeregistration',
|
|
65
|
+
value: mapKeypathMessage(cert.stakeDeregistration.keypath),
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if ('stakeDelegation' in cert) {
|
|
70
|
+
return create(CardanoSignTransactionRequest_CertificateSchema, {
|
|
71
|
+
cert: {
|
|
72
|
+
case: 'stakeDelegation',
|
|
73
|
+
value: create(CardanoSignTransactionRequest_Certificate_StakeDelegationSchema, {
|
|
74
|
+
keypath: parseKeypath(cert.stakeDelegation.keypath),
|
|
75
|
+
poolKeyhash: cert.stakeDelegation.poolKeyhash,
|
|
76
|
+
}),
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if ('voteDelegation' in cert) {
|
|
81
|
+
const voteDelegation = cert.voteDelegation;
|
|
82
|
+
const value = {
|
|
83
|
+
keypath: parseKeypath(voteDelegation.keypath),
|
|
84
|
+
type: mapDrepType(voteDelegation.type),
|
|
85
|
+
...(voteDelegation.drepCredhash === undefined
|
|
86
|
+
? {}
|
|
87
|
+
: { drepCredhash: voteDelegation.drepCredhash }),
|
|
88
|
+
};
|
|
89
|
+
return create(CardanoSignTransactionRequest_CertificateSchema, {
|
|
90
|
+
cert: {
|
|
91
|
+
case: 'voteDelegation',
|
|
92
|
+
value: create(CardanoSignTransactionRequest_Certificate_VoteDelegationSchema, value),
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
throw invalidTypeError('wrong type for CardanoCertificate');
|
|
97
|
+
}
|
|
98
|
+
function mapInput(input) {
|
|
99
|
+
return create(CardanoSignTransactionRequest_InputSchema, {
|
|
100
|
+
keypath: parseKeypath(input.keypath),
|
|
101
|
+
prevOutHash: input.prevOutHash,
|
|
102
|
+
prevOutIndex: validateUint32(input.prevOutIndex, CARDANO_TRANSACTION_DETAIL),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function mapToken(token) {
|
|
106
|
+
return create(CardanoSignTransactionRequest_AssetGroup_TokenSchema, {
|
|
107
|
+
assetName: token.assetName,
|
|
108
|
+
value: validateUint64(token.value, CARDANO_TRANSACTION_DETAIL),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function mapAssetGroup(assetGroup) {
|
|
112
|
+
return create(CardanoSignTransactionRequest_AssetGroupSchema, {
|
|
113
|
+
policyId: assetGroup.policyId,
|
|
114
|
+
tokens: assetGroup.tokens.map(mapToken),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function mapOutput(output) {
|
|
118
|
+
return create(CardanoSignTransactionRequest_OutputSchema, {
|
|
119
|
+
encodedAddress: output.encodedAddress,
|
|
120
|
+
value: validateUint64(output.value, CARDANO_TRANSACTION_DETAIL),
|
|
121
|
+
assetGroups: output.assetGroups?.map(mapAssetGroup) ?? [],
|
|
122
|
+
...(output.scriptConfig === undefined
|
|
123
|
+
? {}
|
|
124
|
+
: { scriptConfig: mapScriptConfig(output.scriptConfig) }),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function mapWithdrawal(withdrawal) {
|
|
128
|
+
return create(CardanoSignTransactionRequest_WithdrawalSchema, {
|
|
129
|
+
keypath: parseKeypath(withdrawal.keypath),
|
|
130
|
+
value: validateUint64(withdrawal.value, CARDANO_TRANSACTION_DETAIL),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function mapTransaction(transaction) {
|
|
134
|
+
return create(CardanoSignTransactionRequestSchema, {
|
|
135
|
+
network: mapNetwork(transaction.network),
|
|
136
|
+
inputs: transaction.inputs.map(mapInput),
|
|
137
|
+
outputs: transaction.outputs.map(mapOutput),
|
|
138
|
+
fee: validateUint64(transaction.fee, CARDANO_TRANSACTION_DETAIL),
|
|
139
|
+
ttl: validateUint64(transaction.ttl, CARDANO_TRANSACTION_DETAIL),
|
|
140
|
+
certificates: transaction.certificates.map(mapCertificate),
|
|
141
|
+
withdrawals: transaction.withdrawals.map(mapWithdrawal),
|
|
142
|
+
validityIntervalStart: validateUint64(transaction.validityIntervalStart, CARDANO_TRANSACTION_DETAIL),
|
|
143
|
+
allowZeroTtl: transaction.allowZeroTTL,
|
|
144
|
+
tagCborSets: transaction.tagCborSets,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
function requireCardanoVersion(info) {
|
|
148
|
+
requireVersion(info, { major: 9, minor: 8, patch: 0 });
|
|
149
|
+
}
|
|
150
|
+
export async function cardanoXpubs(channel, info, keypaths) {
|
|
151
|
+
requireCardanoVersion(info);
|
|
152
|
+
const response = await queryCardano(channel, {
|
|
153
|
+
case: 'xpubs',
|
|
154
|
+
value: create(CardanoXpubsRequestSchema, {
|
|
155
|
+
keypaths: keypaths.map(mapKeypathMessage),
|
|
156
|
+
}),
|
|
157
|
+
});
|
|
158
|
+
if (response.case !== 'xpubs') {
|
|
159
|
+
throw unexpectedResponse();
|
|
160
|
+
}
|
|
161
|
+
return response.value.xpubs.map(bytes => Array.from(bytes));
|
|
162
|
+
}
|
|
163
|
+
export async function cardanoAddress(channel, info, network, scriptConfig, display) {
|
|
164
|
+
requireCardanoVersion(info);
|
|
165
|
+
const response = await queryCardano(channel, {
|
|
166
|
+
case: 'address',
|
|
167
|
+
value: create(CardanoAddressRequestSchema, {
|
|
168
|
+
network: mapNetwork(network),
|
|
169
|
+
scriptConfig: mapScriptConfig(scriptConfig),
|
|
170
|
+
display,
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
if (response.case !== 'pub') {
|
|
174
|
+
throw unexpectedResponse();
|
|
175
|
+
}
|
|
176
|
+
return response.value.pub;
|
|
177
|
+
}
|
|
178
|
+
export async function cardanoSignTransaction(channel, info, transaction) {
|
|
179
|
+
if (transaction.tagCborSets) {
|
|
180
|
+
requireVersion(info, { major: 9, minor: 22, patch: 0 });
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
requireCardanoVersion(info);
|
|
184
|
+
}
|
|
185
|
+
const response = await queryCardano(channel, {
|
|
186
|
+
case: 'signTransaction',
|
|
187
|
+
value: mapTransaction(transaction),
|
|
188
|
+
});
|
|
189
|
+
if (response.case !== 'signTransaction') {
|
|
190
|
+
throw unexpectedResponse();
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
shelleyWitnesses: response.value.shelleyWitnesses.map(witness => ({
|
|
194
|
+
publicKey: Array.from(witness.publicKey),
|
|
195
|
+
signature: Array.from(witness.signature),
|
|
196
|
+
})),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=methods.js.map
|