@btc-vision/transaction 1.2.13 → 1.2.15

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 (37) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/abi/ABICoder.d.ts +0 -1
  3. package/browser/buffer/BinaryReader.d.ts +0 -1
  4. package/browser/buffer/BinaryWriter.d.ts +1 -2
  5. package/browser/index.js +1 -1
  6. package/browser/transaction/TransactionFactory.d.ts +0 -7
  7. package/browser/transaction/browser/BrowserSignerBase.d.ts +1 -1
  8. package/browser/transaction/interfaces/ITransactionParameters.d.ts +2 -2
  9. package/browser/utxo/OPNetLimitedProvider.d.ts +4 -0
  10. package/build/_version.d.ts +1 -1
  11. package/build/_version.js +1 -1
  12. package/build/abi/ABICoder.d.ts +0 -1
  13. package/build/abi/ABICoder.js +0 -4
  14. package/build/buffer/BinaryReader.d.ts +0 -1
  15. package/build/buffer/BinaryReader.js +0 -8
  16. package/build/buffer/BinaryWriter.d.ts +1 -2
  17. package/build/buffer/BinaryWriter.js +1 -8
  18. package/build/transaction/TransactionFactory.d.ts +0 -7
  19. package/build/transaction/browser/BrowserSignerBase.d.ts +1 -1
  20. package/build/transaction/browser/extensions/UnisatSigner.js +1 -1
  21. package/build/transaction/builders/DeploymentTransaction.js +3 -1
  22. package/build/transaction/builders/SharedInteractionTransaction.js +4 -1
  23. package/build/transaction/interfaces/ITransactionParameters.d.ts +2 -2
  24. package/build/utxo/OPNetLimitedProvider.d.ts +4 -0
  25. package/build/utxo/OPNetLimitedProvider.js +7 -0
  26. package/package.json +1 -1
  27. package/src/_version.ts +1 -1
  28. package/src/abi/ABICoder.ts +0 -4
  29. package/src/buffer/BinaryReader.ts +0 -11
  30. package/src/buffer/BinaryWriter.ts +1 -10
  31. package/src/transaction/TransactionFactory.ts +0 -8
  32. package/src/transaction/browser/BrowserSignerBase.ts +1 -1
  33. package/src/transaction/browser/extensions/UnisatSigner.ts +1 -1
  34. package/src/transaction/builders/DeploymentTransaction.ts +3 -1
  35. package/src/transaction/builders/SharedInteractionTransaction.ts +5 -1
  36. package/src/transaction/interfaces/ITransactionParameters.ts +2 -2
  37. package/src/utxo/OPNetLimitedProvider.ts +17 -0
@@ -15,13 +15,6 @@ export interface DeploymentResult {
15
15
  readonly preimage: string;
16
16
  readonly utxos: UTXO[];
17
17
  }
18
- export interface WrapResult {
19
- readonly transaction: [string, string];
20
- readonly vaultAddress: string;
21
- readonly amount: bigint;
22
- readonly receiverAddress: string;
23
- readonly utxos: UTXO[];
24
- }
25
18
  export interface FundingTransactionResponse {
26
19
  readonly tx: Transaction;
27
20
  readonly original: FundingTransaction;
@@ -11,6 +11,6 @@ export declare abstract class CustomKeypair implements Signer {
11
11
  abstract getPublicKey(): Buffer;
12
12
  abstract sign(hash: Buffer, lowR?: boolean): Buffer;
13
13
  abstract signSchnorr(hash: Buffer): Buffer;
14
- abstract verify(hash: Buffer, signature: Buffer): boolean;
14
+ abstract verify(hash: Buffer, signature: Buffer): boolean | Buffer;
15
15
  abstract init(): Promise<void>;
16
16
  }
@@ -25,7 +25,7 @@ export interface IChallengeSolutionTransactionParameters extends ITransactionPar
25
25
  export interface SharedInteractionParameters extends ITransactionParameters {
26
26
  calldata?: Buffer;
27
27
  disableAutoRefund?: boolean;
28
- readonly preimage?: Buffer;
28
+ readonly preimage: Buffer;
29
29
  readonly randomBytes?: Buffer;
30
30
  }
31
31
  export interface IInteractionParameters extends SharedInteractionParameters {
@@ -36,5 +36,5 @@ export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'
36
36
  readonly bytecode: Buffer;
37
37
  readonly calldata?: Buffer;
38
38
  readonly randomBytes?: Buffer;
39
- readonly preimage?: Buffer;
39
+ readonly preimage: Buffer;
40
40
  }
@@ -7,6 +7,9 @@ export interface WalletUTXOs {
7
7
  readonly pending: RawUTXOResponse[];
8
8
  readonly spentTransactions: RawUTXOResponse[];
9
9
  }
10
+ export interface PreimageData {
11
+ readonly preimage: Buffer;
12
+ }
10
13
  export declare class OPNetLimitedProvider {
11
14
  private readonly opnetAPIUrl;
12
15
  private readonly utxoPath;
@@ -15,6 +18,7 @@ export declare class OPNetLimitedProvider {
15
18
  fetchUTXO(settings: FetchUTXOParams): Promise<UTXO[]>;
16
19
  fetchUTXOMultiAddr(settings: FetchUTXOParamsMultiAddress): Promise<UTXO[]>;
17
20
  broadcastTransaction(transaction: string, psbt: boolean): Promise<BroadcastResponse | undefined>;
21
+ getPreimage(): Promise<PreimageData | undefined>;
18
22
  splitUTXOs(wallet: Wallet, network: Network, splitInputsInto: number, amountPerUTXO: bigint): Promise<BroadcastResponse | {
19
23
  error: string;
20
24
  }>;
@@ -1 +1 @@
1
- export declare const version = "1.2.13";
1
+ export declare const version = "1.2.15";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.2.13';
1
+ export const version = '1.2.15';
@@ -10,7 +10,6 @@ export declare enum ABIDataTypes {
10
10
  ADDRESS = "ADDRESS",
11
11
  STRING = "STRING",
12
12
  BYTES32 = "BYTES32",
13
- TUPLE = "TUPLE",
14
13
  BYTES = "BYTES",
15
14
  ADDRESS_UINT256_TUPLE = "ADDRESS_UINT256_TUPLE",
16
15
  ARRAY_OF_ADDRESSES = "ARRAY_OF_ADDRESSES",
@@ -14,7 +14,6 @@ export var ABIDataTypes;
14
14
  ABIDataTypes["ADDRESS"] = "ADDRESS";
15
15
  ABIDataTypes["STRING"] = "STRING";
16
16
  ABIDataTypes["BYTES32"] = "BYTES32";
17
- ABIDataTypes["TUPLE"] = "TUPLE";
18
17
  ABIDataTypes["BYTES"] = "BYTES";
19
18
  ABIDataTypes["ADDRESS_UINT256_TUPLE"] = "ADDRESS_UINT256_TUPLE";
20
19
  ABIDataTypes["ARRAY_OF_ADDRESSES"] = "ARRAY_OF_ADDRESSES";
@@ -64,9 +63,6 @@ export class ABICoder {
64
63
  case ABIDataTypes.INT128:
65
64
  result.push(byteReader.readI128());
66
65
  break;
67
- case ABIDataTypes.TUPLE:
68
- result.push(byteReader.readTuple());
69
- break;
70
66
  case ABIDataTypes.ADDRESS_UINT256_TUPLE:
71
67
  result.push(byteReader.readAddressValueTuple());
72
68
  break;
@@ -19,7 +19,6 @@ export declare class BinaryReader {
19
19
  readStringArray(): string[];
20
20
  readBytesArray(): Uint8Array[];
21
21
  readBytesWithLength(maxLength?: number): Uint8Array;
22
- readTuple(): bigint[];
23
22
  readU8(): u8;
24
23
  readU16(): u16;
25
24
  readU32(le?: boolean): u32;
@@ -106,14 +106,6 @@ export class BinaryReader {
106
106
  }
107
107
  return this.readBytes(length);
108
108
  }
109
- readTuple() {
110
- const length = this.readU32();
111
- const result = new Array(length);
112
- for (let i = 0; i < length; i++) {
113
- result[i] = this.readU256();
114
- }
115
- return result;
116
- }
117
109
  readU8() {
118
110
  this.verifyEnd(this.currentOffset + U8_BYTE_LENGTH);
119
111
  const value = this.buffer.getUint8(this.currentOffset);
@@ -21,14 +21,13 @@ export declare class BinaryWriter {
21
21
  writeStringWithLength(value: string): void;
22
22
  getBuffer(clear?: boolean): Uint8Array;
23
23
  reset(): void;
24
- writeTuple(values: bigint[]): void;
25
24
  toBytesReader(): BinaryReader;
26
25
  getOffset(): u32;
27
26
  setOffset(offset: u32): void;
28
27
  clear(): void;
29
28
  allocSafe(size: u32): void;
30
29
  writeABISelector(name: string, selector: Selector): void;
31
- writeAddressValueTupleMap(map: AddressMap<bigint>): void;
30
+ writeAddressValueTuple(map: AddressMap<bigint>): void;
32
31
  writeLimitedAddressBytesMap(map: AddressMap<Uint8Array[]>): void;
33
32
  writeBytesWithLength(value: Uint8Array): void;
34
33
  writeAddressArray(value: Address[]): void;
@@ -114,13 +114,6 @@ export class BinaryWriter {
114
114
  this.currentOffset = 0;
115
115
  this.buffer = this.getDefaultBuffer(4);
116
116
  }
117
- writeTuple(values) {
118
- this.allocSafe(U32_BYTE_LENGTH + values.length * U256_BYTE_LENGTH);
119
- this.writeU32(values.length);
120
- for (let i = 0; i < values.length; i++) {
121
- this.writeU256(values[i]);
122
- }
123
- }
124
117
  toBytesReader() {
125
118
  return new BinaryReader(this.getBuffer());
126
119
  }
@@ -143,7 +136,7 @@ export class BinaryWriter {
143
136
  this.writeStringWithLength(name);
144
137
  this.writeSelector(selector);
145
138
  }
146
- writeAddressValueTupleMap(map) {
139
+ writeAddressValueTuple(map) {
147
140
  if (map.size > 65535)
148
141
  throw new Error('Map size is too large');
149
142
  this.writeU16(map.size);
@@ -15,13 +15,6 @@ export interface DeploymentResult {
15
15
  readonly preimage: string;
16
16
  readonly utxos: UTXO[];
17
17
  }
18
- export interface WrapResult {
19
- readonly transaction: [string, string];
20
- readonly vaultAddress: string;
21
- readonly amount: bigint;
22
- readonly receiverAddress: string;
23
- readonly utxos: UTXO[];
24
- }
25
18
  export interface FundingTransactionResponse {
26
19
  readonly tx: Transaction;
27
20
  readonly original: FundingTransaction;
@@ -11,6 +11,6 @@ export declare abstract class CustomKeypair implements Signer {
11
11
  abstract getPublicKey(): Buffer;
12
12
  abstract sign(hash: Buffer, lowR?: boolean): Buffer;
13
13
  abstract signSchnorr(hash: Buffer): Buffer;
14
- abstract verify(hash: Buffer, signature: Buffer): boolean;
14
+ abstract verify(hash: Buffer, signature: Buffer): boolean | Buffer;
15
15
  abstract init(): Promise<void>;
16
16
  }
@@ -1,4 +1,4 @@
1
- import { crypto as bitCrypto, script as bitScript, networks, Psbt, toXOnly, } from '@btc-vision/bitcoin';
1
+ import { crypto as bitCrypto, networks, Psbt, script as bitScript, toXOnly, } from '@btc-vision/bitcoin';
2
2
  import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
3
3
  import { canSignNonTaprootInput, isTaprootInput } from '../../../signer/SignerUtils.js';
4
4
  import { CustomKeypair } from '../BrowserSignerBase.js';
@@ -41,8 +41,10 @@ export class DeploymentTransaction extends TransactionBuilder {
41
41
  this.calldata = parameters.calldata;
42
42
  this.verifyCalldata();
43
43
  }
44
+ if (!parameters.preimage)
45
+ throw new Error('Preimage is required');
44
46
  this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
45
- this.preimage = parameters.preimage || BitcoinUtils.getSafeRandomValues(128);
47
+ this.preimage = parameters.preimage;
46
48
  this.rewardChallenge = ChallengeGenerator.generateMineableReward(this.preimage, this.network);
47
49
  this.contractSeed = this.getContractSeed();
48
50
  this.contractSigner = EcKeyPair.fromSeedKeyPair(this.contractSeed, this.network);
@@ -28,7 +28,10 @@ export class SharedInteractionTransaction extends TransactionBuilder {
28
28
  if (!parameters.calldata) {
29
29
  throw new Error('Calldata is required');
30
30
  }
31
- this.preimage = parameters.preimage || BitcoinUtils.getSafeRandomValues(128);
31
+ if (!parameters.preimage) {
32
+ throw new Error('Preimage is required');
33
+ }
34
+ this.preimage = parameters.preimage;
32
35
  this.disableAutoRefund = parameters.disableAutoRefund || false;
33
36
  this.rewardChallenge = ChallengeGenerator.generateMineableReward(this.preimage, this.network);
34
37
  this.calldata = Compressor.compress(parameters.calldata);
@@ -25,7 +25,7 @@ export interface IChallengeSolutionTransactionParameters extends ITransactionPar
25
25
  export interface SharedInteractionParameters extends ITransactionParameters {
26
26
  calldata?: Buffer;
27
27
  disableAutoRefund?: boolean;
28
- readonly preimage?: Buffer;
28
+ readonly preimage: Buffer;
29
29
  readonly randomBytes?: Buffer;
30
30
  }
31
31
  export interface IInteractionParameters extends SharedInteractionParameters {
@@ -36,5 +36,5 @@ export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'
36
36
  readonly bytecode: Buffer;
37
37
  readonly calldata?: Buffer;
38
38
  readonly randomBytes?: Buffer;
39
- readonly preimage?: Buffer;
39
+ readonly preimage: Buffer;
40
40
  }
@@ -7,6 +7,9 @@ export interface WalletUTXOs {
7
7
  readonly pending: RawUTXOResponse[];
8
8
  readonly spentTransactions: RawUTXOResponse[];
9
9
  }
10
+ export interface PreimageData {
11
+ readonly preimage: Buffer;
12
+ }
10
13
  export declare class OPNetLimitedProvider {
11
14
  private readonly opnetAPIUrl;
12
15
  private readonly utxoPath;
@@ -15,6 +18,7 @@ export declare class OPNetLimitedProvider {
15
18
  fetchUTXO(settings: FetchUTXOParams): Promise<UTXO[]>;
16
19
  fetchUTXOMultiAddr(settings: FetchUTXOParamsMultiAddress): Promise<UTXO[]>;
17
20
  broadcastTransaction(transaction: string, psbt: boolean): Promise<BroadcastResponse | undefined>;
21
+ getPreimage(): Promise<PreimageData | undefined>;
18
22
  splitUTXOs(wallet: Wallet, network: Network, splitInputsInto: number, amountPerUTXO: bigint): Promise<BroadcastResponse | {
19
23
  error: string;
20
24
  }>;
@@ -103,6 +103,13 @@ export class OPNetLimitedProvider {
103
103
  }
104
104
  return result;
105
105
  }
106
+ async getPreimage() {
107
+ const result = await this.rpcMethod('btc_preimage', []);
108
+ if (!result) {
109
+ return;
110
+ }
111
+ return result;
112
+ }
106
113
  async splitUTXOs(wallet, network, splitInputsInto, amountPerUTXO) {
107
114
  const utxoSetting = {
108
115
  addresses: [wallet.p2wpkh, wallet.p2tr],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.2.13",
4
+ "version": "1.2.15",
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.2.13';
1
+ export const version = '1.2.15';
@@ -15,7 +15,6 @@ export enum ABIDataTypes {
15
15
  ADDRESS = 'ADDRESS',
16
16
  STRING = 'STRING',
17
17
  BYTES32 = 'BYTES32',
18
- TUPLE = 'TUPLE',
19
18
  BYTES = 'BYTES',
20
19
  ADDRESS_UINT256_TUPLE = 'ADDRESS_UINT256_TUPLE',
21
20
  ARRAY_OF_ADDRESSES = 'ARRAY_OF_ADDRESSES',
@@ -67,9 +66,6 @@ export class ABICoder {
67
66
  case ABIDataTypes.INT128:
68
67
  result.push(byteReader.readI128());
69
68
  break;
70
- case ABIDataTypes.TUPLE: // very basic for now, only contains uint256
71
- result.push(byteReader.readTuple());
72
- break;
73
69
  case ABIDataTypes.ADDRESS_UINT256_TUPLE:
74
70
  result.push(byteReader.readAddressValueTuple());
75
71
  break;
@@ -152,17 +152,6 @@ export class BinaryReader {
152
152
  return this.readBytes(length);
153
153
  }
154
154
 
155
- public readTuple(): bigint[] {
156
- const length = this.readU32();
157
- const result: bigint[] = new Array<bigint>(length);
158
-
159
- for (let i = 0; i < length; i++) {
160
- result[i] = this.readU256();
161
- }
162
-
163
- return result;
164
- }
165
-
166
155
  public readU8(): u8 {
167
156
  this.verifyEnd(this.currentOffset + U8_BYTE_LENGTH);
168
157
 
@@ -163,15 +163,6 @@ export class BinaryWriter {
163
163
  this.buffer = this.getDefaultBuffer(4);
164
164
  }
165
165
 
166
- public writeTuple(values: bigint[]): void {
167
- this.allocSafe(U32_BYTE_LENGTH + values.length * U256_BYTE_LENGTH);
168
- this.writeU32(values.length);
169
-
170
- for (let i = 0; i < values.length; i++) {
171
- this.writeU256(values[i]);
172
- }
173
- }
174
-
175
166
  public toBytesReader(): BinaryReader {
176
167
  return new BinaryReader(this.getBuffer());
177
168
  }
@@ -200,7 +191,7 @@ export class BinaryWriter {
200
191
  this.writeSelector(selector);
201
192
  }
202
193
 
203
- public writeAddressValueTupleMap(map: AddressMap<bigint>): void {
194
+ public writeAddressValueTuple(map: AddressMap<bigint>): void {
204
195
  if (map.size > 65535) throw new Error('Map size is too large');
205
196
 
206
197
  this.writeU16(map.size);
@@ -33,14 +33,6 @@ export interface DeploymentResult {
33
33
  readonly utxos: UTXO[];
34
34
  }
35
35
 
36
- export interface WrapResult {
37
- readonly transaction: [string, string];
38
- readonly vaultAddress: string;
39
- readonly amount: bigint;
40
- readonly receiverAddress: string;
41
- readonly utxos: UTXO[];
42
- }
43
-
44
36
  export interface FundingTransactionResponse {
45
37
  readonly tx: Transaction;
46
38
  readonly original: FundingTransaction;
@@ -30,7 +30,7 @@ export abstract class CustomKeypair implements Signer {
30
30
 
31
31
  public abstract signSchnorr(hash: Buffer): Buffer;
32
32
 
33
- public abstract verify(hash: Buffer, signature: Buffer): boolean;
33
+ public abstract verify(hash: Buffer, signature: Buffer): boolean | Buffer;
34
34
 
35
35
  public abstract init(): Promise<void>;
36
36
  }
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  crypto as bitCrypto,
3
- script as bitScript,
4
3
  Network,
5
4
  networks,
6
5
  Psbt,
6
+ script as bitScript,
7
7
  TapScriptSig,
8
8
  toXOnly,
9
9
  } from '@btc-vision/bitcoin';
@@ -118,8 +118,10 @@ export class DeploymentTransaction extends TransactionBuilder<TransactionType.DE
118
118
  this.verifyCalldata();
119
119
  }
120
120
 
121
+ if(!parameters.preimage) throw new Error('Preimage is required');
122
+
121
123
  this.randomBytes = parameters.randomBytes || BitcoinUtils.rndBytes();
122
- this.preimage = parameters.preimage || BitcoinUtils.getSafeRandomValues(128);
124
+ this.preimage = parameters.preimage;
123
125
 
124
126
  this.rewardChallenge = ChallengeGenerator.generateMineableReward(
125
127
  this.preimage,
@@ -67,7 +67,11 @@ export abstract class SharedInteractionTransaction<
67
67
  throw new Error('Calldata is required');
68
68
  }
69
69
 
70
- this.preimage = parameters.preimage || BitcoinUtils.getSafeRandomValues(128);
70
+ if(!parameters.preimage) {
71
+ throw new Error('Preimage is required');
72
+ }
73
+
74
+ this.preimage = parameters.preimage;
71
75
 
72
76
  this.disableAutoRefund = parameters.disableAutoRefund || false;
73
77
  this.rewardChallenge = ChallengeGenerator.generateMineableReward(
@@ -37,7 +37,7 @@ export interface SharedInteractionParameters extends ITransactionParameters {
37
37
  calldata?: Buffer;
38
38
  disableAutoRefund?: boolean;
39
39
 
40
- readonly preimage?: Buffer;
40
+ readonly preimage: Buffer;
41
41
  readonly randomBytes?: Buffer;
42
42
  }
43
43
 
@@ -52,5 +52,5 @@ export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'
52
52
  readonly calldata?: Buffer;
53
53
 
54
54
  readonly randomBytes?: Buffer;
55
- readonly preimage?: Buffer;
55
+ readonly preimage: Buffer;
56
56
  }
@@ -14,6 +14,10 @@ export interface WalletUTXOs {
14
14
  readonly spentTransactions: RawUTXOResponse[];
15
15
  }
16
16
 
17
+ export interface PreimageData {
18
+ readonly preimage: Buffer;
19
+ }
20
+
17
21
  /**
18
22
  * Allows to fetch UTXO data from any OPNET node
19
23
  */
@@ -177,6 +181,19 @@ export class OPNetLimitedProvider {
177
181
  return result as BroadcastResponse;
178
182
  }
179
183
 
184
+ /**
185
+ * Fetches the preimage from the OPNET node
186
+ * @returns {Promise<PreimageData | undefined>} - The preimage fetched
187
+ */
188
+ public async getPreimage(): Promise<PreimageData | undefined> {
189
+ const result = await this.rpcMethod('btc_preimage', []);
190
+ if (!result) {
191
+ return;
192
+ }
193
+
194
+ return result as PreimageData;
195
+ }
196
+
180
197
  /**
181
198
  * Splits UTXOs into smaller UTXOs
182
199
  * @param {Wallet} wallet - The wallet to split UTXOs