@shapeshiftoss/hdwallet-metamask-multichain 1.55.10-mipd.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/dist/adapter.d.ts +11 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +95 -0
- package/dist/adapter.js.map +1 -0
- package/dist/bitcoin.d.ts +8 -0
- package/dist/bitcoin.d.ts.map +1 -0
- package/dist/bitcoin.js +43 -0
- package/dist/bitcoin.js.map +1 -0
- package/dist/bitcoincash.d.ts +8 -0
- package/dist/bitcoincash.d.ts.map +1 -0
- package/dist/bitcoincash.js +43 -0
- package/dist/bitcoincash.js.map +1 -0
- package/dist/common.d.ts +2 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +6 -0
- package/dist/common.js.map +1 -0
- package/dist/cosmos.d.ts +7 -0
- package/dist/cosmos.d.ts.map +1 -0
- package/dist/cosmos.js +64 -0
- package/dist/cosmos.js.map +1 -0
- package/dist/dogecoin.d.ts +8 -0
- package/dist/dogecoin.d.ts.map +1 -0
- package/dist/dogecoin.js +43 -0
- package/dist/dogecoin.js.map +1 -0
- package/dist/ethereum.d.ts +9 -0
- package/dist/ethereum.d.ts.map +1 -0
- package/dist/ethereum.js +159 -0
- package/dist/ethereum.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/litecoin.d.ts +8 -0
- package/dist/litecoin.d.ts.map +1 -0
- package/dist/litecoin.js +43 -0
- package/dist/litecoin.js.map +1 -0
- package/dist/shapeshift-multichain.d.ts +203 -0
- package/dist/shapeshift-multichain.d.ts.map +1 -0
- package/dist/shapeshift-multichain.js +883 -0
- package/dist/shapeshift-multichain.js.map +1 -0
- package/dist/thorchain.d.ts +7 -0
- package/dist/thorchain.d.ts.map +1 -0
- package/dist/thorchain.js +64 -0
- package/dist/thorchain.js.map +1 -0
- package/dist/utxo.d.ts +6 -0
- package/dist/utxo.d.ts.map +1 -0
- package/dist/utxo.js +205 -0
- package/dist/utxo.js.map +1 -0
- package/package.json +32 -0
- package/src/adapter.ts +62 -0
- package/src/bitcoin.ts +32 -0
- package/src/bitcoincash.ts +32 -0
- package/src/common.ts +2 -0
- package/src/cosmos.ts +30 -0
- package/src/dogecoin.ts +32 -0
- package/src/ethereum.ts +125 -0
- package/src/index.ts +2 -0
- package/src/litecoin.ts +31 -0
- package/src/shapeshift-multichain.test.ts +170 -0
- package/src/shapeshift-multichain.ts +871 -0
- package/src/thorchain.ts +30 -0
- package/src/utxo.ts +201 -0
- package/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/yarn-error.log +18555 -0
package/src/thorchain.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as core from "@shapeshiftoss/hdwallet-core";
|
|
2
|
+
import {
|
|
3
|
+
thorchainGetAddress as snapThorchainGetAddress,
|
|
4
|
+
thorchainSignTransaction as snapThorchainSignTransaction,
|
|
5
|
+
} from "@shapeshiftoss/metamask-snaps-adapter";
|
|
6
|
+
import { ThorchainGetAddressResponse } from "@shapeshiftoss/metamask-snaps-types";
|
|
7
|
+
|
|
8
|
+
import { SNAP_ID } from "./common";
|
|
9
|
+
|
|
10
|
+
export function thorchainGetAccountPaths(msg: core.ThorchainGetAccountPaths): Array<core.ThorchainAccountPath> {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
addressNList: [0x80000000 + 44, 0x80000000 + core.slip44ByCoin("Thorchain"), 0x80000000 + msg.accountIdx, 0, 0],
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
+
export function thorchainNextAccountPath(msg: core.ThorchainAccountPath): core.ThorchainAccountPath | undefined {
|
|
20
|
+
// Only support one account for now (like portis).
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function thorchainGetAddress(msg: core.ThorchainGetAddress): Promise<ThorchainGetAddressResponse> {
|
|
25
|
+
return await snapThorchainGetAddress({ snapId: SNAP_ID, addressParams: { addressNList: msg.addressNList } });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function thorchainSignTx(msg: core.ThorchainSignTx): Promise<core.ThorchainSignedTx | null> {
|
|
29
|
+
return await snapThorchainSignTransaction({ snapId: SNAP_ID, transaction: msg });
|
|
30
|
+
}
|
package/src/utxo.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import * as core from "@shapeshiftoss/hdwallet-core";
|
|
2
|
+
|
|
3
|
+
const supportedCoins = ["Bitcoin", "BitcoinCash", "Litecoin", "Dogecoin"];
|
|
4
|
+
|
|
5
|
+
function legacyAccount(coin: core.Coin, slip44: number, accountIdx: number): core.BTCAccountPath {
|
|
6
|
+
return {
|
|
7
|
+
coin,
|
|
8
|
+
scriptType: core.BTCInputScriptType.SpendAddress,
|
|
9
|
+
addressNList: [0x80000000 + 44, 0x80000000 + slip44, 0x80000000 + accountIdx],
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function segwitAccount(coin: core.Coin, slip44: number, accountIdx: number): core.BTCAccountPath {
|
|
14
|
+
return {
|
|
15
|
+
coin,
|
|
16
|
+
scriptType: core.BTCInputScriptType.SpendP2SHWitness,
|
|
17
|
+
addressNList: [0x80000000 + 49, 0x80000000 + slip44, 0x80000000 + accountIdx],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function segwitNativeAccount(coin: core.Coin, slip44: number, accountIdx: number): core.BTCAccountPath {
|
|
22
|
+
return {
|
|
23
|
+
coin,
|
|
24
|
+
scriptType: core.BTCInputScriptType.SpendWitness,
|
|
25
|
+
addressNList: [0x80000000 + 84, 0x80000000 + slip44, 0x80000000 + accountIdx],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function utxoSupportsCoin(coin: core.Coin): boolean {
|
|
30
|
+
// FIXME: inspect the CoinTable to determine which coins are actually supported by the device.
|
|
31
|
+
return supportedCoins.includes(coin);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function utxoSupportsScriptType(coin: core.Coin, scriptType?: core.BTCInputScriptType): boolean {
|
|
35
|
+
if (!utxoSupportsCoin(coin)) return false;
|
|
36
|
+
|
|
37
|
+
switch (scriptType) {
|
|
38
|
+
case core.BTCInputScriptType.SpendMultisig:
|
|
39
|
+
case core.BTCInputScriptType.SpendAddress:
|
|
40
|
+
case core.BTCInputScriptType.SpendWitness:
|
|
41
|
+
case core.BTCInputScriptType.Bech32:
|
|
42
|
+
case core.BTCInputScriptType.SpendP2SHWitness:
|
|
43
|
+
return true;
|
|
44
|
+
default:
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function describeUTXOPath(
|
|
50
|
+
path: core.BIP32Path,
|
|
51
|
+
coin: core.Coin,
|
|
52
|
+
scriptType?: core.BTCInputScriptType
|
|
53
|
+
): core.PathDescription {
|
|
54
|
+
const pathStr = core.addressNListToBIP32(path);
|
|
55
|
+
const unknown: core.PathDescription = {
|
|
56
|
+
verbose: pathStr,
|
|
57
|
+
coin,
|
|
58
|
+
scriptType,
|
|
59
|
+
isKnown: false,
|
|
60
|
+
};
|
|
61
|
+
if (!scriptType) return unknown;
|
|
62
|
+
|
|
63
|
+
if (!utxoSupportsCoin(coin)) return unknown;
|
|
64
|
+
|
|
65
|
+
if (!utxoSupportsScriptType(coin, scriptType)) return unknown;
|
|
66
|
+
|
|
67
|
+
if (path.length !== 3 && path.length !== 5) return unknown;
|
|
68
|
+
|
|
69
|
+
if ((path[0] & 0x80000000) >>> 0 !== 0x80000000) return unknown;
|
|
70
|
+
|
|
71
|
+
const purpose = path[0] & 0x7fffffff;
|
|
72
|
+
|
|
73
|
+
if (![44, 49, 84].includes(purpose)) return unknown;
|
|
74
|
+
|
|
75
|
+
if (purpose === 44 && scriptType !== core.BTCInputScriptType.SpendAddress) return unknown;
|
|
76
|
+
|
|
77
|
+
if (purpose === 49 && scriptType !== core.BTCInputScriptType.SpendP2SHWitness) return unknown;
|
|
78
|
+
|
|
79
|
+
if (purpose === 84 && scriptType !== core.BTCInputScriptType.SpendWitness) return unknown;
|
|
80
|
+
|
|
81
|
+
const wholeAccount = path.length === 3;
|
|
82
|
+
|
|
83
|
+
const script = scriptType
|
|
84
|
+
? (
|
|
85
|
+
{
|
|
86
|
+
[core.BTCInputScriptType.SpendAddress]: ["Legacy"],
|
|
87
|
+
[core.BTCInputScriptType.SpendP2SHWitness]: [],
|
|
88
|
+
[core.BTCInputScriptType.SpendWitness]: ["Segwit Native"],
|
|
89
|
+
} as Partial<Record<core.BTCInputScriptType, string[]>>
|
|
90
|
+
)[scriptType] ?? []
|
|
91
|
+
: [];
|
|
92
|
+
|
|
93
|
+
let isPrefork = false;
|
|
94
|
+
const slip44 = core.slip44ByCoin(coin);
|
|
95
|
+
if (slip44 === undefined) return unknown;
|
|
96
|
+
if (path[1] !== 0x80000000 + slip44) {
|
|
97
|
+
switch (coin) {
|
|
98
|
+
case "BitcoinCash":
|
|
99
|
+
case "BitcoinGold": {
|
|
100
|
+
if (path[1] === 0x80000000 + core.slip44ByCoin("Bitcoin")) {
|
|
101
|
+
isPrefork = true;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return unknown;
|
|
105
|
+
}
|
|
106
|
+
case "BitcoinSV": {
|
|
107
|
+
if (
|
|
108
|
+
path[1] === 0x80000000 + core.slip44ByCoin("Bitcoin") ||
|
|
109
|
+
path[1] === 0x80000000 + core.slip44ByCoin("BitcoinCash")
|
|
110
|
+
) {
|
|
111
|
+
isPrefork = true;
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
return unknown;
|
|
115
|
+
}
|
|
116
|
+
default:
|
|
117
|
+
return unknown;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let attributes = isPrefork ? ["Prefork"] : [];
|
|
122
|
+
switch (coin) {
|
|
123
|
+
case "Bitcoin":
|
|
124
|
+
case "Litecoin":
|
|
125
|
+
case "BitcoinGold":
|
|
126
|
+
case "Testnet": {
|
|
127
|
+
attributes = attributes.concat(script);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
default:
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const attr = attributes.length ? ` (${attributes.join(", ")})` : "";
|
|
135
|
+
|
|
136
|
+
const accountIdx = path[2] & 0x7fffffff;
|
|
137
|
+
|
|
138
|
+
if (wholeAccount) {
|
|
139
|
+
return {
|
|
140
|
+
coin,
|
|
141
|
+
verbose: `${coin} Account #${accountIdx}${attr}`,
|
|
142
|
+
accountIdx,
|
|
143
|
+
wholeAccount: true,
|
|
144
|
+
isKnown: true,
|
|
145
|
+
scriptType,
|
|
146
|
+
isPrefork,
|
|
147
|
+
};
|
|
148
|
+
} else {
|
|
149
|
+
const change = path[3] === 1 ? "Change " : "";
|
|
150
|
+
const addressIdx = path[4];
|
|
151
|
+
return {
|
|
152
|
+
coin,
|
|
153
|
+
verbose: `${coin} Account #${accountIdx}, ${change}Address #${addressIdx}${attr}`,
|
|
154
|
+
accountIdx,
|
|
155
|
+
addressIdx,
|
|
156
|
+
wholeAccount: false,
|
|
157
|
+
isKnown: true,
|
|
158
|
+
isChange: path[3] === 1,
|
|
159
|
+
scriptType,
|
|
160
|
+
isPrefork,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function utxoGetAccountPaths(msg: core.BTCGetAccountPaths): Array<core.BTCAccountPath> {
|
|
166
|
+
const slip44 = core.slip44ByCoin(msg.coin);
|
|
167
|
+
if (slip44 === undefined) return [];
|
|
168
|
+
const bip44 = legacyAccount(msg.coin, slip44, msg.accountIdx);
|
|
169
|
+
const bip49 = segwitAccount(msg.coin, slip44, msg.accountIdx);
|
|
170
|
+
const bip84 = segwitNativeAccount(msg.coin, slip44, msg.accountIdx);
|
|
171
|
+
|
|
172
|
+
// For BTC Forks
|
|
173
|
+
const btcLegacy = legacyAccount(msg.coin, core.slip44ByCoin("Bitcoin"), msg.accountIdx);
|
|
174
|
+
const btcSegwit = segwitAccount(msg.coin, core.slip44ByCoin("Bitcoin"), msg.accountIdx);
|
|
175
|
+
const btcSegwitNative = segwitNativeAccount(msg.coin, core.slip44ByCoin("Bitcoin"), msg.accountIdx);
|
|
176
|
+
|
|
177
|
+
// For BCH Forks
|
|
178
|
+
const bchLegacy = legacyAccount(msg.coin, core.slip44ByCoin("BitcoinCash"), msg.accountIdx);
|
|
179
|
+
|
|
180
|
+
let paths: Array<core.BTCAccountPath> =
|
|
181
|
+
(
|
|
182
|
+
{
|
|
183
|
+
Bitcoin: [bip44, bip49, bip84],
|
|
184
|
+
Litecoin: [bip44, bip49, bip84],
|
|
185
|
+
Dash: [bip44],
|
|
186
|
+
DigiByte: [bip44, bip49, bip84],
|
|
187
|
+
Dogecoin: [bip44],
|
|
188
|
+
Testnet: [bip44, bip49, bip84],
|
|
189
|
+
BitcoinCash: [bip44, btcLegacy],
|
|
190
|
+
BitcoinSV: [bip44, bchLegacy, btcLegacy],
|
|
191
|
+
BitcoinGold: [bip44, bip49, bip84, btcLegacy, btcSegwit, btcSegwitNative],
|
|
192
|
+
} as Partial<Record<core.Coin, core.BTCAccountPath[]>>
|
|
193
|
+
)[msg.coin] ?? [];
|
|
194
|
+
|
|
195
|
+
if (msg.scriptType !== undefined)
|
|
196
|
+
paths = paths.filter((path) => {
|
|
197
|
+
return path.scriptType === msg.scriptType;
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
return paths;
|
|
201
|
+
}
|
package/tsconfig.json
ADDED