@shapeshiftoss/hdwallet-keepkey 1.62.39 → 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,119 @@
|
|
|
1
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
2
|
+
import { KeepKeyHDWallet } from './keepkey.js';
|
|
3
|
+
import { Transport } from './transport.js';
|
|
4
|
+
export class Adapter {
|
|
5
|
+
keyring;
|
|
6
|
+
delegate;
|
|
7
|
+
constructor(keyring, delegate) {
|
|
8
|
+
this.keyring = keyring;
|
|
9
|
+
this.delegate = delegate;
|
|
10
|
+
try {
|
|
11
|
+
this.delegate.registerCallbacks?.(this.handleConnect.bind(this), this.handleDisconnect.bind(this));
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
console.error(e);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
static fromDelegate(delegate) {
|
|
18
|
+
const fn = (keyring) => new Adapter(keyring, delegate);
|
|
19
|
+
const out = fn;
|
|
20
|
+
out.useKeyring = fn;
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
static async inspectDevice(delegate, device) {
|
|
24
|
+
const props = (await Promise.resolve(delegate.inspectDevice?.(device))) ??
|
|
25
|
+
(['object', 'function'].includes(typeof device) ? device : {});
|
|
26
|
+
if (!props.serialNumber && typeof device === 'string')
|
|
27
|
+
props.serialNumber = device;
|
|
28
|
+
return {
|
|
29
|
+
get productName() {
|
|
30
|
+
const out = props['productName'];
|
|
31
|
+
return typeof out === 'string' ? out : 'KeepKey';
|
|
32
|
+
},
|
|
33
|
+
get serialNumber() {
|
|
34
|
+
const out = props['serialNumber'];
|
|
35
|
+
if (typeof out !== 'string')
|
|
36
|
+
throw new Error('could not get serialNumber from device');
|
|
37
|
+
return out;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async inspectDevice(device) {
|
|
42
|
+
return Adapter.inspectDevice(this.delegate, device);
|
|
43
|
+
}
|
|
44
|
+
async handleConnect(device) {
|
|
45
|
+
try {
|
|
46
|
+
await this.initialize([device]);
|
|
47
|
+
const { productName, serialNumber } = await this.inspectDevice(device);
|
|
48
|
+
await this.keyring.emit([productName, serialNumber, core.Events.CONNECT], serialNumber);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
console.error(e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async handleDisconnect(device) {
|
|
55
|
+
const { productName, serialNumber } = await this.inspectDevice(device);
|
|
56
|
+
try {
|
|
57
|
+
await this.keyring.remove(serialNumber);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// swallow keyring removal errors
|
|
61
|
+
}
|
|
62
|
+
await this.keyring.emit([productName, serialNumber, core.Events.DISCONNECT], serialNumber);
|
|
63
|
+
}
|
|
64
|
+
async initialize(devices, tryDebugLink, autoConnect) {
|
|
65
|
+
devices = devices ?? (await this.getDevices());
|
|
66
|
+
for (const device of devices) {
|
|
67
|
+
const { serialNumber } = await this.inspectDevice(device);
|
|
68
|
+
if (this.keyring.wallets[serialNumber])
|
|
69
|
+
await this.keyring.remove(serialNumber);
|
|
70
|
+
const delegate = await this.getTransportDelegate(device);
|
|
71
|
+
if (delegate === null)
|
|
72
|
+
continue;
|
|
73
|
+
const transport = await Transport.create(this.keyring, delegate);
|
|
74
|
+
await transport.connect();
|
|
75
|
+
if (tryDebugLink)
|
|
76
|
+
await transport.tryConnectDebugLink();
|
|
77
|
+
const wallet = await KeepKeyHDWallet.create(transport);
|
|
78
|
+
if (autoConnect)
|
|
79
|
+
await wallet.initialize();
|
|
80
|
+
this.keyring.add(wallet, serialNumber);
|
|
81
|
+
}
|
|
82
|
+
return Object.keys(this.keyring.wallets).length;
|
|
83
|
+
}
|
|
84
|
+
async getDevice(serialNumber) {
|
|
85
|
+
if (this.delegate.getDevice)
|
|
86
|
+
return await this.delegate.getDevice(serialNumber);
|
|
87
|
+
if (!serialNumber)
|
|
88
|
+
throw new Error('no default device specified');
|
|
89
|
+
const devices = await this.getDevices();
|
|
90
|
+
return (await Promise.all(devices.map(async (x) => (await this.inspectDevice(x)).serialNumber === serialNumber ? x : null))).filter(x => x !== null)[0];
|
|
91
|
+
}
|
|
92
|
+
async getDevices() {
|
|
93
|
+
if (this.delegate.getDevices)
|
|
94
|
+
return await this.delegate.getDevices();
|
|
95
|
+
let defaultDevice = undefined;
|
|
96
|
+
try {
|
|
97
|
+
defaultDevice = await this.getDevice();
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// swallow default device fetch errors
|
|
101
|
+
}
|
|
102
|
+
return defaultDevice ? [defaultDevice] : [];
|
|
103
|
+
}
|
|
104
|
+
async getTransportDelegate(device) {
|
|
105
|
+
return await this.delegate.getTransportDelegate(device);
|
|
106
|
+
}
|
|
107
|
+
async pairDevice(serialNumber, tryDebugLink) {
|
|
108
|
+
const device = await this.getDevice(serialNumber);
|
|
109
|
+
if (!device)
|
|
110
|
+
throw new Error(serialNumber
|
|
111
|
+
? `could not find device matching serial number '${serialNumber}'`
|
|
112
|
+
: 'could not find default device');
|
|
113
|
+
return this.pairRawDevice(device, tryDebugLink);
|
|
114
|
+
}
|
|
115
|
+
async pairRawDevice(device, tryDebugLink) {
|
|
116
|
+
await this.initialize([device], tryDebugLink, true);
|
|
117
|
+
return core.mustBeDefined(this.keyring.get((await this.inspectDevice(device)).serialNumber));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
2
|
+
import type { Transport } from './transport.js';
|
|
3
|
+
export declare function binanceGetAccountPaths(msg: core.BinanceGetAccountPaths): core.BinanceAccountPath[];
|
|
4
|
+
export declare function binanceSignTx(transport: Transport, msg: core.BinanceSignTx): Promise<core.BinanceSignedTx>;
|
|
5
|
+
export declare function binanceGetAddress(transport: Transport, msg: core.BinanceGetAddress): Promise<string>;
|
|
@@ -0,0 +1,112 @@
|
|
|
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 core from '@shapeshiftoss/hdwallet-core';
|
|
4
|
+
import BigNumber from 'bignumber.js';
|
|
5
|
+
import CryptoJS from 'crypto-js';
|
|
6
|
+
import { encodeBnbTx } from './bnbencoding.js';
|
|
7
|
+
export function binanceGetAccountPaths(msg) {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
addressNList: [
|
|
11
|
+
0x80000000 + 44,
|
|
12
|
+
0x80000000 + core.slip44ByCoin('Binance'),
|
|
13
|
+
0x80000000 + msg.accountIdx,
|
|
14
|
+
0,
|
|
15
|
+
0,
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
export async function binanceSignTx(transport, msg) {
|
|
21
|
+
return transport.lockDuring(async () => {
|
|
22
|
+
if (msg.testnet)
|
|
23
|
+
throw new Error('testnet not supported');
|
|
24
|
+
const partialTx = Object.assign({}, msg.tx);
|
|
25
|
+
if (!partialTx.data)
|
|
26
|
+
partialTx.data = null;
|
|
27
|
+
if (!partialTx.memo)
|
|
28
|
+
partialTx.memo = '';
|
|
29
|
+
if (!partialTx.sequence)
|
|
30
|
+
partialTx.sequence = '0';
|
|
31
|
+
if (!partialTx.source)
|
|
32
|
+
partialTx.source = '0';
|
|
33
|
+
if (!partialTx.account_number)
|
|
34
|
+
throw new Error('account_number is required');
|
|
35
|
+
if (!partialTx.chain_id)
|
|
36
|
+
throw new Error('chain_id is required');
|
|
37
|
+
const tx = partialTx;
|
|
38
|
+
if (tx.data)
|
|
39
|
+
throw new Error('tx data field not supported');
|
|
40
|
+
const signTx = new BinanceMessages.BinanceSignTx();
|
|
41
|
+
signTx.setAddressNList(msg.addressNList);
|
|
42
|
+
signTx.setAccountNumber(tx.account_number);
|
|
43
|
+
signTx.setChainId(tx.chain_id);
|
|
44
|
+
signTx.setSequence(tx.sequence);
|
|
45
|
+
if (tx.memo)
|
|
46
|
+
signTx.setMemo(tx.memo);
|
|
47
|
+
//verify not a batch tx
|
|
48
|
+
if (msg.tx.msgs.length > 1)
|
|
49
|
+
throw new Error('Binance batch sending not supported!');
|
|
50
|
+
const message = msg.tx.msgs[0];
|
|
51
|
+
//tell device not a batch tx
|
|
52
|
+
signTx.setMsgCount(1);
|
|
53
|
+
//tell device im about to send a tx to sign
|
|
54
|
+
let resp = await transport.call(Messages.MessageType.MESSAGETYPE_BINANCESIGNTX, signTx, {
|
|
55
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
56
|
+
omitLock: true,
|
|
57
|
+
});
|
|
58
|
+
const outputAmount = new BigNumber(message.outputs[0].coins[0].amount);
|
|
59
|
+
const inputAmount = new BigNumber(message.inputs[0].coins[0].amount);
|
|
60
|
+
if (!outputAmount.isInteger())
|
|
61
|
+
throw new Error('Output amount must be an integer');
|
|
62
|
+
if (!inputAmount.isInteger())
|
|
63
|
+
throw new Error('Input amount must be an integer');
|
|
64
|
+
const coinOut = new BinanceMessages.BinanceTransferMsg.BinanceCoin();
|
|
65
|
+
coinOut.setAmount(outputAmount.toString());
|
|
66
|
+
coinOut.setDenom(message.outputs[0].coins[0].denom);
|
|
67
|
+
const outputs = new BinanceMessages.BinanceTransferMsg.BinanceInputOutput();
|
|
68
|
+
outputs.setAddress(message.outputs[0].address);
|
|
69
|
+
outputs.setCoinsList([coinOut]);
|
|
70
|
+
const coinIn = new BinanceMessages.BinanceTransferMsg.BinanceCoin();
|
|
71
|
+
coinIn.setAmount(inputAmount.toString());
|
|
72
|
+
coinIn.setDenom(message.inputs[0].coins[0].denom);
|
|
73
|
+
const inputs = new BinanceMessages.BinanceTransferMsg.BinanceInputOutput();
|
|
74
|
+
inputs.setAddress(message.inputs[0].address);
|
|
75
|
+
inputs.setCoinsList([coinIn]);
|
|
76
|
+
const send = new BinanceMessages.BinanceTransferMsg();
|
|
77
|
+
send.addInputs(inputs);
|
|
78
|
+
send.addOutputs(outputs);
|
|
79
|
+
//sent tx to device
|
|
80
|
+
resp = await transport.call(Messages.MessageType.MESSAGETYPE_BINANCETRANSFERMSG, send, {
|
|
81
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
82
|
+
omitLock: true,
|
|
83
|
+
});
|
|
84
|
+
if (resp.message_enum !== Messages.MessageType.MESSAGETYPE_BINANCESIGNEDTX) {
|
|
85
|
+
throw new Error(`binance: unexpected response ${resp.message_type}`);
|
|
86
|
+
}
|
|
87
|
+
const signedTx = new BinanceMessages.BinanceSignedTx();
|
|
88
|
+
signedTx.setSignature(resp.message.signature);
|
|
89
|
+
signedTx.setPublicKey(resp.message.publicKey);
|
|
90
|
+
const serialized = encodeBnbTx(tx, Buffer.from(signedTx.getPublicKey_asU8()), Buffer.from(signedTx.getSignature_asU8())).toString('hex');
|
|
91
|
+
const out = {
|
|
92
|
+
...tx,
|
|
93
|
+
signatures: {
|
|
94
|
+
pub_key: signedTx.getPublicKey_asB64(),
|
|
95
|
+
signature: signedTx.getSignature_asB64(),
|
|
96
|
+
},
|
|
97
|
+
serialized,
|
|
98
|
+
txid: CryptoJS.SHA256(CryptoJS.enc.Hex.parse(serialized)).toString(),
|
|
99
|
+
};
|
|
100
|
+
return out;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export async function binanceGetAddress(transport, msg) {
|
|
104
|
+
const getAddr = new BinanceMessages.BinanceGetAddress();
|
|
105
|
+
getAddr.setAddressNList(msg.addressNList);
|
|
106
|
+
getAddr.setShowDisplay(msg.showDisplay !== false);
|
|
107
|
+
const response = await transport.call(Messages.MessageType.MESSAGETYPE_BINANCEGETADDRESS, getAddr, {
|
|
108
|
+
msgTimeout: core.LONG_TIMEOUT,
|
|
109
|
+
});
|
|
110
|
+
const binanceAddress = response.proto;
|
|
111
|
+
return core.mustBeDefined(binanceAddress.getAddress());
|
|
112
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as core from '@shapeshiftoss/hdwallet-core';
|
|
2
|
+
import type { Transport } from './transport.js';
|
|
3
|
+
export declare function btcSupportsCoin(coin: core.Coin): Promise<boolean>;
|
|
4
|
+
export declare function btcSupportsScriptType(coin: core.Coin, scriptType?: core.BTCInputScriptType): Promise<boolean>;
|
|
5
|
+
export declare function btcGetAddress(wallet: core.BTCWallet, transport: Transport, msg: core.BTCGetAddress): Promise<string>;
|
|
6
|
+
export declare function btcSignTx(wallet: core.BTCWallet, transport: Transport, msgIn: core.BTCSignTxKK): Promise<core.BTCSignedTx>;
|
|
7
|
+
export declare function btcSupportsSecureTransfer(): Promise<boolean>;
|
|
8
|
+
export declare function btcSupportsNativeShapeShift(): boolean;
|
|
9
|
+
export declare function btcSignMessage(wallet: core.BTCWallet, transport: Transport, msg: core.BTCSignMessage): Promise<core.BTCSignedMessage>;
|
|
10
|
+
export declare function btcVerifyMessage(wallet: core.BTCWallet, transport: Transport, msg: core.BTCVerifyMessage): Promise<boolean>;
|
|
11
|
+
export declare function btcGetAccountPaths(msg: core.BTCGetAccountPaths): core.BTCAccountPath[];
|