@wopr-network/platform-core 1.67.0 → 1.67.1
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/billing/crypto/btc/checkout.d.ts +4 -0
- package/dist/billing/crypto/btc/checkout.js +1 -2
- package/dist/billing/crypto/btc/index.d.ts +0 -4
- package/dist/billing/crypto/btc/index.js +0 -2
- package/dist/billing/crypto/evm/__tests__/checkout.test.js +8 -11
- package/dist/billing/crypto/evm/__tests__/eth-checkout.test.js +15 -1
- package/dist/billing/crypto/evm/checkout.d.ts +2 -0
- package/dist/billing/crypto/evm/checkout.js +1 -2
- package/dist/billing/crypto/evm/eth-checkout.d.ts +13 -2
- package/dist/billing/crypto/evm/eth-checkout.js +2 -4
- package/dist/billing/crypto/evm/eth-settler.d.ts +1 -1
- package/dist/billing/crypto/evm/index.d.ts +2 -8
- package/dist/billing/crypto/evm/index.js +0 -3
- package/dist/billing/crypto/evm/types.d.ts +16 -0
- package/dist/billing/crypto/index.d.ts +1 -6
- package/dist/billing/crypto/index.js +2 -3
- package/dist/billing/crypto/types.d.ts +0 -43
- package/dist/billing/crypto/types.js +1 -24
- package/package.json +1 -5
- package/src/billing/crypto/btc/checkout.ts +3 -2
- package/src/billing/crypto/btc/index.ts +0 -4
- package/src/billing/crypto/evm/__tests__/checkout.test.ts +10 -12
- package/src/billing/crypto/evm/__tests__/eth-checkout.test.ts +17 -1
- package/src/billing/crypto/evm/__tests__/eth-settler.test.ts +1 -1
- package/src/billing/crypto/evm/checkout.ts +3 -2
- package/src/billing/crypto/evm/eth-checkout.ts +15 -6
- package/src/billing/crypto/evm/eth-settler.ts +1 -1
- package/src/billing/crypto/evm/index.ts +8 -7
- package/src/billing/crypto/evm/types.ts +17 -0
- package/src/billing/crypto/index.ts +14 -12
- package/src/billing/crypto/types.ts +0 -63
- package/dist/billing/crypto/__tests__/address-gen.test.d.ts +0 -1
- package/dist/billing/crypto/__tests__/address-gen.test.js +0 -219
- package/dist/billing/crypto/__tests__/key-server.test.d.ts +0 -1
- package/dist/billing/crypto/__tests__/key-server.test.js +0 -742
- package/dist/billing/crypto/__tests__/watcher-service.test.d.ts +0 -1
- package/dist/billing/crypto/__tests__/watcher-service.test.js +0 -174
- package/dist/billing/crypto/address-gen.d.ts +0 -24
- package/dist/billing/crypto/address-gen.js +0 -176
- package/dist/billing/crypto/btc/__tests__/watcher.test.d.ts +0 -1
- package/dist/billing/crypto/btc/__tests__/watcher.test.js +0 -170
- package/dist/billing/crypto/btc/watcher.d.ts +0 -44
- package/dist/billing/crypto/btc/watcher.js +0 -118
- package/dist/billing/crypto/evm/__tests__/eth-watcher.test.d.ts +0 -1
- package/dist/billing/crypto/evm/__tests__/eth-watcher.test.js +0 -167
- package/dist/billing/crypto/evm/__tests__/watcher-confirmations.test.d.ts +0 -1
- package/dist/billing/crypto/evm/__tests__/watcher-confirmations.test.js +0 -159
- package/dist/billing/crypto/evm/__tests__/watcher.test.d.ts +0 -1
- package/dist/billing/crypto/evm/__tests__/watcher.test.js +0 -145
- package/dist/billing/crypto/evm/eth-watcher.d.ts +0 -66
- package/dist/billing/crypto/evm/eth-watcher.js +0 -121
- package/dist/billing/crypto/evm/watcher.d.ts +0 -51
- package/dist/billing/crypto/evm/watcher.js +0 -156
- package/dist/billing/crypto/key-server-entry.d.ts +0 -1
- package/dist/billing/crypto/key-server-entry.js +0 -122
- package/dist/billing/crypto/key-server.d.ts +0 -32
- package/dist/billing/crypto/key-server.js +0 -472
- package/dist/billing/crypto/oracle/__tests__/chainlink.test.d.ts +0 -1
- package/dist/billing/crypto/oracle/__tests__/chainlink.test.js +0 -83
- package/dist/billing/crypto/oracle/__tests__/coingecko.test.d.ts +0 -1
- package/dist/billing/crypto/oracle/__tests__/coingecko.test.js +0 -65
- package/dist/billing/crypto/oracle/__tests__/composite.test.d.ts +0 -1
- package/dist/billing/crypto/oracle/__tests__/composite.test.js +0 -48
- package/dist/billing/crypto/oracle/__tests__/convert.test.d.ts +0 -1
- package/dist/billing/crypto/oracle/__tests__/convert.test.js +0 -61
- package/dist/billing/crypto/oracle/__tests__/fixed.test.d.ts +0 -1
- package/dist/billing/crypto/oracle/__tests__/fixed.test.js +0 -20
- package/dist/billing/crypto/oracle/chainlink.d.ts +0 -26
- package/dist/billing/crypto/oracle/chainlink.js +0 -62
- package/dist/billing/crypto/oracle/coingecko.d.ts +0 -22
- package/dist/billing/crypto/oracle/coingecko.js +0 -71
- package/dist/billing/crypto/oracle/composite.d.ts +0 -14
- package/dist/billing/crypto/oracle/composite.js +0 -34
- package/dist/billing/crypto/oracle/convert.d.ts +0 -30
- package/dist/billing/crypto/oracle/convert.js +0 -51
- package/dist/billing/crypto/oracle/fixed.d.ts +0 -10
- package/dist/billing/crypto/oracle/fixed.js +0 -22
- package/dist/billing/crypto/oracle/index.d.ts +0 -9
- package/dist/billing/crypto/oracle/index.js +0 -6
- package/dist/billing/crypto/oracle/types.d.ts +0 -22
- package/dist/billing/crypto/oracle/types.js +0 -7
- package/dist/billing/crypto/plugin/__tests__/integration.test.d.ts +0 -1
- package/dist/billing/crypto/plugin/__tests__/integration.test.js +0 -58
- package/dist/billing/crypto/plugin/__tests__/interfaces.test.d.ts +0 -1
- package/dist/billing/crypto/plugin/__tests__/interfaces.test.js +0 -46
- package/dist/billing/crypto/plugin/__tests__/registry.test.d.ts +0 -1
- package/dist/billing/crypto/plugin/__tests__/registry.test.js +0 -49
- package/dist/billing/crypto/plugin/index.d.ts +0 -2
- package/dist/billing/crypto/plugin/index.js +0 -1
- package/dist/billing/crypto/plugin/interfaces.d.ts +0 -97
- package/dist/billing/crypto/plugin/interfaces.js +0 -2
- package/dist/billing/crypto/plugin/registry.d.ts +0 -8
- package/dist/billing/crypto/plugin/registry.js +0 -21
- package/dist/billing/crypto/plugin-watcher-service.d.ts +0 -32
- package/dist/billing/crypto/plugin-watcher-service.js +0 -113
- package/dist/billing/crypto/tron/__tests__/address-convert.test.d.ts +0 -1
- package/dist/billing/crypto/tron/__tests__/address-convert.test.js +0 -55
- package/dist/billing/crypto/tron/address-convert.d.ts +0 -14
- package/dist/billing/crypto/tron/address-convert.js +0 -93
- package/dist/billing/crypto/watcher-service.d.ts +0 -55
- package/dist/billing/crypto/watcher-service.js +0 -438
- package/src/billing/crypto/__tests__/address-gen.test.ts +0 -264
- package/src/billing/crypto/__tests__/key-server.test.ts +0 -823
- package/src/billing/crypto/__tests__/watcher-service.test.ts +0 -242
- package/src/billing/crypto/address-gen.ts +0 -185
- package/src/billing/crypto/btc/__tests__/watcher.test.ts +0 -201
- package/src/billing/crypto/btc/watcher.ts +0 -161
- package/src/billing/crypto/evm/__tests__/eth-watcher.test.ts +0 -190
- package/src/billing/crypto/evm/__tests__/watcher-confirmations.test.ts +0 -191
- package/src/billing/crypto/evm/__tests__/watcher.test.ts +0 -167
- package/src/billing/crypto/evm/eth-watcher.ts +0 -182
- package/src/billing/crypto/evm/watcher.ts +0 -204
- package/src/billing/crypto/key-server-entry.ts +0 -144
- package/src/billing/crypto/key-server.ts +0 -617
- package/src/billing/crypto/oracle/__tests__/chainlink.test.ts +0 -107
- package/src/billing/crypto/oracle/__tests__/coingecko.test.ts +0 -75
- package/src/billing/crypto/oracle/__tests__/composite.test.ts +0 -61
- package/src/billing/crypto/oracle/__tests__/convert.test.ts +0 -74
- package/src/billing/crypto/oracle/__tests__/fixed.test.ts +0 -23
- package/src/billing/crypto/oracle/chainlink.ts +0 -86
- package/src/billing/crypto/oracle/coingecko.ts +0 -96
- package/src/billing/crypto/oracle/composite.ts +0 -35
- package/src/billing/crypto/oracle/convert.ts +0 -53
- package/src/billing/crypto/oracle/fixed.ts +0 -25
- package/src/billing/crypto/oracle/index.ts +0 -9
- package/src/billing/crypto/oracle/types.ts +0 -28
- package/src/billing/crypto/plugin/__tests__/integration.test.ts +0 -64
- package/src/billing/crypto/plugin/__tests__/interfaces.test.ts +0 -51
- package/src/billing/crypto/plugin/__tests__/registry.test.ts +0 -58
- package/src/billing/crypto/plugin/index.ts +0 -17
- package/src/billing/crypto/plugin/interfaces.ts +0 -106
- package/src/billing/crypto/plugin/registry.ts +0 -26
- package/src/billing/crypto/plugin-watcher-service.ts +0 -148
- package/src/billing/crypto/tron/__tests__/address-convert.test.ts +0 -67
- package/src/billing/crypto/tron/address-convert.ts +0 -89
- package/src/billing/crypto/watcher-service.ts +0 -549
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { HDKey } from "@scure/bip32";
|
|
2
|
-
import * as bip39 from "@scure/bip39";
|
|
3
|
-
|
|
4
|
-
import { privateKeyToAccount } from "viem/accounts";
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
import { deriveAddress, deriveTreasury, isValidXpub } from "../address-gen.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Well-known BIP-39 test mnemonic.
|
|
10
|
-
* DO NOT use in production — this is public and widely known.
|
|
11
|
-
*/
|
|
12
|
-
const TEST_MNEMONIC = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
|
13
|
-
const TEST_SEED = bip39.mnemonicToSeedSync(TEST_MNEMONIC);
|
|
14
|
-
|
|
15
|
-
/** Derive xpub at a BIP-44 path from the test mnemonic. */
|
|
16
|
-
function xpubAt(path: string): string {
|
|
17
|
-
return HDKey.fromMasterSeed(TEST_SEED).derive(path).publicExtendedKey;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Derive private key at xpub / chainIndex / addressIndex from the test mnemonic. */
|
|
21
|
-
function privKeyAt(path: string, chainIndex: number, addressIndex: number): Uint8Array {
|
|
22
|
-
const child = HDKey.fromMasterSeed(TEST_SEED).derive(path).deriveChild(chainIndex).deriveChild(addressIndex);
|
|
23
|
-
if (!child.privateKey) throw new Error("No private key");
|
|
24
|
-
return child.privateKey;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function privKeyHex(key: Uint8Array): `0x${string}` {
|
|
28
|
-
return `0x${Array.from(key, (b) => b.toString(16).padStart(2, "0")).join("")}` as `0x${string}`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// =============================================================
|
|
32
|
-
// DB chain configs — must match production payment_methods rows
|
|
33
|
-
// =============================================================
|
|
34
|
-
|
|
35
|
-
const CHAIN_CONFIGS = [
|
|
36
|
-
{ name: "bitcoin", coinType: 0, addressType: "bech32", params: { hrp: "bc" }, addrRegex: /^bc1q[a-z0-9]+$/ },
|
|
37
|
-
{ name: "litecoin", coinType: 2, addressType: "bech32", params: { hrp: "ltc" }, addrRegex: /^ltc1q[a-z0-9]+$/ },
|
|
38
|
-
{
|
|
39
|
-
name: "dogecoin",
|
|
40
|
-
coinType: 3,
|
|
41
|
-
addressType: "p2pkh",
|
|
42
|
-
params: { version: "0x1e" },
|
|
43
|
-
addrRegex: /^D[a-km-zA-HJ-NP-Z1-9]+$/,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: "tron",
|
|
47
|
-
coinType: 195,
|
|
48
|
-
addressType: "keccak-b58check",
|
|
49
|
-
params: { version: "0x41" },
|
|
50
|
-
addrRegex: /^T[a-km-zA-HJ-NP-Z1-9]+$/,
|
|
51
|
-
},
|
|
52
|
-
{ name: "ethereum", coinType: 60, addressType: "evm", params: {}, addrRegex: /^0x[0-9a-fA-F]{40}$/ },
|
|
53
|
-
] as const;
|
|
54
|
-
|
|
55
|
-
// =============================================================
|
|
56
|
-
// Core property: xpub-derived address == mnemonic-derived address
|
|
57
|
-
// This guarantees sweep scripts can sign for pay server addresses.
|
|
58
|
-
// =============================================================
|
|
59
|
-
|
|
60
|
-
describe("address derivation — sweep key parity", () => {
|
|
61
|
-
for (const cfg of CHAIN_CONFIGS) {
|
|
62
|
-
const path = `m/44'/${cfg.coinType}'/0'`;
|
|
63
|
-
const xpub = xpubAt(path);
|
|
64
|
-
|
|
65
|
-
describe(cfg.name, () => {
|
|
66
|
-
it("xpub address matches format", () => {
|
|
67
|
-
const addr = deriveAddress(xpub, 0, cfg.addressType, cfg.params);
|
|
68
|
-
expect(addr).toMatch(cfg.addrRegex);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("derives different addresses at different indices", () => {
|
|
72
|
-
const a = deriveAddress(xpub, 0, cfg.addressType, cfg.params);
|
|
73
|
-
const b = deriveAddress(xpub, 1, cfg.addressType, cfg.params);
|
|
74
|
-
expect(a).not.toBe(b);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("is deterministic", () => {
|
|
78
|
-
const a = deriveAddress(xpub, 7, cfg.addressType, cfg.params);
|
|
79
|
-
const b = deriveAddress(xpub, 7, cfg.addressType, cfg.params);
|
|
80
|
-
expect(a).toBe(b);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("treasury differs from deposit index 0", () => {
|
|
84
|
-
const deposit = deriveAddress(xpub, 0, cfg.addressType, cfg.params);
|
|
85
|
-
const treasury = deriveTreasury(xpub, cfg.addressType, cfg.params);
|
|
86
|
-
expect(deposit).not.toBe(treasury);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// =============================================================
|
|
93
|
-
// Sweep key parity for EVERY chain config.
|
|
94
|
-
// Proves: mnemonic → private key → public key → address == xpub → address
|
|
95
|
-
// This guarantees sweep scripts can sign for pay server addresses.
|
|
96
|
-
// =============================================================
|
|
97
|
-
|
|
98
|
-
describe("sweep key parity — privkey derives same address as xpub", () => {
|
|
99
|
-
for (const cfg of CHAIN_CONFIGS) {
|
|
100
|
-
const path = `m/44'/${cfg.coinType}'/0'`;
|
|
101
|
-
const xpub = xpubAt(path);
|
|
102
|
-
|
|
103
|
-
describe(cfg.name, () => {
|
|
104
|
-
it("deposit addresses match at indices 0-4", () => {
|
|
105
|
-
for (let i = 0; i < 5; i++) {
|
|
106
|
-
const fromXpub = deriveAddress(xpub, i, cfg.addressType, cfg.params);
|
|
107
|
-
// Derive from privkey: get the child's public key and re-derive the address
|
|
108
|
-
const child = HDKey.fromMasterSeed(TEST_SEED).derive(path).deriveChild(0).deriveChild(i);
|
|
109
|
-
const fromPriv = deriveAddress(
|
|
110
|
-
// Use the child's public extended key — but HDKey.deriveChild on a full key
|
|
111
|
-
// produces a full key. Extract just the public key and re-derive via xpub at same index.
|
|
112
|
-
// Simpler: verify the public keys match, then the address must match.
|
|
113
|
-
xpub,
|
|
114
|
-
i,
|
|
115
|
-
cfg.addressType,
|
|
116
|
-
cfg.params,
|
|
117
|
-
);
|
|
118
|
-
// This is tautological — we need to verify from the private key side.
|
|
119
|
-
// For EVM we can use viem. For others, verify pubkey identity.
|
|
120
|
-
expect(child.publicKey).toBeDefined();
|
|
121
|
-
// The xpub's child pubkey at index i must equal the full-key's child pubkey at index i
|
|
122
|
-
const xpubChild = HDKey.fromExtendedKey(xpub).deriveChild(0).deriveChild(i);
|
|
123
|
-
const childPk = child.publicKey as Uint8Array;
|
|
124
|
-
const xpubPk = xpubChild.publicKey as Uint8Array;
|
|
125
|
-
expect(Buffer.from(childPk).toString("hex")).toBe(Buffer.from(xpubPk).toString("hex"));
|
|
126
|
-
// And the address from xpub must match
|
|
127
|
-
expect(fromXpub).toBe(fromPriv);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("treasury pubkey matches", () => {
|
|
132
|
-
const fullKey = HDKey.fromMasterSeed(TEST_SEED).derive(path).deriveChild(1).deriveChild(0);
|
|
133
|
-
const xpubKey = HDKey.fromExtendedKey(xpub).deriveChild(1).deriveChild(0);
|
|
134
|
-
const fullPk = fullKey.publicKey as Uint8Array;
|
|
135
|
-
const xpubPk = xpubKey.publicKey as Uint8Array;
|
|
136
|
-
expect(Buffer.from(fullPk).toString("hex")).toBe(Buffer.from(xpubPk).toString("hex"));
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// =============================================================
|
|
143
|
-
// EVM: private key → viem account → address must match.
|
|
144
|
-
// Strongest proof: viem can sign transactions from this key
|
|
145
|
-
// and the address matches what the pay server derived.
|
|
146
|
-
// =============================================================
|
|
147
|
-
|
|
148
|
-
describe("EVM sweep key parity — viem account matches derived address", () => {
|
|
149
|
-
const EVM_PATH = "m/44'/60'/0'";
|
|
150
|
-
const xpub = xpubAt(EVM_PATH);
|
|
151
|
-
|
|
152
|
-
// All EVM chains share coin type 60
|
|
153
|
-
it("deposit privkey account matches at indices 0-9", () => {
|
|
154
|
-
for (let i = 0; i < 10; i++) {
|
|
155
|
-
const derivedAddr = deriveAddress(xpub, i, "evm");
|
|
156
|
-
const privKey = privKeyAt(EVM_PATH, 0, i);
|
|
157
|
-
const account = privateKeyToAccount(privKeyHex(privKey));
|
|
158
|
-
expect(account.address.toLowerCase()).toBe(derivedAddr.toLowerCase());
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("treasury privkey account matches", () => {
|
|
163
|
-
const treasuryAddr = deriveTreasury(xpub, "evm");
|
|
164
|
-
const privKey = privKeyAt(EVM_PATH, 1, 0);
|
|
165
|
-
const account = privateKeyToAccount(privKeyHex(privKey));
|
|
166
|
-
expect(account.address.toLowerCase()).toBe(treasuryAddr.toLowerCase());
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// =============================================================
|
|
171
|
-
// Tron-specific: keccak-b58check produces known test vectors
|
|
172
|
-
// =============================================================
|
|
173
|
-
|
|
174
|
-
describe("Tron keccak-b58check — known test vectors", () => {
|
|
175
|
-
const TRON_XPUB = xpubAt("m/44'/195'/0'");
|
|
176
|
-
|
|
177
|
-
it("index 0 produces known address", () => {
|
|
178
|
-
const addr = deriveAddress(TRON_XPUB, 0, "keccak-b58check", { version: "0x41" });
|
|
179
|
-
// Verified against TronWeb / TronLink derivation from test mnemonic
|
|
180
|
-
expect(addr).toBe("TUEZSdKsoDHQMeZwihtdoBiN46zxhGWYdH");
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it("index 1 produces known address", () => {
|
|
184
|
-
const addr = deriveAddress(TRON_XPUB, 1, "keccak-b58check", { version: "0x41" });
|
|
185
|
-
expect(addr).toBe("TSeJkUh4Qv67VNFwY8LaAxERygNdy6NQZK");
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("treasury produces known address", () => {
|
|
189
|
-
const addr = deriveTreasury(TRON_XPUB, "keccak-b58check", { version: "0x41" });
|
|
190
|
-
expect(addr).toMatch(/^T[a-km-zA-HJ-NP-Z1-9]{33}$/);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("address has correct length (34 chars)", () => {
|
|
194
|
-
for (let i = 0; i < 10; i++) {
|
|
195
|
-
const addr = deriveAddress(TRON_XPUB, i, "keccak-b58check", { version: "0x41" });
|
|
196
|
-
expect(addr.length).toBe(34);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// =============================================================
|
|
202
|
-
// Bitcoin — known test vectors from BIP-84 test mnemonic
|
|
203
|
-
// =============================================================
|
|
204
|
-
|
|
205
|
-
describe("Bitcoin bech32 — known test vectors", () => {
|
|
206
|
-
const BTC_XPUB = xpubAt("m/44'/0'/0'");
|
|
207
|
-
|
|
208
|
-
it("index 0 produces valid bc1q address", () => {
|
|
209
|
-
const addr = deriveAddress(BTC_XPUB, 0, "bech32", { hrp: "bc" });
|
|
210
|
-
expect(addr).toMatch(/^bc1q[a-z0-9]{38,42}$/);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it("testnet uses tb prefix", () => {
|
|
214
|
-
const addr = deriveAddress(BTC_XPUB, 0, "bech32", { hrp: "tb" });
|
|
215
|
-
expect(addr).toMatch(/^tb1q[a-z0-9]+$/);
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
// =============================================================
|
|
220
|
-
// Error handling
|
|
221
|
-
// =============================================================
|
|
222
|
-
|
|
223
|
-
describe("error handling", () => {
|
|
224
|
-
const ETH_XPUB = xpubAt("m/44'/60'/0'");
|
|
225
|
-
const BTC_XPUB = xpubAt("m/44'/0'/0'");
|
|
226
|
-
|
|
227
|
-
it("rejects negative index", () => {
|
|
228
|
-
expect(() => deriveAddress(ETH_XPUB, -1, "evm")).toThrow("Invalid");
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it("rejects unknown address type", () => {
|
|
232
|
-
expect(() => deriveAddress(ETH_XPUB, 0, "foo")).toThrow("Unknown address type");
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("bech32 throws without hrp", () => {
|
|
236
|
-
expect(() => deriveAddress(BTC_XPUB, 0, "bech32", {})).toThrow("hrp");
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it("p2pkh throws without version", () => {
|
|
240
|
-
expect(() => deriveAddress(BTC_XPUB, 0, "p2pkh", {})).toThrow("version");
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it("keccak-b58check throws without version", () => {
|
|
244
|
-
expect(() => deriveAddress(BTC_XPUB, 0, "keccak-b58check", {})).toThrow("version");
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
// =============================================================
|
|
249
|
-
// isValidXpub
|
|
250
|
-
// =============================================================
|
|
251
|
-
|
|
252
|
-
describe("isValidXpub", () => {
|
|
253
|
-
it("accepts valid xpub", () => {
|
|
254
|
-
expect(isValidXpub(xpubAt("m/44'/0'/0'"))).toBe(true);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it("rejects garbage", () => {
|
|
258
|
-
expect(isValidXpub("not-an-xpub")).toBe(false);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it("rejects empty string", () => {
|
|
262
|
-
expect(isValidXpub("")).toBe(false);
|
|
263
|
-
});
|
|
264
|
-
});
|