@ckb-ccc/core 0.1.2 → 1.0.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.
- package/CHANGELOG.md +6 -0
- package/dist/barrel.d.ts +1 -1
- package/dist/barrel.d.ts.map +1 -1
- package/dist/barrel.js +1 -1
- package/dist/bytes/index.d.ts +14 -0
- package/dist/bytes/index.d.ts.map +1 -1
- package/dist/bytes/index.js +29 -0
- package/dist/ckb/advanced.d.ts +0 -1
- package/dist/ckb/advanced.d.ts.map +1 -1
- package/dist/ckb/advanced.js +0 -1
- package/dist/ckb/script.d.ts +17 -58
- package/dist/ckb/script.d.ts.map +1 -1
- package/dist/ckb/script.js +31 -78
- package/dist/ckb/transaction.d.ts +114 -260
- package/dist/ckb/transaction.d.ts.map +1 -1
- package/dist/ckb/transaction.js +162 -358
- package/dist/molecule/barrel.d.ts +4 -0
- package/dist/molecule/barrel.d.ts.map +1 -0
- package/dist/molecule/barrel.js +3 -0
- package/dist/molecule/codec.d.ts.map +1 -1
- package/dist/molecule/codec.js +6 -3
- package/dist/molecule/entity.d.ts +98 -0
- package/dist/molecule/entity.d.ts.map +1 -0
- package/dist/molecule/entity.js +113 -0
- package/dist/molecule/index.d.ts +1 -2
- package/dist/molecule/index.d.ts.map +1 -1
- package/dist/molecule/index.js +1 -2
- package/dist/molecule/predefined.d.ts +13 -20
- package/dist/molecule/predefined.d.ts.map +1 -1
- package/dist/molecule/predefined.js +14 -54
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist.commonjs/barrel.d.ts +1 -1
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +1 -14
- package/dist.commonjs/bytes/index.d.ts +14 -0
- package/dist.commonjs/bytes/index.d.ts.map +1 -1
- package/dist.commonjs/bytes/index.js +30 -0
- package/dist.commonjs/ckb/advanced.d.ts +0 -1
- package/dist.commonjs/ckb/advanced.d.ts.map +1 -1
- package/dist.commonjs/ckb/advanced.js +0 -14
- package/dist.commonjs/ckb/script.d.ts +17 -58
- package/dist.commonjs/ckb/script.d.ts.map +1 -1
- package/dist.commonjs/ckb/script.js +31 -102
- package/dist.commonjs/ckb/transaction.d.ts +114 -260
- package/dist.commonjs/ckb/transaction.d.ts.map +1 -1
- package/dist.commonjs/ckb/transaction.js +182 -408
- package/dist.commonjs/molecule/barrel.d.ts +4 -0
- package/dist.commonjs/molecule/barrel.d.ts.map +1 -0
- package/dist.commonjs/{ckb/molecule.advanced/index.js → molecule/barrel.js} +3 -8
- package/dist.commonjs/molecule/codec.d.ts.map +1 -1
- package/dist.commonjs/molecule/codec.js +6 -3
- package/dist.commonjs/molecule/entity.d.ts +98 -0
- package/dist.commonjs/molecule/entity.d.ts.map +1 -0
- package/dist.commonjs/molecule/entity.js +118 -0
- package/dist.commonjs/molecule/index.d.ts +1 -2
- package/dist.commonjs/molecule/index.d.ts.map +1 -1
- package/dist.commonjs/molecule/index.js +13 -4
- package/dist.commonjs/molecule/predefined.d.ts +13 -20
- package/dist.commonjs/molecule/predefined.d.ts.map +1 -1
- package/dist.commonjs/molecule/predefined.js +14 -77
- package/dist.commonjs/utils/index.d.ts +3 -0
- package/dist.commonjs/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/barrel.ts +1 -1
- package/src/bytes/index.ts +34 -0
- package/src/ckb/advanced.ts +0 -1
- package/src/ckb/script.ts +22 -85
- package/src/ckb/transaction.ts +134 -412
- package/src/molecule/barrel.ts +3 -0
- package/src/molecule/codec.ts +9 -5
- package/src/molecule/entity.ts +163 -0
- package/src/molecule/index.ts +1 -2
- package/src/molecule/predefined.ts +20 -69
- package/src/utils/index.ts +5 -0
- package/dist/ckb/molecule.advanced/generated.d.ts +0 -355
- package/dist/ckb/molecule.advanced/generated.d.ts.map +0 -1
- package/dist/ckb/molecule.advanced/generated.js +0 -1468
- package/dist/ckb/molecule.advanced/index.d.ts +0 -6
- package/dist/ckb/molecule.advanced/index.d.ts.map +0 -1
- package/dist/ckb/molecule.advanced/index.js +0 -7
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts +0 -355
- package/dist.commonjs/ckb/molecule.advanced/generated.d.ts.map +0 -1
- package/dist.commonjs/ckb/molecule.advanced/generated.js +0 -1535
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts +0 -6
- package/dist.commonjs/ckb/molecule.advanced/index.d.ts.map +0 -1
- package/src/ckb/molecule.advanced/blockchain.mol +0 -118
- package/src/ckb/molecule.advanced/generated.d.ts +0 -444
- package/src/ckb/molecule.advanced/generated.js +0 -1804
- package/src/ckb/molecule.advanced/index.ts +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @ckb-ccc/core
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
3
9
|
## 0.1.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
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 *
|
|
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";
|
package/dist/barrel.d.ts.map
CHANGED
|
@@ -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,
|
|
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 *
|
|
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";
|
package/dist/bytes/index.d.ts
CHANGED
|
@@ -70,4 +70,18 @@ export declare function bytesTo(val: BytesLike, encoding: BytesFromEncoding): st
|
|
|
70
70
|
* ```
|
|
71
71
|
*/
|
|
72
72
|
export declare function bytesFrom(bytes: BytesLike, encoding?: BytesFromEncoding): Bytes;
|
|
73
|
+
/**
|
|
74
|
+
* Compares two byte-like values for equality.
|
|
75
|
+
* @public
|
|
76
|
+
*
|
|
77
|
+
* @param a - The first byte-like value to compare.
|
|
78
|
+
* @param b - The second byte-like value to compare.
|
|
79
|
+
* @returns A boolean indicating whether the two byte-like values are equal.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* bytesEq([1], Uint8Array.from([1])) // true
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function bytesEq(a: BytesLike, b: BytesLike): boolean;
|
|
73
87
|
//# 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;;;;;;;;;;;;;;;;;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;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,GAAG,OAAO,CAmB3D"}
|
package/dist/bytes/index.js
CHANGED
|
@@ -93,3 +93,32 @@ export function bytesFrom(bytes, encoding) {
|
|
|
93
93
|
}
|
|
94
94
|
return new Uint8Array(bytes);
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Compares two byte-like values for equality.
|
|
98
|
+
* @public
|
|
99
|
+
*
|
|
100
|
+
* @param a - The first byte-like value to compare.
|
|
101
|
+
* @param b - The second byte-like value to compare.
|
|
102
|
+
* @returns A boolean indicating whether the two byte-like values are equal.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* bytesEq([1], Uint8Array.from([1])) // true
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export function bytesEq(a, b) {
|
|
110
|
+
if (a === b) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
const x = bytesFrom(a);
|
|
114
|
+
const y = bytesFrom(b);
|
|
115
|
+
if (x.length !== y.length) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
for (let i = 0; i < x.length; i++) {
|
|
119
|
+
if (x[i] !== y[i]) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
package/dist/ckb/advanced.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/ckb/advanced.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/ckb/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC"}
|
package/dist/ckb/advanced.js
CHANGED
package/dist/ckb/script.d.ts
CHANGED
|
@@ -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
|
|
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 | Script): 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
|
package/dist/ckb/script.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AACzD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAW,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAO3C,eAAO,MAAM,aAAa,EAAE,GAAG,CAAC,KAAK,CAAC,YAAY,EAAE,QAAQ,CAI1D,CAAC;AAEH;;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,GAAG;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,YAAY,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB,CAAC;;;;;;;;;;;;;AACF;;GAEG;AACH,qBASa,MAAO,SAAQ,WAAqC;IAStD,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,QAAQ;IAClB,IAAI,EAAE,GAAG;IAVlB;;;;;;OAMG;gBAEM,QAAQ,EAAE,GAAG,EACb,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,GAAG;IAKlB,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;;;;;;;;OASG;IACH,KAAK,IAAI,MAAM;IAIf;;;;;;;;;;;;;;OAcG;IAEH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;IAYvC;;;;;;;;;;;;;;;;OAgBG;WAEU,eAAe,CAC1B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,MAAM,CAAC;CAUnB;AAED,eAAO,MAAM,SAAS,8DAAqB,CAAC"}
|
package/dist/ckb/script.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
|
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
|
|
131
|
+
if (script instanceof Script_1) {
|
|
120
132
|
return script;
|
|
121
133
|
}
|
|
122
|
-
return new
|
|
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,17 @@ export class Script {
|
|
|
140
152
|
*/
|
|
141
153
|
static async fromKnownScript(client, knownScript, args) {
|
|
142
154
|
const script = await client.getKnownScript(knownScript);
|
|
143
|
-
return new
|
|
155
|
+
return new Script_1(script.codeHash, script.hashType, hexFrom(args));
|
|
144
156
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
|
160
|
+
.table({
|
|
161
|
+
codeHash: mol.Byte32,
|
|
162
|
+
hashType: HashTypeCodec,
|
|
163
|
+
args: mol.Bytes,
|
|
164
|
+
})
|
|
165
|
+
.map({ outMap: (decoded) => Script.from(decoded) }))
|
|
166
|
+
], Script);
|
|
167
|
+
export { Script };
|
|
168
|
+
export const ScriptOpt = mol.option(Script);
|