@ckb-ccc/core 0.0.8-alpha.3 → 0.0.9-alpha.0

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