@btc-vision/transaction 1.1.5 → 1.1.6
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/_version.d.ts +1 -1
- package/browser/abi/ABICoder.d.ts +2 -3
- package/browser/buffer/BinaryReader.d.ts +1 -0
- package/browser/buffer/BinaryWriter.d.ts +1 -0
- package/browser/index.js +1 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/abi/ABICoder.d.ts +2 -3
- package/build/abi/ABICoder.js +5 -22
- package/build/buffer/BinaryReader.d.ts +1 -0
- package/build/buffer/BinaryReader.js +4 -0
- package/build/buffer/BinaryWriter.d.ts +1 -0
- package/build/buffer/BinaryWriter.js +13 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/abi/ABICoder.ts +5 -31
- package/src/buffer/BinaryReader.ts +8 -0
- package/src/buffer/BinaryWriter.ts +17 -0
- package/wbtc_disabled/Generate.ts.disabled +0 -40
- package/wbtc_disabled/UnwrapGeneration.ts.disabled +0 -13
- package/wbtc_disabled/WrappedGenerationParameters.ts.disabled +0 -33
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.1.
|
|
1
|
+
export declare const version = "1.1.6";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.1.
|
|
1
|
+
export const version = '1.1.6';
|
package/build/abi/ABICoder.d.ts
CHANGED
|
@@ -3,11 +3,12 @@ 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",
|
|
@@ -22,8 +23,6 @@ export declare enum ABIDataTypes {
|
|
|
22
23
|
}
|
|
23
24
|
export declare class ABICoder {
|
|
24
25
|
decodeData(data: Uint8Array, types: ABIDataTypes[]): unknown[];
|
|
25
|
-
encodePointer(key: string): bigint;
|
|
26
|
-
encodePointerHash(pointer: number, sub: bigint): Uint8Array;
|
|
27
26
|
encodeSelector(selectorIdentifier: string): string;
|
|
28
27
|
numericSelectorToHex(selector: number): string;
|
|
29
28
|
private bigIntToUint8Array;
|
package/build/abi/ABICoder.js
CHANGED
|
@@ -7,11 +7,12 @@ 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";
|
|
@@ -52,6 +53,9 @@ export class ABICoder {
|
|
|
52
53
|
case ABIDataTypes.STRING:
|
|
53
54
|
result.push(byteReader.readStringWithLength());
|
|
54
55
|
break;
|
|
56
|
+
case ABIDataTypes.UINT128:
|
|
57
|
+
result.push(byteReader.readU128());
|
|
58
|
+
break;
|
|
55
59
|
case ABIDataTypes.UINT256:
|
|
56
60
|
result.push(byteReader.readU256());
|
|
57
61
|
break;
|
|
@@ -94,27 +98,6 @@ export class ABICoder {
|
|
|
94
98
|
}
|
|
95
99
|
return result;
|
|
96
100
|
}
|
|
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
101
|
encodeSelector(selectorIdentifier) {
|
|
119
102
|
const hash = this.sha256(selectorIdentifier);
|
|
120
103
|
const selector = hash.subarray(0, 4);
|
|
@@ -24,6 +24,7 @@ export declare class BinaryReader {
|
|
|
24
24
|
readU32(le?: boolean): u32;
|
|
25
25
|
readU64(): bigint;
|
|
26
26
|
readAddressValueTuple(): AddressMap<bigint>;
|
|
27
|
+
readU128(): bigint;
|
|
27
28
|
readU256(): bigint;
|
|
28
29
|
readBytes(length: u32, zeroStop?: boolean): Uint8Array;
|
|
29
30
|
readString(length: u16): string;
|
|
@@ -140,6 +140,10 @@ export class BinaryReader {
|
|
|
140
140
|
}
|
|
141
141
|
return result;
|
|
142
142
|
}
|
|
143
|
+
readU128() {
|
|
144
|
+
const next16Bytes = this.readBytes(16);
|
|
145
|
+
return BigInt('0x' + next16Bytes.reduce((acc, byte) => acc + byte.toString(16).padStart(2, '0'), ''));
|
|
146
|
+
}
|
|
143
147
|
readU256() {
|
|
144
148
|
const next32Bytes = this.readBytes(32);
|
|
145
149
|
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;
|
|
@@ -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++) {
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.1.
|
|
1
|
+
export const version = '1.1.6';
|
package/src/abi/ABICoder.ts
CHANGED
|
@@ -8,11 +8,12 @@ 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',
|
|
@@ -55,6 +56,9 @@ export class ABICoder {
|
|
|
55
56
|
case ABIDataTypes.STRING:
|
|
56
57
|
result.push(byteReader.readStringWithLength());
|
|
57
58
|
break;
|
|
59
|
+
case ABIDataTypes.UINT128:
|
|
60
|
+
result.push(byteReader.readU128());
|
|
61
|
+
break;
|
|
58
62
|
case ABIDataTypes.UINT256:
|
|
59
63
|
result.push(byteReader.readU256());
|
|
60
64
|
break;
|
|
@@ -99,36 +103,6 @@ export class ABICoder {
|
|
|
99
103
|
return result;
|
|
100
104
|
}
|
|
101
105
|
|
|
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
106
|
public encodeSelector(selectorIdentifier: string): string {
|
|
133
107
|
// first 4 bytes of sha256 hash of the function signature
|
|
134
108
|
const hash = this.sha256(selectorIdentifier);
|
|
@@ -191,6 +191,14 @@ export class BinaryReader {
|
|
|
191
191
|
return result;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
public readU128(): bigint {
|
|
195
|
+
const next16Bytes = this.readBytes(16);
|
|
196
|
+
|
|
197
|
+
return BigInt(
|
|
198
|
+
'0x' + next16Bytes.reduce((acc, byte) => acc + byte.toString(16).padStart(2, '0'), ''),
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
194
202
|
public readU256(): bigint {
|
|
195
203
|
const next32Bytes = this.readBytes(32);
|
|
196
204
|
|
|
@@ -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
|
|
|
@@ -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
|
-
}
|