@ckb-ccc/core 1.22.1 → 1.23.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 (49) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/advanced.d.mts +1 -1
  3. package/dist/advanced.mjs +1 -1
  4. package/dist/{advancedBarrel-Daj_LJkz.d.mts → advancedBarrel-BBbQZ2OW.d.mts} +480 -379
  5. package/dist/advancedBarrel-BBbQZ2OW.d.mts.map +1 -0
  6. package/dist/advancedBarrel.d.mts +1 -1
  7. package/dist/advancedBarrel.mjs +1 -1
  8. package/dist/barrel-Dz1WLXRX.mjs +7 -0
  9. package/dist/barrel-Dz1WLXRX.mjs.map +1 -0
  10. package/dist/barrel.d.mts +2 -2
  11. package/dist/barrel.mjs +1 -1
  12. package/dist/index.d.mts +2 -2
  13. package/dist/index.mjs +1 -1
  14. package/dist/transformers-BHt442Nd.mjs +2 -0
  15. package/dist/transformers-BHt442Nd.mjs.map +1 -0
  16. package/dist.commonjs/advanced.d.ts +1 -1
  17. package/dist.commonjs/advanced.js +1 -1
  18. package/dist.commonjs/{advancedBarrel-CJL3rfuW.d.ts → advancedBarrel-BS4zFcFI.d.ts} +480 -379
  19. package/dist.commonjs/advancedBarrel-BS4zFcFI.d.ts.map +1 -0
  20. package/dist.commonjs/advancedBarrel.d.ts +1 -1
  21. package/dist.commonjs/advancedBarrel.js +1 -1
  22. package/dist.commonjs/{barrel--PaV2IZx.js → barrel-CZYID7jh.js} +10 -10
  23. package/dist.commonjs/barrel-CZYID7jh.js.map +1 -0
  24. package/dist.commonjs/barrel.d.ts +2 -2
  25. package/dist.commonjs/barrel.js +1 -1
  26. package/dist.commonjs/index.d.ts +2 -2
  27. package/dist.commonjs/index.js +1 -1
  28. package/dist.commonjs/transformers-CYUULrnt.js +2 -0
  29. package/dist.commonjs/transformers-CYUULrnt.js.map +1 -0
  30. package/package.json +1 -1
  31. package/src/address/index.ts +32 -4
  32. package/src/ckb/transaction.ts +59 -27
  33. package/src/client/cache/memory.advanced.ts +18 -3
  34. package/src/client/client.ts +41 -2
  35. package/src/client/clientPublicMainnet.ts +9 -2
  36. package/src/client/clientPublicTestnet.ts +9 -2
  37. package/src/client/jsonRpc/client.ts +7 -7
  38. package/src/codec/codec.ts +51 -27
  39. package/src/codec/entity.ts +26 -16
  40. package/src/molecule/codec.ts +437 -202
  41. package/dist/advancedBarrel-Daj_LJkz.d.mts.map +0 -1
  42. package/dist/barrel-pRBtHOAW.mjs +0 -7
  43. package/dist/barrel-pRBtHOAW.mjs.map +0 -1
  44. package/dist/transformers-lavDTtAW.mjs +0 -2
  45. package/dist/transformers-lavDTtAW.mjs.map +0 -1
  46. package/dist.commonjs/advancedBarrel-CJL3rfuW.d.ts.map +0 -1
  47. package/dist.commonjs/barrel--PaV2IZx.js.map +0 -1
  48. package/dist.commonjs/transformers-VBXQGQKe.js +0 -2
  49. package/dist.commonjs/transformers-VBXQGQKe.js.map +0 -1
@@ -3,7 +3,7 @@ import { hashCkb } from "../hasher/index.js";
3
3
  import { Hex, hexFrom } from "../hex/index.js";
4
4
  import type { UnionDecoded, UnionMatchHandlers } from "../molecule/codec.js";
5
5
  import { Constructor } from "../utils/index.js";
6
- import type { CodecLike, DecodedType } from "./codec.js";
6
+ import type { CodecLike, ContextType, DecodedType } from "./codec.js";
7
7
 
8
8
  /**
9
9
  * The base class of CCC to create a serializable instance. This should be used with the {@link codec} decorator.
@@ -15,7 +15,12 @@ export abstract class Entity {
15
15
  * This should be used with the {@link codec} decorator.
16
16
  * @public
17
17
  */
18
- static Base<SubTypeLike, SubType = SubTypeLike>() {
18
+ static Base<
19
+ SubTypeLike,
20
+ SubType = SubTypeLike,
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ Context = any,
23
+ >() {
19
24
  abstract class Impl extends Entity {
20
25
  /**
21
26
  * The bytes length of the entity, if it is fixed, otherwise undefined
@@ -41,10 +46,11 @@ export abstract class Entity {
41
46
  * @public
42
47
  * @static
43
48
  * @param _ - The bytes to decode
49
+ * @param _context - Optional context passed to the codec
44
50
  * @returns The decoded entity
45
51
  * @throws Will throw an error if the entity is not serializable
46
52
  */
47
- static decode(_: BytesLike): SubType {
53
+ static decode(_: BytesLike, _context?: Context): SubType {
48
54
  throw new Error(
49
55
  "decode not implemented, use @ccc.codec to decorate your type",
50
56
  );
@@ -55,10 +61,11 @@ export abstract class Entity {
55
61
  * @public
56
62
  * @static
57
63
  * @param _ - The bytes to create the entity from
64
+ * @param _context - Optional context passed to the codec
58
65
  * @returns The created entity
59
66
  * @throws Will throw an error if the entity is not serializable
60
67
  */
61
- static fromBytes(_bytes: BytesLike): SubType {
68
+ static fromBytes(_bytes: BytesLike, _context?: Context): SubType {
62
69
  throw new Error(
63
70
  "fromBytes not implemented, use @ccc.codec to decorate your type",
64
71
  );
@@ -181,14 +188,18 @@ export abstract class Entity {
181
188
  */
182
189
  static BaseUnion<
183
190
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
184
- CodecType extends CodecLike<any, UnionDecoded<any, any>>,
191
+ CodecType extends CodecLike<any, UnionDecoded<any, any>, any>,
185
192
  SubTypeLike,
186
193
  SubType = SubTypeLike,
187
194
  >() {
188
195
  type Handlers<Result> = UnionMatchHandlers<CodecType, Result>;
189
196
  type Decoded = DecodedType<CodecType>;
190
197
 
191
- abstract class Impl extends Entity.Base<SubTypeLike, SubType>() {
198
+ abstract class Impl extends Entity.Base<
199
+ SubTypeLike,
200
+ SubType,
201
+ ContextType<CodecType>
202
+ >() {
192
203
  /**
193
204
  * The inner decoded object representing the union value.
194
205
  * @public
@@ -263,12 +274,11 @@ export function codec<
263
274
  Encodable,
264
275
  TypeLike extends Encodable,
265
276
  Decoded extends TypeLike,
277
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
278
+ Context = any,
266
279
  >(codec: {
267
280
  encode: (encodable: Encodable) => Bytes;
268
- decode: (
269
- decodable: Bytes,
270
- config?: { isExtraFieldIgnored?: boolean },
271
- ) => Decoded;
281
+ decode: (decodable: Bytes, context?: Context) => Decoded;
272
282
  byteLength?: number;
273
283
  }) {
274
284
  return function <
@@ -277,8 +287,8 @@ export function codec<
277
287
  from(decoded: TypeLike): Type;
278
288
  byteLength?: number;
279
289
  encode(encodable: TypeLike): Bytes;
280
- decode(bytesLike: BytesLike): Type;
281
- fromBytes(bytes: BytesLike): Type;
290
+ decode(bytesLike: BytesLike, context?: Context): Type;
291
+ fromBytes(bytes: BytesLike, context?: Context): Type;
282
292
  },
283
293
  >(Constructor: ConstructorType, ..._: unknown[]) {
284
294
  Constructor.byteLength = codec.byteLength;
@@ -288,13 +298,13 @@ export function codec<
288
298
  };
289
299
  }
290
300
  if (Constructor.decode === undefined) {
291
- Constructor.decode = function (bytesLike: BytesLike) {
292
- return Constructor.from(codec.decode(bytesFrom(bytesLike)));
301
+ Constructor.decode = function (bytesLike: BytesLike, context?: Context) {
302
+ return Constructor.from(codec.decode(bytesFrom(bytesLike), context));
293
303
  };
294
304
  }
295
305
  if (Constructor.fromBytes === undefined) {
296
- Constructor.fromBytes = function (bytes: BytesLike) {
297
- return Constructor.from(codec.decode(bytesFrom(bytes)));
306
+ Constructor.fromBytes = function (bytes: BytesLike, context?: Context) {
307
+ return Constructor.from(codec.decode(bytesFrom(bytes), context));
298
308
  };
299
309
  }
300
310