@btc-vision/transaction 1.5.3 → 1.5.4
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/abi/ABICoder.d.ts +1 -0
- package/browser/buffer/BinaryWriter.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/transaction/browser/types/Unisat.d.ts +1 -1
- package/build/abi/ABICoder.d.ts +1 -0
- package/build/abi/ABICoder.js +4 -0
- package/build/buffer/BinaryWriter.d.ts +1 -1
- package/build/buffer/BinaryWriter.js +11 -9
- package/build/keypair/EcKeyPair.js +5 -5
- package/build/transaction/browser/types/Unisat.d.ts +1 -1
- package/package.json +2 -2
- package/src/abi/ABICoder.ts +4 -0
- package/src/buffer/BinaryWriter.ts +13 -11
- package/src/keypair/EcKeyPair.ts +5 -5
- package/src/transaction/browser/types/Unisat.ts +1 -1
|
@@ -63,7 +63,7 @@ export interface Unisat {
|
|
|
63
63
|
switchNetwork(network: UnisatNetwork): Promise<void>;
|
|
64
64
|
getPublicKey(): Promise<string>;
|
|
65
65
|
getBalance(): Promise<Balance>;
|
|
66
|
-
signMessage(message: string, type?: MessageType): Promise<string>;
|
|
66
|
+
signMessage(message: string | Buffer, type?: MessageType): Promise<string>;
|
|
67
67
|
signData(hex: string, type?: SignatureType): Promise<string>;
|
|
68
68
|
pushTx(options: {
|
|
69
69
|
rawtx: string;
|
package/build/abi/ABICoder.d.ts
CHANGED
package/build/abi/ABICoder.js
CHANGED
|
@@ -13,6 +13,7 @@ export var ABIDataTypes;
|
|
|
13
13
|
ABIDataTypes["BOOL"] = "BOOL";
|
|
14
14
|
ABIDataTypes["ADDRESS"] = "ADDRESS";
|
|
15
15
|
ABIDataTypes["STRING"] = "STRING";
|
|
16
|
+
ABIDataTypes["BYTES4"] = "BYTES4";
|
|
16
17
|
ABIDataTypes["BYTES32"] = "BYTES32";
|
|
17
18
|
ABIDataTypes["BYTES"] = "BYTES";
|
|
18
19
|
ABIDataTypes["ADDRESS_UINT256_TUPLE"] = "ADDRESS_UINT256_TUPLE";
|
|
@@ -42,6 +43,9 @@ export class ABICoder {
|
|
|
42
43
|
case ABIDataTypes.UINT32:
|
|
43
44
|
result.push(byteReader.readU32());
|
|
44
45
|
break;
|
|
46
|
+
case ABIDataTypes.BYTES4:
|
|
47
|
+
result.push(byteReader.readBytes(4));
|
|
48
|
+
break;
|
|
45
49
|
case ABIDataTypes.BYTES32:
|
|
46
50
|
result.push(byteReader.readBytes(32));
|
|
47
51
|
break;
|
|
@@ -17,8 +17,8 @@ export declare class BinaryWriter {
|
|
|
17
17
|
writeU128(bigIntValue: bigint, be?: boolean): void;
|
|
18
18
|
writeBytes(value: Uint8Array | Buffer): void;
|
|
19
19
|
writeString(value: string): void;
|
|
20
|
-
writeAddress(value: Address): void;
|
|
21
20
|
writeStringWithLength(value: string): void;
|
|
21
|
+
writeAddress(value: Address): void;
|
|
22
22
|
getBuffer(clear?: boolean): Uint8Array;
|
|
23
23
|
reset(): void;
|
|
24
24
|
toBytesReader(): BinaryReader;
|
|
@@ -109,20 +109,22 @@ export class BinaryWriter {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
writeString(value) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
const encoder = new TextEncoder();
|
|
113
|
+
const bytes = encoder.encode(value);
|
|
114
|
+
this.allocSafe(bytes.length);
|
|
115
|
+
this.writeBytes(bytes);
|
|
116
|
+
}
|
|
117
|
+
writeStringWithLength(value) {
|
|
118
|
+
const encoder = new TextEncoder();
|
|
119
|
+
const bytes = encoder.encode(value);
|
|
120
|
+
this.allocSafe(U32_BYTE_LENGTH + bytes.length);
|
|
121
|
+
this.writeU32(bytes.length);
|
|
122
|
+
this.writeBytes(bytes);
|
|
116
123
|
}
|
|
117
124
|
writeAddress(value) {
|
|
118
125
|
this.verifyAddress(value);
|
|
119
126
|
this.writeBytes(value);
|
|
120
127
|
}
|
|
121
|
-
writeStringWithLength(value) {
|
|
122
|
-
this.allocSafe(U32_BYTE_LENGTH + value.length);
|
|
123
|
-
this.writeU32(value.length);
|
|
124
|
-
this.writeString(value);
|
|
125
|
-
}
|
|
126
128
|
getBuffer(clear = true) {
|
|
127
129
|
const buf = new Uint8Array(this.buffer.byteLength);
|
|
128
130
|
for (let i = 0; i < this.buffer.byteLength; i++) {
|
|
@@ -12,7 +12,7 @@ if (!BIP32factory) {
|
|
|
12
12
|
throw new Error('Failed to load BIP32 library');
|
|
13
13
|
}
|
|
14
14
|
secp256k1.utils.precompute(8);
|
|
15
|
-
const {
|
|
15
|
+
const { Point, CURVE } = secp256k1;
|
|
16
16
|
const TAP_TAG = utf8ToBytes('TapTweak');
|
|
17
17
|
const TAP_TAG_HASH = sha256(TAP_TAG);
|
|
18
18
|
function tapTweakHash(x) {
|
|
@@ -113,19 +113,19 @@ export class EcKeyPair {
|
|
|
113
113
|
pub = pub.slice(2);
|
|
114
114
|
const P = Point.fromHex(pub);
|
|
115
115
|
const Peven = (P.y & 1n) === 0n ? P : P.negate();
|
|
116
|
-
const xBytes = Peven.
|
|
116
|
+
const xBytes = Peven.toBytes(true).subarray(1);
|
|
117
117
|
const tBytes = tapTweakHash(xBytes);
|
|
118
118
|
const t = mod(bytesToNumberBE(tBytes), CURVE.n);
|
|
119
119
|
const Q = Peven.add(Point.BASE.multiply(t));
|
|
120
|
-
return Buffer.from(Q.
|
|
120
|
+
return Buffer.from(Q.toBytes(true));
|
|
121
121
|
}
|
|
122
122
|
static tweakBatchSharedT(pubkeys, tweakScalar) {
|
|
123
123
|
const T = Point.BASE.multiply(tweakScalar);
|
|
124
124
|
return pubkeys.map((bytes) => {
|
|
125
125
|
const P = Point.fromHex(bytes);
|
|
126
|
-
const P_even = P.
|
|
126
|
+
const P_even = P.y % 2n === 0n ? P : P.negate();
|
|
127
127
|
const Q = P_even.add(T);
|
|
128
|
-
return Q.
|
|
128
|
+
return Q.toBytes(true);
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
static generateWallet(network = networks.bitcoin) {
|
|
@@ -63,7 +63,7 @@ export interface Unisat {
|
|
|
63
63
|
switchNetwork(network: UnisatNetwork): Promise<void>;
|
|
64
64
|
getPublicKey(): Promise<string>;
|
|
65
65
|
getBalance(): Promise<Balance>;
|
|
66
|
-
signMessage(message: string, type?: MessageType): Promise<string>;
|
|
66
|
+
signMessage(message: string | Buffer, type?: MessageType): Promise<string>;
|
|
67
67
|
signData(hex: string, type?: SignatureType): Promise<string>;
|
|
68
68
|
pushTx(options: {
|
|
69
69
|
rawtx: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btc-vision/transaction",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.4",
|
|
5
5
|
"author": "BlobMaster41",
|
|
6
6
|
"description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
|
|
7
7
|
"engines": {
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
91
91
|
"@bitcoinerlab/secp256k1": "^1.2.0",
|
|
92
92
|
"@btc-vision/bitcoin": "^6.4.6",
|
|
93
|
-
"@btc-vision/bitcoin-rpc": "^1.0.
|
|
93
|
+
"@btc-vision/bitcoin-rpc": "^1.0.2",
|
|
94
94
|
"@btc-vision/logger": "^1.0.6",
|
|
95
95
|
"@eslint/js": "^9.28.0",
|
|
96
96
|
"@noble/secp256k1": "^2.2.3",
|
package/src/abi/ABICoder.ts
CHANGED
|
@@ -14,6 +14,7 @@ export enum ABIDataTypes {
|
|
|
14
14
|
BOOL = 'BOOL',
|
|
15
15
|
ADDRESS = 'ADDRESS',
|
|
16
16
|
STRING = 'STRING',
|
|
17
|
+
BYTES4 = 'BYTES4',
|
|
17
18
|
BYTES32 = 'BYTES32',
|
|
18
19
|
BYTES = 'BYTES',
|
|
19
20
|
ADDRESS_UINT256_TUPLE = 'ADDRESS_UINT256_TUPLE',
|
|
@@ -45,6 +46,9 @@ export class ABICoder {
|
|
|
45
46
|
case ABIDataTypes.UINT32:
|
|
46
47
|
result.push(byteReader.readU32());
|
|
47
48
|
break;
|
|
49
|
+
case ABIDataTypes.BYTES4:
|
|
50
|
+
result.push(byteReader.readBytes(4));
|
|
51
|
+
break;
|
|
48
52
|
case ABIDataTypes.BYTES32:
|
|
49
53
|
result.push(byteReader.readBytes(32));
|
|
50
54
|
break;
|
|
@@ -146,24 +146,26 @@ export class BinaryWriter {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
public writeString(value: string): void {
|
|
149
|
-
|
|
149
|
+
const encoder = new TextEncoder();
|
|
150
|
+
const bytes = encoder.encode(value);
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
152
|
+
this.allocSafe(bytes.length);
|
|
153
|
+
this.writeBytes(bytes);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
public
|
|
157
|
-
|
|
156
|
+
public writeStringWithLength(value: string): void {
|
|
157
|
+
const encoder = new TextEncoder();
|
|
158
|
+
const bytes = encoder.encode(value);
|
|
158
159
|
|
|
159
|
-
this.
|
|
160
|
+
this.allocSafe(U32_BYTE_LENGTH + bytes.length);
|
|
161
|
+
this.writeU32(bytes.length);
|
|
162
|
+
this.writeBytes(bytes);
|
|
160
163
|
}
|
|
161
164
|
|
|
162
|
-
public
|
|
163
|
-
this.
|
|
165
|
+
public writeAddress(value: Address): void {
|
|
166
|
+
this.verifyAddress(value);
|
|
164
167
|
|
|
165
|
-
this.
|
|
166
|
-
this.writeString(value);
|
|
168
|
+
this.writeBytes(value);
|
|
167
169
|
}
|
|
168
170
|
|
|
169
171
|
public getBuffer(clear: boolean = true): Uint8Array {
|
package/src/keypair/EcKeyPair.ts
CHANGED
|
@@ -28,7 +28,7 @@ if (!BIP32factory) {
|
|
|
28
28
|
|
|
29
29
|
secp256k1.utils.precompute(8);
|
|
30
30
|
|
|
31
|
-
const {
|
|
31
|
+
const { Point, CURVE } = secp256k1;
|
|
32
32
|
|
|
33
33
|
const TAP_TAG = utf8ToBytes('TapTweak');
|
|
34
34
|
const TAP_TAG_HASH = sha256(TAP_TAG);
|
|
@@ -272,12 +272,12 @@ export class EcKeyPair {
|
|
|
272
272
|
const P = Point.fromHex(pub);
|
|
273
273
|
const Peven = (P.y & 1n) === 0n ? P : P.negate();
|
|
274
274
|
|
|
275
|
-
const xBytes = Peven.
|
|
275
|
+
const xBytes = Peven.toBytes(true).subarray(1);
|
|
276
276
|
const tBytes = tapTweakHash(xBytes);
|
|
277
277
|
const t = mod(bytesToNumberBE(tBytes), CURVE.n);
|
|
278
278
|
|
|
279
279
|
const Q = Peven.add(Point.BASE.multiply(t));
|
|
280
|
-
return Buffer.from(Q.
|
|
280
|
+
return Buffer.from(Q.toBytes(true));
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
/**
|
|
@@ -294,9 +294,9 @@ export class EcKeyPair {
|
|
|
294
294
|
|
|
295
295
|
return pubkeys.map((bytes) => {
|
|
296
296
|
const P = Point.fromHex(bytes);
|
|
297
|
-
const P_even = P.
|
|
297
|
+
const P_even = P.y % 2n === 0n ? P : P.negate();
|
|
298
298
|
const Q = P_even.add(T);
|
|
299
|
-
return Q.
|
|
299
|
+
return Q.toBytes(true);
|
|
300
300
|
});
|
|
301
301
|
}
|
|
302
302
|
|
|
@@ -85,7 +85,7 @@ export interface Unisat {
|
|
|
85
85
|
|
|
86
86
|
getBalance(): Promise<Balance>;
|
|
87
87
|
|
|
88
|
-
signMessage(message: string, type?: MessageType): Promise<string>;
|
|
88
|
+
signMessage(message: string | Buffer, type?: MessageType): Promise<string>;
|
|
89
89
|
|
|
90
90
|
signData(hex: string, type?: SignatureType): Promise<string>;
|
|
91
91
|
|