mainnet-js 3.1.7 → 4.0.0-next.10
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/dist/module/cache/IndexedDbCache.d.ts +1 -1
- package/dist/module/cache/IndexedDbCache.d.ts.map +1 -1
- package/dist/module/cache/MemoryCache.d.ts +1 -1
- package/dist/module/cache/MemoryCache.d.ts.map +1 -1
- package/dist/module/cache/WebStorageCache.d.ts +1 -1
- package/dist/module/cache/WebStorageCache.d.ts.map +1 -1
- package/dist/module/cache/walletCache.d.ts +16 -6
- package/dist/module/cache/walletCache.d.ts.map +1 -1
- package/dist/module/cache/walletCache.js +92 -34
- package/dist/module/cache/walletCache.js.map +1 -1
- package/dist/module/cli.js +1 -2
- package/dist/module/cli.js.map +1 -1
- package/dist/module/db/index.d.ts +1 -1
- package/dist/module/db/index.d.ts.map +1 -1
- package/dist/module/db/index.js +1 -1
- package/dist/module/db/index.js.map +1 -1
- package/dist/module/enum.d.ts +1 -1
- package/dist/module/enum.d.ts.map +1 -1
- package/dist/module/history/getHistory.d.ts +1 -1
- package/dist/module/history/getHistory.d.ts.map +1 -1
- package/dist/module/history/getHistory.js +3 -3
- package/dist/module/history/getHistory.js.map +1 -1
- package/dist/module/index.d.ts +25 -22
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +33 -26
- package/dist/module/index.js.map +1 -1
- package/dist/module/interface.d.ts +12 -2
- package/dist/module/interface.d.ts.map +1 -1
- package/dist/module/interface.js.map +1 -1
- package/dist/module/libauth.d.ts +1 -1
- package/dist/module/libauth.d.ts.map +1 -1
- package/dist/module/libauth.js +1 -1
- package/dist/module/libauth.js.map +1 -1
- package/dist/module/mine/mine.d.ts +2 -7
- package/dist/module/mine/mine.d.ts.map +1 -1
- package/dist/module/mine/mine.js +6 -27
- package/dist/module/mine/mine.js.map +1 -1
- package/dist/module/network/Connection.d.ts +1 -12
- package/dist/module/network/Connection.d.ts.map +1 -1
- package/dist/module/network/Connection.js +24 -33
- package/dist/module/network/Connection.js.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.d.ts +16 -17
- package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.js +91 -93
- package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
- package/dist/module/network/MockNetworkProvider.d.ts +28 -0
- package/dist/module/network/MockNetworkProvider.d.ts.map +1 -0
- package/dist/module/network/MockNetworkProvider.js +74 -0
- package/dist/module/network/MockNetworkProvider.js.map +1 -0
- package/dist/module/network/NetworkProvider.d.ts +9 -2
- package/dist/module/network/NetworkProvider.d.ts.map +1 -1
- package/dist/module/network/configuration.d.ts +2 -4
- package/dist/module/network/configuration.d.ts.map +1 -1
- package/dist/module/network/configuration.js +25 -50
- package/dist/module/network/configuration.js.map +1 -1
- package/dist/module/network/constant.d.ts +7 -7
- package/dist/module/network/constant.d.ts.map +1 -1
- package/dist/module/network/constant.js +21 -24
- package/dist/module/network/constant.js.map +1 -1
- package/dist/module/network/default.d.ts +5 -3
- package/dist/module/network/default.d.ts.map +1 -1
- package/dist/module/network/default.js +29 -51
- package/dist/module/network/default.js.map +1 -1
- package/dist/module/network/index.d.ts +4 -4
- package/dist/module/network/index.d.ts.map +1 -1
- package/dist/module/network/index.js +2 -2
- package/dist/module/network/index.js.map +1 -1
- package/dist/module/network/interface.d.ts +0 -6
- package/dist/module/network/interface.d.ts.map +1 -1
- package/dist/module/rate/ExchangeRate.d.ts +1 -1
- package/dist/module/rate/ExchangeRate.d.ts.map +1 -1
- package/dist/module/rate/ExchangeRate.js +13 -7
- package/dist/module/rate/ExchangeRate.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +3 -3
- package/dist/module/transaction/Wif.d.ts.map +1 -1
- package/dist/module/transaction/Wif.js +4 -4
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/transaction/allocateFee.d.ts +1 -1
- package/dist/module/transaction/allocateFee.d.ts.map +1 -1
- package/dist/module/transaction/allocateFee.js +2 -2
- package/dist/module/transaction/allocateFee.js.map +1 -1
- package/dist/module/util/deriveCashaddr.js.map +1 -1
- package/dist/module/util/deriveNetwork.js +1 -1
- package/dist/module/util/deriveNetwork.js.map +1 -1
- package/dist/module/util/getAddrsByXpubKey.js +1 -1
- package/dist/module/util/getAddrsByXpubKey.js.map +1 -1
- package/dist/module/util/getXPubKey.js +1 -1
- package/dist/module/util/getXPubKey.js.map +1 -1
- package/dist/module/util/hd.d.ts +2 -0
- package/dist/module/util/hd.d.ts.map +1 -1
- package/dist/module/util/hd.js +41 -0
- package/dist/module/util/hd.js.map +1 -1
- package/dist/module/util/index.d.ts +7 -9
- package/dist/module/util/index.d.ts.map +1 -1
- package/dist/module/util/index.js +7 -9
- package/dist/module/util/index.js.map +1 -1
- package/dist/module/util/transaction.js +1 -1
- package/dist/module/util/transaction.js.map +1 -1
- package/dist/module/wallet/Base.d.ts +13 -9
- package/dist/module/wallet/Base.d.ts.map +1 -1
- package/dist/module/wallet/Base.js +54 -58
- package/dist/module/wallet/Base.js.map +1 -1
- package/dist/module/wallet/HDWallet.d.ts.map +1 -1
- package/dist/module/wallet/HDWallet.js +19 -38
- package/dist/module/wallet/HDWallet.js.map +1 -1
- package/dist/module/wallet/Util.d.ts +4 -22
- package/dist/module/wallet/Util.d.ts.map +1 -1
- package/dist/module/wallet/Util.js +75 -102
- package/dist/module/wallet/Util.js.map +1 -1
- package/dist/module/wallet/Watch.d.ts +24 -5
- package/dist/module/wallet/Watch.d.ts.map +1 -1
- package/dist/module/wallet/Watch.js +141 -17
- package/dist/module/wallet/Watch.js.map +1 -1
- package/dist/module/wallet/Wif.d.ts +2 -6
- package/dist/module/wallet/Wif.d.ts.map +1 -1
- package/dist/module/wallet/Wif.js +3 -69
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/module/wallet/createWallet.d.ts +1 -1
- package/dist/module/wallet/createWallet.d.ts.map +1 -1
- package/dist/module/wallet/createWallet.js +2 -1
- package/dist/module/wallet/createWallet.js.map +1 -1
- package/dist/module/wallet/interface.d.ts +3 -2
- package/dist/module/wallet/interface.d.ts.map +1 -1
- package/dist/module/wallet/model.d.ts +2 -1
- package/dist/module/wallet/model.d.ts.map +1 -1
- package/dist/module/wallet/model.js +1 -1
- package/dist/module/wallet/model.js.map +1 -1
- package/package.json +17 -29
- package/dist/index.html +0 -9
- package/dist/mainnet-3.1.7.js +0 -2066
- package/dist/module/network/util.d.ts +0 -3
- package/dist/module/network/util.d.ts.map +0 -1
- package/dist/module/network/util.js +0 -27
- package/dist/module/network/util.js.map +0 -1
- package/dist/module/test/expect.d.ts +0 -12
- package/dist/module/test/expect.d.ts.map +0 -1
- package/dist/module/test/expect.js +0 -47
- package/dist/module/test/expect.js.map +0 -1
- package/dist/module/test/fetch.d.ts +0 -3
- package/dist/module/test/fetch.d.ts.map +0 -1
- package/dist/module/test/fetch.js +0 -32
- package/dist/module/test/fetch.js.map +0 -1
- package/dist/module/util/randomBytes.d.ts +0 -2
- package/dist/module/util/randomBytes.d.ts.map +0 -1
- package/dist/module/util/randomBytes.js +0 -13
- package/dist/module/util/randomBytes.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/cache/IndexedDbCache.test.ts +0 -15
- package/src/cache/IndexedDbCache.ts +0 -172
- package/src/cache/MemoryCache.test.ts +0 -15
- package/src/cache/MemoryCache.ts +0 -32
- package/src/cache/WebStorageCache.test.ts +0 -15
- package/src/cache/WebStorageCache.ts +0 -38
- package/src/cache/index.ts +0 -2
- package/src/cache/interface.ts +0 -9
- package/src/cache/walletCache.ts +0 -254
- package/src/chain.ts +0 -3
- package/src/cli.ts +0 -32
- package/src/config.ts +0 -23
- package/src/constant.ts +0 -27
- package/src/db/ExchangeRateProvider.ts +0 -28
- package/src/db/StorageProvider.ts +0 -64
- package/src/db/index.ts +0 -2
- package/src/db/interface.ts +0 -11
- package/src/enum.ts +0 -34
- package/src/history/getHistory.test.ts +0 -290
- package/src/history/getHistory.ts +0 -411
- package/src/history/interface.ts +0 -24
- package/src/index.ts +0 -48
- package/src/interface.ts +0 -72
- package/src/libauth.ts +0 -11
- package/src/message/index.ts +0 -2
- package/src/message/interface.ts +0 -40
- package/src/message/signed.test.ts +0 -309
- package/src/message/signed.ts +0 -201
- package/src/mine/index.ts +0 -1
- package/src/mine/mine.test.ts +0 -10
- package/src/mine/mine.ts +0 -42
- package/src/network/Connection.test.ts +0 -51
- package/src/network/Connection.ts +0 -73
- package/src/network/ElectrumNetworkProvider.ts +0 -657
- package/src/network/NetworkProvider.ts +0 -180
- package/src/network/Rpc.test.ts +0 -130
- package/src/network/configuration.test.ts +0 -59
- package/src/network/configuration.ts +0 -72
- package/src/network/constant.ts +0 -43
- package/src/network/default.ts +0 -120
- package/src/network/electrum.test.ts +0 -28
- package/src/network/getRelayFeeCache.test.ts +0 -15
- package/src/network/getRelayFeeCache.ts +0 -23
- package/src/network/index.ts +0 -14
- package/src/network/interface.ts +0 -80
- package/src/network/util.test.ts +0 -24
- package/src/network/util.ts +0 -30
- package/src/rate/ExchangeRate.test.headless.js +0 -35
- package/src/rate/ExchangeRate.test.ts +0 -51
- package/src/rate/ExchangeRate.ts +0 -142
- package/src/test/expect.ts +0 -59
- package/src/test/fetch.ts +0 -39
- package/src/test/json.test.ts +0 -13
- package/src/transaction/Wif.ts +0 -680
- package/src/transaction/allocateFee.test.ts +0 -298
- package/src/transaction/allocateFee.ts +0 -149
- package/src/util/amountInSatoshi.test.ts +0 -27
- package/src/util/amountInSatoshi.ts +0 -33
- package/src/util/asSendRequestObject.ts +0 -81
- package/src/util/base64.test.ts +0 -39
- package/src/util/base64.ts +0 -12
- package/src/util/browserNotSupported.ts +0 -7
- package/src/util/checkForEmptySeed.ts +0 -9
- package/src/util/checkUtxos.ts +0 -29
- package/src/util/checkWifNetwork.ts +0 -24
- package/src/util/convert.test.ts +0 -46
- package/src/util/convert.ts +0 -50
- package/src/util/delay.ts +0 -3
- package/src/util/deriveCashaddr.test.ts +0 -164
- package/src/util/deriveCashaddr.ts +0 -143
- package/src/util/deriveLockscript.ts +0 -16
- package/src/util/deriveNetwork.ts +0 -19
- package/src/util/derivePublicKeyHash.test.ts +0 -55
- package/src/util/derivePublicKeyHash.ts +0 -64
- package/src/util/floor.test.ts +0 -21
- package/src/util/floor.ts +0 -4
- package/src/util/getAddrsByXpubKey.test.ts +0 -115
- package/src/util/getAddrsByXpubKey.ts +0 -86
- package/src/util/getRuntimePlatform.test.headless.js +0 -40
- package/src/util/getRuntimePlatform.test.ts +0 -5
- package/src/util/getRuntimePlatform.ts +0 -31
- package/src/util/getUsdRate.ts +0 -5
- package/src/util/getXPubKey.ts +0 -39
- package/src/util/hash160.test.ts +0 -18
- package/src/util/hash160.ts +0 -12
- package/src/util/hd.ts +0 -16
- package/src/util/header.test.ts +0 -34
- package/src/util/header.ts +0 -26
- package/src/util/index.ts +0 -33
- package/src/util/randomBytes.ts +0 -13
- package/src/util/randomInt.test.ts +0 -15
- package/src/util/randomInt.ts +0 -4
- package/src/util/sanitizeAddress.ts +0 -10
- package/src/util/sanitizeUnit.ts +0 -11
- package/src/util/satoshiToAmount.test.ts +0 -6
- package/src/util/satoshiToAmount.ts +0 -33
- package/src/util/sumSendRequestAmounts.ts +0 -34
- package/src/util/sumUtxoValue.ts +0 -27
- package/src/util/transaction.ts +0 -10
- package/src/wallet/Base.ts +0 -1563
- package/src/wallet/Cashtokens.test.headless.js +0 -730
- package/src/wallet/Cashtokens.test.ts +0 -1411
- package/src/wallet/HDWallet.test.ts +0 -1086
- package/src/wallet/HDWallet.ts +0 -992
- package/src/wallet/Util.test.ts +0 -134
- package/src/wallet/Util.ts +0 -191
- package/src/wallet/WalletCache.test.ts +0 -45
- package/src/wallet/Watch.ts +0 -441
- package/src/wallet/Wif.bip39.test.ts +0 -48
- package/src/wallet/Wif.test.ts +0 -1189
- package/src/wallet/Wif.ts +0 -687
- package/src/wallet/Wif.watchOnly.test.ts +0 -58
- package/src/wallet/createWallet.ts +0 -238
- package/src/wallet/enum.ts +0 -18
- package/src/wallet/interface.ts +0 -102
- package/src/wallet/model.test.ts +0 -24
- package/src/wallet/model.ts +0 -352
- package/tsconfig.browser.json +0 -11
- package/tsconfig.json +0 -33
- package/webpack.config.cjs +0 -132
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
derivePublicNodeCashaddr,
|
|
3
|
-
getAddrsByXpubKey,
|
|
4
|
-
getXpubKeyInfo,
|
|
5
|
-
} from "./getAddrsByXpubKey";
|
|
6
|
-
|
|
7
|
-
test("Should decode xpubInfo", async () => {
|
|
8
|
-
let xpub =
|
|
9
|
-
"xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhawA7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj";
|
|
10
|
-
let xpubInfo = getXpubKeyInfo(xpub);
|
|
11
|
-
expect(xpubInfo.version).toBe("mainnet");
|
|
12
|
-
expect(xpubInfo.depth).toBe(3);
|
|
13
|
-
expect(xpubInfo.parentFingerprint).toBe("155bca59");
|
|
14
|
-
expect(xpubInfo.childNumber).toBe(2147483648);
|
|
15
|
-
expect(xpubInfo.chain).toBe(
|
|
16
|
-
"3da4bc190a2680111d31fadfdc905f2a7f6ce77c6f109919116f253d43445219"
|
|
17
|
-
);
|
|
18
|
-
expect(xpubInfo.data).toBe(
|
|
19
|
-
"03774c910fcf07fa96886ea794f0d5caed9afe30b44b83f7e213bb92930e7df4bd"
|
|
20
|
-
);
|
|
21
|
-
expect(xpubInfo.fingerprint).toBe("6cc9f252");
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test("Should derive cashaddr given xpub and path", async () => {
|
|
25
|
-
// abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
|
|
26
|
-
// m/44'/145'/0'/0/
|
|
27
|
-
const xpub =
|
|
28
|
-
"xpub6F2iaK2JUPcgrZ6RTGH6t8VybLPu1XzfrHsDsaKvK6NfULznU6i6aw6ZoefDW2DpNruSLw73RwQg46qvpqB3eryeJJ2tkFCF4Z6gbr8Pjja";
|
|
29
|
-
const vectors = [
|
|
30
|
-
// M/44'/145'/0'/0/0
|
|
31
|
-
"bitcoincash:qqyx49mu0kkn9ftfj6hje6g2wfer34yfnq5tahq3q6",
|
|
32
|
-
// M/44'/145'/0'/0/1
|
|
33
|
-
"bitcoincash:qp8sfdhgjlq68hlzka9lcsxtcnvuvnd0xqxugfzzc5",
|
|
34
|
-
// M/44'/145'/0'/0/2
|
|
35
|
-
"bitcoincash:qqkuy34ntrye9a2h4xpdstcu4aq5wfrwscjtaphenr",
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
for (let i = 0; i < vectors.length; i++) {
|
|
39
|
-
// M/44'/145'/0'/0/
|
|
40
|
-
const publicNode = derivePublicNodeCashaddr(xpub, `${i}`);
|
|
41
|
-
expect(publicNode).toBe(vectors[i]);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("Should derive list of cashaddrs from m/44'/0'/0' given xpub path, & limit", async () => {
|
|
46
|
-
// abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
|
|
47
|
-
// m/44'/0'/0'
|
|
48
|
-
const xpub =
|
|
49
|
-
"xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhawA7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj";
|
|
50
|
-
const vectors = [
|
|
51
|
-
// m/44'/0'/0'/0/0
|
|
52
|
-
"bitcoincash:qrvcdmgpk73zyfd8pmdl9wnuld36zh9n4gms8s0u59",
|
|
53
|
-
// m/44'/0'/0'/0/1
|
|
54
|
-
"bitcoincash:qp4wzvqu73x22ft4r5tk8tz0aufdz9fescwtpcmhc7",
|
|
55
|
-
// m/44'/0'/0'/0/2
|
|
56
|
-
"bitcoincash:qr0kwqzf2h3wvjjhn4pg895lrxwp96wqgyhkksq2nh",
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
// M/44'/0'/0'/0/i
|
|
60
|
-
const cashaddrs = getAddrsByXpubKey(xpub, "0/0", 3);
|
|
61
|
-
expect(cashaddrs).toStrictEqual(vectors);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test("Should derive list of change cashaddrs from m/44'/0'/0' given xpub path, & limit", async () => {
|
|
65
|
-
// abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
|
|
66
|
-
// m/44'/0'/0'
|
|
67
|
-
const xpub =
|
|
68
|
-
"xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhawA7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj";
|
|
69
|
-
const vectors = [
|
|
70
|
-
// m/44'/0'/0'/1/0
|
|
71
|
-
"bitcoincash:qzawj0yw07mgys3dy3uqkxsj54gwlapg7gjw8v3grk",
|
|
72
|
-
// m/44'/0'/0'/1/1
|
|
73
|
-
"bitcoincash:qqsqv86eghvyxcq7q5eg3l3ad7r7xcff65egddy9e9",
|
|
74
|
-
// m/44'/0'/0'/1/2
|
|
75
|
-
"bitcoincash:qrdexhxheryn7n2kf2s7g9kypfe0ynakrqm3j0f69w",
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
// M/44'/0'/0'/0/i
|
|
79
|
-
const cashaddrs = getAddrsByXpubKey(xpub, "1/0", 3);
|
|
80
|
-
expect(cashaddrs).toStrictEqual(vectors);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("Should derive list of cashaddrs from M/44'/145'/0' given xpub, path and limit", async () => {
|
|
84
|
-
// abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
|
|
85
|
-
// m/44'/145'/0'
|
|
86
|
-
const xpub =
|
|
87
|
-
"xpub6ByHsPNSQXTWZ7PLESMY2FufyYWtLXagSUpMQq7Un96SiThZH2iJB1X7pwviH1WtKVeDP6K8d6xxFzzoaFzF3s8BKCZx8oEDdDkNnp4owAZ";
|
|
88
|
-
const vectors = [
|
|
89
|
-
// M/44'/145'/0'/0/0
|
|
90
|
-
"bitcoincash:qqyx49mu0kkn9ftfj6hje6g2wfer34yfnq5tahq3q6",
|
|
91
|
-
// M/44'/145'/0'/0/1
|
|
92
|
-
"bitcoincash:qp8sfdhgjlq68hlzka9lcsxtcnvuvnd0xqxugfzzc5",
|
|
93
|
-
// M/44'/145'/0'/0/2
|
|
94
|
-
"bitcoincash:qqkuy34ntrye9a2h4xpdstcu4aq5wfrwscjtaphenr",
|
|
95
|
-
];
|
|
96
|
-
|
|
97
|
-
const cashaddrs = getAddrsByXpubKey(xpub, "0/0", 3);
|
|
98
|
-
expect(cashaddrs).toStrictEqual(vectors);
|
|
99
|
-
});
|
|
100
|
-
test("Should derive list of change cashaddrs from M/44'/145'/0' given xpub, path and limit", async () => {
|
|
101
|
-
// abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
|
|
102
|
-
// m/44'/145'/0'
|
|
103
|
-
const xpub =
|
|
104
|
-
"xpub6ByHsPNSQXTWZ7PLESMY2FufyYWtLXagSUpMQq7Un96SiThZH2iJB1X7pwviH1WtKVeDP6K8d6xxFzzoaFzF3s8BKCZx8oEDdDkNnp4owAZ";
|
|
105
|
-
const vectors = [
|
|
106
|
-
// M/44'/145'/0'/1/0
|
|
107
|
-
"bitcoincash:qr8aeharupyrmhfu0d4tdmsnc5y8cfk47y6qrsjsrx",
|
|
108
|
-
// M/44'/145'/0'/1/1
|
|
109
|
-
"bitcoincash:qr88m3rp5nd5aerz5rh9lzly9u5pevykagwscmjk0c",
|
|
110
|
-
// M/44'/145'/0'/1/2
|
|
111
|
-
"bitcoincash:qp57cex47jtyhedphe2c63gpzsx3zs0ryvejxly47d",
|
|
112
|
-
];
|
|
113
|
-
const cashaddrs = getAddrsByXpubKey(xpub, "1/0", 3);
|
|
114
|
-
expect(cashaddrs).toStrictEqual(vectors);
|
|
115
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
decodeHdPublicKey,
|
|
3
|
-
encodeCashAddress,
|
|
4
|
-
binToHex,
|
|
5
|
-
CashAddressNetworkPrefix,
|
|
6
|
-
CashAddressType,
|
|
7
|
-
deriveHdPathRelative,
|
|
8
|
-
} from "@bitauth/libauth";
|
|
9
|
-
|
|
10
|
-
import { hash160 } from "./hash160.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Derive cashsaddresses given the `xpub`, relative `path` and count of addresses to derive.
|
|
14
|
-
*
|
|
15
|
-
* @param xpub the parent xpubkey from which to derive child public keys, for example `xpub6ByHsPNSQXTWZ7PLESMY2FufyYWtLXagSUpMQq7Un96SiThZH2iJB1X7pwviH1WtKVeDP6K8d6xxFzzoaFzF3s8BKCZx8oEDdDkNnp4owAZ` at `m/44'/145'/0'`
|
|
16
|
-
* @param path relative path from the parent xpubkey to derive the child public keys, for example "0/0" for receiving addresses or "1/0" for change addresses
|
|
17
|
-
* @param count amount of child public keys to derive
|
|
18
|
-
* @returns array of cashaddresses derived from the xpubkey
|
|
19
|
-
*/
|
|
20
|
-
export function getAddrsByXpubKey(
|
|
21
|
-
xpub: string,
|
|
22
|
-
path: string,
|
|
23
|
-
count: number
|
|
24
|
-
): Array<string> {
|
|
25
|
-
const pathComponents = path.split("/");
|
|
26
|
-
const result: Array<string> = [];
|
|
27
|
-
|
|
28
|
-
const start = parseInt(pathComponents.pop()!);
|
|
29
|
-
const end = start + count;
|
|
30
|
-
for (let curr = start; curr < end; curr++) {
|
|
31
|
-
const childPath = [...pathComponents, curr].join("/");
|
|
32
|
-
result.push(derivePublicNodeCashaddr(xpub, childPath));
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function getAddrsByXpubKeyObject(obj): Array<string> {
|
|
38
|
-
return getAddrsByXpubKey(obj.xpubkey, obj.path, obj.count);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function derivePublicNodeCashaddr(xpub: string, path?: string): string {
|
|
42
|
-
const publicParent = decodeHdPublicKey(xpub);
|
|
43
|
-
|
|
44
|
-
if (typeof publicParent === "string") {
|
|
45
|
-
throw new Error(publicParent);
|
|
46
|
-
}
|
|
47
|
-
const prefix = (
|
|
48
|
-
publicParent.network === "mainnet" ? "bitcoincash" : "bchtest"
|
|
49
|
-
) as CashAddressNetworkPrefix;
|
|
50
|
-
|
|
51
|
-
let cashaddr;
|
|
52
|
-
if (typeof path === "string") {
|
|
53
|
-
const childNode = deriveHdPathRelative(publicParent.node, path);
|
|
54
|
-
if (typeof childNode === "string") {
|
|
55
|
-
throw new Error(childNode);
|
|
56
|
-
} else {
|
|
57
|
-
const childPkh = hash160(childNode.publicKey);
|
|
58
|
-
cashaddr = encodeCashAddress({
|
|
59
|
-
prefix,
|
|
60
|
-
type: CashAddressType.p2pkh,
|
|
61
|
-
payload: childPkh,
|
|
62
|
-
}).address;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return cashaddr;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function getXpubKeyInfo(hdPublicKey: string) {
|
|
69
|
-
const node = decodeHdPublicKey(hdPublicKey);
|
|
70
|
-
if (typeof node === "string") {
|
|
71
|
-
throw new Error(node);
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
version: node.network,
|
|
75
|
-
depth: node.node.depth,
|
|
76
|
-
parentFingerprint: binToHex(node.node.parentFingerprint),
|
|
77
|
-
childNumber: node.node.childIndex,
|
|
78
|
-
chain: binToHex(node.node.chainCode),
|
|
79
|
-
data: binToHex(node.node.publicKey),
|
|
80
|
-
fingerprint: binToHex(hash160(node.node.publicKey).slice(0, 4)),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export async function getXpubKeyInfoObject(obj) {
|
|
85
|
-
return getXpubKeyInfo(obj.xpubkey);
|
|
86
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const playwright = require("playwright");
|
|
2
|
-
const PAGE_URL = "http://localhost:8080";
|
|
3
|
-
|
|
4
|
-
describe(`Wallet should function in the browser`, () => {
|
|
5
|
-
let browser = null;
|
|
6
|
-
let page = null;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Create the browser and page context
|
|
10
|
-
*/
|
|
11
|
-
beforeAll(async () => {
|
|
12
|
-
browser = await playwright["chromium"].launch();
|
|
13
|
-
page = await browser.newPage();
|
|
14
|
-
|
|
15
|
-
if (!page) {
|
|
16
|
-
throw new Error("Connection wasn't established");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Open the page
|
|
20
|
-
await page.goto(PAGE_URL, {
|
|
21
|
-
waitUntil: "networkidle0",
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterAll(async () => {
|
|
26
|
-
await browser.close();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test(`Should load page`, async () => {
|
|
30
|
-
expect(page).not.toBeNull();
|
|
31
|
-
expect(await page.title()).toEqual("The Empty Mainnet App");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test(`Should recognize browser as platform`, async () => {
|
|
35
|
-
const result = await page.evaluate(async () => {
|
|
36
|
-
return Mainnet.getRuntimePlatform();
|
|
37
|
-
});
|
|
38
|
-
expect(result).toBe("browser");
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export enum RuntimePlatform {
|
|
2
|
-
node = "node",
|
|
3
|
-
browser = "browser",
|
|
4
|
-
webworker = "webworker",
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function getRuntimePlatform(): RuntimePlatform {
|
|
8
|
-
// https://github.com/foo123/asynchronous.js/blob/master/asynchronous.js
|
|
9
|
-
if (
|
|
10
|
-
"undefined" !== typeof global &&
|
|
11
|
-
("[object global]" === toString.call(global) ||
|
|
12
|
-
"[object Object]" === toString.call(global))
|
|
13
|
-
) {
|
|
14
|
-
return RuntimePlatform.node;
|
|
15
|
-
} else {
|
|
16
|
-
if (
|
|
17
|
-
"undefined" !== typeof WorkerGlobalScope &&
|
|
18
|
-
"function" === typeof importScripts &&
|
|
19
|
-
navigator instanceof WorkerNavigator
|
|
20
|
-
) {
|
|
21
|
-
return RuntimePlatform.webworker;
|
|
22
|
-
} else if (
|
|
23
|
-
"undefined" !== typeof navigator &&
|
|
24
|
-
"undefined" !== typeof document
|
|
25
|
-
) {
|
|
26
|
-
return RuntimePlatform.browser;
|
|
27
|
-
} else {
|
|
28
|
-
throw Error("Could not determine runtime platform");
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
package/src/util/getUsdRate.ts
DELETED
package/src/util/getXPubKey.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
deriveHdPrivateNodeFromSeed,
|
|
3
|
-
deriveHdPath,
|
|
4
|
-
deriveHdPublicNode,
|
|
5
|
-
encodeHdPublicKey,
|
|
6
|
-
HdKeyNetwork,
|
|
7
|
-
hexToBin,
|
|
8
|
-
} from "@bitauth/libauth";
|
|
9
|
-
|
|
10
|
-
export function getXPubKey(
|
|
11
|
-
seed: Uint8Array | string,
|
|
12
|
-
derivationPath: string,
|
|
13
|
-
network: string
|
|
14
|
-
) {
|
|
15
|
-
if (typeof seed === "string") {
|
|
16
|
-
seed = hexToBin(seed);
|
|
17
|
-
}
|
|
18
|
-
let hdNode = deriveHdPrivateNodeFromSeed(seed, {
|
|
19
|
-
assumeValidity: true, // TODO: we should switch to libauth's BIP39 implementation and set this to false
|
|
20
|
-
throwErrors: true,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
let node = deriveHdPath(hdNode, derivationPath);
|
|
24
|
-
if (typeof node === "string") {
|
|
25
|
-
throw node;
|
|
26
|
-
}
|
|
27
|
-
let parentPublicNode = deriveHdPublicNode(node);
|
|
28
|
-
|
|
29
|
-
let xPubKey = encodeHdPublicKey(
|
|
30
|
-
{
|
|
31
|
-
network: network as HdKeyNetwork,
|
|
32
|
-
node: parentPublicNode,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
throwErrors: true,
|
|
36
|
-
}
|
|
37
|
-
).hdPublicKey;
|
|
38
|
-
return xPubKey;
|
|
39
|
-
}
|
package/src/util/hash160.test.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { hash160 } from "./hash160";
|
|
2
|
-
import { hexToBin } from "@bitauth/libauth";
|
|
3
|
-
|
|
4
|
-
test("Should calculate the correct hash from a publicKey", async () => {
|
|
5
|
-
let pk = "02d531ce83a065cdc342b1e709106741bb070ea7aaec29d012f2dba956b9027675";
|
|
6
|
-
let pkh = hash160(hexToBin(pk));
|
|
7
|
-
expect(pkh).toStrictEqual(
|
|
8
|
-
hexToBin("e8f538181a07625fc5b2194ea9fa3815f42900a2")
|
|
9
|
-
);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test("Should calculate the correct hash from a publicKey", async () => {
|
|
13
|
-
let pk = "02b4632d08485ff1df2db55b9dafd23347d1c47a457072a1e87be26896549a8737";
|
|
14
|
-
let pkh = hash160(hexToBin(pk));
|
|
15
|
-
expect(pkh).toStrictEqual(
|
|
16
|
-
hexToBin("93ce48570b55c42c2af816aeaba06cfee1224fae")
|
|
17
|
-
);
|
|
18
|
-
});
|
package/src/util/hash160.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ripemd160, sha256 } from "@bitauth/libauth";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* hash160 - Calculate the sha256, ripemd160 hash of a value
|
|
5
|
-
*
|
|
6
|
-
* @param {message} Uint8Array value to hash as a binary array
|
|
7
|
-
*
|
|
8
|
-
* @returns a promise to the hash160 value of the input
|
|
9
|
-
*/
|
|
10
|
-
export function hash160(message: Uint8Array) {
|
|
11
|
-
return ripemd160.hash(sha256.hash(message));
|
|
12
|
-
}
|
package/src/util/hd.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export const arrayRange = (start: number, stop: number) =>
|
|
2
|
-
Array.from({ length: stop - start }, (_, index) => start + index);
|
|
3
|
-
|
|
4
|
-
export const getNextUnusedIndex = (
|
|
5
|
-
index: number,
|
|
6
|
-
statuses: Array<string | null>
|
|
7
|
-
): number => {
|
|
8
|
-
if (index === -1) {
|
|
9
|
-
index = statuses.findIndex((status) => status === null);
|
|
10
|
-
if (index === -1) {
|
|
11
|
-
index = statuses.length;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return index;
|
|
16
|
-
};
|
package/src/util/header.test.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { HeaderI, HexHeaderI } from "../interface";
|
|
2
|
-
import { disconnectProviders, initProviders } from "../network";
|
|
3
|
-
import { Wallet } from "../wallet/Wif";
|
|
4
|
-
|
|
5
|
-
beforeAll(async () => {
|
|
6
|
-
await initProviders();
|
|
7
|
-
});
|
|
8
|
-
afterAll(async () => {
|
|
9
|
-
await disconnectProviders();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
describe("header tests", () => {
|
|
13
|
-
it("decodeHeader", async () => {
|
|
14
|
-
const wallet = await Wallet.newRandom();
|
|
15
|
-
const hexHeader = (await wallet.provider!.getHeader(854724)) as HexHeaderI;
|
|
16
|
-
expect(hexHeader.height).toBe(854724);
|
|
17
|
-
expect(hexHeader.hex).toBe(
|
|
18
|
-
"0080c4339674a81d4e35a5b590b15a6b69f93b7b22bd14845b3517000000000000000000128a8b776c82fda87f60c6fdb0de26f021cdf39ffd835dc309eb1fc6bbfaac343e2f96662d5202184db2428f"
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
const header = (await wallet.provider!.getHeader(854724, true)) as HeaderI;
|
|
22
|
-
expect(header.version).toBe(868515840);
|
|
23
|
-
expect(header.previousBlockHash).toBe(
|
|
24
|
-
"00000000000000000017355b8414bd227b3bf9696b5ab190b5a5354e1da87496"
|
|
25
|
-
);
|
|
26
|
-
expect(header.merkleRoot).toBe(
|
|
27
|
-
"34acfabbc61feb09c35d83fd9ff3cd21f026deb0fdc6607fa8fd826c778b8a12"
|
|
28
|
-
);
|
|
29
|
-
expect(header.timestamp).toBe(1721118526);
|
|
30
|
-
expect(header.bits).toBe(402805293);
|
|
31
|
-
expect(header.nonce).toBe(2403512909);
|
|
32
|
-
expect(header.height).toBe(854724);
|
|
33
|
-
});
|
|
34
|
-
});
|
package/src/util/header.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertSuccess,
|
|
3
|
-
binToHex,
|
|
4
|
-
hexToBin,
|
|
5
|
-
readUint32LE,
|
|
6
|
-
} from "@bitauth/libauth";
|
|
7
|
-
import { HeaderI, HexHeaderI } from "../interface.js";
|
|
8
|
-
|
|
9
|
-
export const decodeHeader = (hexHeader: HexHeaderI): HeaderI => {
|
|
10
|
-
const result = {} as HeaderI;
|
|
11
|
-
|
|
12
|
-
const header = hexToBin(hexHeader.hex);
|
|
13
|
-
result.version = assertSuccess(
|
|
14
|
-
readUint32LE({ bin: header, index: 0 })
|
|
15
|
-
).result;
|
|
16
|
-
result.previousBlockHash = binToHex(header.slice(4, 36).reverse());
|
|
17
|
-
result.merkleRoot = binToHex(header.slice(36, 68).reverse());
|
|
18
|
-
result.timestamp = assertSuccess(
|
|
19
|
-
readUint32LE({ bin: header, index: 68 })
|
|
20
|
-
).result;
|
|
21
|
-
result.bits = assertSuccess(readUint32LE({ bin: header, index: 72 })).result;
|
|
22
|
-
result.nonce = assertSuccess(readUint32LE({ bin: header, index: 76 })).result;
|
|
23
|
-
result.height = hexHeader.height;
|
|
24
|
-
|
|
25
|
-
return result;
|
|
26
|
-
};
|
package/src/util/index.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export { amountInSatoshi } from "./amountInSatoshi.js";
|
|
2
|
-
export { asSendRequestObject } from "./asSendRequestObject.js";
|
|
3
|
-
export { atob, btoa } from "./base64.js";
|
|
4
|
-
export {
|
|
5
|
-
binToHex,
|
|
6
|
-
hexToBin,
|
|
7
|
-
utf8ToBin,
|
|
8
|
-
binToBase64,
|
|
9
|
-
sha256,
|
|
10
|
-
} from "@bitauth/libauth";
|
|
11
|
-
export * from "./convert.js";
|
|
12
|
-
export { delay } from "./delay.js";
|
|
13
|
-
export { derivedNetwork } from "./deriveNetwork.js";
|
|
14
|
-
export { derivePublicKeyHash } from "./derivePublicKeyHash.js";
|
|
15
|
-
export * from "./deriveCashaddr.js";
|
|
16
|
-
export {
|
|
17
|
-
getAddrsByXpubKey,
|
|
18
|
-
getAddrsByXpubKeyObject,
|
|
19
|
-
getXpubKeyInfo,
|
|
20
|
-
getXpubKeyInfoObject,
|
|
21
|
-
} from "../util/getAddrsByXpubKey.js";
|
|
22
|
-
export { getRuntimePlatform, RuntimePlatform } from "./getRuntimePlatform.js";
|
|
23
|
-
export { getUsdRate } from "./getUsdRate.js";
|
|
24
|
-
export { hash160 } from "./hash160.js";
|
|
25
|
-
export { ExchangeRate, ExchageRatePromise } from "../rate/ExchangeRate.js";
|
|
26
|
-
export { sanitizeAddress } from "./sanitizeAddress.js";
|
|
27
|
-
export { sanitizeUnit } from "./sanitizeUnit.js";
|
|
28
|
-
export { getWeakRandomInt } from "./randomInt.js";
|
|
29
|
-
export { getXPubKey } from "../util/getXPubKey.js";
|
|
30
|
-
export { sumUtxoValue } from "./sumUtxoValue.js";
|
|
31
|
-
export * from "./sumUtxoValue.js";
|
|
32
|
-
export { decodeHeader } from "./header.js";
|
|
33
|
-
export * from "./checkUtxos.js";
|
package/src/util/randomBytes.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { getRuntimePlatform } from "./getRuntimePlatform.js";
|
|
2
|
-
import crypto from "crypto";
|
|
3
|
-
|
|
4
|
-
export function generateRandomBytes(len = 32) {
|
|
5
|
-
// nodejs
|
|
6
|
-
if (getRuntimePlatform() === "node") {
|
|
7
|
-
return crypto.randomBytes(len);
|
|
8
|
-
}
|
|
9
|
-
// window, webworkers, service workers
|
|
10
|
-
else {
|
|
11
|
-
return window.crypto.getRandomValues(new Uint8Array(len));
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getWeakRandomInt } from "./randomInt";
|
|
2
|
-
|
|
3
|
-
test("get a random int", async () => {
|
|
4
|
-
let zero = await getWeakRandomInt(0);
|
|
5
|
-
expect(zero).toBe(0);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
test("average some random ints", async () => {
|
|
9
|
-
let average = 0;
|
|
10
|
-
for (let i = 0; i < 100; i++) {
|
|
11
|
-
average += getWeakRandomInt(1000) / 100;
|
|
12
|
-
}
|
|
13
|
-
expect(average).toBeGreaterThan(400);
|
|
14
|
-
expect(average).toBeLessThan(600);
|
|
15
|
-
});
|
package/src/util/randomInt.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { derivePrefix } from "./derivePublicKeyHash.js";
|
|
2
|
-
|
|
3
|
-
// Assure address is prefixed.
|
|
4
|
-
export function sanitizeAddress(address: string) {
|
|
5
|
-
if (address.includes(":")) {
|
|
6
|
-
return address;
|
|
7
|
-
} else {
|
|
8
|
-
return `${derivePrefix(address)}:${address}`;
|
|
9
|
-
}
|
|
10
|
-
}
|
package/src/util/sanitizeUnit.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { UnitEnum } from "../enum.js";
|
|
2
|
-
|
|
3
|
-
export function sanitizeUnit(rawUnit: any): UnitEnum {
|
|
4
|
-
if (rawUnit) {
|
|
5
|
-
return rawUnit.toLocaleLowerCase() as UnitEnum;
|
|
6
|
-
} else {
|
|
7
|
-
throw Error(
|
|
8
|
-
"Attempted to sanitize a unit of value, but the unit was undefined."
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { bchParam } from "../chain.js";
|
|
2
|
-
import { UnitEnum } from "../enum.js";
|
|
3
|
-
import { ExchangeRate } from "../rate/ExchangeRate.js";
|
|
4
|
-
import { sanitizeUnit } from "../util/sanitizeUnit.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* converts given value and unit from satoshi
|
|
8
|
-
*
|
|
9
|
-
* @param {value} number some value in satoshi
|
|
10
|
-
* @param {rawUnit} any the target unit
|
|
11
|
-
*
|
|
12
|
-
* @returns a promise to the value in the unit of account given by rawUnit
|
|
13
|
-
*/
|
|
14
|
-
export async function satoshiToAmount(
|
|
15
|
-
value: bigint,
|
|
16
|
-
rawUnit: any
|
|
17
|
-
): Promise<number> {
|
|
18
|
-
const unit = sanitizeUnit(rawUnit);
|
|
19
|
-
switch (unit) {
|
|
20
|
-
case UnitEnum.BCH:
|
|
21
|
-
return Number(value) / Number(bchParam.subUnits);
|
|
22
|
-
case UnitEnum.SAT:
|
|
23
|
-
return Number(value);
|
|
24
|
-
default:
|
|
25
|
-
const Currency_over_BCH = await ExchangeRate.get(rawUnit);
|
|
26
|
-
// truncate currency amounts to fixed precision (2),
|
|
27
|
-
// then return the fixed value string as a float.
|
|
28
|
-
const currencyValue = Number(
|
|
29
|
-
Number(value) * (Currency_over_BCH / Number(bchParam.subUnits))
|
|
30
|
-
).toFixed(2);
|
|
31
|
-
return Number.parseFloat(currencyValue);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
OpReturnData,
|
|
3
|
-
SendRequest,
|
|
4
|
-
TokenSendRequest,
|
|
5
|
-
} from "../wallet/model.js";
|
|
6
|
-
|
|
7
|
-
// This function sums a list of send request objects
|
|
8
|
-
export async function sumSendRequestAmounts(
|
|
9
|
-
requests: Array<SendRequest | TokenSendRequest | OpReturnData>
|
|
10
|
-
) {
|
|
11
|
-
if (requests) {
|
|
12
|
-
const balanceArray: (BigInt | Error)[] = await Promise.all(
|
|
13
|
-
requests.map(async (r: SendRequest | TokenSendRequest | OpReturnData) => {
|
|
14
|
-
if (r instanceof SendRequest) {
|
|
15
|
-
return r.value;
|
|
16
|
-
} else if (r instanceof TokenSendRequest) {
|
|
17
|
-
return r.value || 1000n;
|
|
18
|
-
} else return 0n;
|
|
19
|
-
})
|
|
20
|
-
);
|
|
21
|
-
const balance = balanceArray.reduce(sumBalance, BigInt(0));
|
|
22
|
-
return balance;
|
|
23
|
-
} else {
|
|
24
|
-
return BigInt(0);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function sumBalance(a: BigInt, b: BigInt | Error) {
|
|
29
|
-
// a is zero or a number
|
|
30
|
-
if (b instanceof Error) {
|
|
31
|
-
throw b;
|
|
32
|
-
}
|
|
33
|
-
return BigInt(a as bigint) + BigInt(b as bigint);
|
|
34
|
-
}
|
package/src/util/sumUtxoValue.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Utxo } from "../interface.js";
|
|
2
|
-
|
|
3
|
-
export function sumUtxoValue(utxos: Utxo[]) {
|
|
4
|
-
if (utxos.length > 0) {
|
|
5
|
-
const balanceArray: bigint[] = utxos.map((o: Utxo) => {
|
|
6
|
-
return o.satoshis;
|
|
7
|
-
});
|
|
8
|
-
const balance = balanceArray.reduce((a: bigint, b: bigint) => a + b, 0n);
|
|
9
|
-
return balance;
|
|
10
|
-
} else {
|
|
11
|
-
return 0n;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function sumTokenAmounts(utxos: Utxo[], tokenId: string): bigint {
|
|
16
|
-
if (utxos.length > 0) {
|
|
17
|
-
const tokenArray: bigint[] = utxos
|
|
18
|
-
.filter((utxo) => utxo.token?.category === tokenId)
|
|
19
|
-
.map((o: Utxo) => {
|
|
20
|
-
return o.token?.amount || 0n;
|
|
21
|
-
});
|
|
22
|
-
const balance = tokenArray.reduce((a: bigint, b: bigint) => a + b, 0n);
|
|
23
|
-
return balance;
|
|
24
|
-
} else {
|
|
25
|
-
return 0n;
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/util/transaction.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { hexToBin, sha256, binToHex } from "@bitauth/libauth";
|
|
2
|
-
|
|
3
|
-
export async function getTransactionHash(
|
|
4
|
-
rawTransactionHex: string
|
|
5
|
-
): Promise<string> {
|
|
6
|
-
const transactionBin = hexToBin(rawTransactionHex);
|
|
7
|
-
|
|
8
|
-
// transaction hash is a double sha256 of a raw transaction data, reversed byte order
|
|
9
|
-
return binToHex(sha256.hash(sha256.hash(transactionBin)).reverse());
|
|
10
|
-
}
|