@shapeshiftoss/hdwallet-keepkey 1.62.41 → 1.62.42
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/LICENSE.md +6 -6
- package/dist/cjs/.tsbuildinfo +1 -0
- package/dist/{adapter.d.ts → cjs/adapter.d.ts} +6 -7
- package/dist/cjs/adapter.js +146 -0
- package/dist/{binance.d.ts → cjs/binance.d.ts} +3 -4
- package/dist/cjs/binance.js +144 -0
- package/dist/{bitcoin.d.ts → cjs/bitcoin.d.ts} +3 -4
- package/dist/cjs/bitcoin.js +549 -0
- package/dist/{bnbencoding.d.ts → cjs/bnbencoding.d.ts} +3 -2
- package/dist/{bnbencoding.js → cjs/bnbencoding.js} +22 -22
- package/dist/{cosmos.d.ts → cjs/cosmos.d.ts} +4 -5
- package/dist/cjs/cosmos.js +219 -0
- package/dist/{eos.d.ts → cjs/eos.d.ts} +3 -4
- package/dist/cjs/eos.js +244 -0
- package/dist/{ethereum.d.ts → cjs/ethereum.d.ts} +4 -5
- package/dist/cjs/ethereum.js +264 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/{index.js → cjs/index.js} +0 -1
- package/dist/{keepkey.d.ts → cjs/keepkey.d.ts} +45 -20
- package/dist/cjs/keepkey.js +959 -0
- package/dist/{mayachain.d.ts → cjs/mayachain.d.ts} +4 -5
- package/dist/cjs/mayachain.js +169 -0
- package/dist/{osmosis.d.ts → cjs/osmosis.d.ts} +4 -5
- package/dist/cjs/osmosis.js +270 -0
- package/dist/cjs/package.json +1 -0
- package/dist/{ripple.d.ts → cjs/ripple.d.ts} +3 -4
- package/dist/cjs/ripple.js +104 -0
- package/dist/{thorchain.d.ts → cjs/thorchain.d.ts} +4 -5
- package/dist/cjs/thorchain.js +169 -0
- package/dist/{transport.d.ts → cjs/transport.d.ts} +2 -3
- package/dist/cjs/transport.js +333 -0
- package/dist/{typeRegistry.d.ts → cjs/typeRegistry.d.ts} +2 -3
- package/dist/{typeRegistry.js → cjs/typeRegistry.js} +26 -13
- package/dist/{utils.d.ts → cjs/utils.d.ts} +1 -2
- package/dist/{utils.js → cjs/utils.js} +7 -8
- package/dist/esm/.tsbuildinfo +1 -0
- package/dist/esm/adapter.d.ts +35 -0
- package/dist/esm/adapter.js +119 -0
- package/dist/esm/binance.d.ts +5 -0
- package/dist/esm/binance.js +112 -0
- package/dist/esm/bitcoin.d.ts +11 -0
- package/dist/esm/bitcoin.js +511 -0
- package/dist/esm/bnbencoding.d.ts +11 -0
- package/dist/esm/bnbencoding.js +103 -0
- package/dist/esm/cosmos.d.ts +6 -0
- package/dist/esm/cosmos.js +187 -0
- package/dist/esm/eos.d.ts +5 -0
- package/dist/esm/eos.js +212 -0
- package/dist/esm/ethereum.d.ts +17 -0
- package/dist/esm/ethereum.js +229 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/keepkey.d.ts +177 -0
- package/dist/esm/keepkey.js +925 -0
- package/dist/esm/mayachain.d.ts +6 -0
- package/dist/esm/mayachain.js +137 -0
- package/dist/esm/osmosis.d.ts +6 -0
- package/dist/esm/osmosis.js +238 -0
- package/dist/esm/ripple.d.ts +5 -0
- package/dist/esm/ripple.js +72 -0
- package/dist/esm/thorchain.d.ts +6 -0
- package/dist/esm/thorchain.js +137 -0
- package/dist/esm/transport.d.ts +55 -0
- package/dist/esm/transport.js +306 -0
- package/dist/esm/typeRegistry.d.ts +4 -0
- package/dist/esm/typeRegistry.js +47 -0
- package/dist/esm/utils.d.ts +6 -0
- package/dist/esm/utils.js +56 -0
- package/package.json +33 -19
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js +0 -175
- package/dist/adapter.js.map +0 -1
- package/dist/binance.d.ts.map +0 -1
- package/dist/binance.js +0 -146
- package/dist/binance.js.map +0 -1
- package/dist/bitcoin.d.ts.map +0 -1
- package/dist/bitcoin.js +0 -568
- package/dist/bitcoin.js.map +0 -1
- package/dist/bnbencoding.d.ts.map +0 -1
- package/dist/bnbencoding.js.map +0 -1
- package/dist/cosmos.d.ts.map +0 -1
- package/dist/cosmos.js +0 -230
- package/dist/cosmos.js.map +0 -1
- package/dist/eos.d.ts.map +0 -1
- package/dist/eos.js +0 -247
- package/dist/eos.js.map +0 -1
- package/dist/ethereum.d.ts.map +0 -1
- package/dist/ethereum.js +0 -281
- package/dist/ethereum.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keepkey.d.ts.map +0 -1
- package/dist/keepkey.js +0 -1027
- package/dist/keepkey.js.map +0 -1
- package/dist/mayachain.d.ts.map +0 -1
- package/dist/mayachain.js +0 -180
- package/dist/mayachain.js.map +0 -1
- package/dist/osmosis.d.ts.map +0 -1
- package/dist/osmosis.js +0 -278
- package/dist/osmosis.js.map +0 -1
- package/dist/ripple.d.ts.map +0 -1
- package/dist/ripple.js +0 -111
- package/dist/ripple.js.map +0 -1
- package/dist/thorchain.d.ts.map +0 -1
- package/dist/thorchain.js +0 -180
- package/dist/thorchain.js.map +0 -1
- package/dist/transport.d.ts.map +0 -1
- package/dist/transport.js +0 -365
- package/dist/transport.js.map +0 -1
- package/dist/typeRegistry.d.ts.map +0 -1
- package/dist/typeRegistry.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import * as Messages from '@keepkey/device-protocol/lib/messages_pb';
|
|
2
|
+
import * as Types from '@keepkey/device-protocol/lib/types_pb';
|
|
3
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
4
|
+
import * as crypto from 'crypto';
|
|
5
|
+
import * as jspb from 'google-protobuf';
|
|
6
|
+
import { messageNameRegistry, messageTypeRegistry } from './typeRegistry.js';
|
|
7
|
+
import { SEGMENT_SIZE } from './utils.js';
|
|
8
|
+
export class Transport extends core.Transport {
|
|
9
|
+
debugLink = false;
|
|
10
|
+
userActionRequired = false;
|
|
11
|
+
delegate;
|
|
12
|
+
/// One per transport, unlike on Trezor, since the contention is
|
|
13
|
+
/// only per-device, not global.
|
|
14
|
+
callInProgress = {
|
|
15
|
+
main: undefined,
|
|
16
|
+
debug: undefined,
|
|
17
|
+
};
|
|
18
|
+
constructor(keyring, delegate) {
|
|
19
|
+
super(keyring);
|
|
20
|
+
this.delegate = delegate;
|
|
21
|
+
}
|
|
22
|
+
static async create(keyring, delegate) {
|
|
23
|
+
return new Transport(keyring, delegate);
|
|
24
|
+
}
|
|
25
|
+
isOpened() {
|
|
26
|
+
return this.delegate.isOpened();
|
|
27
|
+
}
|
|
28
|
+
getDeviceID() {
|
|
29
|
+
return this.delegate.getDeviceID();
|
|
30
|
+
}
|
|
31
|
+
connect() {
|
|
32
|
+
return this.delegate.connect();
|
|
33
|
+
}
|
|
34
|
+
async tryConnectDebugLink() {
|
|
35
|
+
let out = false;
|
|
36
|
+
if (this.delegate.tryConnectDebugLink && (await this.delegate.tryConnectDebugLink()))
|
|
37
|
+
out = true;
|
|
38
|
+
this.debugLink = out;
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
disconnect() {
|
|
42
|
+
return this.delegate.disconnect();
|
|
43
|
+
}
|
|
44
|
+
async write(buf, debugLink) {
|
|
45
|
+
// break frame into segments
|
|
46
|
+
for (let i = 0; i < buf.length; i += SEGMENT_SIZE) {
|
|
47
|
+
const segment = buf.slice(i, i + SEGMENT_SIZE);
|
|
48
|
+
const padding = new Uint8Array(SEGMENT_SIZE - segment.length);
|
|
49
|
+
const fragments = [];
|
|
50
|
+
fragments.push(new Uint8Array([SEGMENT_SIZE]));
|
|
51
|
+
fragments.push(segment);
|
|
52
|
+
fragments.push(padding);
|
|
53
|
+
const fragmentBuffer = new Uint8Array(fragments.map(x => x.length).reduce((a, x) => a + x, 0));
|
|
54
|
+
fragments.reduce((a, x) => (fragmentBuffer.set(x, a), a + x.length), 0);
|
|
55
|
+
await this.delegate.writeChunk(fragmentBuffer, debugLink);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async read(debugLink) {
|
|
59
|
+
const first = await this.delegate.readChunk(debugLink);
|
|
60
|
+
// Check that buffer starts with: "?##" [ 0x3f, 0x23, 0x23 ]
|
|
61
|
+
// "?" = USB reportId, "##" = KeepKey magic bytes
|
|
62
|
+
// Message ID is bytes 4-5. Message length starts at byte 6.
|
|
63
|
+
const firstView = new DataView(first.buffer.slice(first.byteOffset, first.byteOffset + first.byteLength));
|
|
64
|
+
const valid = (firstView.getUint32(0) & 0xffffff00) === 0x3f232300;
|
|
65
|
+
const msgLength = firstView.getUint32(5);
|
|
66
|
+
if (!valid)
|
|
67
|
+
throw new Error('message not valid');
|
|
68
|
+
const buffer = new Uint8Array(9 + msgLength);
|
|
69
|
+
buffer.set(first.slice(0, Math.min(first.length, buffer.length)));
|
|
70
|
+
for (let offset = first.length; offset < buffer.length;) {
|
|
71
|
+
// Drop USB "?" reportId in the first byte
|
|
72
|
+
const next = (await this.delegate.readChunk(debugLink)).slice(1);
|
|
73
|
+
buffer.set(next.slice(0, Math.min(next.length, buffer.length - offset)), offset);
|
|
74
|
+
offset += next.length;
|
|
75
|
+
}
|
|
76
|
+
return buffer;
|
|
77
|
+
}
|
|
78
|
+
getVendor() {
|
|
79
|
+
return 'KeepKey';
|
|
80
|
+
}
|
|
81
|
+
getEntropy(length) {
|
|
82
|
+
if (typeof window !== 'undefined' && window?.crypto) {
|
|
83
|
+
return window.crypto.getRandomValues(new Uint8Array(length));
|
|
84
|
+
}
|
|
85
|
+
return crypto.randomBytes(length);
|
|
86
|
+
}
|
|
87
|
+
async getFirmwareHash(firmware) {
|
|
88
|
+
if (typeof window !== 'undefined' && window?.crypto) {
|
|
89
|
+
return new Uint8Array(await window.crypto.subtle.digest({ name: 'SHA-256' }, firmware));
|
|
90
|
+
}
|
|
91
|
+
const hash = crypto.createHash('sha256');
|
|
92
|
+
hash.update(firmware);
|
|
93
|
+
return hash.digest();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Utility function to cancel all pending calls whenver one of them is cancelled.
|
|
97
|
+
*/
|
|
98
|
+
async cancellable(inProgress) {
|
|
99
|
+
try {
|
|
100
|
+
await inProgress;
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
// Throw away the error, as the other context will handle it,
|
|
104
|
+
// unless it was a cancel, in which case we cancel everything.
|
|
105
|
+
if (core.isIndexable(e) && e.type === core.HDWalletErrorType.ActionCancelled) {
|
|
106
|
+
this.callInProgress = { main: undefined, debug: undefined };
|
|
107
|
+
throw e;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async lockDuring(action) {
|
|
112
|
+
this.callInProgress.main = (async () => {
|
|
113
|
+
await this.cancellable(this.callInProgress.main);
|
|
114
|
+
return action();
|
|
115
|
+
})();
|
|
116
|
+
return this.callInProgress.main;
|
|
117
|
+
}
|
|
118
|
+
async handleCancellableResponse() {
|
|
119
|
+
return this.readResponse(false);
|
|
120
|
+
}
|
|
121
|
+
async readResponse(debugLink) {
|
|
122
|
+
let buf;
|
|
123
|
+
do {
|
|
124
|
+
buf = await this.read(debugLink);
|
|
125
|
+
} while (!buf);
|
|
126
|
+
const [msgTypeEnum, msg] = this.fromMessageBuffer(buf);
|
|
127
|
+
const event = core.makeEvent({
|
|
128
|
+
message_type: messageNameRegistry[msgTypeEnum],
|
|
129
|
+
message_enum: msgTypeEnum,
|
|
130
|
+
message: msg.toObject(),
|
|
131
|
+
proto: msg,
|
|
132
|
+
from_wallet: true,
|
|
133
|
+
});
|
|
134
|
+
this.emit(String(msgTypeEnum), event);
|
|
135
|
+
if (debugLink)
|
|
136
|
+
return event;
|
|
137
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_FAILURE) {
|
|
138
|
+
const failureEvent = core.makeEvent({
|
|
139
|
+
message_type: core.Events.FAILURE,
|
|
140
|
+
message_enum: msgTypeEnum,
|
|
141
|
+
message: msg.toObject(),
|
|
142
|
+
from_wallet: true,
|
|
143
|
+
});
|
|
144
|
+
this.emit(core.Events.FAILURE, failureEvent);
|
|
145
|
+
return failureEvent;
|
|
146
|
+
}
|
|
147
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_BUTTONREQUEST) {
|
|
148
|
+
this.emit(core.Events.BUTTON_REQUEST, core.makeEvent({
|
|
149
|
+
message_type: core.Events.BUTTON_REQUEST,
|
|
150
|
+
from_wallet: true,
|
|
151
|
+
}));
|
|
152
|
+
this.userActionRequired = true;
|
|
153
|
+
return this.call(Messages.MessageType.MESSAGETYPE_BUTTONACK, new Messages.ButtonAck(), {
|
|
154
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
155
|
+
omitLock: true,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_ENTROPYREQUEST) {
|
|
159
|
+
const ack = new Messages.EntropyAck();
|
|
160
|
+
ack.setEntropy(this.getEntropy(32));
|
|
161
|
+
return this.call(Messages.MessageType.MESSAGETYPE_ENTROPYACK, ack, {
|
|
162
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
163
|
+
omitLock: true,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_PINMATRIXREQUEST) {
|
|
167
|
+
this.emit(core.Events.PIN_REQUEST, core.makeEvent({
|
|
168
|
+
message_type: core.Events.PIN_REQUEST,
|
|
169
|
+
from_wallet: true,
|
|
170
|
+
}));
|
|
171
|
+
this.userActionRequired = true;
|
|
172
|
+
return this.handleCancellableResponse();
|
|
173
|
+
}
|
|
174
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_PASSPHRASEREQUEST) {
|
|
175
|
+
this.emit(core.Events.PASSPHRASE_REQUEST, core.makeEvent({
|
|
176
|
+
message_type: core.Events.PASSPHRASE_REQUEST,
|
|
177
|
+
from_wallet: true,
|
|
178
|
+
}));
|
|
179
|
+
this.userActionRequired = true;
|
|
180
|
+
return this.handleCancellableResponse();
|
|
181
|
+
}
|
|
182
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_CHARACTERREQUEST) {
|
|
183
|
+
this.emit(core.Events.CHARACTER_REQUEST, core.makeEvent({
|
|
184
|
+
message_type: core.Events.CHARACTER_REQUEST,
|
|
185
|
+
from_wallet: true,
|
|
186
|
+
}));
|
|
187
|
+
this.userActionRequired = true;
|
|
188
|
+
return this.handleCancellableResponse();
|
|
189
|
+
}
|
|
190
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_WORDREQUEST) {
|
|
191
|
+
this.emit(core.Events.WORD_REQUEST, core.makeEvent({
|
|
192
|
+
message_type: core.Events.WORD_REQUEST,
|
|
193
|
+
from_wallet: true,
|
|
194
|
+
}));
|
|
195
|
+
this.userActionRequired = true;
|
|
196
|
+
return this.handleCancellableResponse();
|
|
197
|
+
}
|
|
198
|
+
return event;
|
|
199
|
+
}
|
|
200
|
+
async call(msgTypeEnum, msg, options) {
|
|
201
|
+
options ??= {};
|
|
202
|
+
options.msgTimeout ??= core.DEFAULT_TIMEOUT;
|
|
203
|
+
this.emit(String(msgTypeEnum), core.makeEvent({
|
|
204
|
+
message_type: messageNameRegistry[msgTypeEnum],
|
|
205
|
+
message_enum: msgTypeEnum,
|
|
206
|
+
message: msg.toObject(),
|
|
207
|
+
proto: msg,
|
|
208
|
+
from_wallet: false,
|
|
209
|
+
}));
|
|
210
|
+
const makePromise = async () => {
|
|
211
|
+
if ([
|
|
212
|
+
Messages.MessageType.MESSAGETYPE_BUTTONACK,
|
|
213
|
+
Messages.MessageType.MESSAGETYPE_PASSPHRASEACK,
|
|
214
|
+
Messages.MessageType.MESSAGETYPE_CHARACTERACK,
|
|
215
|
+
Messages.MessageType.MESSAGETYPE_PINMATRIXACK,
|
|
216
|
+
Messages.MessageType.MESSAGETYPE_WORDACK,
|
|
217
|
+
].includes(msgTypeEnum)) {
|
|
218
|
+
this.userActionRequired = true;
|
|
219
|
+
}
|
|
220
|
+
await this.write(this.toMessageBuffer(msgTypeEnum, msg), !!options?.debugLink);
|
|
221
|
+
if (options?.noWait)
|
|
222
|
+
return undefined;
|
|
223
|
+
const response = await this.readResponse(!!options?.debugLink);
|
|
224
|
+
this.userActionRequired = false;
|
|
225
|
+
if (response.message_enum === Messages.MessageType.MESSAGETYPE_FAILURE &&
|
|
226
|
+
response.message.code === Types.FailureType.FAILURE_ACTIONCANCELLED) {
|
|
227
|
+
this.callInProgress = { main: undefined, debug: undefined };
|
|
228
|
+
throw new core.ActionCancelled();
|
|
229
|
+
}
|
|
230
|
+
if (response.message_type === core.Events.FAILURE)
|
|
231
|
+
throw response;
|
|
232
|
+
return response;
|
|
233
|
+
};
|
|
234
|
+
if (options?.omitLock)
|
|
235
|
+
return makePromise();
|
|
236
|
+
// See the comments in hdwallet-trezor-connect's call for why this weird
|
|
237
|
+
// sequence. We've got a very similar issue here that needs pretty much
|
|
238
|
+
// the same solution.
|
|
239
|
+
const lockKey = options?.debugLink ? 'debug' : 'main';
|
|
240
|
+
this.callInProgress[lockKey] = (async () => {
|
|
241
|
+
await this.cancellable(this.callInProgress[lockKey]);
|
|
242
|
+
try {
|
|
243
|
+
return makePromise();
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
this.userActionRequired = false;
|
|
247
|
+
}
|
|
248
|
+
})();
|
|
249
|
+
return await this.callInProgress[lockKey];
|
|
250
|
+
}
|
|
251
|
+
async cancel() {
|
|
252
|
+
if (!this.userActionRequired)
|
|
253
|
+
return;
|
|
254
|
+
try {
|
|
255
|
+
this.callInProgress = { main: undefined, debug: undefined };
|
|
256
|
+
const cancelMsg = new Messages.Cancel();
|
|
257
|
+
await this.call(Messages.MessageType.MESSAGETYPE_CANCEL, cancelMsg, {
|
|
258
|
+
omitLock: this.userActionRequired,
|
|
259
|
+
noWait: this.userActionRequired,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
catch (e) {
|
|
263
|
+
console.error('Cancel Pending Error', e);
|
|
264
|
+
}
|
|
265
|
+
finally {
|
|
266
|
+
this.callInProgress = { main: undefined, debug: undefined };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
toMessageBuffer(msgTypeEnum, msg) {
|
|
270
|
+
const messageBuffer = msg.serializeBinary();
|
|
271
|
+
const headerBuffer = new Uint8Array(8);
|
|
272
|
+
const headerView = new DataView(headerBuffer.buffer);
|
|
273
|
+
headerView.setUint8(0, 0x23);
|
|
274
|
+
headerView.setUint8(1, 0x23);
|
|
275
|
+
headerView.setUint16(2, msgTypeEnum);
|
|
276
|
+
headerView.setUint32(4, messageBuffer.byteLength);
|
|
277
|
+
const fragments = [headerBuffer, messageBuffer];
|
|
278
|
+
const fragmentBuffer = new Uint8Array(fragments.map(x => x.length).reduce((a, x) => a + x, 0));
|
|
279
|
+
fragments.reduce((a, x) => (fragmentBuffer.set(x, a), a + x.length), 0);
|
|
280
|
+
return fragmentBuffer;
|
|
281
|
+
}
|
|
282
|
+
fromMessageBuffer(buf) {
|
|
283
|
+
const typeID = new DataView(buf.buffer).getUint16(3);
|
|
284
|
+
const MType = messageTypeRegistry[typeID];
|
|
285
|
+
if (!MType) {
|
|
286
|
+
const msg = new Messages.Failure();
|
|
287
|
+
msg.setCode(Types.FailureType.FAILURE_UNEXPECTEDMESSAGE);
|
|
288
|
+
msg.setMessage('Unknown message type received');
|
|
289
|
+
return [Messages.MessageType.MESSAGETYPE_FAILURE, msg];
|
|
290
|
+
}
|
|
291
|
+
const msg = new MType();
|
|
292
|
+
const reader = new jspb.BinaryReader(buf, 9, buf.length - 9);
|
|
293
|
+
return [typeID, MType.deserializeBinaryFromReader(msg, reader)];
|
|
294
|
+
}
|
|
295
|
+
static failureMessageFactory(e) {
|
|
296
|
+
const msg = new Messages.Failure();
|
|
297
|
+
msg.setCode(Types.FailureType.FAILURE_UNEXPECTEDMESSAGE);
|
|
298
|
+
if (typeof e === 'string') {
|
|
299
|
+
msg.setMessage(e);
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
msg.setMessage(String(e));
|
|
303
|
+
}
|
|
304
|
+
return msg.serializeBinary();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as Messages from '@keepkey/device-protocol/lib/messages_pb';
|
|
2
|
+
import * as BinanceMessages from '@keepkey/device-protocol/lib/messages-binance_pb';
|
|
3
|
+
import * as CosmosMessages from '@keepkey/device-protocol/lib/messages-cosmos_pb';
|
|
4
|
+
import * as EosMessages from '@keepkey/device-protocol/lib/messages-eos_pb';
|
|
5
|
+
import * as MayachainMessages from '@keepkey/device-protocol/lib/messages-mayachain_pb';
|
|
6
|
+
import * as NanoMessages from '@keepkey/device-protocol/lib/messages-nano_pb';
|
|
7
|
+
import * as RippleMessages from '@keepkey/device-protocol/lib/messages-ripple_pb';
|
|
8
|
+
import * as ThorchainMessages from '@keepkey/device-protocol/lib/messages-thorchain_pb';
|
|
9
|
+
import omit from 'lodash/omit';
|
|
10
|
+
// Conflict between typedef and actual js export
|
|
11
|
+
// When CJS modules are loaded in ESM context (e.g. vitest), `import * as X`
|
|
12
|
+
// creates a namespace with only `default` and `module.exports` as enumerable keys.
|
|
13
|
+
// Property access (X.Foo) works via proxy, but Object.entries() does not enumerate them.
|
|
14
|
+
// Access the underlying CJS module.exports via `.default` for proper enumeration.
|
|
15
|
+
const unwrapCjsModule = (mod) => mod.default ?? mod;
|
|
16
|
+
const MessagesUnwrapped = unwrapCjsModule(Messages);
|
|
17
|
+
const BinanceMessagesUnwrapped = unwrapCjsModule(BinanceMessages);
|
|
18
|
+
const CosmosMessagesUnwrapped = unwrapCjsModule(CosmosMessages);
|
|
19
|
+
const EosMessagesUnwrapped = unwrapCjsModule(EosMessages);
|
|
20
|
+
const MayachainMessagesUnwrapped = unwrapCjsModule(MayachainMessages);
|
|
21
|
+
const NanoMessagesUnwrapped = unwrapCjsModule(NanoMessages);
|
|
22
|
+
const RippleMessagesUnwrapped = unwrapCjsModule(RippleMessages);
|
|
23
|
+
const ThorchainMessagesUnwrapped = unwrapCjsModule(ThorchainMessages);
|
|
24
|
+
const AllMessages = []
|
|
25
|
+
.concat(Object.entries(omit(MessagesUnwrapped, 'MessageType', 'MessageTypeMap')))
|
|
26
|
+
.concat(Object.entries(CosmosMessagesUnwrapped))
|
|
27
|
+
.concat(Object.entries(BinanceMessagesUnwrapped))
|
|
28
|
+
.concat(Object.entries(RippleMessagesUnwrapped))
|
|
29
|
+
.concat(Object.entries(NanoMessagesUnwrapped))
|
|
30
|
+
.concat(Object.entries(omit(EosMessagesUnwrapped, 'EosPublicKeyKind', 'EosPublicKeyKindMap')))
|
|
31
|
+
.concat(Object.entries(ThorchainMessagesUnwrapped))
|
|
32
|
+
.concat(Object.entries(MayachainMessagesUnwrapped));
|
|
33
|
+
const upperCasedMessageClasses = AllMessages.reduce((registry, entry) => {
|
|
34
|
+
registry[entry[0].toUpperCase()] = entry[1];
|
|
35
|
+
return registry;
|
|
36
|
+
}, {});
|
|
37
|
+
// Map of message type enums to human readable message name
|
|
38
|
+
export const messageNameRegistry = Object.entries(unwrapCjsModule(Messages).MessageType).reduce((registry, entry) => {
|
|
39
|
+
registry[entry[1]] = entry[0].split('_')[1] ?? '';
|
|
40
|
+
return registry;
|
|
41
|
+
}, {});
|
|
42
|
+
// Map of message type enum to their protobuf constructor
|
|
43
|
+
export const messageTypeRegistry = Object.entries(unwrapCjsModule(Messages).MessageType).reduce((registry, entry) => {
|
|
44
|
+
const part = entry[0].split('_')[1] ?? '';
|
|
45
|
+
registry[entry[1]] = upperCasedMessageClasses[part.toUpperCase()];
|
|
46
|
+
return registry;
|
|
47
|
+
}, {});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
2
|
+
export declare const SEGMENT_SIZE = 63;
|
|
3
|
+
export declare function protoFieldToSetMethod(fieldName: string): string;
|
|
4
|
+
export declare function toUTF8Array(str: string): Uint8Array;
|
|
5
|
+
export declare function translateInputScriptType(scriptType: core.BTCInputScriptType): any;
|
|
6
|
+
export declare function translateOutputScriptType(scriptType: core.BTCOutputScriptType): any;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as Types from '@keepkey/device-protocol/lib/types_pb';
|
|
2
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
3
|
+
export const SEGMENT_SIZE = 63;
|
|
4
|
+
// Shim until this exists for jspb https://github.com/protocolbuffers/protobuf/issues/1591
|
|
5
|
+
export function protoFieldToSetMethod(fieldName) {
|
|
6
|
+
return `set${fieldName.charAt(0).toUpperCase() + fieldName.slice(1)}`;
|
|
7
|
+
}
|
|
8
|
+
// https://gist.github.com/joni/3760795/8f0c1a608b7f0c8b3978db68105c5b1d741d0446
|
|
9
|
+
export function toUTF8Array(str) {
|
|
10
|
+
const utf8 = [];
|
|
11
|
+
for (let i = 0; i < str.length; i++) {
|
|
12
|
+
let charcode = str.charCodeAt(i);
|
|
13
|
+
if (charcode < 0x80)
|
|
14
|
+
utf8.push(charcode);
|
|
15
|
+
else if (charcode < 0x800) {
|
|
16
|
+
utf8.push(0xc0 | (charcode >> 6), 0x80 | (charcode & 0x3f));
|
|
17
|
+
}
|
|
18
|
+
else if (charcode < 0xd800 || charcode >= 0xe000) {
|
|
19
|
+
utf8.push(0xe0 | (charcode >> 12), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f));
|
|
20
|
+
}
|
|
21
|
+
// surrogate pair
|
|
22
|
+
else {
|
|
23
|
+
i++;
|
|
24
|
+
charcode = ((charcode & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff);
|
|
25
|
+
utf8.push(0xf0 | (charcode >> 18), 0x80 | ((charcode >> 12) & 0x3f), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return new Uint8Array(utf8);
|
|
29
|
+
}
|
|
30
|
+
export function translateInputScriptType(scriptType) {
|
|
31
|
+
switch (scriptType) {
|
|
32
|
+
case core.BTCInputScriptType.CashAddr:
|
|
33
|
+
case core.BTCInputScriptType.SpendAddress:
|
|
34
|
+
return Types.InputScriptType.SPENDADDRESS;
|
|
35
|
+
case core.BTCInputScriptType.SpendMultisig:
|
|
36
|
+
return Types.InputScriptType.SPENDMULTISIG;
|
|
37
|
+
case core.BTCInputScriptType.SpendP2SHWitness:
|
|
38
|
+
return Types.InputScriptType.SPENDP2SHWITNESS;
|
|
39
|
+
case core.BTCInputScriptType.SpendWitness:
|
|
40
|
+
return Types.InputScriptType.SPENDWITNESS;
|
|
41
|
+
}
|
|
42
|
+
throw new Error('unhandled InputSriptType enum: ' + scriptType);
|
|
43
|
+
}
|
|
44
|
+
export function translateOutputScriptType(scriptType) {
|
|
45
|
+
switch (scriptType) {
|
|
46
|
+
case core.BTCOutputScriptType.PayToAddress:
|
|
47
|
+
return Types.OutputScriptType.PAYTOADDRESS;
|
|
48
|
+
case core.BTCOutputScriptType.PayToMultisig:
|
|
49
|
+
return Types.OutputScriptType.PAYTOMULTISIG;
|
|
50
|
+
case core.BTCOutputScriptType.PayToP2SHWitness:
|
|
51
|
+
return Types.OutputScriptType.PAYTOP2SHWITNESS;
|
|
52
|
+
case core.BTCOutputScriptType.PayToWitness:
|
|
53
|
+
return Types.OutputScriptType.PAYTOWITNESS;
|
|
54
|
+
}
|
|
55
|
+
throw new Error('unhandled OutputScriptType enum: ' + scriptType);
|
|
56
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/hdwallet-keepkey",
|
|
3
|
-
"version": "1.62.
|
|
3
|
+
"version": "1.62.42",
|
|
4
|
+
"repository": "https://github.com/shapeshift/web",
|
|
4
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/cjs/index.js",
|
|
8
|
+
"module": "dist/esm/index.js",
|
|
9
|
+
"types": "dist/esm/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/esm/index.d.ts",
|
|
13
|
+
"import": "./dist/esm/index.js",
|
|
14
|
+
"require": "./dist/cjs/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
5
20
|
"publishConfig": {
|
|
6
21
|
"access": "public"
|
|
7
22
|
},
|
|
8
|
-
"main": "dist/index.js",
|
|
9
|
-
"source": "src/index.ts",
|
|
10
|
-
"types": "dist/index.d.ts",
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "tsc --build",
|
|
13
|
-
"build:docs": "typedoc --out docs --target es6 --theme minimal --mode file src",
|
|
14
|
-
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
15
|
-
"prepublishOnly": "yarn clean && yarn build"
|
|
16
|
-
},
|
|
17
23
|
"dependencies": {
|
|
18
24
|
"@bitcoinerlab/secp256k1": "^1.1.1",
|
|
19
25
|
"@ethereumjs/common": "3.2.0",
|
|
@@ -21,19 +27,20 @@
|
|
|
21
27
|
"@keepkey/device-protocol": "7.13.4",
|
|
22
28
|
"@metamask/eth-sig-util": "^7.0.0",
|
|
23
29
|
"@shapeshiftoss/bitcoinjs-lib": "7.0.0-shapeshift.2",
|
|
24
|
-
"@shapeshiftoss/hdwallet-core": "^1.62.41",
|
|
25
30
|
"@shapeshiftoss/proto-tx-builder": "0.10.0",
|
|
26
31
|
"bignumber.js": "^9.0.1",
|
|
27
32
|
"bnb-javascript-sdk-nobroadcast": "2.16.15",
|
|
28
33
|
"bs58": "^5.0.0",
|
|
29
34
|
"bs58check": "^4.0.0",
|
|
30
|
-
"crypto-js": "^4.
|
|
35
|
+
"crypto-js": "^4.2.0",
|
|
31
36
|
"eip55": "^2.1.0",
|
|
37
|
+
"ethers": "5.7.2",
|
|
32
38
|
"google-protobuf": "^3.15.8",
|
|
33
39
|
"icepick": "^2.4.0",
|
|
34
|
-
"lodash": "^4.17.
|
|
40
|
+
"lodash": "^4.17.23",
|
|
35
41
|
"p-lazy": "^3.1.0",
|
|
36
|
-
"semver": "^7.3.8"
|
|
42
|
+
"semver": "^7.3.8",
|
|
43
|
+
"@shapeshiftoss/hdwallet-core": "^1.62.41"
|
|
37
44
|
},
|
|
38
45
|
"devDependencies": {
|
|
39
46
|
"@cosmjs/amino": "^0.28.13",
|
|
@@ -43,9 +50,16 @@
|
|
|
43
50
|
"@types/crypto-js": "^4.0.0",
|
|
44
51
|
"@types/google-protobuf": "^3.15.1",
|
|
45
52
|
"@types/icepick": "^2.3.0",
|
|
46
|
-
"@types/lodash": "^4.14.
|
|
47
|
-
"@types/semver": "^6.2.2"
|
|
48
|
-
"typedoc": "^0.20.36"
|
|
53
|
+
"@types/lodash": "^4.14.178",
|
|
54
|
+
"@types/semver": "^6.2.2"
|
|
49
55
|
},
|
|
50
|
-
"
|
|
51
|
-
|
|
56
|
+
"sideEffects": false,
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "rm -rf dist && pnpm exec tsc --build && pnpm run postbuild",
|
|
59
|
+
"clean": "rm -rf dist node_modules",
|
|
60
|
+
"dev": "pnpm exec tsc --build --watch",
|
|
61
|
+
"postbuild": "pnpm run postbuild:esm && pnpm run postbuild:cjs",
|
|
62
|
+
"postbuild:esm": "pnpm exec tsc-esm-fix --target=dist/esm --ext=.js",
|
|
63
|
+
"postbuild:cjs": "echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/dist/adapter.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,8BAA8B,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAa,iBAAiB,EAAE,MAAM,aAAa,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