@ckb-ccc/core 0.0.4-alpha.1 → 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.
- package/README.md +12 -7
- package/dist/address/address.advanced.d.ts +34 -0
- package/dist/address/address.advanced.d.ts.map +1 -1
- package/dist/address/address.advanced.js +41 -7
- package/dist/address/index.d.ts +36 -0
- package/dist/address/index.d.ts.map +1 -1
- package/dist/address/index.js +44 -5
- package/dist/bytes/advanced.d.ts +3 -0
- package/dist/bytes/advanced.d.ts.map +1 -1
- package/dist/bytes/index.d.ts +57 -0
- package/dist/bytes/index.d.ts.map +1 -1
- package/dist/bytes/index.js +57 -0
- package/dist/ckb/script.d.ts +98 -1
- package/dist/ckb/script.d.ts.map +1 -1
- package/dist/ckb/script.js +98 -1
- package/dist/ckb/transaction.d.ts +392 -1
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +403 -1
- package/dist/client/advanced.d.ts +1 -0
- package/dist/client/advanced.d.ts.map +1 -1
- package/dist/client/advanced.js +1 -0
- package/dist/client/client.d.ts +10 -8
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +18 -0
- package/dist/client/clientPublicMainnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicMainnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.d.ts +3 -3
- package/dist/client/clientPublicMainnet.d.ts.map +1 -1
- package/dist/client/clientPublicMainnet.js +2 -2
- package/dist/client/clientPublicTestnet.advanced.d.ts +2 -2
- package/dist/client/clientPublicTestnet.advanced.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.d.ts +3 -3
- package/dist/client/clientPublicTestnet.d.ts.map +1 -1
- package/dist/client/clientPublicTestnet.js +2 -2
- package/dist/client/clientTypes.d.ts +6 -0
- package/dist/client/clientTypes.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/jsonRpc/advanced.d.ts +2 -87
- package/dist/client/jsonRpc/advanced.d.ts.map +1 -1
- package/dist/client/jsonRpc/advanced.js +2 -65
- package/dist/client/jsonRpc/index.d.ts +60 -6
- package/dist/client/jsonRpc/index.d.ts.map +1 -1
- package/dist/client/jsonRpc/index.js +72 -7
- package/dist/client/jsonRpc/transformers.d.ts +28 -0
- package/dist/client/jsonRpc/transformers.d.ts.map +1 -0
- package/dist/client/jsonRpc/transformers.js +122 -0
- package/dist/client/jsonRpc/types.d.ts +41 -0
- package/dist/client/jsonRpc/types.d.ts.map +1 -0
- package/dist/client/jsonRpc/types.js +1 -0
- package/dist/fixedPoint/index.d.ts +43 -1
- package/dist/fixedPoint/index.d.ts.map +1 -1
- package/dist/fixedPoint/index.js +39 -1
- package/dist/hasher/index.d.ts +43 -2
- package/dist/hasher/index.d.ts.map +1 -1
- package/dist/hasher/index.js +42 -0
- package/dist/hex/index.d.ts +19 -0
- package/dist/hex/index.d.ts.map +1 -1
- package/dist/hex/index.js +12 -0
- package/dist/num/index.d.ts +99 -0
- package/dist/num/index.d.ts.map +1 -1
- package/dist/num/index.js +92 -0
- package/dist/signer/btc/signerBtc.d.ts +40 -2
- package/dist/signer/btc/signerBtc.d.ts.map +1 -1
- package/dist/signer/btc/signerBtc.js +36 -4
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts +48 -0
- package/dist/signer/btc/signerBtcPublicKeyReadonly.d.ts.map +1 -1
- package/dist/signer/btc/signerBtcPublicKeyReadonly.js +53 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts +47 -0
- package/dist/signer/ckb/signerCkbScriptReadonly.d.ts.map +1 -1
- package/dist/signer/ckb/signerCkbScriptReadonly.js +52 -0
- package/dist/signer/evm/signerEvm.d.ts +34 -2
- package/dist/signer/evm/signerEvm.d.ts.map +1 -1
- package/dist/signer/evm/signerEvm.js +35 -4
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts +43 -1
- package/dist/signer/evm/signerEvmAddressReadonly.d.ts.map +1 -1
- package/dist/signer/evm/signerEvmAddressReadonly.js +47 -0
- package/dist/signer/helpers.d.ts +35 -2
- package/dist/signer/helpers.d.ts.map +1 -1
- package/dist/signer/helpers.js +67 -11
- package/dist/signer/signer.d.ts +98 -7
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/signer/signer.js +70 -3
- package/package.json +3 -3
- package/src/address/address.advanced.ts +54 -18
- package/src/address/index.ts +51 -7
- package/src/bytes/advanced.ts +12 -9
- package/src/bytes/index.ts +60 -0
- package/src/ckb/script.ts +111 -2
- package/src/ckb/transaction.ts +455 -2
- package/src/client/advanced.ts +1 -0
- package/src/client/client.ts +31 -8
- package/src/client/clientPublicMainnet.advanced.ts +5 -2
- package/src/client/clientPublicMainnet.ts +6 -4
- package/src/client/clientPublicTestnet.advanced.ts +5 -2
- package/src/client/clientPublicTestnet.ts +6 -4
- package/src/client/clientTypes.ts +13 -0
- package/src/client/index.ts +1 -0
- package/src/client/jsonRpc/advanced.ts +2 -93
- package/src/client/jsonRpc/index.ts +99 -11
- package/src/client/jsonRpc/transformers.ts +161 -0
- package/src/client/jsonRpc/types.ts +48 -0
- package/src/fixedPoint/index.ts +52 -2
- package/src/hasher/index.ts +47 -1
- package/src/hex/index.ts +19 -0
- package/src/num/index.ts +101 -0
- package/src/signer/btc/signerBtc.ts +47 -4
- package/src/signer/btc/signerBtcPublicKeyReadonly.ts +54 -0
- package/src/signer/ckb/signerCkbScriptReadonly.ts +54 -0
- package/src/signer/evm/signerEvm.ts +42 -4
- package/src/signer/evm/signerEvmAddressReadonly.ts +50 -1
- package/src/signer/helpers.ts +87 -11
- 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
|
-
|
|
33
|
-
|
|
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 (
|