@ckb-ccc/core 0.0.7-alpha.2 → 0.0.8-alpha.3

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 (115) hide show
  1. package/README.md +6 -4
  2. package/dist.commonjs/address/address.advanced.d.ts +29 -24
  3. package/dist.commonjs/address/address.advanced.js +115 -89
  4. package/dist.commonjs/address/advanced.d.ts +1 -1
  5. package/dist.commonjs/address/advanced.js +30 -14
  6. package/dist.commonjs/address/index.d.ts +51 -44
  7. package/dist.commonjs/address/index.js +84 -65
  8. package/dist.commonjs/advanced.d.ts +1 -1
  9. package/dist.commonjs/advanced.js +47 -22
  10. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  11. package/dist.commonjs/advancedBarrel.js +30 -14
  12. package/dist.commonjs/barrel.d.ts +1 -1
  13. package/dist.commonjs/barrel.js +30 -14
  14. package/dist.commonjs/bytes/advanced.d.ts +11 -2
  15. package/dist.commonjs/bytes/index.d.ts +9 -3
  16. package/dist.commonjs/bytes/index.js +28 -26
  17. package/dist.commonjs/ckb/advanced.d.ts +1 -1
  18. package/dist.commonjs/ckb/advanced.js +47 -22
  19. package/dist.commonjs/ckb/index.d.ts +1 -1
  20. package/dist.commonjs/ckb/index.js +30 -14
  21. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +420 -260
  22. package/dist.commonjs/ckb/molecule.advanced/generated.js +1536 -1332
  23. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +3 -3
  24. package/dist.commonjs/ckb/molecule.advanced/index.js +34 -18
  25. package/dist.commonjs/ckb/script.advanced.d.ts +1 -1
  26. package/dist.commonjs/ckb/script.advanced.js +12 -9
  27. package/dist.commonjs/ckb/script.d.ts +121 -117
  28. package/dist.commonjs/ckb/script.js +220 -176
  29. package/dist.commonjs/ckb/transaction.advanced.d.ts +1 -1
  30. package/dist.commonjs/ckb/transaction.advanced.js +4 -4
  31. package/dist.commonjs/ckb/transaction.d.ts +792 -717
  32. package/dist.commonjs/ckb/transaction.js +1383 -1155
  33. package/dist.commonjs/client/advanced.d.ts +1 -1
  34. package/dist.commonjs/client/advanced.js +30 -14
  35. package/dist.commonjs/client/client.advanced.d.ts +23 -6
  36. package/dist.commonjs/client/client.advanced.js +89 -61
  37. package/dist.commonjs/client/client.d.ts +113 -53
  38. package/dist.commonjs/client/client.js +214 -181
  39. package/dist.commonjs/client/clientPublicMainnet.advanced.d.ts +8 -4
  40. package/dist.commonjs/client/clientPublicMainnet.advanced.js +144 -127
  41. package/dist.commonjs/client/clientPublicMainnet.d.ts +8 -6
  42. package/dist.commonjs/client/clientPublicMainnet.js +17 -15
  43. package/dist.commonjs/client/clientPublicTestnet.advanced.d.ts +6 -3
  44. package/dist.commonjs/client/clientPublicTestnet.advanced.js +204 -179
  45. package/dist.commonjs/client/clientPublicTestnet.d.ts +8 -6
  46. package/dist.commonjs/client/clientPublicTestnet.js +13 -13
  47. package/dist.commonjs/client/clientTypes.advanced.d.ts +14 -14
  48. package/dist.commonjs/client/clientTypes.advanced.js +1 -1
  49. package/dist.commonjs/client/clientTypes.d.ts +51 -26
  50. package/dist.commonjs/client/clientTypes.js +56 -22
  51. package/dist.commonjs/client/index.d.ts +1 -1
  52. package/dist.commonjs/client/index.js +30 -14
  53. package/dist.commonjs/client/jsonRpc/advanced.d.ts +1 -1
  54. package/dist.commonjs/client/jsonRpc/advanced.js +30 -14
  55. package/dist.commonjs/client/jsonRpc/index.d.ts +94 -75
  56. package/dist.commonjs/client/jsonRpc/index.js +135 -108
  57. package/dist.commonjs/client/jsonRpc/transformers.d.ts +76 -36
  58. package/dist.commonjs/client/jsonRpc/transformers.js +174 -152
  59. package/dist.commonjs/client/jsonRpc/types.d.ts +38 -38
  60. package/dist.commonjs/fixedPoint/index.d.ts +9 -3
  61. package/dist.commonjs/fixedPoint/index.js +26 -20
  62. package/dist.commonjs/fixedPoint/index.test.d.ts +1 -1
  63. package/dist.commonjs/fixedPoint/index.test.js +42 -36
  64. package/dist.commonjs/hasher/advanced.d.ts +1 -1
  65. package/dist.commonjs/hasher/index.d.ts +36 -36
  66. package/dist.commonjs/hasher/index.js +54 -47
  67. package/dist.commonjs/hex/index.d.ts +1 -1
  68. package/dist.commonjs/hex/index.js +1 -1
  69. package/dist.commonjs/index.d.ts +1 -1
  70. package/dist.commonjs/index.js +47 -22
  71. package/dist.commonjs/num/index.d.ts +1 -1
  72. package/dist.commonjs/num/index.js +39 -27
  73. package/dist.commonjs/signer/btc/index.d.ts +1 -1
  74. package/dist.commonjs/signer/btc/index.js +30 -14
  75. package/dist.commonjs/signer/btc/signerBtc.d.ts +47 -47
  76. package/dist.commonjs/signer/btc/signerBtc.js +89 -66
  77. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.d.ts +45 -45
  78. package/dist.commonjs/signer/btc/signerBtcPublicKeyReadonly.js +52 -52
  79. package/dist.commonjs/signer/btc/verify.d.ts +6 -2
  80. package/dist.commonjs/signer/btc/verify.js +10 -3
  81. package/dist.commonjs/signer/ckb/index.d.ts +1 -1
  82. package/dist.commonjs/signer/ckb/index.js +30 -14
  83. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +45 -45
  84. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +56 -56
  85. package/dist.commonjs/signer/ckb/verifyJoyId.d.ts +6 -2
  86. package/dist.commonjs/signer/ckb/verifyJoyId.js +11 -8
  87. package/dist.commonjs/signer/dummy/alwaysError.d.ts +4 -4
  88. package/dist.commonjs/signer/dummy/alwaysError.js +7 -7
  89. package/dist.commonjs/signer/dummy/dummy.d.ts +7 -7
  90. package/dist.commonjs/signer/dummy/dummy.js +16 -16
  91. package/dist.commonjs/signer/dummy/index.d.ts +1 -1
  92. package/dist.commonjs/signer/dummy/index.js +30 -14
  93. package/dist.commonjs/signer/dummy/openLink.d.ts +4 -4
  94. package/dist.commonjs/signer/dummy/openLink.js +7 -7
  95. package/dist.commonjs/signer/evm/index.d.ts +1 -1
  96. package/dist.commonjs/signer/evm/index.js +30 -14
  97. package/dist.commonjs/signer/evm/signerEvm.d.ts +42 -38
  98. package/dist.commonjs/signer/evm/signerEvm.js +105 -70
  99. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.d.ts +37 -37
  100. package/dist.commonjs/signer/evm/signerEvmAddressReadonly.js +42 -42
  101. package/dist.commonjs/signer/evm/verify.d.ts +6 -2
  102. package/dist.commonjs/signer/evm/verify.js +7 -2
  103. package/dist.commonjs/signer/index.d.ts +1 -1
  104. package/dist.commonjs/signer/index.js +30 -14
  105. package/dist.commonjs/signer/nostr/index.d.ts +1 -1
  106. package/dist.commonjs/signer/nostr/index.js +30 -14
  107. package/dist.commonjs/signer/nostr/signerNostr.d.ts +57 -57
  108. package/dist.commonjs/signer/nostr/signerNostr.js +100 -71
  109. package/dist.commonjs/signer/nostr/verify.d.ts +9 -3
  110. package/dist.commonjs/signer/nostr/verify.js +50 -39
  111. package/dist.commonjs/signer/signer/index.d.ts +156 -150
  112. package/dist.commonjs/signer/signer/index.js +208 -181
  113. package/dist.commonjs/utils/index.d.ts +38 -8
  114. package/dist.commonjs/utils/index.js +18 -12
  115. package/package.json +2 -2
@@ -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.ckbHash)(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.ckbHash)(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;
@@ -5,177 +5,183 @@ import { Client } from "../../client";
5
5
  import { Hex } from "../../hex";
6
6
  import { Num } from "../../num";
7
7
  export declare enum SignerSignType {
8
- Unknown = "Unknown",
9
- BtcEcdsa = "BtcEcdsa",
10
- EvmPersonal = "EvmPersonal",
11
- JoyId = "JoyId",
12
- NostrEvent = "NostrEvent"
8
+ Unknown = "Unknown",
9
+ BtcEcdsa = "BtcEcdsa",
10
+ EvmPersonal = "EvmPersonal",
11
+ JoyId = "JoyId",
12
+ NostrEvent = "NostrEvent",
13
13
  }
14
14
  /**
15
15
  * An enumeration of signer display types in wallet.
16
16
  */
17
17
  export declare enum SignerType {
18
- EVM = "EVM",
19
- BTC = "BTC",
20
- CKB = "CKB",
21
- Nostr = "Nostr"
18
+ EVM = "EVM",
19
+ BTC = "BTC",
20
+ CKB = "CKB",
21
+ Nostr = "Nostr",
22
22
  }
23
23
  export declare class Signature {
24
- signature: string;
25
- identity: string;
26
- signType: SignerSignType;
27
- constructor(signature: string, identity: string, signType: SignerSignType);
24
+ signature: string;
25
+ identity: string;
26
+ signType: SignerSignType;
27
+ constructor(signature: string, identity: string, signType: SignerSignType);
28
28
  }
29
29
  /**
30
30
  * An abstract class representing a generic signer.
31
31
  * This class provides methods to connect, get addresses, and sign transactions.
32
32
  */
33
33
  export declare abstract class Signer {
34
- protected client_: Client;
35
- constructor(client_: Client);
36
- abstract get type(): SignerType;
37
- abstract get signType(): SignerSignType;
38
- get client(): Client;
39
- static verifyMessage(message: string | BytesLike, signature: Signature): Promise<boolean>;
40
- /**
41
- * Replace the current client.
42
- * returns false if the new client is invalid for this signer.
43
- */
44
- replaceClient(client: Client): Promise<boolean>;
45
- /**
46
- * Connects to the signer.
47
- *
48
- * @returns A promise that resolves when the connection is complete.
49
- */
50
- abstract connect(): Promise<void>;
51
- /**
52
- * Check if the signer is connected.
53
- *
54
- * @returns A promise that resolves the connection status.
55
- */
56
- abstract isConnected(): Promise<boolean>;
57
- /**
58
- * Gets the internal address associated with the signer.
59
- *
60
- * @returns A promise that resolves to a string representing the internal address.
61
- */
62
- abstract getInternalAddress(): Promise<string>;
63
- /**
64
- * Gets the identity for verifying signature, usually it's address
65
- *
66
- * @returns A promise that resolves to a string representing the identity
67
- */
68
- getIdentity(): Promise<string>;
69
- /**
70
- * Gets an array of Address objects associated with the signer.
71
- *
72
- * @returns A promise that resolves to an array of Address objects.
73
- */
74
- abstract getAddressObjs(): Promise<Address[]>;
75
- /**
76
- * Gets the recommended Address object for the signer.
77
- *
78
- * @param _preference - Optional preference parameter.
79
- * @returns A promise that resolves to the recommended Address object.
80
- */
81
- getRecommendedAddressObj(_preference?: unknown): Promise<Address>;
82
- /**
83
- * Gets the recommended address for the signer as a string.
84
- *
85
- * @param preference - Optional preference parameter.
86
- * @returns A promise that resolves to the recommended address as a string.
87
- */
88
- getRecommendedAddress(preference?: unknown): Promise<string>;
89
- /**
90
- * Gets an array of addresses associated with the signer as strings.
91
- *
92
- * @returns A promise that resolves to an array of addresses as strings.
93
- */
94
- getAddresses(): Promise<string[]>;
95
- /**
96
- * Gets balance of all addresses
97
- *
98
- * @returns A promise that resolves to the balance
99
- */
100
- getBalance(): Promise<Num>;
101
- /**
102
- * Signs a message.
103
- *
104
- * @param _ - The message to sign, as a string or BytesLike object.
105
- * @returns A promise that resolves to the signature info.
106
- * @throws Will throw an error if not implemented.
107
- */
108
- signMessage(message: string | BytesLike): Promise<Signature>;
109
- /**
110
- * Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
111
- *
112
- * @param _ - The message to sign, as a string or BytesLike object.
113
- * @returns A promise that resolves to the signature as a string.
114
- * @throws Will throw an error if not implemented.
115
- */
116
- signMessageRaw(_: string | BytesLike): Promise<string>;
117
- /**
118
- * Verify a signature.
119
- *
120
- * @param _ - The original message.
121
- * @param _ - The signature to verify.
122
- * @returns A promise that resolves to the verification result.
123
- * @throws Will throw an error if not implemented.
124
- */
125
- verifyMessage(message: string | BytesLike, signature: string | Signature): Promise<boolean>;
126
- /**
127
- * Verify a string signature. This method is not implemented and should be overridden by subclasses.
128
- *
129
- * @param _0 - The original message.
130
- * @param _1 - The signature to verify.
131
- * @returns A promise that resolves to the verification result.
132
- * @throws Will throw an error if not implemented.
133
- */
134
- verifyMessageRaw(_0: string | BytesLike, _1: string): Promise<boolean>;
135
- /**
136
- * Sends a transaction after signing it.
137
- *
138
- * @param tx - The transaction to send, represented as a TransactionLike object.
139
- * @returns A promise that resolves to the transaction hash as a Hex string.
140
- */
141
- sendTransaction(tx: TransactionLike): Promise<Hex>;
142
- /**
143
- * Signs a transaction.
144
- *
145
- * @param tx - The transaction to sign, represented as a TransactionLike object.
146
- * @returns A promise that resolves to the signed Transaction object.
147
- */
148
- signTransaction(tx: TransactionLike): Promise<Transaction>;
149
- /**
150
- * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
151
- *
152
- * @param _ - The transaction to prepare, represented as a TransactionLike object.
153
- * @returns A promise that resolves to the prepared Transaction object.
154
- * @throws Will throw an error if not implemented.
155
- */
156
- prepareTransaction(_: TransactionLike): Promise<Transaction>;
157
- /**
158
- * Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
159
- *
160
- * @param _ - The transaction to sign, represented as a TransactionLike object.
161
- * @returns A promise that resolves to the signed Transaction object.
162
- * @throws Will throw an error if not implemented.
163
- */
164
- signOnlyTransaction(_: TransactionLike): Promise<Transaction>;
34
+ protected client_: Client;
35
+ constructor(client_: Client);
36
+ abstract get type(): SignerType;
37
+ abstract get signType(): SignerSignType;
38
+ get client(): Client;
39
+ static verifyMessage(
40
+ message: string | BytesLike,
41
+ signature: Signature,
42
+ ): Promise<boolean>;
43
+ /**
44
+ * Replace the current client.
45
+ * returns false if the new client is invalid for this signer.
46
+ */
47
+ replaceClient(client: Client): Promise<boolean>;
48
+ /**
49
+ * Connects to the signer.
50
+ *
51
+ * @returns A promise that resolves when the connection is complete.
52
+ */
53
+ abstract connect(): Promise<void>;
54
+ /**
55
+ * Check if the signer is connected.
56
+ *
57
+ * @returns A promise that resolves the connection status.
58
+ */
59
+ abstract isConnected(): Promise<boolean>;
60
+ /**
61
+ * Gets the internal address associated with the signer.
62
+ *
63
+ * @returns A promise that resolves to a string representing the internal address.
64
+ */
65
+ abstract getInternalAddress(): Promise<string>;
66
+ /**
67
+ * Gets the identity for verifying signature, usually it's address
68
+ *
69
+ * @returns A promise that resolves to a string representing the identity
70
+ */
71
+ getIdentity(): Promise<string>;
72
+ /**
73
+ * Gets an array of Address objects associated with the signer.
74
+ *
75
+ * @returns A promise that resolves to an array of Address objects.
76
+ */
77
+ abstract getAddressObjs(): Promise<Address[]>;
78
+ /**
79
+ * Gets the recommended Address object for the signer.
80
+ *
81
+ * @param _preference - Optional preference parameter.
82
+ * @returns A promise that resolves to the recommended Address object.
83
+ */
84
+ getRecommendedAddressObj(_preference?: unknown): Promise<Address>;
85
+ /**
86
+ * Gets the recommended address for the signer as a string.
87
+ *
88
+ * @param preference - Optional preference parameter.
89
+ * @returns A promise that resolves to the recommended address as a string.
90
+ */
91
+ getRecommendedAddress(preference?: unknown): Promise<string>;
92
+ /**
93
+ * Gets an array of addresses associated with the signer as strings.
94
+ *
95
+ * @returns A promise that resolves to an array of addresses as strings.
96
+ */
97
+ getAddresses(): Promise<string[]>;
98
+ /**
99
+ * Gets balance of all addresses
100
+ *
101
+ * @returns A promise that resolves to the balance
102
+ */
103
+ getBalance(): Promise<Num>;
104
+ /**
105
+ * Signs a message.
106
+ *
107
+ * @param _ - The message to sign, as a string or BytesLike object.
108
+ * @returns A promise that resolves to the signature info.
109
+ * @throws Will throw an error if not implemented.
110
+ */
111
+ signMessage(message: string | BytesLike): Promise<Signature>;
112
+ /**
113
+ * Signs a message and returns signature only. This method is not implemented and should be overridden by subclasses.
114
+ *
115
+ * @param _ - The message to sign, as a string or BytesLike object.
116
+ * @returns A promise that resolves to the signature as a string.
117
+ * @throws Will throw an error if not implemented.
118
+ */
119
+ signMessageRaw(_: string | BytesLike): Promise<string>;
120
+ /**
121
+ * Verify a signature.
122
+ *
123
+ * @param _ - The original message.
124
+ * @param _ - The signature to verify.
125
+ * @returns A promise that resolves to the verification result.
126
+ * @throws Will throw an error if not implemented.
127
+ */
128
+ verifyMessage(
129
+ message: string | BytesLike,
130
+ signature: string | Signature,
131
+ ): Promise<boolean>;
132
+ /**
133
+ * Verify a string signature. This method is not implemented and should be overridden by subclasses.
134
+ *
135
+ * @param _0 - The original message.
136
+ * @param _1 - The signature to verify.
137
+ * @returns A promise that resolves to the verification result.
138
+ * @throws Will throw an error if not implemented.
139
+ */
140
+ verifyMessageRaw(_0: string | BytesLike, _1: string): Promise<boolean>;
141
+ /**
142
+ * Sends a transaction after signing it.
143
+ *
144
+ * @param tx - The transaction to send, represented as a TransactionLike object.
145
+ * @returns A promise that resolves to the transaction hash as a Hex string.
146
+ */
147
+ sendTransaction(tx: TransactionLike): Promise<Hex>;
148
+ /**
149
+ * Signs a transaction.
150
+ *
151
+ * @param tx - The transaction to sign, represented as a TransactionLike object.
152
+ * @returns A promise that resolves to the signed Transaction object.
153
+ */
154
+ signTransaction(tx: TransactionLike): Promise<Transaction>;
155
+ /**
156
+ * prepare a transaction before signing. This method is not implemented and should be overridden by subclasses.
157
+ *
158
+ * @param _ - The transaction to prepare, represented as a TransactionLike object.
159
+ * @returns A promise that resolves to the prepared Transaction object.
160
+ * @throws Will throw an error if not implemented.
161
+ */
162
+ prepareTransaction(_: TransactionLike): Promise<Transaction>;
163
+ /**
164
+ * Signs a transaction without preparing information for it. This method is not implemented and should be overridden by subclasses.
165
+ *
166
+ * @param _ - The transaction to sign, represented as a TransactionLike object.
167
+ * @returns A promise that resolves to the signed Transaction object.
168
+ * @throws Will throw an error if not implemented.
169
+ */
170
+ signOnlyTransaction(_: TransactionLike): Promise<Transaction>;
165
171
  }
166
172
  /**
167
173
  * A class representing information about a signer, including its type and the signer instance.
168
174
  */
169
175
  export declare class SignerInfo {
170
- name: string;
171
- signer: Signer;
172
- constructor(name: string, signer: Signer);
176
+ name: string;
177
+ signer: Signer;
178
+ constructor(name: string, signer: Signer);
173
179
  }
174
180
  /**
175
181
  * Represents a wallet with a name, icon, and an array of signer information.
176
182
  */
177
183
  export type Wallet = {
178
- name: string;
179
- icon: string;
184
+ name: string;
185
+ icon: string;
180
186
  };
181
- //# sourceMappingURL=index.d.ts.map
187
+ //# sourceMappingURL=index.d.ts.map