@ckb-ccc/core 0.0.10-alpha.4 → 0.0.10-alpha.6

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 (135) hide show
  1. package/dist/address/address.advanced.js +4 -2
  2. package/dist/ckb/transaction.d.ts.map +1 -1
  3. package/dist/ckb/transaction.js +1 -2
  4. package/dist/signer/ckb/signerCkbPrivateKey.d.ts +1 -0
  5. package/dist/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -1
  6. package/dist/signer/ckb/signerCkbPrivateKey.js +7 -7
  7. package/dist/signer/signer/index.d.ts +0 -9
  8. package/dist/signer/signer/index.d.ts.map +1 -1
  9. package/dist/signer/signer/index.js +6 -13
  10. package/dist.commonjs/address/address.advanced.d.ts +24 -29
  11. package/dist.commonjs/address/address.advanced.js +91 -115
  12. package/dist.commonjs/address/advanced.d.ts +1 -1
  13. package/dist.commonjs/address/advanced.js +14 -30
  14. package/dist.commonjs/address/index.d.ts +44 -51
  15. package/dist.commonjs/address/index.js +65 -84
  16. package/dist.commonjs/advanced.d.ts +1 -1
  17. package/dist.commonjs/advanced.js +22 -47
  18. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  19. package/dist.commonjs/advancedBarrel.js +14 -30
  20. package/dist.commonjs/barrel.d.ts +1 -1
  21. package/dist.commonjs/barrel.js +14 -30
  22. package/dist.commonjs/bytes/advanced.d.ts +2 -11
  23. package/dist.commonjs/bytes/index.d.ts +3 -9
  24. package/dist.commonjs/bytes/index.js +26 -28
  25. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  26. package/dist.commonjs/ckb/advanced.js +22 -47
  27. package/dist.commonjs/ckb/index.d.ts +1 -1
  28. package/dist.commonjs/ckb/index.js +14 -30
  29. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +260 -420
  30. package/dist.commonjs/ckb/molecule.advanced/generated.js +1332 -1536
  31. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  32. package/dist.commonjs/ckb/molecule.advanced/index.js +18 -34
  33. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  34. package/dist.commonjs/ckb/script.advanced.js +9 -12
  35. package/dist.commonjs/ckb/script.d.ts +117 -121
  36. package/dist.commonjs/ckb/script.js +176 -220
  37. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  38. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  39. package/dist.commonjs/ckb/transaction.d.ts +722 -806
  40. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  41. package/dist.commonjs/ckb/transaction.js +1190 -1424
  42. package/dist.commonjs/client/advanced.d.ts +1 -1
  43. package/dist.commonjs/client/advanced.js +14 -30
  44. package/dist.commonjs/client/client.advanced.d.ts +6 -23
  45. package/dist.commonjs/client/client.advanced.js +61 -89
  46. package/dist.commonjs/client/client.d.ts +54 -114
  47. package/dist.commonjs/client/client.js +182 -215
  48. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +4 -8
  49. package/dist.commonjs/client/clientPublicMainnet.advanced.js +189 -215
  50. package/dist.commonjs/client/clientPublicMainnet.d.ts +6 -8
  51. package/dist.commonjs/client/clientPublicMainnet.js +15 -17
  52. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +3 -6
  53. package/dist.commonjs/client/clientPublicTestnet.advanced.js +199 -227
  54. package/dist.commonjs/client/clientPublicTestnet.d.ts +6 -8
  55. package/dist.commonjs/client/clientPublicTestnet.js +13 -13
  56. package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
  57. package/dist.commonjs/client/clientTypes.advanced.js +1 -1
  58. package/dist.commonjs/client/clientTypes.d.ts +26 -51
  59. package/dist.commonjs/client/clientTypes.js +22 -56
  60. package/dist.commonjs/client/index.d.ts +1 -1
  61. package/dist.commonjs/client/index.js +14 -30
  62. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  63. package/dist.commonjs/client/jsonRpc/advanced.js +14 -30
  64. package/dist.commonjs/client/jsonRpc/index.d.ts +75 -94
  65. package/dist.commonjs/client/jsonRpc/index.js +108 -135
  66. package/dist.commonjs/client/jsonRpc/transformers.d.ts +36 -76
  67. package/dist.commonjs/client/jsonRpc/transformers.js +152 -174
  68. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  69. package/dist.commonjs/fixedPoint/index.d.ts +3 -9
  70. package/dist.commonjs/fixedPoint/index.js +20 -26
  71. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  72. package/dist.commonjs/fixedPoint/index.test.js +36 -42
  73. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  74. package/dist.commonjs/hasher/index.d.ts +37 -40
  75. package/dist.commonjs/hasher/index.js +48 -58
  76. package/dist.commonjs/hex/index.d.ts +1 -1
  77. package/dist.commonjs/hex/index.js +1 -1
  78. package/dist.commonjs/index.d.ts +1 -1
  79. package/dist.commonjs/index.js +22 -47
  80. package/dist.commonjs/num/index.d.ts +1 -1
  81. package/dist.commonjs/num/index.js +27 -39
  82. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  83. package/dist.commonjs/signer/btc/index.js +14 -30
  84. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  85. package/dist.commonjs/signer/btc/signerBtc.js +66 -89
  86. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  87. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  88. package/dist.commonjs/signer/btc/verify.d.ts +2 -6
  89. package/dist.commonjs/signer/btc/verify.js +3 -10
  90. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  91. package/dist.commonjs/signer/ckb/index.js +14 -30
  92. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts +6 -5
  93. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.d.ts.map +1 -1
  94. package/dist.commonjs/signer/ckb/signerCkbPrivateKey.js +28 -42
  95. package/dist.commonjs/signer/ckb/signerCkbPublicKey.d.ts +11 -11
  96. package/dist.commonjs/signer/ckb/signerCkbPublicKey.js +35 -45
  97. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  98. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  99. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.d.ts +3 -9
  100. package/dist.commonjs/signer/ckb/verifyCkbSecp256k1.js +5 -13
  101. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +2 -6
  102. package/dist.commonjs/signer/ckb/verifyJoyId.js +8 -11
  103. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  104. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  105. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  106. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  107. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  108. package/dist.commonjs/signer/dummy/index.js +14 -30
  109. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  110. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  111. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  112. package/dist.commonjs/signer/evm/index.js +14 -30
  113. package/dist.commonjs/signer/evm/signerEvm.d.ts +38 -42
  114. package/dist.commonjs/signer/evm/signerEvm.js +70 -105
  115. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
  116. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  117. package/dist.commonjs/signer/evm/verify.d.ts +2 -6
  118. package/dist.commonjs/signer/evm/verify.js +2 -7
  119. package/dist.commonjs/signer/index.d.ts +1 -1
  120. package/dist.commonjs/signer/index.js +14 -30
  121. package/dist.commonjs/signer/nostr/index.d.ts +1 -1
  122. package/dist.commonjs/signer/nostr/index.js +14 -30
  123. package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
  124. package/dist.commonjs/signer/nostr/signerNostr.js +71 -100
  125. package/dist.commonjs/signer/nostr/verify.d.ts +3 -9
  126. package/dist.commonjs/signer/nostr/verify.js +39 -50
  127. package/dist.commonjs/signer/signer/index.d.ts +153 -171
  128. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  129. package/dist.commonjs/signer/signer/index.js +191 -234
  130. package/dist.commonjs/utils/index.d.ts +9 -42
  131. package/dist.commonjs/utils/index.js +12 -18
  132. package/package.json +3 -3
  133. package/src/address/address.advanced.ts +4 -4
  134. package/src/signer/ckb/signerCkbPrivateKey.ts +8 -8
  135. package/src/signer/signer/index.ts +6 -14
@@ -4,53 +4,39 @@ exports.SignerCkbPrivateKey = void 0;
4
4
  const secp256k1_1 = require("@noble/curves/secp256k1");
5
5
  const bytes_1 = require("../../bytes");
6
6
  const ckb_1 = require("../../ckb");
7
- const hasher_1 = require("../../hasher");
8
7
  const hex_1 = require("../../hex");
9
8
  const num_1 = require("../../num");
10
9
  const signerCkbPublicKey_1 = require("./signerCkbPublicKey");
10
+ const verifyCkbSecp256k1_1 = require("./verifyCkbSecp256k1");
11
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!");
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(client, secp256k1_1.secp256k1.getPublicKey((0, bytes_1.bytesFrom)(pk), true));
18
+ this.privateKey = pk;
16
19
  }
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;
20
+ async _signMessage(message) {
21
+ const signature = secp256k1_1.secp256k1.sign((0, bytes_1.bytesFrom)(message), (0, bytes_1.bytesFrom)(this.privateKey));
22
+ const { r, s, recovery } = signature;
23
+ return (0, hex_1.hexFrom)((0, bytes_1.bytesConcat)((0, num_1.numBeToBytes)(r, 32), (0, num_1.numBeToBytes)(s, 32), (0, num_1.numBeToBytes)(recovery, 1)));
24
+ }
25
+ async signMessageRaw(message) {
26
+ return this._signMessage((0, verifyCkbSecp256k1_1.messageHashCkbSecp256k1)(message));
27
+ }
28
+ async signOnlyTransaction(txLike) {
29
+ const tx = ckb_1.Transaction.from(txLike);
30
+ const { script } = await this.getRecommendedAddressObj();
31
+ const info = await tx.getSignHashInfo(script, this.client);
32
+ if (!info) {
33
+ return tx;
34
+ }
35
+ const signature = await this._signMessage(info.message);
36
+ const witness = tx.getWitnessArgsAt(info.position) ?? ckb_1.WitnessArgs.from({});
37
+ witness.lock = signature;
38
+ tx.setWitnessArgsAt(info.position, witness);
39
+ return tx;
47
40
  }
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
41
  }
56
42
  exports.SignerCkbPrivateKey = SignerCkbPrivateKey;
@@ -4,15 +4,15 @@ import { Client } from "../../client";
4
4
  import { Hex, HexLike } from "../../hex";
5
5
  import { Signer, SignerSignType, SignerType } from "../signer";
6
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>;
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
17
  }
18
- //# sourceMappingURL=signerCkbPublicKey.d.ts.map
18
+ //# sourceMappingURL=signerCkbPublicKey.d.ts.map
@@ -9,50 +9,40 @@ const hasher_1 = require("../../hasher");
9
9
  const hex_1 = require("../../hex");
10
10
  const signer_1 = require("../signer");
11
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
- }
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(this.client, client_1.KnownScript.Secp256k1Blake160, (0, bytes_1.bytesFrom)((0, hasher_1.hashCkb)(this.publicKey)).slice(0, 20)),
38
+ ];
39
+ }
40
+ async prepareTransaction(txLike) {
41
+ const tx = ckb_1.Transaction.from(txLike);
42
+ const { script } = await this.getRecommendedAddressObj();
43
+ await tx.addCellDepsOfKnownScripts(this.client, client_1.KnownScript.Secp256k1Blake160);
44
+ await tx.prepareSighashAllWitness(script, 65, this.client);
45
+ return tx;
46
+ }
57
47
  }
58
48
  exports.SignerCkbPublicKey = SignerCkbPublicKey;
@@ -7,49 +7,49 @@ import { Signer, SignerSignType, SignerType } from "../signer";
7
7
  * This class does not support signing operations.
8
8
  */
9
9
  export declare class SignerCkbScriptReadonly extends Signer {
10
- get type(): SignerType;
11
- get signType(): SignerSignType;
12
- private readonly script;
13
- /**
14
- * Creates an instance of SignerCkbScriptReadonly.
15
- *
16
- * @param client - The client instance used for communication.
17
- * @param script - The script associated with the signer.
18
- */
19
- constructor(client: Client, script: ScriptLike);
20
- /**
21
- * Connects to the client. This implementation does nothing as the class is read-only.
22
- *
23
- * @returns A promise that resolves when the connection is complete.
24
- */
25
- connect(): Promise<void>;
26
- /**
27
- * Check if the signer is connected.
28
- *
29
- * @returns A promise that resolves the connection status.
30
- */
31
- isConnected(): Promise<boolean>;
32
- /**
33
- * Gets the internal address for the script.
34
- *
35
- * @returns A promise that resolves to a string representing the internal address.
36
- *
37
- * @example
38
- * ```typescript
39
- * const internalAddress = await signer.getInternalAddress(); // Outputs the internal address
40
- * ```
41
- */
42
- getInternalAddress(): Promise<string>;
43
- /**
44
- * Gets an array of Address objects representing the script address.
45
- *
46
- * @returns A promise that resolves to an array of Address objects.
47
- *
48
- * @example
49
- * ```typescript
50
- * const addressObjs = await signer.getAddressObjs(); // Outputs the array of Address objects
51
- * ```
52
- */
53
- getAddressObjs(): Promise<Address[]>;
10
+ get type(): SignerType;
11
+ get signType(): SignerSignType;
12
+ private readonly script;
13
+ /**
14
+ * Creates an instance of SignerCkbScriptReadonly.
15
+ *
16
+ * @param client - The client instance used for communication.
17
+ * @param script - The script associated with the signer.
18
+ */
19
+ constructor(client: Client, script: ScriptLike);
20
+ /**
21
+ * Connects to the client. This implementation does nothing as the class is read-only.
22
+ *
23
+ * @returns A promise that resolves when the connection is complete.
24
+ */
25
+ connect(): Promise<void>;
26
+ /**
27
+ * Check if the signer is connected.
28
+ *
29
+ * @returns A promise that resolves the connection status.
30
+ */
31
+ isConnected(): Promise<boolean>;
32
+ /**
33
+ * Gets the internal address for the script.
34
+ *
35
+ * @returns A promise that resolves to a string representing the internal address.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const internalAddress = await signer.getInternalAddress(); // Outputs the internal address
40
+ * ```
41
+ */
42
+ getInternalAddress(): Promise<string>;
43
+ /**
44
+ * Gets an array of Address objects representing the script address.
45
+ *
46
+ * @returns A promise that resolves to an array of Address objects.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const addressObjs = await signer.getAddressObjs(); // Outputs the array of Address objects
51
+ * ```
52
+ */
53
+ getAddressObjs(): Promise<Address[]>;
54
54
  }
55
- //# sourceMappingURL=signerCkbScriptReadonly.d.ts.map
55
+ //# sourceMappingURL=signerCkbScriptReadonly.d.ts.map
@@ -9,61 +9,61 @@ const signer_1 = require("../signer");
9
9
  * This class does not support signing operations.
10
10
  */
11
11
  class SignerCkbScriptReadonly extends signer_1.Signer {
12
- get type() {
13
- return signer_1.SignerType.CKB;
14
- }
15
- get signType() {
16
- return signer_1.SignerSignType.Unknown;
17
- }
18
- /**
19
- * Creates an instance of SignerCkbScriptReadonly.
20
- *
21
- * @param client - The client instance used for communication.
22
- * @param script - The script associated with the signer.
23
- */
24
- constructor(client, script) {
25
- super(client);
26
- this.script = ckb_1.Script.from(script);
27
- }
28
- /**
29
- * Connects to the client. This implementation does nothing as the class is read-only.
30
- *
31
- * @returns A promise that resolves when the connection is complete.
32
- */
33
- async connect() {}
34
- /**
35
- * Check if the signer is connected.
36
- *
37
- * @returns A promise that resolves the connection status.
38
- */
39
- async isConnected() {
40
- return true;
41
- }
42
- /**
43
- * Gets the internal address for the script.
44
- *
45
- * @returns A promise that resolves to a string representing the internal address.
46
- *
47
- * @example
48
- * ```typescript
49
- * const internalAddress = await signer.getInternalAddress(); // Outputs the internal address
50
- * ```
51
- */
52
- async getInternalAddress() {
53
- return this.getRecommendedAddress();
54
- }
55
- /**
56
- * Gets an array of Address objects representing the script address.
57
- *
58
- * @returns A promise that resolves to an array of Address objects.
59
- *
60
- * @example
61
- * ```typescript
62
- * const addressObjs = await signer.getAddressObjs(); // Outputs the array of Address objects
63
- * ```
64
- */
65
- async getAddressObjs() {
66
- return [address_1.Address.fromScript(this.script, this.client)];
67
- }
12
+ get type() {
13
+ return signer_1.SignerType.CKB;
14
+ }
15
+ get signType() {
16
+ return signer_1.SignerSignType.Unknown;
17
+ }
18
+ /**
19
+ * Creates an instance of SignerCkbScriptReadonly.
20
+ *
21
+ * @param client - The client instance used for communication.
22
+ * @param script - The script associated with the signer.
23
+ */
24
+ constructor(client, script) {
25
+ super(client);
26
+ this.script = ckb_1.Script.from(script);
27
+ }
28
+ /**
29
+ * Connects to the client. This implementation does nothing as the class is read-only.
30
+ *
31
+ * @returns A promise that resolves when the connection is complete.
32
+ */
33
+ async connect() { }
34
+ /**
35
+ * Check if the signer is connected.
36
+ *
37
+ * @returns A promise that resolves the connection status.
38
+ */
39
+ async isConnected() {
40
+ return true;
41
+ }
42
+ /**
43
+ * Gets the internal address for the script.
44
+ *
45
+ * @returns A promise that resolves to a string representing the internal address.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const internalAddress = await signer.getInternalAddress(); // Outputs the internal address
50
+ * ```
51
+ */
52
+ async getInternalAddress() {
53
+ return this.getRecommendedAddress();
54
+ }
55
+ /**
56
+ * Gets an array of Address objects representing the script address.
57
+ *
58
+ * @returns A promise that resolves to an array of Address objects.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const addressObjs = await signer.getAddressObjs(); // Outputs the array of Address objects
63
+ * ```
64
+ */
65
+ async getAddressObjs() {
66
+ return [address_1.Address.fromScript(this.script, this.client)];
67
+ }
68
68
  }
69
69
  exports.SignerCkbScriptReadonly = SignerCkbScriptReadonly;
@@ -1,11 +1,5 @@
1
1
  import { BytesLike } from "../../bytes";
2
2
  import { Hex } from "../../hex";
3
- export declare function messageHashCkbSecp256k1(
4
- message: string | BytesLike,
5
- ): Hex;
6
- export declare function verifyMessageCkbSecp256k1(
7
- message: string | BytesLike,
8
- signature: string,
9
- publicKey: string,
10
- ): boolean;
11
- //# sourceMappingURL=verifyCkbSecp256k1.d.ts.map
3
+ export declare function messageHashCkbSecp256k1(message: string | BytesLike): Hex;
4
+ export declare function verifyMessageCkbSecp256k1(message: string | BytesLike, signature: string, publicKey: string): boolean;
5
+ //# sourceMappingURL=verifyCkbSecp256k1.d.ts.map
@@ -7,21 +7,13 @@ const hasher_1 = require("../../hasher");
7
7
  const hex_1 = require("../../hex");
8
8
  const num_1 = require("../../num");
9
9
  function messageHashCkbSecp256k1(message) {
10
- const msg =
11
- typeof message === "string" ? message : (0, hex_1.hexFrom)(message);
12
- const buffer = (0, bytes_1.bytesFrom)(`Nervos Message:${msg}`, "utf8");
13
- return (0, hasher_1.hashCkb)(buffer);
10
+ const msg = typeof message === "string" ? message : (0, hex_1.hexFrom)(message);
11
+ const buffer = (0, bytes_1.bytesFrom)(`Nervos Message:${msg}`, "utf8");
12
+ return (0, hasher_1.hashCkb)(buffer);
14
13
  }
15
14
  exports.messageHashCkbSecp256k1 = messageHashCkbSecp256k1;
16
15
  function verifyMessageCkbSecp256k1(message, signature, publicKey) {
17
- const signatureBytes = (0, bytes_1.bytesFrom)(signature);
18
- return secp256k1_1.secp256k1.verify(
19
- new secp256k1_1.secp256k1.Signature(
20
- (0, num_1.numFrom)(signatureBytes.slice(0, 32)),
21
- (0, num_1.numFrom)(signatureBytes.slice(32, 64)),
22
- ).addRecoveryBit(Number((0, num_1.numFrom)(signatureBytes.slice(64, 65)))),
23
- (0, bytes_1.bytesFrom)(messageHashCkbSecp256k1(message)),
24
- (0, bytes_1.bytesFrom)(publicKey),
25
- );
16
+ const signatureBytes = (0, bytes_1.bytesFrom)(signature);
17
+ return secp256k1_1.secp256k1.verify(new secp256k1_1.secp256k1.Signature((0, num_1.numFrom)(signatureBytes.slice(0, 32)), (0, num_1.numFrom)(signatureBytes.slice(32, 64))).addRecoveryBit(Number((0, num_1.numFrom)(signatureBytes.slice(64, 65)))), (0, bytes_1.bytesFrom)(messageHashCkbSecp256k1(message)), (0, bytes_1.bytesFrom)(publicKey));
26
18
  }
27
19
  exports.verifyMessageCkbSecp256k1 = verifyMessageCkbSecp256k1;
@@ -1,7 +1,3 @@
1
1
  import { BytesLike } from "../../bytes";
2
- export declare function verifyMessageJoyId(
3
- message: string | BytesLike,
4
- signature: string,
5
- identity: string,
6
- ): Promise<boolean>;
7
- //# sourceMappingURL=verifyJoyId.d.ts.map
2
+ export declare function verifyMessageJoyId(message: string | BytesLike, signature: string, identity: string): Promise<boolean>;
3
+ //# sourceMappingURL=verifyJoyId.d.ts.map
@@ -4,16 +4,13 @@ exports.verifyMessageJoyId = void 0;
4
4
  const ckb_1 = require("@joyid/ckb");
5
5
  const hex_1 = require("../../hex");
6
6
  function verifyMessageJoyId(message, signature, identity) {
7
- const challenge =
8
- typeof message === "string"
9
- ? message
10
- : (0, hex_1.hexFrom)(message).slice(2);
11
- const { publicKey, keyType } = JSON.parse(identity);
12
- return (0, ckb_1.verifySignature)({
13
- challenge,
14
- pubkey: publicKey,
15
- keyType,
16
- ...JSON.parse(signature),
17
- });
7
+ const challenge = typeof message === "string" ? message : (0, hex_1.hexFrom)(message).slice(2);
8
+ const { publicKey, keyType } = JSON.parse(identity);
9
+ return (0, ckb_1.verifySignature)({
10
+ challenge,
11
+ pubkey: publicKey,
12
+ keyType,
13
+ ...JSON.parse(signature),
14
+ });
18
15
  }
19
16
  exports.verifyMessageJoyId = verifyMessageJoyId;
@@ -2,8 +2,8 @@ import { Client } from "../../client";
2
2
  import { SignerType } from "../signer";
3
3
  import { SignerDummy } from "./dummy";
4
4
  export declare class SignerAlwaysError extends SignerDummy {
5
- private readonly message;
6
- constructor(client: Client, type: SignerType, message: string);
7
- connect(): Promise<void>;
5
+ private readonly message;
6
+ constructor(client: Client, type: SignerType, message: string);
7
+ connect(): Promise<void>;
8
8
  }
9
- //# sourceMappingURL=alwaysError.d.ts.map
9
+ //# sourceMappingURL=alwaysError.d.ts.map
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SignerAlwaysError = void 0;
4
4
  const dummy_1 = require("./dummy");
5
5
  class SignerAlwaysError extends dummy_1.SignerDummy {
6
- constructor(client, type, message) {
7
- super(client, type);
8
- this.message = message;
9
- }
10
- async connect() {
11
- throw new Error(this.message);
12
- }
6
+ constructor(client, type, message) {
7
+ super(client, type);
8
+ this.message = message;
9
+ }
10
+ async connect() {
11
+ throw new Error(this.message);
12
+ }
13
13
  }
14
14
  exports.SignerAlwaysError = SignerAlwaysError;
@@ -2,11 +2,11 @@ import { Address } from "../../address";
2
2
  import { Client } from "../../client";
3
3
  import { Signer, SignerSignType, SignerType } from "../signer";
4
4
  export declare abstract class SignerDummy extends Signer {
5
- readonly type: SignerType;
6
- get signType(): SignerSignType;
7
- constructor(client: Client, type: SignerType);
8
- isConnected(): Promise<boolean>;
9
- getInternalAddress(): Promise<string>;
10
- getAddressObjs(): Promise<Address[]>;
5
+ readonly type: SignerType;
6
+ get signType(): SignerSignType;
7
+ constructor(client: Client, type: SignerType);
8
+ isConnected(): Promise<boolean>;
9
+ getInternalAddress(): Promise<string>;
10
+ getAddressObjs(): Promise<Address[]>;
11
11
  }
12
- //# sourceMappingURL=dummy.d.ts.map
12
+ //# sourceMappingURL=dummy.d.ts.map
@@ -3,21 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SignerDummy = void 0;
4
4
  const signer_1 = require("../signer");
5
5
  class SignerDummy extends signer_1.Signer {
6
- get signType() {
7
- return signer_1.SignerSignType.Unknown;
8
- }
9
- constructor(client, type) {
10
- super(client);
11
- this.type = type;
12
- }
13
- async isConnected() {
14
- return false;
15
- }
16
- async getInternalAddress() {
17
- throw new Error("Can't get address from SignerDummy");
18
- }
19
- async getAddressObjs() {
20
- throw new Error("Can't get addresses from SignerDummy");
21
- }
6
+ get signType() {
7
+ return signer_1.SignerSignType.Unknown;
8
+ }
9
+ constructor(client, type) {
10
+ super(client);
11
+ this.type = type;
12
+ }
13
+ async isConnected() {
14
+ return false;
15
+ }
16
+ async getInternalAddress() {
17
+ throw new Error("Can't get address from SignerDummy");
18
+ }
19
+ async getAddressObjs() {
20
+ throw new Error("Can't get addresses from SignerDummy");
21
+ }
22
22
  }
23
23
  exports.SignerDummy = SignerDummy;
@@ -1,4 +1,4 @@
1
1
  export * from "./alwaysError";
2
2
  export * from "./dummy";
3
3
  export * from "./openLink";
4
- //# sourceMappingURL=index.d.ts.map
4
+ //# sourceMappingURL=index.d.ts.map
@@ -1,34 +1,18 @@
1
1
  "use strict";
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
- };
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
+ };
32
16
  Object.defineProperty(exports, "__esModule", { value: true });
33
17
  __exportStar(require("./alwaysError"), exports);
34
18
  __exportStar(require("./dummy"), exports);