@ckb-ccc/core 0.1.2 → 1.0.1

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 (110) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/address/address.advanced.d.ts.map +1 -1
  3. package/dist/address/address.advanced.js +6 -2
  4. package/dist/barrel.d.ts +1 -1
  5. package/dist/barrel.d.ts.map +1 -1
  6. package/dist/barrel.js +1 -1
  7. package/dist/bytes/index.d.ts +35 -0
  8. package/dist/bytes/index.d.ts.map +1 -1
  9. package/dist/bytes/index.js +60 -4
  10. package/dist/ckb/advanced.d.ts +0 -1
  11. package/dist/ckb/advanced.d.ts.map +1 -1
  12. package/dist/ckb/advanced.js +0 -1
  13. package/dist/ckb/script.d.ts +17 -58
  14. package/dist/ckb/script.d.ts.map +1 -1
  15. package/dist/ckb/script.js +29 -78
  16. package/dist/ckb/transaction.d.ts +125 -264
  17. package/dist/ckb/transaction.d.ts.map +1 -1
  18. package/dist/ckb/transaction.js +146 -357
  19. package/dist/molecule/barrel.d.ts +4 -0
  20. package/dist/molecule/barrel.d.ts.map +1 -0
  21. package/dist/molecule/barrel.js +3 -0
  22. package/dist/molecule/codec.d.ts +2 -0
  23. package/dist/molecule/codec.d.ts.map +1 -1
  24. package/dist/molecule/codec.js +57 -44
  25. package/dist/molecule/entity.d.ts +119 -0
  26. package/dist/molecule/entity.d.ts.map +1 -0
  27. package/dist/molecule/entity.js +134 -0
  28. package/dist/molecule/index.d.ts +1 -2
  29. package/dist/molecule/index.d.ts.map +1 -1
  30. package/dist/molecule/index.js +1 -2
  31. package/dist/molecule/predefined.d.ts +13 -20
  32. package/dist/molecule/predefined.d.ts.map +1 -1
  33. package/dist/molecule/predefined.js +14 -54
  34. package/dist/num/index.d.ts.map +1 -1
  35. package/dist/num/index.js +2 -2
  36. package/dist/signer/btc/verify.js +1 -1
  37. package/dist/signer/doge/verify.d.ts.map +1 -1
  38. package/dist/signer/doge/verify.js +3 -1
  39. package/dist/utils/index.d.ts +3 -0
  40. package/dist/utils/index.d.ts.map +1 -1
  41. package/dist.commonjs/address/address.advanced.d.ts.map +1 -1
  42. package/dist.commonjs/address/address.advanced.js +6 -2
  43. package/dist.commonjs/barrel.d.ts +1 -1
  44. package/dist.commonjs/barrel.d.ts.map +1 -1
  45. package/dist.commonjs/barrel.js +1 -14
  46. package/dist.commonjs/bytes/index.d.ts +35 -0
  47. package/dist.commonjs/bytes/index.d.ts.map +1 -1
  48. package/dist.commonjs/bytes/index.js +62 -4
  49. package/dist.commonjs/ckb/advanced.d.ts +0 -1
  50. package/dist.commonjs/ckb/advanced.d.ts.map +1 -1
  51. package/dist.commonjs/ckb/advanced.js +0 -14
  52. package/dist.commonjs/ckb/script.d.ts +17 -58
  53. package/dist.commonjs/ckb/script.d.ts.map +1 -1
  54. package/dist.commonjs/ckb/script.js +29 -102
  55. package/dist.commonjs/ckb/transaction.d.ts +125 -264
  56. package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
  57. package/dist.commonjs/ckb/transaction.js +167 -408
  58. package/dist.commonjs/molecule/barrel.d.ts +4 -0
  59. package/dist.commonjs/molecule/barrel.d.ts.map +1 -0
  60. package/dist.commonjs/{ckb/molecule.advanced/index.js → molecule/barrel.js} +3 -8
  61. package/dist.commonjs/molecule/codec.d.ts +2 -0
  62. package/dist.commonjs/molecule/codec.d.ts.map +1 -1
  63. package/dist.commonjs/molecule/codec.js +56 -43
  64. package/dist.commonjs/molecule/entity.d.ts +119 -0
  65. package/dist.commonjs/molecule/entity.d.ts.map +1 -0
  66. package/dist.commonjs/molecule/entity.js +139 -0
  67. package/dist.commonjs/molecule/index.d.ts +1 -2
  68. package/dist.commonjs/molecule/index.d.ts.map +1 -1
  69. package/dist.commonjs/molecule/index.js +13 -4
  70. package/dist.commonjs/molecule/predefined.d.ts +13 -20
  71. package/dist.commonjs/molecule/predefined.d.ts.map +1 -1
  72. package/dist.commonjs/molecule/predefined.js +14 -77
  73. package/dist.commonjs/num/index.d.ts.map +1 -1
  74. package/dist.commonjs/num/index.js +2 -2
  75. package/dist.commonjs/signer/btc/verify.js +1 -1
  76. package/dist.commonjs/signer/doge/verify.d.ts.map +1 -1
  77. package/dist.commonjs/signer/doge/verify.js +3 -1
  78. package/dist.commonjs/utils/index.d.ts +3 -0
  79. package/dist.commonjs/utils/index.d.ts.map +1 -1
  80. package/package.json +1 -1
  81. package/src/address/address.advanced.ts +6 -2
  82. package/src/barrel.ts +1 -1
  83. package/src/bytes/index.ts +70 -6
  84. package/src/ckb/advanced.ts +0 -1
  85. package/src/ckb/script.ts +20 -85
  86. package/src/ckb/transaction.ts +123 -416
  87. package/src/molecule/barrel.ts +3 -0
  88. package/src/molecule/codec.ts +82 -66
  89. package/src/molecule/entity.ts +183 -0
  90. package/src/molecule/index.ts +1 -2
  91. package/src/molecule/predefined.ts +20 -69
  92. package/src/num/index.ts +2 -5
  93. package/src/signer/btc/verify.ts +1 -1
  94. package/src/signer/doge/verify.ts +3 -1
  95. package/src/utils/index.ts +5 -0
  96. package/dist/ckb/molecule.advanced/generated.d.ts +0 -355
  97. package/dist/ckb/molecule.advanced/generated.d.ts.map +0 -1
  98. package/dist/ckb/molecule.advanced/generated.js +0 -1468
  99. package/dist/ckb/molecule.advanced/index.d.ts +0 -6
  100. package/dist/ckb/molecule.advanced/index.d.ts.map +0 -1
  101. package/dist/ckb/molecule.advanced/index.js +0 -7
  102. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +0 -355
  103. package/dist.commonjs/ckb/molecule.advanced/generated.d.ts.map +0 -1
  104. package/dist.commonjs/ckb/molecule.advanced/generated.js +0 -1535
  105. package/dist.commonjs/ckb/molecule.advanced/index.d.ts +0 -6
  106. package/dist.commonjs/ckb/molecule.advanced/index.d.ts.map +0 -1
  107. package/src/ckb/molecule.advanced/blockchain.mol +0 -118
  108. package/src/ckb/molecule.advanced/generated.d.ts +0 -444
  109. package/src/ckb/molecule.advanced/generated.js +0 -1804
  110. package/src/ckb/molecule.advanced/index.ts +0 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ckb-ccc/core
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#111](https://github.com/ckb-devrel/ccc/pull/111) [`719055b`](https://github.com/ckb-devrel/ccc/commit/719055b404f31b40362f51714b9f11c85b857581) Thanks [@Hanssen0](https://github.com/Hanssen0)! - fix: call stack overflow caused by spread operator
8
+
9
+ - [#109](https://github.com/ckb-devrel/ccc/pull/109) [`94caaca`](https://github.com/ckb-devrel/ccc/commit/94caaca11c63752a25282d42f51161c94397dec6) Thanks [@Hanssen0](https://github.com/Hanssen0)! - refactor: remove redundant code
10
+
11
+ ## 1.0.0
12
+
13
+ ### Major Changes
14
+
15
+ - [#107](https://github.com/ckb-devrel/ccc/pull/107) [`b99f55f`](https://github.com/ckb-devrel/ccc/commit/b99f55f74e64106391ce53f7d0bd0fa7522023cc) Thanks [@Hanssen0](https://github.com/Hanssen0)! - feat: molecule
16
+
3
17
  ## 0.1.2
4
18
 
5
19
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"address.advanced.d.ts","sourceRoot":"","sources":["../../src/address/address.advanced.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAe,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;;;GAeG;AAEH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CA2BA;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CAyEtB;AAED,oBAAY,aAAa;IACvB;;OAEG;IACH,IAAI,IAAO;IACX;;;OAGG;IACH,KAAK,IAAO;IACZ;;;OAGG;IACH,QAAQ,IAAO;IACf;;;OAGG;IACH,QAAQ,IAAO;CAChB;AAED,eAAO,MAAM,oBAAoB,OAAO,CAAC"}
1
+ {"version":3,"file":"address.advanced.d.ts","sourceRoot":"","sources":["../../src/address/address.advanced.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAe,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;;;GAeG;AAEH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CA+BA;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC,CAyEtB;AAED,oBAAY,aAAa;IACvB;;OAEG;IACH,IAAI,IAAO;IACX;;;OAGG;IACH,KAAK,IAAO;IACZ;;;OAGG;IACH,QAAQ,IAAO;IACf;;;OAGG;IACH,QAAQ,IAAO;CAChB;AAED,eAAO,MAAM,oBAAoB,OAAO,CAAC"}
@@ -22,7 +22,9 @@ export function addressPayloadFromString(address) {
22
22
  // Try parse full format address
23
23
  try {
24
24
  const { words, prefix } = bech32m.decode(address, ADDRESS_BECH32_LIMIT);
25
- const [formatType, ...payload] = bech32m.fromWords(words);
25
+ const decoded = bech32m.fromWords(words);
26
+ const formatType = decoded[0];
27
+ const payload = decoded.slice(1);
26
28
  if (formatType === AddressFormat.Full) {
27
29
  return { prefix, format: AddressFormat.Full, payload };
28
30
  }
@@ -31,7 +33,9 @@ export function addressPayloadFromString(address) {
31
33
  // Try parse legacy 2019 format address
32
34
  try {
33
35
  const { prefix, words } = bech32.decode(address, ADDRESS_BECH32_LIMIT);
34
- const [formatType, ...payload] = bech32.fromWords(words);
36
+ const decoded = bech32.fromWords(words);
37
+ const formatType = decoded[0];
38
+ const payload = decoded.slice(1);
35
39
  if ([
36
40
  AddressFormat.FullData,
37
41
  AddressFormat.FullType,
package/dist/barrel.d.ts CHANGED
@@ -6,7 +6,7 @@ export * from "./fixedPoint/index.js";
6
6
  export * from "./hasher/index.js";
7
7
  export * from "./hex/index.js";
8
8
  export * from "./keystore/index.js";
9
- export * as mol from "./molecule/index.js";
9
+ export * from "./molecule/index.js";
10
10
  export * from "./num/index.js";
11
11
  export * from "./signer/index.js";
12
12
  export * from "./utils/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
package/dist/barrel.js CHANGED
@@ -6,7 +6,7 @@ export * from "./fixedPoint/index.js";
6
6
  export * from "./hasher/index.js";
7
7
  export * from "./hex/index.js";
8
8
  export * from "./keystore/index.js";
9
- export * as mol from "./molecule/index.js";
9
+ export * from "./molecule/index.js";
10
10
  export * from "./num/index.js";
11
11
  export * from "./signer/index.js";
12
12
  export * from "./utils/index.js";
@@ -7,6 +7,27 @@ export type Bytes = Uint8Array;
7
7
  * @public
8
8
  */
9
9
  export type BytesLike = string | Uint8Array | ArrayBuffer | ArrayLike<number>;
10
+ /**
11
+ * Concatenates multiple byte-like arrays to the first number array.
12
+ * @public
13
+ *
14
+ * @param result - The number array as result
15
+ * @param args - The byte-like arrays to concatenate.
16
+ * @returns The first number array
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const concatenatedBytes = [1, 2];
21
+ * bytesConcatTo(
22
+ * concatenatedBytes
23
+ * new Uint8Array([3, 4]),
24
+ * "hello",
25
+ * [5, 6, 7]
26
+ * );
27
+ * console.log(concatenatedBytes); // Outputs [1, 2, 3, 4, /* bytes of "hello" *\/, 5, 6, 7]
28
+ * ```
29
+ */
30
+ export declare function bytesConcatTo(result: number[], ...args: BytesLike[]): number[];
10
31
  /**
11
32
  * Concatenates multiple byte-like arrays into a single byte array.
12
33
  * @public
@@ -70,4 +91,18 @@ export declare function bytesTo(val: BytesLike, encoding: BytesFromEncoding): st
70
91
  * ```
71
92
  */
72
93
  export declare function bytesFrom(bytes: BytesLike, encoding?: BytesFromEncoding): Bytes;
94
+ /**
95
+ * Compares two byte-like values for equality.
96
+ * @public
97
+ *
98
+ * @param a - The first byte-like value to compare.
99
+ * @param b - The second byte-like value to compare.
100
+ * @returns A boolean indicating whether the two byte-like values are equal.
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * bytesEq([1], Uint8Array.from([1])) // true
105
+ * ```
106
+ */
107
+ export declare function bytesEq(a: BytesLike, b: BytesLike): boolean;
73
108
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bytes/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC;AAC/B;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAE9E;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,WAAW,CAAC,GAAG,IAAI,EAAE,SAAS,EAAE,GAAG,KAAK,CAOvD;AAED;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAE3E;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,wBAAgB,SAAS,CACvB,KAAK,EAAE,SAAS,EAChB,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,KAAK,CA4BP"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bytes/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC;AAC/B;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EAAE,EAChB,GAAG,IAAI,EAAE,SAAS,EAAE,GACnB,MAAM,EAAE,CASV;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH,wBAAgB,WAAW,CAAC,GAAG,IAAI,EAAE,SAAS,EAAE,GAAG,KAAK,CAEvD;AAED;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAAgB,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAE3E;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,wBAAgB,SAAS,CACvB,KAAK,EAAE,SAAS,EAChB,QAAQ,CAAC,EAAE,iBAAiB,GAC3B,KAAK,CA4BP;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,OAAO,CAmB3D"}
@@ -1,4 +1,34 @@
1
1
  import { Buffer } from "buffer/index.js";
2
+ /**
3
+ * Concatenates multiple byte-like arrays to the first number array.
4
+ * @public
5
+ *
6
+ * @param result - The number array as result
7
+ * @param args - The byte-like arrays to concatenate.
8
+ * @returns The first number array
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const concatenatedBytes = [1, 2];
13
+ * bytesConcatTo(
14
+ * concatenatedBytes
15
+ * new Uint8Array([3, 4]),
16
+ * "hello",
17
+ * [5, 6, 7]
18
+ * );
19
+ * console.log(concatenatedBytes); // Outputs [1, 2, 3, 4, /* bytes of "hello" *\/, 5, 6, 7]
20
+ * ```
21
+ */
22
+ export function bytesConcatTo(result, ...args) {
23
+ return args.reduce((acc, v) => {
24
+ const bytes = bytesFrom(v);
25
+ // Spread operator will cause call stack size exceeded
26
+ for (const byte of bytes) {
27
+ result.push(byte);
28
+ }
29
+ return acc;
30
+ }, result);
31
+ }
2
32
  /**
3
33
  * Concatenates multiple byte-like arrays into a single byte array.
4
34
  * @public
@@ -18,10 +48,7 @@ import { Buffer } from "buffer/index.js";
18
48
  * ```
19
49
  */
20
50
  export function bytesConcat(...args) {
21
- return new Uint8Array(args.reduce((acc, v) => {
22
- acc.push(...bytesFrom(v));
23
- return acc;
24
- }, []));
51
+ return new Uint8Array(bytesConcatTo([], ...args));
25
52
  }
26
53
  /**
27
54
  * Converts a byte-like value to a string using the specified encoding.
@@ -93,3 +120,32 @@ export function bytesFrom(bytes, encoding) {
93
120
  }
94
121
  return new Uint8Array(bytes);
95
122
  }
123
+ /**
124
+ * Compares two byte-like values for equality.
125
+ * @public
126
+ *
127
+ * @param a - The first byte-like value to compare.
128
+ * @param b - The second byte-like value to compare.
129
+ * @returns A boolean indicating whether the two byte-like values are equal.
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * bytesEq([1], Uint8Array.from([1])) // true
134
+ * ```
135
+ */
136
+ export function bytesEq(a, b) {
137
+ if (a === b) {
138
+ return true;
139
+ }
140
+ const x = bytesFrom(a);
141
+ const y = bytesFrom(b);
142
+ if (x.length !== y.length) {
143
+ return false;
144
+ }
145
+ for (let i = 0; i < x.length; i++) {
146
+ if (x[i] !== y[i]) {
147
+ return false;
148
+ }
149
+ }
150
+ return true;
151
+ }
@@ -1,4 +1,3 @@
1
- export * as moleculeCodecCkb from "./molecule.advanced/index.js";
2
1
  export * from "./script.advanced.js";
3
2
  export * from "./transaction.advanced.js";
4
3
  //# sourceMappingURL=advanced.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/ckb/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAC;AACjE,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC"}
1
+ {"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/ckb/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC"}
@@ -1,3 +1,2 @@
1
- export * as moleculeCodecCkb from "./molecule.advanced/index.js";
2
1
  export * from "./script.advanced.js";
3
2
  export * from "./transaction.advanced.js";
@@ -1,7 +1,8 @@
1
1
  import { Bytes, BytesLike } from "../bytes/index.js";
2
2
  import { Client, KnownScript } from "../client/index.js";
3
3
  import { Hex, HexLike } from "../hex/index.js";
4
- import * as mol from "./molecule.advanced/index.js";
4
+ import { mol } from "../molecule/index.js";
5
+ export declare const HashTypeCodec: mol.Codec<HashTypeLike, HashType>;
5
6
  /**
6
7
  * @public
7
8
  */
@@ -62,10 +63,22 @@ export type ScriptLike = {
62
63
  hashType: HashTypeLike;
63
64
  args: BytesLike;
64
65
  };
66
+ declare const Script_base: (abstract new () => {
67
+ toBytes(): Bytes;
68
+ clone(): Script;
69
+ eq(other: ScriptLike): boolean;
70
+ hash(): Hex;
71
+ }) & {
72
+ byteLength?: number;
73
+ encode(_: ScriptLike): Bytes;
74
+ decode(_: BytesLike): Script;
75
+ fromBytes(_bytes: BytesLike): Script;
76
+ from(_: ScriptLike): Script;
77
+ };
65
78
  /**
66
79
  * @public
67
80
  */
68
- export declare class Script {
81
+ export declare class Script extends Script_base {
69
82
  codeHash: Hex;
70
83
  hashType: HashType;
71
84
  args: Hex;
@@ -123,61 +136,7 @@ export declare class Script {
123
136
  * ```
124
137
  */
125
138
  static fromKnownScript(client: Client, knownScript: KnownScript, args: HexLike): Promise<Script>;
126
- /**
127
- * Converts the Script instance to molecule data format.
128
- *
129
- * @returns An object representing the script in molecule data format.
130
- */
131
- _toMolData(): {
132
- codeHash: Uint8Array;
133
- hashType: Uint8Array;
134
- args: Uint8Array;
135
- };
136
- /**
137
- * Converts the Script instance to bytes.
138
- *
139
- * @returns A Uint8Array containing the script bytes.
140
- *
141
- * @example
142
- * ```typescript
143
- * const scriptBytes = script.toBytes();
144
- * ```
145
- */
146
- toBytes(): Bytes;
147
- /**
148
- * Get hash of a script
149
- *
150
- * @returns Hash of this script
151
- *
152
- * @example
153
- * ```typescript
154
- * const hash = script.hash();
155
- * ```
156
- */
157
- hash(): Hex;
158
- /**
159
- * Creates a Script instance from a byte-like value or molecule Script.
160
- *
161
- * @param bytes - The byte-like value or molecule Script to convert.
162
- * @returns A Script instance.
163
- *
164
- * @example
165
- * ```typescript
166
- * const script = Script.fromBytes(new Uint8Array([/* script bytes *\/]));
167
- * ```
168
- */
169
- static fromBytes(bytes: BytesLike | mol.Script): Script;
170
- /**
171
- * Compares the current Script instance with another ScriptLike object for equality.
172
- *
173
- * @param val - The ScriptLike object to compare with.
174
- * @returns True if the scripts are equal, otherwise false.
175
- *
176
- * @example
177
- * ```typescript
178
- * const isEqual = script.eq(anotherScript);
179
- * ```
180
- */
181
- eq(val: ScriptLike): boolean;
182
139
  }
140
+ export declare const ScriptOpt: mol.Codec<ScriptLike | null | undefined, Script | undefined>;
141
+ export {};
183
142
  //# sourceMappingURL=script.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../src/ckb/script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAa,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,GAAG,MAAM,8BAA8B,CAAC;AAOpD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AACpD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3D;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,QAAQ,CAmBxD;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,YAAY,GAAG,KAAK,CAE7D;AAED;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,QAAQ,CAE5D;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAA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;CAUnB;AAED,eAAO,MAAM,SAAS,8DAAqB,CAAC"}
@@ -1,8 +1,19 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var Script_1;
1
8
  import { bytesFrom } from "../bytes/index.js";
2
- import { hashCkb } from "../hasher/index.js";
3
9
  import { hexFrom } from "../hex/index.js";
4
- import * as mol from "./molecule.advanced/index.js";
10
+ import { mol } from "../molecule/index.js";
5
11
  import { HASH_TYPES, HASH_TYPE_TO_NUM, NUM_TO_HASH_TYPE, } from "./script.advanced.js";
12
+ export const HashTypeCodec = mol.Codec.from({
13
+ byteLength: 1,
14
+ encode: hashTypeToBytes,
15
+ decode: hashTypeFromBytes,
16
+ });
6
17
  /**
7
18
  * Converts a HashTypeLike value to a HashType.
8
19
  * @public
@@ -71,7 +82,7 @@ export function hashTypeFromBytes(bytes) {
71
82
  /**
72
83
  * @public
73
84
  */
74
- export class Script {
85
+ let Script = Script_1 = class Script extends mol.Entity.Base() {
75
86
  /**
76
87
  * Creates an instance of Script.
77
88
  *
@@ -80,6 +91,7 @@ export class Script {
80
91
  * @param args - The arguments for the script.
81
92
  */
82
93
  constructor(codeHash, hashType, args) {
94
+ super();
83
95
  this.codeHash = codeHash;
84
96
  this.hashType = hashType;
85
97
  this.args = args;
@@ -98,7 +110,7 @@ export class Script {
98
110
  * ```
99
111
  */
100
112
  clone() {
101
- return new Script(this.codeHash, this.hashType, this.args);
113
+ return new Script_1(this.codeHash, this.hashType, this.args);
102
114
  }
103
115
  /**
104
116
  * Creates a Script instance from a ScriptLike object.
@@ -116,10 +128,10 @@ export class Script {
116
128
  * ```
117
129
  */
118
130
  static from(script) {
119
- if (script instanceof Script) {
131
+ if (script instanceof Script_1) {
120
132
  return script;
121
133
  }
122
- return new Script(hexFrom(script.codeHash), hashTypeFrom(script.hashType), hexFrom(script.args));
134
+ return new Script_1(hexFrom(script.codeHash), hashTypeFrom(script.hashType), hexFrom(script.args));
123
135
  }
124
136
  /**
125
137
  * Creates a Script instance from client and known script.
@@ -140,76 +152,15 @@ export class Script {
140
152
  */
141
153
  static async fromKnownScript(client, knownScript, args) {
142
154
  const script = await client.getKnownScript(knownScript);
143
- return new Script(script.codeHash, script.hashType, hexFrom(args));
155
+ return new Script_1(script.codeHash, script.hashType, hexFrom(args));
144
156
  }
145
- /**
146
- * Converts the Script instance to molecule data format.
147
- *
148
- * @returns An object representing the script in molecule data format.
149
- */
150
- _toMolData() {
151
- return {
152
- codeHash: bytesFrom(this.codeHash),
153
- hashType: hashTypeToBytes(this.hashType),
154
- args: bytesFrom(this.args),
155
- };
156
- }
157
- /**
158
- * Converts the Script instance to bytes.
159
- *
160
- * @returns A Uint8Array containing the script bytes.
161
- *
162
- * @example
163
- * ```typescript
164
- * const scriptBytes = script.toBytes();
165
- * ```
166
- */
167
- toBytes() {
168
- return bytesFrom(mol.SerializeScript(this._toMolData()));
169
- }
170
- /**
171
- * Get hash of a script
172
- *
173
- * @returns Hash of this script
174
- *
175
- * @example
176
- * ```typescript
177
- * const hash = script.hash();
178
- * ```
179
- */
180
- hash() {
181
- return hashCkb(this.toBytes());
182
- }
183
- /**
184
- * Creates a Script instance from a byte-like value or molecule Script.
185
- *
186
- * @param bytes - The byte-like value or molecule Script to convert.
187
- * @returns A Script instance.
188
- *
189
- * @example
190
- * ```typescript
191
- * const script = Script.fromBytes(new Uint8Array([/* script bytes *\/]));
192
- * ```
193
- */
194
- static fromBytes(bytes) {
195
- const view = bytes instanceof mol.Script ? bytes : new mol.Script(bytesFrom(bytes));
196
- return new Script(hexFrom(view.getCodeHash().raw()), hashTypeFromBytes([view.getHashType()]), hexFrom(view.getArgs().raw()));
197
- }
198
- /**
199
- * Compares the current Script instance with another ScriptLike object for equality.
200
- *
201
- * @param val - The ScriptLike object to compare with.
202
- * @returns True if the scripts are equal, otherwise false.
203
- *
204
- * @example
205
- * ```typescript
206
- * const isEqual = script.eq(anotherScript);
207
- * ```
208
- */
209
- eq(val) {
210
- const script = Script.from(val);
211
- return (this.codeHash === script.codeHash &&
212
- this.args === script.args &&
213
- this.hashType === script.hashType);
214
- }
215
- }
157
+ };
158
+ Script = Script_1 = __decorate([
159
+ mol.codec(mol.table({
160
+ codeHash: mol.Byte32,
161
+ hashType: HashTypeCodec,
162
+ args: mol.Bytes,
163
+ }))
164
+ ], Script);
165
+ export { Script };
166
+ export const ScriptOpt = mol.option(Script);