@ckb-ccc/core 0.0.4-alpha.8 → 0.0.5-alpha.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 (209) hide show
  1. package/README.md +6 -0
  2. package/dist/ckb/transaction.d.ts +85 -2
  3. package/dist/ckb/transaction.d.ts.map +1 -1
  4. package/dist/ckb/transaction.js +152 -7
  5. package/dist/client/client.d.ts +8 -3
  6. package/dist/client/client.d.ts.map +1 -1
  7. package/dist/client/client.js +29 -2
  8. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  9. package/dist/client/clientPublicMainnet.advanced.js +4 -0
  10. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  11. package/dist/client/clientPublicTestnet.advanced.js +4 -0
  12. package/dist/client/clientTypes.d.ts +48 -1
  13. package/dist/client/clientTypes.d.ts.map +1 -1
  14. package/dist/client/clientTypes.js +27 -1
  15. package/dist/client/jsonRpc/index.d.ts +9 -1
  16. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  17. package/dist/client/jsonRpc/index.js +15 -1
  18. package/dist/client/jsonRpc/transformers.d.ts +17 -3
  19. package/dist/client/jsonRpc/transformers.d.ts.map +1 -1
  20. package/dist/client/jsonRpc/transformers.js +37 -3
  21. package/dist/client/jsonRpc/types.d.ts +15 -0
  22. package/dist/client/jsonRpc/types.d.ts.map +1 -1
  23. package/dist/fixedPoint/index.d.ts.map +1 -1
  24. package/dist/fixedPoint/index.js +4 -1
  25. package/dist/fixedPoint/index.test.d.ts +2 -0
  26. package/dist/fixedPoint/index.test.d.ts.map +1 -0
  27. package/dist/fixedPoint/index.test.js +43 -0
  28. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  29. package/dist/signer/btc/signerBtc.js +2 -3
  30. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +12 -0
  31. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  32. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +16 -0
  33. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +12 -0
  34. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  35. package/dist/signer/ckb/signerCkbScriptReadonly.js +16 -0
  36. package/dist/signer/evm/signerEvm.d.ts +5 -1
  37. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  38. package/dist/signer/evm/signerEvm.js +21 -8
  39. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +13 -1
  40. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  41. package/dist/signer/evm/signerEvmAddressReadonly.js +16 -0
  42. package/dist/signer/index.d.ts +0 -1
  43. package/dist/signer/index.d.ts.map +1 -1
  44. package/dist/signer/index.js +0 -1
  45. package/dist/signer/signer.d.ts +26 -6
  46. package/dist/signer/signer.d.ts.map +1 -1
  47. package/dist/signer/signer.js +14 -3
  48. package/dist.commonjs/address/address.advanced.d.ts +65 -0
  49. package/dist.commonjs/address/address.advanced.d.ts.map +1 -0
  50. package/dist.commonjs/address/address.advanced.js +149 -0
  51. package/dist.commonjs/address/advanced.d.ts +2 -0
  52. package/dist.commonjs/address/advanced.d.ts.map +1 -0
  53. package/dist.commonjs/address/advanced.js +17 -0
  54. package/dist.commonjs/address/index.d.ts +54 -0
  55. package/dist.commonjs/address/index.d.ts.map +1 -0
  56. package/dist.commonjs/address/index.js +84 -0
  57. package/dist.commonjs/advanced.d.ts +3 -0
  58. package/dist.commonjs/advanced.d.ts.map +1 -0
  59. package/dist.commonjs/advanced.js +31 -0
  60. package/dist.commonjs/advancedBarrel.d.ts +5 -0
  61. package/dist.commonjs/advancedBarrel.d.ts.map +1 -0
  62. package/dist.commonjs/advancedBarrel.js +20 -0
  63. package/dist.commonjs/barrel.d.ts +11 -0
  64. package/dist.commonjs/barrel.d.ts.map +1 -0
  65. package/dist.commonjs/barrel.js +26 -0
  66. package/dist.commonjs/bytes/advanced.d.ts +5 -0
  67. package/dist.commonjs/bytes/advanced.d.ts.map +1 -0
  68. package/dist.commonjs/bytes/advanced.js +2 -0
  69. package/dist.commonjs/bytes/index.d.ts +64 -0
  70. package/dist.commonjs/bytes/index.d.ts.map +1 -0
  71. package/dist.commonjs/bytes/index.js +97 -0
  72. package/dist.commonjs/ckb/advanced.d.ts +4 -0
  73. package/dist.commonjs/ckb/advanced.d.ts.map +1 -0
  74. package/dist.commonjs/ckb/advanced.js +32 -0
  75. package/dist.commonjs/ckb/index.d.ts +3 -0
  76. package/dist.commonjs/ckb/index.d.ts.map +1 -0
  77. package/dist.commonjs/ckb/index.js +18 -0
  78. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +355 -0
  79. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts.map +1 -0
  80. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -0
  81. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +6 -0
  82. package/dist.commonjs/ckb/molecule.advanced/index.d.ts.map +1 -0
  83. package/dist.commonjs/ckb/molecule.advanced/index.js +25 -0
  84. package/dist.commonjs/ckb/script.advanced.d.ts +5 -0
  85. package/dist.commonjs/ckb/script.advanced.d.ts.map +1 -0
  86. package/dist.commonjs/ckb/script.advanced.js +16 -0
  87. package/dist.commonjs/ckb/script.d.ts +126 -0
  88. package/dist.commonjs/ckb/script.d.ts.map +1 -0
  89. package/dist.commonjs/ckb/script.js +188 -0
  90. package/dist.commonjs/ckb/transaction.advanced.d.ts +5 -0
  91. package/dist.commonjs/ckb/transaction.advanced.d.ts.map +1 -0
  92. package/dist.commonjs/ckb/transaction.advanced.js +12 -0
  93. package/dist.commonjs/ckb/transaction.d.ts +616 -0
  94. package/dist.commonjs/ckb/transaction.d.ts.map +1 -0
  95. package/dist.commonjs/ckb/transaction.js +810 -0
  96. package/dist.commonjs/client/advanced.d.ts +4 -0
  97. package/dist.commonjs/client/advanced.d.ts.map +1 -0
  98. package/dist.commonjs/client/advanced.js +19 -0
  99. package/dist.commonjs/client/client.d.ts +24 -0
  100. package/dist.commonjs/client/client.d.ts.map +1 -0
  101. package/dist.commonjs/client/client.js +57 -0
  102. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -0
  103. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -0
  104. package/dist.commonjs/client/clientPublicMainnet.advanced.js +30 -0
  105. package/dist.commonjs/client/clientPublicMainnet.d.ts +9 -0
  106. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -0
  107. package/dist.commonjs/client/clientPublicMainnet.js +17 -0
  108. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +4 -0
  109. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts.map +1 -0
  110. package/dist.commonjs/client/clientPublicTestnet.advanced.js +30 -0
  111. package/dist.commonjs/client/clientPublicTestnet.d.ts +9 -0
  112. package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -0
  113. package/dist.commonjs/client/clientPublicTestnet.js +17 -0
  114. package/dist.commonjs/client/clientTypes.d.ts +55 -0
  115. package/dist.commonjs/client/clientTypes.d.ts.map +1 -0
  116. package/dist.commonjs/client/clientTypes.js +31 -0
  117. package/dist.commonjs/client/index.d.ts +6 -0
  118. package/dist.commonjs/client/index.d.ts.map +1 -0
  119. package/dist.commonjs/client/index.js +21 -0
  120. package/dist.commonjs/client/jsonRpc/advanced.d.ts +3 -0
  121. package/dist.commonjs/client/jsonRpc/advanced.d.ts.map +1 -0
  122. package/dist.commonjs/client/jsonRpc/advanced.js +18 -0
  123. package/dist.commonjs/client/jsonRpc/index.d.ts +76 -0
  124. package/dist.commonjs/client/jsonRpc/index.d.ts.map +1 -0
  125. package/dist.commonjs/client/jsonRpc/index.js +142 -0
  126. package/dist.commonjs/client/jsonRpc/transformers.d.ts +42 -0
  127. package/dist.commonjs/client/jsonRpc/transformers.d.ts.map +1 -0
  128. package/dist.commonjs/client/jsonRpc/transformers.js +160 -0
  129. package/dist.commonjs/client/jsonRpc/types.d.ts +56 -0
  130. package/dist.commonjs/client/jsonRpc/types.d.ts.map +1 -0
  131. package/dist.commonjs/client/jsonRpc/types.js +2 -0
  132. package/dist.commonjs/fixedPoint/index.d.ts +49 -0
  133. package/dist.commonjs/fixedPoint/index.d.ts.map +1 -0
  134. package/dist.commonjs/fixedPoint/index.js +68 -0
  135. package/dist.commonjs/fixedPoint/index.test.d.ts +2 -0
  136. package/dist.commonjs/fixedPoint/index.test.d.ts.map +1 -0
  137. package/dist.commonjs/fixedPoint/index.test.js +45 -0
  138. package/dist.commonjs/hasher/advanced.d.ts +2 -0
  139. package/dist.commonjs/hasher/advanced.d.ts.map +1 -0
  140. package/dist.commonjs/hasher/advanced.js +4 -0
  141. package/dist.commonjs/hasher/index.d.ts +52 -0
  142. package/dist.commonjs/hasher/index.d.ts.map +1 -0
  143. package/dist.commonjs/hasher/index.js +68 -0
  144. package/dist.commonjs/hex/index.d.ts +24 -0
  145. package/dist.commonjs/hex/index.d.ts.map +1 -0
  146. package/dist.commonjs/hex/index.js +20 -0
  147. package/dist.commonjs/index.d.ts +3 -0
  148. package/dist.commonjs/index.d.ts.map +1 -0
  149. package/dist.commonjs/index.js +31 -0
  150. package/dist.commonjs/num/index.d.ts +112 -0
  151. package/dist.commonjs/num/index.d.ts.map +1 -0
  152. package/dist.commonjs/num/index.js +139 -0
  153. package/dist.commonjs/signer/btc/index.d.ts +3 -0
  154. package/dist.commonjs/signer/btc/index.d.ts.map +1 -0
  155. package/dist.commonjs/signer/btc/index.js +18 -0
  156. package/dist.commonjs/signer/btc/signerBtc.d.ts +50 -0
  157. package/dist.commonjs/signer/btc/signerBtc.d.ts.map +1 -0
  158. package/dist.commonjs/signer/btc/signerBtc.js +70 -0
  159. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +60 -0
  160. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -0
  161. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +72 -0
  162. package/dist.commonjs/signer/ckb/index.d.ts +2 -0
  163. package/dist.commonjs/signer/ckb/index.d.ts.map +1 -0
  164. package/dist.commonjs/signer/ckb/index.js +17 -0
  165. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +59 -0
  166. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -0
  167. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +71 -0
  168. package/dist.commonjs/signer/evm/index.d.ts +3 -0
  169. package/dist.commonjs/signer/evm/index.d.ts.map +1 -0
  170. package/dist.commonjs/signer/evm/index.js +18 -0
  171. package/dist.commonjs/signer/evm/signerEvm.d.ts +46 -0
  172. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -0
  173. package/dist.commonjs/signer/evm/signerEvm.js +82 -0
  174. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +52 -0
  175. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -0
  176. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +62 -0
  177. package/dist.commonjs/signer/index.d.ts +5 -0
  178. package/dist.commonjs/signer/index.d.ts.map +1 -0
  179. package/dist.commonjs/signer/index.js +20 -0
  180. package/dist.commonjs/signer/signer.d.ts +133 -0
  181. package/dist.commonjs/signer/signer.d.ts.map +1 -0
  182. package/dist.commonjs/signer/signer.js +117 -0
  183. package/dist.commonjs/tsconfig.commonjs.tsbuildinfo +1 -0
  184. package/dist.commonjs/utils/index.d.ts +7 -0
  185. package/dist.commonjs/utils/index.d.ts.map +1 -0
  186. package/dist.commonjs/utils/index.js +10 -0
  187. package/jest.config.js +5 -0
  188. package/package.json +24 -7
  189. package/src/ckb/transaction.ts +198 -3
  190. package/src/client/client.ts +64 -3
  191. package/src/client/clientPublicMainnet.advanced.ts +5 -0
  192. package/src/client/clientPublicTestnet.advanced.ts +5 -0
  193. package/src/client/clientTypes.ts +70 -1
  194. package/src/client/jsonRpc/index.ts +38 -2
  195. package/src/client/jsonRpc/transformers.ts +73 -4
  196. package/src/client/jsonRpc/types.ts +16 -0
  197. package/src/fixedPoint/index.test.ts +55 -0
  198. package/src/fixedPoint/index.ts +7 -1
  199. package/src/signer/btc/signerBtc.ts +6 -3
  200. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +18 -0
  201. package/src/signer/ckb/signerCkbScriptReadonly.ts +18 -0
  202. package/src/signer/evm/signerEvm.ts +56 -14
  203. package/src/signer/evm/signerEvmAddressReadonly.ts +19 -1
  204. package/src/signer/index.ts +0 -1
  205. package/src/signer/signer.ts +29 -3
  206. package/dist/signer/helpers.d.ts +0 -40
  207. package/dist/signer/helpers.d.ts.map +0 -1
  208. package/dist/signer/helpers.js +0 -90
  209. package/src/signer/helpers.ts +0 -122
@@ -1,40 +0,0 @@
1
- import { ScriptLike, Transaction, TransactionLike } from "../ckb";
2
- import { Client } from "../client";
3
- import { Hex } from "../hex";
4
- /**
5
- * Computes the signing hash information for a given transaction and script.
6
- *
7
- * @param txLike - The transaction to sign, represented as a TransactionLike object.
8
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
9
- * @param client - The client for complete extra infos in the transaction.
10
- * @returns A promise that resolves to an object containing the signing message and the witness position,
11
- * or undefined if no matching input is found.
12
- *
13
- * @example
14
- * ```typescript
15
- * const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
16
- * if (signHashInfo) {
17
- * console.log(signHashInfo.message); // Outputs the signing message
18
- * console.log(signHashInfo.position); // Outputs the witness position
19
- * }
20
- * ```
21
- */
22
- export declare function getSignHashInfo(txLike: TransactionLike, scriptLike: ScriptLike, client: Client): Promise<{
23
- message: Hex;
24
- position: number;
25
- } | undefined>;
26
- /**
27
- * Prepare dummy witness for sighash all method
28
- *
29
- * @param txLike - The transaction to prepare, represented as a TransactionLike object.
30
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
31
- * @param client - The client for complete extra infos in the transaction.
32
- * @returns A promise that resolves to the prepared transaction
33
- *
34
- * @example
35
- * ```typescript
36
- * const tx = await prepareSighashAllWitness(transactionLike, scriptLike, client);
37
- * ```
38
- */
39
- export declare function prepareSighashAllWitness(txLike: TransactionLike, scriptLike: ScriptLike, lockLen: number, client: Client): Promise<Transaction>;
40
- //# sourceMappingURL=helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/signer/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,WAAW,EACX,eAAe,EAEhB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,GAAG,EAAW,MAAM,QAAQ,CAAC;AAEtC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAuCzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CA6BtB"}
@@ -1,90 +0,0 @@
1
- import { Script, Transaction, WitnessArgs, } from "../ckb";
2
- import { Hasher } from "../hasher";
3
- import { hexFrom } from "../hex";
4
- /**
5
- * Computes the signing hash information for a given transaction and script.
6
- *
7
- * @param txLike - The transaction to sign, represented as a TransactionLike object.
8
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
9
- * @param client - The client for complete extra infos in the transaction.
10
- * @returns A promise that resolves to an object containing the signing message and the witness position,
11
- * or undefined if no matching input is found.
12
- *
13
- * @example
14
- * ```typescript
15
- * const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
16
- * if (signHashInfo) {
17
- * console.log(signHashInfo.message); // Outputs the signing message
18
- * console.log(signHashInfo.position); // Outputs the witness position
19
- * }
20
- * ```
21
- */
22
- export async function getSignHashInfo(txLike, scriptLike, client) {
23
- const tx = Transaction.from(txLike);
24
- const script = Script.from(scriptLike);
25
- let position = -1;
26
- const hasher = new Hasher();
27
- hasher.update(tx.hash());
28
- for (let i = 0; i < tx.witnesses.length; i += 1) {
29
- if (tx.inputs[i]) {
30
- const input = await tx.inputs[i].completeExtraInfos(client);
31
- if (!input.cellOutput) {
32
- throw Error("Unable to resolve inputs info");
33
- }
34
- if (!script.eq(input.cellOutput.lock)) {
35
- continue;
36
- }
37
- if (position === -1) {
38
- position = i;
39
- }
40
- }
41
- if (position === -1) {
42
- return undefined;
43
- }
44
- Transaction.hashWitnessToHasher(tx.witnesses[i], hasher);
45
- }
46
- if (position === -1) {
47
- return undefined;
48
- }
49
- return {
50
- message: hasher.digest(),
51
- position,
52
- };
53
- }
54
- /**
55
- * Prepare dummy witness for sighash all method
56
- *
57
- * @param txLike - The transaction to prepare, represented as a TransactionLike object.
58
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
59
- * @param client - The client for complete extra infos in the transaction.
60
- * @returns A promise that resolves to the prepared transaction
61
- *
62
- * @example
63
- * ```typescript
64
- * const tx = await prepareSighashAllWitness(transactionLike, scriptLike, client);
65
- * ```
66
- */
67
- export async function prepareSighashAllWitness(txLike, scriptLike, lockLen, client) {
68
- const tx = Transaction.from(txLike);
69
- const script = Script.from(scriptLike);
70
- let position = -1;
71
- for (let i = 0; i < tx.inputs.length; i += 1) {
72
- const input = await tx.inputs[i].completeExtraInfos(client);
73
- if (!input.cellOutput) {
74
- throw Error("Unable to resolve inputs info");
75
- }
76
- if (script.eq(input.cellOutput.lock)) {
77
- position = i;
78
- break;
79
- }
80
- }
81
- if (position === -1) {
82
- return tx;
83
- }
84
- const witness = tx.witnesses[position]
85
- ? WitnessArgs.fromBytes(tx.witnesses[position])
86
- : WitnessArgs.from({});
87
- witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
88
- tx.witnesses[position] = hexFrom(witness.toBytes());
89
- return tx;
90
- }
@@ -1,122 +0,0 @@
1
- import {
2
- Script,
3
- ScriptLike,
4
- Transaction,
5
- TransactionLike,
6
- WitnessArgs,
7
- } from "../ckb";
8
- import { Client } from "../client";
9
- import { Hasher } from "../hasher";
10
- import { Hex, hexFrom } from "../hex";
11
-
12
- /**
13
- * Computes the signing hash information for a given transaction and script.
14
- *
15
- * @param txLike - The transaction to sign, represented as a TransactionLike object.
16
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
17
- * @param client - The client for complete extra infos in the transaction.
18
- * @returns A promise that resolves to an object containing the signing message and the witness position,
19
- * or undefined if no matching input is found.
20
- *
21
- * @example
22
- * ```typescript
23
- * const signHashInfo = await getSignHashInfo(transactionLike, scriptLike, client);
24
- * if (signHashInfo) {
25
- * console.log(signHashInfo.message); // Outputs the signing message
26
- * console.log(signHashInfo.position); // Outputs the witness position
27
- * }
28
- * ```
29
- */
30
- export async function getSignHashInfo(
31
- txLike: TransactionLike,
32
- scriptLike: ScriptLike,
33
- client: Client,
34
- ): Promise<{ message: Hex; position: number } | undefined> {
35
- const tx = Transaction.from(txLike);
36
- const script = Script.from(scriptLike);
37
- let position = -1;
38
- const hasher = new Hasher();
39
- hasher.update(tx.hash());
40
-
41
- for (let i = 0; i < tx.witnesses.length; i += 1) {
42
- if (tx.inputs[i]) {
43
- const input = await tx.inputs[i].completeExtraInfos(client);
44
-
45
- if (!input.cellOutput) {
46
- throw Error("Unable to resolve inputs info");
47
- }
48
-
49
- if (!script.eq(input.cellOutput.lock)) {
50
- continue;
51
- }
52
-
53
- if (position === -1) {
54
- position = i;
55
- }
56
- }
57
-
58
- if (position === -1) {
59
- return undefined;
60
- }
61
-
62
- Transaction.hashWitnessToHasher(tx.witnesses[i], hasher);
63
- }
64
-
65
- if (position === -1) {
66
- return undefined;
67
- }
68
-
69
- return {
70
- message: hasher.digest(),
71
- position,
72
- };
73
- }
74
-
75
- /**
76
- * Prepare dummy witness for sighash all method
77
- *
78
- * @param txLike - The transaction to prepare, represented as a TransactionLike object.
79
- * @param scriptLike - The script associated with the transaction, represented as a ScriptLike object.
80
- * @param client - The client for complete extra infos in the transaction.
81
- * @returns A promise that resolves to the prepared transaction
82
- *
83
- * @example
84
- * ```typescript
85
- * const tx = await prepareSighashAllWitness(transactionLike, scriptLike, client);
86
- * ```
87
- */
88
- export async function prepareSighashAllWitness(
89
- txLike: TransactionLike,
90
- scriptLike: ScriptLike,
91
- lockLen: number,
92
- client: Client,
93
- ): Promise<Transaction> {
94
- const tx = Transaction.from(txLike);
95
- const script = Script.from(scriptLike);
96
-
97
- let position = -1;
98
-
99
- for (let i = 0; i < tx.inputs.length; i += 1) {
100
- const input = await tx.inputs[i].completeExtraInfos(client);
101
-
102
- if (!input.cellOutput) {
103
- throw Error("Unable to resolve inputs info");
104
- }
105
-
106
- if (script.eq(input.cellOutput.lock)) {
107
- position = i;
108
- break;
109
- }
110
- }
111
- if (position === -1) {
112
- return tx;
113
- }
114
-
115
- const witness = tx.witnesses[position]
116
- ? WitnessArgs.fromBytes(tx.witnesses[position])
117
- : WitnessArgs.from({});
118
- witness.lock = hexFrom(Array.from(new Array(lockLen), () => 0));
119
- tx.witnesses[position] = hexFrom(witness.toBytes());
120
-
121
- return tx;
122
- }