@ckb-ccc/core 0.0.10-alpha.0 → 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 (173) 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/clientPublicTestnet.advanced.js +3 -3
  9. package/dist/client/clientTypes.advanced.d.ts +8 -8
  10. package/dist/client/clientTypes.advanced.d.ts.map +1 -1
  11. package/dist/client/clientTypes.d.ts +2 -2
  12. package/dist/client/clientTypes.d.ts.map +1 -1
  13. package/dist/client/clientTypes.js +2 -2
  14. package/dist/signer/ckb/index.d.ts +2 -0
  15. package/dist/signer/ckb/index.d.ts.map +1 -1
  16. package/dist/signer/ckb/index.js +2 -0
  17. package/dist/signer/ckb/signerCkbPrivateKey.d.ts +4 -13
  18. package/dist/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -1
  19. package/dist/signer/ckb/signerCkbPrivateKey.js +10 -37
  20. package/dist/signer/ckb/signerCkbPublicKey.d.ts +18 -0
  21. package/dist/signer/ckb/signerCkbPublicKey.d.ts.map +1 -0
  22. package/dist/signer/ckb/signerCkbPublicKey.js +44 -0
  23. package/dist/signer/ckb/verifyCkbSecp256k1.d.ts +5 -0
  24. package/dist/signer/ckb/verifyCkbSecp256k1.d.ts.map +1 -0
  25. package/dist/signer/ckb/verifyCkbSecp256k1.js +14 -0
  26. package/dist/signer/signer/index.d.ts.map +1 -1
  27. package/dist/signer/signer/index.js +2 -0
  28. package/dist/utils/index.d.ts +18 -9
  29. package/dist/utils/index.d.ts.map +1 -1
  30. package/dist/utils/index.js +2 -2
  31. package/dist.commonjs/address/address.advanced.d.ts +29 -24
  32. package/dist.commonjs/address/address.advanced.js +115 -89
  33. package/dist.commonjs/address/advanced.d.ts +1 -1
  34. package/dist.commonjs/address/advanced.js +30 -14
  35. package/dist.commonjs/address/index.d.ts +51 -44
  36. package/dist.commonjs/address/index.js +84 -65
  37. package/dist.commonjs/advanced.d.ts +1 -1
  38. package/dist.commonjs/advanced.js +47 -22
  39. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  40. package/dist.commonjs/advancedBarrel.js +30 -14
  41. package/dist.commonjs/barrel.d.ts +1 -1
  42. package/dist.commonjs/barrel.js +30 -14
  43. package/dist.commonjs/bytes/advanced.d.ts +11 -2
  44. package/dist.commonjs/bytes/index.d.ts +9 -3
  45. package/dist.commonjs/bytes/index.js +28 -26
  46. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  47. package/dist.commonjs/ckb/advanced.js +47 -22
  48. package/dist.commonjs/ckb/index.d.ts +1 -1
  49. package/dist.commonjs/ckb/index.js +30 -14
  50. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
  51. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
  52. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  53. package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
  54. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  55. package/dist.commonjs/ckb/script.advanced.js +12 -9
  56. package/dist.commonjs/ckb/script.d.ts +121 -117
  57. package/dist.commonjs/ckb/script.js +220 -176
  58. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  59. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  60. package/dist.commonjs/ckb/transaction.d.ts +806 -718
  61. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  62. package/dist.commonjs/ckb/transaction.js +1425 -1158
  63. package/dist.commonjs/client/advanced.d.ts +1 -1
  64. package/dist.commonjs/client/advanced.js +30 -14
  65. package/dist.commonjs/client/client.advanced.d.ts +23 -6
  66. package/dist.commonjs/client/client.advanced.js +89 -61
  67. package/dist.commonjs/client/client.d.ts +114 -54
  68. package/dist.commonjs/client/client.d.ts.map +1 -1
  69. package/dist.commonjs/client/client.js +215 -182
  70. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +8 -4
  71. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  72. package/dist.commonjs/client/clientPublicMainnet.advanced.js +215 -161
  73. package/dist.commonjs/client/clientPublicMainnet.d.ts +8 -6
  74. package/dist.commonjs/client/clientPublicMainnet.js +17 -15
  75. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +6 -3
  76. package/dist.commonjs/client/clientPublicTestnet.advanced.js +227 -199
  77. package/dist.commonjs/client/clientPublicTestnet.d.ts +8 -6
  78. package/dist.commonjs/client/clientPublicTestnet.js +13 -13
  79. package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
  80. package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -1
  81. package/dist.commonjs/client/clientTypes.advanced.js +1 -1
  82. package/dist.commonjs/client/clientTypes.d.ts +52 -27
  83. package/dist.commonjs/client/clientTypes.d.ts.map +1 -1
  84. package/dist.commonjs/client/clientTypes.js +56 -22
  85. package/dist.commonjs/client/index.d.ts +1 -1
  86. package/dist.commonjs/client/index.js +30 -14
  87. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  88. package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
  89. package/dist.commonjs/client/jsonRpc/index.d.ts +94 -75
  90. package/dist.commonjs/client/jsonRpc/index.js +135 -108
  91. package/dist.commonjs/client/jsonRpc/transformers.d.ts +76 -36
  92. package/dist.commonjs/client/jsonRpc/transformers.js +174 -152
  93. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  94. package/dist.commonjs/fixedPoint/index.d.ts +9 -3
  95. package/dist.commonjs/fixedPoint/index.js +26 -20
  96. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  97. package/dist.commonjs/fixedPoint/index.test.js +42 -36
  98. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  99. package/dist.commonjs/hasher/index.d.ts +40 -37
  100. package/dist.commonjs/hasher/index.js +58 -48
  101. package/dist.commonjs/hex/index.d.ts +1 -1
  102. package/dist.commonjs/hex/index.js +1 -1
  103. package/dist.commonjs/index.d.ts +1 -1
  104. package/dist.commonjs/index.js +47 -22
  105. package/dist.commonjs/num/index.d.ts +1 -1
  106. package/dist.commonjs/num/index.js +39 -27
  107. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  108. package/dist.commonjs/signer/btc/index.js +30 -14
  109. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  110. package/dist.commonjs/signer/btc/signerBtc.js +89 -66
  111. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  112. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  113. package/dist.commonjs/signer/btc/verify.d.ts +6 -2
  114. package/dist.commonjs/signer/btc/verify.js +10 -3
  115. package/dist.commonjs/signer/ckb/index.d.ts +3 -1
  116. package/dist.commonjs/signer/ckb/index.d.ts.map +1 -1
  117. package/dist.commonjs/signer/ckb/index.js +32 -14
  118. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts +8 -17
  119. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -1
  120. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +45 -58
  121. package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts +18 -0
  122. package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts.map +1 -0
  123. package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +58 -0
  124. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  125. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  126. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts +11 -0
  127. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts.map +1 -0
  128. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +27 -0
  129. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -2
  130. package/dist.commonjs/signer/ckb/verifyJoyId.js +11 -8
  131. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  132. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  133. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  134. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  135. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  136. package/dist.commonjs/signer/dummy/index.js +30 -14
  137. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  138. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  139. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  140. package/dist.commonjs/signer/evm/index.js +30 -14
  141. package/dist.commonjs/signer/evm/signerEvm.d.ts +42 -38
  142. package/dist.commonjs/signer/evm/signerEvm.js +105 -70
  143. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
  144. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  145. package/dist.commonjs/signer/evm/verify.d.ts +6 -2
  146. package/dist.commonjs/signer/evm/verify.js +7 -2
  147. package/dist.commonjs/signer/index.d.ts +1 -1
  148. package/dist.commonjs/signer/index.js +30 -14
  149. package/dist.commonjs/signer/nostr/index.d.ts +1 -1
  150. package/dist.commonjs/signer/nostr/index.js +30 -14
  151. package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
  152. package/dist.commonjs/signer/nostr/signerNostr.js +100 -71
  153. package/dist.commonjs/signer/nostr/verify.d.ts +9 -3
  154. package/dist.commonjs/signer/nostr/verify.js +50 -39
  155. package/dist.commonjs/signer/signer/index.d.ts +171 -162
  156. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  157. package/dist.commonjs/signer/signer/index.js +235 -197
  158. package/dist.commonjs/utils/index.d.ts +56 -14
  159. package/dist.commonjs/utils/index.d.ts.map +1 -1
  160. package/dist.commonjs/utils/index.js +19 -13
  161. package/package.json +2 -2
  162. package/src/ckb/transaction.ts +87 -33
  163. package/src/client/client.ts +1 -1
  164. package/src/client/clientPublicMainnet.advanced.ts +34 -2
  165. package/src/client/clientPublicTestnet.advanced.ts +3 -3
  166. package/src/client/clientTypes.advanced.ts +8 -8
  167. package/src/client/clientTypes.ts +4 -4
  168. package/src/signer/ckb/index.ts +2 -0
  169. package/src/signer/ckb/signerCkbPrivateKey.ts +14 -54
  170. package/src/signer/ckb/signerCkbPublicKey.ts +63 -0
  171. package/src/signer/ckb/verifyCkbSecp256k1.ts +27 -0
  172. package/src/signer/signer/index.ts +6 -0
  173. package/src/utils/index.ts +24 -12
@@ -1,17 +1,33 @@
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 });
17
33
  __exportStar(require("./signerNostr"), exports);
@@ -4,63 +4,63 @@ import { Transaction, TransactionLike } from "../../ckb";
4
4
  import { Hex } from "../../hex";
5
5
  import { Signer, SignerSignType, SignerType } from "../signer";
6
6
  export interface NostrEvent {
7
- id?: string;
8
- pubkey?: string;
9
- sig?: string;
10
- created_at: number;
11
- kind: number;
12
- tags: string[][];
13
- content: string;
7
+ id?: string;
8
+ pubkey?: string;
9
+ sig?: string;
10
+ created_at: number;
11
+ kind: number;
12
+ tags: string[][];
13
+ content: string;
14
14
  }
15
15
  export declare abstract class SignerNostr extends Signer {
16
- static CKB_SIG_HASH_ALL_TAG: string;
17
- static CKB_UNLOCK_EVENT_KIND: number;
18
- static CKB_UNLOCK_EVENT_CONTENT: string;
19
- get type(): SignerType;
20
- get signType(): SignerSignType;
21
- /**
22
- * Gets the Nostr public key associated with the signer.
23
- *
24
- * @returns A promise that resolves to a string representing the Nostr public key.
25
- */
26
- abstract getNostrPublicKey(): Promise<Hex>;
27
- /**
28
- * Sign a nostr event.
29
- *
30
- * @returns A promise that resolves to the signed event.
31
- */
32
- abstract signNostrEvent(event: NostrEvent): Promise<Required<NostrEvent>>;
33
- /**
34
- * Sign a message.
35
- *
36
- * @returns A promise that resolves to the signature.
37
- */
38
- signMessageRaw(message: string | BytesLike): Promise<Hex>;
39
- /**
40
- * Gets the internal address, which is the EVM account in this case.
41
- *
42
- * @returns A promise that resolves to a string representing the internal address.
43
- */
44
- getInternalAddress(): Promise<string>;
45
- /**
46
- * Gets an array of Address objects representing the known script addresses for the signer.
47
- *
48
- * @returns A promise that resolves to an array of Address objects.
49
- */
50
- getAddressObjs(): Promise<Address[]>;
51
- /**
52
- * prepare a transaction before signing.
53
- *
54
- * @param txLike - The transaction to prepare, represented as a TransactionLike object.
55
- * @returns A promise that resolves to the prepared Transaction object.
56
- */
57
- prepareTransaction(txLike: TransactionLike): Promise<Transaction>;
58
- /**
59
- * Signs a transaction without modifying it.
60
- *
61
- * @param txLike - The transaction to sign, represented as a TransactionLike object.
62
- * @returns A promise that resolves to a signed Transaction object.
63
- */
64
- signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
16
+ static CKB_SIG_HASH_ALL_TAG: string;
17
+ static CKB_UNLOCK_EVENT_KIND: number;
18
+ static CKB_UNLOCK_EVENT_CONTENT: string;
19
+ get type(): SignerType;
20
+ get signType(): SignerSignType;
21
+ /**
22
+ * Gets the Nostr public key associated with the signer.
23
+ *
24
+ * @returns A promise that resolves to a string representing the Nostr public key.
25
+ */
26
+ abstract getNostrPublicKey(): Promise<Hex>;
27
+ /**
28
+ * Sign a nostr event.
29
+ *
30
+ * @returns A promise that resolves to the signed event.
31
+ */
32
+ abstract signNostrEvent(event: NostrEvent): Promise<Required<NostrEvent>>;
33
+ /**
34
+ * Sign a message.
35
+ *
36
+ * @returns A promise that resolves to the signature.
37
+ */
38
+ signMessageRaw(message: string | BytesLike): Promise<Hex>;
39
+ /**
40
+ * Gets the internal address, which is the EVM account in this case.
41
+ *
42
+ * @returns A promise that resolves to a string representing the internal address.
43
+ */
44
+ getInternalAddress(): Promise<string>;
45
+ /**
46
+ * Gets an array of Address objects representing the known script addresses for the signer.
47
+ *
48
+ * @returns A promise that resolves to an array of Address objects.
49
+ */
50
+ getAddressObjs(): Promise<Address[]>;
51
+ /**
52
+ * prepare a transaction before signing.
53
+ *
54
+ * @param txLike - The transaction to prepare, represented as a TransactionLike object.
55
+ * @returns A promise that resolves to the prepared Transaction object.
56
+ */
57
+ prepareTransaction(txLike: TransactionLike): Promise<Transaction>;
58
+ /**
59
+ * Signs a transaction without modifying it.
60
+ *
61
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
62
+ * @returns A promise that resolves to a signed Transaction object.
63
+ */
64
+ signOnlyTransaction(txLike: TransactionLike): Promise<Transaction>;
65
65
  }
66
- //# sourceMappingURL=signerNostr.d.ts.map
66
+ //# sourceMappingURL=signerNostr.d.ts.map
@@ -11,79 +11,108 @@ const hex_1 = require("../../hex");
11
11
  const signer_1 = require("../signer");
12
12
  const verify_1 = require("./verify");
13
13
  class SignerNostr extends signer_1.Signer {
14
- get type() {
15
- return signer_1.SignerType.Nostr;
16
- }
17
- get signType() {
18
- return signer_1.SignerSignType.NostrEvent;
19
- }
20
- /**
21
- * Sign a message.
22
- *
23
- * @returns A promise that resolves to the signature.
24
- */
25
- async signMessageRaw(message) {
26
- return (0, hex_1.hexFrom)((await this.signNostrEvent((0, verify_1.buildNostrEventFromMessage)(message))).sig);
27
- }
28
- /**
29
- * Gets the internal address, which is the EVM account in this case.
30
- *
31
- * @returns A promise that resolves to a string representing the internal address.
32
- */
33
- async getInternalAddress() {
34
- return bech32_1.bech32.encode("npub", bech32_1.bech32.toWords((0, bytes_1.bytesFrom)(await this.getNostrPublicKey())));
35
- }
36
- /**
37
- * Gets an array of Address objects representing the known script addresses for the signer.
38
- *
39
- * @returns A promise that resolves to an array of Address objects.
40
- */
41
- async getAddressObjs() {
42
- const publicKey = await this.getNostrPublicKey();
43
- return [
44
- await address_1.Address.fromKnownScript(this.client, client_1.KnownScript.NostrLock, (0, hex_1.hexFrom)((0, bytes_1.bytesConcat)([0x00], (0, hasher_1.hashCkb)(publicKey).slice(0, 42)))),
45
- ];
46
- }
47
- /**
48
- * prepare a transaction before signing.
49
- *
50
- * @param txLike - The transaction to prepare, represented as a TransactionLike object.
51
- * @returns A promise that resolves to the prepared Transaction object.
52
- */
53
- async prepareTransaction(txLike) {
54
- const tx = ckb_1.Transaction.from(txLike);
55
- const { script } = await this.getRecommendedAddressObj();
56
- await tx.addCellDepsOfKnownScripts(this.client, client_1.KnownScript.NostrLock);
57
- await tx.prepareSighashAllWitness(script, 572, this.client);
58
- return tx;
59
- }
60
- /**
61
- * Signs a transaction without modifying it.
62
- *
63
- * @param txLike - The transaction to sign, represented as a TransactionLike object.
64
- * @returns A promise that resolves to a signed Transaction object.
65
- */
66
- async signOnlyTransaction(txLike) {
67
- let tx = ckb_1.Transaction.from(txLike);
68
- const { script } = await this.getRecommendedAddressObj();
69
- const info = await tx.getSignHashInfo(script, this.client);
70
- if (!info) {
71
- return tx;
72
- }
73
- const signedEvent = (0, bytes_1.bytesFrom)(JSON.stringify(await this.signNostrEvent({
74
- pubkey: (await this.getNostrPublicKey()).slice(2),
75
- tags: [[SignerNostr.CKB_SIG_HASH_ALL_TAG, info.message.slice(2)]],
76
- created_at: Math.floor(Date.now() / 1000),
77
- kind: SignerNostr.CKB_UNLOCK_EVENT_KIND,
78
- content: SignerNostr.CKB_UNLOCK_EVENT_CONTENT,
79
- })), "utf8");
80
- const witness = ckb_1.WitnessArgs.fromBytes(tx.witnesses[info.position]);
81
- witness.lock = (0, hex_1.hexFrom)(signedEvent);
82
- tx.setWitnessArgsAt(info.position, witness);
83
- return tx;
14
+ get type() {
15
+ return signer_1.SignerType.Nostr;
16
+ }
17
+ get signType() {
18
+ return signer_1.SignerSignType.NostrEvent;
19
+ }
20
+ /**
21
+ * Sign a message.
22
+ *
23
+ * @returns A promise that resolves to the signature.
24
+ */
25
+ async signMessageRaw(message) {
26
+ return (0, hex_1.hexFrom)(
27
+ (
28
+ await this.signNostrEvent(
29
+ (0, verify_1.buildNostrEventFromMessage)(message),
30
+ )
31
+ ).sig,
32
+ );
33
+ }
34
+ /**
35
+ * Gets the internal address, which is the EVM account in this case.
36
+ *
37
+ * @returns A promise that resolves to a string representing the internal address.
38
+ */
39
+ async getInternalAddress() {
40
+ return bech32_1.bech32.encode(
41
+ "npub",
42
+ bech32_1.bech32.toWords(
43
+ (0, bytes_1.bytesFrom)(await this.getNostrPublicKey()),
44
+ ),
45
+ );
46
+ }
47
+ /**
48
+ * Gets an array of Address objects representing the known script addresses for the signer.
49
+ *
50
+ * @returns A promise that resolves to an array of Address objects.
51
+ */
52
+ async getAddressObjs() {
53
+ const publicKey = await this.getNostrPublicKey();
54
+ return [
55
+ await address_1.Address.fromKnownScript(
56
+ this.client,
57
+ client_1.KnownScript.NostrLock,
58
+ (0, hex_1.hexFrom)(
59
+ (0, bytes_1.bytesConcat)(
60
+ [0x00],
61
+ (0, hasher_1.hashCkb)(publicKey).slice(0, 42),
62
+ ),
63
+ ),
64
+ ),
65
+ ];
66
+ }
67
+ /**
68
+ * prepare a transaction before signing.
69
+ *
70
+ * @param txLike - The transaction to prepare, represented as a TransactionLike object.
71
+ * @returns A promise that resolves to the prepared Transaction object.
72
+ */
73
+ async prepareTransaction(txLike) {
74
+ const tx = ckb_1.Transaction.from(txLike);
75
+ const { script } = await this.getRecommendedAddressObj();
76
+ await tx.addCellDepsOfKnownScripts(
77
+ this.client,
78
+ client_1.KnownScript.NostrLock,
79
+ );
80
+ await tx.prepareSighashAllWitness(script, 572, this.client);
81
+ return tx;
82
+ }
83
+ /**
84
+ * Signs a transaction without modifying it.
85
+ *
86
+ * @param txLike - The transaction to sign, represented as a TransactionLike object.
87
+ * @returns A promise that resolves to a signed Transaction object.
88
+ */
89
+ async signOnlyTransaction(txLike) {
90
+ let tx = ckb_1.Transaction.from(txLike);
91
+ const { script } = await this.getRecommendedAddressObj();
92
+ const info = await tx.getSignHashInfo(script, this.client);
93
+ if (!info) {
94
+ return tx;
84
95
  }
96
+ const signedEvent = (0, bytes_1.bytesFrom)(
97
+ JSON.stringify(
98
+ await this.signNostrEvent({
99
+ pubkey: (await this.getNostrPublicKey()).slice(2),
100
+ tags: [[SignerNostr.CKB_SIG_HASH_ALL_TAG, info.message.slice(2)]],
101
+ created_at: Math.floor(Date.now() / 1000),
102
+ kind: SignerNostr.CKB_UNLOCK_EVENT_KIND,
103
+ content: SignerNostr.CKB_UNLOCK_EVENT_CONTENT,
104
+ }),
105
+ ),
106
+ "utf8",
107
+ );
108
+ const witness = ckb_1.WitnessArgs.fromBytes(tx.witnesses[info.position]);
109
+ witness.lock = (0, hex_1.hexFrom)(signedEvent);
110
+ tx.setWitnessArgsAt(info.position, witness);
111
+ return tx;
112
+ }
85
113
  }
86
114
  exports.SignerNostr = SignerNostr;
87
115
  SignerNostr.CKB_SIG_HASH_ALL_TAG = "ckb_sighash_all";
88
116
  SignerNostr.CKB_UNLOCK_EVENT_KIND = 23334;
89
- SignerNostr.CKB_UNLOCK_EVENT_CONTENT = "Signing a CKB transaction\n\nIMPORTANT: Please verify the integrity and authenticity of connected Nostr client before signing this message\n";
117
+ SignerNostr.CKB_UNLOCK_EVENT_CONTENT =
118
+ "Signing a CKB transaction\n\nIMPORTANT: Please verify the integrity and authenticity of connected Nostr client before signing this message\n";
@@ -1,5 +1,11 @@
1
1
  import { BytesLike } from "../../bytes";
2
2
  import { NostrEvent } from "./signerNostr";
3
- export declare function buildNostrEventFromMessage(message: string | BytesLike): NostrEvent;
4
- export declare function verifyMessageNostrEvent(message: string | BytesLike, signature: string, address: string): boolean;
5
- //# sourceMappingURL=verify.d.ts.map
3
+ export declare function buildNostrEventFromMessage(
4
+ message: string | BytesLike,
5
+ ): NostrEvent;
6
+ export declare function verifyMessageNostrEvent(
7
+ message: string | BytesLike,
8
+ signature: string,
9
+ address: string,
10
+ ): boolean;
11
+ //# sourceMappingURL=verify.d.ts.map
@@ -7,47 +7,58 @@ const bech32_1 = require("bech32");
7
7
  const bytes_1 = require("../../bytes");
8
8
  const hex_1 = require("../../hex");
9
9
  function buildNostrEventFromMessage(message) {
10
- if (typeof message === "string") {
11
- try {
12
- const event = JSON.parse(message);
13
- if (typeof event === "object" &&
14
- typeof event.created_at === "number" &&
15
- typeof event.kind === "number" &&
16
- typeof event.content === "string" &&
17
- Array.isArray(event.args) &&
18
- event.args.every((tag) => Array.isArray(tag) &&
19
- tag.every((v) => typeof v === "string"))) {
20
- return event;
21
- }
22
- }
23
- catch (_) { }
24
- }
25
- return {
26
- kind: 23335,
27
- created_at: 0,
28
- content: typeof message === "string" ? message : (0, hex_1.hexFrom)(message),
29
- tags: [],
30
- };
10
+ if (typeof message === "string") {
11
+ try {
12
+ const event = JSON.parse(message);
13
+ if (
14
+ typeof event === "object" &&
15
+ typeof event.created_at === "number" &&
16
+ typeof event.kind === "number" &&
17
+ typeof event.content === "string" &&
18
+ Array.isArray(event.args) &&
19
+ event.args.every(
20
+ (tag) =>
21
+ Array.isArray(tag) && tag.every((v) => typeof v === "string"),
22
+ )
23
+ ) {
24
+ return event;
25
+ }
26
+ } catch (_) {}
27
+ }
28
+ return {
29
+ kind: 23335,
30
+ created_at: 0,
31
+ content:
32
+ typeof message === "string" ? message : (0, hex_1.hexFrom)(message),
33
+ tags: [],
34
+ };
31
35
  }
32
36
  exports.buildNostrEventFromMessage = buildNostrEventFromMessage;
33
37
  function verifyMessageNostrEvent(message, signature, address) {
34
- const { words } = bech32_1.bech32.decode(address);
35
- const publicKey = (0, hex_1.hexFrom)(bech32_1.bech32.fromWords(words)).slice(2);
36
- const event = buildNostrEventFromMessage(message);
37
- const serialized = JSON.stringify([
38
- 0,
39
- publicKey,
40
- event.created_at,
41
- event.kind,
42
- event.tags,
43
- event.content,
44
- ]);
45
- const eventHash = (0, hex_1.hexFrom)((0, sha256_1.sha256)((0, bytes_1.bytesFrom)(serialized, "utf8")));
46
- try {
47
- return secp256k1_1.schnorr.verify(signature.slice(2), eventHash.slice(2), publicKey);
48
- }
49
- catch (_) {
50
- return false;
51
- }
38
+ const { words } = bech32_1.bech32.decode(address);
39
+ const publicKey = (0, hex_1.hexFrom)(bech32_1.bech32.fromWords(words)).slice(
40
+ 2,
41
+ );
42
+ const event = buildNostrEventFromMessage(message);
43
+ const serialized = JSON.stringify([
44
+ 0,
45
+ publicKey,
46
+ event.created_at,
47
+ event.kind,
48
+ event.tags,
49
+ event.content,
50
+ ]);
51
+ const eventHash = (0, hex_1.hexFrom)(
52
+ (0, sha256_1.sha256)((0, bytes_1.bytesFrom)(serialized, "utf8")),
53
+ );
54
+ try {
55
+ return secp256k1_1.schnorr.verify(
56
+ signature.slice(2),
57
+ eventHash.slice(2),
58
+ publicKey,
59
+ );
60
+ } catch (_) {
61
+ return false;
62
+ }
52
63
  }
53
64
  exports.verifyMessageNostrEvent = verifyMessageNostrEvent;