@btc-vision/transaction 1.0.114 → 1.0.116

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.
@@ -11,8 +11,8 @@ export declare class Address extends Uint8Array {
11
11
  static wrap(bytes: ArrayLike<number>): Address;
12
12
  toHex(): string;
13
13
  equals(a: Address): boolean;
14
- isBiggerThan(a: Address): boolean;
15
- isSmallerThan(a: Address): boolean;
14
+ lessThan(a: Address): boolean;
15
+ greaterThan(a: Address): boolean;
16
16
  set(publicKey: ArrayLike<number>): void;
17
17
  isValid(network: Network): boolean;
18
18
  p2wpkh(network: Network): string;
@@ -4,6 +4,7 @@ export type MemorySlotPointer = bigint;
4
4
  export type BufferLike = Uint8Array | Buffer;
5
5
  export type MemorySlotData<T> = T;
6
6
  export type PointerStorage = DeterministicMap<MemorySlotPointer, MemorySlotData<bigint>>;
7
+ export type BlockchainStorage = DeterministicMap<string, PointerStorage>;
7
8
  export type i32 = number;
8
9
  export type u8 = number;
9
10
  export type u16 = number;
@@ -1 +1 @@
1
- export declare const version = "1.0.114";
1
+ export declare const version = "1.0.116";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.114';
1
+ export const version = '1.0.116';
@@ -5,6 +5,7 @@ export declare class AddressMap<V> extends Map<Address, V> {
5
5
  set(key: Address, value: V): void;
6
6
  indexOf(address: Address): i32;
7
7
  has(key: Address): boolean;
8
- get(key: Address): V;
8
+ get(key: Address): V | undefined;
9
9
  delete(key: Address): boolean;
10
+ [Symbol.iterator](): IterableIterator<[Address, V]>;
10
11
  }
@@ -30,7 +30,7 @@ export class AddressMap extends Map {
30
30
  get(key) {
31
31
  const index = this.indexOf(key);
32
32
  if (index == -1) {
33
- throw new Error('Key not found in map');
33
+ return;
34
34
  }
35
35
  return this._values[index];
36
36
  }
@@ -43,4 +43,9 @@ export class AddressMap extends Map {
43
43
  this._values.splice(index, 1);
44
44
  return true;
45
45
  }
46
+ *[Symbol.iterator]() {
47
+ for (const key of this._keys) {
48
+ yield [key, this.get(key)];
49
+ }
50
+ }
46
51
  }
@@ -1,13 +1,13 @@
1
- import { i32 } from '../utils/types.js';
2
1
  import { Address } from '../keypair/Address.js';
3
2
  export declare class AddressSet {
4
3
  private keys;
5
4
  constructor(keys?: Address[]);
5
+ get size(): number;
6
6
  add(address: Address): void;
7
- contains(address: Address): boolean;
7
+ has(address: Address): boolean;
8
8
  remove(address: Address): void;
9
- size(): i32;
10
9
  clone(): AddressSet;
11
10
  clear(): void;
12
11
  combine(set: AddressSet): AddressSet;
12
+ [Symbol.iterator](): Generator<Address, void, unknown>;
13
13
  }
@@ -2,12 +2,15 @@ export class AddressSet {
2
2
  constructor(keys = []) {
3
3
  this.keys = keys;
4
4
  }
5
+ get size() {
6
+ return this.keys.length;
7
+ }
5
8
  add(address) {
6
- if (!this.contains(address)) {
9
+ if (!this.has(address)) {
7
10
  this.keys.push(address);
8
11
  }
9
12
  }
10
- contains(address) {
13
+ has(address) {
11
14
  for (let i = 0; i < this.keys.length; i++) {
12
15
  if (this.keys[i].equals(address)) {
13
16
  return true;
@@ -21,9 +24,6 @@ export class AddressSet {
21
24
  this.keys.splice(index, 1);
22
25
  }
23
26
  }
24
- size() {
25
- return this.keys.length;
26
- }
27
27
  clone() {
28
28
  const clone = new AddressSet();
29
29
  for (let i = 0; i < this.keys.length; i++) {
@@ -41,4 +41,9 @@ export class AddressSet {
41
41
  }
42
42
  return clone;
43
43
  }
44
+ *[Symbol.iterator]() {
45
+ for (let i = 0; i < this.keys.length; i++) {
46
+ yield this.keys[i];
47
+ }
48
+ }
44
49
  }
@@ -7,7 +7,7 @@ export declare class Map<K, V> {
7
7
  values(): V[];
8
8
  set(key: K, value: V): void;
9
9
  indexOf(key: K): i32;
10
- get(key: K): V;
10
+ get(key: K): V | undefined;
11
11
  has(key: K): boolean;
12
12
  delete(key: K): boolean;
13
13
  clear(): void;
@@ -33,7 +33,7 @@ export class Map {
33
33
  get(key) {
34
34
  const index = this.indexOf(key);
35
35
  if (index == -1) {
36
- throw new Error('Key not found in map');
36
+ return undefined;
37
37
  }
38
38
  return this._values[index];
39
39
  }
@@ -11,8 +11,8 @@ export declare class Address extends Uint8Array {
11
11
  static wrap(bytes: ArrayLike<number>): Address;
12
12
  toHex(): string;
13
13
  equals(a: Address): boolean;
14
- isBiggerThan(a: Address): boolean;
15
- isSmallerThan(a: Address): boolean;
14
+ lessThan(a: Address): boolean;
15
+ greaterThan(a: Address): boolean;
16
16
  set(publicKey: ArrayLike<number>): void;
17
17
  isValid(network: Network): boolean;
18
18
  p2wpkh(network: Network): string;
@@ -57,21 +57,31 @@ export class Address extends Uint8Array {
57
57
  }
58
58
  return true;
59
59
  }
60
- isBiggerThan(a) {
61
- for (let i = 0; i < this.length; i++) {
62
- if (this[i] < a[i]) {
60
+ lessThan(a) {
61
+ for (let i = 0; i < 32; i++) {
62
+ const thisByte = this[i];
63
+ const aByte = a[i];
64
+ if (thisByte < aByte) {
65
+ return true;
66
+ }
67
+ else if (thisByte > aByte) {
63
68
  return false;
64
69
  }
65
70
  }
66
- return true;
67
- }
68
- isSmallerThan(a) {
69
- for (let i = 0; i < this.length; i++) {
70
- if (this[i] > a[i]) {
71
+ return false;
72
+ }
73
+ greaterThan(a) {
74
+ for (let i = 0; i < 32; i++) {
75
+ const thisByte = this[i];
76
+ const aByte = a[i];
77
+ if (thisByte > aByte) {
78
+ return true;
79
+ }
80
+ else if (thisByte < aByte) {
71
81
  return false;
72
82
  }
73
83
  }
74
- return true;
84
+ return false;
75
85
  }
76
86
  set(publicKey) {
77
87
  if (publicKey.length !== 33 && publicKey.length !== 32 && publicKey.length !== 65) {
@@ -100,6 +100,7 @@ export class AddressVerificator {
100
100
  }
101
101
  }
102
102
  catch (error) {
103
+ console.log(error);
103
104
  }
104
105
  return null;
105
106
  }
@@ -4,6 +4,7 @@ export type MemorySlotPointer = bigint;
4
4
  export type BufferLike = Uint8Array | Buffer;
5
5
  export type MemorySlotData<T> = T;
6
6
  export type PointerStorage = DeterministicMap<MemorySlotPointer, MemorySlotData<bigint>>;
7
+ export type BlockchainStorage = DeterministicMap<string, PointerStorage>;
7
8
  export type i32 = number;
8
9
  export type u8 = number;
9
10
  export type u16 = number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.0.114",
4
+ "version": "1.0.116",
5
5
  "author": "BlobMaster41",
6
6
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
7
7
  "engines": {
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.114';
1
+ export const version = '1.0.116';
@@ -35,10 +35,10 @@ export class AddressMap<V> extends Map<Address, V> {
35
35
  return false;
36
36
  }
37
37
 
38
- public get(key: Address): V {
38
+ public get(key: Address): V | undefined {
39
39
  const index: i32 = this.indexOf(key);
40
40
  if (index == -1) {
41
- throw new Error('Key not found in map');
41
+ return;
42
42
  }
43
43
  return this._values[index];
44
44
  }
@@ -54,4 +54,10 @@ export class AddressMap<V> extends Map<Address, V> {
54
54
 
55
55
  return true;
56
56
  }
57
+
58
+ *[Symbol.iterator](): IterableIterator<[Address, V]> {
59
+ for (const key of this._keys) {
60
+ yield [key, this.get(key) as V];
61
+ }
62
+ }
57
63
  }
@@ -1,4 +1,3 @@
1
- import { i32 } from '../utils/types.js';
2
1
  import { Address } from '../keypair/Address.js';
3
2
 
4
3
  export class AddressSet {
@@ -8,13 +7,17 @@ export class AddressSet {
8
7
  this.keys = keys;
9
8
  }
10
9
 
10
+ public get size(): number {
11
+ return this.keys.length;
12
+ }
13
+
11
14
  public add(address: Address): void {
12
- if (!this.contains(address)) {
15
+ if (!this.has(address)) {
13
16
  this.keys.push(address);
14
17
  }
15
18
  }
16
19
 
17
- public contains(address: Address): boolean {
20
+ public has(address: Address): boolean {
18
21
  for (let i = 0; i < this.keys.length; i++) {
19
22
  if (this.keys[i].equals(address)) {
20
23
  return true;
@@ -32,10 +35,6 @@ export class AddressSet {
32
35
  }
33
36
  }
34
37
 
35
- public size(): i32 {
36
- return this.keys.length;
37
- }
38
-
39
38
  public clone(): AddressSet {
40
39
  const clone = new AddressSet();
41
40
 
@@ -59,4 +58,10 @@ export class AddressSet {
59
58
 
60
59
  return clone;
61
60
  }
61
+
62
+ *[Symbol.iterator]() {
63
+ for (let i = 0; i < this.keys.length; i++) {
64
+ yield this.keys[i];
65
+ }
66
+ }
62
67
  }
@@ -36,10 +36,10 @@ export class Map<K, V> {
36
36
  return -1;
37
37
  }
38
38
 
39
- public get(key: K): V {
39
+ public get(key: K): V | undefined {
40
40
  const index: i32 = this.indexOf(key);
41
41
  if (index == -1) {
42
- throw new Error('Key not found in map');
42
+ return undefined;
43
43
  }
44
44
  return this._values[index];
45
45
  }
@@ -87,28 +87,40 @@ export class Address extends Uint8Array {
87
87
  * Check if the address is bigger than another address
88
88
  * @returns {boolean} If bigger
89
89
  */
90
- public isBiggerThan(a: Address): boolean {
91
- for (let i = 0; i < this.length; i++) {
92
- if (this[i] < a[i]) {
93
- return false;
90
+ public lessThan(a: Address): boolean {
91
+ // Compare the two addresses byte-by-byte, treating them as big-endian uint256
92
+ for (let i = 0; i < 32; i++) {
93
+ const thisByte = this[i];
94
+ const aByte = a[i];
95
+
96
+ if (thisByte < aByte) {
97
+ return true; // this is less than a
98
+ } else if (thisByte > aByte) {
99
+ return false; // this is greater than or equal to a
94
100
  }
95
101
  }
96
102
 
97
- return true;
103
+ return false;
98
104
  }
99
105
 
100
106
  /**
101
107
  * Check if the address is smaller than another address
102
108
  * @returns {boolean} If smaller
103
109
  */
104
- public isSmallerThan(a: Address): boolean {
105
- for (let i = 0; i < this.length; i++) {
106
- if (this[i] > a[i]) {
107
- return false;
110
+ public greaterThan(a: Address): boolean {
111
+ // Compare the two addresses byte-by-byte, treating them as big-endian uint256
112
+ for (let i = 0; i < 32; i++) {
113
+ const thisByte = this[i];
114
+ const aByte = a[i];
115
+
116
+ if (thisByte > aByte) {
117
+ return true; // this is greater than a
118
+ } else if (thisByte < aByte) {
119
+ return false; // this is less than or equal to a
108
120
  }
109
121
  }
110
122
 
111
- return true;
123
+ return false;
112
124
  }
113
125
 
114
126
  /**
@@ -127,27 +139,6 @@ export class Address extends Uint8Array {
127
139
  const buf = Buffer.alloc(32);
128
140
  buf.set(publicKey);
129
141
 
130
- /*let lowByte: number = 0;
131
- try {
132
- EcKeyPair.tweakPublicKey('02' + buf.toString('hex'));
133
- lowByte = 2;
134
- } catch (e) {
135
- console.log(`Invalid pubkey (2) ${e}`);
136
- }
137
-
138
- try {
139
- EcKeyPair.tweakPublicKey('03' + buf.toString('hex'));
140
- lowByte = 3;
141
- } catch (e) {
142
- console.log(`Invalid pubkey (3) ${e}`);
143
- }
144
-
145
- if (lowByte === 0) {
146
- console.log(AddressGenerator.generateTaprootAddress(buf, networks.regtest));
147
-
148
- throw new Error('Invalid public key');
149
- }*/
150
-
151
142
  super.set(publicKey);
152
143
  } else {
153
144
  this._keyPair = EcKeyPair.fromPublicKey(Uint8Array.from(publicKey));
@@ -175,6 +175,7 @@ export class AddressVerificator {
175
175
  }
176
176
  }
177
177
  } catch (error) {
178
+ console.log(error);
178
179
  // Ignore errors from Bech32/Bech32m decoding
179
180
  }
180
181
 
@@ -7,7 +7,6 @@ function deadAddress(): Address {
7
7
 
8
8
  // Addresses Regtest
9
9
  export const FACTORY_ADDRESS_REGTEST: Address = deadAddress();
10
-
11
10
  export const POOL_ADDRESS_REGTEST: Address = deadAddress();
12
11
  export const WBTC_ADDRESS_REGTEST: Address = deadAddress();
13
12
  export const MOTO_ADDRESS_REGTEST: Address = deadAddress();
@@ -8,6 +8,7 @@ export type BufferLike = Uint8Array | Buffer;
8
8
 
9
9
  export type MemorySlotData<T> = T;
10
10
  export type PointerStorage = DeterministicMap<MemorySlotPointer, MemorySlotData<bigint>>;
11
+ export type BlockchainStorage = DeterministicMap<string, PointerStorage>;
11
12
 
12
13
  export type i32 = number;
13
14
  export type u8 = number;