@ckb-ccc/core 1.9.1 → 1.11.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 (99) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/ckb/hash.d.ts +18 -0
  3. package/dist/ckb/hash.d.ts.map +1 -0
  4. package/dist/ckb/hash.js +19 -0
  5. package/dist/ckb/index.d.ts +2 -0
  6. package/dist/ckb/index.d.ts.map +1 -1
  7. package/dist/ckb/index.js +2 -0
  8. package/dist/ckb/script.d.ts +12 -0
  9. package/dist/ckb/script.d.ts.map +1 -1
  10. package/dist/ckb/script.js +17 -0
  11. package/dist/ckb/transaction.d.ts +326 -25
  12. package/dist/ckb/transaction.d.ts.map +1 -1
  13. package/dist/ckb/transaction.js +354 -79
  14. package/dist/ckb/transactionErrors.d.ts +15 -0
  15. package/dist/ckb/transactionErrors.d.ts.map +1 -0
  16. package/dist/ckb/transactionErrors.js +21 -0
  17. package/dist/client/cache/cache.d.ts +7 -0
  18. package/dist/client/cache/cache.d.ts.map +1 -1
  19. package/dist/client/cache/cache.js +11 -0
  20. package/dist/client/cache/memory.advanced.d.ts +36 -3
  21. package/dist/client/cache/memory.advanced.d.ts.map +1 -1
  22. package/dist/client/cache/memory.advanced.js +53 -25
  23. package/dist/client/cache/memory.d.ts +10 -1
  24. package/dist/client/cache/memory.d.ts.map +1 -1
  25. package/dist/client/cache/memory.js +13 -2
  26. package/dist/client/client.d.ts.map +1 -1
  27. package/dist/client/client.js +6 -9
  28. package/dist/client/clientTypes.advanced.d.ts +0 -1
  29. package/dist/client/clientTypes.advanced.d.ts.map +1 -1
  30. package/dist/client/clientTypes.advanced.js +0 -1
  31. package/dist/hasher/hasherCkb.d.ts +0 -16
  32. package/dist/hasher/hasherCkb.d.ts.map +1 -1
  33. package/dist/hasher/hasherCkb.js +0 -18
  34. package/dist/molecule/codec.d.ts +30 -10
  35. package/dist/molecule/codec.d.ts.map +1 -1
  36. package/dist/molecule/codec.js +46 -13
  37. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +18 -6
  38. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  39. package/dist/signer/ckb/signerCkbScriptReadonly.js +18 -6
  40. package/dist/signer/signer/index.d.ts +11 -1
  41. package/dist/signer/signer/index.d.ts.map +1 -1
  42. package/dist/signer/signer/index.js +23 -0
  43. package/dist.commonjs/ckb/hash.d.ts +18 -0
  44. package/dist.commonjs/ckb/hash.d.ts.map +1 -0
  45. package/dist.commonjs/ckb/hash.js +22 -0
  46. package/dist.commonjs/ckb/index.d.ts +2 -0
  47. package/dist.commonjs/ckb/index.d.ts.map +1 -1
  48. package/dist.commonjs/ckb/index.js +2 -0
  49. package/dist.commonjs/ckb/script.d.ts +12 -0
  50. package/dist.commonjs/ckb/script.d.ts.map +1 -1
  51. package/dist.commonjs/ckb/script.js +17 -0
  52. package/dist.commonjs/ckb/transaction.d.ts +326 -25
  53. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  54. package/dist.commonjs/ckb/transaction.js +353 -78
  55. package/dist.commonjs/ckb/transactionErrors.d.ts +15 -0
  56. package/dist.commonjs/ckb/transactionErrors.d.ts.map +1 -0
  57. package/dist.commonjs/ckb/transactionErrors.js +26 -0
  58. package/dist.commonjs/client/cache/cache.d.ts +7 -0
  59. package/dist.commonjs/client/cache/cache.d.ts.map +1 -1
  60. package/dist.commonjs/client/cache/cache.js +11 -0
  61. package/dist.commonjs/client/cache/memory.advanced.d.ts +36 -3
  62. package/dist.commonjs/client/cache/memory.advanced.d.ts.map +1 -1
  63. package/dist.commonjs/client/cache/memory.advanced.js +54 -26
  64. package/dist.commonjs/client/cache/memory.d.ts +10 -1
  65. package/dist.commonjs/client/cache/memory.d.ts.map +1 -1
  66. package/dist.commonjs/client/cache/memory.js +12 -1
  67. package/dist.commonjs/client/client.d.ts.map +1 -1
  68. package/dist.commonjs/client/client.js +5 -8
  69. package/dist.commonjs/client/clientTypes.advanced.d.ts +0 -1
  70. package/dist.commonjs/client/clientTypes.advanced.d.ts.map +1 -1
  71. package/dist.commonjs/client/clientTypes.advanced.js +1 -2
  72. package/dist.commonjs/hasher/hasherCkb.d.ts +0 -16
  73. package/dist.commonjs/hasher/hasherCkb.d.ts.map +1 -1
  74. package/dist.commonjs/hasher/hasherCkb.js +2 -21
  75. package/dist.commonjs/molecule/codec.d.ts +30 -10
  76. package/dist.commonjs/molecule/codec.d.ts.map +1 -1
  77. package/dist.commonjs/molecule/codec.js +46 -13
  78. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts +18 -6
  79. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  80. package/dist.commonjs/signer/ckb/signerCkbScriptReadonly.js +18 -6
  81. package/dist.commonjs/signer/signer/index.d.ts +11 -1
  82. package/dist.commonjs/signer/signer/index.d.ts.map +1 -1
  83. package/dist.commonjs/signer/signer/index.js +23 -0
  84. package/package.json +1 -1
  85. package/prettier.config.mjs +1 -1
  86. package/src/ckb/hash.ts +28 -0
  87. package/src/ckb/index.ts +2 -0
  88. package/src/ckb/script.ts +20 -0
  89. package/src/ckb/transaction.ts +436 -80
  90. package/src/ckb/transactionErrors.ts +36 -0
  91. package/src/client/cache/cache.ts +14 -1
  92. package/src/client/cache/memory.advanced.ts +57 -30
  93. package/src/client/cache/memory.ts +18 -1
  94. package/src/client/client.ts +5 -10
  95. package/src/client/clientTypes.advanced.ts +0 -1
  96. package/src/hasher/hasherCkb.ts +0 -26
  97. package/src/molecule/codec.ts +50 -13
  98. package/src/signer/ckb/signerCkbScriptReadonly.ts +24 -8
  99. package/src/signer/signer/index.ts +34 -0
@@ -307,28 +307,61 @@ function table(codecLayout) {
307
307
  });
308
308
  }
309
309
  /**
310
- * Union is a dynamic-size type.
311
- * Serializing a union has two steps:
312
- * - Serialize an item type id in bytes as a 32 bit unsigned integer in little-endian. The item type id is the index of the inner items, and it's starting at 0.
313
- * - Serialize the inner item.
314
- * @param codecLayout the union item record
315
- * @param fields the custom item type id record
310
+ * Constructs a union codec that can serialize and deserialize values tagged with a type identifier.
311
+ *
312
+ * If all variants have the same fixed size, the resulting union codec is fixed-size (header + payload).
313
+ * Otherwise, it falls back to a dynamic-size codec.
314
+ *
315
+ * Serialization format:
316
+ * 1. 4-byte little-endian unsigned integer for the variant index.
317
+ * 2. Encoded bytes of the selected variant.
318
+ *
319
+ * @typeParam T
320
+ * A record mapping variant names to codecs.
321
+ * @param codecLayout
322
+ * An object whose keys are variant names and values are codecs for each variant.
323
+ * @param fields
324
+ * Optional mapping from variant names to custom numeric IDs. If omitted, the index
325
+ * of each variant in `codecLayout` is used as its ID.
326
+ *
327
+ *
316
328
  * @example
317
- * // without custom id
318
- * union({ cafe: Uint8, bee: Uint8 })
319
- * // with custom id
320
- * union({ cafe: Uint8, bee: Uint8 }, { cafe: 0xcafe, bee: 0xbee })
329
+ * // Dynamic union without custom numeric IDs
330
+ * union({ cafe: Uint8, bee: Uint16 })
331
+ *
332
+ * // Dynamic union with custom numeric IDs
333
+ * union({ cafe: Uint8, bee: Uint16 }, { cafe: 0xcafe, bee: 0xbee })
334
+ *
335
+ * // Fixed-size union without custom numeric IDs
336
+ * const PaddedUint8 = struct({ data : u8, padding : u8 })
337
+ * union({ cafe: PaddedUint8, bee: Uint16 });
338
+ *
339
+ * // Fixed-size union with custom numeric IDs
340
+ * union({ cafe: PaddedUint8, bee: Uint16 }, { cafe: 0xcafe, bee: 0xbee })
321
341
  */
322
342
  function union(codecLayout, fields) {
323
- const keys = Object.keys(codecLayout);
343
+ const entries = Object.entries(codecLayout);
344
+ // Determine if all variants have a fixed and equal byteLength.
345
+ let byteLength;
346
+ if (entries.length > 0) {
347
+ const firstLen = entries[0][1].byteLength;
348
+ if (firstLen !== undefined &&
349
+ entries.every(([, { byteLength: len }]) => len === firstLen)) {
350
+ // Add 4 bytes for the type header
351
+ byteLength = firstLen + 4;
352
+ }
353
+ }
324
354
  return Codec.from({
355
+ byteLength,
325
356
  encode({ type, value }) {
326
357
  const typeStr = type.toString();
327
358
  const codec = codecLayout[typeStr];
328
359
  if (!codec) {
329
- throw new Error(`union: invalid type, expected ${keys.toString()}, but got ${typeStr}`);
360
+ throw new Error(`union: invalid type, expected ${entries.map((e) => e[0]).toString()}, but got ${typeStr}`);
330
361
  }
331
- const fieldId = fields ? (fields[typeStr] ?? -1) : keys.indexOf(typeStr);
362
+ const fieldId = fields
363
+ ? (fields[typeStr] ?? -1)
364
+ : entries.findIndex((e) => e[0] === typeStr);
332
365
  if (fieldId < 0) {
333
366
  throw new Error(`union: invalid field id ${fieldId} of ${typeStr}`);
334
367
  }
@@ -1,23 +1,35 @@
1
1
  import { Address } from "../../address/index.js";
2
- import { ScriptLike } from "../../ckb/index.js";
2
+ import { Script, ScriptLike } from "../../ckb/index.js";
3
3
  import { Client } from "../../client/index.js";
4
4
  import { Signer, SignerSignType, SignerType } from "../signer/index.js";
5
5
  /**
6
- * A class extending Signer that provides read-only access to a CKB script.
7
- * This class does not support signing operations.
6
+ * A read-only signer for a CKB script. It can be used to get addresses,
7
+ * but not to sign transactions. This is useful when you want to watch an address
8
+ * without having the private key.
9
+ *
8
10
  * @public
9
11
  */
10
12
  export declare class SignerCkbScriptReadonly extends Signer {
13
+ /**
14
+ * The type of the signer.
15
+ */
11
16
  get type(): SignerType;
17
+ /**
18
+ * The sign type of the signer.
19
+ * As this is a read-only signer, the sign type is {@link SignerSignType.Unknown}.
20
+ */
12
21
  get signType(): SignerSignType;
13
- private readonly script;
22
+ /**
23
+ * The scripts associated with the signer.
24
+ */
25
+ readonly scripts: Script[];
14
26
  /**
15
27
  * Creates an instance of SignerCkbScriptReadonly.
16
28
  *
17
29
  * @param client - The client instance used for communication.
18
- * @param script - The script associated with the signer.
30
+ * @param scripts - The scripts associated with the signer. Can be a single script, an array of scripts, or multiple script arguments.
19
31
  */
20
- constructor(client: Client, script: ScriptLike);
32
+ constructor(client: Client, ...scripts: (ScriptLike | ScriptLike[])[]);
21
33
  /**
22
34
  * Connects to the client. This implementation does nothing as the class is read-only.
23
35
  *
@@ -1 +1 @@
1
- {"version":3,"file":"signerCkbScriptReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/signerCkbScriptReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAU,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAExE;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,MAAM;IACjD,IAAI,IAAI,IAAI,UAAU,CAErB;IAED,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAM9C;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;;;;;;OASG;IAEG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAG3C"}
1
+ {"version":3,"file":"signerCkbScriptReadonly.d.ts","sourceRoot":"","sources":["../../../src/signer/ckb/signerCkbScriptReadonly.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAExE;;;;;;GAMG;AACH,qBAAa,uBAAwB,SAAQ,MAAM;IACjD;;OAEG;IACH,IAAI,IAAI,IAAI,UAAU,CAErB;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,cAAc,CAE7B;IAED;;OAEG;IACH,SAAgB,OAAO,EAAE,MAAM,EAAE,CAAC;IAElC;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,UAAU,GAAG,UAAU,EAAE,CAAC,EAAE;IASrE;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAIrC;;;;;;;;;OASG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3C;;;;;;;;;OASG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;CAK3C"}
@@ -5,14 +5,23 @@ const index_js_1 = require("../../address/index.js");
5
5
  const index_js_2 = require("../../ckb/index.js");
6
6
  const index_js_3 = require("../signer/index.js");
7
7
  /**
8
- * A class extending Signer that provides read-only access to a CKB script.
9
- * This class does not support signing operations.
8
+ * A read-only signer for a CKB script. It can be used to get addresses,
9
+ * but not to sign transactions. This is useful when you want to watch an address
10
+ * without having the private key.
11
+ *
10
12
  * @public
11
13
  */
12
14
  class SignerCkbScriptReadonly extends index_js_3.Signer {
15
+ /**
16
+ * The type of the signer.
17
+ */
13
18
  get type() {
14
19
  return index_js_3.SignerType.CKB;
15
20
  }
21
+ /**
22
+ * The sign type of the signer.
23
+ * As this is a read-only signer, the sign type is {@link SignerSignType.Unknown}.
24
+ */
16
25
  get signType() {
17
26
  return index_js_3.SignerSignType.Unknown;
18
27
  }
@@ -20,11 +29,14 @@ class SignerCkbScriptReadonly extends index_js_3.Signer {
20
29
  * Creates an instance of SignerCkbScriptReadonly.
21
30
  *
22
31
  * @param client - The client instance used for communication.
23
- * @param script - The script associated with the signer.
32
+ * @param scripts - The scripts associated with the signer. Can be a single script, an array of scripts, or multiple script arguments.
24
33
  */
25
- constructor(client, script) {
34
+ constructor(client, ...scripts) {
26
35
  super(client);
27
- this.script = index_js_2.Script.from(script);
36
+ this.scripts = scripts.flat().map(index_js_2.Script.from);
37
+ if (this.scripts.length === 0) {
38
+ throw new Error("SignerCkbScriptReadonly requires at least one script.");
39
+ }
28
40
  }
29
41
  /**
30
42
  * Connects to the client. This implementation does nothing as the class is read-only.
@@ -64,7 +76,7 @@ class SignerCkbScriptReadonly extends index_js_3.Signer {
64
76
  * ```
65
77
  */
66
78
  async getAddressObjs() {
67
- return [index_js_1.Address.fromScript(this.script, this.client)];
79
+ return this.scripts.map((script) => index_js_1.Address.fromScript(script, this.client));
68
80
  }
69
81
  }
70
82
  exports.SignerCkbScriptReadonly = SignerCkbScriptReadonly;
@@ -2,7 +2,7 @@ import { Address } from "../../address/index.js";
2
2
  import { ClientCollectableSearchKeyFilterLike } from "../../advancedBarrel.js";
3
3
  import { BytesLike } from "../../bytes/index.js";
4
4
  import { Cell, Transaction, TransactionLike } from "../../ckb/index.js";
5
- import { Client, ClientFindTransactionsGroupedResponse, ClientFindTransactionsResponse } from "../../client/index.js";
5
+ import { Client, ClientFindTransactionsGroupedResponse, ClientFindTransactionsResponse, ClientIndexerSearchKeyFilterLike } from "../../client/index.js";
6
6
  import { Hex } from "../../hex/index.js";
7
7
  import { Num } from "../../num/index.js";
8
8
  /**
@@ -131,6 +131,16 @@ export declare abstract class Signer {
131
131
  * @returns A promise that resolves to an array of addresses as strings.
132
132
  */
133
133
  getAddresses(): Promise<string[]>;
134
+ /**
135
+ * Find cells of this signer
136
+ *
137
+ * @param filter - The filter for the search key.
138
+ * @param withData - Whether to include cell data in the response.
139
+ * @param order - The order of the returned cells, can be "asc" or "desc".
140
+ * @param limit - The maximum number of cells for every querying chunk.
141
+ * @returns A async generator that yields all matching cells
142
+ */
143
+ findCellsOnChain(filter: ClientIndexerSearchKeyFilterLike, withData?: boolean | null, order?: "asc" | "desc", limit?: number): AsyncGenerator<Cell>;
134
144
  /**
135
145
  * Find cells of this signer
136
146
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/signer/signer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,oCAAoC,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EACL,MAAM,EACN,qCAAqC,EACrC,8BAA8B,EAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAQzC;;GAEG;AACH,oBAAY,cAAc;IACxB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;IAC3B,KAAK,UAAU;IACf,UAAU,eAAe;IACzB,YAAY,iBAAiB;IAC7B,SAAS,cAAc;CACxB;AAED;;;GAGG;AACH,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,KAAK,UAAU;IACf,IAAI,SAAS;CACd;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;IACvB;;;;;;;;;;OAUG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS;IAEX,SAAS,EAAE,MAAM;IACjB,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,cAAc;gBAFxB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,cAAc;CAElC;AAED;;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I,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;CAExB;AAED;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -134,6 +134,29 @@ class Signer {
134
134
  async getAddresses() {
135
135
  return this.getAddressObjs().then((addresses) => addresses.map((address) => address.toString()));
136
136
  }
137
+ /**
138
+ * Find cells of this signer
139
+ *
140
+ * @param filter - The filter for the search key.
141
+ * @param withData - Whether to include cell data in the response.
142
+ * @param order - The order of the returned cells, can be "asc" or "desc".
143
+ * @param limit - The maximum number of cells for every querying chunk.
144
+ * @returns A async generator that yields all matching cells
145
+ */
146
+ async *findCellsOnChain(filter, withData, order, limit) {
147
+ const scripts = await this.getAddressObjs();
148
+ for (const { script } of scripts) {
149
+ for await (const cell of this.client.findCellsOnChain({
150
+ script,
151
+ scriptType: "lock",
152
+ filter,
153
+ scriptSearchMode: "exact",
154
+ withData,
155
+ }, order, limit)) {
156
+ yield cell;
157
+ }
158
+ }
159
+ }
137
160
  /**
138
161
  * Find cells of this signer
139
162
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckb-ccc/core",
3
- "version": "1.9.1",
3
+ "version": "1.11.0",
4
4
  "description": "Core of CCC - CKBer's Codebase",
5
5
  "author": "Hanssen0 <hanssen0@hanssen0.com>",
6
6
  "license": "MIT",
@@ -7,7 +7,7 @@
7
7
  const config = {
8
8
  singleQuote: false,
9
9
  trailingComma: "all",
10
- plugins: [import.meta.resolve("prettier-plugin-organize-imports")],
10
+ plugins: ["prettier-plugin-organize-imports"],
11
11
  };
12
12
 
13
13
  export default config;
@@ -0,0 +1,28 @@
1
+ import { hashCkb } from "../hasher/hasherCkb.js";
2
+ import { Hex } from "../hex/index.js";
3
+ import { NumLike, numLeToBytes } from "../num/index.js";
4
+ import { CellInput, CellInputLike } from "./transaction.js";
5
+
6
+ /**
7
+ * Computes the Type ID hash of the given data.
8
+ * @public
9
+ *
10
+ * @param cellInputLike - The first cell input of the transaction.
11
+ * @param outputIndex - The output index of the Type ID cell.
12
+ * @returns The hexadecimal string representation of the hash.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const hash = hashTypeId(cellInput, outputIndex); // Outputs something like "0x..."
17
+ * ```
18
+ */
19
+
20
+ export function hashTypeId(
21
+ cellInputLike: CellInputLike,
22
+ outputIndex: NumLike,
23
+ ): Hex {
24
+ return hashCkb(
25
+ CellInput.from(cellInputLike).toBytes(),
26
+ numLeToBytes(outputIndex, 8),
27
+ );
28
+ }
package/src/ckb/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export * from "./hash.js";
1
2
  export * from "./script.js";
2
3
  export * from "./transaction.js";
4
+ export * from "./transactionErrors.js";
3
5
  export * from "./transactionLumos.js";
package/src/ckb/script.ts CHANGED
@@ -149,6 +149,26 @@ export class Script extends mol.Entity.Base<ScriptLike, Script>() {
149
149
  return new Script(this.codeHash, this.hashType, this.args);
150
150
  }
151
151
 
152
+ /**
153
+ * Check if the script is equal to another script.
154
+ * @public
155
+ * @param other - The other script to compare with
156
+ * @returns True if the scripts are equal, false otherwise
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const isEqual = script0.eq(script1);
161
+ * ```
162
+ */
163
+ eq(other: ScriptLike): boolean {
164
+ other = Script.from(other);
165
+ return (
166
+ this.args === other.args &&
167
+ this.codeHash === other.codeHash &&
168
+ this.hashType === other.hashType
169
+ );
170
+ }
171
+
152
172
  /**
153
173
  * Creates a Script instance from a ScriptLike object.
154
174
  *