@ckb-ccc/core 1.22.0 → 2.0.0-next.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.
- package/CHANGELOG.md +61 -1
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.mjs +1 -1
- package/{dist.commonjs/advancedBarrel-CJL3rfuW.d.ts → dist/advancedBarrel-DfFMFhdl.d.mts} +934 -567
- package/dist/advancedBarrel-DfFMFhdl.d.mts.map +1 -0
- package/dist/advancedBarrel.d.mts +1 -1
- package/dist/advancedBarrel.mjs +1 -1
- package/dist/barrel-ONYEMVg5.mjs +7 -0
- package/dist/barrel-ONYEMVg5.mjs.map +1 -0
- package/dist/barrel.d.mts +2 -2
- package/dist/barrel.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/transformers-CduZ1Js5.mjs +2 -0
- package/dist/transformers-CduZ1Js5.mjs.map +1 -0
- package/dist.commonjs/advanced.d.ts +1 -1
- package/dist.commonjs/advanced.js +1 -1
- package/{dist/advancedBarrel-Daj_LJkz.d.mts → dist.commonjs/advancedBarrel-Dl0mM9JO.d.ts} +935 -566
- package/dist.commonjs/advancedBarrel-Dl0mM9JO.d.ts.map +1 -0
- package/dist.commonjs/advancedBarrel.d.ts +1 -1
- package/dist.commonjs/advancedBarrel.js +1 -1
- package/dist.commonjs/{barrel-DZkApbAR.js → barrel-HfgYMxP_.js} +10 -10
- package/dist.commonjs/barrel-HfgYMxP_.js.map +1 -0
- package/dist.commonjs/barrel.d.ts +2 -2
- package/dist.commonjs/barrel.js +1 -1
- package/dist.commonjs/index.d.ts +2 -2
- package/dist.commonjs/index.js +1 -1
- package/dist.commonjs/transformers-BUlLwiyt.js +2 -0
- package/dist.commonjs/transformers-BUlLwiyt.js.map +1 -0
- package/package.json +1 -1
- package/src/ckb/epoch.ts +44 -26
- package/src/ckb/script.ts +23 -46
- package/src/ckb/transaction.ts +192 -195
- package/src/client/client.ts +2 -2
- package/src/client/jsonRpc/client.ts +3 -7
- package/src/codec/codec.ts +65 -40
- package/src/codec/entity.ts +95 -67
- package/src/codec/predefined.ts +11 -0
- package/src/molecule/codec.ts +116 -8
- package/src/molecule/predefined.ts +1 -0
- package/src/signer/ckb/signerMultisigCkbReadonly.ts +36 -24
- package/src/signer/ckb/verifyJoyId.ts +39 -11
- package/src/signer/index.ts +17 -0
- package/src/signer/signer/index.ts +11 -0
- package/src/signer/signerFromSignature.ts +65 -0
- package/src/utils/index.ts +108 -26
- package/dist/advancedBarrel-Daj_LJkz.d.mts.map +0 -1
- package/dist/barrel-CFOWSjcM.mjs +0 -7
- package/dist/barrel-CFOWSjcM.mjs.map +0 -1
- package/dist/transformers-DAMi6ZOq.mjs +0 -2
- package/dist/transformers-DAMi6ZOq.mjs.map +0 -1
- package/dist.commonjs/advancedBarrel-CJL3rfuW.d.ts.map +0 -1
- package/dist.commonjs/barrel-DZkApbAR.js.map +0 -1
- package/dist.commonjs/transformers-C6jbFO7W.js +0 -2
- package/dist.commonjs/transformers-C6jbFO7W.js.map +0 -1
package/package.json
CHANGED
package/src/ckb/epoch.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { ClientBlockHeader } from "../client/clientTypes.js";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
codec,
|
|
4
|
+
codecPadding,
|
|
5
|
+
codecUint,
|
|
6
|
+
DecodedType,
|
|
7
|
+
Entity,
|
|
8
|
+
} from "../codec/index.js";
|
|
3
9
|
import { Zero } from "../fixedPoint/index.js";
|
|
4
10
|
import { type Hex, type HexLike } from "../hex/index.js";
|
|
5
11
|
import { mol } from "../molecule/index.js";
|
|
@@ -36,6 +42,13 @@ export type EpochLike =
|
|
|
36
42
|
| Num
|
|
37
43
|
| Hex;
|
|
38
44
|
|
|
45
|
+
const EpochCodec = mol.struct({
|
|
46
|
+
padding: codecPadding(1),
|
|
47
|
+
denominator: codecUint(2),
|
|
48
|
+
numerator: codecUint(2),
|
|
49
|
+
integer: codecUint(3),
|
|
50
|
+
});
|
|
51
|
+
|
|
39
52
|
/**
|
|
40
53
|
* Epoch
|
|
41
54
|
*
|
|
@@ -55,15 +68,12 @@ export type EpochLike =
|
|
|
55
68
|
* @remarks
|
|
56
69
|
* This class is primarily a thin value-object; operations return new Epoch instances.
|
|
57
70
|
*/
|
|
58
|
-
@codec(
|
|
59
|
-
mol.struct({
|
|
60
|
-
padding: codecPadding(1),
|
|
61
|
-
denominator: codecUint(2),
|
|
62
|
-
numerator: codecUint(2),
|
|
63
|
-
integer: codecUint(3),
|
|
64
|
-
}),
|
|
65
|
-
)
|
|
71
|
+
@codec(EpochCodec)
|
|
66
72
|
export class Epoch extends Entity.Base<EpochLike, Epoch>() {
|
|
73
|
+
public readonly integer: Num;
|
|
74
|
+
public readonly numerator: Num;
|
|
75
|
+
public readonly denominator: Num;
|
|
76
|
+
|
|
67
77
|
/**
|
|
68
78
|
* Construct a new Epoch instance.
|
|
69
79
|
*
|
|
@@ -71,12 +81,16 @@ export class Epoch extends Entity.Base<EpochLike, Epoch>() {
|
|
|
71
81
|
* @param numerator - Fractional numerator (Num).
|
|
72
82
|
* @param denominator - Fractional denominator (Num).
|
|
73
83
|
*/
|
|
74
|
-
public constructor(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
) {
|
|
84
|
+
public constructor({
|
|
85
|
+
integer,
|
|
86
|
+
numerator,
|
|
87
|
+
denominator,
|
|
88
|
+
}: Omit<DecodedType<typeof EpochCodec>, "padding">) {
|
|
79
89
|
super();
|
|
90
|
+
|
|
91
|
+
this.integer = integer;
|
|
92
|
+
this.numerator = numerator;
|
|
93
|
+
this.denominator = denominator;
|
|
80
94
|
}
|
|
81
95
|
|
|
82
96
|
/**
|
|
@@ -229,11 +243,11 @@ export class Epoch extends Entity.Base<EpochLike, Epoch>() {
|
|
|
229
243
|
static fromNum(v: NumLike): Epoch {
|
|
230
244
|
const num = numFrom(v);
|
|
231
245
|
|
|
232
|
-
return
|
|
233
|
-
num & numFrom("0xffffff"),
|
|
234
|
-
(num >> numFrom(24)) & numFrom("0xffff"),
|
|
235
|
-
(num >> numFrom(40)) & numFrom("0xffff"),
|
|
236
|
-
);
|
|
246
|
+
return Epoch.from({
|
|
247
|
+
integer: num & numFrom("0xffffff"),
|
|
248
|
+
numerator: (num >> numFrom(24)) & numFrom("0xffff"),
|
|
249
|
+
denominator: (num >> numFrom(40)) & numFrom("0xffff"),
|
|
250
|
+
});
|
|
237
251
|
}
|
|
238
252
|
|
|
239
253
|
/**
|
|
@@ -250,21 +264,25 @@ export class Epoch extends Entity.Base<EpochLike, Epoch>() {
|
|
|
250
264
|
* @param e - Value convertible to Epoch
|
|
251
265
|
* @returns Epoch instance
|
|
252
266
|
*/
|
|
253
|
-
static
|
|
267
|
+
static from(e: EpochLike): Epoch {
|
|
254
268
|
if (e instanceof Epoch) {
|
|
255
269
|
return e;
|
|
256
270
|
}
|
|
257
271
|
|
|
258
272
|
if (Array.isArray(e)) {
|
|
259
|
-
return new Epoch(
|
|
273
|
+
return new Epoch({
|
|
274
|
+
integer: numFrom(e[0]),
|
|
275
|
+
numerator: numFrom(e[1]),
|
|
276
|
+
denominator: numFrom(e[2]),
|
|
277
|
+
});
|
|
260
278
|
}
|
|
261
279
|
|
|
262
280
|
if (typeof e === "object") {
|
|
263
|
-
return new Epoch(
|
|
264
|
-
numFrom(e.integer),
|
|
265
|
-
numFrom(e.numerator),
|
|
266
|
-
numFrom(e.denominator),
|
|
267
|
-
);
|
|
281
|
+
return new Epoch({
|
|
282
|
+
integer: numFrom(e.integer),
|
|
283
|
+
numerator: numFrom(e.numerator),
|
|
284
|
+
denominator: numFrom(e.denominator),
|
|
285
|
+
});
|
|
268
286
|
}
|
|
269
287
|
|
|
270
288
|
return Epoch.fromNum(e);
|
package/src/ckb/script.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Bytes, BytesLike, bytesFrom } from "../bytes/index.js";
|
|
2
2
|
import type { Client } from "../client/index.js";
|
|
3
3
|
import { KnownScript } from "../client/knownScript.js";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Codec,
|
|
6
|
+
DecodedType,
|
|
7
|
+
EncodableType,
|
|
8
|
+
Entity,
|
|
9
|
+
codec,
|
|
10
|
+
} from "../codec/index.js";
|
|
5
11
|
import { Hex, HexLike, hexFrom } from "../hex/index.js";
|
|
6
12
|
import { mol } from "../molecule/index.js";
|
|
7
13
|
import {
|
|
@@ -98,25 +104,24 @@ export function hashTypeFromBytes(bytes: BytesLike): HashType {
|
|
|
98
104
|
return NUM_TO_HASH_TYPE[bytesFrom(bytes)[0]];
|
|
99
105
|
}
|
|
100
106
|
|
|
107
|
+
const ScriptCodec = mol.table({
|
|
108
|
+
codeHash: mol.Byte32,
|
|
109
|
+
hashType: HashTypeCodec,
|
|
110
|
+
args: mol.Bytes,
|
|
111
|
+
});
|
|
101
112
|
/**
|
|
102
113
|
* @public
|
|
103
114
|
*/
|
|
104
|
-
export type ScriptLike =
|
|
105
|
-
codeHash: BytesLike;
|
|
106
|
-
hashType: HashTypeLike;
|
|
107
|
-
args: BytesLike;
|
|
108
|
-
};
|
|
115
|
+
export type ScriptLike = EncodableType<typeof ScriptCodec>;
|
|
109
116
|
/**
|
|
110
117
|
* @public
|
|
111
118
|
*/
|
|
112
|
-
@codec(
|
|
113
|
-
mol.table({
|
|
114
|
-
codeHash: mol.Byte32,
|
|
115
|
-
hashType: HashTypeCodec,
|
|
116
|
-
args: mol.Bytes,
|
|
117
|
-
}),
|
|
118
|
-
)
|
|
119
|
+
@codec(ScriptCodec)
|
|
119
120
|
export class Script extends Entity.Base<ScriptLike, Script>() {
|
|
121
|
+
public codeHash: Hex;
|
|
122
|
+
public hashType: HashType;
|
|
123
|
+
public args: Hex;
|
|
124
|
+
|
|
120
125
|
/**
|
|
121
126
|
* Creates an instance of Script.
|
|
122
127
|
*
|
|
@@ -124,12 +129,12 @@ export class Script extends Entity.Base<ScriptLike, Script>() {
|
|
|
124
129
|
* @param hashType - The hash type of the script.
|
|
125
130
|
* @param args - The arguments for the script.
|
|
126
131
|
*/
|
|
127
|
-
constructor(
|
|
128
|
-
public codeHash: Hex,
|
|
129
|
-
public hashType: HashType,
|
|
130
|
-
public args: Hex,
|
|
131
|
-
) {
|
|
132
|
+
constructor({ codeHash, hashType, args }: DecodedType<typeof ScriptCodec>) {
|
|
132
133
|
super();
|
|
134
|
+
|
|
135
|
+
this.codeHash = codeHash;
|
|
136
|
+
this.hashType = hashType;
|
|
137
|
+
this.args = args;
|
|
133
138
|
}
|
|
134
139
|
|
|
135
140
|
get occupiedSize(): number {
|
|
@@ -174,34 +179,6 @@ export class Script extends Entity.Base<ScriptLike, Script>() {
|
|
|
174
179
|
);
|
|
175
180
|
}
|
|
176
181
|
|
|
177
|
-
/**
|
|
178
|
-
* Creates a Script instance from a ScriptLike object.
|
|
179
|
-
*
|
|
180
|
-
* @param script - A ScriptLike object or an instance of Script.
|
|
181
|
-
* @returns A Script instance.
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* const script = Script.from({
|
|
186
|
-
* codeHash: "0x1234...",
|
|
187
|
-
* hashType: "type",
|
|
188
|
-
* args: "0xabcd..."
|
|
189
|
-
* });
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
|
-
|
|
193
|
-
static from(script: ScriptLike): Script {
|
|
194
|
-
if (script instanceof Script) {
|
|
195
|
-
return script;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return new Script(
|
|
199
|
-
hexFrom(script.codeHash),
|
|
200
|
-
hashTypeFrom(script.hashType),
|
|
201
|
-
hexFrom(script.args),
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
182
|
/**
|
|
206
183
|
* Creates a Script instance from client and known script.
|
|
207
184
|
*
|