@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
package/README.md CHANGED
@@ -21,11 +21,13 @@
21
21
  </p>
22
22
 
23
23
  <p align="center">
24
- "Common Chains Connector" is where CCC begins.
24
+ "CCC - CKBers' Codebase" is the next step of "Common Chains Connector".
25
25
  <br />
26
- CCC helps you to interoperate wallets from different chain ecosystems with CKB,
26
+ Empower yourself with CCC to discover the unlimited potential of CKB.
27
27
  <br />
28
- fully enabling CKB's cryptographic freedom power.
28
+ Interoperate with wallets from different chain ecosystems.
29
+ <br />
30
+ Fully enabling CKB's Turing completeness and cryptographic freedom power.
29
31
  </p>
30
32
 
31
33
  ## Preview
@@ -36,7 +38,7 @@
36
38
  </a>
37
39
  </p>
38
40
 
39
- This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/).
41
+ This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/). It showcases how to use CCC for some basic scenarios in CKB.
40
42
 
41
43
  <h3 align="center">
42
44
  Read more about CCC on its <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
@@ -17,9 +17,9 @@ import { type AddressLike } from "./index";
17
17
  * ```
18
18
  */
19
19
  export declare function addressPayloadFromString(address: string): {
20
- prefix: string;
21
- format: AddressFormat;
22
- payload: number[];
20
+ prefix: string;
21
+ format: AddressFormat;
22
+ payload: number[];
23
23
  };
24
24
  /**
25
25
  * Converts an address payload into an address-like object.
@@ -39,27 +39,32 @@ export declare function addressPayloadFromString(address: string): {
39
39
  * console.log(address.prefix); // Outputs the address prefix
40
40
  * ```
41
41
  */
42
- export declare function addressFromPayload(prefix: string, format: AddressFormat, payload: number[], client: Client): Promise<AddressLike>;
42
+ export declare function addressFromPayload(
43
+ prefix: string,
44
+ format: AddressFormat,
45
+ payload: number[],
46
+ client: Client,
47
+ ): Promise<AddressLike>;
43
48
  export declare enum AddressFormat {
44
- /**
45
- * full version identifies the hashType
46
- */
47
- Full = 0,
48
- /**
49
- * @deprecated
50
- * short version for locks with Known codeHash, deprecated
51
- */
52
- Short = 1,
53
- /**
54
- * @deprecated
55
- * full version with hashType = "Data", deprecated
56
- */
57
- FullData = 2,
58
- /**
59
- * @deprecated
60
- * full version with hashType = "Type", deprecated
61
- */
62
- FullType = 4
49
+ /**
50
+ * full version identifies the hashType
51
+ */
52
+ Full = 0,
53
+ /**
54
+ * @deprecated
55
+ * short version for locks with Known codeHash, deprecated
56
+ */
57
+ Short = 1,
58
+ /**
59
+ * @deprecated
60
+ * full version with hashType = "Data", deprecated
61
+ */
62
+ FullData = 2,
63
+ /**
64
+ * @deprecated
65
+ * full version with hashType = "Type", deprecated
66
+ */
67
+ FullType = 4,
63
68
  }
64
69
  export declare const ADDRESS_BECH32_LIMIT = 1023;
65
- //# sourceMappingURL=address.advanced.d.ts.map
70
+ //# sourceMappingURL=address.advanced.d.ts.map
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ADDRESS_BECH32_LIMIT = exports.AddressFormat = exports.addressFromPayload = exports.addressPayloadFromString = void 0;
3
+ exports.ADDRESS_BECH32_LIMIT =
4
+ exports.AddressFormat =
5
+ exports.addressFromPayload =
6
+ exports.addressPayloadFromString =
7
+ void 0;
4
8
  const bech32_1 = require("bech32");
5
9
  const ckb_1 = require("../ckb");
6
10
  const client_1 = require("../client");
@@ -22,27 +26,35 @@ const hex_1 = require("../hex");
22
26
  * ```
23
27
  */
24
28
  function addressPayloadFromString(address) {
25
- // Try parse full format address
26
- {
27
- const { words, prefix } = bech32_1.bech32m.decode(address, exports.ADDRESS_BECH32_LIMIT);
28
- const [formatType, ...payload] = bech32_1.bech32m.fromWords(words);
29
- if (formatType === AddressFormat.Full) {
30
- return { prefix, format: AddressFormat.Full, payload };
31
- }
29
+ // Try parse full format address
30
+ {
31
+ const { words, prefix } = bech32_1.bech32m.decode(
32
+ address,
33
+ exports.ADDRESS_BECH32_LIMIT,
34
+ );
35
+ const [formatType, ...payload] = bech32_1.bech32m.fromWords(words);
36
+ if (formatType === AddressFormat.Full) {
37
+ return { prefix, format: AddressFormat.Full, payload };
32
38
  }
33
- // Try parse legacy 2019 format address
34
- {
35
- const { prefix, words } = bech32_1.bech32.decode(address, exports.ADDRESS_BECH32_LIMIT);
36
- const [formatType, ...payload] = bech32_1.bech32.fromWords(words);
37
- if ([
38
- AddressFormat.FullData,
39
- AddressFormat.FullType,
40
- AddressFormat.Short,
41
- ].includes(formatType)) {
42
- return { prefix, format: formatType, payload };
43
- }
39
+ }
40
+ // Try parse legacy 2019 format address
41
+ {
42
+ const { prefix, words } = bech32_1.bech32.decode(
43
+ address,
44
+ exports.ADDRESS_BECH32_LIMIT,
45
+ );
46
+ const [formatType, ...payload] = bech32_1.bech32.fromWords(words);
47
+ if (
48
+ [
49
+ AddressFormat.FullData,
50
+ AddressFormat.FullType,
51
+ AddressFormat.Short,
52
+ ].includes(formatType)
53
+ ) {
54
+ return { prefix, format: formatType, payload };
44
55
  }
45
- throw Error(`Unknown address format ${address}`);
56
+ }
57
+ throw Error(`Unknown address format ${address}`);
46
58
  }
47
59
  exports.addressPayloadFromString = addressPayloadFromString;
48
60
  /**
@@ -64,83 +76,97 @@ exports.addressPayloadFromString = addressPayloadFromString;
64
76
  * ```
65
77
  */
66
78
  async function addressFromPayload(prefix, format, payload, client) {
67
- if (format === AddressFormat.Full) {
68
- if (payload.length < 32 + 1) {
69
- throw new Error(`Invalid full address without enough payload ${(0, hex_1.hexFrom)(payload)}`);
70
- }
71
- return {
72
- script: {
73
- codeHash: payload.slice(0, 32),
74
- hashType: (0, ckb_1.hashTypeFromBytes)(payload.slice(32, 33)),
75
- args: payload.slice(33),
76
- },
77
- prefix,
78
- };
79
+ if (format === AddressFormat.Full) {
80
+ if (payload.length < 32 + 1) {
81
+ throw new Error(
82
+ `Invalid full address without enough payload ${(0, hex_1.hexFrom)(payload)}`,
83
+ );
79
84
  }
80
- if (format === AddressFormat.FullData) {
81
- if (payload.length < 32) {
82
- throw new Error(`Invalid full data address without enough payload ${(0, hex_1.hexFrom)(payload)}`);
83
- }
84
- return {
85
- script: {
86
- codeHash: payload.slice(0, 32),
87
- hashType: "data",
88
- args: payload.slice(32),
89
- },
90
- prefix,
91
- };
92
- }
93
- if (format === AddressFormat.FullType) {
94
- if (payload.length < 32) {
95
- throw new Error(`Invalid full type address without enough payload ${(0, hex_1.hexFrom)(payload)}`);
96
- }
97
- return {
98
- script: {
99
- codeHash: payload.slice(0, 32),
100
- hashType: "type",
101
- args: payload.slice(32),
102
- },
103
- prefix,
104
- };
105
- }
106
- // format === AddressFormat.Short
107
- if (payload.length !== 21) {
108
- throw new Error(`Invalid short address without enough payload ${(0, hex_1.hexFrom)(payload)}`);
85
+ return {
86
+ script: {
87
+ codeHash: payload.slice(0, 32),
88
+ hashType: (0, ckb_1.hashTypeFromBytes)(payload.slice(32, 33)),
89
+ args: payload.slice(33),
90
+ },
91
+ prefix,
92
+ };
93
+ }
94
+ if (format === AddressFormat.FullData) {
95
+ if (payload.length < 32) {
96
+ throw new Error(
97
+ `Invalid full data address without enough payload ${(0, hex_1.hexFrom)(payload)}`,
98
+ );
109
99
  }
110
- const script = [
111
- client_1.KnownScript.Secp256k1Blake160,
112
- client_1.KnownScript.Secp256k1Multisig,
113
- client_1.KnownScript.AnyoneCanPay,
114
- ][payload[0]];
115
- if (script === undefined) {
116
- throw new Error(`Invalid short address with unknown script ${(0, hex_1.hexFrom)(payload)}`);
100
+ return {
101
+ script: {
102
+ codeHash: payload.slice(0, 32),
103
+ hashType: "data",
104
+ args: payload.slice(32),
105
+ },
106
+ prefix,
107
+ };
108
+ }
109
+ if (format === AddressFormat.FullType) {
110
+ if (payload.length < 32) {
111
+ throw new Error(
112
+ `Invalid full type address without enough payload ${(0, hex_1.hexFrom)(payload)}`,
113
+ );
117
114
  }
118
115
  return {
119
- script: await ckb_1.Script.fromKnownScript(client, script, payload.slice(1)),
120
- prefix,
116
+ script: {
117
+ codeHash: payload.slice(0, 32),
118
+ hashType: "type",
119
+ args: payload.slice(32),
120
+ },
121
+ prefix,
121
122
  };
123
+ }
124
+ // format === AddressFormat.Short
125
+ if (payload.length !== 21) {
126
+ throw new Error(
127
+ `Invalid short address without enough payload ${(0, hex_1.hexFrom)(payload)}`,
128
+ );
129
+ }
130
+ const script = [
131
+ client_1.KnownScript.Secp256k1Blake160,
132
+ client_1.KnownScript.Secp256k1Multisig,
133
+ client_1.KnownScript.AnyoneCanPay,
134
+ ][payload[0]];
135
+ if (script === undefined) {
136
+ throw new Error(
137
+ `Invalid short address with unknown script ${(0, hex_1.hexFrom)(payload)}`,
138
+ );
139
+ }
140
+ return {
141
+ script: await ckb_1.Script.fromKnownScript(
142
+ client,
143
+ script,
144
+ payload.slice(1),
145
+ ),
146
+ prefix,
147
+ };
122
148
  }
123
149
  exports.addressFromPayload = addressFromPayload;
124
150
  var AddressFormat;
125
151
  (function (AddressFormat) {
126
- /**
127
- * full version identifies the hashType
128
- */
129
- AddressFormat[AddressFormat["Full"] = 0] = "Full";
130
- /**
131
- * @deprecated
132
- * short version for locks with Known codeHash, deprecated
133
- */
134
- AddressFormat[AddressFormat["Short"] = 1] = "Short";
135
- /**
136
- * @deprecated
137
- * full version with hashType = "Data", deprecated
138
- */
139
- AddressFormat[AddressFormat["FullData"] = 2] = "FullData";
140
- /**
141
- * @deprecated
142
- * full version with hashType = "Type", deprecated
143
- */
144
- AddressFormat[AddressFormat["FullType"] = 4] = "FullType";
152
+ /**
153
+ * full version identifies the hashType
154
+ */
155
+ AddressFormat[(AddressFormat["Full"] = 0)] = "Full";
156
+ /**
157
+ * @deprecated
158
+ * short version for locks with Known codeHash, deprecated
159
+ */
160
+ AddressFormat[(AddressFormat["Short"] = 1)] = "Short";
161
+ /**
162
+ * @deprecated
163
+ * full version with hashType = "Data", deprecated
164
+ */
165
+ AddressFormat[(AddressFormat["FullData"] = 2)] = "FullData";
166
+ /**
167
+ * @deprecated
168
+ * full version with hashType = "Type", deprecated
169
+ */
170
+ AddressFormat[(AddressFormat["FullType"] = 4)] = "FullType";
145
171
  })(AddressFormat || (exports.AddressFormat = AddressFormat = {}));
146
172
  exports.ADDRESS_BECH32_LIMIT = 1023;
@@ -1,2 +1,2 @@
1
1
  export * from "./address.advanced";
2
- //# sourceMappingURL=advanced.d.ts.map
2
+ //# sourceMappingURL=advanced.d.ts.map
@@ -1,17 +1,33 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
2
+ var __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (
9
+ !desc ||
10
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
11
+ ) {
12
+ desc = {
13
+ enumerable: true,
14
+ get: function () {
15
+ return m[k];
16
+ },
17
+ };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }
21
+ : function (o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ });
25
+ var __exportStar =
26
+ (this && this.__exportStar) ||
27
+ function (m, exports) {
28
+ for (var p in m)
29
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
30
+ __createBinding(exports, m, p);
31
+ };
16
32
  Object.defineProperty(exports, "__esModule", { value: true });
17
33
  __exportStar(require("./address.advanced"), exports);
@@ -2,53 +2,60 @@ import { Script, ScriptLike } from "../ckb";
2
2
  import { Client, KnownScript } from "../client";
3
3
  import { HexLike } from "../hex";
4
4
  export type AddressLike = {
5
- script: ScriptLike;
6
- prefix: string;
5
+ script: ScriptLike;
6
+ prefix: string;
7
7
  };
8
8
  /**
9
9
  * Represents a ckb address with associated script and prefix.
10
10
  */
11
11
  export declare class Address {
12
- script: Script;
13
- prefix: string;
14
- /**
15
- * Creates an instance of Address.
16
- *
17
- * @param script - The script associated with the address.
18
- * @param prefix - The address prefix.
19
- */
20
- constructor(script: Script, prefix: string);
21
- /**
22
- * Creates an Address instance from an AddressLike object.
23
- *
24
- * @param address - An AddressLike object or an instance of Address.
25
- * @returns An Address instance.
26
- */
27
- static from(address: AddressLike): Address;
28
- /**
29
- * Creates an Address instance from an address string.
30
- *
31
- * @param address - The address string to parse.
32
- * @param clients - A Client instance or a record of Client instances keyed by prefix.
33
- * @returns A promise that resolves to an Address instance.
34
- *
35
- * @throws Will throw an error if the address prefix is unknown or mismatched.
36
- */
37
- static fromString(address: string, clients: Client | Record<string, Client>): Promise<Address>;
38
- /**
39
- * Creates an Address instance from a script and client.
40
- *
41
- * @param script - The script-like object.
42
- * @param client - The client instance used to fetch the address prefix.
43
- * @returns A promise that resolves to an Address instance.
44
- */
45
- static fromScript(script: ScriptLike, client: Client): Address;
46
- static fromKnownScript(client: Client, script: KnownScript, args: HexLike): Promise<Address>;
47
- /**
48
- * Converts the Address instance to a string.
49
- *
50
- * @returns The address as a string.
51
- */
52
- toString(): string;
12
+ script: Script;
13
+ prefix: string;
14
+ /**
15
+ * Creates an instance of Address.
16
+ *
17
+ * @param script - The script associated with the address.
18
+ * @param prefix - The address prefix.
19
+ */
20
+ constructor(script: Script, prefix: string);
21
+ /**
22
+ * Creates an Address instance from an AddressLike object.
23
+ *
24
+ * @param address - An AddressLike object or an instance of Address.
25
+ * @returns An Address instance.
26
+ */
27
+ static from(address: AddressLike): Address;
28
+ /**
29
+ * Creates an Address instance from an address string.
30
+ *
31
+ * @param address - The address string to parse.
32
+ * @param clients - A Client instance or a record of Client instances keyed by prefix.
33
+ * @returns A promise that resolves to an Address instance.
34
+ *
35
+ * @throws Will throw an error if the address prefix is unknown or mismatched.
36
+ */
37
+ static fromString(
38
+ address: string,
39
+ clients: Client | Record<string, Client>,
40
+ ): Promise<Address>;
41
+ /**
42
+ * Creates an Address instance from a script and client.
43
+ *
44
+ * @param script - The script-like object.
45
+ * @param client - The client instance used to fetch the address prefix.
46
+ * @returns A promise that resolves to an Address instance.
47
+ */
48
+ static fromScript(script: ScriptLike, client: Client): Address;
49
+ static fromKnownScript(
50
+ client: Client,
51
+ script: KnownScript,
52
+ args: HexLike,
53
+ ): Promise<Address>;
54
+ /**
55
+ * Converts the Address instance to a string.
56
+ *
57
+ * @returns The address as a string.
58
+ */
59
+ toString(): string;
53
60
  }
54
- //# sourceMappingURL=index.d.ts.map
61
+ //# sourceMappingURL=index.d.ts.map
@@ -9,73 +9,92 @@ const address_advanced_1 = require("./address.advanced");
9
9
  * Represents a ckb address with associated script and prefix.
10
10
  */
11
11
  class Address {
12
- /**
13
- * Creates an instance of Address.
14
- *
15
- * @param script - The script associated with the address.
16
- * @param prefix - The address prefix.
17
- */
18
- constructor(script, prefix) {
19
- this.script = script;
20
- this.prefix = prefix;
12
+ /**
13
+ * Creates an instance of Address.
14
+ *
15
+ * @param script - The script associated with the address.
16
+ * @param prefix - The address prefix.
17
+ */
18
+ constructor(script, prefix) {
19
+ this.script = script;
20
+ this.prefix = prefix;
21
+ }
22
+ /**
23
+ * Creates an Address instance from an AddressLike object.
24
+ *
25
+ * @param address - An AddressLike object or an instance of Address.
26
+ * @returns An Address instance.
27
+ */
28
+ static from(address) {
29
+ if (address instanceof Address) {
30
+ return address;
21
31
  }
22
- /**
23
- * Creates an Address instance from an AddressLike object.
24
- *
25
- * @param address - An AddressLike object or an instance of Address.
26
- * @returns An Address instance.
27
- */
28
- static from(address) {
29
- if (address instanceof Address) {
30
- return address;
31
- }
32
- return new Address(ckb_1.Script.from(address.script), address.prefix);
32
+ return new Address(ckb_1.Script.from(address.script), address.prefix);
33
+ }
34
+ /**
35
+ * Creates an Address instance from an address string.
36
+ *
37
+ * @param address - The address string to parse.
38
+ * @param clients - A Client instance or a record of Client instances keyed by prefix.
39
+ * @returns A promise that resolves to an Address instance.
40
+ *
41
+ * @throws Will throw an error if the address prefix is unknown or mismatched.
42
+ */
43
+ static async fromString(address, clients) {
44
+ const { prefix, format, payload } = (0,
45
+ address_advanced_1.addressPayloadFromString)(address);
46
+ const client = clients[prefix] ?? clients;
47
+ if (!client) {
48
+ throw new Error(`Unknown address prefix ${prefix}`);
33
49
  }
34
- /**
35
- * Creates an Address instance from an address string.
36
- *
37
- * @param address - The address string to parse.
38
- * @param clients - A Client instance or a record of Client instances keyed by prefix.
39
- * @returns A promise that resolves to an Address instance.
40
- *
41
- * @throws Will throw an error if the address prefix is unknown or mismatched.
42
- */
43
- static async fromString(address, clients) {
44
- const { prefix, format, payload } = (0, address_advanced_1.addressPayloadFromString)(address);
45
- const client = clients[prefix] ?? clients;
46
- if (!client) {
47
- throw new Error(`Unknown address prefix ${prefix}`);
48
- }
49
- const expectedPrefix = client.addressPrefix;
50
- if (expectedPrefix !== prefix) {
51
- throw new Error(`Unknown address prefix ${prefix}, expected ${expectedPrefix}`);
52
- }
53
- return Address.from(await (0, address_advanced_1.addressFromPayload)(prefix, format, payload, client));
54
- }
55
- /**
56
- * Creates an Address instance from a script and client.
57
- *
58
- * @param script - The script-like object.
59
- * @param client - The client instance used to fetch the address prefix.
60
- * @returns A promise that resolves to an Address instance.
61
- */
62
- static fromScript(script, client) {
63
- return Address.from({ script, prefix: client.addressPrefix });
64
- }
65
- static async fromKnownScript(client, script, args) {
66
- return Address.from({
67
- script: await ckb_1.Script.fromKnownScript(client, script, args),
68
- prefix: client.addressPrefix,
69
- });
70
- }
71
- /**
72
- * Converts the Address instance to a string.
73
- *
74
- * @returns The address as a string.
75
- */
76
- toString() {
77
- const data = (0, bytes_1.bytesConcat)([address_advanced_1.AddressFormat.Full], (0, bytes_1.bytesFrom)(this.script.codeHash), (0, ckb_1.hashTypeToBytes)(this.script.hashType), (0, bytes_1.bytesFrom)(this.script.args));
78
- return bech32_1.bech32m.encode(this.prefix, bech32_1.bech32m.toWords(data), address_advanced_1.ADDRESS_BECH32_LIMIT);
50
+ const expectedPrefix = client.addressPrefix;
51
+ if (expectedPrefix !== prefix) {
52
+ throw new Error(
53
+ `Unknown address prefix ${prefix}, expected ${expectedPrefix}`,
54
+ );
79
55
  }
56
+ return Address.from(
57
+ await (0, address_advanced_1.addressFromPayload)(
58
+ prefix,
59
+ format,
60
+ payload,
61
+ client,
62
+ ),
63
+ );
64
+ }
65
+ /**
66
+ * Creates an Address instance from a script and client.
67
+ *
68
+ * @param script - The script-like object.
69
+ * @param client - The client instance used to fetch the address prefix.
70
+ * @returns A promise that resolves to an Address instance.
71
+ */
72
+ static fromScript(script, client) {
73
+ return Address.from({ script, prefix: client.addressPrefix });
74
+ }
75
+ static async fromKnownScript(client, script, args) {
76
+ return Address.from({
77
+ script: await ckb_1.Script.fromKnownScript(client, script, args),
78
+ prefix: client.addressPrefix,
79
+ });
80
+ }
81
+ /**
82
+ * Converts the Address instance to a string.
83
+ *
84
+ * @returns The address as a string.
85
+ */
86
+ toString() {
87
+ const data = (0, bytes_1.bytesConcat)(
88
+ [address_advanced_1.AddressFormat.Full],
89
+ (0, bytes_1.bytesFrom)(this.script.codeHash),
90
+ (0, ckb_1.hashTypeToBytes)(this.script.hashType),
91
+ (0, bytes_1.bytesFrom)(this.script.args),
92
+ );
93
+ return bech32_1.bech32m.encode(
94
+ this.prefix,
95
+ bech32_1.bech32m.toWords(data),
96
+ address_advanced_1.ADDRESS_BECH32_LIMIT,
97
+ );
98
+ }
80
99
  }
81
100
  exports.Address = Address;
@@ -1,3 +1,3 @@
1
1
  export * from "./advancedBarrel";
2
2
  export * as cccA from "./advancedBarrel";
3
- //# sourceMappingURL=advanced.d.ts.map
3
+ //# sourceMappingURL=advanced.d.ts.map