@btc-vision/transaction 1.0.30 → 1.0.31

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 (136) hide show
  1. package/README.md +5 -1
  2. package/Unwrap.md +165 -0
  3. package/browser/_version.d.ts +1 -1
  4. package/browser/index.js +1 -1
  5. package/browser/opnet.d.ts +3 -2
  6. package/browser/transaction/TransactionFactory.d.ts +3 -4
  7. package/browser/transaction/builders/MultiSignTransaction.d.ts +6 -5
  8. package/browser/transaction/builders/TapUnwarpTransaction.d.ts +3 -0
  9. package/browser/transaction/builders/UnwarpTransaction.d.ts +0 -1
  10. package/browser/transaction/builders/UnwrapSegwitTransaction.d.ts +33 -0
  11. package/browser/transaction/builders/UnwrapTransaction.d.ts +43 -0
  12. package/browser/transaction/interfaces/ITransactionParameters.d.ts +0 -1
  13. package/browser/transaction/shared/TweakedTransaction.d.ts +3 -1
  14. package/build/_version.d.ts +1 -1
  15. package/build/_version.js +1 -1
  16. package/build/generators/builders/MultisignGenerator.js +2 -1
  17. package/build/opnet.d.ts +3 -2
  18. package/build/opnet.js +3 -2
  19. package/build/tests/massWrapReg.js +3 -3
  20. package/build/tests/mineReg.js +5 -6
  21. package/build/tests/multisign.js +3 -3
  22. package/build/tests/unwrapReg.js +3 -6
  23. package/build/tests/unwrapReg2.js +25 -12
  24. package/build/tests/wrapReg.js +2 -2
  25. package/build/transaction/TransactionFactory.d.ts +3 -4
  26. package/build/transaction/TransactionFactory.js +19 -20
  27. package/build/transaction/builders/MultiSignTransaction.d.ts +6 -5
  28. package/build/transaction/builders/MultiSignTransaction.js +34 -32
  29. package/build/transaction/builders/TapUnwarpTransaction.d.ts +4 -0
  30. package/build/transaction/builders/TapUnwarpTransaction.js +30 -4
  31. package/build/transaction/builders/UnwarpSegwitTransaction.d.ts +34 -0
  32. package/build/transaction/builders/UnwarpSegwitTransaction.js +184 -0
  33. package/build/transaction/builders/UnwarpTransaction.d.ts +13 -7
  34. package/build/transaction/builders/UnwarpTransaction.js +95 -67
  35. package/build/transaction/builders/UnwrapSegwitTransaction.d.ts +33 -0
  36. package/build/transaction/builders/UnwrapSegwitTransaction.js +184 -0
  37. package/build/transaction/builders/UnwrapTransaction.d.ts +43 -0
  38. package/build/transaction/builders/UnwrapTransaction.js +230 -0
  39. package/build/transaction/interfaces/ITransactionParameters.d.ts +0 -1
  40. package/build/transaction/shared/P2TR_MS.js +0 -1
  41. package/build/transaction/shared/TweakedTransaction.d.ts +3 -1
  42. package/build/transaction/shared/TweakedTransaction.js +38 -3
  43. package/build/utxo/OPNetLimitedProvider.js +1 -1
  44. package/docs/assets/navigation.js +1 -1
  45. package/docs/assets/search.js +1 -1
  46. package/docs/classes/AddressGenerator.html +2 -2
  47. package/docs/classes/AddressVerificator.html +2 -2
  48. package/docs/classes/BitcoinUtils.html +4 -4
  49. package/docs/classes/CalldataGenerator.html +10 -10
  50. package/docs/classes/Compressor.html +4 -4
  51. package/docs/classes/ContractBaseMetadata.html +4 -4
  52. package/docs/classes/DeploymentGenerator.html +9 -9
  53. package/docs/classes/DeploymentTransaction.html +113 -91
  54. package/docs/classes/EcKeyPair.html +16 -16
  55. package/docs/classes/FundingTransaction.html +92 -70
  56. package/docs/classes/Generator.html +9 -9
  57. package/docs/classes/InteractionTransaction.html +108 -82
  58. package/docs/classes/MultiSignGenerator.html +2 -13
  59. package/docs/classes/MultiSignTransaction.html +119 -82
  60. package/docs/classes/OPNetLimitedProvider.html +17 -7
  61. package/docs/classes/P2TR_MS.html +186 -0
  62. package/docs/classes/PsbtTransaction.html +66 -59
  63. package/docs/classes/SharedInteractionTransaction.html +108 -86
  64. package/docs/classes/TapscriptVerificator.html +2 -2
  65. package/docs/classes/TransactionBuilder.html +92 -70
  66. package/docs/classes/TransactionFactory.html +26 -6
  67. package/docs/classes/TweakedSigner.html +2 -2
  68. package/docs/classes/TweakedTransaction.html +55 -33
  69. package/docs/classes/UnwrapGeneration.html +177 -0
  70. package/docs/classes/UnwrapSegwitTransaction.html +502 -0
  71. package/docs/classes/UnwrapTransaction.html +154 -90
  72. package/docs/classes/Wallet.html +11 -11
  73. package/docs/classes/WrapTransaction.html +121 -95
  74. package/docs/classes/WrappedGeneration.html +8 -8
  75. package/docs/classes/wBTC.html +7 -7
  76. package/docs/enums/PSBTTypes.html +2 -2
  77. package/docs/enums/TransactionSequence.html +2 -2
  78. package/docs/enums/TransactionType.html +2 -2
  79. package/docs/hierarchy.html +1 -1
  80. package/docs/index.html +6 -4
  81. package/docs/interfaces/BroadcastResponse.html +2 -2
  82. package/docs/interfaces/ContractAddressVerificationParams.html +2 -2
  83. package/docs/interfaces/DeploymentResult.html +2 -2
  84. package/docs/interfaces/FetchUTXOParams.html +2 -2
  85. package/docs/interfaces/FetchUTXOParamsMultiAddress.html +2 -2
  86. package/docs/interfaces/GenerationConstraints.html +5 -5
  87. package/docs/interfaces/IDeploymentParameters.html +2 -2
  88. package/docs/interfaces/IFundingTransactionParameters.html +2 -2
  89. package/docs/interfaces/IInteractionParameters.html +2 -2
  90. package/docs/interfaces/ITransactionParameters.html +2 -2
  91. package/docs/interfaces/ITweakedTransactionData.html +2 -2
  92. package/docs/interfaces/IUnwrapParameters.html +3 -3
  93. package/docs/interfaces/IWBTCUTXODocument.html +2 -2
  94. package/docs/interfaces/IWallet.html +4 -4
  95. package/docs/interfaces/IWrapParameters.html +2 -2
  96. package/docs/interfaces/MultiSignFromBase64Params.html +2 -2
  97. package/docs/interfaces/MultiSignParameters.html +2 -2
  98. package/docs/interfaces/NetworkInformation.html +2 -2
  99. package/docs/interfaces/PsbtInputExtended.html +1 -1
  100. package/docs/interfaces/PsbtOutputExtendedAddress.html +2 -2
  101. package/docs/interfaces/PsbtOutputExtendedScript.html +2 -2
  102. package/docs/interfaces/PsbtTransactionData.html +2 -5
  103. package/docs/interfaces/RawUTXOResponse.html +2 -2
  104. package/docs/interfaces/SharedInteractionParameters.html +2 -2
  105. package/docs/interfaces/TapLeafScript.html +2 -2
  106. package/docs/interfaces/TweakSettings.html +3 -3
  107. package/docs/interfaces/UTXO.html +2 -2
  108. package/docs/interfaces/UnwrapResult.html +3 -3
  109. package/docs/interfaces/UnwrappedGenerationParameters.html +178 -0
  110. package/docs/interfaces/UpdateInput.html +2 -2
  111. package/docs/interfaces/VaultUTXOs.html +2 -2
  112. package/docs/interfaces/WrapResult.html +2 -2
  113. package/docs/interfaces/WrappedGenerationParameters.html +6 -6
  114. package/docs/modules.html +4 -0
  115. package/docs/types/FromBase64Params.html +1 -1
  116. package/docs/types/PsbtOutputExtended.html +1 -1
  117. package/docs/variables/version.html +1 -1
  118. package/package.json +2 -2
  119. package/src/_version.ts +1 -1
  120. package/src/generators/builders/CalldataGenerator.ts +144 -144
  121. package/src/generators/builders/MultiSignGenerator.ts +7 -18
  122. package/src/opnet.ts +4 -2
  123. package/src/tests/massWrapReg.ts +3 -4
  124. package/src/tests/mineReg.ts +6 -6
  125. package/src/tests/multisign.ts +3 -3
  126. package/src/tests/unwrapReg.ts +3 -7
  127. package/src/tests/unwrapReg2.ts +26 -123
  128. package/src/tests/wrapReg.ts +2 -2
  129. package/src/transaction/TransactionFactory.ts +34 -22
  130. package/src/transaction/builders/MultiSignTransaction.ts +86 -64
  131. package/src/transaction/builders/{UnwarpTransaction.ts → UnwrapSegwitTransaction.ts} +5 -37
  132. package/src/transaction/builders/{TapUnwarpTransaction.ts → UnwrapTransaction.ts} +78 -64
  133. package/src/transaction/interfaces/ITransactionParameters.ts +0 -4
  134. package/src/transaction/shared/P2TR_MS.ts +0 -4
  135. package/src/transaction/shared/TweakedTransaction.ts +96 -5
  136. package/src/utxo/OPNetLimitedProvider.ts +1 -1
package/README.md CHANGED
@@ -48,10 +48,14 @@ of the repository.
48
48
  npm i
49
49
  ```
50
50
 
51
- ## Deployments and Wrapping
51
+ ## Deployments, Wrapping and Unwrapping
52
52
 
53
53
  To learn how to wrap and unwrap Bitcoin on OP_NET, please refer to
54
54
  the [Wrap.md](https://github.com/btc-vision/transaction/blob/main/Wrap.md) guide.
55
+
56
+ To learn how to unwrap Bitcoin on OP_NET, please refer to
57
+ the [Unwrap.md](https://github.com/btc-vision/transaction/blob/main/Unwrap.md) guide.
58
+
55
59
  To learn how to deploy smart contracts on OP_NET, please refer to
56
60
  the [Deploy.md](https://github.com/btc-vision/transaction/blob/main/Deploy.md) guide.
57
61
 
package/Unwrap.md ADDED
@@ -0,0 +1,165 @@
1
+ Sure, here's the modified guide for unwrapping wBTC:
2
+
3
+ # Unwrapping wBTC Guide
4
+
5
+ This guide will walk you through the process of unwrapping wBTC (Wrapped Bitcoin) using the OPNet protocol. Unwrapping
6
+ wBTC converts it back into regular Bitcoin, enabling you to use it directly on the Bitcoin network.
7
+
8
+ ## What is Unwrapping?
9
+
10
+ Unwrapping wBTC involves converting your wrapped tokens back into Bitcoin. This process ensures that the wBTC you hold
11
+ is exchanged for an equivalent amount of Bitcoin, maintaining a 1:1 ratio. This allows you to move seamlessly between
12
+ using Bitcoin in decentralized applications and holding it in its original form.
13
+
14
+ ## Preview
15
+
16
+ You can check your wBTC balance at any time via [wbtc.opnet.org](https://wbtc.opnet.org).
17
+
18
+ ## Prerequisites
19
+
20
+ - Node.js and npm installed
21
+ - Bitcoin testnet wallet
22
+ - Access to an OPNet node
23
+ - Bitcoin RPC configured for testnet
24
+
25
+ ## Setup
26
+
27
+ First, ensure you have the necessary dependencies installed in your project:
28
+
29
+ ```sh
30
+ npm i
31
+ ```
32
+
33
+ ## Step-by-Step Guide
34
+
35
+ ### 1. Import Required Libraries
36
+
37
+ ```typescript
38
+ import { Wallet } from '../keypair/Wallet.js';
39
+ import { OPNetLimitedProvider } from '../utxo/OPNetLimitedProvider.js';
40
+ import { networks, Network } from 'bitcoinjs-lib';
41
+ import { TransactionFactory } from '../transaction/TransactionFactory.js';
42
+ import { IUnwrapParameters } from '../transaction/interfaces/ITransactionParameters.js';
43
+ import { FetchUTXOParams, UTXO } from '../utxo/interfaces/IUTXO.js';
44
+ import { UnwrapTransaction } from '../transaction/UnwrapTransaction.js';
45
+ ```
46
+
47
+ ### Setting Up Configurations
48
+
49
+ We must provide the necessary configurations for the network and wallet:
50
+
51
+ - The opnetNode variable is the URL of the OPNet node.
52
+ - The Testnet variable contains the wallet address, public key, and private key.
53
+
54
+ ```typescript
55
+ const network: Network = networks.testnet;
56
+ const opnetNode: string = 'https://testnet.opnet.org';
57
+ ```
58
+
59
+ ### 2. Load Wallet
60
+
61
+ ```typescript
62
+ const wallet: Wallet = new Wallet(Testnet.wallet, network);
63
+ ```
64
+
65
+ ### 3. Connect to OPNet
66
+
67
+ ```typescript
68
+ const opnet: OPNetLimitedProvider = new OPNetLimitedProvider(opnetNode);
69
+ const factory: TransactionFactory = new TransactionFactory();
70
+ ```
71
+
72
+ ### 4. Initialize RPC with Testnet Configuration
73
+
74
+ ```typescript
75
+ await rpc.init(Testnet.config);
76
+ ```
77
+
78
+ ### 5. Define Unwrap Amount and Fetch UTXOs
79
+
80
+ We must define the amount to unwrap and fetch the UTXOs required for the transaction. Each OPNet vaults have UTXOs. We
81
+ need to fetch these UTXOs to unwrap the wBTC. We request an opnet node for the most optimized UTXOs to unwrap the wBTC.
82
+ If the UTXOs used to unwrap the wBTC do not follow the OPNet consensus rules, the unwrapping request will be denied.
83
+
84
+ ```typescript
85
+ const unwrapAmount: bigint = UnwrapTransaction.MINIMUM_CONSOLIDATION_AMOUNT; // Minimum amount to unwrap
86
+ const unwrapUtxos = await opnet.fetchUnWrapParameters(unwrapAmount, wallet.p2tr);
87
+ if (!unwrapUtxos) {
88
+ throw new Error('No vault UTXOs or something went wrong. Please try again.');
89
+ }
90
+
91
+ const utxoSetting: FetchUTXOParams = {
92
+ address: wallet.p2wpkh,
93
+ minAmount: 10000n,
94
+ requestedAmount: unwrapAmount,
95
+ };
96
+
97
+ const utxos: UTXO[] = await opnet.fetchUTXO(utxoSetting);
98
+ if (!utxos) {
99
+ throw new Error('No UTXOs found');
100
+ }
101
+ ```
102
+
103
+ ### 6. Create Unwrap Parameters and Finalize Transaction
104
+
105
+ Now, we will create the unwrap parameters and finalize the transaction using the TransactionFactory.
106
+
107
+ ```typescript
108
+ const unwrapParameters: IUnwrapParameters = {
109
+ from: wallet.p2tr, // Address to unwrap
110
+ utxos: utxos, // User UTXOs to spend
111
+ unwrapUTXOs: unwrapUtxos.vaultUTXOs, // Vault UTXOs to unwrap
112
+ signer: wallet.keypair, // Signer
113
+ network: network, // Bitcoin network
114
+ feeRate: 100, // Fee rate in satoshis per byte (bitcoin fee)
115
+ priorityFee: 10000n, // OPNet priority fee (incl gas.)
116
+ amount: unwrapAmount, // Amount to unwrap
117
+ };
118
+
119
+ try {
120
+ const finalTx = await factory.unwrap(unwrapParameters);
121
+ console.log(`Due to bitcoin fees, you will lose ${finalTx.unwrapFeeLoss} satoshis by unwrapping. Do you want to proceed?`);
122
+ console.log(`Final transaction:`, finalTx);
123
+ } catch (e) {
124
+ console.error(`Something went wrong:`, e);
125
+ }
126
+ ```
127
+
128
+ ### 7. Broadcast the Transactions
129
+
130
+ To broadcast the transactions, we will send the raw transactions to the network.
131
+
132
+ ```typescript
133
+ try {
134
+ // If this transaction is missing, opnet will deny the unwrapping request.
135
+ const fundingTransaction = await opnet.broadcastTransaction(finalTx.fundingTransaction, false);
136
+ console.log(`Broadcasted:`, fundingTransaction);
137
+
138
+ // This transaction is partially signed. You can not submit it to the Bitcoin network. It must pass via the OPNet network.
139
+ const unwrapTransaction = await opnet.broadcastTransaction(finalTx.psbt, true);
140
+ console.log(`Broadcasted:`, unwrapTransaction);
141
+ } catch (e) {
142
+ console.error(`Error:`, e);
143
+ }
144
+ ```
145
+
146
+ ### 8. Mining a Block (Optional, for Regtest)
147
+
148
+ If you are using a regtest or need to mine a block to proceed:
149
+
150
+ ```typescript
151
+ const shouldMineBlock: boolean = true;
152
+
153
+ async function mineBlock(): Promise<boolean> {
154
+ const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
155
+ if (!ok) {
156
+ throw new Error('Could not mine block');
157
+ }
158
+ console.log(`Mined block`, ok);
159
+ return !!ok.length;
160
+ }
161
+ ```
162
+
163
+ ## Conclusion
164
+
165
+ You have now successfully unwrapped wBTC into Bitcoin using OPNet!
@@ -1 +1 @@
1
- export declare const version = "1.0.30";
1
+ export declare const version = "1.0.31";