@btc-vision/transaction 1.7.31 → 1.8.0-alpha.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/AUDIT/README.md +9 -0
- package/CHANGELOG.md +5 -0
- package/README.md +62 -18
- package/SECURITY.md +71 -0
- package/browser/deterministic/ExtendedAddressMap.d.ts +17 -0
- package/browser/index.js +448 -362
- package/browser/keypair/Address.d.ts +3 -1
- package/browser/mnemonic/Mnemonic.d.ts +1 -1
- package/browser/noble-curves.js +1087 -1116
- package/browser/noble-hashes.js +25 -25
- package/browser/opnet.d.ts +1 -0
- package/browser/transaction/browser/WalletNetworks.d.ts +3 -3
- package/browser/transaction/browser/types/Unisat.d.ts +2 -2
- package/browser/vendors.js +950 -911
- package/build/deterministic/ExtendedAddressMap.d.ts +17 -0
- package/build/deterministic/ExtendedAddressMap.js +60 -0
- package/build/keypair/Address.d.ts +3 -1
- package/build/keypair/Address.js +30 -10
- package/build/mnemonic/Mnemonic.d.ts +1 -1
- package/build/mnemonic/Mnemonic.js +2 -2
- package/build/opnet.d.ts +1 -0
- package/build/opnet.js +1 -0
- package/build/transaction/browser/WalletNetworks.d.ts +3 -3
- package/build/transaction/browser/WalletNetworks.js +3 -3
- package/build/transaction/browser/extensions/UnisatSigner.js +3 -3
- package/build/transaction/browser/types/Unisat.d.ts +2 -2
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +13 -13
- package/src/deterministic/ExtendedAddressMap.ts +83 -0
- package/src/keypair/Address.ts +53 -9
- package/src/mnemonic/Mnemonic.ts +2 -2
- package/src/opnet.ts +1 -0
- package/src/transaction/browser/WalletNetworks.ts +3 -3
- package/src/transaction/browser/extensions/UnisatSigner.ts +3 -3
- package/src/transaction/browser/types/Unisat.ts +2 -2
- package/test/derivePath.test.ts +30 -29
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btc-vision/transaction",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.0-alpha.1",
|
|
5
5
|
"author": "BlobMaster41",
|
|
6
6
|
"description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
|
|
7
7
|
"engines": {
|
|
@@ -148,32 +148,32 @@
|
|
|
148
148
|
"prebuild": "npm run check:circular"
|
|
149
149
|
},
|
|
150
150
|
"devDependencies": {
|
|
151
|
-
"@babel/core": "^7.28.
|
|
151
|
+
"@babel/core": "^7.28.6",
|
|
152
152
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
153
153
|
"@babel/plugin-transform-runtime": "^7.28.5",
|
|
154
|
-
"@babel/preset-env": "^7.28.
|
|
154
|
+
"@babel/preset-env": "^7.28.6",
|
|
155
155
|
"@babel/preset-flow": "^7.27.1",
|
|
156
156
|
"@babel/preset-react": "^7.28.5",
|
|
157
157
|
"@babel/preset-typescript": "^7.28.5",
|
|
158
158
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
159
|
-
"@types/node": "^
|
|
159
|
+
"@types/node": "^25.0.9",
|
|
160
160
|
"@types/sha.js": "^2.4.4",
|
|
161
161
|
"@vitejs/plugin-legacy": "^7.2.1",
|
|
162
|
-
"@vitest/ui": "^4.0.
|
|
163
|
-
"eslint": "^9.39.
|
|
162
|
+
"@vitest/ui": "^4.0.17",
|
|
163
|
+
"eslint": "^9.39.2",
|
|
164
164
|
"https-browserify": "^1.0.0",
|
|
165
165
|
"madge": "^8.0.0",
|
|
166
166
|
"os-browserify": "^0.3.0",
|
|
167
|
-
"prettier": "^3.
|
|
167
|
+
"prettier": "^3.8.0",
|
|
168
168
|
"stream-browserify": "^3.0.0",
|
|
169
169
|
"stream-http": "^3.2.0",
|
|
170
170
|
"tslib": "^2.8.1",
|
|
171
|
-
"typedoc": "^0.28.
|
|
172
|
-
"typescript-eslint": "^8.
|
|
173
|
-
"vite": "^7.3.
|
|
171
|
+
"typedoc": "^0.28.16",
|
|
172
|
+
"typescript-eslint": "^8.53.1",
|
|
173
|
+
"vite": "^7.3.1",
|
|
174
174
|
"vite-plugin-dts": "^4.5.4",
|
|
175
|
-
"vite-plugin-node-polyfills": "^0.
|
|
176
|
-
"vitest": "^4.0.
|
|
175
|
+
"vite-plugin-node-polyfills": "^0.25.0",
|
|
176
|
+
"vitest": "^4.0.17"
|
|
177
177
|
},
|
|
178
178
|
"dependencies": {
|
|
179
179
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
"@btc-vision/bitcoin-rpc": "^1.0.6",
|
|
184
184
|
"@btc-vision/logger": "^1.0.8",
|
|
185
185
|
"@btc-vision/post-quantum": "^0.5.3",
|
|
186
|
-
"@eslint/js": "^9.39.
|
|
186
|
+
"@eslint/js": "^9.39.2",
|
|
187
187
|
"@noble/curves": "^1.9.7",
|
|
188
188
|
"@noble/secp256k1": "^3.0.0",
|
|
189
189
|
"assert": "^2.1.0",
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Address } from '../keypair/Address.js';
|
|
2
|
+
import { FastMap } from './FastMap.js';
|
|
3
|
+
|
|
4
|
+
export class ExtendedAddressMap<V> {
|
|
5
|
+
private items: FastMap<bigint, V>;
|
|
6
|
+
|
|
7
|
+
constructor(iterable?: ReadonlyArray<readonly [Address, V]> | null) {
|
|
8
|
+
this.items = new FastMap();
|
|
9
|
+
|
|
10
|
+
if (iterable) {
|
|
11
|
+
for (const [key, value] of iterable) {
|
|
12
|
+
this.set(key, value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public get size(): number {
|
|
18
|
+
return this.items.size;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public set(key: Address, value: V): this {
|
|
22
|
+
const keyBigInt = key.tweakedToBigInt();
|
|
23
|
+
this.items.set(keyBigInt, value);
|
|
24
|
+
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public get(key: Address): V | undefined {
|
|
29
|
+
return this.items.get(key.tweakedToBigInt());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public has(key: Address): boolean {
|
|
33
|
+
return this.items.has(key.tweakedToBigInt());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public delete(key: Address): boolean {
|
|
37
|
+
const keyBigInt = key.tweakedToBigInt();
|
|
38
|
+
return this.items.delete(keyBigInt);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public clear(): void {
|
|
42
|
+
this.items.clear();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public indexOf(address: Address): number {
|
|
46
|
+
return this.items.indexOf(address.tweakedToBigInt());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* WARNING, THIS RETURN NEW COPY OF THE KEYS
|
|
51
|
+
*/
|
|
52
|
+
*entries(): IterableIterator<[Address, V]> {
|
|
53
|
+
for (const [keyBigInt, value] of this.items.entries()) {
|
|
54
|
+
yield [Address.fromBigInt(keyBigInt), value];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
*keys(): IterableIterator<Address> {
|
|
59
|
+
for (const keyBigInt of this.items.keys()) {
|
|
60
|
+
yield Address.fromBigInt(keyBigInt);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
*values(): IterableIterator<V> {
|
|
65
|
+
for (const value of this.items.values()) {
|
|
66
|
+
yield value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
forEach(
|
|
71
|
+
callback: (value: V, key: Address, map: ExtendedAddressMap<V>) => void,
|
|
72
|
+
thisArg?: unknown,
|
|
73
|
+
): void {
|
|
74
|
+
for (const [keyBigInt, value] of this.items.entries()) {
|
|
75
|
+
const key = Address.fromBigInt(0n, keyBigInt);
|
|
76
|
+
callback.call(thisArg, value, key, this);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
*[Symbol.iterator](): IterableIterator<[Address, V]> {
|
|
81
|
+
yield* this.entries();
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/keypair/Address.ts
CHANGED
|
@@ -32,6 +32,7 @@ export class Address extends Uint8Array {
|
|
|
32
32
|
#p2wda: IP2WSHAddress | undefined;
|
|
33
33
|
#mldsaPublicKey: Uint8Array | undefined;
|
|
34
34
|
#cachedBigInt: bigint | undefined;
|
|
35
|
+
#cachedBigIntTweaked: bigint | undefined;
|
|
35
36
|
#cachedUint64Array: [bigint, bigint, bigint, bigint] | undefined;
|
|
36
37
|
#originalMDLSAPublicKey: Uint8Array | undefined;
|
|
37
38
|
#mldsaLevel: MLDSASecurityLevel | undefined;
|
|
@@ -192,6 +193,7 @@ export class Address extends Uint8Array {
|
|
|
192
193
|
* This is the inverse operation of toBigInt().
|
|
193
194
|
*
|
|
194
195
|
* @param {bigint} value - The 256-bit unsigned integer to convert (0 to 2^256-1)
|
|
196
|
+
* @param {bigint} [tweakedValue] - Optional tweaked public key as a 256-bit unsigned integer
|
|
195
197
|
* @returns {Address} A new Address instance containing the converted value
|
|
196
198
|
*
|
|
197
199
|
* @throws {RangeError} If the value is negative or exceeds 2^256-1
|
|
@@ -203,16 +205,11 @@ export class Address extends Uint8Array {
|
|
|
203
205
|
* console.log(address.toHex()); // 0x0000000000000000000000000000000000000000000000000000abc123...
|
|
204
206
|
* ```
|
|
205
207
|
*/
|
|
206
|
-
public static fromBigInt(value: bigint): Address {
|
|
207
|
-
const
|
|
208
|
-
const
|
|
208
|
+
public static fromBigInt(value: bigint, tweakedValue?: bigint): Address {
|
|
209
|
+
const address = Address.bigintToUint8Array(value);
|
|
210
|
+
const legacyAddress = tweakedValue ? Address.bigintToUint8Array(tweakedValue) : undefined;
|
|
209
211
|
|
|
210
|
-
|
|
211
|
-
view.setBigUint64(8, (value >> 128n) & 0xffffffffffffffffn, false);
|
|
212
|
-
view.setBigUint64(16, (value >> 64n) & 0xffffffffffffffffn, false);
|
|
213
|
-
view.setBigUint64(24, value & 0xffffffffffffffffn, false);
|
|
214
|
-
|
|
215
|
-
return new Address(buffer);
|
|
212
|
+
return new Address(address, legacyAddress);
|
|
216
213
|
}
|
|
217
214
|
|
|
218
215
|
/**
|
|
@@ -253,6 +250,18 @@ export class Address extends Uint8Array {
|
|
|
253
250
|
return new Address(buffer);
|
|
254
251
|
}
|
|
255
252
|
|
|
253
|
+
private static bigintToUint8Array(value: bigint): Uint8Array {
|
|
254
|
+
const buffer = new Uint8Array(32);
|
|
255
|
+
const view = new DataView(buffer.buffer);
|
|
256
|
+
|
|
257
|
+
view.setBigUint64(0, (value >> 192n) & 0xffffffffffffffffn, false);
|
|
258
|
+
view.setBigUint64(8, (value >> 128n) & 0xffffffffffffffffn, false);
|
|
259
|
+
view.setBigUint64(16, (value >> 64n) & 0xffffffffffffffffn, false);
|
|
260
|
+
view.setBigUint64(24, value & 0xffffffffffffffffn, false);
|
|
261
|
+
|
|
262
|
+
return buffer;
|
|
263
|
+
}
|
|
264
|
+
|
|
256
265
|
/**
|
|
257
266
|
* Converts the address to four 64-bit unsigned integers.
|
|
258
267
|
*
|
|
@@ -419,6 +428,41 @@ export class Address extends Uint8Array {
|
|
|
419
428
|
return this.#cachedBigInt;
|
|
420
429
|
}
|
|
421
430
|
|
|
431
|
+
/**
|
|
432
|
+
* Converts the tweaked public key to a BigInt representation.
|
|
433
|
+
*
|
|
434
|
+
* This method uses an optimized DataView approach to read the 32-byte address
|
|
435
|
+
* as four 64-bit big-endian unsigned integers, then combines them using bitwise
|
|
436
|
+
* operations. This is approximately 10-20x faster than string-based conversion.
|
|
437
|
+
*
|
|
438
|
+
* @returns {bigint} The address as a 256-bit unsigned integer
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```typescript
|
|
442
|
+
* const address = Address.fromString('0x0123456789abcdef...', '0xtweaked...');
|
|
443
|
+
* const bigIntValue = address.tweakedToBigInt();
|
|
444
|
+
* console.log(bigIntValue); // 123456789...n
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
public tweakedToBigInt(): bigint {
|
|
448
|
+
if (!this.legacyPublicKey) {
|
|
449
|
+
throw new Error('Legacy public key not set');
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (this.#cachedBigIntTweaked !== undefined) {
|
|
453
|
+
return this.#cachedBigIntTweaked;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const view = new DataView(this.legacyPublicKey.buffer, this.byteOffset, 32);
|
|
457
|
+
this.#cachedBigIntTweaked =
|
|
458
|
+
(view.getBigUint64(0, false) << 192n) |
|
|
459
|
+
(view.getBigUint64(8, false) << 128n) |
|
|
460
|
+
(view.getBigUint64(16, false) << 64n) |
|
|
461
|
+
view.getBigUint64(24, false);
|
|
462
|
+
|
|
463
|
+
return this.#cachedBigIntTweaked;
|
|
464
|
+
}
|
|
465
|
+
|
|
422
466
|
public equals(a: Address): boolean {
|
|
423
467
|
const b: Address = this as Address;
|
|
424
468
|
|
package/src/mnemonic/Mnemonic.ts
CHANGED
|
@@ -263,7 +263,7 @@ export class Mnemonic {
|
|
|
263
263
|
* @param isChange - Whether this is a change address (default: false)
|
|
264
264
|
* @returns A Wallet instance with both classical and quantum keys
|
|
265
265
|
*/
|
|
266
|
-
public
|
|
266
|
+
public deriveOPWallet(
|
|
267
267
|
addressType: AddressTypes = AddressTypes.P2TR,
|
|
268
268
|
index: number = 0,
|
|
269
269
|
account: number = 0,
|
|
@@ -338,7 +338,7 @@ export class Mnemonic {
|
|
|
338
338
|
const wallets: Wallet[] = [];
|
|
339
339
|
|
|
340
340
|
for (let i = 0; i < count; i++) {
|
|
341
|
-
wallets.push(this.
|
|
341
|
+
wallets.push(this.deriveOPWallet(addressType, startIndex + i, account, isChange));
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
return wallets;
|
package/src/opnet.ts
CHANGED
|
@@ -125,6 +125,7 @@ export * from './abi/ABICoder.js';
|
|
|
125
125
|
export * from './buffer/BinaryReader.js';
|
|
126
126
|
export * from './buffer/BinaryWriter.js';
|
|
127
127
|
export * from './deterministic/AddressMap.js';
|
|
128
|
+
export * from './deterministic/ExtendedAddressMap.js';
|
|
128
129
|
export * from './deterministic/AddressSet.js';
|
|
129
130
|
export * from './deterministic/DeterministicMap.js';
|
|
130
131
|
export * from './deterministic/DeterministicSet.js';
|
|
@@ -107,13 +107,13 @@ export class UnisatSigner extends CustomKeypair {
|
|
|
107
107
|
|
|
108
108
|
const network = await this.unisat.getNetwork();
|
|
109
109
|
switch (network) {
|
|
110
|
-
case WalletNetworks.
|
|
110
|
+
case WalletNetworks.Mainnet:
|
|
111
111
|
this._network = networks.bitcoin;
|
|
112
112
|
break;
|
|
113
|
-
case WalletNetworks.
|
|
113
|
+
case WalletNetworks.Testnet:
|
|
114
114
|
this._network = networks.testnet;
|
|
115
115
|
break;
|
|
116
|
-
case WalletNetworks.
|
|
116
|
+
case WalletNetworks.Regtest:
|
|
117
117
|
this._network = networks.regtest;
|
|
118
118
|
break;
|
|
119
119
|
default:
|
|
@@ -51,8 +51,8 @@ export interface PsbtSignatureOptions {
|
|
|
51
51
|
export interface Unisat {
|
|
52
52
|
web3?: Web3Provider;
|
|
53
53
|
|
|
54
|
-
disconnect: () => void
|
|
55
|
-
connect: () => void
|
|
54
|
+
disconnect: () => Promise<void>;
|
|
55
|
+
connect: () => Promise<void>;
|
|
56
56
|
|
|
57
57
|
sendBitcoin(
|
|
58
58
|
toAddress: string,
|
package/test/derivePath.test.ts
CHANGED
|
@@ -233,10 +233,11 @@ describe('Wallet.derivePath', () => {
|
|
|
233
233
|
});
|
|
234
234
|
});
|
|
235
235
|
|
|
236
|
-
describe('Mnemonic.
|
|
236
|
+
describe('Mnemonic.deriveOPWallet', () => {
|
|
237
237
|
const testMnemonic =
|
|
238
238
|
'episode frost someone page color giraffe match vanish sheriff veteran hub year pull save dizzy limb already turn reopen truth cradle rural wisdom change';
|
|
239
|
-
const unisatExpectedAddress =
|
|
239
|
+
const unisatExpectedAddress =
|
|
240
|
+
'bcrt1phn6ej9ct038j722wdzkvsk7c6pmugtd5d3qnpwxc8g40zerf2ujs55tkz3';
|
|
240
241
|
|
|
241
242
|
describe('P2TR (Taproot) derivation', () => {
|
|
242
243
|
it('should match Unisat P2TR address for regtest', () => {
|
|
@@ -247,7 +248,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
247
248
|
MLDSASecurityLevel.LEVEL2,
|
|
248
249
|
);
|
|
249
250
|
|
|
250
|
-
const wallet = mnemonic.
|
|
251
|
+
const wallet = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0, 0, false);
|
|
251
252
|
|
|
252
253
|
expect(wallet.p2tr).toBe(unisatExpectedAddress);
|
|
253
254
|
});
|
|
@@ -260,7 +261,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
260
261
|
MLDSASecurityLevel.LEVEL2,
|
|
261
262
|
);
|
|
262
263
|
|
|
263
|
-
const wallet = mnemonic.
|
|
264
|
+
const wallet = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0);
|
|
264
265
|
|
|
265
266
|
expect(wallet.p2tr).toMatch(/^bc1p/);
|
|
266
267
|
});
|
|
@@ -273,7 +274,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
273
274
|
MLDSASecurityLevel.LEVEL2,
|
|
274
275
|
);
|
|
275
276
|
|
|
276
|
-
const wallet = mnemonic.
|
|
277
|
+
const wallet = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0);
|
|
277
278
|
|
|
278
279
|
expect(wallet.p2tr).toMatch(/^tb1p/);
|
|
279
280
|
});
|
|
@@ -288,13 +289,13 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
288
289
|
MLDSASecurityLevel.LEVEL2,
|
|
289
290
|
);
|
|
290
291
|
|
|
291
|
-
const wallet = mnemonic.
|
|
292
|
+
const wallet = mnemonic.deriveOPWallet(AddressTypes.P2WPKH, 0);
|
|
292
293
|
|
|
293
294
|
expect(wallet.p2wpkh).toBeDefined();
|
|
294
295
|
expect(wallet.p2wpkh).toMatch(/^bc1q/);
|
|
295
296
|
});
|
|
296
297
|
|
|
297
|
-
it(
|
|
298
|
+
it("should use BIP84 path (m/84'/0'/0'/0/0)", () => {
|
|
298
299
|
const mnemonic = new Mnemonic(
|
|
299
300
|
testMnemonic,
|
|
300
301
|
'',
|
|
@@ -302,7 +303,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
302
303
|
MLDSASecurityLevel.LEVEL2,
|
|
303
304
|
);
|
|
304
305
|
|
|
305
|
-
const wallet = mnemonic.
|
|
306
|
+
const wallet = mnemonic.deriveOPWallet(AddressTypes.P2WPKH, 0);
|
|
306
307
|
expect(wallet.p2wpkh).toBeDefined();
|
|
307
308
|
});
|
|
308
309
|
});
|
|
@@ -316,7 +317,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
316
317
|
MLDSASecurityLevel.LEVEL2,
|
|
317
318
|
);
|
|
318
319
|
|
|
319
|
-
const wallet = mnemonic.
|
|
320
|
+
const wallet = mnemonic.deriveOPWallet(AddressTypes.P2PKH, 0);
|
|
320
321
|
|
|
321
322
|
expect(wallet.legacy).toBeDefined();
|
|
322
323
|
expect(wallet.legacy).toMatch(/^1/);
|
|
@@ -332,9 +333,9 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
332
333
|
MLDSASecurityLevel.LEVEL2,
|
|
333
334
|
);
|
|
334
335
|
|
|
335
|
-
const wallet0 = mnemonic.
|
|
336
|
-
const wallet1 = mnemonic.
|
|
337
|
-
const wallet2 = mnemonic.
|
|
336
|
+
const wallet0 = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0);
|
|
337
|
+
const wallet1 = mnemonic.deriveOPWallet(AddressTypes.P2TR, 1);
|
|
338
|
+
const wallet2 = mnemonic.deriveOPWallet(AddressTypes.P2TR, 2);
|
|
338
339
|
|
|
339
340
|
expect(wallet0.p2tr).not.toBe(wallet1.p2tr);
|
|
340
341
|
expect(wallet1.p2tr).not.toBe(wallet2.p2tr);
|
|
@@ -349,8 +350,8 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
349
350
|
MLDSASecurityLevel.LEVEL2,
|
|
350
351
|
);
|
|
351
352
|
|
|
352
|
-
const wallet1 = mnemonic.
|
|
353
|
-
const wallet2 = mnemonic.
|
|
353
|
+
const wallet1 = mnemonic.deriveOPWallet(AddressTypes.P2TR, 5);
|
|
354
|
+
const wallet2 = mnemonic.deriveOPWallet(AddressTypes.P2TR, 5);
|
|
354
355
|
|
|
355
356
|
expect(wallet1.p2tr).toBe(wallet2.p2tr);
|
|
356
357
|
expect(wallet1.toPublicKeyHex()).toBe(wallet2.toPublicKeyHex());
|
|
@@ -366,8 +367,8 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
366
367
|
MLDSASecurityLevel.LEVEL2,
|
|
367
368
|
);
|
|
368
369
|
|
|
369
|
-
const account0 = mnemonic.
|
|
370
|
-
const account1 = mnemonic.
|
|
370
|
+
const account0 = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0, 0);
|
|
371
|
+
const account1 = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0, 1);
|
|
371
372
|
|
|
372
373
|
expect(account0.p2tr).not.toBe(account1.p2tr);
|
|
373
374
|
});
|
|
@@ -380,8 +381,8 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
380
381
|
MLDSASecurityLevel.LEVEL2,
|
|
381
382
|
);
|
|
382
383
|
|
|
383
|
-
const receiving = mnemonic.
|
|
384
|
-
const change = mnemonic.
|
|
384
|
+
const receiving = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0, 0, false);
|
|
385
|
+
const change = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0, 0, true);
|
|
385
386
|
|
|
386
387
|
expect(receiving.p2tr).not.toBe(change.p2tr);
|
|
387
388
|
});
|
|
@@ -396,7 +397,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
396
397
|
MLDSASecurityLevel.LEVEL2,
|
|
397
398
|
);
|
|
398
399
|
|
|
399
|
-
const wallet = mnemonic.
|
|
400
|
+
const wallet = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0);
|
|
400
401
|
|
|
401
402
|
expect(wallet.quantumPublicKey).toBeDefined();
|
|
402
403
|
expect(wallet.quantumPublicKey.length).toBe(1312); // LEVEL2 size
|
|
@@ -411,14 +412,14 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
411
412
|
MLDSASecurityLevel.LEVEL2,
|
|
412
413
|
);
|
|
413
414
|
|
|
414
|
-
const wallet0 = mnemonic.
|
|
415
|
-
const wallet1 = mnemonic.
|
|
415
|
+
const wallet0 = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0);
|
|
416
|
+
const wallet1 = mnemonic.deriveOPWallet(AddressTypes.P2TR, 1);
|
|
416
417
|
|
|
417
418
|
expect(wallet0.address.toHex()).not.toBe(wallet1.address.toHex());
|
|
418
419
|
});
|
|
419
420
|
});
|
|
420
421
|
|
|
421
|
-
describe('
|
|
422
|
+
describe('deriveMultipleOPWallet', () => {
|
|
422
423
|
it('should derive multiple wallets', () => {
|
|
423
424
|
const mnemonic = new Mnemonic(
|
|
424
425
|
testMnemonic,
|
|
@@ -427,7 +428,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
427
428
|
MLDSASecurityLevel.LEVEL2,
|
|
428
429
|
);
|
|
429
430
|
|
|
430
|
-
const wallets = mnemonic.
|
|
431
|
+
const wallets = mnemonic.deriveMultipleOPWallet(AddressTypes.P2TR, 5);
|
|
431
432
|
|
|
432
433
|
expect(wallets.length).toBe(5);
|
|
433
434
|
expect(wallets[0].p2tr).toBeDefined();
|
|
@@ -442,7 +443,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
442
443
|
MLDSASecurityLevel.LEVEL2,
|
|
443
444
|
);
|
|
444
445
|
|
|
445
|
-
const wallets = mnemonic.
|
|
446
|
+
const wallets = mnemonic.deriveMultipleOPWallet(AddressTypes.P2TR, 3);
|
|
446
447
|
|
|
447
448
|
const addresses = wallets.map((w) => w.p2tr);
|
|
448
449
|
const uniqueAddresses = new Set(addresses);
|
|
@@ -458,8 +459,8 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
458
459
|
MLDSASecurityLevel.LEVEL2,
|
|
459
460
|
);
|
|
460
461
|
|
|
461
|
-
const wallets = mnemonic.
|
|
462
|
-
const wallet5 = mnemonic.
|
|
462
|
+
const wallets = mnemonic.deriveMultipleOPWallet(AddressTypes.P2TR, 2, 5);
|
|
463
|
+
const wallet5 = mnemonic.deriveOPWallet(AddressTypes.P2TR, 5);
|
|
463
464
|
|
|
464
465
|
expect(wallets[0].p2tr).toBe(wallet5.p2tr);
|
|
465
466
|
});
|
|
@@ -475,7 +476,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
475
476
|
);
|
|
476
477
|
|
|
477
478
|
expect(() => {
|
|
478
|
-
mnemonic.
|
|
479
|
+
mnemonic.deriveOPWallet('INVALID_TYPE' as AddressTypes, 0);
|
|
479
480
|
}).toThrow('Unsupported address type');
|
|
480
481
|
});
|
|
481
482
|
});
|
|
@@ -489,7 +490,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
489
490
|
MLDSASecurityLevel.LEVEL2,
|
|
490
491
|
);
|
|
491
492
|
|
|
492
|
-
const wallet = mnemonic.
|
|
493
|
+
const wallet = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0);
|
|
493
494
|
|
|
494
495
|
expect(wallet.network.bech32).toBe('tb');
|
|
495
496
|
});
|
|
@@ -504,7 +505,7 @@ describe('Mnemonic.deriveUnisat', () => {
|
|
|
504
505
|
MLDSASecurityLevel.LEVEL3,
|
|
505
506
|
);
|
|
506
507
|
|
|
507
|
-
const wallet = mnemonic.
|
|
508
|
+
const wallet = mnemonic.deriveOPWallet(AddressTypes.P2TR, 0);
|
|
508
509
|
|
|
509
510
|
expect(wallet.securityLevel).toBe(MLDSASecurityLevel.LEVEL3);
|
|
510
511
|
expect(wallet.quantumPublicKey.length).toBe(1952); // LEVEL3 size
|