@btc-vision/transaction 1.1.5 → 1.1.7

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.
@@ -1 +1 @@
1
- export declare const version = "1.1.5";
1
+ export declare const version = "1.1.7";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.1.5';
1
+ export const version = '1.1.7';
@@ -3,16 +3,18 @@ export declare enum ABIDataTypes {
3
3
  UINT16 = "UINT16",
4
4
  UINT32 = "UINT32",
5
5
  UINT64 = "UINT64",
6
+ UINT128 = "UINT128",
7
+ UINT256 = "UINT256",
6
8
  BOOL = "BOOL",
7
9
  ADDRESS = "ADDRESS",
8
10
  STRING = "STRING",
9
11
  BYTES32 = "BYTES32",
10
- UINT256 = "UINT256",
11
12
  TUPLE = "TUPLE",
12
13
  BYTES = "BYTES",
13
14
  ADDRESS_UINT256_TUPLE = "ADDRESS_UINT256_TUPLE",
14
15
  ARRAY_OF_ADDRESSES = "ARRAY_OF_ADDRESSES",
15
16
  ARRAY_OF_UINT256 = "ARRAY_OF_UINT256",
17
+ ARRAY_OF_UINT128 = "ARRAY_OF_UINT128",
16
18
  ARRAY_OF_UINT64 = "ARRAY_OF_UINT64",
17
19
  ARRAY_OF_UINT32 = "ARRAY_OF_UINT32",
18
20
  ARRAY_OF_UINT16 = "ARRAY_OF_UINT16",
@@ -22,8 +24,6 @@ export declare enum ABIDataTypes {
22
24
  }
23
25
  export declare class ABICoder {
24
26
  decodeData(data: Uint8Array, types: ABIDataTypes[]): unknown[];
25
- encodePointer(key: string): bigint;
26
- encodePointerHash(pointer: number, sub: bigint): Uint8Array;
27
27
  encodeSelector(selectorIdentifier: string): string;
28
28
  numericSelectorToHex(selector: number): string;
29
29
  private bigIntToUint8Array;
@@ -7,16 +7,18 @@ export var ABIDataTypes;
7
7
  ABIDataTypes["UINT16"] = "UINT16";
8
8
  ABIDataTypes["UINT32"] = "UINT32";
9
9
  ABIDataTypes["UINT64"] = "UINT64";
10
+ ABIDataTypes["UINT128"] = "UINT128";
11
+ ABIDataTypes["UINT256"] = "UINT256";
10
12
  ABIDataTypes["BOOL"] = "BOOL";
11
13
  ABIDataTypes["ADDRESS"] = "ADDRESS";
12
14
  ABIDataTypes["STRING"] = "STRING";
13
15
  ABIDataTypes["BYTES32"] = "BYTES32";
14
- ABIDataTypes["UINT256"] = "UINT256";
15
16
  ABIDataTypes["TUPLE"] = "TUPLE";
16
17
  ABIDataTypes["BYTES"] = "BYTES";
17
18
  ABIDataTypes["ADDRESS_UINT256_TUPLE"] = "ADDRESS_UINT256_TUPLE";
18
19
  ABIDataTypes["ARRAY_OF_ADDRESSES"] = "ARRAY_OF_ADDRESSES";
19
20
  ABIDataTypes["ARRAY_OF_UINT256"] = "ARRAY_OF_UINT256";
21
+ ABIDataTypes["ARRAY_OF_UINT128"] = "ARRAY_OF_UINT128";
20
22
  ABIDataTypes["ARRAY_OF_UINT64"] = "ARRAY_OF_UINT64";
21
23
  ABIDataTypes["ARRAY_OF_UINT32"] = "ARRAY_OF_UINT32";
22
24
  ABIDataTypes["ARRAY_OF_UINT16"] = "ARRAY_OF_UINT16";
@@ -52,6 +54,9 @@ export class ABICoder {
52
54
  case ABIDataTypes.STRING:
53
55
  result.push(byteReader.readStringWithLength());
54
56
  break;
57
+ case ABIDataTypes.UINT128:
58
+ result.push(byteReader.readU128());
59
+ break;
55
60
  case ABIDataTypes.UINT256:
56
61
  result.push(byteReader.readU256());
57
62
  break;
@@ -73,6 +78,9 @@ export class ABICoder {
73
78
  case ABIDataTypes.ARRAY_OF_UINT256:
74
79
  result.push(byteReader.readU256Array());
75
80
  break;
81
+ case ABIDataTypes.ARRAY_OF_UINT128:
82
+ result.push(byteReader.readU128Array());
83
+ break;
76
84
  case ABIDataTypes.ARRAY_OF_UINT64:
77
85
  result.push(byteReader.readU64Array());
78
86
  break;
@@ -94,27 +102,6 @@ export class ABICoder {
94
102
  }
95
103
  return result;
96
104
  }
97
- encodePointer(key) {
98
- const hash = this.sha256(key);
99
- const finalBuffer = Buffer.alloc(BufferHelper.EXPECTED_BUFFER_LENGTH);
100
- const selector = hash.subarray(0, BufferHelper.EXPECTED_BUFFER_LENGTH);
101
- for (let i = 0; i < BufferHelper.EXPECTED_BUFFER_LENGTH; i++) {
102
- finalBuffer[i] = selector[i];
103
- }
104
- return BigInt('0x' + finalBuffer.toString('hex'));
105
- }
106
- encodePointerHash(pointer, sub) {
107
- const finalBuffer = new Uint8Array(BufferHelper.EXPECTED_BUFFER_LENGTH + 2);
108
- finalBuffer[0] = pointer & 0xff;
109
- finalBuffer[1] = (pointer >> 8) & 0xff;
110
- const subKey = this.bigIntToUint8Array(sub, BufferHelper.EXPECTED_BUFFER_LENGTH);
111
- finalBuffer.set(subKey, 2);
112
- const hashed = this.sha256(finalBuffer);
113
- if (hashed.byteLength !== BufferHelper.EXPECTED_BUFFER_LENGTH) {
114
- throw new Error('Invalid hash length');
115
- }
116
- return hashed;
117
- }
118
105
  encodeSelector(selectorIdentifier) {
119
106
  const hash = this.sha256(selectorIdentifier);
120
107
  const selector = hash.subarray(0, 4);
@@ -11,6 +11,7 @@ export declare class BinaryReader {
11
11
  setBuffer(bytes: BufferLike): void;
12
12
  readAddressArray(): Address[];
13
13
  readU256Array(): bigint[];
14
+ readU128Array(): bigint[];
14
15
  readU64Array(): bigint[];
15
16
  readU32Array(): u32[];
16
17
  readU16Array(): u16[];
@@ -24,6 +25,7 @@ export declare class BinaryReader {
24
25
  readU32(le?: boolean): u32;
25
26
  readU64(): bigint;
26
27
  readAddressValueTuple(): AddressMap<bigint>;
28
+ readU128(): bigint;
27
29
  readU256(): bigint;
28
30
  readBytes(length: u32, zeroStop?: boolean): Uint8Array;
29
31
  readString(length: u16): string;
@@ -43,6 +43,14 @@ export class BinaryReader {
43
43
  }
44
44
  return result;
45
45
  }
46
+ readU128Array() {
47
+ const length = this.readU16();
48
+ const result = new Array(length);
49
+ for (let i = 0; i < length; i++) {
50
+ result[i] = this.readU128();
51
+ }
52
+ return result;
53
+ }
46
54
  readU64Array() {
47
55
  const length = this.readU16();
48
56
  const result = new Array(length);
@@ -140,6 +148,10 @@ export class BinaryReader {
140
148
  }
141
149
  return result;
142
150
  }
151
+ readU128() {
152
+ const next16Bytes = this.readBytes(16);
153
+ return BigInt('0x' + next16Bytes.reduce((acc, byte) => acc + byte.toString(16).padStart(2, '0'), ''));
154
+ }
143
155
  readU256() {
144
156
  const next32Bytes = this.readBytes(32);
145
157
  return BigInt('0x' + next32Bytes.reduce((acc, byte) => acc + byte.toString(16).padStart(2, '0'), ''));
@@ -13,6 +13,7 @@ export declare class BinaryWriter {
13
13
  writeSelector(value: Selector): void;
14
14
  writeBoolean(value: boolean): void;
15
15
  writeU256(bigIntValue: bigint): void;
16
+ writeU128(bigIntValue: bigint): void;
16
17
  writeBytes(value: Uint8Array | Buffer): void;
17
18
  writeString(value: string): void;
18
19
  writeAddress(value: Address): void;
@@ -32,6 +33,7 @@ export declare class BinaryWriter {
32
33
  writeAddressArray(value: Address[]): void;
33
34
  writeU32Array(value: u32[]): void;
34
35
  writeU256Array(value: bigint[]): void;
36
+ writeU128Array(value: bigint[]): void;
35
37
  writeStringArray(value: string[]): void;
36
38
  writeU16Array(value: u16[]): void;
37
39
  writeU8Array(value: u8[]): void;
@@ -53,6 +53,19 @@ export class BinaryWriter {
53
53
  this.writeU8(bytesToHex[i]);
54
54
  }
55
55
  }
56
+ writeU128(bigIntValue) {
57
+ if (bigIntValue > 340282366920938463463374607431768211455n) {
58
+ throw new Error('Value is too large.');
59
+ }
60
+ this.allocSafe(16);
61
+ const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue);
62
+ if (bytesToHex.byteLength !== 16) {
63
+ throw new Error(`Invalid u128 value: ${bigIntValue}`);
64
+ }
65
+ for (let i = 0; i < bytesToHex.byteLength; i++) {
66
+ this.writeU8(bytesToHex[i]);
67
+ }
68
+ }
56
69
  writeBytes(value) {
57
70
  this.allocSafe(value.byteLength);
58
71
  for (let i = 0; i < value.byteLength; i++) {
@@ -177,6 +190,14 @@ export class BinaryWriter {
177
190
  this.writeU256(value[i]);
178
191
  }
179
192
  }
193
+ writeU128Array(value) {
194
+ if (value.length > 65535)
195
+ throw new Error('Array size is too large');
196
+ this.writeU16(value.length);
197
+ for (let i = 0; i < value.length; i++) {
198
+ this.writeU128(value[i]);
199
+ }
200
+ }
180
201
  writeStringArray(value) {
181
202
  if (value.length > 65535)
182
203
  throw new Error('Array size is too large');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.1.5",
4
+ "version": "1.1.7",
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.1.5';
1
+ export const version = '1.1.7';
@@ -8,16 +8,18 @@ export enum ABIDataTypes {
8
8
  UINT16 = 'UINT16',
9
9
  UINT32 = 'UINT32',
10
10
  UINT64 = 'UINT64',
11
+ UINT128 = 'UINT128',
12
+ UINT256 = 'UINT256',
11
13
  BOOL = 'BOOL',
12
14
  ADDRESS = 'ADDRESS',
13
15
  STRING = 'STRING',
14
16
  BYTES32 = 'BYTES32',
15
- UINT256 = 'UINT256',
16
17
  TUPLE = 'TUPLE',
17
18
  BYTES = 'BYTES',
18
19
  ADDRESS_UINT256_TUPLE = 'ADDRESS_UINT256_TUPLE',
19
20
  ARRAY_OF_ADDRESSES = 'ARRAY_OF_ADDRESSES',
20
21
  ARRAY_OF_UINT256 = 'ARRAY_OF_UINT256',
22
+ ARRAY_OF_UINT128 = 'ARRAY_OF_UINT128',
21
23
  ARRAY_OF_UINT64 = 'ARRAY_OF_UINT64',
22
24
  ARRAY_OF_UINT32 = 'ARRAY_OF_UINT32',
23
25
  ARRAY_OF_UINT16 = 'ARRAY_OF_UINT16',
@@ -55,6 +57,9 @@ export class ABICoder {
55
57
  case ABIDataTypes.STRING:
56
58
  result.push(byteReader.readStringWithLength());
57
59
  break;
60
+ case ABIDataTypes.UINT128:
61
+ result.push(byteReader.readU128());
62
+ break;
58
63
  case ABIDataTypes.UINT256:
59
64
  result.push(byteReader.readU256());
60
65
  break;
@@ -76,6 +81,9 @@ export class ABICoder {
76
81
  case ABIDataTypes.ARRAY_OF_UINT256:
77
82
  result.push(byteReader.readU256Array());
78
83
  break;
84
+ case ABIDataTypes.ARRAY_OF_UINT128:
85
+ result.push(byteReader.readU128Array());
86
+ break;
79
87
  case ABIDataTypes.ARRAY_OF_UINT64:
80
88
  result.push(byteReader.readU64Array());
81
89
  break;
@@ -99,36 +107,6 @@ export class ABICoder {
99
107
  return result;
100
108
  }
101
109
 
102
- public encodePointer(key: string): bigint {
103
- const hash = this.sha256(key);
104
- const finalBuffer = Buffer.alloc(BufferHelper.EXPECTED_BUFFER_LENGTH);
105
- const selector = hash.subarray(0, BufferHelper.EXPECTED_BUFFER_LENGTH); // 32 bytes
106
-
107
- for (let i = 0; i < BufferHelper.EXPECTED_BUFFER_LENGTH; i++) {
108
- finalBuffer[i] = selector[i];
109
- }
110
-
111
- return BigInt('0x' + finalBuffer.toString('hex'));
112
- }
113
-
114
- public encodePointerHash(pointer: number, sub: bigint): Uint8Array {
115
- const finalBuffer = new Uint8Array(BufferHelper.EXPECTED_BUFFER_LENGTH + 2); // 32 bytes for `sub` + 2 bytes for `pointer`
116
- // Encode pointer
117
- finalBuffer[0] = pointer & 0xff;
118
- finalBuffer[1] = (pointer >> 8) & 0xff;
119
-
120
- // Convert `sub` to Uint8Array and append it
121
- const subKey = this.bigIntToUint8Array(sub, BufferHelper.EXPECTED_BUFFER_LENGTH); // Assuming a function to convert BigInt to Uint8Array of fixed size
122
- finalBuffer.set(subKey, 2);
123
-
124
- const hashed = this.sha256(finalBuffer);
125
- if (hashed.byteLength !== BufferHelper.EXPECTED_BUFFER_LENGTH) {
126
- throw new Error('Invalid hash length');
127
- }
128
-
129
- return hashed;
130
- }
131
-
132
110
  public encodeSelector(selectorIdentifier: string): string {
133
111
  // first 4 bytes of sha256 hash of the function signature
134
112
  const hash = this.sha256(selectorIdentifier);
@@ -55,6 +55,17 @@ export class BinaryReader {
55
55
  return result;
56
56
  }
57
57
 
58
+ public readU128Array(): bigint[] {
59
+ const length = this.readU16();
60
+ const result: bigint[] = new Array<bigint>(length);
61
+
62
+ for (let i = 0; i < length; i++) {
63
+ result[i] = this.readU128();
64
+ }
65
+
66
+ return result;
67
+ }
68
+
58
69
  public readU64Array(): bigint[] {
59
70
  const length = this.readU16();
60
71
  const result: bigint[] = new Array<bigint>(length);
@@ -191,6 +202,14 @@ export class BinaryReader {
191
202
  return result;
192
203
  }
193
204
 
205
+ public readU128(): bigint {
206
+ const next16Bytes = this.readBytes(16);
207
+
208
+ return BigInt(
209
+ '0x' + next16Bytes.reduce((acc, byte) => acc + byte.toString(16).padStart(2, '0'), ''),
210
+ );
211
+ }
212
+
194
213
  public readU256(): bigint {
195
214
  const next32Bytes = this.readBytes(32);
196
215
 
@@ -71,6 +71,23 @@ export class BinaryWriter {
71
71
  }
72
72
  }
73
73
 
74
+ public writeU128(bigIntValue: bigint): void {
75
+ if (bigIntValue > 340282366920938463463374607431768211455n) {
76
+ throw new Error('Value is too large.');
77
+ }
78
+
79
+ this.allocSafe(16);
80
+
81
+ const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue);
82
+ if (bytesToHex.byteLength !== 16) {
83
+ throw new Error(`Invalid u128 value: ${bigIntValue}`);
84
+ }
85
+
86
+ for (let i = 0; i < bytesToHex.byteLength; i++) {
87
+ this.writeU8(bytesToHex[i]);
88
+ }
89
+ }
90
+
74
91
  public writeBytes(value: Uint8Array | Buffer): void {
75
92
  this.allocSafe(value.byteLength);
76
93
 
@@ -227,6 +244,16 @@ export class BinaryWriter {
227
244
  }
228
245
  }
229
246
 
247
+ public writeU128Array(value: bigint[]): void {
248
+ if (value.length > 65535) throw new Error('Array size is too large');
249
+
250
+ this.writeU16(value.length);
251
+
252
+ for (let i = 0; i < value.length; i++) {
253
+ this.writeU128(value[i]);
254
+ }
255
+ }
256
+
230
257
  public writeStringArray(value: string[]): void {
231
258
  if (value.length > 65535) throw new Error('Array size is too large');
232
259
 
@@ -1,40 +0,0 @@
1
- import { VaultUTXOs } from '../src/transaction/processor/PsbtTransaction.js';
2
-
3
- export interface GenerationConstraints {
4
- /** Timestamp of the generation */
5
- readonly timestamp: number;
6
-
7
- /** Protocol version used for generation */
8
- readonly version: string;
9
-
10
- /** Minimum different trusted validators */
11
- readonly minimum: number;
12
-
13
- /** Minimum different trusted validator in a new generated transaction */
14
- readonly transactionMinimum: number;
15
- }
16
-
17
- export interface WrappedGenerationParameters {
18
- /** Public trusted keys */
19
- readonly keys: string[];
20
-
21
- /** Vault address (p2ms) */
22
- readonly vault: string;
23
-
24
- /** Public trusted entities */
25
- readonly entities: string[];
26
-
27
- /** OPNet Signature that verify the trusted keys and entities */
28
- readonly signature: string;
29
-
30
- /** Generation constraints */
31
- readonly constraints: GenerationConstraints;
32
- }
33
-
34
- export interface UnwrappedGenerationParameters {
35
- /** UTXOs to unwrap from */
36
- readonly vaultUTXOs: VaultUTXOs[];
37
-
38
- /** WBTC balance */
39
- readonly balance: string;
40
- }
@@ -1,13 +0,0 @@
1
- import { UnwrappedGenerationParameters } from './Generate.js';
2
- import { VaultUTXOs } from '../src/transaction/processor/PsbtTransaction.js';
3
-
4
- export class UnwrapGeneration implements Omit<UnwrappedGenerationParameters, 'balance'> {
5
- public readonly vaultUTXOs: VaultUTXOs[];
6
-
7
- public readonly balance: bigint;
8
-
9
- constructor(params: UnwrappedGenerationParameters) {
10
- this.vaultUTXOs = params.vaultUTXOs;
11
- this.balance = BigInt(params.balance);
12
- }
13
- }
@@ -1,33 +0,0 @@
1
- import { GenerationConstraints, WrappedGenerationParameters } from './Generate.js';
2
-
3
- export class WrappedGeneration implements WrappedGenerationParameters {
4
- /** Generation constraints */
5
- public readonly constraints: GenerationConstraints;
6
-
7
- /** Public trusted entities */
8
- public readonly entities: string[];
9
-
10
- /** Public trusted keys */
11
- public readonly keys: string[];
12
-
13
- /** OPNet Signature that verify the trusted keys and entities */
14
- public readonly signature: string;
15
-
16
- /** Vault address (p2ms) */
17
- public readonly vault: string;
18
-
19
- /**
20
- * Public keys of the trusted entities
21
- */
22
- public readonly pubKeys: Buffer[];
23
-
24
- constructor(params: WrappedGenerationParameters) {
25
- this.constraints = params.constraints;
26
- this.entities = params.entities;
27
- this.keys = params.keys;
28
- this.signature = params.signature;
29
- this.vault = params.vault;
30
-
31
- this.pubKeys = this.keys.map((key: string) => Buffer.from(key, 'base64'));
32
- }
33
- }