@btc-vision/transaction 1.1.13 → 1.1.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 (41) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/buffer/BinaryReader.d.ts +2 -2
  3. package/browser/buffer/BinaryWriter.d.ts +2 -2
  4. package/browser/index.js +1 -1
  5. package/browser/index.js.LICENSE.txt +2 -0
  6. package/browser/opnet.d.ts +26 -24
  7. package/browser/transaction/browser/extensions/XverseSigner.d.ts +36 -0
  8. package/browser/transaction/browser/types/Xverse.d.ts +79 -0
  9. package/browser/utils/lengths.d.ts +16 -0
  10. package/browser/utils/types.d.ts +0 -1
  11. package/build/_version.d.ts +1 -1
  12. package/build/_version.js +1 -1
  13. package/build/buffer/BinaryReader.d.ts +2 -2
  14. package/build/buffer/BinaryReader.js +14 -12
  15. package/build/buffer/BinaryWriter.d.ts +2 -2
  16. package/build/buffer/BinaryWriter.js +12 -12
  17. package/build/keypair/Address.js +10 -8
  18. package/build/opnet.d.ts +26 -24
  19. package/build/opnet.js +26 -24
  20. package/build/transaction/TransactionFactory.js +11 -2
  21. package/build/transaction/browser/extensions/XverseSigner.d.ts +36 -0
  22. package/build/transaction/browser/extensions/XverseSigner.js +299 -0
  23. package/build/transaction/browser/types/Xverse.d.ts +79 -0
  24. package/build/transaction/browser/types/Xverse.js +6 -0
  25. package/build/utils/BufferHelper.js +2 -1
  26. package/build/utils/lengths.d.ts +16 -0
  27. package/build/utils/lengths.js +15 -0
  28. package/build/utils/types.d.ts +0 -1
  29. package/build/utils/types.js +1 -1
  30. package/package.json +1 -1
  31. package/src/_version.ts +1 -1
  32. package/src/buffer/BinaryReader.ts +24 -12
  33. package/src/buffer/BinaryWriter.ts +23 -15
  34. package/src/keypair/Address.ts +11 -9
  35. package/src/opnet.ts +26 -24
  36. package/src/transaction/TransactionFactory.ts +12 -2
  37. package/src/transaction/browser/extensions/XverseSigner.ts +429 -0
  38. package/src/transaction/browser/types/Xverse.ts +104 -0
  39. package/src/utils/BufferHelper.ts +2 -1
  40. package/src/utils/lengths.ts +20 -0
  41. package/src/utils/types.ts +0 -2
@@ -1,8 +1,17 @@
1
- import { BufferHelper } from '../utils/BufferHelper.js';
2
- import { ADDRESS_BYTE_LENGTH, i32, Selector, u16, u32, u64, u8 } from '../utils/types.js';
1
+ import { AddressMap } from '../deterministic/AddressMap.js';
3
2
  import { Address } from '../keypair/Address.js';
3
+ import { BufferHelper } from '../utils/BufferHelper.js';
4
+ import {
5
+ ADDRESS_BYTE_LENGTH,
6
+ U128_BYTE_LENGTH,
7
+ U16_BYTE_LENGTH,
8
+ U256_BYTE_LENGTH,
9
+ U32_BYTE_LENGTH,
10
+ U64_BYTE_LENGTH,
11
+ U8_BYTE_LENGTH,
12
+ } from '../utils/lengths.js';
13
+ import { i32, Selector, u16, u32, u64, u8 } from '../utils/types.js';
4
14
  import { BinaryReader } from './BinaryReader.js';
5
- import { AddressMap } from '../deterministic/AddressMap.js';
6
15
 
7
16
  export class BinaryWriter {
8
17
  private currentOffset: u32 = 0;
@@ -15,14 +24,14 @@ export class BinaryWriter {
15
24
  public writeU8(value: u8): void {
16
25
  if (value > 255) throw new Error('Value is too large.');
17
26
 
18
- this.allocSafe(1);
27
+ this.allocSafe(U8_BYTE_LENGTH);
19
28
  this.buffer.setUint8(this.currentOffset++, value);
20
29
  }
21
30
 
22
31
  public writeU16(value: u16): void {
23
32
  if (value > 65535) throw new Error('Value is too large.');
24
33
 
25
- this.allocSafe(2);
34
+ this.allocSafe(U16_BYTE_LENGTH);
26
35
  this.buffer.setUint16(this.currentOffset, value, true);
27
36
  this.currentOffset += 2;
28
37
  }
@@ -30,7 +39,7 @@ export class BinaryWriter {
30
39
  public writeU32(value: u32, le: boolean = true): void {
31
40
  if (value > 4294967295) throw new Error('Value is too large.');
32
41
 
33
- this.allocSafe(4);
42
+ this.allocSafe(U32_BYTE_LENGTH);
34
43
  this.buffer.setUint32(this.currentOffset, value, le);
35
44
  this.currentOffset += 4;
36
45
  }
@@ -38,7 +47,7 @@ export class BinaryWriter {
38
47
  public writeU64(value: u64): void {
39
48
  if (value > 18446744073709551615n) throw new Error('Value is too large.');
40
49
 
41
- this.allocSafe(8);
50
+ this.allocSafe(U64_BYTE_LENGTH);
42
51
  this.buffer.setBigUint64(this.currentOffset, value, true);
43
52
  this.currentOffset += 8;
44
53
  }
@@ -59,10 +68,10 @@ export class BinaryWriter {
59
68
  throw new Error('Value is too large.');
60
69
  }
61
70
 
62
- this.allocSafe(32);
71
+ this.allocSafe(U256_BYTE_LENGTH);
63
72
 
64
73
  const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue);
65
- if (bytesToHex.byteLength !== 32) {
74
+ if (bytesToHex.byteLength !== U256_BYTE_LENGTH) {
66
75
  throw new Error(`Invalid u256 value: ${bigIntValue}`);
67
76
  }
68
77
 
@@ -76,10 +85,10 @@ export class BinaryWriter {
76
85
  throw new Error('Value is too large.');
77
86
  }
78
87
 
79
- this.allocSafe(16);
88
+ this.allocSafe(U128_BYTE_LENGTH);
80
89
 
81
- const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue, 16);
82
- if (bytesToHex.byteLength !== 16) {
90
+ const bytesToHex = BufferHelper.valueToUint8Array(bigIntValue, U128_BYTE_LENGTH);
91
+ if (bytesToHex.byteLength !== U128_BYTE_LENGTH) {
83
92
  throw new Error(`Invalid u128 value: ${bigIntValue}`);
84
93
  }
85
94
 
@@ -111,7 +120,7 @@ export class BinaryWriter {
111
120
  }
112
121
 
113
122
  public writeStringWithLength(value: string): void {
114
- this.allocSafe(value.length + 2);
123
+ this.allocSafe(U16_BYTE_LENGTH + value.length);
115
124
 
116
125
  this.writeU16(value.length);
117
126
  this.writeString(value);
@@ -134,7 +143,7 @@ export class BinaryWriter {
134
143
  }
135
144
 
136
145
  public writeTuple(values: bigint[]): void {
137
- this.allocSafe(4 + values.length * 32);
146
+ this.allocSafe(U32_BYTE_LENGTH + values.length * U256_BYTE_LENGTH);
138
147
  this.writeU32(values.length);
139
148
 
140
149
  for (let i = 0; i < values.length; i++) {
@@ -248,7 +257,6 @@ export class BinaryWriter {
248
257
  if (value.length > 65535) throw new Error('Array size is too large');
249
258
 
250
259
  this.writeU16(value.length);
251
-
252
260
  for (let i = 0; i < value.length; i++) {
253
261
  this.writeU128(value[i]);
254
262
  }
@@ -1,8 +1,9 @@
1
1
  import { Network } from '@btc-vision/bitcoin';
2
- import { EcKeyPair } from './EcKeyPair.js';
2
+ import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
3
3
  import { ECPairInterface } from 'ecpair';
4
+ import { ADDRESS_BYTE_LENGTH } from '../utils/lengths.js';
4
5
  import { AddressVerificator } from './AddressVerificator.js';
5
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
6
+ import { EcKeyPair } from './EcKeyPair.js';
6
7
 
7
8
  const hexPattern = /^[0-9a-fA-F]+$/;
8
9
  const isHexadecimal = (input: string): boolean => {
@@ -20,7 +21,7 @@ export class Address extends Uint8Array {
20
21
  #keyPair: ECPairInterface | undefined;
21
22
 
22
23
  public constructor(bytes?: ArrayLike<number>) {
23
- super(32);
24
+ super(ADDRESS_BYTE_LENGTH);
24
25
 
25
26
  if (!bytes) {
26
27
  return;
@@ -126,7 +127,7 @@ export class Address extends Uint8Array {
126
127
  public lessThan(a: Address): boolean {
127
128
  const b: Address = this as Address;
128
129
 
129
- for (let i = 0; i < 32; i++) {
130
+ for (let i = 0; i < ADDRESS_BYTE_LENGTH; i++) {
130
131
  const thisByte = b[i];
131
132
  const aByte = a[i];
132
133
 
@@ -148,7 +149,7 @@ export class Address extends Uint8Array {
148
149
  // Compare the two addresses byte-by-byte, treating them as big-endian uint256
149
150
  const b = this as Address;
150
151
 
151
- for (let i = 0; i < 32; i++) {
152
+ for (let i = 0; i < ADDRESS_BYTE_LENGTH; i++) {
152
153
  const thisByte = b[i];
153
154
  const aByte = a[i];
154
155
 
@@ -168,12 +169,13 @@ export class Address extends Uint8Array {
168
169
  * @returns {void}
169
170
  */
170
171
  public override set(publicKey: ArrayLike<number>): void {
171
- if (publicKey.length !== 33 && publicKey.length !== 32 && publicKey.length !== 65) {
172
+ const validLengths = [ADDRESS_BYTE_LENGTH, 33, 65];
173
+ if (!validLengths.includes(publicKey.length)) {
172
174
  throw new Error(`Invalid public key length ${publicKey.length}`);
173
175
  }
174
176
 
175
- if (publicKey.length === 32) {
176
- const buf = Buffer.alloc(32);
177
+ if (publicKey.length === ADDRESS_BYTE_LENGTH) {
178
+ const buf = Buffer.alloc(ADDRESS_BYTE_LENGTH);
177
179
  buf.set(publicKey);
178
180
 
179
181
  super.set(publicKey);
@@ -228,7 +230,7 @@ export class Address extends Uint8Array {
228
230
  public toString(): string {
229
231
  return this.toHex();
230
232
  }
231
-
233
+
232
234
  /**
233
235
  * Convert the address to a JSON string
234
236
  */
package/src/opnet.ts CHANGED
@@ -4,24 +4,24 @@ export { version } from './_version.js';
4
4
  export * from './bytecode/Compressor.js';
5
5
 
6
6
  /** Generators */
7
- export * from './generators/Generator.js';
8
7
  export * from './generators/builders/CalldataGenerator.js';
9
- export * from './generators/builders/LegacyCalldataGenerator.js';
10
- export * from './generators/builders/DeploymentGenerator.js';
11
8
  export * from './generators/builders/CustomGenerator.js';
9
+ export * from './generators/builders/DeploymentGenerator.js';
10
+ export * from './generators/builders/LegacyCalldataGenerator.js';
12
11
  export * from './generators/builders/MultiSignGenerator.js';
13
12
  export * from './generators/Features.js';
13
+ export * from './generators/Generator.js';
14
14
 
15
15
  /** Address */
16
16
  export * from './generators/AddressGenerator.js';
17
17
  export * from './verification/TapscriptVerificator.js';
18
18
 
19
19
  /** Key Pair */
20
+ export * from './keypair/AddressVerificator.js';
20
21
  export * from './keypair/EcKeyPair.js';
21
- export * from './keypair/Wallet.js';
22
22
  export * from './keypair/interfaces/IWallet.js';
23
- export * from './keypair/AddressVerificator.js';
24
23
  export * from './keypair/MessageSigner.js';
24
+ export * from './keypair/Wallet.js';
25
25
 
26
26
  /** Metadata */
27
27
  export * from './metadata/ContractBaseMetadata.js';
@@ -31,19 +31,19 @@ export * from './network/ChainId.js';
31
31
  export * from './signer/TweakedSigner.js';
32
32
 
33
33
  /** Transaction */
34
- export * from './transaction/TransactionFactory.js';
34
+ export * from './transaction/enums/TransactionType.js';
35
35
  export * from './transaction/interfaces/ITransactionParameters.js';
36
36
  export * from './transaction/interfaces/Tap.js';
37
- export * from './transaction/enums/TransactionType.js';
37
+ export * from './transaction/TransactionFactory.js';
38
38
 
39
39
  /** Builders */
40
- export * from './transaction/builders/InteractionTransaction.js';
41
- export * from './transaction/builders/FundingTransaction.js';
42
- export * from './transaction/builders/TransactionBuilder.js';
43
- export * from './transaction/builders/SharedInteractionTransaction.js';
44
- export * from './transaction/builders/DeploymentTransaction.js';
45
40
  export * from './transaction/builders/CustomScriptTransaction.js';
41
+ export * from './transaction/builders/DeploymentTransaction.js';
42
+ export * from './transaction/builders/FundingTransaction.js';
43
+ export * from './transaction/builders/InteractionTransaction.js';
46
44
  export * from './transaction/builders/MultiSignTransaction.js';
45
+ export * from './transaction/builders/SharedInteractionTransaction.js';
46
+ export * from './transaction/builders/TransactionBuilder.js';
47
47
 
48
48
  /** Utils */
49
49
  export * from './utils/BitcoinUtils.js';
@@ -56,34 +56,36 @@ export * from './utxo/OPNetLimitedProvider.js';
56
56
  export * from './transaction/processor/PsbtTransaction.js';
57
57
 
58
58
  /** Shared */
59
+ export * from './transaction/psbt/PSBTTypes.js';
59
60
  export * from './transaction/shared/TweakedTransaction.js';
60
61
  export * from './utxo/interfaces/BroadcastResponse.js';
61
- export * from './transaction/psbt/PSBTTypes.js';
62
62
 
63
63
  export * from './transaction/shared/P2TR_MS.js';
64
64
 
65
65
  /** Consensus */
66
- export * from './consensus/ConsensusConfig.js';
67
66
  export * from './consensus/Consensus.js';
67
+ export * from './consensus/ConsensusConfig.js';
68
68
  export * from './consensus/metadata/RoswellConsensus.js';
69
69
 
70
70
  /** Binary */
71
- export * from './utils/BufferHelper.js';
72
- export * from './utils/types.js';
73
- export * from './keypair/Address.js';
74
- export * from './event/NetEvent.js';
75
- export * from './deterministic/DeterministicMap.js';
76
- export * from './deterministic/DeterministicSet.js';
77
- export * from './deterministic/AddressMap.js';
78
- export * from './deterministic/AddressSet.js';
79
71
  export * from './abi/ABICoder.js';
80
- export * from './buffer/BinaryWriter.js';
81
72
  export * from './buffer/BinaryReader.js';
73
+ export * from './buffer/BinaryWriter.js';
74
+ export * from './deterministic/AddressMap.js';
75
+ export * from './deterministic/AddressSet.js';
76
+ export * from './deterministic/DeterministicMap.js';
77
+ export * from './deterministic/DeterministicSet.js';
78
+ export * from './event/NetEvent.js';
79
+ export * from './keypair/Address.js';
80
+ export * from './utils/BufferHelper.js';
81
+ export * from './utils/types.js';
82
82
 
83
83
  /** Custom signers */
84
84
  export * from './transaction/browser/BrowserSignerBase.js';
85
85
  export * from './transaction/browser/extensions/UnisatSigner.js';
86
+ export * from './transaction/browser/extensions/XverseSigner.js';
86
87
  export * from './transaction/browser/types/Unisat.js';
88
+ export * from './transaction/browser/types/Xverse.js';
87
89
 
88
- export * from './transaction/browser/Web3Provider.js';
89
90
  export * from './metadata/tokens.js';
91
+ export * from './transaction/browser/Web3Provider.js';
@@ -146,6 +146,10 @@ export class TransactionFactory {
146
146
  throw new Error('Field "from" not provided.');
147
147
  }
148
148
 
149
+ if (!interactionParameters.utxos[0]) {
150
+ throw new Error('Missing at least one UTXO.');
151
+ }
152
+
149
153
  const preTransaction: InteractionTransaction = new InteractionTransaction({
150
154
  ...interactionParameters,
151
155
  utxos: [interactionParameters.utxos[0]], // we simulate one input here.
@@ -163,14 +167,20 @@ export class TransactionFactory {
163
167
  this.getPriorityFee(interactionParameters) +
164
168
  preTransaction.getOptionalOutputValue();
165
169
 
166
- const feeEstimationFundingTransaction = await this.createFundTransaction({ ...parameters });
170
+ const feeEstimationFundingTransaction = await this.createFundTransaction({
171
+ ...parameters,
172
+ optionalOutputs: [],
173
+ });
167
174
  if (!feeEstimationFundingTransaction) {
168
175
  throw new Error('Could not sign funding transaction.');
169
176
  }
170
177
 
171
178
  parameters.estimatedFees = feeEstimationFundingTransaction.estimatedFees;
172
179
 
173
- const signedTransaction = await this.createFundTransaction(parameters);
180
+ const signedTransaction = await this.createFundTransaction({
181
+ ...parameters,
182
+ optionalOutputs: [],
183
+ });
174
184
  if (!signedTransaction) {
175
185
  throw new Error('Could not sign funding transaction.');
176
186
  }