@btc-vision/transaction 1.0.122 → 1.1.0

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 (71) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/consensus/ConsensusConfig.d.ts +0 -4
  3. package/browser/index.js +1 -1
  4. package/browser/opnet.d.ts +0 -6
  5. package/browser/transaction/TransactionFactory.d.ts +1 -13
  6. package/browser/transaction/browser/Web3Provider.d.ts +2 -6
  7. package/browser/transaction/browser/extensions/UnisatSigner.d.ts +3 -0
  8. package/browser/transaction/interfaces/ITransactionParameters.d.ts +0 -14
  9. package/browser/transaction/processor/PsbtTransaction.d.ts +0 -15
  10. package/browser/utils/BitcoinUtils.d.ts +0 -3
  11. package/browser/utxo/OPNetLimitedProvider.d.ts +1 -5
  12. package/build/_version.d.ts +1 -1
  13. package/build/_version.js +1 -1
  14. package/build/consensus/ConsensusConfig.d.ts +0 -4
  15. package/build/consensus/metadata/RoswellConsensus.js +0 -4
  16. package/build/opnet.d.ts +0 -6
  17. package/build/opnet.js +0 -6
  18. package/build/transaction/TransactionFactory.d.ts +1 -13
  19. package/build/transaction/TransactionFactory.js +1 -161
  20. package/build/transaction/browser/Web3Provider.d.ts +2 -6
  21. package/build/transaction/browser/extensions/UnisatSigner.d.ts +3 -0
  22. package/build/transaction/browser/extensions/UnisatSigner.js +65 -3
  23. package/build/transaction/builders/SharedInteractionTransaction.js +4 -4
  24. package/build/transaction/interfaces/ITransactionParameters.d.ts +0 -14
  25. package/build/transaction/processor/PsbtTransaction.d.ts +0 -15
  26. package/build/transaction/processor/PsbtTransaction.js +0 -9
  27. package/build/utils/BitcoinUtils.d.ts +0 -3
  28. package/build/utils/BitcoinUtils.js +0 -19
  29. package/build/utxo/OPNetLimitedProvider.d.ts +1 -5
  30. package/build/utxo/OPNetLimitedProvider.js +0 -28
  31. package/package.json +1 -2
  32. package/src/_version.ts +1 -1
  33. package/src/consensus/ConsensusConfig.ts +4 -4
  34. package/src/consensus/metadata/RoswellConsensus.ts +4 -4
  35. package/src/opnet.ts +6 -6
  36. package/src/transaction/TransactionFactory.ts +13 -25
  37. package/src/transaction/browser/Web3Provider.ts +1 -9
  38. package/src/transaction/browser/extensions/UnisatSigner.ts +83 -3
  39. package/src/transaction/builders/SharedInteractionTransaction.ts +16 -6
  40. package/src/transaction/builders/{WrapTransaction.ts → WrapTransaction.ts.disabled} +1 -1
  41. package/src/transaction/interfaces/ITransactionParameters.ts +2 -5
  42. package/src/transaction/processor/PsbtTransaction.ts +4 -4
  43. package/src/utils/BitcoinUtils.ts +4 -5
  44. package/src/utxo/OPNetLimitedProvider.ts +5 -9
  45. package/{src/wbtc/Generate.ts → wbtc_disabled/Generate.ts.disabled} +1 -1
  46. package/{src/wbtc/UnwrapGeneration.ts → wbtc_disabled/UnwrapGeneration.ts.disabled} +1 -1
  47. package/browser/metadata/contracts/wBTC.d.ts +0 -13
  48. package/browser/transaction/builders/UnwrapSegwitTransaction.d.ts +0 -32
  49. package/browser/transaction/builders/UnwrapTransaction.d.ts +0 -41
  50. package/browser/transaction/builders/WrapTransaction.d.ts +0 -29
  51. package/browser/wbtc/Generate.d.ts +0 -18
  52. package/browser/wbtc/UnwrapGeneration.d.ts +0 -7
  53. package/browser/wbtc/WrappedGenerationParameters.d.ts +0 -10
  54. package/build/metadata/contracts/wBTC.d.ts +0 -13
  55. package/build/metadata/contracts/wBTC.js +0 -34
  56. package/build/transaction/builders/UnwrapSegwitTransaction.d.ts +0 -32
  57. package/build/transaction/builders/UnwrapSegwitTransaction.js +0 -179
  58. package/build/transaction/builders/UnwrapTransaction.d.ts +0 -41
  59. package/build/transaction/builders/UnwrapTransaction.js +0 -258
  60. package/build/transaction/builders/WrapTransaction.d.ts +0 -29
  61. package/build/transaction/builders/WrapTransaction.js +0 -146
  62. package/build/wbtc/Generate.d.ts +0 -18
  63. package/build/wbtc/Generate.js +0 -1
  64. package/build/wbtc/UnwrapGeneration.d.ts +0 -7
  65. package/build/wbtc/UnwrapGeneration.js +0 -6
  66. package/build/wbtc/WrappedGenerationParameters.d.ts +0 -10
  67. package/build/wbtc/WrappedGenerationParameters.js +0 -10
  68. package/src/metadata/contracts/wBTC.ts +0 -59
  69. /package/src/transaction/builders/{UnwrapSegwitTransaction.ts → UnwrapSegwitTransaction.ts.disabled} +0 -0
  70. /package/src/transaction/builders/{UnwrapTransaction.ts → UnwrapTransaction.ts.disabled} +0 -0
  71. /package/{src/wbtc/WrappedGenerationParameters.ts → wbtc_disabled/WrappedGenerationParameters.ts.disabled} +0 -0
@@ -1,9 +1,6 @@
1
1
  import { UTXO } from '../../utxo/interfaces/IUTXO.js';
2
- import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
3
2
  import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
4
- import { VaultUTXOs } from '../processor/PsbtTransaction.js';
5
3
  import { ChainId } from '../../network/ChainId.js';
6
- import { Address } from '../../keypair/Address.js';
7
4
  import { PsbtOutputExtended } from '@btc-vision/bitcoin';
8
5
  export interface ITransactionParameters extends ITweakedTransactionData {
9
6
  readonly from?: string;
@@ -29,17 +26,6 @@ export interface IInteractionParameters extends Omit<SharedInteractionParameters
29
26
  readonly calldata: Buffer;
30
27
  readonly to: string;
31
28
  }
32
- export interface IWrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
33
- readonly to?: string;
34
- readonly from: string;
35
- readonly amount: bigint;
36
- readonly receiver?: Address;
37
- readonly generationParameters: WrappedGeneration;
38
- }
39
- export interface IUnwrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
40
- readonly unwrapUTXOs: VaultUTXOs[];
41
- readonly amount: bigint;
42
- }
43
29
  export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'> {
44
30
  readonly bytecode: Buffer;
45
31
  readonly calldata?: Buffer;
@@ -5,20 +5,6 @@ export interface PsbtTransactionData extends ITweakedTransactionData {
5
5
  readonly signer: Signer;
6
6
  readonly network: Network;
7
7
  }
8
- export interface IWBTCUTXODocument {
9
- readonly vault: string;
10
- readonly blockId: bigint;
11
- readonly hash: string;
12
- readonly value: bigint;
13
- readonly outputIndex: number;
14
- readonly output: string;
15
- }
16
- export interface VaultUTXOs {
17
- readonly vault: string;
18
- readonly publicKeys: string[];
19
- readonly minimum: number;
20
- readonly utxos: IWBTCUTXODocument[];
21
- }
22
8
  export type FromBase64Params = Omit<PsbtTransactionData, 'psbt'>;
23
9
  export declare class PsbtTransaction extends TweakedTransaction {
24
10
  readonly logColor: string;
@@ -36,5 +22,4 @@ export declare class PsbtTransaction extends TweakedTransaction {
36
22
  addOutput(output: PsbtOutputExtended): void;
37
23
  attemptFinalizeInputs(n?: number): boolean;
38
24
  getPSBT(): Psbt;
39
- private getTotalOutputAmount;
40
25
  }
@@ -77,13 +77,4 @@ export class PsbtTransaction extends TweakedTransaction {
77
77
  getPSBT() {
78
78
  return this.transaction;
79
79
  }
80
- getTotalOutputAmount(vaults) {
81
- let total = BigInt(0);
82
- for (const vault of vaults) {
83
- for (const utxo of vault.utxos) {
84
- total += BigInt(utxo.value);
85
- }
86
- }
87
- return total;
88
- }
89
80
  }
@@ -1,9 +1,6 @@
1
- import { VaultUTXOs } from '../transaction/processor/PsbtTransaction.js';
2
1
  export declare class BitcoinUtils {
3
2
  static btcToSatoshi(btc: number): bigint;
4
3
  static rndBytes(): Buffer;
5
4
  static getUnsafeRandomValues(length: number): Buffer;
6
5
  static opnetHash(data: Buffer): string;
7
- static orderVaultsByAddress(vaults: VaultUTXOs[]): VaultUTXOs[];
8
- static findVaultWithMostPublicKeys(vaults: VaultUTXOs[]): VaultUTXOs;
9
6
  }
@@ -28,23 +28,4 @@ export class BitcoinUtils {
28
28
  const hash = hashed.digest();
29
29
  return `0x${Buffer.from(hash).toString('hex')}`;
30
30
  }
31
- static orderVaultsByAddress(vaults) {
32
- return vaults.sort((a, b) => {
33
- return a.vault.localeCompare(b.vault);
34
- });
35
- }
36
- static findVaultWithMostPublicKeys(vaults) {
37
- vaults = BitcoinUtils.orderVaultsByAddress(vaults);
38
- let mostPublicKeys = 0;
39
- let vault;
40
- for (const v of vaults) {
41
- if (v.publicKeys.length > mostPublicKeys) {
42
- mostPublicKeys = v.publicKeys.length;
43
- vault = v;
44
- }
45
- }
46
- if (!vault)
47
- throw new Error('No vault with public keys found.');
48
- return vault;
49
- }
50
31
  }
@@ -1,7 +1,5 @@
1
1
  import { Network } from '@btc-vision/bitcoin';
2
- import { Address, Wallet } from '../opnet.js';
3
- import { UnwrapGeneration } from '../wbtc/UnwrapGeneration.js';
4
- import { WrappedGeneration } from '../wbtc/WrappedGenerationParameters.js';
2
+ import { Wallet } from '../opnet.js';
5
3
  import { BroadcastResponse } from './interfaces/BroadcastResponse.js';
6
4
  import { FetchUTXOParams, FetchUTXOParamsMultiAddress, RawUTXOResponse, UTXO } from './interfaces/IUTXO.js';
7
5
  export interface WalletUTXOs {
@@ -21,6 +19,4 @@ export declare class OPNetLimitedProvider {
21
19
  error: string;
22
20
  }>;
23
21
  rpcMethod(method: string, paramsMethod: unknown[]): Promise<unknown>;
24
- fetchWrapParameters(amount: bigint): Promise<WrappedGeneration | undefined>;
25
- fetchUnWrapParameters(amount: bigint, receiver: Address): Promise<UnwrapGeneration | undefined>;
26
22
  }
@@ -1,7 +1,4 @@
1
- import { currentConsensusConfig } from '../consensus/ConsensusConfig.js';
2
1
  import { TransactionFactory } from '../opnet.js';
3
- import { UnwrapGeneration } from '../wbtc/UnwrapGeneration.js';
4
- import { WrappedGeneration } from '../wbtc/WrappedGenerationParameters.js';
5
2
  export class OPNetLimitedProvider {
6
3
  constructor(opnetAPIUrl) {
7
4
  this.opnetAPIUrl = opnetAPIUrl;
@@ -164,29 +161,4 @@ export class OPNetLimitedProvider {
164
161
  }
165
162
  return result;
166
163
  }
167
- async fetchWrapParameters(amount) {
168
- if (amount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
169
- throw new Error(`Amount must be greater than the minimum consolidation amount ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT}sat.`);
170
- }
171
- const params = [0, amount.toString()];
172
- const result = await this.rpcMethod('btc_generate', params);
173
- if (!result) {
174
- return;
175
- }
176
- return new WrappedGeneration(result);
177
- }
178
- async fetchUnWrapParameters(amount, receiver) {
179
- if (amount < 330n) {
180
- throw new Error(`Amount must be greater than the minimum consolidation amount ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT}sat.`);
181
- }
182
- if (receiver.length < 50) {
183
- throw new Error('Invalid receiver address');
184
- }
185
- const params = [1, amount.toString(), receiver.toHex()];
186
- const result = await this.rpcMethod('btc_generate', params);
187
- if (!result) {
188
- return;
189
- }
190
- return new UnwrapGeneration(result);
191
- }
192
164
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.0.122",
4
+ "version": "1.1.0",
5
5
  "author": "BlobMaster41",
6
6
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
7
7
  "engines": {
@@ -102,7 +102,6 @@
102
102
  "babel-preset-react": "^6.24.1",
103
103
  "babelify": "^10.0.0",
104
104
  "bech32": "^2.0.0",
105
- "bignumber.js": "^9.1.2",
106
105
  "bip32": "^5.0.0-rc.0",
107
106
  "browserify-zlib": "^0.2.0",
108
107
  "buffer": "^6.0.3",
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.122';
1
+ export const version = '1.1.0';
@@ -13,20 +13,20 @@ export interface ConsensusConfig<T extends Consensus> {
13
13
 
14
14
  /** WBTC vaults */
15
15
  // Defines the minimum amount that can be consolidated in a single transaction.
16
- readonly VAULT_MINIMUM_AMOUNT: bigint;
16
+ //readonly VAULT_MINIMUM_AMOUNT: bigint;
17
17
 
18
18
  // Defines the requested minimum acceptance for joining UTXOs when an unwrap is being done.
19
19
  // If the consolidate output going back to the vault is lower than this amount, the transaction will be rejected.
20
20
  // User must pay for the consolidation, this help the network by having fewer UTXOs.
21
- readonly VAULT_NETWORK_CONSOLIDATION_ACCEPTANCE: bigint;
21
+ //readonly VAULT_NETWORK_CONSOLIDATION_ACCEPTANCE: bigint;
22
22
 
23
23
  // Everytime an user wrap bitcoin, he prepays the fees for the consolidation at a maximum fee rate of the following determined value.
24
24
  // If the fees are lower, the user will be refunded the difference.
25
25
  // If the fees are higher, the user must pay the difference.
26
- readonly UNWRAP_CONSOLIDATION_PREPAID_FEES: bigint;
26
+ //readonly UNWRAP_CONSOLIDATION_PREPAID_FEES: bigint;
27
27
 
28
28
  // The maximum fee rate for the consolidation.
29
- readonly UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT: bigint;
29
+ //readonly UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT: bigint;
30
30
  }
31
31
 
32
32
  export const OPNetConsensusConfig: { [key in Consensus]?: ConsensusConfig<key> } = {
@@ -9,18 +9,18 @@ export const RoswellConsensus: ConsensusConfig<Consensus.Roswell> = {
9
9
  ENABLED_AT_BLOCK: 0n,
10
10
 
11
11
  // Defines the minimum amount that can be consolidated in a single transaction.
12
- VAULT_MINIMUM_AMOUNT: 200000n,
12
+ //VAULT_MINIMUM_AMOUNT: 200000n,
13
13
 
14
14
  // Defines the requested minimum acceptance for joining UTXOs when an unwrap is being done.
15
15
  // If the consolidate output going back to the vault is lower than this amount, the transaction will be rejected.
16
16
  // User must pay for the consolidation, this help the network by having fewer UTXOs.
17
- VAULT_NETWORK_CONSOLIDATION_ACCEPTANCE: 200000n * 2n,
17
+ //VAULT_NETWORK_CONSOLIDATION_ACCEPTANCE: 200000n * 2n,
18
18
 
19
19
  // Everytime an user wrap bitcoin, he prepays the fees for the consolidation at a maximum fee rate of the following determined value.
20
20
  // If the fees are lower, the user will be refunded the difference.
21
21
  // If the fees are higher, the user must pay the difference.
22
- UNWRAP_CONSOLIDATION_PREPAID_FEES: 250n,
22
+ //UNWRAP_CONSOLIDATION_PREPAID_FEES: 250n,
23
23
 
24
24
  // Equivalent to 56500 satoshis, calculated from UNWRAP_CONSOLIDATION_PREPAID_FEES.
25
- UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT: 56500n,
25
+ //UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT: 56500n,
26
26
  };
package/src/opnet.ts CHANGED
@@ -23,7 +23,7 @@ export * from './keypair/interfaces/IWallet.js';
23
23
  export * from './keypair/AddressVerificator.js';
24
24
 
25
25
  /** Metadata */
26
- export * from './metadata/contracts/wBTC.js';
26
+ //export * from './metadata/contracts/wBTC.js';
27
27
  export * from './metadata/ContractBaseMetadata.js';
28
28
 
29
29
  /** Signer */
@@ -39,16 +39,16 @@ export * from './transaction/enums/TransactionType.js';
39
39
  export * from './transaction/builders/InteractionTransaction.js';
40
40
  export * from './transaction/builders/FundingTransaction.js';
41
41
  export * from './transaction/builders/TransactionBuilder.js';
42
- export * from './transaction/builders/WrapTransaction.js';
42
+ //export * from './transaction/builders/WrapTransaction.ts.disabled';
43
43
  export * from './transaction/builders/SharedInteractionTransaction.js';
44
44
  export * from './transaction/builders/DeploymentTransaction.js';
45
- export * from './transaction/builders/UnwrapTransaction.js';
45
+ //export * from './transaction/builders/UnwrapTransaction.ts.disabled';
46
46
  export * from './transaction/builders/CustomScriptTransaction.js';
47
47
  export * from './transaction/builders/MultiSignTransaction.js';
48
48
 
49
49
  /** wBTC */
50
- export * from './wbtc/WrappedGenerationParameters.js';
51
- export * from './wbtc/Generate.js';
50
+ //export * from '../wbtc_disabled/WrappedGenerationParameters.js';
51
+ //export * from '../wbtc_disabled/Generate.js';
52
52
  export * from './network/ChainId.js';
53
53
 
54
54
  /** Utils */
@@ -67,7 +67,7 @@ export * from './utxo/interfaces/BroadcastResponse.js';
67
67
  export * from './transaction/psbt/PSBTTypes.js';
68
68
 
69
69
  export * from './transaction/shared/P2TR_MS.js';
70
- export * from './wbtc/UnwrapGeneration.js';
70
+ //export * from '../wbtc_disabled/UnwrapGeneration.ts.disabled';
71
71
 
72
72
  /** Consensus */
73
73
  export * from './consensus/ConsensusConfig.js';
@@ -1,7 +1,6 @@
1
- import { Psbt, Transaction } from '@btc-vision/bitcoin';
1
+ import { Transaction } from '@btc-vision/bitcoin';
2
2
  import { Output } from '@btc-vision/bitcoin/src/transaction.js';
3
- import { currentConsensus, currentConsensusConfig } from '../consensus/ConsensusConfig.js';
4
- import { wBTC } from '../metadata/contracts/wBTC.js';
3
+ import { currentConsensus } from '../consensus/ConsensusConfig.js';
5
4
  import { UTXO } from '../utxo/interfaces/IUTXO.js';
6
5
  import {
7
6
  CustomScriptTransaction,
@@ -11,19 +10,13 @@ import { DeploymentTransaction } from './builders/DeploymentTransaction.js';
11
10
  import { FundingTransaction } from './builders/FundingTransaction.js';
12
11
  import { InteractionTransaction } from './builders/InteractionTransaction.js';
13
12
  import { TransactionBuilder } from './builders/TransactionBuilder.js';
14
- import { UnwrapSegwitTransaction } from './builders/UnwrapSegwitTransaction.js';
15
- import { UnwrapTransaction } from './builders/UnwrapTransaction.js';
16
- import { WrapTransaction } from './builders/WrapTransaction.js';
17
13
  import { TransactionType } from './enums/TransactionType.js';
18
14
  import {
19
15
  IDeploymentParameters,
20
16
  IFundingTransactionParameters,
21
17
  IInteractionParameters,
22
18
  ITransactionParameters,
23
- IUnwrapParameters,
24
- IWrapParameters,
25
19
  } from './interfaces/ITransactionParameters.js';
26
- import { VaultUTXOs } from './processor/PsbtTransaction.js';
27
20
  import { PSBTTypes } from './psbt/PSBTTypes.js';
28
21
 
29
22
  export interface DeploymentResult {
@@ -58,20 +51,14 @@ export interface BitcoinTransferResponse {
58
51
  readonly nextUTXOs: UTXO[];
59
52
  }
60
53
 
61
- export interface UnwrapResult {
54
+ /*export interface UnwrapResult {
62
55
  readonly fundingTransaction: string;
63
56
  readonly psbt: string;
64
57
 
65
- /**
66
- * @description The fee refund or loss.
67
- * @description If the amount is negative, it means that the user has to pay the difference. The difference is deducted from the amount.
68
- * @description If the amount is positive, it means that the user will be refunded the difference.
69
- * @type {bigint}
70
- */
71
58
  readonly feeRefundOrLoss: bigint;
72
59
 
73
60
  readonly utxos: UTXO[];
74
- }
61
+ }*/
75
62
 
76
63
  export class TransactionFactory {
77
64
  /**
@@ -290,7 +277,7 @@ export class TransactionFactory {
290
277
  * @returns {Promise<WrapResult>} - The signed transaction
291
278
  * @throws {Error} - If the transaction could not be signed
292
279
  */
293
- public async wrap(wrapParameters: Omit<IWrapParameters, 'calldata'>): Promise<WrapResult> {
280
+ /*public async wrap(wrapParameters: Omit<IWrapParameters, 'calldata'>): Promise<WrapResult> {
294
281
  if (wrapParameters.amount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
295
282
  throw new Error(
296
283
  `Amount is too low. Minimum consolidation is ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT} sat. Received ${wrapParameters.amount} sat. Make sure that you cover the unwrap consolidation fees of ${currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT}sat.`,
@@ -348,7 +335,7 @@ export class TransactionFactory {
348
335
  receiverAddress: finalTransaction.receiver.p2tr(wrapParameters.network),
349
336
  utxos: this.getUTXOAsTransaction(signedTransaction.tx, wrapParameters.from, 1),
350
337
  };
351
- }
338
+ }*/
352
339
 
353
340
  /**
354
341
  * Unwrap bitcoin.
@@ -357,7 +344,7 @@ export class TransactionFactory {
357
344
  * @throws {Error} - If the transaction could not be signed
358
345
  * @deprecated
359
346
  */
360
- public async unwrapSegwit(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult> {
347
+ /*public async unwrapSegwit(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult> {
361
348
  console.error('The "unwrap" method is deprecated. Use unwrapTap instead.');
362
349
 
363
350
  const transaction: UnwrapSegwitTransaction = new UnwrapSegwitTransaction(unwrapParameters);
@@ -424,7 +411,7 @@ export class TransactionFactory {
424
411
  feeRefundOrLoss: estimatedFees,
425
412
  utxos: [],
426
413
  };
427
- }
414
+ }*/
428
415
 
429
416
  /**
430
417
  * Unwrap bitcoin via taproot.
@@ -432,7 +419,8 @@ export class TransactionFactory {
432
419
  * @returns {Promise<UnwrapResult>} - The signed transaction
433
420
  * @throws {Error} - If the transaction could not be signed
434
421
  */
435
- public async unwrap(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult> {
422
+
423
+ /*public async unwrap(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult> {
436
424
  if (!unwrapParameters.from) {
437
425
  throw new Error('Field "from" not provided.');
438
426
  }
@@ -495,7 +483,7 @@ export class TransactionFactory {
495
483
  feeRefundOrLoss: finalTransaction.getFeeLossOrRefund(),
496
484
  utxos: this.getUTXOAsTransaction(signedTransaction.tx, unwrapParameters.from, 1),
497
485
  };
498
- }
486
+ }*/
499
487
 
500
488
  /**
501
489
  * @description Creates a funding transaction.
@@ -566,7 +554,7 @@ export class TransactionFactory {
566
554
  };
567
555
  }
568
556
 
569
- private calculateNumSignatures(vault: VaultUTXOs[]): bigint {
557
+ /*private calculateNumSignatures(vault: VaultUTXOs[]): bigint {
570
558
  let numSignatures = 0n;
571
559
 
572
560
  for (const v of vault) {
@@ -594,7 +582,7 @@ export class TransactionFactory {
594
582
  }
595
583
 
596
584
  return BigInt(size);
597
- }
585
+ }*/
598
586
 
599
587
  private writePSBTHeader(type: PSBTTypes, psbt: string): string {
600
588
  const buf = Buffer.from(psbt, 'base64');
@@ -1,15 +1,11 @@
1
1
  import {
2
2
  IDeploymentParameters,
3
3
  IInteractionParameters,
4
- IUnwrapParameters,
5
- IWrapParameters,
6
4
  } from '../interfaces/ITransactionParameters.js';
7
5
  import { UTXO } from '../../utxo/interfaces/IUTXO.js';
8
- import { DeploymentResult, UnwrapResult, WrapResult } from '../TransactionFactory';
6
+ import { DeploymentResult } from '../TransactionFactory';
9
7
 
10
8
  export type InteractionParametersWithoutSigner = Omit<IInteractionParameters, 'signer'>;
11
- export type IWrapParametersWithoutSigner = Omit<IWrapParameters, 'signer'>;
12
- export type IUnwrapParametersWithoutSigner = Omit<IUnwrapParameters, 'signer'>;
13
9
  export type IDeploymentParametersWithoutSigner = Omit<IDeploymentParameters, 'signer' | 'network'>;
14
10
 
15
11
  export interface BroadcastTransactionOptions {
@@ -54,8 +50,4 @@ export interface Web3Provider {
54
50
  deployContract(params: IDeploymentParametersWithoutSigner): Promise<DeploymentResult>;
55
51
 
56
52
  broadcast(transactions: BroadcastTransactionOptions[]): Promise<BroadcastedTransaction[]>;
57
-
58
- wrap(wrapParameters: IWrapParametersWithoutSigner): Promise<WrapResult>;
59
-
60
- unwrap(unwrapParameters: IUnwrapParametersWithoutSigner): Promise<UnwrapResult>;
61
53
  }
@@ -3,6 +3,7 @@ import { ECPairInterface } from 'ecpair';
3
3
  import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
4
4
  import { CustomKeypair } from '../BrowserSignerBase.js';
5
5
  import { PsbtSignatureOptions, Unisat, UnisatNetwork } from '../types/Unisat.js';
6
+ import { PartialSig } from 'bip174/src/lib/interfaces.js';
6
7
 
7
8
  declare global {
8
9
  interface Window {
@@ -138,14 +139,65 @@ export class UnisatSigner extends CustomKeypair {
138
139
  i: number,
139
140
  sighashTypes: number[],
140
141
  ): Promise<void> {
141
- const firstSignature = await this.signTweaked(transaction, i, sighashTypes, false);
142
+ const input = transaction.data.inputs[i];
143
+ if (
144
+ input.tapKeySig ||
145
+ input.finalScriptSig ||
146
+ (Array.isArray(input.partialSig) &&
147
+ input.partialSig.length &&
148
+ this.hasAlreadyPartialSig(input.partialSig)) ||
149
+ (Array.isArray(input.tapScriptSig) &&
150
+ input.tapScriptSig.length &&
151
+ this.hasAlreadySignedTapScriptSig(input.tapScriptSig))
152
+ ) {
153
+ return;
154
+ }
155
+
156
+ const firstSignature = await this.signAllTweaked(transaction, sighashTypes, false);
142
157
  this.combine(transaction, firstSignature, i);
143
158
  }
144
159
 
145
160
  public async signInput(transaction: Psbt, i: number, sighashTypes: number[]): Promise<void> {
146
- const secondSignature = await this.signTweaked(transaction, i, sighashTypes, true);
161
+ const input = transaction.data.inputs[i];
162
+ if (
163
+ input.tapKeySig ||
164
+ input.finalScriptSig ||
165
+ (Array.isArray(input.partialSig) &&
166
+ input.partialSig.length &&
167
+ this.hasAlreadyPartialSig(input.partialSig)) ||
168
+ (Array.isArray(input.tapScriptSig) &&
169
+ input.tapScriptSig.length &&
170
+ this.hasAlreadySignedTapScriptSig(input.tapScriptSig))
171
+ ) {
172
+ return;
173
+ }
174
+
175
+ const firstSignature = await this.signAllTweaked(transaction, sighashTypes, true);
176
+ this.combine(transaction, firstSignature, i);
177
+ }
178
+
179
+ private hasAlreadySignedTapScriptSig(input: TapScriptSig[]): boolean {
180
+ for (let i = 0; i < input.length; i++) {
181
+ const item = input[i];
182
+ const buf = Buffer.from(item.pubkey);
183
+ if (buf.equals(this.publicKey) && item.signature) {
184
+ return true;
185
+ }
186
+ }
147
187
 
148
- this.combine(transaction, secondSignature, i);
188
+ return false;
189
+ }
190
+
191
+ private hasAlreadyPartialSig(input: PartialSig[]): boolean {
192
+ for (let i = 0; i < input.length; i++) {
193
+ const item = input[i];
194
+ const buf = Buffer.from(item.pubkey);
195
+ if (buf.equals(this.publicKey) && item.signature) {
196
+ return true;
197
+ }
198
+ }
199
+
200
+ return false;
149
201
  }
150
202
 
151
203
  private combine(transaction: Psbt, newPsbt: Psbt, i: number): void {
@@ -177,6 +229,34 @@ export class UnisatSigner extends CustomKeypair {
177
229
  }
178
230
  }
179
231
 
232
+ private async signAllTweaked(
233
+ transaction: Psbt,
234
+ sighashTypes: number[],
235
+ disableTweakSigner: boolean = false,
236
+ ): Promise<Psbt> {
237
+ const pubKey = this.publicKey.toString('hex');
238
+ const toSign = transaction.data.inputs.map((_, i) => {
239
+ return [
240
+ {
241
+ index: i,
242
+ publicKey: pubKey,
243
+ sighashTypes,
244
+ disableTweakSigner: disableTweakSigner,
245
+ },
246
+ ];
247
+ });
248
+
249
+ const opts: PsbtSignatureOptions = {
250
+ autoFinalized: false,
251
+ toSignInputs: toSign.flat(),
252
+ };
253
+
254
+ const psbt = transaction.toHex();
255
+ const signed = await this.unisat.signPsbt(psbt, opts);
256
+
257
+ return Psbt.fromHex(signed);
258
+ }
259
+
180
260
  private async signTweaked(
181
261
  transaction: Psbt,
182
262
  i: number,
@@ -188,13 +188,23 @@ export abstract class SharedInteractionTransaction<
188
188
 
189
189
  for (let i = 0; i < transaction.data.inputs.length; i++) {
190
190
  if (i === 0) {
191
- // multi sig input
192
- transaction.signInput(0, this.scriptSigner);
193
- transaction.signInput(0, this.getSignerKey());
194
-
195
- transaction.finalizeInput(0, this.customFinalizer);
191
+ await this.signInput(transaction, transaction.data.inputs[i], i, this.scriptSigner);
192
+ await this.signInput(
193
+ transaction,
194
+ transaction.data.inputs[i],
195
+ i,
196
+ this.getSignerKey(),
197
+ );
198
+
199
+ transaction.finalizeInput(i, this.customFinalizer);
196
200
  } else {
197
- transaction.signInput(i, this.getSignerKey());
201
+ await this.signInput(
202
+ transaction,
203
+ transaction.data.inputs[i],
204
+ i,
205
+ this.getSignerKey(),
206
+ );
207
+
198
208
  transaction.finalizeInput(i);
199
209
  }
200
210
  }
@@ -4,7 +4,7 @@ import { TapLeafScript } from '../interfaces/Tap.js';
4
4
  import { IWrapParameters } from '../interfaces/ITransactionParameters.js';
5
5
  import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
6
6
  import { wBTC } from '../../metadata/contracts/wBTC.js';
7
- import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
7
+ import { WrappedGeneration } from '../../../wbtc_disabled/WrappedGenerationParameters.js';
8
8
  import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
9
9
  import { Network, PsbtOutputExtendedAddress } from '@btc-vision/bitcoin';
10
10
  import { P2TR_MS } from '../shared/P2TR_MS.js';
@@ -1,9 +1,6 @@
1
1
  import { UTXO } from '../../utxo/interfaces/IUTXO.js';
2
- import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
3
2
  import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
4
- import { VaultUTXOs } from '../processor/PsbtTransaction.js';
5
3
  import { ChainId } from '../../network/ChainId.js';
6
- import { Address } from '../../keypair/Address.js';
7
4
  import { PsbtOutputExtended } from '@btc-vision/bitcoin';
8
5
 
9
6
  export interface ITransactionParameters extends ITweakedTransactionData {
@@ -43,7 +40,7 @@ export interface IInteractionParameters
43
40
  readonly to: string;
44
41
  }
45
42
 
46
- export interface IWrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
43
+ /*export interface IWrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
47
44
  readonly to?: string;
48
45
  readonly from: string;
49
46
 
@@ -56,7 +53,7 @@ export interface IWrapParameters extends Omit<SharedInteractionParameters, 'opti
56
53
  export interface IUnwrapParameters extends Omit<SharedInteractionParameters, 'optionalOutputs'> {
57
54
  readonly unwrapUTXOs: VaultUTXOs[];
58
55
  readonly amount: bigint;
59
- }
56
+ }*/
60
57
 
61
58
  export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'> {
62
59
  readonly bytecode: Buffer;
@@ -14,7 +14,7 @@ export interface PsbtTransactionData extends ITweakedTransactionData {
14
14
  readonly network: Network;
15
15
  }
16
16
 
17
- export interface IWBTCUTXODocument {
17
+ /*export interface IWBTCUTXODocument {
18
18
  readonly vault: string;
19
19
  readonly blockId: bigint;
20
20
 
@@ -30,7 +30,7 @@ export interface VaultUTXOs {
30
30
  readonly publicKeys: string[];
31
31
  readonly minimum: number;
32
32
  readonly utxos: IWBTCUTXODocument[];
33
- }
33
+ }*/
34
34
 
35
35
  export type FromBase64Params = Omit<PsbtTransactionData, 'psbt'>;
36
36
 
@@ -166,7 +166,7 @@ export class PsbtTransaction extends TweakedTransaction {
166
166
  return this.transaction;
167
167
  }
168
168
 
169
- private getTotalOutputAmount(vaults: VaultUTXOs[]): bigint {
169
+ /*private getTotalOutputAmount(vaults: VaultUTXOs[]): bigint {
170
170
  let total = BigInt(0);
171
171
  for (const vault of vaults) {
172
172
  for (const utxo of vault.utxos) {
@@ -175,5 +175,5 @@ export class PsbtTransaction extends TweakedTransaction {
175
175
  }
176
176
 
177
177
  return total;
178
- }
178
+ }*/
179
179
  }