@ckb-ccc/core 0.0.9-alpha.1 → 0.0.10-alpha.4

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 (190) hide show
  1. package/dist/ckb/transaction.d.ts +19 -15
  2. package/dist/ckb/transaction.d.ts.map +1 -1
  3. package/dist/ckb/transaction.js +44 -10
  4. package/dist/client/client.d.ts +1 -1
  5. package/dist/client/client.d.ts.map +1 -1
  6. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  7. package/dist/client/clientPublicMainnet.advanced.js +30 -2
  8. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  9. package/dist/client/clientPublicMainnet.js +1 -1
  10. package/dist/client/clientPublicTestnet.advanced.js +3 -3
  11. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  12. package/dist/client/clientPublicTestnet.js +1 -1
  13. package/dist/client/clientTypes.advanced.d.ts +8 -8
  14. package/dist/client/clientTypes.advanced.d.ts.map +1 -1
  15. package/dist/client/clientTypes.d.ts +2 -2
  16. package/dist/client/clientTypes.d.ts.map +1 -1
  17. package/dist/client/clientTypes.js +2 -2
  18. package/dist/signer/ckb/index.d.ts +3 -0
  19. package/dist/signer/ckb/index.d.ts.map +1 -1
  20. package/dist/signer/ckb/index.js +3 -0
  21. package/dist/signer/ckb/signerCkbPrivateKey.d.ts +12 -0
  22. package/dist/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -0
  23. package/dist/signer/ckb/signerCkbPrivateKey.js +38 -0
  24. package/dist/signer/ckb/signerCkbPublicKey.d.ts +18 -0
  25. package/dist/signer/ckb/signerCkbPublicKey.d.ts.map +1 -0
  26. package/dist/signer/ckb/signerCkbPublicKey.js +44 -0
  27. package/dist/signer/ckb/verifyCkbSecp256k1.d.ts +5 -0
  28. package/dist/signer/ckb/verifyCkbSecp256k1.d.ts.map +1 -0
  29. package/dist/signer/ckb/verifyCkbSecp256k1.js +14 -0
  30. package/dist/signer/evm/signerEvm.d.ts +2 -1
  31. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  32. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +2 -2
  33. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  34. package/dist/signer/signer/index.d.ts +8 -6
  35. package/dist/signer/signer/index.d.ts.map +1 -1
  36. package/dist/signer/signer/index.js +9 -5
  37. package/dist/utils/index.d.ts +18 -9
  38. package/dist/utils/index.d.ts.map +1 -1
  39. package/dist/utils/index.js +2 -2
  40. package/dist.commonjs/address/address.advanced.d.ts +29 -24
  41. package/dist.commonjs/address/address.advanced.js +115 -89
  42. package/dist.commonjs/address/advanced.d.ts +1 -1
  43. package/dist.commonjs/address/advanced.js +30 -14
  44. package/dist.commonjs/address/index.d.ts +51 -44
  45. package/dist.commonjs/address/index.js +84 -65
  46. package/dist.commonjs/advanced.d.ts +1 -1
  47. package/dist.commonjs/advanced.js +47 -22
  48. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  49. package/dist.commonjs/advancedBarrel.js +30 -14
  50. package/dist.commonjs/barrel.d.ts +1 -1
  51. package/dist.commonjs/barrel.js +30 -14
  52. package/dist.commonjs/bytes/advanced.d.ts +11 -2
  53. package/dist.commonjs/bytes/index.d.ts +9 -3
  54. package/dist.commonjs/bytes/index.js +28 -26
  55. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  56. package/dist.commonjs/ckb/advanced.js +47 -22
  57. package/dist.commonjs/ckb/index.d.ts +1 -1
  58. package/dist.commonjs/ckb/index.js +30 -14
  59. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
  60. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
  61. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  62. package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
  63. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  64. package/dist.commonjs/ckb/script.advanced.js +12 -9
  65. package/dist.commonjs/ckb/script.d.ts +121 -117
  66. package/dist.commonjs/ckb/script.js +220 -176
  67. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  68. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  69. package/dist.commonjs/ckb/transaction.d.ts +806 -718
  70. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  71. package/dist.commonjs/ckb/transaction.js +1425 -1158
  72. package/dist.commonjs/client/advanced.d.ts +1 -1
  73. package/dist.commonjs/client/advanced.js +30 -14
  74. package/dist.commonjs/client/client.advanced.d.ts +23 -6
  75. package/dist.commonjs/client/client.advanced.js +89 -61
  76. package/dist.commonjs/client/client.d.ts +114 -54
  77. package/dist.commonjs/client/client.d.ts.map +1 -1
  78. package/dist.commonjs/client/client.js +215 -182
  79. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +8 -4
  80. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  81. package/dist.commonjs/client/clientPublicMainnet.advanced.js +215 -161
  82. package/dist.commonjs/client/clientPublicMainnet.d.ts +8 -6
  83. package/dist.commonjs/client/clientPublicMainnet.d.ts.map +1 -1
  84. package/dist.commonjs/client/clientPublicMainnet.js +17 -15
  85. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +6 -3
  86. package/dist.commonjs/client/clientPublicTestnet.advanced.js +227 -199
  87. package/dist.commonjs/client/clientPublicTestnet.d.ts +8 -6
  88. package/dist.commonjs/client/clientPublicTestnet.d.ts.map +1 -1
  89. package/dist.commonjs/client/clientPublicTestnet.js +13 -13
  90. package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
  91. package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -1
  92. package/dist.commonjs/client/clientTypes.advanced.js +1 -1
  93. package/dist.commonjs/client/clientTypes.d.ts +52 -27
  94. package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
  95. package/dist.commonjs/client/clientTypes.js +56 -22
  96. package/dist.commonjs/client/index.d.ts +1 -1
  97. package/dist.commonjs/client/index.js +30 -14
  98. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  99. package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
  100. package/dist.commonjs/client/jsonRpc/index.d.ts +94 -75
  101. package/dist.commonjs/client/jsonRpc/index.js +135 -108
  102. package/dist.commonjs/client/jsonRpc/transformers.d.ts +76 -36
  103. package/dist.commonjs/client/jsonRpc/transformers.js +174 -152
  104. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  105. package/dist.commonjs/fixedPoint/index.d.ts +9 -3
  106. package/dist.commonjs/fixedPoint/index.js +26 -20
  107. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  108. package/dist.commonjs/fixedPoint/index.test.js +42 -36
  109. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  110. package/dist.commonjs/hasher/index.d.ts +40 -37
  111. package/dist.commonjs/hasher/index.js +58 -48
  112. package/dist.commonjs/hex/index.d.ts +1 -1
  113. package/dist.commonjs/hex/index.js +1 -1
  114. package/dist.commonjs/index.d.ts +1 -1
  115. package/dist.commonjs/index.js +47 -22
  116. package/dist.commonjs/num/index.d.ts +1 -1
  117. package/dist.commonjs/num/index.js +39 -27
  118. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  119. package/dist.commonjs/signer/btc/index.js +30 -14
  120. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  121. package/dist.commonjs/signer/btc/signerBtc.js +89 -66
  122. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  123. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  124. package/dist.commonjs/signer/btc/verify.d.ts +6 -2
  125. package/dist.commonjs/signer/btc/verify.js +10 -3
  126. package/dist.commonjs/signer/ckb/index.d.ts +4 -1
  127. package/dist.commonjs/signer/ckb/index.d.ts.map +1 -1
  128. package/dist.commonjs/signer/ckb/index.js +33 -14
  129. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts +12 -0
  130. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -0
  131. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +56 -0
  132. package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts +18 -0
  133. package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts.map +1 -0
  134. package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +58 -0
  135. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  136. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  137. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts +11 -0
  138. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts.map +1 -0
  139. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +27 -0
  140. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -2
  141. package/dist.commonjs/signer/ckb/verifyJoyId.js +11 -8
  142. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  143. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  144. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  145. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  146. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  147. package/dist.commonjs/signer/dummy/index.js +30 -14
  148. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  149. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  150. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  151. package/dist.commonjs/signer/evm/index.js +30 -14
  152. package/dist.commonjs/signer/evm/signerEvm.d.ts +43 -38
  153. package/dist.commonjs/signer/evm/signerEvm.d.ts.map +1 -1
  154. package/dist.commonjs/signer/evm/signerEvm.js +105 -70
  155. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +38 -38
  156. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  157. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  158. package/dist.commonjs/signer/evm/verify.d.ts +6 -2
  159. package/dist.commonjs/signer/evm/verify.js +7 -2
  160. package/dist.commonjs/signer/index.d.ts +1 -1
  161. package/dist.commonjs/signer/index.js +30 -14
  162. package/dist.commonjs/signer/nostr/index.d.ts +1 -1
  163. package/dist.commonjs/signer/nostr/index.js +30 -14
  164. package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
  165. package/dist.commonjs/signer/nostr/signerNostr.js +100 -71
  166. package/dist.commonjs/signer/nostr/verify.d.ts +9 -3
  167. package/dist.commonjs/signer/nostr/verify.js +50 -39
  168. package/dist.commonjs/signer/signer/index.d.ts +171 -160
  169. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  170. package/dist.commonjs/signer/signer/index.js +235 -195
  171. package/dist.commonjs/utils/index.d.ts +56 -14
  172. package/dist.commonjs/utils/index.d.ts.map +1 -1
  173. package/dist.commonjs/utils/index.js +19 -13
  174. package/package.json +2 -2
  175. package/src/ckb/transaction.ts +87 -33
  176. package/src/client/client.ts +1 -1
  177. package/src/client/clientPublicMainnet.advanced.ts +34 -2
  178. package/src/client/clientPublicMainnet.ts +1 -1
  179. package/src/client/clientPublicTestnet.advanced.ts +3 -3
  180. package/src/client/clientPublicTestnet.ts +1 -1
  181. package/src/client/clientTypes.advanced.ts +8 -8
  182. package/src/client/clientTypes.ts +4 -4
  183. package/src/signer/ckb/index.ts +3 -0
  184. package/src/signer/ckb/signerCkbPrivateKey.ts +58 -0
  185. package/src/signer/ckb/signerCkbPublicKey.ts +63 -0
  186. package/src/signer/ckb/verifyCkbSecp256k1.ts +27 -0
  187. package/src/signer/evm/signerEvm.ts +2 -2
  188. package/src/signer/evm/signerEvmAddressReadonly.ts +1 -1
  189. package/src/signer/signer/index.ts +17 -9
  190. package/src/utils/index.ts +24 -12
@@ -16,72 +16,95 @@ const signer_1 = require("../signer");
16
16
  * as well as signing transactions.
17
17
  */
18
18
  class SignerBtc extends signer_1.Signer {
19
- get type() {
20
- return signer_1.SignerType.BTC;
21
- }
22
- get signType() {
23
- return signer_1.SignerSignType.BtcEcdsa;
24
- }
25
- /**
26
- * Gets the internal address, which is the Bitcoin account in this case.
27
- *
28
- * @returns A promise that resolves to a string representing the internal address.
29
- */
30
- async getInternalAddress() {
31
- return this.getBtcAccount();
32
- }
33
- /**
34
- * Gets the identity, which is the Bitcoin public key in this case.
35
- *
36
- * @returns A promise that resolves to a string representing the identity
37
- */
38
- async getIdentity() {
39
- return (0, hex_1.hexFrom)(await this.getBtcPublicKey()).slice(2);
40
- }
41
- /**
42
- * Gets an array of Address objects representing the known script addresses for the signer.
43
- *
44
- * @returns A promise that resolves to an array of Address objects.
45
- */
46
- async getAddressObjs() {
47
- const publicKey = await this.getBtcPublicKey();
48
- const hash = (0, ripemd160_1.ripemd160)((0, sha256_1.sha256)((0, bytes_1.bytesFrom)(publicKey)));
49
- return [
50
- await address_1.Address.fromKnownScript(this.client, client_1.KnownScript.OmniLock, (0, hex_1.hexFrom)([0x04, ...hash, 0x00])),
51
- ];
52
- }
53
- /**
54
- * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
55
- *
56
- * @param txLike - The transaction to prepare, represented as a TransactionLike object.
57
- * @returns A promise that resolves to the prepared Transaction object.
58
- */
59
- async prepareTransaction(txLike) {
60
- const tx = ckb_1.Transaction.from(txLike);
61
- const { script } = await this.getRecommendedAddressObj();
62
- await tx.addCellDepsOfKnownScripts(this.client, client_1.KnownScript.OmniLock);
63
- await tx.prepareSighashAllWitness(script, 85, this.client);
64
- return tx;
65
- }
66
- /**
67
- * Signs a transaction without modifying it.
68
- *
69
- * @param txLike - The transaction to sign, represented as a TransactionLike object.
70
- * @returns A promise that resolves to a signed Transaction object.
71
- */
72
- async signOnlyTransaction(txLike) {
73
- const tx = ckb_1.Transaction.from(txLike);
74
- const { script } = await this.getRecommendedAddressObj();
75
- const info = await tx.getSignHashInfo(script, this.client);
76
- if (!info) {
77
- return tx;
78
- }
79
- const signature = (0, bytes_1.bytesFrom)(await this.signMessageRaw(`CKB (Bitcoin Layer) transaction: ${info.message}`), "base64");
80
- signature[0] = 31 + ((signature[0] - 27) % 4);
81
- const witness = ckb_1.WitnessArgs.fromBytes(tx.witnesses[info.position]);
82
- witness.lock = (0, hex_1.hexFrom)((0, bytes_1.bytesConcat)((0, num_1.numToBytes)(5 * 4 + signature.length, 4), (0, num_1.numToBytes)(4 * 4, 4), (0, num_1.numToBytes)(5 * 4 + signature.length, 4), (0, num_1.numToBytes)(5 * 4 + signature.length, 4), (0, num_1.numToBytes)(signature.length, 4), signature));
83
- tx.setWitnessArgsAt(info.position, witness);
84
- return tx;
19
+ get type() {
20
+ return signer_1.SignerType.BTC;
21
+ }
22
+ get signType() {
23
+ return signer_1.SignerSignType.BtcEcdsa;
24
+ }
25
+ /**
26
+ * Gets the internal address, which is the Bitcoin account in this case.
27
+ *
28
+ * @returns A promise that resolves to a string representing the internal address.
29
+ */
30
+ async getInternalAddress() {
31
+ return this.getBtcAccount();
32
+ }
33
+ /**
34
+ * Gets the identity, which is the Bitcoin public key in this case.
35
+ *
36
+ * @returns A promise that resolves to a string representing the identity
37
+ */
38
+ async getIdentity() {
39
+ return (0, hex_1.hexFrom)(await this.getBtcPublicKey()).slice(2);
40
+ }
41
+ /**
42
+ * Gets an array of Address objects representing the known script addresses for the signer.
43
+ *
44
+ * @returns A promise that resolves to an array of Address objects.
45
+ */
46
+ async getAddressObjs() {
47
+ const publicKey = await this.getBtcPublicKey();
48
+ const hash = (0, ripemd160_1.ripemd160)(
49
+ (0, sha256_1.sha256)((0, bytes_1.bytesFrom)(publicKey)),
50
+ );
51
+ return [
52
+ await address_1.Address.fromKnownScript(
53
+ this.client,
54
+ client_1.KnownScript.OmniLock,
55
+ (0, hex_1.hexFrom)([0x04, ...hash, 0x00]),
56
+ ),
57
+ ];
58
+ }
59
+ /**
60
+ * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
61
+ *
62
+ * @param txLike - The transaction to prepare, represented as a TransactionLike object.
63
+ * @returns A promise that resolves to the prepared Transaction object.
64
+ */
65
+ async prepareTransaction(txLike) {
66
+ const tx = ckb_1.Transaction.from(txLike);
67
+ const { script } = await this.getRecommendedAddressObj();
68
+ await tx.addCellDepsOfKnownScripts(
69
+ this.client,
70
+ client_1.KnownScript.OmniLock,
71
+ );
72
+ await tx.prepareSighashAllWitness(script, 85, this.client);
73
+ return tx;
74
+ }
75
+ /**
76
+ * Signs a transaction without modifying it.
77
+ *
78
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
79
+ * @returns A promise that resolves to a signed Transaction object.
80
+ */
81
+ async signOnlyTransaction(txLike) {
82
+ const tx = ckb_1.Transaction.from(txLike);
83
+ const { script } = await this.getRecommendedAddressObj();
84
+ const info = await tx.getSignHashInfo(script, this.client);
85
+ if (!info) {
86
+ return tx;
85
87
  }
88
+ const signature = (0, bytes_1.bytesFrom)(
89
+ await this.signMessageRaw(
90
+ `CKB (Bitcoin Layer) transaction: ${info.message}`,
91
+ ),
92
+ "base64",
93
+ );
94
+ signature[0] = 31 + ((signature[0] - 27) % 4);
95
+ const witness = ckb_1.WitnessArgs.fromBytes(tx.witnesses[info.position]);
96
+ witness.lock = (0, hex_1.hexFrom)(
97
+ (0, bytes_1.bytesConcat)(
98
+ (0, num_1.numToBytes)(5 * 4 + signature.length, 4),
99
+ (0, num_1.numToBytes)(4 * 4, 4),
100
+ (0, num_1.numToBytes)(5 * 4 + signature.length, 4),
101
+ (0, num_1.numToBytes)(5 * 4 + signature.length, 4),
102
+ (0, num_1.numToBytes)(signature.length, 4),
103
+ signature,
104
+ ),
105
+ );
106
+ tx.setWitnessArgsAt(info.position, witness);
107
+ return tx;
108
+ }
86
109
  }
87
110
  exports.SignerBtc = SignerBtc;
@@ -6,49 +6,49 @@ import { SignerBtc } from "./signerBtc";
6
6
  * This class does not support signing operations.
7
7
  */
8
8
  export declare class SignerBtcPublicKeyReadonly extends SignerBtc {
9
- private readonly account;
10
- private readonly publicKey;
11
- /**
12
- * Creates an instance of SignerBtcPublicKeyReadonly.
13
- *
14
- * @param client - The client instance used for communication.
15
- * @param account - The Bitcoin account associated with the signer.
16
- * @param publicKey - The public key associated with the signer.
17
- */
18
- constructor(client: Client, account: string, publicKey: HexLike);
19
- /**
20
- * Connects to the client. This implementation does nothing as the class is read-only.
21
- *
22
- * @returns A promise that resolves when the connection is complete.
23
- */
24
- connect(): Promise<void>;
25
- /**
26
- * Check if the signer is connected.
27
- *
28
- * @returns A promise that resolves the connection status.
29
- */
30
- isConnected(): Promise<boolean>;
31
- /**
32
- * Gets the Bitcoin account associated with the signer.
33
- *
34
- * @returns A promise that resolves to a string representing the Bitcoin account.
35
- *
36
- * @example
37
- * ```typescript
38
- * const account = await signer.getBtcAccount(); // Outputs the Bitcoin account
39
- * ```
40
- */
41
- getBtcAccount(): Promise<string>;
42
- /**
43
- * Gets the Bitcoin public key associated with the signer.
44
- *
45
- * @returns A promise that resolves to a Hex string representing the Bitcoin public key.
46
- *
47
- * @example
48
- * ```typescript
49
- * const publicKey = await signer.getBtcPublicKey(); // Outputs the Bitcoin public key
50
- * ```
51
- */
52
- getBtcPublicKey(): Promise<Hex>;
9
+ private readonly account;
10
+ private readonly publicKey;
11
+ /**
12
+ * Creates an instance of SignerBtcPublicKeyReadonly.
13
+ *
14
+ * @param client - The client instance used for communication.
15
+ * @param account - The Bitcoin account associated with the signer.
16
+ * @param publicKey - The public key associated with the signer.
17
+ */
18
+ constructor(client: Client, account: string, publicKey: HexLike);
19
+ /**
20
+ * Connects to the client. This implementation does nothing as the class is read-only.
21
+ *
22
+ * @returns A promise that resolves when the connection is complete.
23
+ */
24
+ connect(): Promise<void>;
25
+ /**
26
+ * Check if the signer is connected.
27
+ *
28
+ * @returns A promise that resolves the connection status.
29
+ */
30
+ isConnected(): Promise<boolean>;
31
+ /**
32
+ * Gets the Bitcoin account associated with the signer.
33
+ *
34
+ * @returns A promise that resolves to a string representing the Bitcoin account.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const account = await signer.getBtcAccount(); // Outputs the Bitcoin account
39
+ * ```
40
+ */
41
+ getBtcAccount(): Promise<string>;
42
+ /**
43
+ * Gets the Bitcoin public key associated with the signer.
44
+ *
45
+ * @returns A promise that resolves to a Hex string representing the Bitcoin public key.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const publicKey = await signer.getBtcPublicKey(); // Outputs the Bitcoin public key
50
+ * ```
51
+ */
52
+ getBtcPublicKey(): Promise<Hex>;
53
53
  }
54
- //# sourceMappingURL=signerBtcPublicKeyReadonly.d.ts.map
54
+ //# sourceMappingURL=signerBtcPublicKeyReadonly.d.ts.map
@@ -8,57 +8,57 @@ const signerBtc_1 = require("./signerBtc");
8
8
  * This class does not support signing operations.
9
9
  */
10
10
  class SignerBtcPublicKeyReadonly extends signerBtc_1.SignerBtc {
11
- /**
12
- * Creates an instance of SignerBtcPublicKeyReadonly.
13
- *
14
- * @param client - The client instance used for communication.
15
- * @param account - The Bitcoin account associated with the signer.
16
- * @param publicKey - The public key associated with the signer.
17
- */
18
- constructor(client, account, publicKey) {
19
- super(client);
20
- this.account = account;
21
- this.publicKey = (0, hex_1.hexFrom)(publicKey);
22
- }
23
- /**
24
- * Connects to the client. This implementation does nothing as the class is read-only.
25
- *
26
- * @returns A promise that resolves when the connection is complete.
27
- */
28
- async connect() { }
29
- /**
30
- * Check if the signer is connected.
31
- *
32
- * @returns A promise that resolves the connection status.
33
- */
34
- async isConnected() {
35
- return true;
36
- }
37
- /**
38
- * Gets the Bitcoin account associated with the signer.
39
- *
40
- * @returns A promise that resolves to a string representing the Bitcoin account.
41
- *
42
- * @example
43
- * ```typescript
44
- * const account = await signer.getBtcAccount(); // Outputs the Bitcoin account
45
- * ```
46
- */
47
- async getBtcAccount() {
48
- return this.account;
49
- }
50
- /**
51
- * Gets the Bitcoin public key associated with the signer.
52
- *
53
- * @returns A promise that resolves to a Hex string representing the Bitcoin public key.
54
- *
55
- * @example
56
- * ```typescript
57
- * const publicKey = await signer.getBtcPublicKey(); // Outputs the Bitcoin public key
58
- * ```
59
- */
60
- async getBtcPublicKey() {
61
- return this.publicKey;
62
- }
11
+ /**
12
+ * Creates an instance of SignerBtcPublicKeyReadonly.
13
+ *
14
+ * @param client - The client instance used for communication.
15
+ * @param account - The Bitcoin account associated with the signer.
16
+ * @param publicKey - The public key associated with the signer.
17
+ */
18
+ constructor(client, account, publicKey) {
19
+ super(client);
20
+ this.account = account;
21
+ this.publicKey = (0, hex_1.hexFrom)(publicKey);
22
+ }
23
+ /**
24
+ * Connects to the client. This implementation does nothing as the class is read-only.
25
+ *
26
+ * @returns A promise that resolves when the connection is complete.
27
+ */
28
+ async connect() {}
29
+ /**
30
+ * Check if the signer is connected.
31
+ *
32
+ * @returns A promise that resolves the connection status.
33
+ */
34
+ async isConnected() {
35
+ return true;
36
+ }
37
+ /**
38
+ * Gets the Bitcoin account associated with the signer.
39
+ *
40
+ * @returns A promise that resolves to a string representing the Bitcoin account.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const account = await signer.getBtcAccount(); // Outputs the Bitcoin account
45
+ * ```
46
+ */
47
+ async getBtcAccount() {
48
+ return this.account;
49
+ }
50
+ /**
51
+ * Gets the Bitcoin public key associated with the signer.
52
+ *
53
+ * @returns A promise that resolves to a Hex string representing the Bitcoin public key.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const publicKey = await signer.getBtcPublicKey(); // Outputs the Bitcoin public key
58
+ * ```
59
+ */
60
+ async getBtcPublicKey() {
61
+ return this.publicKey;
62
+ }
63
63
  }
64
64
  exports.SignerBtcPublicKeyReadonly = SignerBtcPublicKeyReadonly;
@@ -1,3 +1,7 @@
1
1
  import { BytesLike } from "../../bytes";
2
- export declare function verifyMessageBtcEcdsa(message: string | BytesLike, signature: string, publicKey: string): boolean;
3
- //# sourceMappingURL=verify.d.ts.map
2
+ export declare function verifyMessageBtcEcdsa(
3
+ message: string | BytesLike,
4
+ signature: string,
5
+ publicKey: string,
6
+ ): boolean;
7
+ //# sourceMappingURL=verify.d.ts.map
@@ -6,8 +6,15 @@ const bitcoinjs_message_1 = require("bitcoinjs-message");
6
6
  const bytes_1 = require("../../bytes");
7
7
  const hex_1 = require("../../hex");
8
8
  function verifyMessageBtcEcdsa(message, signature, publicKey) {
9
- const challenge = typeof message === "string" ? message : (0, hex_1.hexFrom)(message).slice(2);
10
- const [_, ...rawSign] = (0, bytes_1.bytesFrom)(signature, "base64");
11
- return secp256k1_1.secp256k1.verify((0, bytes_1.bytesFrom)(rawSign), (0, bitcoinjs_message_1.magicHash)(challenge), publicKey);
9
+ const challenge =
10
+ typeof message === "string"
11
+ ? message
12
+ : (0, hex_1.hexFrom)(message).slice(2);
13
+ const [_, ...rawSign] = (0, bytes_1.bytesFrom)(signature, "base64");
14
+ return secp256k1_1.secp256k1.verify(
15
+ (0, bytes_1.bytesFrom)(rawSign),
16
+ (0, bitcoinjs_message_1.magicHash)(challenge),
17
+ publicKey,
18
+ );
12
19
  }
13
20
  exports.verifyMessageBtcEcdsa = verifyMessageBtcEcdsa;
@@ -1,3 +1,6 @@
1
+ export * from "./signerCkbPrivateKey";
2
+ export * from "./signerCkbPublicKey";
1
3
  export * from "./signerCkbScriptReadonly";
4
+ export * from "./verifyCkbSecp256k1";
2
5
  export * from "./verifyJoyId";
3
- //# sourceMappingURL=index.d.ts.map
6
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC"}
@@ -1,18 +1,37 @@
1
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __exportStar =
26
+ (this && this.__exportStar) ||
27
+ function (m, exports) {
28
+ for (var p in m)
29
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
+ __createBinding(exports, m, p);
31
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
+ __exportStar(require("./signerCkbPrivateKey"), exports);
34
+ __exportStar(require("./signerCkbPublicKey"), exports);
17
35
  __exportStar(require("./signerCkbScriptReadonly"), exports);
36
+ __exportStar(require("./verifyCkbSecp256k1"), exports);
18
37
  __exportStar(require("./verifyJoyId"), exports);
@@ -0,0 +1,12 @@
1
+ import { BytesLike } from "../../bytes";
2
+ import { Transaction, TransactionLike } from "../../ckb";
3
+ import { Client } from "../../client";
4
+ import { Hex, HexLike } from "../../hex";
5
+ import { SignerCkbPublicKey } from "./signerCkbPublicKey";
6
+ export declare class SignerCkbPrivateKey extends SignerCkbPublicKey {
7
+ readonly privateKey: Hex;
8
+ constructor(client: Client, privateKey: HexLike);
9
+ signMessageRaw(message: string | BytesLike): Promise<Hex>;
10
+ signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
11
+ }
12
+ //# sourceMappingURL=signerCkbPrivateKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signerCkbPrivateKey.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/signerCkbPrivateKey.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,SAAS,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,GAAG,EAAW,OAAO,EAAE,MAAM,WAAW,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,qBAAa,mBAAoB,SAAQ,kBAAkB;IACzD,SAAgB,UAAU,EAAE,GAAG,CAAC;gBAEpB,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO;IAUzC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC;IAoBzD,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAezE"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignerCkbPrivateKey = void 0;
4
+ const secp256k1_1 = require("@noble/curves/secp256k1");
5
+ const bytes_1 = require("../../bytes");
6
+ const ckb_1 = require("../../ckb");
7
+ const hasher_1 = require("../../hasher");
8
+ const hex_1 = require("../../hex");
9
+ const num_1 = require("../../num");
10
+ const signerCkbPublicKey_1 = require("./signerCkbPublicKey");
11
+ class SignerCkbPrivateKey extends signerCkbPublicKey_1.SignerCkbPublicKey {
12
+ constructor(client, privateKey) {
13
+ const pk = (0, hex_1.hexFrom)(privateKey);
14
+ if ((0, bytes_1.bytesFrom)(pk).length !== 32) {
15
+ throw new Error("Private key must be 32 bytes!");
16
+ }
17
+ super(
18
+ client,
19
+ secp256k1_1.secp256k1.getPublicKey((0, bytes_1.bytesFrom)(pk), true),
20
+ );
21
+ this.privateKey = pk;
22
+ }
23
+ async signMessageRaw(message) {
24
+ const msg =
25
+ typeof message === "string" ? message : (0, hex_1.hexFrom)(message);
26
+ const buffer = (0, bytes_1.bytesFrom)(`Nervos Message:${msg}`, "utf8");
27
+ const hash = (0, hasher_1.hashCkb)(buffer);
28
+ const signature = secp256k1_1.secp256k1.sign(
29
+ (0, bytes_1.bytesFrom)(hash),
30
+ (0, bytes_1.bytesFrom)(this.privateKey),
31
+ );
32
+ const { r, s, recovery } = signature;
33
+ return (0, hex_1.hexFrom)(
34
+ (0, bytes_1.bytesConcat)(
35
+ (0, num_1.numBeToBytes)(r, 32),
36
+ (0, num_1.numBeToBytes)(s, 32),
37
+ (0, num_1.numBeToBytes)(recovery, 1),
38
+ ),
39
+ );
40
+ }
41
+ async signOnlyTransaction(txLike) {
42
+ const tx = ckb_1.Transaction.from(txLike);
43
+ const { script } = await this.getRecommendedAddressObj();
44
+ const info = await tx.getSignHashInfo(script, this.client);
45
+ if (!info) {
46
+ return tx;
47
+ }
48
+ const signature = await this.signMessageRaw(info.message);
49
+ const witness =
50
+ tx.getWitnessArgsAt(info.position) ?? ckb_1.WitnessArgs.from({});
51
+ witness.lock = signature;
52
+ tx.setWitnessArgsAt(info.position, witness);
53
+ return tx;
54
+ }
55
+ }
56
+ exports.SignerCkbPrivateKey = SignerCkbPrivateKey;
@@ -0,0 +1,18 @@
1
+ import { Address } from "../../address";
2
+ import { Transaction, TransactionLike } from "../../ckb";
3
+ import { Client } from "../../client";
4
+ import { Hex, HexLike } from "../../hex";
5
+ import { Signer, SignerSignType, SignerType } from "../signer";
6
+ export declare class SignerCkbPublicKey extends Signer {
7
+ get type(): SignerType;
8
+ get signType(): SignerSignType;
9
+ readonly publicKey: Hex;
10
+ constructor(client: Client, publicKey: HexLike);
11
+ connect(): Promise<void>;
12
+ isConnected(): Promise<boolean>;
13
+ getInternalAddress(): Promise<string>;
14
+ getIdentity(): Promise<string>;
15
+ getAddressObjs(): Promise<Address[]>;
16
+ prepareTransaction(txLike: TransactionLike): Promise<Transaction>;
17
+ }
18
+ //# sourceMappingURL=signerCkbPublicKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signerCkbPublicKey.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/signerCkbPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,MAAM,EAAe,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/D,qBAAa,kBAAmB,SAAQ,MAAM;IAC5C,IAAI,IAAI,IAAI,UAAU,CAErB;IAED,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED,SAAgB,SAAS,EAAE,GAAG,CAAC;gBAEnB,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO;IASxC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAExB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAIrC,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAI9B,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAUpC,kBAAkB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;CAUxE"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignerCkbPublicKey = void 0;
4
+ const address_1 = require("../../address");
5
+ const bytes_1 = require("../../bytes");
6
+ const ckb_1 = require("../../ckb");
7
+ const client_1 = require("../../client");
8
+ const hasher_1 = require("../../hasher");
9
+ const hex_1 = require("../../hex");
10
+ const signer_1 = require("../signer");
11
+ class SignerCkbPublicKey extends signer_1.Signer {
12
+ get type() {
13
+ return signer_1.SignerType.CKB;
14
+ }
15
+ get signType() {
16
+ return signer_1.SignerSignType.CkbSecp256k1;
17
+ }
18
+ constructor(client, publicKey) {
19
+ super(client);
20
+ this.publicKey = (0, hex_1.hexFrom)(publicKey);
21
+ if ((0, bytes_1.bytesFrom)(this.publicKey).length !== 33) {
22
+ throw new Error("Public key must be 33 bytes!");
23
+ }
24
+ }
25
+ async connect() {}
26
+ async isConnected() {
27
+ return true;
28
+ }
29
+ async getInternalAddress() {
30
+ return this.getRecommendedAddress();
31
+ }
32
+ async getIdentity() {
33
+ return this.publicKey;
34
+ }
35
+ async getAddressObjs() {
36
+ return [
37
+ await address_1.Address.fromKnownScript(
38
+ this.client,
39
+ client_1.KnownScript.Secp256k1Blake160,
40
+ (0, bytes_1.bytesFrom)((0, hasher_1.hashCkb)(this.publicKey)).slice(
41
+ 0,
42
+ 20,
43
+ ),
44
+ ),
45
+ ];
46
+ }
47
+ async prepareTransaction(txLike) {
48
+ const tx = ckb_1.Transaction.from(txLike);
49
+ const { script } = await this.getRecommendedAddressObj();
50
+ await tx.addCellDepsOfKnownScripts(
51
+ this.client,
52
+ client_1.KnownScript.Secp256k1Blake160,
53
+ );
54
+ await tx.prepareSighashAllWitness(script, 65, this.client);
55
+ return tx;
56
+ }
57
+ }
58
+ exports.SignerCkbPublicKey = SignerCkbPublicKey;