@btc-vision/transaction 1.7.0 → 1.7.2
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/browser/index.js +1 -1
- package/browser/src/_version.d.ts +1 -1
- package/browser/src/buffer/BinaryReader.d.ts +2 -2
- package/browser/src/deterministic/AddressMap.d.ts +12 -5
- package/browser/src/deterministic/AddressSet.d.ts +2 -1
- package/browser/src/deterministic/DeterministicMap.d.ts +1 -1
- package/browser/src/keypair/Address.d.ts +4 -0
- package/browser/src/mnemonic/BIPStandard.d.ts +8 -0
- package/browser/src/mnemonic/Mnemonic.d.ts +7 -2
- package/browser/src/opnet.d.ts +1 -0
- package/browser/src/utils/lengths.d.ts +15 -16
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/buffer/BinaryReader.d.ts +2 -2
- package/build/deterministic/AddressMap.d.ts +12 -5
- package/build/deterministic/AddressMap.js +51 -33
- package/build/deterministic/AddressSet.d.ts +2 -1
- package/build/deterministic/AddressSet.js +17 -21
- package/build/deterministic/DeterministicMap.d.ts +1 -1
- package/build/deterministic/DeterministicMap.js +15 -15
- package/build/keypair/Address.d.ts +4 -0
- package/build/keypair/Address.js +46 -2
- package/build/mnemonic/BIPStandard.d.ts +8 -0
- package/build/mnemonic/BIPStandard.js +24 -0
- package/build/mnemonic/Mnemonic.d.ts +7 -2
- package/build/mnemonic/Mnemonic.js +48 -6
- package/build/opnet.d.ts +1 -0
- package/build/opnet.js +1 -0
- package/build/utils/lengths.d.ts +15 -16
- package/build/utils/lengths.js +1 -1
- package/documentation/README.md +32 -0
- package/documentation/quantum-support/01-introduction.md +88 -0
- package/documentation/quantum-support/02-mnemonic-and-wallet.md +457 -0
- package/documentation/quantum-support/03-address-generation.md +329 -0
- package/documentation/quantum-support/04-message-signing.md +623 -0
- package/documentation/quantum-support/05-address-verification.md +307 -0
- package/documentation/quantum-support/README.md +65 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/buffer/BinaryReader.ts +3 -3
- package/src/buffer/BinaryWriter.ts +2 -2
- package/src/deterministic/AddressMap.ts +64 -37
- package/src/deterministic/AddressSet.ts +20 -26
- package/src/deterministic/DeterministicMap.ts +16 -13
- package/src/keypair/Address.ts +136 -0
- package/src/mnemonic/BIPStandard.ts +92 -0
- package/src/mnemonic/Mnemonic.ts +133 -8
- package/src/opnet.ts +1 -0
- package/src/utils/lengths.ts +15 -17
- package/test/derivePath.test.ts +280 -1
- package/browser/src/deterministic/Map.d.ts +0 -15
- package/build/deterministic/Map.d.ts +0 -15
- package/build/deterministic/Map.js +0 -63
- package/doc/README.md +0 -0
- package/src/deterministic/Map.ts +0 -74
- /package/{doc → documentation}/addresses/P2OP.md +0 -0
- /package/{doc → documentation}/addresses/P2WDA.md +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.7.
|
|
1
|
+
export declare const version = "1.7.1";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AddressMap } from '../deterministic/AddressMap.js';
|
|
2
2
|
import { Address } from '../keypair/Address.js';
|
|
3
|
-
import { BufferLike,
|
|
3
|
+
import { BufferLike, Selector, u16, u32, u8 } from '../utils/types.js';
|
|
4
4
|
export declare class BinaryReader {
|
|
5
5
|
private buffer;
|
|
6
6
|
private currentOffset;
|
|
@@ -38,7 +38,7 @@ export declare class BinaryReader {
|
|
|
38
38
|
readAddressValueTuple(be?: boolean): AddressMap<bigint>;
|
|
39
39
|
getOffset(): u16;
|
|
40
40
|
setOffset(offset: u16): void;
|
|
41
|
-
verifyEnd(size:
|
|
41
|
+
verifyEnd(size: number): void;
|
|
42
42
|
private reverseBytes;
|
|
43
43
|
private toHexString;
|
|
44
44
|
}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { i32 } from '../utils/types.js';
|
|
2
1
|
import { Address } from '../keypair/Address.js';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare class AddressMap<V> {
|
|
3
|
+
private items;
|
|
4
|
+
private keyOrder;
|
|
5
|
+
constructor(iterable?: ReadonlyArray<readonly [Address, V]> | null);
|
|
6
|
+
get size(): number;
|
|
5
7
|
set(key: Address, value: V): void;
|
|
6
|
-
indexOf(address: Address): i32;
|
|
7
|
-
has(key: Address): boolean;
|
|
8
8
|
get(key: Address): V | undefined;
|
|
9
|
+
has(key: Address): boolean;
|
|
9
10
|
delete(key: Address): boolean;
|
|
11
|
+
clear(): void;
|
|
12
|
+
indexOf(address: Address): number;
|
|
13
|
+
entries(): IterableIterator<[Address, V]>;
|
|
14
|
+
keys(): IterableIterator<Address>;
|
|
15
|
+
values(): IterableIterator<V>;
|
|
16
|
+
forEach(callback: (value: V, key: Address, map: AddressMap<V>) => void, thisArg?: unknown): void;
|
|
10
17
|
[Symbol.iterator](): IterableIterator<[Address, V]>;
|
|
11
18
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Address } from '../keypair/Address.js';
|
|
2
2
|
export declare class AddressSet {
|
|
3
|
+
private items;
|
|
3
4
|
private keys;
|
|
4
5
|
constructor(keys?: Address[]);
|
|
5
6
|
get size(): number;
|
|
@@ -9,5 +10,5 @@ export declare class AddressSet {
|
|
|
9
10
|
clone(): AddressSet;
|
|
10
11
|
clear(): void;
|
|
11
12
|
combine(set: AddressSet): AddressSet;
|
|
12
|
-
[Symbol.iterator]():
|
|
13
|
+
[Symbol.iterator](): IterableIterator<Address>;
|
|
13
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare class DeterministicMap<K, V> {
|
|
2
2
|
#private;
|
|
3
|
-
private compareFn;
|
|
4
3
|
private map;
|
|
4
|
+
private readonly compareFn;
|
|
5
5
|
constructor(compareFn: (a: K, b: K) => number);
|
|
6
6
|
get size(): number;
|
|
7
7
|
static fromMap<K, V>(map: Map<K, V>, compareFn: (a: K, b: K) => number): DeterministicMap<K, V>;
|
|
@@ -11,6 +11,9 @@ export declare class Address extends Uint8Array {
|
|
|
11
11
|
static fromString(mldsaPublicKey: string, classicPublicKey?: string): Address;
|
|
12
12
|
static wrap(bytes: ArrayLike<number>): Address;
|
|
13
13
|
static uncompressedToCompressed(publicKey: ArrayLike<number>): Buffer;
|
|
14
|
+
static fromBigInt(value: bigint): Address;
|
|
15
|
+
static fromUint64Array(w0: bigint, w1: bigint, w2: bigint, w3: bigint): Address;
|
|
16
|
+
toUint64Array(): [bigint, bigint, bigint, bigint];
|
|
14
17
|
toHex(): string;
|
|
15
18
|
tweakedToHex(): string;
|
|
16
19
|
toBuffer(): Buffer;
|
|
@@ -20,6 +23,7 @@ export declare class Address extends Uint8Array {
|
|
|
20
23
|
toHybridPublicKeyHex(): string;
|
|
21
24
|
toHybridPublicKeyBuffer(): Buffer;
|
|
22
25
|
originalPublicKeyBuffer(): Buffer;
|
|
26
|
+
toBigInt(): bigint;
|
|
23
27
|
equals(a: Address): boolean;
|
|
24
28
|
lessThan(a: Address): boolean;
|
|
25
29
|
greaterThan(a: Address): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare enum BIPStandard {
|
|
2
|
+
BIP44 = 44,
|
|
3
|
+
BIP49 = 49,
|
|
4
|
+
BIP84 = 84,
|
|
5
|
+
BIP86 = 86
|
|
6
|
+
}
|
|
7
|
+
export declare function getBIPDescription(standard: BIPStandard): string;
|
|
8
|
+
export declare function buildBIPPath(standard: BIPStandard, coinType: number, account: number, change: number, addressIndex: number): string;
|
|
@@ -2,6 +2,9 @@ import { BIP32Interface, MLDSASecurityLevel, QuantumBIP32Interface } from '@btc-
|
|
|
2
2
|
import { Network } from '@btc-vision/bitcoin';
|
|
3
3
|
import { Wallet } from '../keypair/Wallet.js';
|
|
4
4
|
import { MnemonicStrength } from './MnemonicStrength.js';
|
|
5
|
+
import { BIPStandard } from './BIPStandard.js';
|
|
6
|
+
import { AddressTypes } from '../keypair/AddressVerificator.js';
|
|
7
|
+
export { BIPStandard, getBIPDescription } from './BIPStandard.js';
|
|
5
8
|
export declare class Mnemonic {
|
|
6
9
|
private readonly _phrase;
|
|
7
10
|
private readonly _passphrase;
|
|
@@ -18,8 +21,10 @@ export declare class Mnemonic {
|
|
|
18
21
|
static generatePhrase(strength?: MnemonicStrength): string;
|
|
19
22
|
static generate(strength?: MnemonicStrength, passphrase?: string, network?: Network, securityLevel?: MLDSASecurityLevel): Mnemonic;
|
|
20
23
|
static validate(phrase: string): boolean;
|
|
21
|
-
derive(index?: number, account?: number, isChange?: boolean): Wallet;
|
|
22
|
-
|
|
24
|
+
derive(index?: number, account?: number, isChange?: boolean, bipStandard?: BIPStandard): Wallet;
|
|
25
|
+
deriveUnisat(addressType?: AddressTypes, index?: number, account?: number, isChange?: boolean): Wallet;
|
|
26
|
+
deriveMultipleUnisat(addressType?: AddressTypes, count?: number, startIndex?: number, account?: number, isChange?: boolean): Wallet[];
|
|
27
|
+
deriveMultiple(count: number, startIndex?: number, account?: number, isChange?: boolean, bipStandard?: BIPStandard): Wallet[];
|
|
23
28
|
deriveCustomPath(classicalPath: string, quantumPath: string): Wallet;
|
|
24
29
|
getClassicalRoot(): BIP32Interface;
|
|
25
30
|
getQuantumRoot(): QuantumBIP32Interface;
|
package/browser/src/opnet.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export * from './keypair/MessageSigner.js';
|
|
|
21
21
|
export * from './keypair/Wallet.js';
|
|
22
22
|
export * from './mnemonic/Mnemonic.js';
|
|
23
23
|
export * from './mnemonic/MnemonicStrength.js';
|
|
24
|
+
export * from './mnemonic/BIPStandard.js';
|
|
24
25
|
export { MLDSASecurityLevel, MLDSAKeyPair, QuantumBIP32Interface, QuantumBIP32API, QuantumSigner, QuantumBIP32Factory, QuantumDerivationPath, } from '@btc-vision/bip32';
|
|
25
26
|
export * from './metadata/ContractBaseMetadata.js';
|
|
26
27
|
export * from './network/ChainId.js';
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const BOOLEAN_BYTE_LENGTH: i32;
|
|
1
|
+
export declare const ADDRESS_BYTE_LENGTH: number;
|
|
2
|
+
export declare const SELECTOR_BYTE_LENGTH: number;
|
|
3
|
+
export declare const U256_BYTE_LENGTH: number;
|
|
4
|
+
export declare const U128_BYTE_LENGTH: number;
|
|
5
|
+
export declare const U64_BYTE_LENGTH: number;
|
|
6
|
+
export declare const U32_BYTE_LENGTH: number;
|
|
7
|
+
export declare const U16_BYTE_LENGTH: number;
|
|
8
|
+
export declare const U8_BYTE_LENGTH: number;
|
|
9
|
+
export declare const I256_BYTE_LENGTH: number;
|
|
10
|
+
export declare const I128_BYTE_LENGTH: number;
|
|
11
|
+
export declare const I64_BYTE_LENGTH: number;
|
|
12
|
+
export declare const number_BYTE_LENGTH: number;
|
|
13
|
+
export declare const I16_BYTE_LENGTH: number;
|
|
14
|
+
export declare const I8_BYTE_LENGTH: number;
|
|
15
|
+
export declare const BOOLEAN_BYTE_LENGTH: number;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.7.
|
|
1
|
+
export declare const version = "1.7.1";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.7.
|
|
1
|
+
export const version = '1.7.1';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AddressMap } from '../deterministic/AddressMap.js';
|
|
2
2
|
import { Address } from '../keypair/Address.js';
|
|
3
|
-
import { BufferLike,
|
|
3
|
+
import { BufferLike, Selector, u16, u32, u8 } from '../utils/types.js';
|
|
4
4
|
export declare class BinaryReader {
|
|
5
5
|
private buffer;
|
|
6
6
|
private currentOffset;
|
|
@@ -38,7 +38,7 @@ export declare class BinaryReader {
|
|
|
38
38
|
readAddressValueTuple(be?: boolean): AddressMap<bigint>;
|
|
39
39
|
getOffset(): u16;
|
|
40
40
|
setOffset(offset: u16): void;
|
|
41
|
-
verifyEnd(size:
|
|
41
|
+
verifyEnd(size: number): void;
|
|
42
42
|
private reverseBytes;
|
|
43
43
|
private toHexString;
|
|
44
44
|
}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { i32 } from '../utils/types.js';
|
|
2
1
|
import { Address } from '../keypair/Address.js';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare class AddressMap<V> {
|
|
3
|
+
private items;
|
|
4
|
+
private keyOrder;
|
|
5
|
+
constructor(iterable?: ReadonlyArray<readonly [Address, V]> | null);
|
|
6
|
+
get size(): number;
|
|
5
7
|
set(key: Address, value: V): void;
|
|
6
|
-
indexOf(address: Address): i32;
|
|
7
|
-
has(key: Address): boolean;
|
|
8
8
|
get(key: Address): V | undefined;
|
|
9
|
+
has(key: Address): boolean;
|
|
9
10
|
delete(key: Address): boolean;
|
|
11
|
+
clear(): void;
|
|
12
|
+
indexOf(address: Address): number;
|
|
13
|
+
entries(): IterableIterator<[Address, V]>;
|
|
14
|
+
keys(): IterableIterator<Address>;
|
|
15
|
+
values(): IterableIterator<V>;
|
|
16
|
+
forEach(callback: (value: V, key: Address, map: AddressMap<V>) => void, thisArg?: unknown): void;
|
|
10
17
|
[Symbol.iterator](): IterableIterator<[Address, V]>;
|
|
11
18
|
}
|
|
@@ -1,51 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export class AddressMap {
|
|
2
|
+
constructor(iterable) {
|
|
3
|
+
this.items = new Map();
|
|
4
|
+
this.keyOrder = [];
|
|
5
|
+
if (iterable) {
|
|
6
|
+
for (const [key, value] of iterable) {
|
|
7
|
+
this.set(key, value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
get size() {
|
|
12
|
+
return this.keyOrder.length;
|
|
13
|
+
}
|
|
3
14
|
set(key, value) {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
this.
|
|
7
|
-
this._values.push(value);
|
|
15
|
+
const keyBigInt = key.toBigInt();
|
|
16
|
+
if (!this.items.has(keyBigInt)) {
|
|
17
|
+
this.keyOrder.push(key);
|
|
8
18
|
}
|
|
9
|
-
|
|
10
|
-
|
|
19
|
+
this.items.set(keyBigInt, value);
|
|
20
|
+
}
|
|
21
|
+
get(key) {
|
|
22
|
+
return this.items.get(key.toBigInt());
|
|
23
|
+
}
|
|
24
|
+
has(key) {
|
|
25
|
+
return this.items.has(key.toBigInt());
|
|
26
|
+
}
|
|
27
|
+
delete(key) {
|
|
28
|
+
const keyBigInt = key.toBigInt();
|
|
29
|
+
if (this.items.delete(keyBigInt)) {
|
|
30
|
+
this.keyOrder = this.keyOrder.filter((k) => k.toBigInt() !== keyBigInt);
|
|
31
|
+
return true;
|
|
11
32
|
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
clear() {
|
|
36
|
+
this.items.clear();
|
|
37
|
+
this.keyOrder = [];
|
|
12
38
|
}
|
|
13
39
|
indexOf(address) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
40
|
+
const addressBigInt = address.toBigInt();
|
|
41
|
+
for (let i = 0; i < this.keyOrder.length; i++) {
|
|
42
|
+
if (this.keyOrder[i].toBigInt() === addressBigInt) {
|
|
17
43
|
return i;
|
|
18
44
|
}
|
|
19
45
|
}
|
|
20
46
|
return -1;
|
|
21
47
|
}
|
|
22
|
-
|
|
23
|
-
for (
|
|
24
|
-
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
48
|
+
*entries() {
|
|
49
|
+
for (const key of this.keyOrder) {
|
|
50
|
+
yield [key, this.items.get(key.toBigInt())];
|
|
27
51
|
}
|
|
28
|
-
return false;
|
|
29
52
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (index == -1) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
return this._values[index];
|
|
53
|
+
*keys() {
|
|
54
|
+
yield* this.keyOrder;
|
|
36
55
|
}
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
return false;
|
|
56
|
+
*values() {
|
|
57
|
+
for (const key of this.keyOrder) {
|
|
58
|
+
yield this.items.get(key.toBigInt());
|
|
41
59
|
}
|
|
42
|
-
this._keys.splice(index, 1);
|
|
43
|
-
this._values.splice(index, 1);
|
|
44
|
-
return true;
|
|
45
60
|
}
|
|
46
|
-
|
|
47
|
-
for (const key of this.
|
|
48
|
-
|
|
61
|
+
forEach(callback, thisArg) {
|
|
62
|
+
for (const key of this.keyOrder) {
|
|
63
|
+
callback.call(thisArg, this.items.get(key.toBigInt()), key, this);
|
|
49
64
|
}
|
|
50
65
|
}
|
|
66
|
+
[Symbol.iterator]() {
|
|
67
|
+
return this.entries();
|
|
68
|
+
}
|
|
51
69
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Address } from '../keypair/Address.js';
|
|
2
2
|
export declare class AddressSet {
|
|
3
|
+
private items;
|
|
3
4
|
private keys;
|
|
4
5
|
constructor(keys?: Address[]);
|
|
5
6
|
get size(): number;
|
|
@@ -9,5 +10,5 @@ export declare class AddressSet {
|
|
|
9
10
|
clone(): AddressSet;
|
|
10
11
|
clear(): void;
|
|
11
12
|
combine(set: AddressSet): AddressSet;
|
|
12
|
-
[Symbol.iterator]():
|
|
13
|
+
[Symbol.iterator](): IterableIterator<Address>;
|
|
13
14
|
}
|
|
@@ -1,49 +1,45 @@
|
|
|
1
1
|
export class AddressSet {
|
|
2
2
|
constructor(keys = []) {
|
|
3
|
-
this.
|
|
3
|
+
this.items = new Set();
|
|
4
|
+
this.keys = [];
|
|
5
|
+
for (const key of keys) {
|
|
6
|
+
this.add(key);
|
|
7
|
+
}
|
|
4
8
|
}
|
|
5
9
|
get size() {
|
|
6
10
|
return this.keys.length;
|
|
7
11
|
}
|
|
8
12
|
add(address) {
|
|
9
|
-
|
|
13
|
+
const addressBigInt = address.toBigInt();
|
|
14
|
+
if (!this.items.has(addressBigInt)) {
|
|
15
|
+
this.items.add(addressBigInt);
|
|
10
16
|
this.keys.push(address);
|
|
11
17
|
}
|
|
12
18
|
}
|
|
13
19
|
has(address) {
|
|
14
|
-
|
|
15
|
-
if (this.keys[i].equals(address)) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
20
|
+
return this.items.has(address.toBigInt());
|
|
20
21
|
}
|
|
21
22
|
remove(address) {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
this.keys.
|
|
23
|
+
const addressBigInt = address.toBigInt();
|
|
24
|
+
if (this.items.delete(addressBigInt)) {
|
|
25
|
+
this.keys = this.keys.filter((k) => k.toBigInt() !== addressBigInt);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
clone() {
|
|
28
|
-
|
|
29
|
-
for (let i = 0; i < this.keys.length; i++) {
|
|
30
|
-
clone.add(this.keys[i]);
|
|
31
|
-
}
|
|
32
|
-
return clone;
|
|
29
|
+
return new AddressSet(this.keys);
|
|
33
30
|
}
|
|
34
31
|
clear() {
|
|
32
|
+
this.items.clear();
|
|
35
33
|
this.keys = [];
|
|
36
34
|
}
|
|
37
35
|
combine(set) {
|
|
38
36
|
const clone = this.clone();
|
|
39
|
-
for (
|
|
40
|
-
clone.add(
|
|
37
|
+
for (const key of set.keys) {
|
|
38
|
+
clone.add(key);
|
|
41
39
|
}
|
|
42
40
|
return clone;
|
|
43
41
|
}
|
|
44
42
|
*[Symbol.iterator]() {
|
|
45
|
-
|
|
46
|
-
yield this.keys[i];
|
|
47
|
-
}
|
|
43
|
+
yield* this.keys;
|
|
48
44
|
}
|
|
49
45
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare class DeterministicMap<K, V> {
|
|
2
2
|
#private;
|
|
3
|
-
private compareFn;
|
|
4
3
|
private map;
|
|
4
|
+
private readonly compareFn;
|
|
5
5
|
constructor(compareFn: (a: K, b: K) => number);
|
|
6
6
|
get size(): number;
|
|
7
7
|
static fromMap<K, V>(map: Map<K, V>, compareFn: (a: K, b: K) => number): DeterministicMap<K, V>;
|
|
@@ -9,13 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
12
|
+
var _DeterministicMap_keyOrder;
|
|
13
13
|
export class DeterministicMap {
|
|
14
14
|
constructor(compareFn) {
|
|
15
|
-
this
|
|
16
|
-
_DeterministicMap_keys.set(this, void 0);
|
|
15
|
+
_DeterministicMap_keyOrder.set(this, void 0);
|
|
17
16
|
this.map = new Map();
|
|
18
|
-
__classPrivateFieldSet(this,
|
|
17
|
+
__classPrivateFieldSet(this, _DeterministicMap_keyOrder, [], "f");
|
|
18
|
+
this.compareFn = compareFn;
|
|
19
19
|
}
|
|
20
20
|
get size() {
|
|
21
21
|
return this.map.size;
|
|
@@ -29,8 +29,8 @@ export class DeterministicMap {
|
|
|
29
29
|
}
|
|
30
30
|
set(key, value) {
|
|
31
31
|
if (!this.map.has(key)) {
|
|
32
|
-
__classPrivateFieldGet(this,
|
|
33
|
-
__classPrivateFieldGet(this,
|
|
32
|
+
__classPrivateFieldGet(this, _DeterministicMap_keyOrder, "f").push(key);
|
|
33
|
+
__classPrivateFieldGet(this, _DeterministicMap_keyOrder, "f").sort(this.compareFn);
|
|
34
34
|
}
|
|
35
35
|
this.map.set(key, value);
|
|
36
36
|
}
|
|
@@ -38,14 +38,14 @@ export class DeterministicMap {
|
|
|
38
38
|
return this.map.get(key);
|
|
39
39
|
}
|
|
40
40
|
keys() {
|
|
41
|
-
return __classPrivateFieldGet(this,
|
|
41
|
+
return __classPrivateFieldGet(this, _DeterministicMap_keyOrder, "f").values();
|
|
42
42
|
}
|
|
43
43
|
values() {
|
|
44
44
|
const values = [];
|
|
45
|
-
for (let i = 0; i < __classPrivateFieldGet(this,
|
|
46
|
-
const key = __classPrivateFieldGet(this,
|
|
45
|
+
for (let i = 0; i < __classPrivateFieldGet(this, _DeterministicMap_keyOrder, "f").length; i++) {
|
|
46
|
+
const key = __classPrivateFieldGet(this, _DeterministicMap_keyOrder, "f")[i];
|
|
47
47
|
const value = this.map.get(key);
|
|
48
|
-
if (value) {
|
|
48
|
+
if (value !== undefined) {
|
|
49
49
|
values.push(value);
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
@@ -60,23 +60,23 @@ export class DeterministicMap {
|
|
|
60
60
|
delete(key) {
|
|
61
61
|
if (this.map.has(key)) {
|
|
62
62
|
this.map.delete(key);
|
|
63
|
-
__classPrivateFieldSet(this,
|
|
63
|
+
__classPrivateFieldSet(this, _DeterministicMap_keyOrder, __classPrivateFieldGet(this, _DeterministicMap_keyOrder, "f").filter((k) => k !== key), "f");
|
|
64
64
|
return true;
|
|
65
65
|
}
|
|
66
66
|
return false;
|
|
67
67
|
}
|
|
68
68
|
clear() {
|
|
69
69
|
this.map.clear();
|
|
70
|
-
__classPrivateFieldSet(this,
|
|
70
|
+
__classPrivateFieldSet(this, _DeterministicMap_keyOrder, [], "f");
|
|
71
71
|
}
|
|
72
72
|
forEach(callback) {
|
|
73
|
-
for (const key of __classPrivateFieldGet(this,
|
|
73
|
+
for (const key of __classPrivateFieldGet(this, _DeterministicMap_keyOrder, "f")) {
|
|
74
74
|
const value = this.map.get(key);
|
|
75
75
|
callback(value, key, this);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
*[(
|
|
79
|
-
for (const key of __classPrivateFieldGet(this,
|
|
78
|
+
*[(_DeterministicMap_keyOrder = new WeakMap(), Symbol.iterator)]() {
|
|
79
|
+
for (const key of __classPrivateFieldGet(this, _DeterministicMap_keyOrder, "f")) {
|
|
80
80
|
yield [key, this.map.get(key)];
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -11,6 +11,9 @@ export declare class Address extends Uint8Array {
|
|
|
11
11
|
static fromString(mldsaPublicKey: string, classicPublicKey?: string): Address;
|
|
12
12
|
static wrap(bytes: ArrayLike<number>): Address;
|
|
13
13
|
static uncompressedToCompressed(publicKey: ArrayLike<number>): Buffer;
|
|
14
|
+
static fromBigInt(value: bigint): Address;
|
|
15
|
+
static fromUint64Array(w0: bigint, w1: bigint, w2: bigint, w3: bigint): Address;
|
|
16
|
+
toUint64Array(): [bigint, bigint, bigint, bigint];
|
|
14
17
|
toHex(): string;
|
|
15
18
|
tweakedToHex(): string;
|
|
16
19
|
toBuffer(): Buffer;
|
|
@@ -20,6 +23,7 @@ export declare class Address extends Uint8Array {
|
|
|
20
23
|
toHybridPublicKeyHex(): string;
|
|
21
24
|
toHybridPublicKeyBuffer(): Buffer;
|
|
22
25
|
originalPublicKeyBuffer(): Buffer;
|
|
26
|
+
toBigInt(): bigint;
|
|
23
27
|
equals(a: Address): boolean;
|
|
24
28
|
lessThan(a: Address): boolean;
|
|
25
29
|
greaterThan(a: Address): boolean;
|
package/build/keypair/Address.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _Address_p2tr, _Address_p2op, _Address_network, _Address_originalPublicKey, _Address_keyPair, _Address_uncompressed, _Address_tweakedUncompressed, _Address_p2wda, _Address_mldsaPublicKey;
|
|
12
|
+
var _Address_p2tr, _Address_p2op, _Address_network, _Address_originalPublicKey, _Address_keyPair, _Address_uncompressed, _Address_tweakedUncompressed, _Address_p2wda, _Address_mldsaPublicKey, _Address_cachedBigInt, _Address_cachedUint64Array;
|
|
13
13
|
import { decompressPublicKey, toXOnly } from '@btc-vision/bitcoin';
|
|
14
14
|
import { ADDRESS_BYTE_LENGTH } from '../utils/lengths.js';
|
|
15
15
|
import { AddressVerificator } from './AddressVerificator.js';
|
|
@@ -31,6 +31,8 @@ export class Address extends Uint8Array {
|
|
|
31
31
|
_Address_tweakedUncompressed.set(this, void 0);
|
|
32
32
|
_Address_p2wda.set(this, void 0);
|
|
33
33
|
_Address_mldsaPublicKey.set(this, void 0);
|
|
34
|
+
_Address_cachedBigInt.set(this, void 0);
|
|
35
|
+
_Address_cachedUint64Array.set(this, void 0);
|
|
34
36
|
if (!mldsaPublicKey) {
|
|
35
37
|
return;
|
|
36
38
|
}
|
|
@@ -89,6 +91,37 @@ export class Address extends Uint8Array {
|
|
|
89
91
|
compressed.set(x, 1);
|
|
90
92
|
return compressed;
|
|
91
93
|
}
|
|
94
|
+
static fromBigInt(value) {
|
|
95
|
+
const buffer = new Uint8Array(32);
|
|
96
|
+
const view = new DataView(buffer.buffer);
|
|
97
|
+
view.setBigUint64(0, (value >> 192n) & 0xffffffffffffffffn, false);
|
|
98
|
+
view.setBigUint64(8, (value >> 128n) & 0xffffffffffffffffn, false);
|
|
99
|
+
view.setBigUint64(16, (value >> 64n) & 0xffffffffffffffffn, false);
|
|
100
|
+
view.setBigUint64(24, value & 0xffffffffffffffffn, false);
|
|
101
|
+
return new Address(buffer);
|
|
102
|
+
}
|
|
103
|
+
static fromUint64Array(w0, w1, w2, w3) {
|
|
104
|
+
const buffer = new Uint8Array(32);
|
|
105
|
+
const view = new DataView(buffer.buffer);
|
|
106
|
+
view.setBigUint64(0, w0, false);
|
|
107
|
+
view.setBigUint64(8, w1, false);
|
|
108
|
+
view.setBigUint64(16, w2, false);
|
|
109
|
+
view.setBigUint64(24, w3, false);
|
|
110
|
+
return new Address(buffer);
|
|
111
|
+
}
|
|
112
|
+
toUint64Array() {
|
|
113
|
+
if (__classPrivateFieldGet(this, _Address_cachedUint64Array, "f") !== undefined) {
|
|
114
|
+
return __classPrivateFieldGet(this, _Address_cachedUint64Array, "f");
|
|
115
|
+
}
|
|
116
|
+
const view = new DataView(this.buffer, this.byteOffset, 32);
|
|
117
|
+
__classPrivateFieldSet(this, _Address_cachedUint64Array, [
|
|
118
|
+
view.getBigUint64(0, false),
|
|
119
|
+
view.getBigUint64(8, false),
|
|
120
|
+
view.getBigUint64(16, false),
|
|
121
|
+
view.getBigUint64(24, false),
|
|
122
|
+
], "f");
|
|
123
|
+
return __classPrivateFieldGet(this, _Address_cachedUint64Array, "f");
|
|
124
|
+
}
|
|
92
125
|
toHex() {
|
|
93
126
|
return '0x' + Buffer.from(this).toString('hex');
|
|
94
127
|
}
|
|
@@ -137,6 +170,17 @@ export class Address extends Uint8Array {
|
|
|
137
170
|
}
|
|
138
171
|
return Buffer.from(__classPrivateFieldGet(this, _Address_originalPublicKey, "f"));
|
|
139
172
|
}
|
|
173
|
+
toBigInt() {
|
|
174
|
+
if (__classPrivateFieldGet(this, _Address_cachedBigInt, "f") !== undefined) {
|
|
175
|
+
return __classPrivateFieldGet(this, _Address_cachedBigInt, "f");
|
|
176
|
+
}
|
|
177
|
+
const view = new DataView(this.buffer, this.byteOffset, 32);
|
|
178
|
+
__classPrivateFieldSet(this, _Address_cachedBigInt, (view.getBigUint64(0, false) << 192n) |
|
|
179
|
+
(view.getBigUint64(8, false) << 128n) |
|
|
180
|
+
(view.getBigUint64(16, false) << 64n) |
|
|
181
|
+
view.getBigUint64(24, false), "f");
|
|
182
|
+
return __classPrivateFieldGet(this, _Address_cachedBigInt, "f");
|
|
183
|
+
}
|
|
140
184
|
equals(a) {
|
|
141
185
|
const b = this;
|
|
142
186
|
if (a.length !== b.length) {
|
|
@@ -322,4 +366,4 @@ export class Address extends Uint8Array {
|
|
|
322
366
|
this.classicPublicKey.set(tweakedBytes);
|
|
323
367
|
}
|
|
324
368
|
}
|
|
325
|
-
_Address_p2tr = new WeakMap(), _Address_p2op = new WeakMap(), _Address_network = new WeakMap(), _Address_originalPublicKey = new WeakMap(), _Address_keyPair = new WeakMap(), _Address_uncompressed = new WeakMap(), _Address_tweakedUncompressed = new WeakMap(), _Address_p2wda = new WeakMap(), _Address_mldsaPublicKey = new WeakMap();
|
|
369
|
+
_Address_p2tr = new WeakMap(), _Address_p2op = new WeakMap(), _Address_network = new WeakMap(), _Address_originalPublicKey = new WeakMap(), _Address_keyPair = new WeakMap(), _Address_uncompressed = new WeakMap(), _Address_tweakedUncompressed = new WeakMap(), _Address_p2wda = new WeakMap(), _Address_mldsaPublicKey = new WeakMap(), _Address_cachedBigInt = new WeakMap(), _Address_cachedUint64Array = new WeakMap();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare enum BIPStandard {
|
|
2
|
+
BIP44 = 44,
|
|
3
|
+
BIP49 = 49,
|
|
4
|
+
BIP84 = 84,
|
|
5
|
+
BIP86 = 86
|
|
6
|
+
}
|
|
7
|
+
export declare function getBIPDescription(standard: BIPStandard): string;
|
|
8
|
+
export declare function buildBIPPath(standard: BIPStandard, coinType: number, account: number, change: number, addressIndex: number): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export var BIPStandard;
|
|
2
|
+
(function (BIPStandard) {
|
|
3
|
+
BIPStandard[BIPStandard["BIP44"] = 44] = "BIP44";
|
|
4
|
+
BIPStandard[BIPStandard["BIP49"] = 49] = "BIP49";
|
|
5
|
+
BIPStandard[BIPStandard["BIP84"] = 84] = "BIP84";
|
|
6
|
+
BIPStandard[BIPStandard["BIP86"] = 86] = "BIP86";
|
|
7
|
+
})(BIPStandard || (BIPStandard = {}));
|
|
8
|
+
export function getBIPDescription(standard) {
|
|
9
|
+
switch (standard) {
|
|
10
|
+
case BIPStandard.BIP44:
|
|
11
|
+
return 'BIP44: Legacy addresses (P2PKH), widely used by Unisat and other wallets';
|
|
12
|
+
case BIPStandard.BIP49:
|
|
13
|
+
return 'BIP49: Wrapped SegWit addresses (P2SH-P2WPKH)';
|
|
14
|
+
case BIPStandard.BIP84:
|
|
15
|
+
return 'BIP84: Native SegWit addresses (P2WPKH) - DEFAULT';
|
|
16
|
+
case BIPStandard.BIP86:
|
|
17
|
+
return 'BIP86: Taproot addresses (P2TR)';
|
|
18
|
+
default:
|
|
19
|
+
return 'Unknown BIP standard';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function buildBIPPath(standard, coinType, account, change, addressIndex) {
|
|
23
|
+
return `m/${standard}'/${coinType}'/${account}'/${change}/${addressIndex}`;
|
|
24
|
+
}
|
|
@@ -2,6 +2,9 @@ import { BIP32Interface, MLDSASecurityLevel, QuantumBIP32Interface } from '@btc-
|
|
|
2
2
|
import { Network } from '@btc-vision/bitcoin';
|
|
3
3
|
import { Wallet } from '../keypair/Wallet.js';
|
|
4
4
|
import { MnemonicStrength } from './MnemonicStrength.js';
|
|
5
|
+
import { BIPStandard } from './BIPStandard.js';
|
|
6
|
+
import { AddressTypes } from '../keypair/AddressVerificator.js';
|
|
7
|
+
export { BIPStandard, getBIPDescription } from './BIPStandard.js';
|
|
5
8
|
export declare class Mnemonic {
|
|
6
9
|
private readonly _phrase;
|
|
7
10
|
private readonly _passphrase;
|
|
@@ -18,8 +21,10 @@ export declare class Mnemonic {
|
|
|
18
21
|
static generatePhrase(strength?: MnemonicStrength): string;
|
|
19
22
|
static generate(strength?: MnemonicStrength, passphrase?: string, network?: Network, securityLevel?: MLDSASecurityLevel): Mnemonic;
|
|
20
23
|
static validate(phrase: string): boolean;
|
|
21
|
-
derive(index?: number, account?: number, isChange?: boolean): Wallet;
|
|
22
|
-
|
|
24
|
+
derive(index?: number, account?: number, isChange?: boolean, bipStandard?: BIPStandard): Wallet;
|
|
25
|
+
deriveUnisat(addressType?: AddressTypes, index?: number, account?: number, isChange?: boolean): Wallet;
|
|
26
|
+
deriveMultipleUnisat(addressType?: AddressTypes, count?: number, startIndex?: number, account?: number, isChange?: boolean): Wallet[];
|
|
27
|
+
deriveMultiple(count: number, startIndex?: number, account?: number, isChange?: boolean, bipStandard?: BIPStandard): Wallet[];
|
|
23
28
|
deriveCustomPath(classicalPath: string, quantumPath: string): Wallet;
|
|
24
29
|
getClassicalRoot(): BIP32Interface;
|
|
25
30
|
getQuantumRoot(): QuantumBIP32Interface;
|