@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
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as CosmosMessages from
|
|
2
|
-
import * as core from
|
|
3
|
-
import { Transport } from
|
|
4
|
-
export declare function cosmosGetAccountPaths(msg: core.CosmosGetAccountPaths):
|
|
1
|
+
import * as CosmosMessages from '@keepkey/device-protocol/lib/messages-cosmos_pb';
|
|
2
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
3
|
+
import type { Transport } from './transport';
|
|
4
|
+
export declare function cosmosGetAccountPaths(msg: core.CosmosGetAccountPaths): core.CosmosAccountPath[];
|
|
5
5
|
export declare function cosmosGetAddress(transport: Transport, msg: CosmosMessages.CosmosGetAddress.AsObject): Promise<string>;
|
|
6
6
|
export declare function cosmosSignTx(transport: Transport, msg: core.CosmosSignTx): Promise<any>;
|
|
7
|
-
//# sourceMappingURL=cosmos.d.ts.map
|
|
@@ -0,0 +1,219 @@
|
|
|
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.cosmosSignTx = exports.cosmosGetAddress = exports.cosmosGetAccountPaths = void 0;
|
|
30
|
+
const Messages = __importStar(require("@keepkey/device-protocol/lib/messages_pb"));
|
|
31
|
+
const CosmosMessages = __importStar(require("@keepkey/device-protocol/lib/messages-cosmos_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 cosmosGetAccountPaths(msg) {
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
addressNList: [
|
|
40
|
+
0x80000000 + 44,
|
|
41
|
+
0x80000000 + core.slip44ByCoin('Atom'),
|
|
42
|
+
0x80000000 + msg.accountIdx,
|
|
43
|
+
0,
|
|
44
|
+
0,
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
exports.cosmosGetAccountPaths = cosmosGetAccountPaths;
|
|
50
|
+
async function cosmosGetAddress(transport, msg) {
|
|
51
|
+
const getAddr = new CosmosMessages.CosmosGetAddress();
|
|
52
|
+
getAddr.setAddressNList(msg.addressNList);
|
|
53
|
+
getAddr.setShowDisplay(msg.showDisplay !== false);
|
|
54
|
+
const response = await transport.call(Messages.MessageType.MESSAGETYPE_COSMOSGETADDRESS, getAddr, {
|
|
55
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
56
|
+
});
|
|
57
|
+
const cosmosAddress = response.proto;
|
|
58
|
+
return core.mustBeDefined(cosmosAddress.getAddress());
|
|
59
|
+
}
|
|
60
|
+
exports.cosmosGetAddress = cosmosGetAddress;
|
|
61
|
+
async function cosmosSignTx(transport, msg) {
|
|
62
|
+
const address = await cosmosGetAddress(transport, { addressNList: msg.addressNList });
|
|
63
|
+
const getPublicKeyMsg = new Messages.GetPublicKey();
|
|
64
|
+
getPublicKeyMsg.setAddressNList(msg.addressNList);
|
|
65
|
+
getPublicKeyMsg.setEcdsaCurveName('secp256k1');
|
|
66
|
+
const pubkeyMsg = (await transport.call(Messages.MessageType.MESSAGETYPE_GETPUBLICKEY, getPublicKeyMsg, {
|
|
67
|
+
msgTimeout: core.DEFAULT_TIMEOUT,
|
|
68
|
+
})).proto;
|
|
69
|
+
const pubkey = bs58check_1.default.decode(core.mustBeDefined(pubkeyMsg.getXpub())).slice(45);
|
|
70
|
+
return transport.lockDuring(async () => {
|
|
71
|
+
const signTx = new CosmosMessages.CosmosSignTx();
|
|
72
|
+
signTx.setAddressNList(msg.addressNList);
|
|
73
|
+
signTx.setAccountNumber(msg.account_number);
|
|
74
|
+
signTx.setChainId(msg.chain_id);
|
|
75
|
+
signTx.setFeeAmount(parseInt(msg.tx.fee.amount[0].amount));
|
|
76
|
+
signTx.setGas(parseInt(msg.tx.fee.gas));
|
|
77
|
+
signTx.setSequence(msg.sequence);
|
|
78
|
+
if (msg.tx.memo !== undefined) {
|
|
79
|
+
signTx.setMemo(msg.tx.memo);
|
|
80
|
+
}
|
|
81
|
+
signTx.setMsgCount(1);
|
|
82
|
+
let resp = await transport.call(Messages.MessageType.MESSAGETYPE_COSMOSSIGNTX, signTx, {
|
|
83
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
84
|
+
omitLock: true,
|
|
85
|
+
});
|
|
86
|
+
for (const m of msg.tx.msg) {
|
|
87
|
+
if (resp.message_enum !== Messages.MessageType.MESSAGETYPE_COSMOSMSGREQUEST) {
|
|
88
|
+
throw new Error(`cosmos: unexpected response ${resp.message_type}`);
|
|
89
|
+
}
|
|
90
|
+
let ack;
|
|
91
|
+
if (m.type === 'cosmos-sdk/MsgSend') {
|
|
92
|
+
if (m.value.amount.length !== 1) {
|
|
93
|
+
throw new Error('cosmos: Multiple amounts per msg not supported');
|
|
94
|
+
}
|
|
95
|
+
const denom = m.value.amount[0].denom;
|
|
96
|
+
if (denom !== 'uatom') {
|
|
97
|
+
throw new Error('cosmos: Unsupported denomination: ' + denom);
|
|
98
|
+
}
|
|
99
|
+
const send = new CosmosMessages.CosmosMsgSend();
|
|
100
|
+
send.setFromAddress(m.value.from_address);
|
|
101
|
+
send.setToAddress(m.value.to_address);
|
|
102
|
+
send.setAmount(m.value.amount[0].amount);
|
|
103
|
+
ack = new CosmosMessages.CosmosMsgAck();
|
|
104
|
+
ack.setSend(send);
|
|
105
|
+
}
|
|
106
|
+
else if (m.type === 'cosmos-sdk/MsgDelegate') {
|
|
107
|
+
const denom = m.value.amount.denom;
|
|
108
|
+
if (denom !== 'uatom') {
|
|
109
|
+
throw new Error('cosmos: Unsupported denomination: ' + denom);
|
|
110
|
+
}
|
|
111
|
+
const delegate = new CosmosMessages.CosmosMsgDelegate();
|
|
112
|
+
delegate.setDelegatorAddress(m.value.delegator_address);
|
|
113
|
+
delegate.setValidatorAddress(m.value.validator_address);
|
|
114
|
+
delegate.setAmount(m.value.amount.amount);
|
|
115
|
+
ack = new CosmosMessages.CosmosMsgAck();
|
|
116
|
+
ack.setDelegate(delegate);
|
|
117
|
+
}
|
|
118
|
+
else if (m.type === 'cosmos-sdk/MsgUndelegate') {
|
|
119
|
+
const denom = m.value.amount.denom;
|
|
120
|
+
if (denom !== 'uatom') {
|
|
121
|
+
throw new Error('cosmos: Unsupported denomination: ' + denom);
|
|
122
|
+
}
|
|
123
|
+
const undelegate = new CosmosMessages.CosmosMsgUndelegate();
|
|
124
|
+
undelegate.setDelegatorAddress(m.value.delegator_address);
|
|
125
|
+
undelegate.setValidatorAddress(m.value.validator_address);
|
|
126
|
+
undelegate.setAmount(m.value.amount.amount);
|
|
127
|
+
ack = new CosmosMessages.CosmosMsgAck();
|
|
128
|
+
ack.setUndelegate(undelegate);
|
|
129
|
+
}
|
|
130
|
+
else if (m.type === 'cosmos-sdk/MsgBeginRedelegate') {
|
|
131
|
+
const denom = m.value.amount.denom;
|
|
132
|
+
if (denom !== 'uatom') {
|
|
133
|
+
throw new Error('cosmos: Unsupported denomination: ' + denom);
|
|
134
|
+
}
|
|
135
|
+
const redelegate = new CosmosMessages.CosmosMsgRedelegate();
|
|
136
|
+
redelegate.setDelegatorAddress(m.value.delegator_address);
|
|
137
|
+
redelegate.setValidatorSrcAddress(m.value.validator_src_address);
|
|
138
|
+
redelegate.setValidatorDstAddress(m.value.validator_dst_address);
|
|
139
|
+
redelegate.setAmount(m.value.amount.amount);
|
|
140
|
+
ack = new CosmosMessages.CosmosMsgAck();
|
|
141
|
+
ack.setRedelegate(redelegate);
|
|
142
|
+
}
|
|
143
|
+
else if (m.type === 'cosmos-sdk/MsgWithdrawDelegationReward') {
|
|
144
|
+
const rewards = new CosmosMessages.CosmosMsgRewards();
|
|
145
|
+
rewards.setDelegatorAddress(m.value.delegator_address);
|
|
146
|
+
rewards.setValidatorAddress(m.value.validator_address);
|
|
147
|
+
if (m.value.amount) {
|
|
148
|
+
const denom = m.value.amount.denom;
|
|
149
|
+
if (denom !== 'uatom') {
|
|
150
|
+
throw new Error('cosmos: Unsupported denomination: ' + denom);
|
|
151
|
+
}
|
|
152
|
+
rewards.setAmount(m.value.amount.amount);
|
|
153
|
+
}
|
|
154
|
+
ack = new CosmosMessages.CosmosMsgAck();
|
|
155
|
+
ack.setRewards(rewards);
|
|
156
|
+
}
|
|
157
|
+
else if (m.type === 'cosmos-sdk/MsgTransfer') {
|
|
158
|
+
const denom = m.value.token.denom;
|
|
159
|
+
if (denom !== 'uatom') {
|
|
160
|
+
throw new Error('cosmos: Unsupported denomination: ' + denom);
|
|
161
|
+
}
|
|
162
|
+
const ibcTransfer = new CosmosMessages.CosmosMsgIBCTransfer();
|
|
163
|
+
ibcTransfer.setReceiver(m.value.receiver);
|
|
164
|
+
ibcTransfer.setSender(m.value.sender);
|
|
165
|
+
ibcTransfer.setSourceChannel(m.value.source_channel);
|
|
166
|
+
ibcTransfer.setSourcePort(m.value.source_port);
|
|
167
|
+
ibcTransfer.setRevisionHeight(m.value.timeout_height.revision_height);
|
|
168
|
+
ibcTransfer.setRevisionNumber(m.value.timeout_height.revision_number);
|
|
169
|
+
ibcTransfer.setAmount(m.value.token.amount);
|
|
170
|
+
ibcTransfer.setDenom(m.value.token.denom);
|
|
171
|
+
ack = new CosmosMessages.CosmosMsgAck();
|
|
172
|
+
ack.setIbcTransfer(ibcTransfer);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
throw new Error(`cosmos: Message ${m.type} is not yet supported`);
|
|
176
|
+
}
|
|
177
|
+
resp = await transport.call(Messages.MessageType.MESSAGETYPE_COSMOSMSGACK, ack, {
|
|
178
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
179
|
+
omitLock: true,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (resp.message_enum !== Messages.MessageType.MESSAGETYPE_COSMOSSIGNEDTX) {
|
|
183
|
+
throw new Error(`cosmos: unexpected response ${resp.message_type}`);
|
|
184
|
+
}
|
|
185
|
+
const signedTx = resp.proto;
|
|
186
|
+
const offlineSigner = {
|
|
187
|
+
async getAccounts() {
|
|
188
|
+
return [
|
|
189
|
+
{
|
|
190
|
+
address,
|
|
191
|
+
algo: 'secp256k1',
|
|
192
|
+
pubkey,
|
|
193
|
+
},
|
|
194
|
+
];
|
|
195
|
+
},
|
|
196
|
+
async signAmino(signerAddress, signDoc) {
|
|
197
|
+
if (signerAddress !== address)
|
|
198
|
+
throw new Error('expected signerAddress to match address');
|
|
199
|
+
return {
|
|
200
|
+
signed: signDoc,
|
|
201
|
+
signature: {
|
|
202
|
+
pub_key: {
|
|
203
|
+
type: 'tendermint/PubKeySecp256k1',
|
|
204
|
+
value: signedTx.getPublicKey_asB64(),
|
|
205
|
+
},
|
|
206
|
+
signature: signedTx.getSignature_asB64(),
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
const signerData = {
|
|
212
|
+
sequence: Number(msg.sequence),
|
|
213
|
+
accountNumber: Number(msg.account_number),
|
|
214
|
+
chainId: msg.chain_id,
|
|
215
|
+
};
|
|
216
|
+
return (await protoTxBuilder).sign(address, msg.tx, offlineSigner, signerData, 'cosmos');
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
exports.cosmosSignTx = cosmosSignTx;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as core from
|
|
2
|
-
import { Transport } from
|
|
3
|
-
export declare function eosGetAccountPaths(msg: core.EosGetAccountPaths):
|
|
1
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
2
|
+
import type { Transport } from './transport';
|
|
3
|
+
export declare function eosGetAccountPaths(msg: core.EosGetAccountPaths): core.EosAccountPath[];
|
|
4
4
|
export declare function eosGetPublicKey(transport: Transport, msg: core.EosGetPublicKey): Promise<string>;
|
|
5
5
|
export declare function eosSignTx(transport: Transport, msg: core.EosToSignTx): Promise<core.EosTxSigned>;
|
|
6
|
-
//# sourceMappingURL=eos.d.ts.map
|
package/dist/cjs/eos.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
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.eosSignTx = exports.eosGetPublicKey = exports.eosGetAccountPaths = void 0;
|
|
30
|
+
const Messages = __importStar(require("@keepkey/device-protocol/lib/messages_pb"));
|
|
31
|
+
const EosMessages = __importStar(require("@keepkey/device-protocol/lib/messages-eos_pb"));
|
|
32
|
+
const core = __importStar(require("@shapeshiftoss/hdwallet-core"));
|
|
33
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
34
|
+
const create_hash_1 = __importDefault(require("create-hash"));
|
|
35
|
+
const long_1 = __importDefault(require("long"));
|
|
36
|
+
function eosSigFormatter(r, s, _v) {
|
|
37
|
+
const recoverId = 0x1f;
|
|
38
|
+
let signature = 'SIG_K1_';
|
|
39
|
+
console.debug('formatter logs');
|
|
40
|
+
const keyBuffer = Buffer.alloc(65);
|
|
41
|
+
const rbuf = Buffer.from(r);
|
|
42
|
+
const sbuf = Buffer.from(s);
|
|
43
|
+
keyBuffer.writeUInt8(recoverId, 0);
|
|
44
|
+
rbuf.copy(keyBuffer, 1);
|
|
45
|
+
sbuf.copy(keyBuffer, 33);
|
|
46
|
+
console.debug(keyBuffer);
|
|
47
|
+
const check = [keyBuffer];
|
|
48
|
+
const keyType = 'K1'; // we only sign using K1 curve
|
|
49
|
+
check.push(Buffer.from(keyType));
|
|
50
|
+
console.debug(check);
|
|
51
|
+
console.debug('hash');
|
|
52
|
+
console.debug((0, create_hash_1.default)('ripemd160').update(core.compatibleBufferConcat(check)).digest());
|
|
53
|
+
const chksum = (0, create_hash_1.default)('ripemd160')
|
|
54
|
+
.update(core.compatibleBufferConcat(check))
|
|
55
|
+
.digest()
|
|
56
|
+
.slice(0, 4);
|
|
57
|
+
console.debug(chksum);
|
|
58
|
+
signature = signature.concat(bs58_1.default.encode(core.compatibleBufferConcat([keyBuffer, chksum])));
|
|
59
|
+
console.debug(signature);
|
|
60
|
+
return signature;
|
|
61
|
+
}
|
|
62
|
+
function charToSymbol(c) {
|
|
63
|
+
if (c.charCodeAt(0) >= 'a'.charCodeAt(0) && c.charCodeAt(0) <= 'z'.charCodeAt(0)) {
|
|
64
|
+
return c.charCodeAt(0) - 'a'.charCodeAt(0) + 6;
|
|
65
|
+
}
|
|
66
|
+
if (c.charCodeAt(0) >= '1'.charCodeAt(0) && c.charCodeAt(0) <= '5'.charCodeAt(0)) {
|
|
67
|
+
return c.charCodeAt(0) - '1'.charCodeAt(0) + 1;
|
|
68
|
+
}
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
function nameToNumber(name) {
|
|
72
|
+
let value = new long_1.default(0, 0, true);
|
|
73
|
+
let c = new long_1.default(0, 0, true);
|
|
74
|
+
for (let i = 0; i < 13; i++) {
|
|
75
|
+
if (i < name.length && i < 13) {
|
|
76
|
+
c = long_1.default.fromNumber(charToSymbol(name[i]), true);
|
|
77
|
+
}
|
|
78
|
+
if (i < 12) {
|
|
79
|
+
c = c.and(long_1.default.fromString('1f', true, 16));
|
|
80
|
+
c = c.shl(64 - 5 * (i + 1));
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// last iteration
|
|
84
|
+
c = c.and(long_1.default.fromString('0f', true, 16));
|
|
85
|
+
}
|
|
86
|
+
value = value.or(c);
|
|
87
|
+
}
|
|
88
|
+
return value.toString();
|
|
89
|
+
}
|
|
90
|
+
function symbolFromString(p, name) {
|
|
91
|
+
let result = 0;
|
|
92
|
+
for (let i = 0; i < name.length; i++) {
|
|
93
|
+
result |= name.charCodeAt(i) << (8 * (i + 1));
|
|
94
|
+
}
|
|
95
|
+
result |= p;
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
function assetToNumber(asset) {
|
|
99
|
+
const assetSplit = asset.split(' '); // amount, symbol
|
|
100
|
+
const amountStr = assetSplit[0] ?? '';
|
|
101
|
+
const symbolStr = assetSplit[1] ?? '';
|
|
102
|
+
const dot_pos = amountStr.indexOf('.');
|
|
103
|
+
let fract_part = 0;
|
|
104
|
+
let int_part = 0;
|
|
105
|
+
let precision_digit = 0;
|
|
106
|
+
// parse symbol
|
|
107
|
+
if (dot_pos != -1) {
|
|
108
|
+
precision_digit = amountStr.length - dot_pos - 1;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
precision_digit = 0;
|
|
112
|
+
}
|
|
113
|
+
const sym = symbolFromString(precision_digit, symbolStr);
|
|
114
|
+
//parse amount
|
|
115
|
+
if (dot_pos != -1) {
|
|
116
|
+
int_part = parseInt(amountStr.slice(0, dot_pos));
|
|
117
|
+
fract_part = parseInt(amountStr.slice(dot_pos + 1));
|
|
118
|
+
if (int_part < 0) {
|
|
119
|
+
fract_part *= -1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
int_part = parseInt(amountStr);
|
|
124
|
+
}
|
|
125
|
+
let amount = int_part;
|
|
126
|
+
amount *= Math.pow(10, sym & 0xff);
|
|
127
|
+
amount += fract_part;
|
|
128
|
+
return [amount, sym];
|
|
129
|
+
}
|
|
130
|
+
function eosGetAccountPaths(msg) {
|
|
131
|
+
return [
|
|
132
|
+
{
|
|
133
|
+
addressNList: [
|
|
134
|
+
0x80000000 + 44,
|
|
135
|
+
0x80000000 + core.slip44ByCoin('Eos'),
|
|
136
|
+
0x80000000 + msg.accountIdx,
|
|
137
|
+
0,
|
|
138
|
+
0,
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
exports.eosGetAccountPaths = eosGetAccountPaths;
|
|
144
|
+
async function eosGetPublicKey(transport, msg) {
|
|
145
|
+
const getPubkey = new EosMessages.EosGetPublicKey();
|
|
146
|
+
getPubkey.setAddressNList(msg.addressNList);
|
|
147
|
+
getPubkey.setShowDisplay(msg.showDisplay !== false);
|
|
148
|
+
getPubkey.setKind(msg.kind);
|
|
149
|
+
const response = await transport.call(Messages.MessageType.MESSAGETYPE_EOSGETPUBLICKEY, getPubkey, {
|
|
150
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
151
|
+
});
|
|
152
|
+
const eosPubkey = response.proto;
|
|
153
|
+
return core.mustBeDefined(eosPubkey.getWifPublicKey());
|
|
154
|
+
}
|
|
155
|
+
exports.eosGetPublicKey = eosGetPublicKey;
|
|
156
|
+
async function eosSignTx(transport, msg) {
|
|
157
|
+
return transport.lockDuring(async () => {
|
|
158
|
+
let resp;
|
|
159
|
+
// check some params
|
|
160
|
+
if (msg.tx.actions.length > 1) {
|
|
161
|
+
throw new Error(`Too many actions in Eos transaction: Keepkey only supports one!`);
|
|
162
|
+
}
|
|
163
|
+
const signTx = new EosMessages.EosSignTx();
|
|
164
|
+
signTx.setAddressNList(msg.addressNList);
|
|
165
|
+
signTx.setChainId(core.fromHexString(msg.chain_id));
|
|
166
|
+
const txHeader = new EosMessages.EosTxHeader();
|
|
167
|
+
txHeader.setExpiration((Date.parse(msg.tx.expiration) -
|
|
168
|
+
Date.parse('01 Jan 1970 00:00:00Z') -
|
|
169
|
+
new Date().getTimezoneOffset() * 60 * 1000) /
|
|
170
|
+
1000);
|
|
171
|
+
txHeader.setRefBlockNum(msg.tx.ref_block_num);
|
|
172
|
+
txHeader.setRefBlockPrefix(msg.tx.ref_block_prefix);
|
|
173
|
+
txHeader.setMaxNetUsageWords(msg.tx.max_net_usage_words);
|
|
174
|
+
txHeader.setMaxCpuUsageMs(msg.tx.max_cpu_usage_ms);
|
|
175
|
+
txHeader.setDelaySec(msg.tx.delay_sec);
|
|
176
|
+
signTx.setHeader(txHeader);
|
|
177
|
+
signTx.setNumActions(msg.tx.actions.length);
|
|
178
|
+
console.debug('tx header');
|
|
179
|
+
console.debug(txHeader);
|
|
180
|
+
resp = await transport.call(Messages.MessageType.MESSAGETYPE_EOSSIGNTX, signTx, {
|
|
181
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
182
|
+
omitLock: true,
|
|
183
|
+
});
|
|
184
|
+
if (resp.message_enum !== Messages.MessageType.MESSAGETYPE_EOSTXACTIONREQUEST) {
|
|
185
|
+
throw new Error(`eos: unexpected response ${resp.message_type}`);
|
|
186
|
+
}
|
|
187
|
+
// parse the common block of the action
|
|
188
|
+
const actCommon = new EosMessages.EosActionCommon();
|
|
189
|
+
actCommon.setAccount(nameToNumber(msg.tx.actions[0].account).toString());
|
|
190
|
+
actCommon.setName(nameToNumber(msg.tx.actions[0].name).toString());
|
|
191
|
+
// interate through authorizations and add them
|
|
192
|
+
for (let n = 0; n < msg.tx.actions[0].authorization.length; n++) {
|
|
193
|
+
const actPerm = new EosMessages.EosPermissionLevel();
|
|
194
|
+
actPerm.setActor(nameToNumber(msg.tx.actions[0].authorization[n].actor).toString());
|
|
195
|
+
actPerm.setPermission(nameToNumber(msg.tx.actions[0].authorization[n].permission).toString());
|
|
196
|
+
actCommon.addAuthorization(actPerm);
|
|
197
|
+
}
|
|
198
|
+
const actAck = new EosMessages.EosTxActionAck();
|
|
199
|
+
actAck.setCommon(actCommon);
|
|
200
|
+
// parse the various action types here.
|
|
201
|
+
switch (msg.tx.actions[0].name) {
|
|
202
|
+
case 'transfer': {
|
|
203
|
+
// build the transfer action
|
|
204
|
+
const actType = new EosMessages.EosActionTransfer();
|
|
205
|
+
actType.setSender(nameToNumber(msg.tx.actions[0].data.from).toString());
|
|
206
|
+
actType.setReceiver(nameToNumber(msg.tx.actions[0].data.to).toString());
|
|
207
|
+
const actAsset = new EosMessages.EosAsset();
|
|
208
|
+
const assetParse = assetToNumber(msg.tx.actions[0].data.quantity);
|
|
209
|
+
actAsset.setAmount(assetParse[0].toString());
|
|
210
|
+
actAsset.setSymbol(assetParse[1].toString());
|
|
211
|
+
actType.setQuantity(actAsset);
|
|
212
|
+
actType.setMemo(msg.tx.actions[0].data.memo);
|
|
213
|
+
actAck.setTransfer(actType);
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
console.debug('action data');
|
|
218
|
+
console.debug(actAck);
|
|
219
|
+
resp = await transport.call(Messages.MessageType.MESSAGETYPE_EOSTXACTIONACK, actAck, {
|
|
220
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
221
|
+
omitLock: true,
|
|
222
|
+
});
|
|
223
|
+
if (resp.message_enum !== Messages.MessageType.MESSAGETYPE_EOSSIGNEDTX) {
|
|
224
|
+
throw new Error(`eos: unexpected response ${resp.message_type}`);
|
|
225
|
+
}
|
|
226
|
+
const signedTx = resp.proto;
|
|
227
|
+
// format signature for use in the eos system
|
|
228
|
+
// const EosFormatSig = eosSigFormatter(signedTx.getSignatureR() as Uint8Array, signedTx.getSignatureS() as Uint8Array, signedTx.getSignatureV())
|
|
229
|
+
const signatureR = signedTx.getSignatureR_asU8();
|
|
230
|
+
const signatureS = signedTx.getSignatureS_asU8();
|
|
231
|
+
const signatureV = signedTx.getSignatureV();
|
|
232
|
+
if (signatureV === undefined)
|
|
233
|
+
throw new Error('missing signatureV');
|
|
234
|
+
const sig = {
|
|
235
|
+
signatureV,
|
|
236
|
+
signatureR,
|
|
237
|
+
signatureS,
|
|
238
|
+
hash: signedTx.getHash(),
|
|
239
|
+
eosFormSig: eosSigFormatter(signatureR, signatureS, signatureV),
|
|
240
|
+
};
|
|
241
|
+
return sig;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
exports.eosSignTx = eosSignTx;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as core from
|
|
2
|
-
import { Transport } from
|
|
3
|
-
export declare function ethSupportsNetwork(
|
|
1
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
2
|
+
import type { Transport } from './transport';
|
|
3
|
+
export declare function ethSupportsNetwork(_chainId: number): Promise<boolean>;
|
|
4
4
|
export declare function ethSupportsSecureTransfer(): Promise<boolean>;
|
|
5
5
|
export declare function ethSupportsNativeShapeShift(): boolean;
|
|
6
|
-
export declare function ethGetAccountPaths(msg: core.ETHGetAccountPath):
|
|
6
|
+
export declare function ethGetAccountPaths(msg: core.ETHGetAccountPath): core.ETHAccountPath[];
|
|
7
7
|
export declare function ethSignTx(transport: Transport, msg: core.ETHSignTx): Promise<core.ETHSignedTx>;
|
|
8
8
|
export declare function ethGetAddress(transport: Transport, msg: core.ETHGetAddress): Promise<core.Address>;
|
|
9
9
|
export declare function ethSignMessage(transport: Transport, msg: core.ETHSignMessage): Promise<core.ETHSignedMessage>;
|
|
@@ -15,4 +15,3 @@ export declare function ethSignMessage(transport: Transport, msg: core.ETHSignMe
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function ethSignTypedData(transport: Transport, msg: core.ETHSignTypedData): Promise<core.ETHSignedTypedData>;
|
|
17
17
|
export declare function ethVerifyMessage(transport: Transport, msg: core.ETHVerifyMessage): Promise<boolean>;
|
|
18
|
-
//# sourceMappingURL=ethereum.d.ts.map
|