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,24 +0,0 @@
|
|
|
1
|
-
import { NetworkType } from "../enum.js";
|
|
2
|
-
|
|
3
|
-
export function checkWifNetwork(
|
|
4
|
-
walletImportFormatString: string,
|
|
5
|
-
networkType: NetworkType
|
|
6
|
-
) {
|
|
7
|
-
if (
|
|
8
|
-
!(
|
|
9
|
-
walletImportFormatString[0] === "L" || walletImportFormatString[0] === "K"
|
|
10
|
-
) &&
|
|
11
|
-
networkType === NetworkType.Mainnet
|
|
12
|
-
) {
|
|
13
|
-
throw Error(
|
|
14
|
-
`Mainnet type wif ${walletImportFormatString} passed, should start with L or K`
|
|
15
|
-
);
|
|
16
|
-
} else if (
|
|
17
|
-
walletImportFormatString[0] !== "c" &&
|
|
18
|
-
networkType === NetworkType.Testnet
|
|
19
|
-
) {
|
|
20
|
-
throw Error(
|
|
21
|
-
`Testnet type wif ${walletImportFormatString} passed, should start with c`
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/util/convert.test.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { convert } from "./convert";
|
|
2
|
-
import { ExchangeRate } from "../rate/ExchangeRate";
|
|
3
|
-
|
|
4
|
-
test("Should get price sat in usd", async () => {
|
|
5
|
-
let rate = await ExchangeRate.get("usd");
|
|
6
|
-
let usd = await convert(100000000, "sat", "usd");
|
|
7
|
-
expect(Math.round(rate)).toBeLessThan(usd + 1);
|
|
8
|
-
expect(Math.round(rate)).toBeGreaterThan(usd - 1);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test("Should get of bch in usd", async () => {
|
|
12
|
-
let rate = await ExchangeRate.get("usd");
|
|
13
|
-
let usd = await convert(1, "bch", "usd");
|
|
14
|
-
expect(Math.round(rate)).toBeLessThan(usd + 1);
|
|
15
|
-
expect(Math.round(rate)).toBeGreaterThan(usd - 1);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("Should get usd value in fixed format", async () => {
|
|
19
|
-
let usd = await convert(1, "bch", "usd");
|
|
20
|
-
expect(usd.toFixed(2)).toMatch(/^\d+\.\d+?$/);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test("Should get price in usd in bch", async () => {
|
|
24
|
-
let rate = await ExchangeRate.get("usd");
|
|
25
|
-
let unity = await convert(rate, "usd", "bch");
|
|
26
|
-
expect(unity).toBeLessThan(1.01);
|
|
27
|
-
expect(unity).toBeGreaterThan(0.99);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("Should convert in full loop", async () => {
|
|
31
|
-
let usd = await convert(1, "bch", "usd");
|
|
32
|
-
let sat = await convert(usd, "USD", "sat");
|
|
33
|
-
let bch = await convert(sat, "sat", "BCH");
|
|
34
|
-
expect(bch).toBeLessThan(1.01);
|
|
35
|
-
expect(bch).toBeGreaterThan(0.99);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("Should convert all the BCH from sat to bch", async () => {
|
|
39
|
-
let bch = await convert(21000000 * 100000000, "sat", "BCH");
|
|
40
|
-
expect(bch).toBe(21000000);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test("Should convert BCH to EUR", async () => {
|
|
44
|
-
let eur = await convert(1, "BCH", "EUR");
|
|
45
|
-
expect(eur).toBeGreaterThan(0);
|
|
46
|
-
});
|
package/src/util/convert.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { bchParam } from "../chain.js";
|
|
2
|
-
import { amountInSatoshi } from "./amountInSatoshi.js";
|
|
3
|
-
import { satoshiToAmount } from "./satoshiToAmount.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* convert transforms unit of measurement for some monetary value
|
|
7
|
-
*
|
|
8
|
-
* @param {value} number amount to convert
|
|
9
|
-
* @param {from} any unit of measurement to convert from
|
|
10
|
-
* @param {to} any unit of measurement to convert to
|
|
11
|
-
*
|
|
12
|
-
* @returns a promise to the value in "to" units
|
|
13
|
-
*/
|
|
14
|
-
export async function convert(
|
|
15
|
-
value: number,
|
|
16
|
-
from: any,
|
|
17
|
-
to: any
|
|
18
|
-
): Promise<number> {
|
|
19
|
-
let satoshi = await amountInSatoshi(value, from);
|
|
20
|
-
return satoshiToAmount(satoshi, to);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function convertObject({
|
|
24
|
-
value,
|
|
25
|
-
from,
|
|
26
|
-
to,
|
|
27
|
-
}: {
|
|
28
|
-
value: number;
|
|
29
|
-
from: any;
|
|
30
|
-
to: any;
|
|
31
|
-
}) {
|
|
32
|
-
return await convert(value, from, to);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// sats -> bch
|
|
36
|
-
export function toBch(sats: bigint): number {
|
|
37
|
-
return Number(sats) / Number(bchParam.subUnits);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// bch -> sats
|
|
41
|
-
export function toSat(bch: string | number): bigint {
|
|
42
|
-
return BigInt(Math.round(Number(bch) * Number(bchParam.subUnits)));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function toCurrency(
|
|
46
|
-
sats: bigint,
|
|
47
|
-
currency: string
|
|
48
|
-
): Promise<number> {
|
|
49
|
-
return convert(Number(sats), "sat", currency);
|
|
50
|
-
}
|
package/src/util/delay.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { RegTestWallet, Wallet } from "../wallet/Wif";
|
|
2
|
-
import {
|
|
3
|
-
convertAddress,
|
|
4
|
-
deriveCashaddr,
|
|
5
|
-
deriveTokenaddr,
|
|
6
|
-
isTokenaddr,
|
|
7
|
-
isValidAddress,
|
|
8
|
-
toCashaddr,
|
|
9
|
-
toTokenaddr,
|
|
10
|
-
} from "./deriveCashaddr";
|
|
11
|
-
|
|
12
|
-
const p2pkhAddress = "bitcoincash:qpttdv3qg2usm4nm7talhxhl05mlhms3ystlwcm8h4";
|
|
13
|
-
const p2pkhTokenAddress =
|
|
14
|
-
"bitcoincash:zpttdv3qg2usm4nm7talhxhl05mlhms3ysv4ax4pgx";
|
|
15
|
-
|
|
16
|
-
const testnetP2pkhAddress =
|
|
17
|
-
"bchtest:qpttdv3qg2usm4nm7talhxhl05mlhms3ys0d2lessf";
|
|
18
|
-
const testnetP2pkhTokenAddress =
|
|
19
|
-
"bchtest:zpttdv3qg2usm4nm7talhxhl05mlhms3ysg8ephk06";
|
|
20
|
-
|
|
21
|
-
const regtestP2pkhAddress = "bchreg:qpttdv3qg2usm4nm7talhxhl05mlhms3ys43u76rn0";
|
|
22
|
-
const regtestP2pkhTokenAddress =
|
|
23
|
-
"bchreg:zpttdv3qg2usm4nm7talhxhl05mlhms3ysjm0q59vu";
|
|
24
|
-
|
|
25
|
-
const p2shAddress = "bitcoincash:ppvamrzvn62c85tv0y4ncdxyy77csxk7qgcjrpwp98";
|
|
26
|
-
const p2shTokenAddress =
|
|
27
|
-
"bitcoincash:rpvamrzvn62c85tv0y4ncdxyy77csxk7qglcslq865";
|
|
28
|
-
|
|
29
|
-
const testnetP2shAddress = "bchtest:ppvamrzvn62c85tv0y4ncdxyy77csxk7qguq8xvkzm";
|
|
30
|
-
const testnetP2shTokenAddress =
|
|
31
|
-
"bchtest:rpvamrzvn62c85tv0y4ncdxyy77csxk7qgm25czsag";
|
|
32
|
-
|
|
33
|
-
const regtestP2shAddress = "bchreg:ppvamrzvn62c85tv0y4ncdxyy77csxk7qgxu3809pa";
|
|
34
|
-
const regtestP2shTokenAddress =
|
|
35
|
-
"bchreg:rpvamrzvn62c85tv0y4ncdxyy77csxk7qgpkzepr7w";
|
|
36
|
-
|
|
37
|
-
const p2sh32Address =
|
|
38
|
-
"bitcoincash:pww87w869tuuzw4avtyxtlwhq32l25xkyy9n3xhzfelhj0d3vm8xx5auz6k7z";
|
|
39
|
-
const p2sh32TokenAddress =
|
|
40
|
-
"bitcoincash:rww87w869tuuzw4avtyxtlwhq32l25xkyy9n3xhzfelhj0d3vm8xxxwqrrh8f";
|
|
41
|
-
|
|
42
|
-
const testnetP2sh32Address =
|
|
43
|
-
"bchtest:pww87w869tuuzw4avtyxtlwhq32l25xkyy9n3xhzfelhj0d3vm8xxh6duz9ts";
|
|
44
|
-
const testnetP2sh32TokenAddress =
|
|
45
|
-
"bchtest:rww87w869tuuzw4avtyxtlwhq32l25xkyy9n3xhzfelhj0d3vm8xx9f3amyjm";
|
|
46
|
-
|
|
47
|
-
const regtestP2sh32Address =
|
|
48
|
-
"bchreg:pww87w869tuuzw4avtyxtlwhq32l25xkyy9n3xhzfelhj0d3vm8xxzslk9juc";
|
|
49
|
-
const regtestP2sh32TokenAddress =
|
|
50
|
-
"bchreg:rww87w869tuuzw4avtyxtlwhq32l25xkyy9n3xhzfelhj0d3vm8xxsrrhun9n";
|
|
51
|
-
|
|
52
|
-
test("Should derive cashaddr", async () => {
|
|
53
|
-
const wallet = await Wallet.newRandom();
|
|
54
|
-
expect(deriveCashaddr(wallet.privateKey!, wallet.networkPrefix)).toBe(
|
|
55
|
-
wallet.cashaddr!
|
|
56
|
-
);
|
|
57
|
-
expect(deriveTokenaddr(wallet.privateKey!, wallet.networkPrefix)).toBe(
|
|
58
|
-
wallet.tokenaddr!
|
|
59
|
-
);
|
|
60
|
-
expect(deriveTokenaddr(wallet.publicKey!, wallet.networkPrefix)).toBe(
|
|
61
|
-
wallet.tokenaddr!
|
|
62
|
-
);
|
|
63
|
-
expect(
|
|
64
|
-
deriveTokenaddr(wallet.publicKeyCompressed!, wallet.networkPrefix)
|
|
65
|
-
).toBe(wallet.tokenaddr!);
|
|
66
|
-
expect(deriveTokenaddr(wallet.publicKeyHash!, wallet.networkPrefix)).toBe(
|
|
67
|
-
wallet.tokenaddr!
|
|
68
|
-
);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("Test address conversion", async () => {
|
|
72
|
-
const wallet = await RegTestWallet.watchOnly(process.env.ADDRESS!);
|
|
73
|
-
|
|
74
|
-
// p2pkh
|
|
75
|
-
expect(toTokenaddr(wallet.cashaddr)).toBe(wallet.tokenaddr);
|
|
76
|
-
expect(toCashaddr(wallet.cashaddr)).toBe(wallet.cashaddr);
|
|
77
|
-
|
|
78
|
-
// p2pkh with tokens
|
|
79
|
-
expect(toCashaddr(wallet.tokenaddr)).toBe(wallet.cashaddr);
|
|
80
|
-
expect(toTokenaddr(wallet.tokenaddr)).toBe(wallet.tokenaddr);
|
|
81
|
-
|
|
82
|
-
// p2sh
|
|
83
|
-
expect(toCashaddr(p2shAddress)).toBe(p2shAddress);
|
|
84
|
-
expect(toTokenaddr(p2shAddress)).toBe(p2shTokenAddress);
|
|
85
|
-
|
|
86
|
-
// p2sh with tokens
|
|
87
|
-
expect(toCashaddr(p2shTokenAddress)).toBe(p2shAddress);
|
|
88
|
-
expect(toTokenaddr(p2shTokenAddress)).toBe(p2shTokenAddress);
|
|
89
|
-
|
|
90
|
-
// p2sh32
|
|
91
|
-
expect(toCashaddr(p2sh32Address)).toBe(p2sh32Address);
|
|
92
|
-
expect(toTokenaddr(p2sh32Address)).toBe(p2sh32TokenAddress);
|
|
93
|
-
|
|
94
|
-
// p2sh32 with tokens
|
|
95
|
-
expect(toCashaddr(p2sh32TokenAddress)).toBe(p2sh32Address);
|
|
96
|
-
expect(toTokenaddr(p2sh32TokenAddress)).toBe(p2sh32TokenAddress);
|
|
97
|
-
|
|
98
|
-
expect(toCashaddr(wallet.tokenaddr)).toBe(
|
|
99
|
-
"bchreg:qpttdv3qg2usm4nm7talhxhl05mlhms3ys43u76rn0"
|
|
100
|
-
);
|
|
101
|
-
expect(toTokenaddr(wallet.cashaddr)).toBe(
|
|
102
|
-
"bchreg:zpttdv3qg2usm4nm7talhxhl05mlhms3ysjm0q59vu"
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
expect(isTokenaddr(wallet.cashaddr)).toBe(false);
|
|
106
|
-
expect(isTokenaddr(wallet.tokenaddr)).toBe(true);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("Test address network conversion", async () => {
|
|
110
|
-
expect(convertAddress(p2pkhAddress, "mainnet")).toBe(p2pkhAddress);
|
|
111
|
-
expect(convertAddress(p2pkhAddress, "testnet")).toBe(testnetP2pkhAddress);
|
|
112
|
-
expect(convertAddress(p2pkhAddress, "regtest")).toBe(regtestP2pkhAddress);
|
|
113
|
-
|
|
114
|
-
expect(convertAddress(p2pkhTokenAddress, "mainnet")).toBe(p2pkhTokenAddress);
|
|
115
|
-
expect(convertAddress(p2pkhTokenAddress, "testnet")).toBe(
|
|
116
|
-
testnetP2pkhTokenAddress
|
|
117
|
-
);
|
|
118
|
-
expect(convertAddress(p2pkhTokenAddress, "regtest")).toBe(
|
|
119
|
-
regtestP2pkhTokenAddress
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
expect(convertAddress(p2shAddress, "mainnet")).toBe(p2shAddress);
|
|
123
|
-
expect(convertAddress(p2shAddress, "testnet")).toBe(testnetP2shAddress);
|
|
124
|
-
expect(convertAddress(p2shAddress, "regtest")).toBe(regtestP2shAddress);
|
|
125
|
-
|
|
126
|
-
expect(convertAddress(p2shTokenAddress, "mainnet")).toBe(p2shTokenAddress);
|
|
127
|
-
expect(convertAddress(p2shTokenAddress, "testnet")).toBe(
|
|
128
|
-
testnetP2shTokenAddress
|
|
129
|
-
);
|
|
130
|
-
expect(convertAddress(p2shTokenAddress, "regtest")).toBe(
|
|
131
|
-
regtestP2shTokenAddress
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
expect(convertAddress(p2sh32Address, "mainnet")).toBe(p2sh32Address);
|
|
135
|
-
expect(convertAddress(p2sh32Address, "testnet")).toBe(testnetP2sh32Address);
|
|
136
|
-
expect(convertAddress(p2sh32Address, "regtest")).toBe(regtestP2sh32Address);
|
|
137
|
-
|
|
138
|
-
expect(convertAddress(p2sh32TokenAddress, "mainnet")).toBe(
|
|
139
|
-
p2sh32TokenAddress
|
|
140
|
-
);
|
|
141
|
-
expect(convertAddress(p2sh32TokenAddress, "testnet")).toBe(
|
|
142
|
-
testnetP2sh32TokenAddress
|
|
143
|
-
);
|
|
144
|
-
expect(convertAddress(p2sh32TokenAddress, "regtest")).toBe(
|
|
145
|
-
regtestP2sh32TokenAddress
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
// change token awareness
|
|
149
|
-
expect(convertAddress(p2pkhAddress, "mainnet", true)).toBe(p2pkhTokenAddress);
|
|
150
|
-
expect(convertAddress(p2pkhAddress, "mainnet", false)).toBe(p2pkhAddress);
|
|
151
|
-
expect(convertAddress(p2pkhTokenAddress, "mainnet", true)).toBe(
|
|
152
|
-
p2pkhTokenAddress
|
|
153
|
-
);
|
|
154
|
-
expect(convertAddress(p2pkhTokenAddress, "mainnet", false)).toBe(
|
|
155
|
-
p2pkhAddress
|
|
156
|
-
);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test("Test isValidAddress", async () => {
|
|
160
|
-
const wallet = await RegTestWallet.watchOnly(process.env.ADDRESS!);
|
|
161
|
-
expect(isValidAddress(wallet.cashaddr)).toBe(true);
|
|
162
|
-
expect(isValidAddress(wallet.tokenaddr)).toBe(true);
|
|
163
|
-
expect(isValidAddress("asdf")).toBe(false);
|
|
164
|
-
});
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CashAddressNetworkPrefix,
|
|
3
|
-
CashAddressType,
|
|
4
|
-
decodeCashAddress,
|
|
5
|
-
DecodedCashAddress,
|
|
6
|
-
encodeCashAddress,
|
|
7
|
-
secp256k1,
|
|
8
|
-
} from "@bitauth/libauth";
|
|
9
|
-
import { prefixFromNetworkMap } from "../enum.js";
|
|
10
|
-
import { Network } from "../interface.js";
|
|
11
|
-
import { hash160 } from "./hash160.js";
|
|
12
|
-
|
|
13
|
-
export function isValidAddress(cashaddr: string): boolean {
|
|
14
|
-
const result = decodeCashAddress(cashaddr);
|
|
15
|
-
if (typeof result === "string") {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function deriveCashaddr(
|
|
23
|
-
privateKey: Uint8Array,
|
|
24
|
-
networkPrefix: CashAddressNetworkPrefix
|
|
25
|
-
): string {
|
|
26
|
-
let publicKey = secp256k1.derivePublicKeyCompressed(privateKey);
|
|
27
|
-
if (typeof publicKey === "string") {
|
|
28
|
-
throw new Error(publicKey);
|
|
29
|
-
}
|
|
30
|
-
let pkh = hash160(publicKey);
|
|
31
|
-
return encodeCashAddress({
|
|
32
|
-
prefix: networkPrefix,
|
|
33
|
-
type: CashAddressType.p2pkh,
|
|
34
|
-
payload: pkh,
|
|
35
|
-
}).address;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function deriveTokenaddr(
|
|
39
|
-
key: Uint8Array,
|
|
40
|
-
networkPrefix: CashAddressNetworkPrefix
|
|
41
|
-
): string {
|
|
42
|
-
let publicKeyHash: Uint8Array;
|
|
43
|
-
// private key
|
|
44
|
-
if (key.length === 32) {
|
|
45
|
-
let publicKeyCompressed = secp256k1.derivePublicKeyCompressed(key);
|
|
46
|
-
if (typeof publicKeyCompressed === "string") {
|
|
47
|
-
throw new Error(publicKeyCompressed);
|
|
48
|
-
}
|
|
49
|
-
publicKeyHash = hash160(publicKeyCompressed);
|
|
50
|
-
} else if (key.length === 65) {
|
|
51
|
-
// uncompressed public key
|
|
52
|
-
let publicKeyCompressed = secp256k1.compressPublicKey(key);
|
|
53
|
-
if (typeof publicKeyCompressed === "string") {
|
|
54
|
-
throw new Error(publicKeyCompressed);
|
|
55
|
-
}
|
|
56
|
-
publicKeyHash = hash160(publicKeyCompressed);
|
|
57
|
-
} else if (key.length === 33) {
|
|
58
|
-
// compressed public key
|
|
59
|
-
publicKeyHash = hash160(key);
|
|
60
|
-
} else if (key.length === 20) {
|
|
61
|
-
// public key hash
|
|
62
|
-
publicKeyHash = key;
|
|
63
|
-
} else {
|
|
64
|
-
throw new Error("Unsupported type of key");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return encodeCashAddress({
|
|
68
|
-
prefix: networkPrefix,
|
|
69
|
-
type: CashAddressType.p2pkhWithTokens,
|
|
70
|
-
payload: publicKeyHash,
|
|
71
|
-
}).address;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function decodeAddress(address: string): DecodedCashAddress {
|
|
75
|
-
const result = decodeCashAddress(address);
|
|
76
|
-
if (typeof result === "string") {
|
|
77
|
-
throw new Error(result);
|
|
78
|
-
}
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function toCashaddr(address: string): string {
|
|
83
|
-
if (address.indexOf(":q") > 0 || address.indexOf(":p") > 0) {
|
|
84
|
-
return address;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const result = decodeAddress(address);
|
|
88
|
-
|
|
89
|
-
return encodeCashAddress({
|
|
90
|
-
prefix: result.prefix as CashAddressNetworkPrefix,
|
|
91
|
-
type: result.type.replace("WithTokens", "") as CashAddressType,
|
|
92
|
-
payload: result.payload,
|
|
93
|
-
}).address;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function toTokenaddr(address: string): string {
|
|
97
|
-
if (address.indexOf(":z") > 0 || address.indexOf(":r") > 0) {
|
|
98
|
-
return address;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const result = decodeAddress(address);
|
|
102
|
-
|
|
103
|
-
return encodeCashAddress({
|
|
104
|
-
prefix: result.prefix as CashAddressNetworkPrefix,
|
|
105
|
-
type: (result.type.replace("WithTokens", "") +
|
|
106
|
-
"WithTokens") as CashAddressType,
|
|
107
|
-
payload: result.payload,
|
|
108
|
-
}).address;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export function isTokenaddr(address: string): boolean {
|
|
112
|
-
const result = decodeAddress(address);
|
|
113
|
-
|
|
114
|
-
return result.type.endsWith("WithTokens");
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// This function converts a cash address to a cash address of the specified network.
|
|
118
|
-
// If withTokens is true, it will return a token-aware address.
|
|
119
|
-
// If withTokens is false, it will return a non-token-aware address.
|
|
120
|
-
// If withTokens is undefined, it will not change the token-awareness.
|
|
121
|
-
export function convertAddress(
|
|
122
|
-
address: string,
|
|
123
|
-
network: Network = "mainnet",
|
|
124
|
-
withTokens: boolean | undefined = undefined
|
|
125
|
-
): string {
|
|
126
|
-
const result = decodeAddress(address);
|
|
127
|
-
|
|
128
|
-
return encodeCashAddress({
|
|
129
|
-
prefix: prefixFromNetworkMap[network] as CashAddressNetworkPrefix,
|
|
130
|
-
type:
|
|
131
|
-
withTokens === undefined
|
|
132
|
-
? result.type
|
|
133
|
-
: ((result.type.replace("WithTokens", "") +
|
|
134
|
-
(withTokens ? "WithTokens" : "")) as CashAddressType),
|
|
135
|
-
payload: result.payload,
|
|
136
|
-
}).address;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function checkTokenaddr(cashaddr: string, enforce: boolean) {
|
|
140
|
-
if (enforce && !isTokenaddr(cashaddr)) {
|
|
141
|
-
throw new Error("Error trying to send to a non-tokenaware cash address");
|
|
142
|
-
}
|
|
143
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { cashAddressToLockingBytecode } from "@bitauth/libauth";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Helper function to convert an address to a locking script
|
|
5
|
-
*
|
|
6
|
-
* @param address Address to convert to locking script
|
|
7
|
-
*
|
|
8
|
-
* @returns a locking script corresponding to the passed address
|
|
9
|
-
*/
|
|
10
|
-
export function deriveLockscript(address: string): Uint8Array {
|
|
11
|
-
const result = cashAddressToLockingBytecode(address);
|
|
12
|
-
|
|
13
|
-
if (typeof result === "string") throw new Error(result);
|
|
14
|
-
|
|
15
|
-
return result.bytecode;
|
|
16
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { derivePrefix } from "./derivePublicKeyHash.js";
|
|
2
|
-
import { networkPrefixMap } from "../enum.js";
|
|
3
|
-
|
|
4
|
-
// This function if for assuring that a list of addresses are on the name network
|
|
5
|
-
// for a single address use: networkPrefixMap[derivePrefix(address)]
|
|
6
|
-
export function derivedNetwork(addresses: string[]) {
|
|
7
|
-
let networks = addresses.map(
|
|
8
|
-
(address) => networkPrefixMap[derivePrefix(address)]
|
|
9
|
-
);
|
|
10
|
-
// Get a unique set of networks requested
|
|
11
|
-
let networkSet = new Set(networks);
|
|
12
|
-
if (networkSet.size > 1) {
|
|
13
|
-
throw Error("Addresses are not on the same network");
|
|
14
|
-
} else if (networkSet.size === 0) {
|
|
15
|
-
throw Error("No address network was derived");
|
|
16
|
-
} else {
|
|
17
|
-
return networkSet.values().next().value;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hexToBin,
|
|
3
|
-
binToHex,
|
|
4
|
-
instantiateRipemd160,
|
|
5
|
-
instantiateSha256,
|
|
6
|
-
instantiateSecp256k1,
|
|
7
|
-
} from "@bitauth/libauth";
|
|
8
|
-
import { Wallet } from "../wallet/Wif";
|
|
9
|
-
import { derivePublicKeyHash } from "./derivePublicKeyHash";
|
|
10
|
-
|
|
11
|
-
test("Should return the a public key hash", async () => {
|
|
12
|
-
let pkh = derivePublicKeyHash(
|
|
13
|
-
"bchreg:pz0z7u9p96h2p6hfychxdrmwgdlzpk5luc22ykt2z6"
|
|
14
|
-
);
|
|
15
|
-
let pkh2 = derivePublicKeyHash("pz0z7u9p96h2p6hfychxdrmwgdlzpk5luc22ykt2z6");
|
|
16
|
-
expect(pkh.length).toBe(20);
|
|
17
|
-
expect(pkh2.length).toBe(20);
|
|
18
|
-
expect(pkh).toStrictEqual(pkh2);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test("Should calculate public key hash using via hash160", async () => {
|
|
22
|
-
const ripemd160 = await instantiateRipemd160();
|
|
23
|
-
const sha256 = await instantiateSha256();
|
|
24
|
-
let pkh2 = ripemd160.hash(
|
|
25
|
-
sha256.hash(
|
|
26
|
-
hexToBin(
|
|
27
|
-
"02b4632d08485ff1df2db55b9dafd23347d1c47a457072a1e87be26896549a8737"
|
|
28
|
-
)
|
|
29
|
-
)
|
|
30
|
-
);
|
|
31
|
-
expect(pkh2.length).toBe(20);
|
|
32
|
-
expect(binToHex(pkh2)).toEqual("93ce48570b55c42c2af816aeaba06cfee1224fae");
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("Should calculate public key hash consistent with hash160", async () => {
|
|
36
|
-
const ripemd160 = await instantiateRipemd160();
|
|
37
|
-
const sha256 = await instantiateSha256();
|
|
38
|
-
const secp256k1 = await instantiateSecp256k1();
|
|
39
|
-
let w = await Wallet.fromId(
|
|
40
|
-
"seed:mainnet:abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
|
41
|
-
);
|
|
42
|
-
// using cashaddr functoin
|
|
43
|
-
let pkh = derivePublicKeyHash(w.getDepositAddress());
|
|
44
|
-
// manually from compressed public key
|
|
45
|
-
let publicKeyCompressed = secp256k1.derivePublicKeyCompressed(w.privateKey!);
|
|
46
|
-
if (typeof publicKeyCompressed === "string") {
|
|
47
|
-
throw new Error(publicKeyCompressed);
|
|
48
|
-
}
|
|
49
|
-
let pkh2 = ripemd160.hash(sha256.hash(publicKeyCompressed));
|
|
50
|
-
let pkh3 = w.publicKeyHash!;
|
|
51
|
-
expect(pkh2.length).toBe(20);
|
|
52
|
-
expect(binToHex(pkh)).toEqual("d986ed01b7a22225a70edbf2ba7cfb63a15cb3aa");
|
|
53
|
-
expect(binToHex(pkh2)).toEqual("d986ed01b7a22225a70edbf2ba7cfb63a15cb3aa");
|
|
54
|
-
expect(binToHex(pkh3)).toEqual("d986ed01b7a22225a70edbf2ba7cfb63a15cb3aa");
|
|
55
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CashAddressNetworkPrefix,
|
|
3
|
-
decodeCashAddressFormat,
|
|
4
|
-
decodeCashAddressFormatWithoutPrefix,
|
|
5
|
-
} from "@bitauth/libauth";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Helper function to convert an address to a public key hash
|
|
9
|
-
*
|
|
10
|
-
* @param address Address to convert to a hash
|
|
11
|
-
*
|
|
12
|
-
* @returns a public key hash corresponding to the passed address
|
|
13
|
-
*/
|
|
14
|
-
export function derivePublicKeyHash(address: string): Uint8Array {
|
|
15
|
-
let result:
|
|
16
|
-
| string
|
|
17
|
-
| {
|
|
18
|
-
payload: Uint8Array;
|
|
19
|
-
prefix: string;
|
|
20
|
-
version: number;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// If the address has a prefix decode it as is
|
|
24
|
-
if (address.includes(":")) {
|
|
25
|
-
result = decodeCashAddressFormat(address);
|
|
26
|
-
}
|
|
27
|
-
// otherwise, derive the network from the address without prefix
|
|
28
|
-
else {
|
|
29
|
-
result = decodeCashAddressFormatWithoutPrefix(address);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (typeof result === "string") throw new Error(result);
|
|
33
|
-
|
|
34
|
-
// return the public key hash
|
|
35
|
-
return result.payload;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Helper function to convert an address prefix
|
|
40
|
-
*
|
|
41
|
-
* @param address Address with or without prefix
|
|
42
|
-
*
|
|
43
|
-
* @returns the address prefix
|
|
44
|
-
*/
|
|
45
|
-
export function derivePrefix(address: string): CashAddressNetworkPrefix {
|
|
46
|
-
let result:
|
|
47
|
-
| string
|
|
48
|
-
| {
|
|
49
|
-
payload: Uint8Array;
|
|
50
|
-
prefix: string;
|
|
51
|
-
version: number;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
if (address.includes(":")) {
|
|
55
|
-
result = decodeCashAddressFormat(address);
|
|
56
|
-
} else {
|
|
57
|
-
result = decodeCashAddressFormatWithoutPrefix(address);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (typeof result === "string") throw new Error(result);
|
|
61
|
-
|
|
62
|
-
// TODO pass the network in and check it or raise Error
|
|
63
|
-
return result.prefix as CashAddressNetworkPrefix;
|
|
64
|
-
}
|
package/src/util/floor.test.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { floor } from "./floor";
|
|
2
|
-
|
|
3
|
-
test("Should return a number floored to 2 precision", async () => {
|
|
4
|
-
let result = floor(5.019, 2).toString();
|
|
5
|
-
expect(result).toStrictEqual("5.01");
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
test("Should return a number floored to 3 precision", async () => {
|
|
9
|
-
let result = floor(5.0199, 3).toString();
|
|
10
|
-
expect(result).toStrictEqual("5.019");
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test("Should return a number floored to 2 precision", async () => {
|
|
14
|
-
let result = floor(5.0200001, 2).toString();
|
|
15
|
-
expect(result).toStrictEqual("5.02");
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test("Should return a number floored to 0 precision", async () => {
|
|
19
|
-
let result = floor(5.996, 0).toString();
|
|
20
|
-
expect(result).toStrictEqual("5");
|
|
21
|
-
});
|
package/src/util/floor.ts
DELETED