opnet 1.0.13 → 1.0.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 (253) hide show
  1. package/CONTRIBUTING.md +71 -0
  2. package/README.md +6 -7
  3. package/browser/_version.d.ts +1 -1
  4. package/browser/abi/BaseContractProperty.d.ts +3 -0
  5. package/browser/abi/BitcoinAbiTypes.d.ts +4 -0
  6. package/browser/abi/BitcoinInterface.d.ts +9 -0
  7. package/browser/abi/interfaces/BaseContractProperties.d.ts +4 -0
  8. package/browser/abi/interfaces/BitcoinAbiValue.d.ts +5 -0
  9. package/browser/abi/interfaces/BitcoinInterfaceAbi.d.ts +11 -0
  10. package/browser/bitcoin/UTXOs.d.ts +1 -6
  11. package/browser/bitcoin/interfaces/IUTXO.d.ts +7 -0
  12. package/browser/common/CommonTypes.d.ts +1 -0
  13. package/browser/contracts/CallResult.d.ts +6 -3
  14. package/browser/contracts/Contract.d.ts +28 -0
  15. package/browser/contracts/interfaces/ICallResult.d.ts +2 -3
  16. package/browser/contracts/interfaces/IContract.d.ts +4 -0
  17. package/browser/crypto/crypto-browser.d.ts +7 -0
  18. package/browser/index.js +1 -1
  19. package/browser/opnet.d.ts +11 -0
  20. package/browser/scripts/testContract.d.ts +1 -0
  21. package/browser/scripts/testMethods.d.ts +1 -0
  22. package/browser/utils/BitcoinUtils.d.ts +4 -0
  23. package/build/_version.d.ts +1 -1
  24. package/build/_version.js +1 -1
  25. package/build/abi/BaseContractProperty.d.ts +3 -0
  26. package/build/abi/BaseContractProperty.js +1 -0
  27. package/build/abi/BitcoinAbiTypes.d.ts +4 -0
  28. package/build/abi/BitcoinAbiTypes.js +5 -0
  29. package/build/abi/BitcoinInterface.d.ts +9 -0
  30. package/build/abi/BitcoinInterface.js +45 -0
  31. package/build/abi/BitcoinInterfaceAbi.d.ts +3 -0
  32. package/build/abi/BitcoinInterfaceAbi.js +1 -0
  33. package/build/abi/enums/ParamTypes.d.ts +0 -0
  34. package/build/abi/enums/ParamTypes.js +1 -0
  35. package/build/abi/interface/BitcoinInterface.d.ts +6 -0
  36. package/build/abi/interface/BitcoinInterface.js +12 -0
  37. package/build/abi/interface/BitcoinInterfaceAbi.d.ts +3 -0
  38. package/build/abi/interface/BitcoinInterfaceAbi.js +1 -0
  39. package/build/abi/interfaces/BaseContractProperties.d.ts +4 -0
  40. package/build/abi/interfaces/BaseContractProperties.js +1 -0
  41. package/build/abi/interfaces/BaseContractProperty.d.ts +2 -0
  42. package/build/abi/interfaces/BaseContractProperty.js +1 -0
  43. package/build/abi/interfaces/BitcoinAbiInput.d.ts +5 -0
  44. package/build/abi/interfaces/BitcoinAbiInput.js +1 -0
  45. package/build/abi/interfaces/BitcoinAbiValue.d.ts +5 -0
  46. package/build/abi/interfaces/BitcoinAbiValue.js +1 -0
  47. package/build/abi/interfaces/BitcoinInterfaceAbi.d.ts +11 -0
  48. package/build/abi/interfaces/BitcoinInterfaceAbi.js +1 -0
  49. package/build/bitcoin/UTXOs.d.ts +1 -6
  50. package/build/bitcoin/interfaces/IUTXO.d.ts +7 -0
  51. package/build/bitcoin/interfaces/IUTXO.js +1 -0
  52. package/build/common/CommonTypes.d.ts +1 -0
  53. package/build/contracts/CallResult.d.ts +6 -3
  54. package/build/contracts/CallResult.js +9 -2
  55. package/build/contracts/Contract.d.ts +28 -0
  56. package/build/contracts/Contract.js +206 -0
  57. package/build/contracts/interfaces/ICallResult.d.ts +2 -3
  58. package/build/contracts/interfaces/IContract.d.ts +4 -0
  59. package/build/contracts/interfaces/IContract.js +1 -0
  60. package/build/interface/BitcoinInterface.d.ts +6 -0
  61. package/build/interface/BitcoinInterface.js +12 -0
  62. package/build/interface/BitcoinInterfaceAbi.d.ts +3 -0
  63. package/build/interface/BitcoinInterfaceAbi.js +1 -0
  64. package/build/interface/Interface.d.ts +2 -0
  65. package/build/interface/Interface.js +2 -0
  66. package/build/interface.d.ts +0 -0
  67. package/build/interface.js +1 -0
  68. package/build/opnet.d.ts +11 -0
  69. package/build/opnet.js +11 -0
  70. package/build/scripts/test.js +12 -0
  71. package/build/scripts/testContract.d.ts +1 -0
  72. package/build/scripts/testContract.js +28 -0
  73. package/build/scripts/testMethods.d.ts +1 -0
  74. package/build/scripts/testMethods.js +24 -0
  75. package/build/utils/BitcoinUtils.d.ts +4 -0
  76. package/build/utils/BitcoinUtils.js +7 -0
  77. package/cjs/_version.d.ts +1 -0
  78. package/cjs/_version.js +4 -0
  79. package/cjs/abi/BaseContractProperty.d.ts +3 -0
  80. package/cjs/abi/BaseContractProperty.js +2 -0
  81. package/cjs/abi/BitcoinAbiTypes.d.ts +4 -0
  82. package/cjs/abi/BitcoinAbiTypes.js +8 -0
  83. package/cjs/abi/BitcoinInterface.d.ts +9 -0
  84. package/cjs/abi/BitcoinInterface.js +49 -0
  85. package/cjs/abi/interfaces/BaseContractProperties.d.ts +4 -0
  86. package/cjs/abi/interfaces/BaseContractProperties.js +2 -0
  87. package/cjs/abi/interfaces/BitcoinAbiValue.d.ts +5 -0
  88. package/cjs/abi/interfaces/BitcoinAbiValue.js +2 -0
  89. package/cjs/abi/interfaces/BitcoinInterfaceAbi.d.ts +11 -0
  90. package/cjs/abi/interfaces/BitcoinInterfaceAbi.js +2 -0
  91. package/cjs/bitcoin/BitcoinAddress.d.ts +20 -0
  92. package/cjs/bitcoin/BitcoinAddress.js +116 -0
  93. package/cjs/bitcoin/UTXOs.d.ts +15 -0
  94. package/cjs/bitcoin/UTXOs.js +16 -0
  95. package/cjs/block/Block.d.ts +2 -3
  96. package/cjs/block/Block.js +3 -28
  97. package/cjs/block/interfaces/IBlock.d.ts +28 -0
  98. package/cjs/block/interfaces/IBlock.js +2 -0
  99. package/cjs/common/CommonTypes.d.ts +4 -0
  100. package/cjs/common/CommonTypes.js +2 -0
  101. package/cjs/contracts/CallResult.d.ts +13 -0
  102. package/cjs/contracts/CallResult.js +25 -0
  103. package/cjs/contracts/Contract.d.ts +28 -0
  104. package/cjs/contracts/Contract.js +212 -0
  105. package/cjs/contracts/ContractData.d.ts +15 -0
  106. package/cjs/contracts/ContractData.js +36 -0
  107. package/cjs/contracts/interfaces/IAccessList.d.ts +6 -0
  108. package/cjs/contracts/interfaces/IAccessList.js +2 -0
  109. package/cjs/contracts/interfaces/ICallResult.d.ts +11 -0
  110. package/cjs/contracts/interfaces/ICallResult.js +2 -0
  111. package/cjs/contracts/interfaces/IContract.d.ts +4 -0
  112. package/cjs/contracts/interfaces/IContract.js +2 -0
  113. package/cjs/contracts/interfaces/IRawContract.d.ts +13 -0
  114. package/cjs/contracts/interfaces/IRawContract.js +2 -0
  115. package/cjs/crypto/crypto.d.ts +2 -0
  116. package/cjs/crypto/crypto.js +8 -0
  117. package/cjs/index.d.ts +3 -11
  118. package/cjs/index.js +16 -11
  119. package/cjs/opnet.d.ts +36 -0
  120. package/cjs/opnet.js +54 -0
  121. package/cjs/providers/AbstractRpcProvider.d.ts +34 -0
  122. package/cjs/providers/AbstractRpcProvider.js +161 -0
  123. package/cjs/providers/JSONRpcProvider.d.ts +5 -9
  124. package/cjs/providers/JSONRpcProvider.js +4 -29
  125. package/cjs/providers/WebsocketRpcProvider.d.ts +8 -0
  126. package/cjs/providers/WebsocketRpcProvider.js +27 -0
  127. package/cjs/scripts/testContract.d.ts +1 -0
  128. package/cjs/scripts/testContract.js +30 -0
  129. package/cjs/scripts/testMethods.d.ts +1 -0
  130. package/cjs/scripts/testMethods.js +26 -0
  131. package/cjs/serialize/BigInt.d.ts +6 -0
  132. package/cjs/serialize/BigInt.js +5 -0
  133. package/cjs/storage/StoredValue.d.ts +10 -0
  134. package/cjs/storage/StoredValue.js +28 -0
  135. package/cjs/storage/interfaces/IStorageValue.d.ts +9 -0
  136. package/cjs/storage/interfaces/IStorageValue.js +2 -0
  137. package/cjs/transactions/DeploymentTransaction.d.ts +10 -1
  138. package/cjs/transactions/DeploymentTransaction.js +16 -0
  139. package/cjs/transactions/GenericTransaction.d.ts +1 -1
  140. package/cjs/transactions/InteractionTransaction.d.ts +1 -1
  141. package/cjs/transactions/Transaction.d.ts +1 -1
  142. package/cjs/transactions/Transaction.js +1 -1
  143. package/cjs/transactions/TransactionParser.d.ts +7 -0
  144. package/cjs/transactions/TransactionParser.js +32 -0
  145. package/cjs/transactions/TransactionReceipt.d.ts +10 -0
  146. package/cjs/transactions/TransactionReceipt.js +16 -0
  147. package/cjs/transactions/interfaces/ITransaction.d.ts +39 -0
  148. package/cjs/transactions/interfaces/ITransaction.js +2 -0
  149. package/cjs/transactions/interfaces/ITransactionReceipt.d.ts +8 -0
  150. package/cjs/transactions/interfaces/ITransactionReceipt.js +2 -0
  151. package/cjs/utils/BitcoinUtils.d.ts +4 -0
  152. package/cjs/utils/BitcoinUtils.js +14 -0
  153. package/docs/assets/navigation.js +1 -1
  154. package/docs/assets/search.js +1 -1
  155. package/docs/classes/AbstractRpcProvider.html +15 -15
  156. package/docs/classes/BaseContract.html +187 -0
  157. package/docs/classes/BitcoinAddress.html +5 -2
  158. package/docs/classes/BitcoinInterface.html +182 -0
  159. package/docs/classes/BitcoinUtils.html +183 -0
  160. package/docs/classes/Block.html +5 -3
  161. package/docs/classes/CallResult.html +6 -2
  162. package/docs/classes/ContractData.html +4 -2
  163. package/docs/classes/DeploymentTransaction.html +4 -2
  164. package/docs/classes/GenericTransaction.html +4 -2
  165. package/docs/classes/IBaseContract.html +192 -0
  166. package/docs/classes/InteractionTransaction.html +3 -2
  167. package/docs/classes/JSONRpcProvider.html +14 -14
  168. package/docs/classes/StoredValue.html +4 -2
  169. package/docs/classes/TransactionBase.html +4 -2
  170. package/docs/classes/TransactionInput.html +3 -2
  171. package/docs/classes/TransactionOutput.html +3 -2
  172. package/docs/classes/TransactionParser.html +3 -2
  173. package/docs/classes/TransactionReceipt.html +3 -2
  174. package/docs/classes/UTXO.html +4 -2
  175. package/docs/classes/WebSocketRpcProvider.html +14 -14
  176. package/docs/enums/ABIDataTypes.html +183 -0
  177. package/docs/enums/BitcoinAbiTypes.html +178 -0
  178. package/docs/enums/OPNetTransactionTypes.html +2 -2
  179. package/docs/functions/getContract.html +180 -0
  180. package/docs/hierarchy.html +1 -1
  181. package/docs/index.html +4 -5
  182. package/docs/interfaces/BaseContractProperties.html +176 -0
  183. package/docs/interfaces/BitcoinAbiValue.html +180 -0
  184. package/docs/interfaces/BitcoinInterfaceAbiBase.html +182 -0
  185. package/docs/interfaces/IAccessList.html +3 -1
  186. package/docs/interfaces/IAccessListItem.html +3 -1
  187. package/docs/interfaces/IBlock.html +5 -3
  188. package/docs/interfaces/IBlockCommon.html +5 -3
  189. package/docs/interfaces/ICallRequestError.html +4 -2
  190. package/docs/interfaces/ICallResultData.html +4 -2
  191. package/docs/interfaces/IContract.html +177 -0
  192. package/docs/interfaces/IDeploymentTransaction.html +4 -2
  193. package/docs/interfaces/IGenericTransaction.html +4 -2
  194. package/docs/interfaces/IInteractionTransaction.html +4 -2
  195. package/docs/interfaces/IRawContract.html +5 -2
  196. package/docs/interfaces/IStorageValue.html +4 -2
  197. package/docs/interfaces/ITransactionBase.html +4 -2
  198. package/docs/interfaces/ITransactionInput.html +3 -2
  199. package/docs/interfaces/ITransactionOutput.html +3 -2
  200. package/docs/interfaces/ITransactionReceipt.html +4 -2
  201. package/docs/interfaces/IUTXO.html +4 -2
  202. package/docs/modules.html +38 -24
  203. package/docs/types/BaseContractProperty.html +176 -0
  204. package/docs/types/BitcoinAddressLike.html +1 -1
  205. package/docs/types/BitcoinInterfaceAbi.html +174 -0
  206. package/docs/types/BlockHeaderChecksumProof.html +1 -1
  207. package/docs/types/DecodedCallResult.html +174 -0
  208. package/docs/types/ICallResult.html +2 -1
  209. package/docs/types/ITransaction.html +2 -1
  210. package/docs/types/PointerLike.html +1 -1
  211. package/docs/types/UTXOs.html +3 -1
  212. package/docs/variables/version.html +1 -1
  213. package/package.json +6 -4
  214. package/src/_version.ts +1 -1
  215. package/src/abi/BaseContractProperty.ts +8 -0
  216. package/src/abi/BitcoinAbiTypes.ts +9 -0
  217. package/src/abi/BitcoinInterface.ts +63 -0
  218. package/src/abi/interfaces/BaseContractProperties.ts +9 -0
  219. package/src/abi/interfaces/BitcoinAbiValue.ts +18 -0
  220. package/src/abi/interfaces/BitcoinInterfaceAbi.ts +19 -0
  221. package/src/bitcoin/BitcoinAddress.ts +5 -0
  222. package/src/bitcoin/UTXOs.ts +28 -26
  223. package/src/bitcoin/interfaces/IUTXO.ts +12 -0
  224. package/src/block/Block.ts +5 -0
  225. package/src/block/interfaces/IBlock.ts +46 -38
  226. package/src/common/CommonTypes.ts +16 -4
  227. package/src/contracts/CallResult.ts +34 -20
  228. package/src/contracts/Contract.ts +321 -0
  229. package/src/contracts/ContractData.ts +46 -41
  230. package/src/contracts/interfaces/IAccessList.ts +17 -7
  231. package/src/contracts/interfaces/ICallResult.ts +29 -15
  232. package/src/contracts/interfaces/IContract.ts +10 -0
  233. package/src/contracts/interfaces/IRawContract.ts +17 -12
  234. package/src/crypto/crypto-browser.js +71 -60
  235. package/src/opnet.ts +17 -0
  236. package/src/providers/AbstractRpcProvider.ts +352 -351
  237. package/src/scripts/testContract.ts +51 -0
  238. package/src/scripts/{test.ts → testMethods.ts} +52 -54
  239. package/src/scripts/test_abi.json +31 -0
  240. package/src/storage/StoredValue.ts +35 -30
  241. package/src/storage/interfaces/IStorageValue.ts +15 -10
  242. package/src/transactions/DeploymentTransaction.ts +41 -36
  243. package/src/transactions/GenericTransaction.ts +19 -12
  244. package/src/transactions/InteractionTransaction.ts +44 -40
  245. package/src/transactions/Transaction.ts +8 -0
  246. package/src/transactions/TransactionInput.ts +8 -0
  247. package/src/transactions/TransactionOutput.ts +8 -0
  248. package/src/transactions/TransactionParser.ts +47 -43
  249. package/src/transactions/TransactionReceipt.ts +22 -18
  250. package/src/transactions/interfaces/ITransaction.ts +78 -52
  251. package/src/transactions/interfaces/ITransactionReceipt.ts +14 -9
  252. package/src/utils/BitcoinUtils.ts +22 -0
  253. package/webpack.config.js +71 -75
@@ -1,6 +1,18 @@
1
1
  import { JSONRpcProvider } from '../providers/JSONRpcProvider.js';
2
2
  const provider = new JSONRpcProvider('https://testnet.opnet.org');
3
3
  (async () => {
4
+ const blockNumber = await provider.getBlockNumber();
5
+ console.log('Current network height:', blockNumber);
6
+ const block = await provider.getBlock(2810101n, true);
7
+ console.log('Block ->', block.transactions[2]);
8
+ const balance = await provider.getBalance('tb1qcfszz8dcvsz9mcp70ezw5zy2r3ydr0cfz60d3t');
9
+ console.log('Balance out:', balance);
10
+ const utxos = await provider.getUXTOs('tb1qcfszz8dcvsz9mcp70ezw5zy2r3ydr0cfz60d3t');
11
+ console.log('UTXOs:', utxos);
12
+ const transaction = await provider.getTransaction('63e77ba9fa4262b3d4d0d9d97fa8a7359534606c3f3af096284662e3f619f374');
13
+ console.log('Transaction:', transaction);
14
+ const receipt = await provider.getTransactionReceipt('63e77ba9fa4262b3d4d0d9d97fa8a7359534606c3f3af096284662e3f619f374');
15
+ console.log('Receipt:', receipt);
4
16
  const net = await provider.getNetwork();
5
17
  console.log(net);
6
18
  const code = await provider.getCode('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { ABIDataTypes } from '@btc-vision/bsi-binary';
2
+ import { BitcoinAbiTypes } from '../abi/BitcoinAbiTypes.js';
3
+ import { getContract } from '../contracts/Contract.js';
4
+ import { JSONRpcProvider } from '../providers/JSONRpcProvider.js';
5
+ const provider = new JSONRpcProvider('https://testnet.opnet.org');
6
+ (async () => {
7
+ const abi = [
8
+ {
9
+ name: 'balanceOf',
10
+ inputs: [
11
+ {
12
+ name: 'address',
13
+ type: ABIDataTypes.ADDRESS,
14
+ },
15
+ ],
16
+ outputs: [
17
+ {
18
+ name: 'balance',
19
+ type: ABIDataTypes.UINT256,
20
+ },
21
+ ],
22
+ type: BitcoinAbiTypes.Function,
23
+ },
24
+ ];
25
+ const contract = getContract('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', abi, provider);
26
+ const res = (await contract.balanceOf('bc1p134a291b21a4ef28c961daee77a75e81cd7c0f00733a152930f76746a3e9'));
27
+ console.log('Balance:', res.decoded);
28
+ })();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import { JSONRpcProvider } from '../providers/JSONRpcProvider.js';
2
+ const provider = new JSONRpcProvider('https://testnet.opnet.org');
3
+ (async () => {
4
+ const blockNumber = await provider.getBlockNumber();
5
+ console.log('Current network height:', blockNumber);
6
+ const block = await provider.getBlock(2810101n, true);
7
+ console.log('Block ->', block.transactions[2]);
8
+ const balance = await provider.getBalance('tb1qcfszz8dcvsz9mcp70ezw5zy2r3ydr0cfz60d3t');
9
+ console.log('Balance out:', balance);
10
+ const utxos = await provider.getUXTOs('tb1qcfszz8dcvsz9mcp70ezw5zy2r3ydr0cfz60d3t');
11
+ console.log('UTXOs:', utxos);
12
+ const transaction = await provider.getTransaction('63e77ba9fa4262b3d4d0d9d97fa8a7359534606c3f3af096284662e3f619f374');
13
+ console.log('Transaction:', transaction);
14
+ const receipt = await provider.getTransactionReceipt('63e77ba9fa4262b3d4d0d9d97fa8a7359534606c3f3af096284662e3f619f374');
15
+ console.log('Receipt:', receipt);
16
+ const net = await provider.getNetwork();
17
+ console.log(net);
18
+ const code = await provider.getCode('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a');
19
+ console.log('Code:', code);
20
+ const pointerValue = await provider.getStorageAt('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', 'EXLK/QhEQMI5d9DrthLvozT+UcDQ7WuSPaz7g8GV3AQ=', true);
21
+ console.log('Pointer value:', pointerValue);
22
+ const callResult = await provider.call('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', '82d62f3d3133734251714a646e416463377635746e583369665971414d6f4658373956664c79000000000000000000000000000000000000000000000000000000000000');
23
+ console.log('Call result:', callResult);
24
+ })();
@@ -0,0 +1,4 @@
1
+ import { BigNumberish } from 'ethers';
2
+ export declare class BitcoinUtils {
3
+ static formatUnits(value: BigNumberish, decimals?: number): string;
4
+ }
@@ -0,0 +1,7 @@
1
+ import BigNumber from 'bignumber.js';
2
+ export class BitcoinUtils {
3
+ static formatUnits(value, decimals = 8) {
4
+ const bn = new BigNumber(value.toString());
5
+ return bn.dividedBy(new BigNumber(10).pow(decimals)).toString();
6
+ }
7
+ }
@@ -0,0 +1 @@
1
+ export declare const version = "1.0.12";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.version = void 0;
4
+ exports.version = '1.0.12';
@@ -0,0 +1,3 @@
1
+ import { CallResult } from '../contracts/CallResult.js';
2
+ import { ICallRequestError } from '../contracts/interfaces/ICallResult.js';
3
+ export type BaseContractProperty = CallResult | ICallRequestError;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export declare enum BitcoinAbiTypes {
2
+ Function = "function",
3
+ Event = "event"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitcoinAbiTypes = void 0;
4
+ var BitcoinAbiTypes;
5
+ (function (BitcoinAbiTypes) {
6
+ BitcoinAbiTypes["Function"] = "function";
7
+ BitcoinAbiTypes["Event"] = "event";
8
+ })(BitcoinAbiTypes || (exports.BitcoinAbiTypes = BitcoinAbiTypes = {}));
@@ -0,0 +1,9 @@
1
+ import { BitcoinInterfaceAbi } from './interfaces/BitcoinInterfaceAbi.js';
2
+ export declare class BitcoinInterface {
3
+ readonly abi: BitcoinInterfaceAbi;
4
+ constructor(abi: BitcoinInterfaceAbi);
5
+ static from(abi: BitcoinInterface | BitcoinInterfaceAbi): BitcoinInterface;
6
+ hasFunction(name: string): boolean;
7
+ private verifyAbi;
8
+ private verifyAbiValues;
9
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BitcoinInterface = void 0;
4
+ class BitcoinInterface {
5
+ abi;
6
+ constructor(abi) {
7
+ this.verifyAbi(abi);
8
+ this.abi = abi;
9
+ }
10
+ static from(abi) {
11
+ if (abi instanceof BitcoinInterface) {
12
+ return abi;
13
+ }
14
+ return new BitcoinInterface(abi);
15
+ }
16
+ hasFunction(name) {
17
+ return this.abi.some((element) => element.name === name && element.type === 'function');
18
+ }
19
+ verifyAbi(abi) {
20
+ if (abi.length === 0) {
21
+ throw new Error('The ABI provided is empty.');
22
+ }
23
+ for (let i = 0; i < abi.length; i++) {
24
+ const element = abi[i];
25
+ if (!element.name) {
26
+ throw new Error('The ABI provided is missing a name.');
27
+ }
28
+ if (!element.type) {
29
+ throw new Error('The ABI provided is missing a type.');
30
+ }
31
+ if (element.inputs && element.inputs.length)
32
+ this.verifyAbiValues(element.inputs);
33
+ if (element.outputs && element.outputs.length)
34
+ this.verifyAbiValues(element.outputs);
35
+ }
36
+ }
37
+ verifyAbiValues(inputs) {
38
+ for (let j = 0; j < inputs.length; j++) {
39
+ const input = inputs[j];
40
+ if (!input.name) {
41
+ throw new Error('The ABI provided is missing an input name.');
42
+ }
43
+ if (!input.type) {
44
+ throw new Error('The ABI provided is missing an input type.');
45
+ }
46
+ }
47
+ }
48
+ }
49
+ exports.BitcoinInterface = BitcoinInterface;
@@ -0,0 +1,4 @@
1
+ import { BaseContractProperty } from '../BaseContractProperty.js';
2
+ export interface BaseContractProperties {
3
+ [key: symbol]: BaseContractProperty;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import { ABIDataTypes } from '@btc-vision/bsi-binary';
2
+ export interface BitcoinAbiValue {
3
+ name: string;
4
+ type: ABIDataTypes;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import { BitcoinAbiTypes } from '../BitcoinAbiTypes.js';
2
+ import { BitcoinAbiValue } from './BitcoinAbiValue.js';
3
+ export interface BitcoinInterfaceAbiBase {
4
+ readonly constant?: boolean;
5
+ readonly name: string;
6
+ readonly inputs?: BitcoinAbiValue[];
7
+ readonly outputs?: BitcoinAbiValue[];
8
+ readonly type: BitcoinAbiTypes;
9
+ readonly payable?: boolean;
10
+ }
11
+ export type BitcoinInterfaceAbi = BitcoinInterfaceAbiBase[];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ import { Network } from 'bitcoinjs-lib';
3
+ import { ECPairInterface } from 'ecpair';
4
+ import { BitcoinAddressLike } from '../common/CommonTypes.js';
5
+ export declare class BitcoinAddress {
6
+ #private;
7
+ private readonly network;
8
+ constructor(keypair: ECPairInterface, network?: Network);
9
+ get taprootAddress(): string;
10
+ get p2wpkhAddress(): string;
11
+ get publicKey(): Buffer;
12
+ get privateKey(): Buffer | undefined;
13
+ static isValidTaprootAddress(_addr: BitcoinAddressLike, network?: Network): boolean;
14
+ static fromPublicKey(publicKey: Buffer, network?: Network): BitcoinAddress;
15
+ static fromPrivateKey(privateKey: Buffer, network?: Network): BitcoinAddress;
16
+ static fromWif(wif: string, network?: Network): BitcoinAddress;
17
+ [Symbol.toStringTag](): string;
18
+ private getP2WPKHAddress;
19
+ private getTaprootAddress;
20
+ }
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.BitcoinAddress = void 0;
27
+ const ecc = __importStar(require("@bitcoinerlab/secp256k1"));
28
+ const bitcoinjs_lib_1 = require("bitcoinjs-lib");
29
+ const ecpair_1 = require("ecpair");
30
+ (0, bitcoinjs_lib_1.initEccLib)(ecc);
31
+ const ECPair = (0, ecpair_1.ECPairFactory)(ecc);
32
+ class BitcoinAddress {
33
+ #keyPair;
34
+ #taprootAddress;
35
+ #p2wpkhAddress;
36
+ network;
37
+ constructor(keypair, network = bitcoinjs_lib_1.networks.bitcoin) {
38
+ this.#keyPair = keypair;
39
+ this.network = network;
40
+ this.#taprootAddress = this.getTaprootAddress();
41
+ this.#p2wpkhAddress = this.getP2WPKHAddress();
42
+ }
43
+ get taprootAddress() {
44
+ if (!this.#taprootAddress) {
45
+ throw new Error('Address not set');
46
+ }
47
+ return this.#taprootAddress;
48
+ }
49
+ get p2wpkhAddress() {
50
+ if (!this.#p2wpkhAddress) {
51
+ throw new Error('Address not set');
52
+ }
53
+ return this.#p2wpkhAddress;
54
+ }
55
+ get publicKey() {
56
+ if (!this.#keyPair) {
57
+ throw new Error('KeyPair not set');
58
+ }
59
+ return this.#keyPair.publicKey;
60
+ }
61
+ get privateKey() {
62
+ if (!this.#keyPair) {
63
+ throw new Error('KeyPair not set');
64
+ }
65
+ return this.#keyPair.privateKey;
66
+ }
67
+ static isValidTaprootAddress(_addr, network = bitcoinjs_lib_1.networks.bitcoin) {
68
+ try {
69
+ let addr;
70
+ if (typeof _addr === 'string') {
71
+ addr = _addr;
72
+ }
73
+ else {
74
+ addr = _addr.taprootAddress;
75
+ }
76
+ return !!bitcoinjs_lib_1.address.toOutputScript(addr, network);
77
+ }
78
+ catch (err) {
79
+ return false;
80
+ }
81
+ }
82
+ static fromPublicKey(publicKey, network = bitcoinjs_lib_1.networks.bitcoin) {
83
+ const keyPair = ECPair.fromPublicKey(publicKey, { network });
84
+ return new BitcoinAddress(keyPair, network);
85
+ }
86
+ static fromPrivateKey(privateKey, network = bitcoinjs_lib_1.networks.bitcoin) {
87
+ const keyPair = ECPair.fromPrivateKey(privateKey, { network });
88
+ return new BitcoinAddress(keyPair, network);
89
+ }
90
+ static fromWif(wif, network = bitcoinjs_lib_1.networks.bitcoin) {
91
+ const keyPair = ECPair.fromWIF(wif, network);
92
+ return new BitcoinAddress(keyPair, network);
93
+ }
94
+ [Symbol.toStringTag]() {
95
+ return this.taprootAddress;
96
+ }
97
+ getP2WPKHAddress() {
98
+ const res = bitcoinjs_lib_1.payments.p2wpkh({ pubkey: this.#keyPair.publicKey, network: this.network });
99
+ if (!res.address) {
100
+ throw new Error('Failed to generate wallet');
101
+ }
102
+ return res.address;
103
+ }
104
+ getTaprootAddress() {
105
+ if (!this.#keyPair) {
106
+ throw new Error('KeyPair not set');
107
+ }
108
+ const myXOnlyPubkey = this.#keyPair.publicKey.slice(1, 33);
109
+ const output = Buffer.concat([
110
+ Buffer.from([0x51, 0x20]),
111
+ myXOnlyPubkey,
112
+ ]);
113
+ return bitcoinjs_lib_1.address.fromOutputScript(output, this.network);
114
+ }
115
+ }
116
+ exports.BitcoinAddress = BitcoinAddress;
@@ -0,0 +1,15 @@
1
+ import { ScriptPubKey } from '@btc-vision/bsi-bitcoin-rpc';
2
+ export interface IUTXO {
3
+ readonly transactionId: string;
4
+ readonly outputIndex: number;
5
+ readonly value: bigint | string;
6
+ readonly scriptPubKey: ScriptPubKey;
7
+ }
8
+ export declare class UTXO implements IUTXO {
9
+ readonly transactionId: string;
10
+ readonly outputIndex: number;
11
+ readonly value: bigint;
12
+ readonly scriptPubKey: ScriptPubKey;
13
+ constructor(iUTXO: IUTXO);
14
+ }
15
+ export type UTXOs = UTXO[];
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UTXO = void 0;
4
+ class UTXO {
5
+ transactionId;
6
+ outputIndex;
7
+ value;
8
+ scriptPubKey;
9
+ constructor(iUTXO) {
10
+ this.transactionId = iUTXO.transactionId;
11
+ this.outputIndex = iUTXO.outputIndex;
12
+ this.value = BigInt(iUTXO.value);
13
+ this.scriptPubKey = iUTXO.scriptPubKey;
14
+ }
15
+ }
16
+ exports.UTXO = UTXO;
@@ -1,7 +1,7 @@
1
1
  import { BigNumberish } from 'ethers';
2
- import { BlockHeaderChecksumProof, IBlock } from '../interfaces/blocks/IBlock.js';
3
2
  import { OPNetTransactionTypes } from '../interfaces/opnet/OPNetTransactionTypes.js';
4
3
  import { TransactionBase } from '../transactions/Transaction.js';
4
+ import { BlockHeaderChecksumProof, IBlock } from './interfaces/IBlock.js';
5
5
  export declare class Block implements IBlock {
6
6
  readonly height: BigNumberish;
7
7
  readonly hash: string;
@@ -21,7 +21,6 @@ export declare class Block implements IBlock {
21
21
  readonly storageRoot: string;
22
22
  readonly receiptRoot: string;
23
23
  readonly checksumProofs: BlockHeaderChecksumProof;
24
- readonly transactions?: TransactionBase<OPNetTransactionTypes>[];
24
+ readonly transactions: TransactionBase<OPNetTransactionTypes>[];
25
25
  constructor(block: IBlock);
26
- private getTransactions;
27
26
  }
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Block = void 0;
4
- const OPNetTransactionTypes_js_1 = require("../interfaces/opnet/OPNetTransactionTypes.js");
5
- const DeploymentTransaction_js_1 = require("../transactions/DeploymentTransaction.js");
6
- const GenericTransaction_js_1 = require("../transactions/GenericTransaction.js");
7
- const InteractionTransaction_js_1 = require("../transactions/InteractionTransaction.js");
4
+ const TransactionParser_js_1 = require("../transactions/TransactionParser.js");
8
5
  class Block {
9
6
  height;
10
7
  hash;
@@ -24,7 +21,7 @@ class Block {
24
21
  storageRoot;
25
22
  receiptRoot;
26
23
  checksumProofs;
27
- transactions;
24
+ transactions = [];
28
25
  constructor(block) {
29
26
  this.height = BigInt(block.height.toString());
30
27
  this.hash = block.hash;
@@ -44,29 +41,7 @@ class Block {
44
41
  this.storageRoot = block.storageRoot;
45
42
  this.receiptRoot = block.receiptRoot;
46
43
  this.checksumProofs = block.checksumProofs;
47
- this.transactions = this.getTransactions(block.transactions);
48
- }
49
- getTransactions(transactions) {
50
- if (!transactions) {
51
- return [];
52
- }
53
- const transactionArray = [];
54
- for (let transaction of transactions) {
55
- switch (transaction.OPNetType) {
56
- case OPNetTransactionTypes_js_1.OPNetTransactionTypes.Generic:
57
- transactionArray.push(new GenericTransaction_js_1.GenericTransaction(transaction));
58
- break;
59
- case OPNetTransactionTypes_js_1.OPNetTransactionTypes.Interaction:
60
- transactionArray.push(new InteractionTransaction_js_1.InteractionTransaction(transaction));
61
- break;
62
- case OPNetTransactionTypes_js_1.OPNetTransactionTypes.Deployment:
63
- transactionArray.push(new DeploymentTransaction_js_1.DeploymentTransaction(transaction));
64
- break;
65
- default:
66
- throw new Error('Unknown transaction type');
67
- }
68
- }
69
- return transactionArray;
44
+ this.transactions = TransactionParser_js_1.TransactionParser.parseTransactions(block.transactions);
70
45
  }
71
46
  }
72
47
  exports.Block = Block;
@@ -0,0 +1,28 @@
1
+ import { BigNumberish } from 'ethers';
2
+ import { OPNetTransactionTypes } from '../../interfaces/opnet/OPNetTransactionTypes.js';
3
+ import { ITransaction } from '../../transactions/interfaces/ITransaction.js';
4
+ import { TransactionBase } from '../../transactions/Transaction.js';
5
+ export type BlockHeaderChecksumProof = Array<[number, string[]]>;
6
+ export interface IBlockCommon {
7
+ height: string | BigNumberish;
8
+ hash: string;
9
+ previousBlockHash: string;
10
+ previousBlockChecksum: string;
11
+ bits: string;
12
+ nonce: number;
13
+ version: number;
14
+ size: number;
15
+ txCount: number;
16
+ weight: number;
17
+ strippedSize: number;
18
+ time: number;
19
+ medianTime: number;
20
+ checksumRoot: string;
21
+ merkleRoot: string;
22
+ storageRoot: string;
23
+ receiptRoot: string;
24
+ checksumProofs: BlockHeaderChecksumProof;
25
+ }
26
+ export interface IBlock extends IBlockCommon {
27
+ transactions?: ITransaction[] | TransactionBase<OPNetTransactionTypes>[];
28
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import { BitcoinAddress } from '../bitcoin/BitcoinAddress.js';
2
+ export type BitcoinAddressLike = string | BitcoinAddress;
3
+ export type PointerLike = bigint | string;
4
+ export type DecodedCallResult = bigint | string | boolean | number | Uint8Array | Array<bigint> | Array<string> | Array<boolean> | Array<number> | Array<Uint8Array>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ import { BinaryReader, NetEvent } from '@btc-vision/bsi-binary';
2
+ import { DecodedCallResult } from '../common/CommonTypes.js';
3
+ import { IAccessList } from './interfaces/IAccessList.js';
4
+ import { ICallResultData } from './interfaces/ICallResult.js';
5
+ export declare class CallResult implements ICallResultData {
6
+ readonly result: BinaryReader;
7
+ readonly events: NetEvent[];
8
+ readonly accessList: IAccessList;
9
+ readonly decoded: Array<DecodedCallResult>;
10
+ constructor(iCallResult: ICallResultData);
11
+ setDecoded(decoded: Array<DecodedCallResult>): void;
12
+ private base64ToUint8Array;
13
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CallResult = void 0;
4
+ const bsi_binary_1 = require("@btc-vision/bsi-binary");
5
+ class CallResult {
6
+ result;
7
+ events;
8
+ accessList;
9
+ decoded = [];
10
+ constructor(iCallResult) {
11
+ this.events = iCallResult.events;
12
+ this.accessList = iCallResult.accessList;
13
+ this.result =
14
+ typeof iCallResult.result === 'string'
15
+ ? new bsi_binary_1.BinaryReader(this.base64ToUint8Array(iCallResult.result))
16
+ : iCallResult.result;
17
+ }
18
+ setDecoded(decoded) {
19
+ this.decoded.push(...decoded);
20
+ }
21
+ base64ToUint8Array(base64) {
22
+ return bsi_binary_1.BufferHelper.bufferToUint8Array(Buffer.from(base64, 'base64'));
23
+ }
24
+ }
25
+ exports.CallResult = CallResult;
@@ -0,0 +1,28 @@
1
+ import { BaseContractProperty } from '../abi/BaseContractProperty.js';
2
+ import { BitcoinInterface } from '../abi/BitcoinInterface.js';
3
+ import { BaseContractProperties } from '../abi/interfaces/BaseContractProperties.js';
4
+ import { BitcoinInterfaceAbi } from '../abi/interfaces/BitcoinInterfaceAbi.js';
5
+ import { BitcoinAddressLike } from '../common/CommonTypes.js';
6
+ import { AbstractRpcProvider } from '../providers/AbstractRpcProvider.js';
7
+ import { IContract } from './interfaces/IContract.js';
8
+ declare const internal: unique symbol;
9
+ export declare class IBaseContract<T extends BaseContractProperties> implements IContract {
10
+ readonly address: BitcoinAddressLike;
11
+ readonly interface: BitcoinInterface;
12
+ readonly provider: AbstractRpcProvider;
13
+ readonly [internal]: keyof T | undefined;
14
+ private events;
15
+ constructor(address: BitcoinAddressLike, abi: BitcoinInterface | BitcoinInterfaceAbi, provider: AbstractRpcProvider);
16
+ protected getFunction(name: symbol): BaseContractProperty | undefined | string | number | symbol;
17
+ private defineInternalFunctions;
18
+ private encodeFunctionData;
19
+ private encodeInput;
20
+ private decodeOutput;
21
+ private callFunction;
22
+ }
23
+ export declare class BaseContract<T extends BaseContractProperties> extends IBaseContract<T> {
24
+ constructor(address: BitcoinAddressLike, abi: BitcoinInterface | BitcoinInterfaceAbi, provider: AbstractRpcProvider);
25
+ private proxify;
26
+ }
27
+ export declare function getContract<T extends BaseContractProperties>(address: BitcoinAddressLike, abi: BitcoinInterface | BitcoinInterfaceAbi, provider: AbstractRpcProvider): BaseContract<T> & Omit<T, keyof BaseContract<T>>;
28
+ export {};