@btc-vision/transaction 1.7.1 → 1.7.3

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.
Files changed (35) hide show
  1. package/browser/index.js +1 -1
  2. package/browser/src/buffer/BinaryReader.d.ts +2 -2
  3. package/browser/src/deterministic/AddressMap.d.ts +12 -5
  4. package/browser/src/deterministic/AddressSet.d.ts +2 -1
  5. package/browser/src/deterministic/DeterministicMap.d.ts +2 -0
  6. package/browser/src/deterministic/Map.d.ts +4 -3
  7. package/browser/src/keypair/Address.d.ts +4 -0
  8. package/browser/src/opnet.d.ts +1 -0
  9. package/browser/src/utils/lengths.d.ts +15 -16
  10. package/build/buffer/BinaryReader.d.ts +2 -2
  11. package/build/deterministic/AddressMap.d.ts +12 -5
  12. package/build/deterministic/AddressMap.js +52 -30
  13. package/build/deterministic/AddressSet.d.ts +2 -1
  14. package/build/deterministic/AddressSet.js +17 -21
  15. package/build/deterministic/DeterministicMap.d.ts +2 -0
  16. package/build/deterministic/DeterministicMap.js +12 -11
  17. package/build/deterministic/Map.d.ts +4 -3
  18. package/build/deterministic/Map.js +11 -8
  19. package/build/keypair/Address.d.ts +4 -0
  20. package/build/keypair/Address.js +46 -2
  21. package/build/opnet.d.ts +1 -0
  22. package/build/opnet.js +1 -0
  23. package/build/utils/lengths.d.ts +15 -16
  24. package/build/utils/lengths.js +1 -1
  25. package/documentation/quantum-support/02-mnemonic-and-wallet.md +22 -10
  26. package/package.json +1 -1
  27. package/src/buffer/BinaryReader.ts +3 -3
  28. package/src/buffer/BinaryWriter.ts +2 -2
  29. package/src/deterministic/AddressMap.ts +66 -35
  30. package/src/deterministic/AddressSet.ts +20 -26
  31. package/src/deterministic/DeterministicMap.ts +14 -12
  32. package/src/deterministic/Map.ts +12 -8
  33. package/src/keypair/Address.ts +136 -0
  34. package/src/opnet.ts +2 -0
  35. package/src/utils/lengths.ts +15 -17
@@ -1,6 +1,6 @@
1
1
  import { AddressMap } from '../deterministic/AddressMap.js';
2
2
  import { Address } from '../keypair/Address.js';
3
- import { BufferLike, i32, Selector, u16, u32, u8 } from '../utils/types.js';
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: i32): void;
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
- import { Map } from './Map.js';
4
- export declare class AddressMap<V> extends Map<Address, V> {
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](): Generator<Address, void, unknown>;
13
+ [Symbol.iterator](): IterableIterator<Address>;
13
14
  }
@@ -1,3 +1,4 @@
1
+ import { Map } from './Map.js';
1
2
  export declare class DeterministicMap<K, V> {
2
3
  #private;
3
4
  private compareFn;
@@ -7,6 +8,7 @@ export declare class DeterministicMap<K, V> {
7
8
  static fromMap<K, V>(map: Map<K, V>, compareFn: (a: K, b: K) => number): DeterministicMap<K, V>;
8
9
  set(key: K, value: V): void;
9
10
  get(key: K): V | undefined;
11
+ entries(): IterableIterator<[K, V]>;
10
12
  keys(): IterableIterator<K>;
11
13
  values(): IterableIterator<V>;
12
14
  has(key: K): boolean;
@@ -3,13 +3,14 @@ export declare class Map<K, V> {
3
3
  protected _keys: K[];
4
4
  protected _values: V[];
5
5
  get size(): i32;
6
- keys(): K[];
7
- values(): V[];
8
- entries(): [K, V][];
6
+ keys(): IterableIterator<K>;
7
+ values(): IterableIterator<V>;
8
+ entries(): IterableIterator<[K, V]>;
9
9
  set(key: K, value: V): void;
10
10
  indexOf(key: K): i32;
11
11
  get(key: K): V | undefined;
12
12
  has(key: K): boolean;
13
13
  delete(key: K): boolean;
14
14
  clear(): void;
15
+ [Symbol.iterator](): IterableIterator<[K, V]>;
15
16
  }
@@ -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;
@@ -75,6 +75,7 @@ export * from './metadata/tokens.js';
75
75
  export * from './transaction/browser/Web3Provider.js';
76
76
  export * from './keypair/Secp256k1PointDeriver.js';
77
77
  export * from './transaction/ContractAddress.js';
78
+ export * from './deterministic/Map.js';
78
79
  declare global {
79
80
  interface Window {
80
81
  unisat?: Unisat;
@@ -1,16 +1,15 @@
1
- import { i32 } from './types';
2
- export declare const ADDRESS_BYTE_LENGTH: i32;
3
- export declare const SELECTOR_BYTE_LENGTH: i32;
4
- export declare const U256_BYTE_LENGTH: i32;
5
- export declare const U128_BYTE_LENGTH: i32;
6
- export declare const U64_BYTE_LENGTH: i32;
7
- export declare const U32_BYTE_LENGTH: i32;
8
- export declare const U16_BYTE_LENGTH: i32;
9
- export declare const U8_BYTE_LENGTH: i32;
10
- export declare const I256_BYTE_LENGTH: i32;
11
- export declare const I128_BYTE_LENGTH: i32;
12
- export declare const I64_BYTE_LENGTH: i32;
13
- export declare const I32_BYTE_LENGTH: i32;
14
- export declare const I16_BYTE_LENGTH: i32;
15
- export declare const I8_BYTE_LENGTH: i32;
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;
@@ -1,6 +1,6 @@
1
1
  import { AddressMap } from '../deterministic/AddressMap.js';
2
2
  import { Address } from '../keypair/Address.js';
3
- import { BufferLike, i32, Selector, u16, u32, u8 } from '../utils/types.js';
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: i32): void;
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
- import { Map } from './Map.js';
4
- export declare class AddressMap<V> extends Map<Address, V> {
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,73 @@
1
1
  import { Map } from './Map.js';
2
- export class AddressMap extends Map {
2
+ export class AddressMap {
3
+ constructor(iterable) {
4
+ this.items = new Map();
5
+ this.keyOrder = [];
6
+ if (iterable) {
7
+ for (const [key, value] of iterable) {
8
+ this.set(key, value);
9
+ }
10
+ }
11
+ }
12
+ get size() {
13
+ return this.keyOrder.length;
14
+ }
3
15
  set(key, value) {
4
- const index = this.indexOf(key);
5
- if (index == -1) {
6
- this._keys.push(key);
7
- this._values.push(value);
16
+ const keyBigInt = key.toBigInt();
17
+ if (!this.items.has(keyBigInt)) {
18
+ this.keyOrder.push(key);
8
19
  }
9
- else {
10
- this._values[index] = value;
20
+ this.items.set(keyBigInt, value);
21
+ }
22
+ get(key) {
23
+ return this.items.get(key.toBigInt());
24
+ }
25
+ has(key) {
26
+ return this.items.has(key.toBigInt());
27
+ }
28
+ delete(key) {
29
+ const keyBigInt = key.toBigInt();
30
+ if (this.items.delete(keyBigInt)) {
31
+ this.keyOrder = this.keyOrder.filter((k) => k.toBigInt() !== keyBigInt);
32
+ return true;
11
33
  }
34
+ return false;
35
+ }
36
+ clear() {
37
+ this.items.clear();
38
+ this.keyOrder = [];
12
39
  }
13
40
  indexOf(address) {
14
- for (let i = 0; i < this._keys.length; i++) {
15
- const key = this._keys[i];
16
- if (address.equals(key)) {
41
+ const addressBigInt = address.toBigInt();
42
+ for (let i = 0; i < this.keyOrder.length; i++) {
43
+ if (this.keyOrder[i].toBigInt() === addressBigInt) {
17
44
  return i;
18
45
  }
19
46
  }
20
47
  return -1;
21
48
  }
22
- has(key) {
23
- for (let i = 0; i < this._keys.length; i++) {
24
- if (key.equals(this._keys[i])) {
25
- return true;
26
- }
49
+ *entries() {
50
+ for (const key of this.keyOrder) {
51
+ yield [key, this.items.get(key.toBigInt())];
27
52
  }
28
- return false;
29
53
  }
30
- get(key) {
31
- const index = this.indexOf(key);
32
- if (index == -1) {
33
- return;
54
+ *keys() {
55
+ yield* this.keyOrder;
56
+ }
57
+ *values() {
58
+ for (const key of this.keyOrder) {
59
+ yield this.items.get(key.toBigInt());
34
60
  }
35
- return this._values[index];
36
61
  }
37
- delete(key) {
38
- const index = this.indexOf(key);
39
- if (index == -1) {
40
- return false;
62
+ forEach(callback, thisArg) {
63
+ for (const key of this.keyOrder) {
64
+ callback.call(thisArg, this.items.get(key.toBigInt()), key, this);
41
65
  }
42
- this._keys.splice(index, 1);
43
- this._values.splice(index, 1);
44
- return true;
45
66
  }
46
67
  *[Symbol.iterator]() {
47
- for (const key of this._keys) {
48
- yield [key, this.get(key)];
68
+ for (let i = 0; i < this.keyOrder.length; i++) {
69
+ const key = this.keyOrder[i];
70
+ yield [key, this.items.get(key.toBigInt())];
49
71
  }
50
72
  }
51
73
  }
@@ -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](): Generator<Address, void, unknown>;
13
+ [Symbol.iterator](): IterableIterator<Address>;
13
14
  }
@@ -1,49 +1,45 @@
1
1
  export class AddressSet {
2
2
  constructor(keys = []) {
3
- this.keys = keys;
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
- if (!this.has(address)) {
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
- for (let i = 0; i < this.keys.length; i++) {
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 index = this.keys.findIndex((key) => key.equals(address));
23
- if (index !== -1) {
24
- this.keys.splice(index, 1);
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
- const clone = new AddressSet();
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 (let i = 0; i < set.keys.length; i++) {
40
- clone.add(set.keys[i]);
37
+ for (const key of set.keys) {
38
+ clone.add(key);
41
39
  }
42
40
  return clone;
43
41
  }
44
42
  *[Symbol.iterator]() {
45
- for (let i = 0; i < this.keys.length; i++) {
46
- yield this.keys[i];
47
- }
43
+ yield* this.keys;
48
44
  }
49
45
  }
@@ -1,3 +1,4 @@
1
+ import { Map } from './Map.js';
1
2
  export declare class DeterministicMap<K, V> {
2
3
  #private;
3
4
  private compareFn;
@@ -7,6 +8,7 @@ export declare class DeterministicMap<K, V> {
7
8
  static fromMap<K, V>(map: Map<K, V>, compareFn: (a: K, b: K) => number): DeterministicMap<K, V>;
8
9
  set(key: K, value: V): void;
9
10
  get(key: K): V | undefined;
11
+ entries(): IterableIterator<[K, V]>;
10
12
  keys(): IterableIterator<K>;
11
13
  values(): IterableIterator<V>;
12
14
  has(key: K): boolean;
@@ -10,6 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _DeterministicMap_keys;
13
+ import { Map } from './Map.js';
13
14
  export class DeterministicMap {
14
15
  constructor(compareFn) {
15
16
  this.compareFn = compareFn;
@@ -37,22 +38,22 @@ export class DeterministicMap {
37
38
  get(key) {
38
39
  return this.map.get(key);
39
40
  }
40
- keys() {
41
- return __classPrivateFieldGet(this, _DeterministicMap_keys, "f").values();
41
+ *entries() {
42
+ for (const key of __classPrivateFieldGet(this, _DeterministicMap_keys, "f")) {
43
+ yield [key, this.map.get(key)];
44
+ }
42
45
  }
43
- values() {
44
- const values = [];
45
- for (let i = 0; i < __classPrivateFieldGet(this, _DeterministicMap_keys, "f").length; i++) {
46
- const key = __classPrivateFieldGet(this, _DeterministicMap_keys, "f")[i];
46
+ *keys() {
47
+ yield* __classPrivateFieldGet(this, _DeterministicMap_keys, "f");
48
+ }
49
+ *values() {
50
+ for (const key of __classPrivateFieldGet(this, _DeterministicMap_keys, "f")) {
47
51
  const value = this.map.get(key);
48
- if (value) {
49
- values.push(value);
50
- }
51
- else {
52
+ if (value === undefined && !this.map.has(key)) {
52
53
  throw new Error('Value not found');
53
54
  }
55
+ yield value;
54
56
  }
55
- return values.values();
56
57
  }
57
58
  has(key) {
58
59
  return this.map.has(key);
@@ -3,13 +3,14 @@ export declare class Map<K, V> {
3
3
  protected _keys: K[];
4
4
  protected _values: V[];
5
5
  get size(): i32;
6
- keys(): K[];
7
- values(): V[];
8
- entries(): [K, V][];
6
+ keys(): IterableIterator<K>;
7
+ values(): IterableIterator<V>;
8
+ entries(): IterableIterator<[K, V]>;
9
9
  set(key: K, value: V): void;
10
10
  indexOf(key: K): i32;
11
11
  get(key: K): V | undefined;
12
12
  has(key: K): boolean;
13
13
  delete(key: K): boolean;
14
14
  clear(): void;
15
+ [Symbol.iterator](): IterableIterator<[K, V]>;
15
16
  }
@@ -6,18 +6,16 @@ export class Map {
6
6
  get size() {
7
7
  return this._keys.length;
8
8
  }
9
- keys() {
10
- return this._keys;
9
+ *keys() {
10
+ yield* this._keys;
11
11
  }
12
- values() {
13
- return this._values;
12
+ *values() {
13
+ yield* this._values;
14
14
  }
15
- entries() {
16
- const result = [];
15
+ *entries() {
17
16
  for (let i = 0; i < this._keys.length; i++) {
18
- result.push([this._keys[i], this._values[i]]);
17
+ yield [this._keys[i], this._values[i]];
19
18
  }
20
- return result;
21
19
  }
22
20
  set(key, value) {
23
21
  const index = this.indexOf(key);
@@ -60,4 +58,9 @@ export class Map {
60
58
  this._keys = [];
61
59
  this._values = [];
62
60
  }
61
+ *[Symbol.iterator]() {
62
+ for (let i = 0; i < this._keys.length; i++) {
63
+ yield [this._keys[i], this._values[i]];
64
+ }
65
+ }
63
66
  }
@@ -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;
@@ -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();
package/build/opnet.d.ts CHANGED
@@ -75,6 +75,7 @@ export * from './metadata/tokens.js';
75
75
  export * from './transaction/browser/Web3Provider.js';
76
76
  export * from './keypair/Secp256k1PointDeriver.js';
77
77
  export * from './transaction/ContractAddress.js';
78
+ export * from './deterministic/Map.js';
78
79
  declare global {
79
80
  interface Window {
80
81
  unisat?: Unisat;
package/build/opnet.js CHANGED
@@ -74,3 +74,4 @@ export * from './metadata/tokens.js';
74
74
  export * from './transaction/browser/Web3Provider.js';
75
75
  export * from './keypair/Secp256k1PointDeriver.js';
76
76
  export * from './transaction/ContractAddress.js';
77
+ export * from './deterministic/Map.js';
@@ -1,16 +1,15 @@
1
- import { i32 } from './types';
2
- export declare const ADDRESS_BYTE_LENGTH: i32;
3
- export declare const SELECTOR_BYTE_LENGTH: i32;
4
- export declare const U256_BYTE_LENGTH: i32;
5
- export declare const U128_BYTE_LENGTH: i32;
6
- export declare const U64_BYTE_LENGTH: i32;
7
- export declare const U32_BYTE_LENGTH: i32;
8
- export declare const U16_BYTE_LENGTH: i32;
9
- export declare const U8_BYTE_LENGTH: i32;
10
- export declare const I256_BYTE_LENGTH: i32;
11
- export declare const I128_BYTE_LENGTH: i32;
12
- export declare const I64_BYTE_LENGTH: i32;
13
- export declare const I32_BYTE_LENGTH: i32;
14
- export declare const I16_BYTE_LENGTH: i32;
15
- export declare const I8_BYTE_LENGTH: i32;
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;
@@ -9,7 +9,7 @@ export const U8_BYTE_LENGTH = 1;
9
9
  export const I256_BYTE_LENGTH = 32;
10
10
  export const I128_BYTE_LENGTH = 16;
11
11
  export const I64_BYTE_LENGTH = 8;
12
- export const I32_BYTE_LENGTH = 4;
12
+ export const number_BYTE_LENGTH = 4;
13
13
  export const I16_BYTE_LENGTH = 2;
14
14
  export const I8_BYTE_LENGTH = 1;
15
15
  export const BOOLEAN_BYTE_LENGTH = 1;