@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,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.thorchainSignTx = exports.thorchainGetAddress = exports.thorchainGetAccountPaths = void 0;
|
|
30
|
+
const Messages = __importStar(require("@keepkey/device-protocol/lib/messages_pb"));
|
|
31
|
+
const ThorchainMessages = __importStar(require("@keepkey/device-protocol/lib/messages-thorchain_pb"));
|
|
32
|
+
const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
|
|
33
|
+
const bs58check_1 = __importDefault(require("bs58check"));
|
|
34
|
+
const p_lazy_1 = __importDefault(require("p-lazy"));
|
|
35
|
+
const protoTxBuilder = p_lazy_1.default.from(() => Promise.resolve().then(() => __importStar(require('@shapeshiftoss/proto-tx-builder'))));
|
|
36
|
+
function thorchainGetAccountPaths(msg) {
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
addressNList: [
|
|
40
|
+
0x80000000 + 44,
|
|
41
|
+
0x80000000 + core.slip44ByCoin('Thorchain'),
|
|
42
|
+
0x80000000 + msg.accountIdx,
|
|
43
|
+
0,
|
|
44
|
+
0,
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
exports.thorchainGetAccountPaths = thorchainGetAccountPaths;
|
|
50
|
+
async function thorchainGetAddress(transport, msg) {
|
|
51
|
+
const getAddr = new ThorchainMessages.ThorchainGetAddress();
|
|
52
|
+
getAddr.setAddressNList(msg.addressNList);
|
|
53
|
+
getAddr.setShowDisplay(msg.showDisplay !== false);
|
|
54
|
+
if (msg.testnet !== undefined)
|
|
55
|
+
getAddr.setTestnet(msg.testnet);
|
|
56
|
+
const response = await transport.call(Messages.MessageType.MESSAGETYPE_THORCHAINGETADDRESS, getAddr, {
|
|
57
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
58
|
+
});
|
|
59
|
+
const thorchainAddress = response.proto;
|
|
60
|
+
return core.mustBeDefined(thorchainAddress.getAddress());
|
|
61
|
+
}
|
|
62
|
+
exports.thorchainGetAddress = thorchainGetAddress;
|
|
63
|
+
async function thorchainSignTx(transport, msg) {
|
|
64
|
+
const address = await thorchainGetAddress(transport, { addressNList: msg.addressNList });
|
|
65
|
+
const getPublicKeyMsg = new Messages.GetPublicKey();
|
|
66
|
+
getPublicKeyMsg.setAddressNList(msg.addressNList);
|
|
67
|
+
getPublicKeyMsg.setEcdsaCurveName('secp256k1');
|
|
68
|
+
const response = await transport.call(Messages.MessageType.MESSAGETYPE_GETPUBLICKEY, getPublicKeyMsg, {
|
|
69
|
+
msgTimeout: core.DEFAULT_TIMEOUT,
|
|
70
|
+
});
|
|
71
|
+
const pubkeyMsg = response.proto;
|
|
72
|
+
const pubkey = bs58check_1.default.decode(core.mustBeDefined(pubkeyMsg.getXpub())).slice(45);
|
|
73
|
+
return transport.lockDuring(async () => {
|
|
74
|
+
const signTx = new ThorchainMessages.ThorchainSignTx();
|
|
75
|
+
signTx.setAddressNList(msg.addressNList);
|
|
76
|
+
signTx.setAccountNumber(msg.account_number);
|
|
77
|
+
signTx.setChainId(msg.chain_id);
|
|
78
|
+
signTx.setFeeAmount(parseInt(msg.tx.fee.amount[0].amount));
|
|
79
|
+
signTx.setGas(parseInt(msg.tx.fee.gas));
|
|
80
|
+
signTx.setSequence(msg.sequence);
|
|
81
|
+
if (msg.tx.memo !== undefined)
|
|
82
|
+
signTx.setMemo(msg.tx.memo);
|
|
83
|
+
signTx.setMsgCount(1);
|
|
84
|
+
let resp = await transport.call(Messages.MessageType.MESSAGETYPE_THORCHAINSIGNTX, signTx, {
|
|
85
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
86
|
+
omitLock: true,
|
|
87
|
+
});
|
|
88
|
+
for (const m of msg.tx.msg) {
|
|
89
|
+
if (resp.message_enum !== Messages.MessageType.MESSAGETYPE_THORCHAINMSGREQUEST) {
|
|
90
|
+
throw new Error(`THORChain: unexpected response ${resp.message_type}`);
|
|
91
|
+
}
|
|
92
|
+
let ack;
|
|
93
|
+
if (m.type === 'thorchain/MsgSend') {
|
|
94
|
+
if (m.value.amount.length !== 1) {
|
|
95
|
+
throw new Error('THORChain: Multiple amounts per MsgSend not supported');
|
|
96
|
+
}
|
|
97
|
+
const denom = m.value.amount[0].denom;
|
|
98
|
+
if (denom !== 'rune') {
|
|
99
|
+
throw new Error('THORChain: Unsupported denomination: ' + denom);
|
|
100
|
+
}
|
|
101
|
+
const send = new ThorchainMessages.ThorchainMsgSend();
|
|
102
|
+
send.setFromAddress(m.value.from_address);
|
|
103
|
+
send.setToAddress(m.value.to_address);
|
|
104
|
+
send.setAmount(m.value.amount[0].amount);
|
|
105
|
+
ack = new ThorchainMessages.ThorchainMsgAck();
|
|
106
|
+
ack.setSend(send);
|
|
107
|
+
}
|
|
108
|
+
else if (m.type === 'thorchain/MsgDeposit') {
|
|
109
|
+
if (m.value.coins.length !== 1) {
|
|
110
|
+
throw new Error('THORChain: Multiple amounts per MsgDeposit not supported');
|
|
111
|
+
}
|
|
112
|
+
const coinAsset = m.value.coins[0].asset;
|
|
113
|
+
if (!['THOR.RUNE', 'THOR.TCY', 'THOR.RUJI'].includes(coinAsset)) {
|
|
114
|
+
throw new Error('THORChain: Unsupported coin asset: ' + coinAsset);
|
|
115
|
+
}
|
|
116
|
+
const deposit = new ThorchainMessages.ThorchainMsgDeposit();
|
|
117
|
+
deposit.setAsset(m.value.coins[0].asset);
|
|
118
|
+
deposit.setAmount(m.value.coins[0].amount);
|
|
119
|
+
deposit.setMemo(m.value.memo);
|
|
120
|
+
deposit.setSigner(m.value.signer);
|
|
121
|
+
ack = new ThorchainMessages.ThorchainMsgAck();
|
|
122
|
+
ack.setDeposit(deposit);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
throw new Error(`THORChain: Message ${m.type} is not yet supported`);
|
|
126
|
+
}
|
|
127
|
+
resp = await transport.call(Messages.MessageType.MESSAGETYPE_THORCHAINMSGACK, ack, {
|
|
128
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
129
|
+
omitLock: true,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (resp.message_enum !== Messages.MessageType.MESSAGETYPE_THORCHAINSIGNEDTX) {
|
|
133
|
+
throw new Error(`THORChain: unexpected response ${resp.message_type}`);
|
|
134
|
+
}
|
|
135
|
+
const signedTx = resp.proto;
|
|
136
|
+
const offlineSigner = {
|
|
137
|
+
async getAccounts() {
|
|
138
|
+
return [
|
|
139
|
+
{
|
|
140
|
+
address,
|
|
141
|
+
algo: 'secp256k1',
|
|
142
|
+
pubkey,
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
},
|
|
146
|
+
async signAmino(signerAddress, signDoc) {
|
|
147
|
+
if (signerAddress !== address)
|
|
148
|
+
throw new Error('expected signerAddress to match address');
|
|
149
|
+
return {
|
|
150
|
+
signed: signDoc,
|
|
151
|
+
signature: {
|
|
152
|
+
pub_key: {
|
|
153
|
+
type: 'tendermint/PubKeySecp256k1',
|
|
154
|
+
value: signedTx.getPublicKey_asB64(),
|
|
155
|
+
},
|
|
156
|
+
signature: signedTx.getSignature_asB64(),
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
const signerData = {
|
|
162
|
+
sequence: Number(msg.sequence),
|
|
163
|
+
accountNumber: Number(msg.account_number),
|
|
164
|
+
chainId: msg.chain_id,
|
|
165
|
+
};
|
|
166
|
+
return (await protoTxBuilder).sign(address, msg.tx, offlineSigner, signerData, 'thor');
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
exports.thorchainSignTx = thorchainSignTx;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as core from
|
|
2
|
-
import * as jspb from
|
|
1
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
2
|
+
import * as jspb from 'google-protobuf';
|
|
3
3
|
export interface TransportDelegate {
|
|
4
4
|
isOpened(): Promise<boolean>;
|
|
5
5
|
getDeviceID(): Promise<string>;
|
|
@@ -53,4 +53,3 @@ export declare class Transport extends core.Transport {
|
|
|
53
53
|
protected fromMessageBuffer(buf: Uint8Array): [number, jspb.Message];
|
|
54
54
|
protected static failureMessageFactory(e?: Error | string): Uint8Array;
|
|
55
55
|
}
|
|
56
|
-
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Transport = void 0;
|
|
27
|
+
const Messages = __importStar(require("@keepkey/device-protocol/lib/messages_pb"));
|
|
28
|
+
const Types = __importStar(require("@keepkey/device-protocol/lib/types_pb"));
|
|
29
|
+
const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
|
|
30
|
+
const crypto = __importStar(require("crypto"));
|
|
31
|
+
const jspb = __importStar(require("google-protobuf"));
|
|
32
|
+
const typeRegistry_1 = require("./typeRegistry");
|
|
33
|
+
const utils_1 = require("./utils");
|
|
34
|
+
class Transport extends core.Transport {
|
|
35
|
+
debugLink = false;
|
|
36
|
+
userActionRequired = false;
|
|
37
|
+
delegate;
|
|
38
|
+
/// One per transport, unlike on Trezor, since the contention is
|
|
39
|
+
/// only per-device, not global.
|
|
40
|
+
callInProgress = {
|
|
41
|
+
main: undefined,
|
|
42
|
+
debug: undefined,
|
|
43
|
+
};
|
|
44
|
+
constructor(keyring, delegate) {
|
|
45
|
+
super(keyring);
|
|
46
|
+
this.delegate = delegate;
|
|
47
|
+
}
|
|
48
|
+
static async create(keyring, delegate) {
|
|
49
|
+
return new Transport(keyring, delegate);
|
|
50
|
+
}
|
|
51
|
+
isOpened() {
|
|
52
|
+
return this.delegate.isOpened();
|
|
53
|
+
}
|
|
54
|
+
getDeviceID() {
|
|
55
|
+
return this.delegate.getDeviceID();
|
|
56
|
+
}
|
|
57
|
+
connect() {
|
|
58
|
+
return this.delegate.connect();
|
|
59
|
+
}
|
|
60
|
+
async tryConnectDebugLink() {
|
|
61
|
+
let out = false;
|
|
62
|
+
if (this.delegate.tryConnectDebugLink && (await this.delegate.tryConnectDebugLink()))
|
|
63
|
+
out = true;
|
|
64
|
+
this.debugLink = out;
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
disconnect() {
|
|
68
|
+
return this.delegate.disconnect();
|
|
69
|
+
}
|
|
70
|
+
async write(buf, debugLink) {
|
|
71
|
+
// break frame into segments
|
|
72
|
+
for (let i = 0; i < buf.length; i += utils_1.SEGMENT_SIZE) {
|
|
73
|
+
const segment = buf.slice(i, i + utils_1.SEGMENT_SIZE);
|
|
74
|
+
const padding = new Uint8Array(utils_1.SEGMENT_SIZE - segment.length);
|
|
75
|
+
const fragments = [];
|
|
76
|
+
fragments.push(new Uint8Array([utils_1.SEGMENT_SIZE]));
|
|
77
|
+
fragments.push(segment);
|
|
78
|
+
fragments.push(padding);
|
|
79
|
+
const fragmentBuffer = new Uint8Array(fragments.map(x => x.length).reduce((a, x) => a + x, 0));
|
|
80
|
+
fragments.reduce((a, x) => (fragmentBuffer.set(x, a), a + x.length), 0);
|
|
81
|
+
await this.delegate.writeChunk(fragmentBuffer, debugLink);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async read(debugLink) {
|
|
85
|
+
const first = await this.delegate.readChunk(debugLink);
|
|
86
|
+
// Check that buffer starts with: "?##" [ 0x3f, 0x23, 0x23 ]
|
|
87
|
+
// "?" = USB reportId, "##" = KeepKey magic bytes
|
|
88
|
+
// Message ID is bytes 4-5. Message length starts at byte 6.
|
|
89
|
+
const firstView = new DataView(first.buffer.slice(first.byteOffset, first.byteOffset + first.byteLength));
|
|
90
|
+
const valid = (firstView.getUint32(0) & 0xffffff00) === 0x3f232300;
|
|
91
|
+
const msgLength = firstView.getUint32(5);
|
|
92
|
+
if (!valid)
|
|
93
|
+
throw new Error('message not valid');
|
|
94
|
+
const buffer = new Uint8Array(9 + msgLength);
|
|
95
|
+
buffer.set(first.slice(0, Math.min(first.length, buffer.length)));
|
|
96
|
+
for (let offset = first.length; offset < buffer.length;) {
|
|
97
|
+
// Drop USB "?" reportId in the first byte
|
|
98
|
+
const next = (await this.delegate.readChunk(debugLink)).slice(1);
|
|
99
|
+
buffer.set(next.slice(0, Math.min(next.length, buffer.length - offset)), offset);
|
|
100
|
+
offset += next.length;
|
|
101
|
+
}
|
|
102
|
+
return buffer;
|
|
103
|
+
}
|
|
104
|
+
getVendor() {
|
|
105
|
+
return 'KeepKey';
|
|
106
|
+
}
|
|
107
|
+
getEntropy(length) {
|
|
108
|
+
if (typeof window !== 'undefined' && window?.crypto) {
|
|
109
|
+
return window.crypto.getRandomValues(new Uint8Array(length));
|
|
110
|
+
}
|
|
111
|
+
return crypto.randomBytes(length);
|
|
112
|
+
}
|
|
113
|
+
async getFirmwareHash(firmware) {
|
|
114
|
+
if (typeof window !== 'undefined' && window?.crypto) {
|
|
115
|
+
return new Uint8Array(await window.crypto.subtle.digest({ name: 'SHA-256' }, firmware));
|
|
116
|
+
}
|
|
117
|
+
const hash = crypto.createHash('sha256');
|
|
118
|
+
hash.update(firmware);
|
|
119
|
+
return hash.digest();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Utility function to cancel all pending calls whenver one of them is cancelled.
|
|
123
|
+
*/
|
|
124
|
+
async cancellable(inProgress) {
|
|
125
|
+
try {
|
|
126
|
+
await inProgress;
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
// Throw away the error, as the other context will handle it,
|
|
130
|
+
// unless it was a cancel, in which case we cancel everything.
|
|
131
|
+
if (core.isIndexable(e) && e.type === core.HDWalletErrorType.ActionCancelled) {
|
|
132
|
+
this.callInProgress = { main: undefined, debug: undefined };
|
|
133
|
+
throw e;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async lockDuring(action) {
|
|
138
|
+
this.callInProgress.main = (async () => {
|
|
139
|
+
await this.cancellable(this.callInProgress.main);
|
|
140
|
+
return action();
|
|
141
|
+
})();
|
|
142
|
+
return this.callInProgress.main;
|
|
143
|
+
}
|
|
144
|
+
async handleCancellableResponse() {
|
|
145
|
+
return this.readResponse(false);
|
|
146
|
+
}
|
|
147
|
+
async readResponse(debugLink) {
|
|
148
|
+
let buf;
|
|
149
|
+
do {
|
|
150
|
+
buf = await this.read(debugLink);
|
|
151
|
+
} while (!buf);
|
|
152
|
+
const [msgTypeEnum, msg] = this.fromMessageBuffer(buf);
|
|
153
|
+
const event = core.makeEvent({
|
|
154
|
+
message_type: typeRegistry_1.messageNameRegistry[msgTypeEnum],
|
|
155
|
+
message_enum: msgTypeEnum,
|
|
156
|
+
message: msg.toObject(),
|
|
157
|
+
proto: msg,
|
|
158
|
+
from_wallet: true,
|
|
159
|
+
});
|
|
160
|
+
this.emit(String(msgTypeEnum), event);
|
|
161
|
+
if (debugLink)
|
|
162
|
+
return event;
|
|
163
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_FAILURE) {
|
|
164
|
+
const failureEvent = core.makeEvent({
|
|
165
|
+
message_type: core.Events.FAILURE,
|
|
166
|
+
message_enum: msgTypeEnum,
|
|
167
|
+
message: msg.toObject(),
|
|
168
|
+
from_wallet: true,
|
|
169
|
+
});
|
|
170
|
+
this.emit(core.Events.FAILURE, failureEvent);
|
|
171
|
+
return failureEvent;
|
|
172
|
+
}
|
|
173
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_BUTTONREQUEST) {
|
|
174
|
+
this.emit(core.Events.BUTTON_REQUEST, core.makeEvent({
|
|
175
|
+
message_type: core.Events.BUTTON_REQUEST,
|
|
176
|
+
from_wallet: true,
|
|
177
|
+
}));
|
|
178
|
+
this.userActionRequired = true;
|
|
179
|
+
return this.call(Messages.MessageType.MESSAGETYPE_BUTTONACK, new Messages.ButtonAck(), {
|
|
180
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
181
|
+
omitLock: true,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_ENTROPYREQUEST) {
|
|
185
|
+
const ack = new Messages.EntropyAck();
|
|
186
|
+
ack.setEntropy(this.getEntropy(32));
|
|
187
|
+
return this.call(Messages.MessageType.MESSAGETYPE_ENTROPYACK, ack, {
|
|
188
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
189
|
+
omitLock: true,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_PINMATRIXREQUEST) {
|
|
193
|
+
this.emit(core.Events.PIN_REQUEST, core.makeEvent({
|
|
194
|
+
message_type: core.Events.PIN_REQUEST,
|
|
195
|
+
from_wallet: true,
|
|
196
|
+
}));
|
|
197
|
+
this.userActionRequired = true;
|
|
198
|
+
return this.handleCancellableResponse();
|
|
199
|
+
}
|
|
200
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_PASSPHRASEREQUEST) {
|
|
201
|
+
this.emit(core.Events.PASSPHRASE_REQUEST, core.makeEvent({
|
|
202
|
+
message_type: core.Events.PASSPHRASE_REQUEST,
|
|
203
|
+
from_wallet: true,
|
|
204
|
+
}));
|
|
205
|
+
this.userActionRequired = true;
|
|
206
|
+
return this.handleCancellableResponse();
|
|
207
|
+
}
|
|
208
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_CHARACTERREQUEST) {
|
|
209
|
+
this.emit(core.Events.CHARACTER_REQUEST, core.makeEvent({
|
|
210
|
+
message_type: core.Events.CHARACTER_REQUEST,
|
|
211
|
+
from_wallet: true,
|
|
212
|
+
}));
|
|
213
|
+
this.userActionRequired = true;
|
|
214
|
+
return this.handleCancellableResponse();
|
|
215
|
+
}
|
|
216
|
+
if (msgTypeEnum === Messages.MessageType.MESSAGETYPE_WORDREQUEST) {
|
|
217
|
+
this.emit(core.Events.WORD_REQUEST, core.makeEvent({
|
|
218
|
+
message_type: core.Events.WORD_REQUEST,
|
|
219
|
+
from_wallet: true,
|
|
220
|
+
}));
|
|
221
|
+
this.userActionRequired = true;
|
|
222
|
+
return this.handleCancellableResponse();
|
|
223
|
+
}
|
|
224
|
+
return event;
|
|
225
|
+
}
|
|
226
|
+
async call(msgTypeEnum, msg, options) {
|
|
227
|
+
options ??= {};
|
|
228
|
+
options.msgTimeout ??= core.DEFAULT_TIMEOUT;
|
|
229
|
+
this.emit(String(msgTypeEnum), core.makeEvent({
|
|
230
|
+
message_type: typeRegistry_1.messageNameRegistry[msgTypeEnum],
|
|
231
|
+
message_enum: msgTypeEnum,
|
|
232
|
+
message: msg.toObject(),
|
|
233
|
+
proto: msg,
|
|
234
|
+
from_wallet: false,
|
|
235
|
+
}));
|
|
236
|
+
const makePromise = async () => {
|
|
237
|
+
if ([
|
|
238
|
+
Messages.MessageType.MESSAGETYPE_BUTTONACK,
|
|
239
|
+
Messages.MessageType.MESSAGETYPE_PASSPHRASEACK,
|
|
240
|
+
Messages.MessageType.MESSAGETYPE_CHARACTERACK,
|
|
241
|
+
Messages.MessageType.MESSAGETYPE_PINMATRIXACK,
|
|
242
|
+
Messages.MessageType.MESSAGETYPE_WORDACK,
|
|
243
|
+
].includes(msgTypeEnum)) {
|
|
244
|
+
this.userActionRequired = true;
|
|
245
|
+
}
|
|
246
|
+
await this.write(this.toMessageBuffer(msgTypeEnum, msg), !!options?.debugLink);
|
|
247
|
+
if (options?.noWait)
|
|
248
|
+
return undefined;
|
|
249
|
+
const response = await this.readResponse(!!options?.debugLink);
|
|
250
|
+
this.userActionRequired = false;
|
|
251
|
+
if (response.message_enum === Messages.MessageType.MESSAGETYPE_FAILURE &&
|
|
252
|
+
response.message.code === Types.FailureType.FAILURE_ACTIONCANCELLED) {
|
|
253
|
+
this.callInProgress = { main: undefined, debug: undefined };
|
|
254
|
+
throw new core.ActionCancelled();
|
|
255
|
+
}
|
|
256
|
+
if (response.message_type === core.Events.FAILURE)
|
|
257
|
+
throw response;
|
|
258
|
+
return response;
|
|
259
|
+
};
|
|
260
|
+
if (options?.omitLock)
|
|
261
|
+
return makePromise();
|
|
262
|
+
// See the comments in hdwallet-trezor-connect's call for why this weird
|
|
263
|
+
// sequence. We've got a very similar issue here that needs pretty much
|
|
264
|
+
// the same solution.
|
|
265
|
+
const lockKey = options?.debugLink ? 'debug' : 'main';
|
|
266
|
+
this.callInProgress[lockKey] = (async () => {
|
|
267
|
+
await this.cancellable(this.callInProgress[lockKey]);
|
|
268
|
+
try {
|
|
269
|
+
return makePromise();
|
|
270
|
+
}
|
|
271
|
+
finally {
|
|
272
|
+
this.userActionRequired = false;
|
|
273
|
+
}
|
|
274
|
+
})();
|
|
275
|
+
return await this.callInProgress[lockKey];
|
|
276
|
+
}
|
|
277
|
+
async cancel() {
|
|
278
|
+
if (!this.userActionRequired)
|
|
279
|
+
return;
|
|
280
|
+
try {
|
|
281
|
+
this.callInProgress = { main: undefined, debug: undefined };
|
|
282
|
+
const cancelMsg = new Messages.Cancel();
|
|
283
|
+
await this.call(Messages.MessageType.MESSAGETYPE_CANCEL, cancelMsg, {
|
|
284
|
+
omitLock: this.userActionRequired,
|
|
285
|
+
noWait: this.userActionRequired,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
catch (e) {
|
|
289
|
+
console.error('Cancel Pending Error', e);
|
|
290
|
+
}
|
|
291
|
+
finally {
|
|
292
|
+
this.callInProgress = { main: undefined, debug: undefined };
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
toMessageBuffer(msgTypeEnum, msg) {
|
|
296
|
+
const messageBuffer = msg.serializeBinary();
|
|
297
|
+
const headerBuffer = new Uint8Array(8);
|
|
298
|
+
const headerView = new DataView(headerBuffer.buffer);
|
|
299
|
+
headerView.setUint8(0, 0x23);
|
|
300
|
+
headerView.setUint8(1, 0x23);
|
|
301
|
+
headerView.setUint16(2, msgTypeEnum);
|
|
302
|
+
headerView.setUint32(4, messageBuffer.byteLength);
|
|
303
|
+
const fragments = [headerBuffer, messageBuffer];
|
|
304
|
+
const fragmentBuffer = new Uint8Array(fragments.map(x => x.length).reduce((a, x) => a + x, 0));
|
|
305
|
+
fragments.reduce((a, x) => (fragmentBuffer.set(x, a), a + x.length), 0);
|
|
306
|
+
return fragmentBuffer;
|
|
307
|
+
}
|
|
308
|
+
fromMessageBuffer(buf) {
|
|
309
|
+
const typeID = new DataView(buf.buffer).getUint16(3);
|
|
310
|
+
const MType = typeRegistry_1.messageTypeRegistry[typeID];
|
|
311
|
+
if (!MType) {
|
|
312
|
+
const msg = new Messages.Failure();
|
|
313
|
+
msg.setCode(Types.FailureType.FAILURE_UNEXPECTEDMESSAGE);
|
|
314
|
+
msg.setMessage('Unknown message type received');
|
|
315
|
+
return [Messages.MessageType.MESSAGETYPE_FAILURE, msg];
|
|
316
|
+
}
|
|
317
|
+
const msg = new MType();
|
|
318
|
+
const reader = new jspb.BinaryReader(buf, 9, buf.length - 9);
|
|
319
|
+
return [typeID, MType.deserializeBinaryFromReader(msg, reader)];
|
|
320
|
+
}
|
|
321
|
+
static failureMessageFactory(e) {
|
|
322
|
+
const msg = new Messages.Failure();
|
|
323
|
+
msg.setCode(Types.FailureType.FAILURE_UNEXPECTEDMESSAGE);
|
|
324
|
+
if (typeof e === 'string') {
|
|
325
|
+
msg.setMessage(e);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
msg.setMessage(String(e));
|
|
329
|
+
}
|
|
330
|
+
return msg.serializeBinary();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
exports.Transport = Transport;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import * as core from
|
|
2
|
-
import * as jspb from
|
|
1
|
+
import type * as core from '@shapeshiftoss/hdwallet-core';
|
|
2
|
+
import type * as jspb from 'google-protobuf';
|
|
3
3
|
export declare const messageNameRegistry: Record<number, string>;
|
|
4
4
|
export declare const messageTypeRegistry: Record<number, core.Constructor<jspb.Message>>;
|
|
5
|
-
//# sourceMappingURL=typeRegistry.d.ts.map
|
|
@@ -37,27 +37,40 @@ const RippleMessages = __importStar(require("@keepkey/device-protocol/lib/messag
|
|
|
37
37
|
const ThorchainMessages = __importStar(require("@keepkey/device-protocol/lib/messages-thorchain_pb"));
|
|
38
38
|
const omit_1 = __importDefault(require("lodash/omit"));
|
|
39
39
|
// Conflict between typedef and actual js export
|
|
40
|
+
// When CJS modules are loaded in ESM context (e.g. vitest), `import * as X`
|
|
41
|
+
// creates a namespace with only `default` and `module.exports` as enumerable keys.
|
|
42
|
+
// Property access (X.Foo) works via proxy, but Object.entries() does not enumerate them.
|
|
43
|
+
// Access the underlying CJS module.exports via `.default` for proper enumeration.
|
|
44
|
+
const unwrapCjsModule = (mod) => mod.default ?? mod;
|
|
45
|
+
const MessagesUnwrapped = unwrapCjsModule(Messages);
|
|
46
|
+
const BinanceMessagesUnwrapped = unwrapCjsModule(BinanceMessages);
|
|
47
|
+
const CosmosMessagesUnwrapped = unwrapCjsModule(CosmosMessages);
|
|
48
|
+
const EosMessagesUnwrapped = unwrapCjsModule(EosMessages);
|
|
49
|
+
const MayachainMessagesUnwrapped = unwrapCjsModule(MayachainMessages);
|
|
50
|
+
const NanoMessagesUnwrapped = unwrapCjsModule(NanoMessages);
|
|
51
|
+
const RippleMessagesUnwrapped = unwrapCjsModule(RippleMessages);
|
|
52
|
+
const ThorchainMessagesUnwrapped = unwrapCjsModule(ThorchainMessages);
|
|
40
53
|
const AllMessages = []
|
|
41
|
-
.concat(Object.entries((0, omit_1.default)(
|
|
42
|
-
.concat(Object.entries(
|
|
43
|
-
.concat(Object.entries(
|
|
44
|
-
.concat(Object.entries(
|
|
45
|
-
.concat(Object.entries(
|
|
46
|
-
.concat(Object.entries((0, omit_1.default)(
|
|
47
|
-
.concat(Object.entries(
|
|
48
|
-
.concat(Object.entries(
|
|
54
|
+
.concat(Object.entries((0, omit_1.default)(MessagesUnwrapped, 'MessageType', 'MessageTypeMap')))
|
|
55
|
+
.concat(Object.entries(CosmosMessagesUnwrapped))
|
|
56
|
+
.concat(Object.entries(BinanceMessagesUnwrapped))
|
|
57
|
+
.concat(Object.entries(RippleMessagesUnwrapped))
|
|
58
|
+
.concat(Object.entries(NanoMessagesUnwrapped))
|
|
59
|
+
.concat(Object.entries((0, omit_1.default)(EosMessagesUnwrapped, 'EosPublicKeyKind', 'EosPublicKeyKindMap')))
|
|
60
|
+
.concat(Object.entries(ThorchainMessagesUnwrapped))
|
|
61
|
+
.concat(Object.entries(MayachainMessagesUnwrapped));
|
|
49
62
|
const upperCasedMessageClasses = AllMessages.reduce((registry, entry) => {
|
|
50
63
|
registry[entry[0].toUpperCase()] = entry[1];
|
|
51
64
|
return registry;
|
|
52
65
|
}, {});
|
|
53
66
|
// Map of message type enums to human readable message name
|
|
54
|
-
exports.messageNameRegistry = Object.entries(Messages.MessageType).reduce((registry, entry) => {
|
|
55
|
-
registry[entry[1]] = entry[0].split(
|
|
67
|
+
exports.messageNameRegistry = Object.entries(unwrapCjsModule(Messages).MessageType).reduce((registry, entry) => {
|
|
68
|
+
registry[entry[1]] = entry[0].split('_')[1] ?? '';
|
|
56
69
|
return registry;
|
|
57
70
|
}, {});
|
|
58
71
|
// Map of message type enum to their protobuf constructor
|
|
59
|
-
exports.messageTypeRegistry = Object.entries(Messages.MessageType).reduce((registry, entry) => {
|
|
60
|
-
|
|
72
|
+
exports.messageTypeRegistry = Object.entries(unwrapCjsModule(Messages).MessageType).reduce((registry, entry) => {
|
|
73
|
+
const part = entry[0].split('_')[1] ?? '';
|
|
74
|
+
registry[entry[1]] = upperCasedMessageClasses[part.toUpperCase()];
|
|
61
75
|
return registry;
|
|
62
76
|
}, {});
|
|
63
|
-
//# sourceMappingURL=typeRegistry.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as core from
|
|
1
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
2
2
|
export declare const SEGMENT_SIZE = 63;
|
|
3
3
|
export declare function protoFieldToSetMethod(fieldName: string): string;
|
|
4
4
|
export declare function toUTF8Array(str: string): Uint8Array;
|
|
5
5
|
export declare function translateInputScriptType(scriptType: core.BTCInputScriptType): any;
|
|
6
6
|
export declare function translateOutputScriptType(scriptType: core.BTCOutputScriptType): any;
|
|
7
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -23,11 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.SEGMENT_SIZE = void 0;
|
|
27
|
-
exports.protoFieldToSetMethod = protoFieldToSetMethod;
|
|
28
|
-
exports.toUTF8Array = toUTF8Array;
|
|
29
|
-
exports.translateInputScriptType = translateInputScriptType;
|
|
30
|
-
exports.translateOutputScriptType = translateOutputScriptType;
|
|
26
|
+
exports.translateOutputScriptType = exports.translateInputScriptType = exports.toUTF8Array = exports.protoFieldToSetMethod = exports.SEGMENT_SIZE = void 0;
|
|
31
27
|
const Types = __importStar(require("@keepkey/device-protocol/lib/types_pb"));
|
|
32
28
|
const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
|
|
33
29
|
exports.SEGMENT_SIZE = 63;
|
|
@@ -35,6 +31,7 @@ exports.SEGMENT_SIZE = 63;
|
|
|
35
31
|
function protoFieldToSetMethod(fieldName) {
|
|
36
32
|
return `set${fieldName.charAt(0).toUpperCase() + fieldName.slice(1)}`;
|
|
37
33
|
}
|
|
34
|
+
exports.protoFieldToSetMethod = protoFieldToSetMethod;
|
|
38
35
|
// https://gist.github.com/joni/3760795/8f0c1a608b7f0c8b3978db68105c5b1d741d0446
|
|
39
36
|
function toUTF8Array(str) {
|
|
40
37
|
const utf8 = [];
|
|
@@ -57,6 +54,7 @@ function toUTF8Array(str) {
|
|
|
57
54
|
}
|
|
58
55
|
return new Uint8Array(utf8);
|
|
59
56
|
}
|
|
57
|
+
exports.toUTF8Array = toUTF8Array;
|
|
60
58
|
function translateInputScriptType(scriptType) {
|
|
61
59
|
switch (scriptType) {
|
|
62
60
|
case core.BTCInputScriptType.CashAddr:
|
|
@@ -69,8 +67,9 @@ function translateInputScriptType(scriptType) {
|
|
|
69
67
|
case core.BTCInputScriptType.SpendWitness:
|
|
70
68
|
return Types.InputScriptType.SPENDWITNESS;
|
|
71
69
|
}
|
|
72
|
-
throw new Error(
|
|
70
|
+
throw new Error('unhandled InputSriptType enum: ' + scriptType);
|
|
73
71
|
}
|
|
72
|
+
exports.translateInputScriptType = translateInputScriptType;
|
|
74
73
|
function translateOutputScriptType(scriptType) {
|
|
75
74
|
switch (scriptType) {
|
|
76
75
|
case core.BTCOutputScriptType.PayToAddress:
|
|
@@ -82,6 +81,6 @@ function translateOutputScriptType(scriptType) {
|
|
|
82
81
|
case core.BTCOutputScriptType.PayToWitness:
|
|
83
82
|
return Types.OutputScriptType.PAYTOWITNESS;
|
|
84
83
|
}
|
|
85
|
-
throw new Error(
|
|
84
|
+
throw new Error('unhandled OutputScriptType enum: ' + scriptType);
|
|
86
85
|
}
|
|
87
|
-
|
|
86
|
+
exports.translateOutputScriptType = translateOutputScriptType;
|