@ledgerhq/live-common 21.16.0 → 21.16.4
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/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js +95 -7
- package/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.js +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js +2 -2
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.js +20 -10
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.js +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.js +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.js +2 -2
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.js.map +1 -1
- package/lib/account/formatters.d.ts.map +1 -1
- package/lib/account/formatters.js +33 -1
- package/lib/account/formatters.js.map +1 -1
- package/lib/apps/polyfill.d.ts.map +1 -1
- package/lib/apps/polyfill.js +3 -0
- package/lib/apps/polyfill.js.map +1 -1
- package/lib/currencies/support.d.ts.map +1 -1
- package/lib/currencies/support.js.map +1 -1
- package/lib/families/bitcoin/bech32m.d.ts +22 -0
- package/lib/families/bitcoin/bech32m.d.ts.map +1 -0
- package/lib/families/bitcoin/bech32m.js +166 -0
- package/lib/families/bitcoin/bech32m.js.map +1 -0
- package/lib/families/bitcoin/datasets/bitcoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.js +4 -0
- package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_cash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_cash.js +4 -0
- package/lib/families/bitcoin/datasets/bitcoin_cash.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_gold.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_gold.js +4 -0
- package/lib/families/bitcoin/datasets/bitcoin_gold.js.map +1 -1
- package/lib/families/bitcoin/datasets/dash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/dash.js +4 -0
- package/lib/families/bitcoin/datasets/dash.js.map +1 -1
- package/lib/families/bitcoin/datasets/decred.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/decred.js +4 -0
- package/lib/families/bitcoin/datasets/decred.js.map +1 -1
- package/lib/families/bitcoin/datasets/digibyte.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/digibyte.js +4 -0
- package/lib/families/bitcoin/datasets/digibyte.js.map +1 -1
- package/lib/families/bitcoin/datasets/dogecoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/dogecoin.js +4 -0
- package/lib/families/bitcoin/datasets/dogecoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/komodo.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/komodo.js +4 -0
- package/lib/families/bitcoin/datasets/komodo.js.map +1 -1
- package/lib/families/bitcoin/datasets/litecoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/litecoin.js +4 -0
- package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/peercoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/peercoin.js +4 -0
- package/lib/families/bitcoin/datasets/peercoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/pivx.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/pivx.js +4 -0
- package/lib/families/bitcoin/datasets/pivx.js.map +1 -1
- package/lib/families/bitcoin/datasets/qtum.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/qtum.js +4 -0
- package/lib/families/bitcoin/datasets/qtum.js.map +1 -1
- package/lib/families/bitcoin/datasets/stakenet.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/stakenet.js +4 -0
- package/lib/families/bitcoin/datasets/stakenet.js.map +1 -1
- package/lib/families/bitcoin/datasets/vertcoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/vertcoin.js +4 -0
- package/lib/families/bitcoin/datasets/vertcoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/viacoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/viacoin.js +4 -0
- package/lib/families/bitcoin/datasets/viacoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/zcash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/zcash.js +4 -0
- package/lib/families/bitcoin/datasets/zcash.js.map +1 -1
- package/lib/families/bitcoin/datasets/zencash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/zencash.js +4 -0
- package/lib/families/bitcoin/datasets/zencash.js.map +1 -1
- package/lib/families/bitcoin/js-buildTransaction.d.ts.map +1 -1
- package/lib/families/bitcoin/js-buildTransaction.js +1 -1
- package/lib/families/bitcoin/js-buildTransaction.js.map +1 -1
- package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +1 -1
- package/lib/families/bitcoin/js-estimateMaxSpendable.js +1 -1
- package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.js +31 -8
- package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js +11 -11
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +2 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/digibyte.js +21 -2
- package/lib/families/bitcoin/wallet-btc/crypto/digibyte.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +2 -2
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js +3 -2
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js +3 -2
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts +2 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js +16 -12
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts +2 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js +12 -7
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts +2 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js +12 -7
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.d.ts +2 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.d.ts +38 -2
- package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.js +103 -35
- package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.js +9 -8
- package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/xpub.js +2 -2
- package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
- package/lib/families/elrond/logic.js +22 -3
- package/lib/families/elrond/logic.js.map +1 -1
- package/lib/nft/NftMetadataProvider/index.d.ts +7 -0
- package/lib/nft/NftMetadataProvider/index.d.ts.map +1 -1
- package/lib/nft/NftMetadataProvider/index.js +3 -3
- package/lib/nft/NftMetadataProvider/index.js.map +1 -1
- package/lib/operation.js +1 -1
- package/lib/operation.js.map +1 -1
- package/package.json +10 -10
- package/src/.DS_Store +0 -0
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +1243 -123478
- package/src/__tests__/families/bitcoin/wallet-btc/utils.test.ts +109 -2
- package/src/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.ts +3 -2
- package/src/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.ts +2 -2
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.ts +35 -31
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.ts +3 -2
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.ts +3 -2
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.ts +6 -4
- package/src/account/formatters.ts +43 -0
- package/src/apps/polyfill.ts +3 -0
- package/src/currencies/.DS_Store +0 -0
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +3 -1
- package/src/currencies/support.ts +1 -0
- package/src/families/bitcoin/bech32m.ts +197 -0
- package/src/families/bitcoin/datasets/bitcoin.ts +4 -0
- package/src/families/bitcoin/datasets/bitcoin_cash.ts +4 -0
- package/src/families/bitcoin/datasets/bitcoin_gold.ts +4 -0
- package/src/families/bitcoin/datasets/dash.ts +4 -0
- package/src/families/bitcoin/datasets/decred.ts +4 -0
- package/src/families/bitcoin/datasets/digibyte.ts +4 -0
- package/src/families/bitcoin/datasets/dogecoin.ts +4 -0
- package/src/families/bitcoin/datasets/komodo.ts +4 -0
- package/src/families/bitcoin/datasets/litecoin.ts +4 -0
- package/src/families/bitcoin/datasets/peercoin.ts +4 -0
- package/src/families/bitcoin/datasets/pivx.ts +4 -0
- package/src/families/bitcoin/datasets/qtum.ts +4 -0
- package/src/families/bitcoin/datasets/stakenet.ts +4 -0
- package/src/families/bitcoin/datasets/vertcoin.ts +4 -0
- package/src/families/bitcoin/datasets/viacoin.ts +4 -0
- package/src/families/bitcoin/datasets/zcash.ts +4 -0
- package/src/families/bitcoin/datasets/zencash.ts +4 -0
- package/src/families/bitcoin/js-buildTransaction.ts +2 -1
- package/src/families/bitcoin/js-estimateMaxSpendable.ts +2 -1
- package/src/families/bitcoin/js-synchronisation.ts +39 -11
- package/src/families/bitcoin/wallet-btc/crypto/bitcoin.ts +5 -4
- package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +2 -1
- package/src/families/bitcoin/wallet-btc/crypto/digibyte.ts +1 -1
- package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +1 -1
- package/src/families/bitcoin/wallet-btc/crypto/zec.ts +3 -2
- package/src/families/bitcoin/wallet-btc/crypto/zen.ts +3 -2
- package/src/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.ts +34 -22
- package/src/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.ts +30 -9
- package/src/families/bitcoin/wallet-btc/pickingstrategies/Merge.ts +30 -9
- package/src/families/bitcoin/wallet-btc/pickingstrategies/types.ts +3 -3
- package/src/families/bitcoin/wallet-btc/utils.ts +113 -41
- package/src/families/bitcoin/wallet-btc/wallet.ts +10 -8
- package/src/families/bitcoin/wallet-btc/xpub.ts +5 -5
- package/src/families/elrond/logic.ts +1 -1
- package/src/nft/NftMetadataProvider/index.tsx +1 -1
- package/src/operation.ts +1 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as bech32 from "bech32";
|
|
2
|
+
import { bech32m } from "../../../../families/bitcoin/bech32m";
|
|
2
3
|
import * as utils from "../../../../families/bitcoin/wallet-btc/utils";
|
|
3
4
|
import { Currency } from "../../../../families/bitcoin/wallet-btc/crypto/types";
|
|
5
|
+
import cryptoFactory from "../../../../families/bitcoin/wallet-btc/crypto/factory";
|
|
6
|
+
import { DerivationModes } from "../../../../families/bitcoin/wallet-btc";
|
|
4
7
|
|
|
5
8
|
function validateAddrs(
|
|
6
9
|
addresses: string[],
|
|
@@ -16,7 +19,8 @@ function toBech32(
|
|
|
16
19
|
data: Buffer,
|
|
17
20
|
version: number,
|
|
18
21
|
prefix: string,
|
|
19
|
-
bech32variant: BechLib
|
|
22
|
+
//bech32variant: BechLib // FIXME Restore this
|
|
23
|
+
bech32variant: any
|
|
20
24
|
): string {
|
|
21
25
|
const words = bech32.toWords(data);
|
|
22
26
|
words.unshift(version);
|
|
@@ -208,3 +212,106 @@ describe("Unit tests for various utils functions", () => {
|
|
|
208
212
|
validateAddrs(["S6NMcEfYbavHrP3Uo1wbEUvKhAbKeMugaa"], "stealthcoin", false);
|
|
209
213
|
});
|
|
210
214
|
});
|
|
215
|
+
|
|
216
|
+
describe("Unit tests for maxTxSize", () => {
|
|
217
|
+
const btc = cryptoFactory("bitcoin_testnet");
|
|
218
|
+
it("Empty tx non-segwit", () => {
|
|
219
|
+
const s = utils.maxTxSizeCeil(0, [], false, btc, DerivationModes.LEGACY);
|
|
220
|
+
expect(s).toEqual(10);
|
|
221
|
+
});
|
|
222
|
+
it("Empty tx segwit", () => {
|
|
223
|
+
const s = utils.maxTxSizeCeil(
|
|
224
|
+
0,
|
|
225
|
+
[],
|
|
226
|
+
false,
|
|
227
|
+
btc,
|
|
228
|
+
DerivationModes.NATIVE_SEGWIT
|
|
229
|
+
);
|
|
230
|
+
expect(s).toEqual(11);
|
|
231
|
+
});
|
|
232
|
+
it("1 p2wpkh input 1 p2wpkh output", () => {});
|
|
233
|
+
|
|
234
|
+
const tr = "tb1pdedptfps5k6hmzars9ks93ejsujh28kw5dhe06gutt9svap40j8qql2dw2";
|
|
235
|
+
const sh = "2Mv9bnjkBUr1GfCybJc7XmnJ5VG4SAT3shT";
|
|
236
|
+
const pkh = "mkQiYQGCkCC7Wus3vfhfTDjgJzQK554evn";
|
|
237
|
+
const wpkh = "tb1qhff3j7euu6t3lv8s5gsy9t5x82wuhfw5z863gj";
|
|
238
|
+
const p2tr = DerivationModes.TAPROOT;
|
|
239
|
+
const p2sh = DerivationModes.SEGWIT;
|
|
240
|
+
const p2pkh = DerivationModes.LEGACY;
|
|
241
|
+
const p2wpkh = DerivationModes.NATIVE_SEGWIT;
|
|
242
|
+
|
|
243
|
+
test.each([
|
|
244
|
+
// In 148 out 34
|
|
245
|
+
[0, [], false, p2pkh, 10],
|
|
246
|
+
[0, [], true, p2pkh, 44],
|
|
247
|
+
[0, [pkh], false, p2pkh, 44],
|
|
248
|
+
[0, [pkh], true, p2pkh, 78],
|
|
249
|
+
[1, [pkh], true, p2pkh, 226],
|
|
250
|
+
[2, [pkh], true, p2pkh, 374],
|
|
251
|
+
[1, [wpkh], true, p2pkh, 223],
|
|
252
|
+
[1, [sh], true, p2pkh, 224],
|
|
253
|
+
[1, [tr], true, p2pkh, 235],
|
|
254
|
+
|
|
255
|
+
// In 68 out 31
|
|
256
|
+
[0, [], false, p2wpkh, 11],
|
|
257
|
+
[0, [], true, p2wpkh, 42],
|
|
258
|
+
[1, [], false, p2wpkh, 79],
|
|
259
|
+
[1, [], true, p2wpkh, 110],
|
|
260
|
+
[2, [], true, p2wpkh, 178],
|
|
261
|
+
|
|
262
|
+
// In 90 out 32, scriptSig 22
|
|
263
|
+
[0, [], false, p2sh, 11],
|
|
264
|
+
[0, [], true, p2sh, 43],
|
|
265
|
+
[1, [], false, p2sh, 101],
|
|
266
|
+
[1, [sh], false, p2sh, 133],
|
|
267
|
+
[2, [sh], false, p2sh, 223],
|
|
268
|
+
|
|
269
|
+
// Fixed 10.5 In 57.75 out 43
|
|
270
|
+
[0, [], false, p2tr, 11],
|
|
271
|
+
[0, [], true, p2tr, 54],
|
|
272
|
+
[1, [], true, p2tr, Math.ceil(53.5 + 57.75 * 1)],
|
|
273
|
+
[2, [], true, p2tr, Math.ceil(53.5 + 57.75 * 2)],
|
|
274
|
+
[3, [], true, p2tr, Math.ceil(53.5 + 57.75 * 3)],
|
|
275
|
+
|
|
276
|
+
// 0xfc=252 inputs
|
|
277
|
+
[247, [], true, p2tr, Math.ceil(53.5 + 57.75 * 247)],
|
|
278
|
+
[248, [], true, p2tr, Math.ceil(53.5 + 57.75 * 248)],
|
|
279
|
+
[249, [], true, p2tr, Math.ceil(53.5 + 57.75 * 249)],
|
|
280
|
+
[250, [], true, p2tr, Math.ceil(53.5 + 57.75 * 250)],
|
|
281
|
+
[251, [], true, p2tr, Math.ceil(53.5 + 57.75 * 251)],
|
|
282
|
+
[252, [], true, p2tr, Math.ceil(53.5 + 57.75 * 252)],
|
|
283
|
+
// 0xfd=253 inputs will add 2 bytes for >= 0xfd
|
|
284
|
+
[253, [], true, p2tr, Math.ceil(53.5 + 57.75 * 253 + 2)],
|
|
285
|
+
[
|
|
286
|
+
256 * 256 - 1,
|
|
287
|
+
[],
|
|
288
|
+
true,
|
|
289
|
+
p2tr,
|
|
290
|
+
Math.ceil(53.5 + 57.75 * (256 * 256 - 1) + 2),
|
|
291
|
+
],
|
|
292
|
+
// 0xffff inputs will add 4 bytes
|
|
293
|
+
[256 * 256, [], true, p2tr, Math.ceil(53.5 + 57.75 * (256 * 256) + 4)],
|
|
294
|
+
|
|
295
|
+
// test address with witness version 16 and witness program [0x01, 0x02] => tb1sqypqyuzpgh
|
|
296
|
+
[
|
|
297
|
+
2,
|
|
298
|
+
[tr, sh, pkh, wpkh, "tb1sqypqyuzpgh"],
|
|
299
|
+
false,
|
|
300
|
+
p2wpkh,
|
|
301
|
+
Math.ceil(10.5 + 68 * 2 + 43 + 32 + 34 + 31 + 13),
|
|
302
|
+
],
|
|
303
|
+
])(
|
|
304
|
+
"%i, %s, %s, %s => %i",
|
|
305
|
+
(inputCount, outputAddrs, useChange, derivationMode, exp) => {
|
|
306
|
+
const s = utils.maxTxSizeCeil(
|
|
307
|
+
inputCount,
|
|
308
|
+
outputAddrs,
|
|
309
|
+
useChange,
|
|
310
|
+
btc,
|
|
311
|
+
derivationMode
|
|
312
|
+
);
|
|
313
|
+
//const s = utils.estimateTxSize(inputCount, outputAddrs.length + (useChange ? 1 : 0), btc, derivationMode);
|
|
314
|
+
expect(s).toEqual(exp);
|
|
315
|
+
}
|
|
316
|
+
);
|
|
317
|
+
});
|
|
@@ -57,9 +57,10 @@ describe("testing estimateMaxSpendable", () => {
|
|
|
57
57
|
expect(maxSpendable.toNumber()).toEqual(
|
|
58
58
|
balance -
|
|
59
59
|
feesPerByte *
|
|
60
|
-
utils.
|
|
60
|
+
utils.maxTxSizeCeil(
|
|
61
61
|
2,
|
|
62
|
-
|
|
62
|
+
[],
|
|
63
|
+
true,
|
|
63
64
|
account.xpub.crypto,
|
|
64
65
|
account.xpub.derivationMode
|
|
65
66
|
)
|
|
@@ -63,7 +63,7 @@ describe("testing wallet", () => {
|
|
|
63
63
|
fromAccount: account,
|
|
64
64
|
txInfo,
|
|
65
65
|
});
|
|
66
|
-
expect(
|
|
66
|
+
expect(Buffer.from(tx, "hex")).toHaveLength(20);
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
it("should allow to build a transaction splitting outputs", async () => {
|
|
@@ -87,7 +87,7 @@ describe("testing wallet", () => {
|
|
|
87
87
|
fromAccount: account,
|
|
88
88
|
txInfo,
|
|
89
89
|
});
|
|
90
|
-
expect(
|
|
90
|
+
expect(Buffer.from(tx, "hex")).toHaveLength(20);
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
it("should throw during sync if there is an error in explorer", async () => {
|
package/src/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.ts
CHANGED
|
@@ -3,7 +3,10 @@ import * as bip39 from "bip39";
|
|
|
3
3
|
import * as bitcoin from "bitcoinjs-lib";
|
|
4
4
|
import coininfo from "coininfo";
|
|
5
5
|
import BigNumber from "bignumber.js";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
DerivationModes,
|
|
8
|
+
OutputInfo,
|
|
9
|
+
} from "../../../../families/bitcoin/wallet-btc/types";
|
|
7
10
|
import Xpub from "../../../../families/bitcoin/wallet-btc/xpub";
|
|
8
11
|
import BitcoinLikeExplorer from "../../../../families/bitcoin/wallet-btc/explorer";
|
|
9
12
|
import Crypto from "../../../../families/bitcoin/wallet-btc/crypto/bitcoin";
|
|
@@ -42,6 +45,17 @@ describe("testing xpub legacy transactions", () => {
|
|
|
42
45
|
xpub,
|
|
43
46
|
};
|
|
44
47
|
|
|
48
|
+
function outputs(amount: number): OutputInfo[] {
|
|
49
|
+
return [
|
|
50
|
+
{
|
|
51
|
+
address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
|
|
52
|
+
isChange: false,
|
|
53
|
+
script: Buffer.from([]),
|
|
54
|
+
value: new BigNumber(amount),
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
45
59
|
it("merge output strategy should be correct", async () => {
|
|
46
60
|
// Initialize the xpub with 2 txs. So that it has 2 utxo
|
|
47
61
|
dataset.xpub.storage.appendTxs([
|
|
@@ -134,17 +148,15 @@ describe("testing xpub legacy transactions", () => {
|
|
|
134
148
|
);
|
|
135
149
|
let res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
136
150
|
dataset.xpub,
|
|
137
|
-
|
|
138
|
-
0
|
|
139
|
-
1
|
|
151
|
+
outputs(10000),
|
|
152
|
+
0
|
|
140
153
|
);
|
|
141
154
|
expect(res.unspentUtxos.length).toEqual(1); // only 1 utxo is enough
|
|
142
155
|
expect(Number(res.unspentUtxos[0].value)).toEqual(300000000); // use cheaper utxo first
|
|
143
156
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
144
157
|
dataset.xpub,
|
|
145
|
-
|
|
146
|
-
0
|
|
147
|
-
1
|
|
158
|
+
outputs(500000000),
|
|
159
|
+
0
|
|
148
160
|
);
|
|
149
161
|
expect(res.unspentUtxos.length).toEqual(2); // need 2 utxo
|
|
150
162
|
expect(
|
|
@@ -161,17 +173,15 @@ describe("testing xpub legacy transactions", () => {
|
|
|
161
173
|
);
|
|
162
174
|
let res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
163
175
|
dataset.xpub,
|
|
164
|
-
|
|
165
|
-
0
|
|
166
|
-
1
|
|
176
|
+
outputs(10000),
|
|
177
|
+
0
|
|
167
178
|
);
|
|
168
179
|
expect(res.unspentUtxos.length).toEqual(1); // only 1 utxo is enough
|
|
169
180
|
expect(Number(res.unspentUtxos[0].value)).toEqual(5000000000); // use old utxo first
|
|
170
181
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
171
182
|
dataset.xpub,
|
|
172
|
-
|
|
173
|
-
0
|
|
174
|
-
1
|
|
183
|
+
outputs(5200000000),
|
|
184
|
+
0
|
|
175
185
|
);
|
|
176
186
|
expect(res.unspentUtxos.length).toEqual(2); // need 2 utxo
|
|
177
187
|
expect(
|
|
@@ -323,45 +333,40 @@ describe("testing xpub legacy transactions", () => {
|
|
|
323
333
|
);
|
|
324
334
|
let res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
325
335
|
dataset.xpub,
|
|
326
|
-
|
|
327
|
-
10
|
|
328
|
-
1
|
|
336
|
+
outputs(10000),
|
|
337
|
+
10
|
|
329
338
|
);
|
|
330
339
|
expect(res.unspentUtxos.length).toEqual(1);
|
|
331
340
|
expect(Number(res.unspentUtxos[0].value)).toEqual(100000000);
|
|
332
341
|
|
|
333
342
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
334
343
|
dataset.xpub,
|
|
335
|
-
|
|
336
|
-
10
|
|
337
|
-
1
|
|
344
|
+
outputs(290000000),
|
|
345
|
+
10
|
|
338
346
|
);
|
|
339
347
|
expect(res.unspentUtxos.length).toEqual(1);
|
|
340
348
|
expect(Number(res.unspentUtxos[0].value)).toEqual(300000000);
|
|
341
349
|
|
|
342
350
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
343
351
|
dataset.xpub,
|
|
344
|
-
|
|
345
|
-
10
|
|
346
|
-
1
|
|
352
|
+
outputs(500000000),
|
|
353
|
+
10
|
|
347
354
|
);
|
|
348
355
|
expect(res.unspentUtxos.length).toEqual(1);
|
|
349
356
|
expect(Number(res.unspentUtxos[0].value)).toEqual(600000000);
|
|
350
357
|
|
|
351
358
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
352
359
|
dataset.xpub,
|
|
353
|
-
|
|
354
|
-
10
|
|
355
|
-
1
|
|
360
|
+
outputs(800000000),
|
|
361
|
+
10
|
|
356
362
|
);
|
|
357
363
|
expect(res.unspentUtxos.length).toEqual(1);
|
|
358
364
|
expect(Number(res.unspentUtxos[0].value)).toEqual(5000000000);
|
|
359
365
|
|
|
360
366
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
361
367
|
dataset.xpub,
|
|
362
|
-
|
|
363
|
-
10
|
|
364
|
-
1
|
|
368
|
+
outputs(5000000000),
|
|
369
|
+
10
|
|
365
370
|
);
|
|
366
371
|
expect(res.unspentUtxos.length).toEqual(2);
|
|
367
372
|
expect(
|
|
@@ -370,9 +375,8 @@ describe("testing xpub legacy transactions", () => {
|
|
|
370
375
|
|
|
371
376
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
372
377
|
dataset.xpub,
|
|
373
|
-
|
|
374
|
-
10
|
|
375
|
-
1
|
|
378
|
+
outputs(5600000000),
|
|
379
|
+
10
|
|
376
380
|
);
|
|
377
381
|
expect(res.unspentUtxos.length).toEqual(3);
|
|
378
382
|
expect(
|
|
@@ -178,9 +178,10 @@ describe.skip("testing xpub segwit transactions", () => {
|
|
|
178
178
|
await xpubs[1].xpub.sync();
|
|
179
179
|
|
|
180
180
|
expectedFee1 =
|
|
181
|
-
utils.
|
|
181
|
+
utils.maxTxSizeCeil(
|
|
182
182
|
inputs.length,
|
|
183
|
-
outputs.
|
|
183
|
+
outputs.map((o) => o.address),
|
|
184
|
+
false,
|
|
184
185
|
crypto,
|
|
185
186
|
DerivationModes.SEGWIT
|
|
186
187
|
) * 100;
|
|
@@ -167,9 +167,10 @@ describe.skip("testing xpub native segwit transactions", () => {
|
|
|
167
167
|
await xpubs[1].xpub.sync();
|
|
168
168
|
|
|
169
169
|
expectedFee1 =
|
|
170
|
-
utils.
|
|
170
|
+
utils.maxTxSizeCeil(
|
|
171
171
|
inputs.length,
|
|
172
|
-
outputs.
|
|
172
|
+
outputs.map((o) => o.address),
|
|
173
|
+
false,
|
|
173
174
|
crypto,
|
|
174
175
|
DerivationModes.NATIVE_SEGWIT
|
|
175
176
|
) * 100;
|
|
@@ -148,9 +148,10 @@ describe.skip("testing xpub legacy transactions", () => {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
expectedFee1 =
|
|
151
|
-
utils.
|
|
151
|
+
utils.maxTxSizeCeil(
|
|
152
152
|
inputs.length,
|
|
153
|
-
outputs.
|
|
153
|
+
outputs.map((o) => o.address),
|
|
154
|
+
false,
|
|
154
155
|
crypto,
|
|
155
156
|
DerivationModes.LEGACY
|
|
156
157
|
) * 100;
|
|
@@ -280,9 +281,10 @@ describe.skip("testing xpub legacy transactions", () => {
|
|
|
280
281
|
await xpubs[1].xpub.sync();
|
|
281
282
|
|
|
282
283
|
expectedFee2 =
|
|
283
|
-
utils.
|
|
284
|
+
utils.maxTxSizeCeil(
|
|
284
285
|
inputs.length,
|
|
285
|
-
outputs.
|
|
286
|
+
outputs.map((o) => o.address),
|
|
287
|
+
false,
|
|
286
288
|
crypto,
|
|
287
289
|
DerivationModes.LEGACY
|
|
288
290
|
) * 100;
|
|
@@ -12,6 +12,15 @@ import { formatCurrencyUnit } from "../currencies";
|
|
|
12
12
|
import { getOperationAmountNumber } from "../operation";
|
|
13
13
|
import { getTagDerivationMode } from "../derivation";
|
|
14
14
|
import byFamily from "../generated/account";
|
|
15
|
+
import { nftsByCollections } from "../nft";
|
|
16
|
+
|
|
17
|
+
const styling = {
|
|
18
|
+
bold: (str: string) => `\x1b[1m${str}\x1b[22m`,
|
|
19
|
+
underline: (str: string) => `\x1b[4m${str}\x1b[24m`,
|
|
20
|
+
cyan: (str: string) => `\x1b[36m${str}\x1b[37m`,
|
|
21
|
+
magenta: (str: string) => `\x1b[35m${str}\x1b[37m`,
|
|
22
|
+
reverse: (str: string) => `\x1b[7m${str}\x1b[27m`,
|
|
23
|
+
};
|
|
15
24
|
|
|
16
25
|
const isSignificantAccount = (acc) =>
|
|
17
26
|
acc.balance.gt(10 ** (getAccountUnit(acc).magnitude - 6));
|
|
@@ -80,6 +89,7 @@ const cliFormat = (account, level?: string) => {
|
|
|
80
89
|
derivationMode,
|
|
81
90
|
index,
|
|
82
91
|
operations,
|
|
92
|
+
nfts,
|
|
83
93
|
} = account;
|
|
84
94
|
const tag = getTagDerivationMode(account.currency, derivationMode);
|
|
85
95
|
const balance = formatCurrencyUnit(account.unit, account.balance, {
|
|
@@ -122,6 +132,39 @@ const cliFormat = (account, level?: string) => {
|
|
|
122
132
|
maybeDisplaySumOfOpsIssue(ta.operations, ta.balance, getAccountUnit(ta))
|
|
123
133
|
)
|
|
124
134
|
.join("\n");
|
|
135
|
+
|
|
136
|
+
if (nfts?.length) {
|
|
137
|
+
const NFTCollections = nftsByCollections(nfts);
|
|
138
|
+
|
|
139
|
+
str += "\n";
|
|
140
|
+
str += `NFT Collections (${NFTCollections.length}) `;
|
|
141
|
+
str += "\n";
|
|
142
|
+
|
|
143
|
+
str += NFTCollections.map(
|
|
144
|
+
// nfts are set to any because there not just NFT, we added a metadata prop on the fly
|
|
145
|
+
// in the first step of the Rxjs flow to avoid having some async code here
|
|
146
|
+
({ contract, nfts }: { contract: string; nfts: any[] }) => {
|
|
147
|
+
const tokenName = nfts?.[0]?.metadata?.tokenName;
|
|
148
|
+
const { bold, magenta, cyan, reverse } = styling;
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
`${bold(tokenName ?? "Unknown Collection Name")} (${magenta(
|
|
152
|
+
contract
|
|
153
|
+
)}): ` +
|
|
154
|
+
nfts
|
|
155
|
+
.map((t) =>
|
|
156
|
+
t?.metadata?.nftName
|
|
157
|
+
? `\n ${t.amount}x ${reverse(
|
|
158
|
+
` ${t?.metadata?.nftName} `
|
|
159
|
+
)} ${cyan("#" + t.tokenId)}`
|
|
160
|
+
: `\n ${t.amount}x ${cyan("#" + t.tokenId)}`
|
|
161
|
+
)
|
|
162
|
+
.join()
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
).join("\n");
|
|
166
|
+
}
|
|
167
|
+
|
|
125
168
|
if (level === "basic") return str;
|
|
126
169
|
str += "\nOPERATIONS (" + operations.length + ")";
|
|
127
170
|
str += operations
|
package/src/apps/polyfill.ts
CHANGED
|
@@ -49,6 +49,9 @@ export const whitelistDependencies = ["Decred", "Decred Testnet"];
|
|
|
49
49
|
["Opensea", "Ethereum"],
|
|
50
50
|
["StakeDAO", "Ethereum"],
|
|
51
51
|
["Yearn", "Ethereum"],
|
|
52
|
+
["RocketPool", "Ethereum"],
|
|
53
|
+
["POAP", "Ethereum"],
|
|
54
|
+
["OlympusDAO", "Ethereum"],
|
|
52
55
|
].forEach(([name, dep]) => declareDep(name, dep));
|
|
53
56
|
export const getDependencies = (appName: string): string[] =>
|
|
54
57
|
directDep[appName] || [];
|
|
Binary file
|
|
@@ -2671,6 +2671,7 @@ Array [
|
|
|
2671
2671
|
"ethereum/erc20/ethereum_cell_network",
|
|
2672
2672
|
"ethereum/erc20/ethereum_dark",
|
|
2673
2673
|
"ethereum/erc20/ethereum_money",
|
|
2674
|
+
"ethereum/erc20/ethereum_name_service",
|
|
2674
2675
|
"ethereum/erc20/ethereum_pro",
|
|
2675
2676
|
"ethereum/erc20/ethereum_push_notification_service",
|
|
2676
2677
|
"ethereum/erc20/ethereum_stake",
|
|
@@ -2994,7 +2995,6 @@ Array [
|
|
|
2994
2995
|
"ethereum/erc20/golden_goose",
|
|
2995
2996
|
"ethereum/erc20/golden_ratio_coin",
|
|
2996
2997
|
"ethereum/erc20/golden_token",
|
|
2997
|
-
"ethereum/erc20/goldenratio",
|
|
2998
2998
|
"ethereum/erc20/goldenugget_token",
|
|
2999
2999
|
"ethereum/erc20/golder_coin",
|
|
3000
3000
|
"ethereum/erc20/goldextoken",
|
|
@@ -3018,6 +3018,7 @@ Array [
|
|
|
3018
3018
|
"ethereum/erc20/grandpa_fan",
|
|
3019
3019
|
"ethereum/erc20/grap",
|
|
3020
3020
|
"ethereum/erc20/grapefruit",
|
|
3021
|
+
"ethereum/erc20/graph_token",
|
|
3021
3022
|
"ethereum/erc20/graphlinq",
|
|
3022
3023
|
"ethereum/erc20/graviton",
|
|
3023
3024
|
"ethereum/erc20/grearn's_token",
|
|
@@ -3889,6 +3890,7 @@ Array [
|
|
|
3889
3890
|
"ethereum/erc20/par_stablecoin",
|
|
3890
3891
|
"ethereum/erc20/paralink_network",
|
|
3891
3892
|
"ethereum/erc20/parallelchain_token",
|
|
3893
|
+
"ethereum/erc20/paraswap",
|
|
3892
3894
|
"ethereum/erc20/pareto",
|
|
3893
3895
|
"ethereum/erc20/paribus",
|
|
3894
3896
|
"ethereum/erc20/parsec_finance",
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
hasCryptoCurrencyId,
|
|
10
10
|
} from "@ledgerhq/cryptoassets";
|
|
11
11
|
import { getEnv } from "../env";
|
|
12
|
+
|
|
12
13
|
// set by user side effect to precise which currencies are considered supported (typically by live)
|
|
13
14
|
let userSupportedCurrencies: CryptoCurrency[] = [];
|
|
14
15
|
let userSupportedFiats: FiatCurrency[] = [];
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Ported from https://github.com/bitcoinjs/bech32/tree/605655d6b37a782345549cd1388db688a96ad56f
|
|
2
|
+
// until we can use bech32 2.0.0
|
|
3
|
+
// We can't directly use bech32 2.0.0 because many of our dependencies are still using bech32 ^1.1.3
|
|
4
|
+
// which conflict on mobile (root cause of https://ledgerhq.atlassian.net/browse/LL-7930)
|
|
5
|
+
// FIXME Remove that file and use bech32 2.0.0 when all dependencies also uses it.
|
|
6
|
+
|
|
7
|
+
const ENCODING_CONST = 0x2bc830a3;
|
|
8
|
+
const ALPHABET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
9
|
+
const ALPHABET_MAP: { [key: string]: number } = {};
|
|
10
|
+
for (let z = 0; z < ALPHABET.length; z++) {
|
|
11
|
+
const x = ALPHABET.charAt(z);
|
|
12
|
+
ALPHABET_MAP[x] = z;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function prefixChk(prefix) {
|
|
16
|
+
let chk = 1;
|
|
17
|
+
for (let i = 0; i < prefix.length; ++i) {
|
|
18
|
+
const c = prefix.charCodeAt(i);
|
|
19
|
+
if (c < 33 || c > 126) return "Invalid prefix (" + prefix + ")";
|
|
20
|
+
chk = polymodStep(chk) ^ (c >> 5);
|
|
21
|
+
}
|
|
22
|
+
chk = polymodStep(chk);
|
|
23
|
+
for (let i = 0; i < prefix.length; ++i) {
|
|
24
|
+
const v = prefix.charCodeAt(i);
|
|
25
|
+
chk = polymodStep(chk) ^ (v & 0x1f);
|
|
26
|
+
}
|
|
27
|
+
return chk;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function polymodStep(pre: number): number {
|
|
31
|
+
const b = pre >> 25;
|
|
32
|
+
return (
|
|
33
|
+
((pre & 0x1ffffff) << 5) ^
|
|
34
|
+
(-((b >> 0) & 1) & 0x3b6a57b2) ^
|
|
35
|
+
(-((b >> 1) & 1) & 0x26508e6d) ^
|
|
36
|
+
(-((b >> 2) & 1) & 0x1ea119fa) ^
|
|
37
|
+
(-((b >> 3) & 1) & 0x3d4233dd) ^
|
|
38
|
+
(-((b >> 4) & 1) & 0x2a1462b3)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function encode(
|
|
43
|
+
prefix: string,
|
|
44
|
+
words: ArrayLike<number>,
|
|
45
|
+
LIMIT?: number
|
|
46
|
+
): string {
|
|
47
|
+
LIMIT = LIMIT || 90;
|
|
48
|
+
if (prefix.length + 7 + words.length > LIMIT)
|
|
49
|
+
throw new TypeError("Exceeds length limit");
|
|
50
|
+
|
|
51
|
+
prefix = prefix.toLowerCase();
|
|
52
|
+
|
|
53
|
+
// determine chk mod
|
|
54
|
+
let chk = prefixChk(prefix);
|
|
55
|
+
if (typeof chk === "string") throw new Error(chk);
|
|
56
|
+
|
|
57
|
+
let result = prefix + "1";
|
|
58
|
+
for (let i = 0; i < words.length; ++i) {
|
|
59
|
+
const x = words[i];
|
|
60
|
+
if (x >> 5 !== 0) throw new Error("Non 5-bit word");
|
|
61
|
+
|
|
62
|
+
chk = polymodStep(chk) ^ x;
|
|
63
|
+
result += ALPHABET.charAt(x);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < 6; ++i) {
|
|
67
|
+
chk = polymodStep(chk);
|
|
68
|
+
}
|
|
69
|
+
chk ^= ENCODING_CONST;
|
|
70
|
+
|
|
71
|
+
for (let i = 0; i < 6; ++i) {
|
|
72
|
+
const v = (chk >> ((5 - i) * 5)) & 0x1f;
|
|
73
|
+
result += ALPHABET.charAt(v);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function __decode(str: string, LIMIT?: number) {
|
|
80
|
+
LIMIT = LIMIT || 90;
|
|
81
|
+
if (str.length < 8) return str + " too short";
|
|
82
|
+
if (str.length > LIMIT) return "Exceeds length limit";
|
|
83
|
+
|
|
84
|
+
// don't allow mixed case
|
|
85
|
+
const lowered = str.toLowerCase();
|
|
86
|
+
const uppered = str.toUpperCase();
|
|
87
|
+
if (str !== lowered && str !== uppered) return "Mixed-case string " + str;
|
|
88
|
+
str = lowered;
|
|
89
|
+
|
|
90
|
+
const split = str.lastIndexOf("1");
|
|
91
|
+
if (split === -1) return "No separator character for " + str;
|
|
92
|
+
if (split === 0) return "Missing prefix for " + str;
|
|
93
|
+
|
|
94
|
+
const prefix = str.slice(0, split);
|
|
95
|
+
const wordChars = str.slice(split + 1);
|
|
96
|
+
if (wordChars.length < 6) return "Data too short";
|
|
97
|
+
|
|
98
|
+
let chk = prefixChk(prefix);
|
|
99
|
+
if (typeof chk === "string") return chk;
|
|
100
|
+
|
|
101
|
+
const words: number[] = [];
|
|
102
|
+
for (let i = 0; i < wordChars.length; ++i) {
|
|
103
|
+
const c = wordChars.charAt(i);
|
|
104
|
+
const v = ALPHABET_MAP[c];
|
|
105
|
+
if (v === undefined) return "Unknown character " + c;
|
|
106
|
+
chk = polymodStep(chk) ^ v;
|
|
107
|
+
|
|
108
|
+
// not in the checksum?
|
|
109
|
+
if (i + 6 >= wordChars.length) continue;
|
|
110
|
+
words.push(v);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (chk !== ENCODING_CONST) return "Invalid checksum for " + str;
|
|
114
|
+
return { prefix, words };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function decodeUnsafe(str: string, LIMIT?: number) {
|
|
118
|
+
const res = __decode(str, LIMIT);
|
|
119
|
+
if (typeof res === "object") return res;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function decode(str: string, LIMIT?: number) {
|
|
123
|
+
const res = __decode(str, LIMIT);
|
|
124
|
+
if (typeof res === "object") return res;
|
|
125
|
+
|
|
126
|
+
throw new Error(res);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function convert(
|
|
130
|
+
data: ArrayLike<number>,
|
|
131
|
+
inBits: number,
|
|
132
|
+
outBits: number,
|
|
133
|
+
pad: true
|
|
134
|
+
): number[];
|
|
135
|
+
function convert(
|
|
136
|
+
data: ArrayLike<number>,
|
|
137
|
+
inBits: number,
|
|
138
|
+
outBits: number,
|
|
139
|
+
pad: false
|
|
140
|
+
): number[] | string;
|
|
141
|
+
function convert(
|
|
142
|
+
data: ArrayLike<number>,
|
|
143
|
+
inBits: number,
|
|
144
|
+
outBits: number,
|
|
145
|
+
pad: boolean
|
|
146
|
+
): number[] | string {
|
|
147
|
+
let value = 0;
|
|
148
|
+
let bits = 0;
|
|
149
|
+
const maxV = (1 << outBits) - 1;
|
|
150
|
+
|
|
151
|
+
const result: number[] = [];
|
|
152
|
+
for (let i = 0; i < data.length; ++i) {
|
|
153
|
+
value = (value << inBits) | data[i];
|
|
154
|
+
bits += inBits;
|
|
155
|
+
|
|
156
|
+
while (bits >= outBits) {
|
|
157
|
+
bits -= outBits;
|
|
158
|
+
result.push((value >> bits) & maxV);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (pad) {
|
|
163
|
+
if (bits > 0) {
|
|
164
|
+
result.push((value << (outBits - bits)) & maxV);
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
if (bits >= inBits) return "Excess padding";
|
|
168
|
+
if ((value << (outBits - bits)) & maxV) return "Non-zero padding";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function toWords(bytes: ArrayLike<number>): number[] {
|
|
175
|
+
return convert(bytes, 8, 5, true);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function fromWordsUnsafe(words: ArrayLike<number>): number[] | undefined {
|
|
179
|
+
const res = convert(words, 5, 8, false);
|
|
180
|
+
if (Array.isArray(res)) return res;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function fromWords(words: ArrayLike<number>): number[] {
|
|
184
|
+
const res = convert(words, 5, 8, false);
|
|
185
|
+
if (Array.isArray(res)) return res;
|
|
186
|
+
|
|
187
|
+
throw new Error(res);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export const bech32m = {
|
|
191
|
+
decodeUnsafe,
|
|
192
|
+
decode,
|
|
193
|
+
encode,
|
|
194
|
+
toWords,
|
|
195
|
+
fromWordsUnsafe,
|
|
196
|
+
fromWords,
|
|
197
|
+
};
|
|
@@ -28,6 +28,10 @@ const networkInfo: NetworkInfoRaw = {
|
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
30
|
const dataset: CurrenciesData<Transaction> = {
|
|
31
|
+
FIXME_ignoreAccountFields: [
|
|
32
|
+
"bitcoinResources.walletAccount", // it is not "stable"
|
|
33
|
+
"bitcoinResources.utxos", // TODO: fix ordering
|
|
34
|
+
],
|
|
31
35
|
scanAccounts: [scanAccounts1],
|
|
32
36
|
accounts: [
|
|
33
37
|
{
|