@ckb-ccc/ssri 0.1.1 → 0.2.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 +13 -0
- package/dist/trait.d.ts +2 -0
- package/dist/trait.d.ts.map +1 -1
- package/dist/trait.js +22 -1
- package/dist.commonjs/trait.d.ts +2 -0
- package/dist.commonjs/trait.d.ts.map +1 -1
- package/dist.commonjs/trait.js +22 -1
- package/package.json +2 -2
- package/src/trait.ts +35 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @ckb-ccc/ssri
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`e4ea183`](https://github.com/ckb-devrel/ccc/commit/e4ea18359675877511550ac0b28f207550f907e4) Thanks [@Hanssen0](https://github.com/Hanssen0)! - feat(ssri): Trait.tryRun to handle expected error
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [`52ef11b`](https://github.com/ckb-devrel/ccc/commit/52ef11baa7bde8a73467683f5c44a863190aa1f1) Thanks [@Hanssen0](https://github.com/Hanssen0)! - fix(ssri): Trait.version() should throw if byteLength mismatch
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`3fdb2c4`](https://github.com/ckb-devrel/ccc/commit/3fdb2c477d0b2766b231e436b8f396f047b02634), [`f429087`](https://github.com/ckb-devrel/ccc/commit/f4290874dfab3fe58844e5169673c5d47bda64e3)]:
|
|
14
|
+
- @ckb-ccc/core@1.4.0
|
|
15
|
+
|
|
3
16
|
## 0.1.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/trait.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare class Trait {
|
|
|
12
12
|
* @param executor - The SSRI executor instance.
|
|
13
13
|
*/
|
|
14
14
|
constructor(code: ccc.OutPointLike, executor?: Executor | null);
|
|
15
|
+
static tryRun<T>(call: Promise<ExecutorResponse<T>>): Promise<ExecutorResponse<T | undefined>>;
|
|
16
|
+
tryRun<T>(call: Promise<ExecutorResponse<T>>): Promise<ExecutorResponse<T | undefined>>;
|
|
15
17
|
assertExecutor(): Executor;
|
|
16
18
|
/**
|
|
17
19
|
* Retrieves a list of methods.
|
package/dist/trait.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trait.d.ts","sourceRoot":"","sources":["../src/trait.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"trait.d.ts","sourceRoot":"","sources":["../src/trait.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EACL,QAAQ,EAGR,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAGvB;;GAEG;AACH,qBAAa,KAAK;IAChB,SAAgB,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC;IACnC,SAAgB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpC;;;;OAIG;gBACS,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI;WAKjD,MAAM,CAAC,CAAC,EACnB,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAcrC,MAAM,CAAC,CAAC,EACZ,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAI3C,cAAc;IAQd;;;;;OAKG;IACG,UAAU,CACd,MAAM,GAAE,GAAG,CAAC,OAAW,EACvB,KAAK,GAAE,GAAG,CAAC,OAAW,GACrB,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;IAUvC;;;;OAIG;IACG,UAAU,CACd,WAAW,EAAE,MAAM,EAAE,EACrB,gBAAgB,CAAC,EAAE,GAAG,CAAC,OAAO,EAAE,GAC/B,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;IAcvC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CAcpD"}
|
package/dist/trait.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { ExecutorErrorDecode, ExecutorErrorExecutionFailed, ExecutorResponse, } from "./executor.js";
|
|
2
3
|
import { getMethodPath } from "./utils.js";
|
|
3
4
|
/**
|
|
4
5
|
* Class representing an SSRI trait. Should be used as the base of all SSRI traits.
|
|
@@ -13,6 +14,21 @@ export class Trait {
|
|
|
13
14
|
this.code = ccc.OutPoint.from(code);
|
|
14
15
|
this.executor = executor ?? undefined;
|
|
15
16
|
}
|
|
17
|
+
static async tryRun(call) {
|
|
18
|
+
try {
|
|
19
|
+
return await call;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
if (e instanceof ExecutorErrorExecutionFailed ||
|
|
23
|
+
e instanceof ExecutorErrorDecode) {
|
|
24
|
+
return ExecutorResponse.new(undefined);
|
|
25
|
+
}
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async tryRun(call) {
|
|
30
|
+
return Trait.tryRun(call);
|
|
31
|
+
}
|
|
16
32
|
assertExecutor() {
|
|
17
33
|
if (!this.executor) {
|
|
18
34
|
throw new Error("SSRI executor is not set");
|
|
@@ -47,6 +63,11 @@ export class Trait {
|
|
|
47
63
|
*/
|
|
48
64
|
async version() {
|
|
49
65
|
const res = await this.assertExecutor().runScript(this.code, "SSRI.version", []);
|
|
50
|
-
return res.map((res) =>
|
|
66
|
+
return res.map((res) => {
|
|
67
|
+
if (res.length !== 4) {
|
|
68
|
+
throw new Error("Invalid U8");
|
|
69
|
+
}
|
|
70
|
+
return ccc.numFrom(res);
|
|
71
|
+
});
|
|
51
72
|
}
|
|
52
73
|
}
|
package/dist.commonjs/trait.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare class Trait {
|
|
|
12
12
|
* @param executor - The SSRI executor instance.
|
|
13
13
|
*/
|
|
14
14
|
constructor(code: ccc.OutPointLike, executor?: Executor | null);
|
|
15
|
+
static tryRun<T>(call: Promise<ExecutorResponse<T>>): Promise<ExecutorResponse<T | undefined>>;
|
|
16
|
+
tryRun<T>(call: Promise<ExecutorResponse<T>>): Promise<ExecutorResponse<T | undefined>>;
|
|
15
17
|
assertExecutor(): Executor;
|
|
16
18
|
/**
|
|
17
19
|
* Retrieves a list of methods.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trait.d.ts","sourceRoot":"","sources":["../src/trait.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"trait.d.ts","sourceRoot":"","sources":["../src/trait.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EACL,QAAQ,EAGR,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAGvB;;GAEG;AACH,qBAAa,KAAK;IAChB,SAAgB,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC;IACnC,SAAgB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpC;;;;OAIG;gBACS,IAAI,EAAE,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI;WAKjD,MAAM,CAAC,CAAC,EACnB,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAcrC,MAAM,CAAC,CAAC,EACZ,IAAI,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IAI3C,cAAc;IAQd;;;;;OAKG;IACG,UAAU,CACd,MAAM,GAAE,GAAG,CAAC,OAAW,EACvB,KAAK,GAAE,GAAG,CAAC,OAAW,GACrB,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;IAUvC;;;;OAIG;IACG,UAAU,CACd,WAAW,EAAE,MAAM,EAAE,EACrB,gBAAgB,CAAC,EAAE,GAAG,CAAC,OAAO,EAAE,GAC/B,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;IAcvC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CAcpD"}
|
package/dist.commonjs/trait.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Trait = void 0;
|
|
4
4
|
const core_1 = require("@ckb-ccc/core");
|
|
5
|
+
const executor_js_1 = require("./executor.js");
|
|
5
6
|
const utils_js_1 = require("./utils.js");
|
|
6
7
|
/**
|
|
7
8
|
* Class representing an SSRI trait. Should be used as the base of all SSRI traits.
|
|
@@ -16,6 +17,21 @@ class Trait {
|
|
|
16
17
|
this.code = core_1.ccc.OutPoint.from(code);
|
|
17
18
|
this.executor = executor ?? undefined;
|
|
18
19
|
}
|
|
20
|
+
static async tryRun(call) {
|
|
21
|
+
try {
|
|
22
|
+
return await call;
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
if (e instanceof executor_js_1.ExecutorErrorExecutionFailed ||
|
|
26
|
+
e instanceof executor_js_1.ExecutorErrorDecode) {
|
|
27
|
+
return executor_js_1.ExecutorResponse.new(undefined);
|
|
28
|
+
}
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async tryRun(call) {
|
|
33
|
+
return Trait.tryRun(call);
|
|
34
|
+
}
|
|
19
35
|
assertExecutor() {
|
|
20
36
|
if (!this.executor) {
|
|
21
37
|
throw new Error("SSRI executor is not set");
|
|
@@ -50,7 +66,12 @@ class Trait {
|
|
|
50
66
|
*/
|
|
51
67
|
async version() {
|
|
52
68
|
const res = await this.assertExecutor().runScript(this.code, "SSRI.version", []);
|
|
53
|
-
return res.map((res) =>
|
|
69
|
+
return res.map((res) => {
|
|
70
|
+
if (res.length !== 4) {
|
|
71
|
+
throw new Error("Invalid U8");
|
|
72
|
+
}
|
|
73
|
+
return core_1.ccc.numFrom(res);
|
|
74
|
+
});
|
|
54
75
|
}
|
|
55
76
|
}
|
|
56
77
|
exports.Trait = Trait;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/ssri",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "SSRI",
|
|
5
5
|
"author": "Alive24 <xct24@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ckb-ccc/core": "1.
|
|
45
|
+
"@ckb-ccc/core": "1.4.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"test": "jest",
|
package/src/trait.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Executor,
|
|
4
|
+
ExecutorErrorDecode,
|
|
5
|
+
ExecutorErrorExecutionFailed,
|
|
6
|
+
ExecutorResponse,
|
|
7
|
+
} from "./executor.js";
|
|
3
8
|
import { getMethodPath } from "./utils.js";
|
|
4
9
|
|
|
5
10
|
/**
|
|
@@ -19,6 +24,28 @@ export class Trait {
|
|
|
19
24
|
this.executor = executor ?? undefined;
|
|
20
25
|
}
|
|
21
26
|
|
|
27
|
+
static async tryRun<T>(
|
|
28
|
+
call: Promise<ExecutorResponse<T>>,
|
|
29
|
+
): Promise<ExecutorResponse<T | undefined>> {
|
|
30
|
+
try {
|
|
31
|
+
return await call;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
if (
|
|
34
|
+
e instanceof ExecutorErrorExecutionFailed ||
|
|
35
|
+
e instanceof ExecutorErrorDecode
|
|
36
|
+
) {
|
|
37
|
+
return ExecutorResponse.new(undefined);
|
|
38
|
+
}
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async tryRun<T>(
|
|
44
|
+
call: Promise<ExecutorResponse<T>>,
|
|
45
|
+
): Promise<ExecutorResponse<T | undefined>> {
|
|
46
|
+
return Trait.tryRun(call);
|
|
47
|
+
}
|
|
48
|
+
|
|
22
49
|
assertExecutor() {
|
|
23
50
|
if (!this.executor) {
|
|
24
51
|
throw new Error("SSRI executor is not set");
|
|
@@ -78,6 +105,12 @@ export class Trait {
|
|
|
78
105
|
"SSRI.version",
|
|
79
106
|
[],
|
|
80
107
|
);
|
|
81
|
-
|
|
108
|
+
|
|
109
|
+
return res.map((res) => {
|
|
110
|
+
if (res.length !== 4) {
|
|
111
|
+
throw new Error("Invalid U8");
|
|
112
|
+
}
|
|
113
|
+
return ccc.numFrom(res);
|
|
114
|
+
});
|
|
82
115
|
}
|
|
83
116
|
}
|