@ckb-ccc/core 0.0.4-alpha.0 → 0.0.4-alpha.11

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 (114) hide show
  1. package/README.md +37 -0
  2. package/dist/address/address.advanced.d.ts +34 -0
  3. package/dist/address/address.advanced.d.ts.map +1 -1
  4. package/dist/address/address.advanced.js +41 -7
  5. package/dist/address/index.d.ts +36 -0
  6. package/dist/address/index.d.ts.map +1 -1
  7. package/dist/address/index.js +44 -5
  8. package/dist/bytes/advanced.d.ts +3 -0
  9. package/dist/bytes/advanced.d.ts.map +1 -1
  10. package/dist/bytes/index.d.ts +57 -0
  11. package/dist/bytes/index.d.ts.map +1 -1
  12. package/dist/bytes/index.js +57 -0
  13. package/dist/ckb/script.d.ts +98 -1
  14. package/dist/ckb/script.d.ts.map +1 -1
  15. package/dist/ckb/script.js +98 -1
  16. package/dist/ckb/transaction.d.ts +392 -1
  17. package/dist/ckb/transaction.d.ts.map +1 -1
  18. package/dist/ckb/transaction.js +403 -1
  19. package/dist/client/advanced.d.ts +1 -0
  20. package/dist/client/advanced.d.ts.map +1 -1
  21. package/dist/client/advanced.js +1 -0
  22. package/dist/client/client.d.ts +10 -8
  23. package/dist/client/client.d.ts.map +1 -1
  24. package/dist/client/client.js +18 -0
  25. package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
  26. package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
  27. package/dist/client/clientPublicMainnet.d.ts +3 -3
  28. package/dist/client/clientPublicMainnet.d.ts.map +1 -1
  29. package/dist/client/clientPublicMainnet.js +2 -2
  30. package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
  31. package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
  32. package/dist/client/clientPublicTestnet.d.ts +3 -3
  33. package/dist/client/clientPublicTestnet.d.ts.map +1 -1
  34. package/dist/client/clientPublicTestnet.js +2 -2
  35. package/dist/client/clientTypes.d.ts +6 -0
  36. package/dist/client/clientTypes.d.ts.map +1 -1
  37. package/dist/client/index.d.ts +1 -0
  38. package/dist/client/index.d.ts.map +1 -1
  39. package/dist/client/index.js +1 -0
  40. package/dist/client/jsonRpc/advanced.d.ts +2 -87
  41. package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
  42. package/dist/client/jsonRpc/advanced.js +2 -65
  43. package/dist/client/jsonRpc/index.d.ts +60 -6
  44. package/dist/client/jsonRpc/index.d.ts.map +1 -1
  45. package/dist/client/jsonRpc/index.js +72 -7
  46. package/dist/client/jsonRpc/transformers.d.ts +28 -0
  47. package/dist/client/jsonRpc/transformers.d.ts.map +1 -0
  48. package/dist/client/jsonRpc/transformers.js +122 -0
  49. package/dist/client/jsonRpc/types.d.ts +41 -0
  50. package/dist/client/jsonRpc/types.d.ts.map +1 -0
  51. package/dist/client/jsonRpc/types.js +1 -0
  52. package/dist/fixedPoint/index.d.ts +43 -1
  53. package/dist/fixedPoint/index.d.ts.map +1 -1
  54. package/dist/fixedPoint/index.js +39 -1
  55. package/dist/hasher/index.d.ts +43 -2
  56. package/dist/hasher/index.d.ts.map +1 -1
  57. package/dist/hasher/index.js +42 -0
  58. package/dist/hex/index.d.ts +19 -0
  59. package/dist/hex/index.d.ts.map +1 -1
  60. package/dist/hex/index.js +12 -0
  61. package/dist/num/index.d.ts +99 -0
  62. package/dist/num/index.d.ts.map +1 -1
  63. package/dist/num/index.js +92 -0
  64. package/dist/signer/btc/signerBtc.d.ts +40 -2
  65. package/dist/signer/btc/signerBtc.d.ts.map +1 -1
  66. package/dist/signer/btc/signerBtc.js +36 -4
  67. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +48 -0
  68. package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
  69. package/dist/signer/btc/signerBtcPublicKeyReadonly.js +53 -0
  70. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +47 -0
  71. package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
  72. package/dist/signer/ckb/signerCkbScriptReadonly.js +52 -0
  73. package/dist/signer/evm/signerEvm.d.ts +34 -2
  74. package/dist/signer/evm/signerEvm.d.ts.map +1 -1
  75. package/dist/signer/evm/signerEvm.js +35 -4
  76. package/dist/signer/evm/signerEvmAddressReadonly.d.ts +43 -1
  77. package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
  78. package/dist/signer/evm/signerEvmAddressReadonly.js +47 -0
  79. package/dist/signer/helpers.d.ts +35 -2
  80. package/dist/signer/helpers.d.ts.map +1 -1
  81. package/dist/signer/helpers.js +67 -11
  82. package/dist/signer/signer.d.ts +98 -7
  83. package/dist/signer/signer.d.ts.map +1 -1
  84. package/dist/signer/signer.js +70 -3
  85. package/package.json +5 -5
  86. package/src/address/address.advanced.ts +43 -7
  87. package/src/address/index.ts +48 -6
  88. package/src/bytes/advanced.ts +12 -9
  89. package/src/bytes/index.ts +60 -0
  90. package/src/ckb/script.ts +111 -2
  91. package/src/ckb/transaction.ts +455 -2
  92. package/src/client/advanced.ts +1 -0
  93. package/src/client/client.ts +31 -8
  94. package/src/client/clientPublicMainnet.advanced.ts +5 -2
  95. package/src/client/clientPublicMainnet.ts +6 -4
  96. package/src/client/clientPublicTestnet.advanced.ts +5 -2
  97. package/src/client/clientPublicTestnet.ts +6 -4
  98. package/src/client/clientTypes.ts +13 -0
  99. package/src/client/index.ts +1 -0
  100. package/src/client/jsonRpc/advanced.ts +2 -93
  101. package/src/client/jsonRpc/index.ts +99 -11
  102. package/src/client/jsonRpc/transformers.ts +161 -0
  103. package/src/client/jsonRpc/types.ts +48 -0
  104. package/src/fixedPoint/index.ts +52 -2
  105. package/src/hasher/index.ts +47 -1
  106. package/src/hex/index.ts +19 -0
  107. package/src/num/index.ts +101 -0
  108. package/src/signer/btc/signerBtc.ts +47 -4
  109. package/src/signer/btc/signerBtcPublicKeyReadonly.ts +54 -0
  110. package/src/signer/ckb/signerCkbScriptReadonly.ts +54 -0
  111. package/src/signer/evm/signerEvm.ts +42 -4
  112. package/src/signer/evm/signerEvmAddressReadonly.ts +50 -1
  113. package/src/signer/helpers.ts +87 -11
  114. package/src/signer/signer.ts +109 -7
package/src/ckb/script.ts CHANGED
@@ -9,6 +9,22 @@ import {
9
9
 
10
10
  export type HashTypeLike = string | number | bigint;
11
11
  export type HashType = "type" | "data" | "data1" | "data2";
12
+
13
+ /**
14
+ * Converts a HashTypeLike value to a HashType.
15
+ *
16
+ * @param val - The value to convert, which can be a string, number, or bigint.
17
+ * @returns The corresponding HashType.
18
+ *
19
+ * @throws Will throw an error if the input value is not a valid hash type.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const hashType = hashTypeFrom(1); // Outputs "data"
24
+ * const hashType = hashTypeFrom("type"); // Outputs "type"
25
+ * ```
26
+ */
27
+
12
28
  export function hashTypeFrom(val: HashTypeLike): HashType {
13
29
  const hashType = (() => {
14
30
  if (typeof val === "number") {
@@ -29,9 +45,37 @@ export function hashTypeFrom(val: HashTypeLike): HashType {
29
45
  }
30
46
  return hashType;
31
47
  }
32
- export function hashTypeToBytes(hashType: HashType): Bytes {
33
- return bytesFrom([HASH_TYPE_TO_NUM[hashType]]);
48
+
49
+ /**
50
+ * Converts a HashTypeLike value to its corresponding byte representation.
51
+ *
52
+ * @param hashType - The hash type value to convert.
53
+ * @returns A Uint8Array containing the byte representation of the hash type.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const hashTypeBytes = hashTypeToBytes("type"); // Outputs Uint8Array [0]
58
+ * ```
59
+ */
60
+
61
+ export function hashTypeToBytes(hashType: HashTypeLike): Bytes {
62
+ return bytesFrom([HASH_TYPE_TO_NUM[hashTypeFrom(hashType)]]);
34
63
  }
64
+
65
+ /**
66
+ * Converts a byte-like value to a HashType.
67
+ *
68
+ * @param bytes - The byte-like value to convert.
69
+ * @returns The corresponding HashType.
70
+ *
71
+ * @throws Will throw an error if the input bytes do not correspond to a valid hash type.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const hashType = hashTypeFromBytes(new Uint8Array([0])); // Outputs "type"
76
+ * ```
77
+ */
78
+
35
79
  export function hashTypeFromBytes(bytes: BytesLike): HashType {
36
80
  return NUM_TO_HASH_TYPE[bytesFrom(bytes)[0]];
37
81
  }
@@ -42,12 +86,36 @@ export type ScriptLike = {
42
86
  args: BytesLike;
43
87
  };
44
88
  export class Script {
89
+ /**
90
+ * Creates an instance of Script.
91
+ *
92
+ * @param codeHash - The code hash of the script.
93
+ * @param hashType - The hash type of the script.
94
+ * @param args - The arguments for the script.
95
+ */
96
+
45
97
  constructor(
46
98
  public codeHash: Hex,
47
99
  public hashType: HashType,
48
100
  public args: Hex,
49
101
  ) {}
50
102
 
103
+ /**
104
+ * Creates a Script instance from a ScriptLike object.
105
+ *
106
+ * @param script - A ScriptLike object or an instance of Script.
107
+ * @returns A Script instance.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const script = Script.from({
112
+ * codeHash: "0x1234...",
113
+ * hashType: "type",
114
+ * args: "0xabcd..."
115
+ * });
116
+ * ```
117
+ */
118
+
51
119
  static from(script: ScriptLike): Script {
52
120
  if (script instanceof Script) {
53
121
  return script;
@@ -60,6 +128,12 @@ export class Script {
60
128
  );
61
129
  }
62
130
 
131
+ /**
132
+ * Converts the Script instance to molecule data format.
133
+ *
134
+ * @returns An object representing the script in molecule data format.
135
+ */
136
+
63
137
  _toMolData() {
64
138
  return {
65
139
  codeHash: bytesFrom(this.codeHash),
@@ -68,10 +142,33 @@ export class Script {
68
142
  };
69
143
  }
70
144
 
145
+ /**
146
+ * Converts the Script instance to bytes.
147
+ *
148
+ * @returns A Uint8Array containing the script bytes.
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const scriptBytes = script.toBytes();
153
+ * ```
154
+ */
155
+
71
156
  toBytes(): Bytes {
72
157
  return bytesFrom(mol.SerializeScript(this._toMolData()));
73
158
  }
74
159
 
160
+ /**
161
+ * Creates a Script instance from a byte-like value or molecule Script.
162
+ *
163
+ * @param bytes - The byte-like value or molecule Script to convert.
164
+ * @returns A Script instance.
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * const script = Script.fromBytes(new Uint8Array([/* script bytes *\/]));
169
+ * ```
170
+ */
171
+
75
172
  static fromBytes(bytes: BytesLike | mol.Script): Script {
76
173
  const view =
77
174
  bytes instanceof mol.Script ? bytes : new mol.Script(bytesFrom(bytes));
@@ -83,6 +180,18 @@ export class Script {
83
180
  );
84
181
  }
85
182
 
183
+ /**
184
+ * Compares the current Script instance with another ScriptLike object for equality.
185
+ *
186
+ * @param val - The ScriptLike object to compare with.
187
+ * @returns True if the scripts are equal, otherwise false.
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * const isEqual = script.eq(anotherScript);
192
+ * ```
193
+ */
194
+
86
195
  eq(val: ScriptLike): boolean {
87
196
  const script = Script.from(val);
88
197
  return (