@ckb-ccc/ssri 0.2.23 → 0.3.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 +19 -0
- package/dist/barrel.d.mts +103 -0
- package/dist/barrel.d.mts.map +1 -0
- package/dist/barrel.mjs +2 -0
- package/dist/barrel.mjs.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/rolldown-runtime-DK3Fl9T5.mjs +1 -0
- package/dist.commonjs/barrel.d.ts +104 -3
- package/dist.commonjs/barrel.d.ts.map +1 -1
- package/dist.commonjs/barrel.js +2 -19
- package/dist.commonjs/barrel.js.map +1 -0
- package/dist.commonjs/index.d.ts +2 -2
- package/dist.commonjs/index.js +1 -37
- package/package.json +20 -19
- package/tsdown.config.mts +41 -0
- package/dist/barrel.d.ts +0 -4
- package/dist/barrel.d.ts.map +0 -1
- package/dist/barrel.js +0 -3
- package/dist/executor.d.ts +0 -57
- package/dist/executor.d.ts.map +0 -1
- package/dist/executor.js +0 -136
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -1
- package/dist/trait.d.ts +0 -37
- package/dist/trait.d.ts.map +0 -1
- package/dist/trait.js +0 -73
- package/dist/utils.d.ts +0 -3
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -4
- package/dist.commonjs/executor.d.ts +0 -57
- package/dist.commonjs/executor.d.ts.map +0 -1
- package/dist.commonjs/executor.js +0 -145
- package/dist.commonjs/index.d.ts.map +0 -1
- package/dist.commonjs/trait.d.ts +0 -37
- package/dist.commonjs/trait.d.ts.map +0 -1
- package/dist.commonjs/trait.js +0 -77
- package/dist.commonjs/utils.d.ts +0 -3
- package/dist.commonjs/utils.d.ts.map +0 -1
- package/dist.commonjs/utils.js +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ckb-ccc/ssri
|
|
2
2
|
|
|
3
|
+
## 0.3.1
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- Updated dependencies [[`98597b5`](https://github.com/ckb-devrel/ccc/commit/98597b56eb6eeb029b72ea963649155dfe1f4215), [`bef9d0a`](https://github.com/ckb-devrel/ccc/commit/bef9d0a037fba045eab24d7ad55400fa26fbbffd), [`8067a08`](https://github.com/ckb-devrel/ccc/commit/8067a08de041ffd7a624adea0b594eb283e2634e), [`7019a1a`](https://github.com/ckb-devrel/ccc/commit/7019a1a7f765dfa7940cdfe51474bcd347f18ec6), [`9beee4d`](https://github.com/ckb-devrel/ccc/commit/9beee4d7f39e4b4b19919c5feb86e1c8be0e089d), [`2d4e701`](https://github.com/ckb-devrel/ccc/commit/2d4e701e54e9bf5247c2363490009acc5606c0ea), [`0eb8435`](https://github.com/ckb-devrel/ccc/commit/0eb8435d9694602fce3b7e6a95f04f793452a88d)]:
|
|
7
|
+
- @ckb-ccc/core@1.15.0
|
|
8
|
+
|
|
9
|
+
## 0.3.0
|
|
10
|
+
### Minor Changes
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
- [#381](https://github.com/ckb-devrel/ccc/pull/381) [`46cc045`](https://github.com/ckb-devrel/ccc/commit/46cc045a3eefe9ba6625482dc7f740a0c59c99d4) Thanks [@Hanssen0](https://github.com/Hanssen0)! - chore: bump packages
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`46cc045`](https://github.com/ckb-devrel/ccc/commit/46cc045a3eefe9ba6625482dc7f740a0c59c99d4)]:
|
|
20
|
+
- @ckb-ccc/core@1.14.0
|
|
21
|
+
|
|
3
22
|
## 0.2.23
|
|
4
23
|
### Patch Changes
|
|
5
24
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
|
|
3
|
+
//#region src/executor.d.ts
|
|
4
|
+
type ContextTransaction = {
|
|
5
|
+
script?: ccc.ScriptLike | null;
|
|
6
|
+
cell?: ccc.CellAnyLike | null;
|
|
7
|
+
tx: ccc.TransactionLike;
|
|
8
|
+
};
|
|
9
|
+
type ContextCell = {
|
|
10
|
+
script?: ccc.ScriptLike | null;
|
|
11
|
+
cell: ccc.CellAnyLike;
|
|
12
|
+
tx?: undefined | null;
|
|
13
|
+
};
|
|
14
|
+
type ContextScript = {
|
|
15
|
+
script: ccc.ScriptLike;
|
|
16
|
+
cell?: undefined | null;
|
|
17
|
+
tx?: undefined | null;
|
|
18
|
+
};
|
|
19
|
+
declare class ExecutorErrorUnknown extends Error {
|
|
20
|
+
constructor(msg?: string);
|
|
21
|
+
}
|
|
22
|
+
declare class ExecutorErrorExecutionFailed extends Error {
|
|
23
|
+
constructor(msg?: string);
|
|
24
|
+
}
|
|
25
|
+
declare class ExecutorErrorDecode extends Error {
|
|
26
|
+
constructor(msg?: string);
|
|
27
|
+
}
|
|
28
|
+
type ContextCode = undefined | {
|
|
29
|
+
script?: undefined | null;
|
|
30
|
+
cell?: undefined | null;
|
|
31
|
+
tx?: undefined | null;
|
|
32
|
+
};
|
|
33
|
+
declare class ExecutorResponse<T> {
|
|
34
|
+
readonly res: T;
|
|
35
|
+
readonly cellDeps: ccc.OutPoint[];
|
|
36
|
+
constructor(res: T, cellDeps: ccc.OutPoint[]);
|
|
37
|
+
static new<T>(res: T, cellDeps?: ccc.OutPointLike[] | null): ExecutorResponse<T>;
|
|
38
|
+
map<U>(fn: (res: T) => U): ExecutorResponse<U>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents an SSRI executor.
|
|
42
|
+
*/
|
|
43
|
+
declare abstract class Executor {
|
|
44
|
+
abstract runScript(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex>>;
|
|
45
|
+
runScriptTry(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex> | undefined>;
|
|
46
|
+
}
|
|
47
|
+
declare class ExecutorJsonRpc extends Executor {
|
|
48
|
+
readonly requestor: ccc.RequestorJsonRpc;
|
|
49
|
+
/**
|
|
50
|
+
* Creates an instance of SSRI executor through Json RPC.
|
|
51
|
+
* @param {string} [url] - The external server URL.
|
|
52
|
+
*/
|
|
53
|
+
constructor(url: string, config?: ccc.RequestorJsonRpcConfig & {
|
|
54
|
+
requestor?: ccc.RequestorJsonRpc;
|
|
55
|
+
});
|
|
56
|
+
get url(): string;
|
|
57
|
+
runScript(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex>>;
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/trait.d.ts
|
|
61
|
+
/**
|
|
62
|
+
* Class representing an SSRI trait. Should be used as the base of all SSRI traits.
|
|
63
|
+
*/
|
|
64
|
+
declare class Trait {
|
|
65
|
+
readonly code: ccc.OutPoint;
|
|
66
|
+
readonly executor?: Executor;
|
|
67
|
+
/**
|
|
68
|
+
* Creates an instance of SSRI trait.
|
|
69
|
+
* @param code - The cell dependency.
|
|
70
|
+
* @param executor - The SSRI executor instance.
|
|
71
|
+
*/
|
|
72
|
+
constructor(code: ccc.OutPointLike, executor?: Executor | null);
|
|
73
|
+
static tryRun<T>(call: Promise<ExecutorResponse<T>>): Promise<ExecutorResponse<T | undefined>>;
|
|
74
|
+
tryRun<T>(call: Promise<ExecutorResponse<T>>): Promise<ExecutorResponse<T | undefined>>;
|
|
75
|
+
assertExecutor(): Executor;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves a list of methods.
|
|
78
|
+
* @param offset - The offset for the methods.
|
|
79
|
+
* @param limit - The limit for the methods.
|
|
80
|
+
* @returns {Promise<Bytes[]>} A promise that resolves to a list of methods.
|
|
81
|
+
*/
|
|
82
|
+
getMethods(offset?: ccc.NumLike, limit?: ccc.NumLike): Promise<ExecutorResponse<ccc.Hex[]>>;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the specified methods exist.
|
|
85
|
+
* @param methodNames - The methods to check.
|
|
86
|
+
* @returns A promise that resolves to an array of booleans indicating if methods exist.
|
|
87
|
+
*/
|
|
88
|
+
hasMethods(methodNames: string[], extraMethodPaths?: ccc.HexLike[]): Promise<ExecutorResponse<boolean[]>>;
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves the version of the trait.
|
|
91
|
+
* @returns A promise that resolves to the version number.
|
|
92
|
+
*/
|
|
93
|
+
version(): Promise<ExecutorResponse<ccc.Num>>;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/utils.d.ts
|
|
97
|
+
declare function getMethodPath(method: string): ccc.Hex;
|
|
98
|
+
declare namespace barrel_d_exports {
|
|
99
|
+
export { ContextCell, ContextCode, ContextScript, ContextTransaction, Executor, ExecutorErrorDecode, ExecutorErrorExecutionFailed, ExecutorErrorUnknown, ExecutorJsonRpc, ExecutorResponse, Trait, getMethodPath };
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
export { ContextCell, ContextCode, ContextScript, ContextTransaction, Executor, ExecutorErrorDecode, ExecutorErrorExecutionFailed, ExecutorErrorUnknown, ExecutorJsonRpc, ExecutorResponse, Trait, getMethodPath, barrel_d_exports as t };
|
|
103
|
+
//# sourceMappingURL=barrel.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.d.mts","names":[],"sources":["../src/executor.ts","../src/trait.ts","../src/utils.ts","../src/barrel.ts"],"mappings":";;;KAIY,kBAAA;EACV,MAAA,GAAS,GAAA,CAAI,UAAA;EACb,IAAA,GAAO,GAAA,CAAI,WAAA;EACX,EAAA,EAAI,GAAA,CAAI,eAAA;AAAA;AAAA,KAGE,WAAA;EACV,MAAA,GAAS,GAAA,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3Fl9T5.mjs";import{ccc as t}from"@ckb-ccc/core";import{cccA as n}from"@ckb-ccc/core/advanced";function r(e){return t.hashCkb(t.bytesFrom(e,`utf8`)).slice(0,18)}var i=class extends Error{constructor(e){super(e)}},a=class extends Error{constructor(e){super(e)}},o=class extends Error{constructor(e){super(e)}},s=class e{constructor(e,t){this.res=e,this.cellDeps=t}static new(n,r){return new e(n,r?.map(t.OutPoint.from)??[])}map(t){try{return new e(t(this.res),this.cellDeps)}catch(e){throw new o(JSON.stringify(e))}}},c=class{async runScriptTry(e,t,n,r){try{return await this.runScript(e,t,n,r)}catch(e){if(e instanceof a)return;throw e}}},l=class extends c{constructor(e,n){super(),this.requestor=n?.requestor??new t.RequestorJsonRpc(e,n,e=>{throw typeof e!=`object`||!e||!(`code`in e)||typeof e.code!=`number`?new i(JSON.stringify(e)):e.code===1003||e.code===1004?`message`in e&&typeof e.message==`string`?new a(e.message):new a:`message`in e&&typeof e.message==`string`?new i(e.message):new i})}get url(){return this.requestor.url}async runScript(e,i,a,o){let c=t.OutPoint.from(e),[l,u]=(()=>{if(o?.tx){let e=t.Transaction.from(o.tx);return[`run_script_level_transaction`,[{inner:n.JsonRpcTransformers.transactionFrom(e),hash:e.hash()}]]}if(o?.cell){let e=t.CellAny.from(o.cell);return[`run_script_level_cell`,[{cell_output:n.JsonRpcTransformers.cellOutputFrom(e.cellOutput,e.outputData),hex_data:t.hexFrom(e.outputData)}]]}return o?.script?[`run_script_level_script`,[n.JsonRpcTransformers.scriptFrom(o.script)]]:[`run_script_level_code`,[]]})(),{content:d,cell_deps:f}=await this.requestor.request(l,[c.txHash,Number(c.index),[r(i),...a.map(t.hexFrom)],...u]);return s.new(d,f.map(n.JsonRpcTransformers.outPointTo))}},u=class e{constructor(e,n){this.code=t.OutPoint.from(e),this.executor=n??void 0}static async tryRun(e){try{return await e}catch(e){if(e instanceof a||e instanceof o)return s.new(void 0);throw e}}async tryRun(t){return e.tryRun(t)}assertExecutor(){if(!this.executor)throw Error(`SSRI executor is not set`);return this.executor}async getMethods(e=0,n=0){return(await this.assertExecutor().runScript(this.code,`SSRI.get_methods`,[t.numToBytes(e??0,8),t.numToBytes(n??0,8)])).map(e=>t.mol.Byte8Vec.decode(e))}async hasMethods(e,n){let i=t.mol.Byte8Vec.encode(e.map(r).concat(n?.map(t.hexFrom)??[]));return(await this.assertExecutor().runScript(this.code,`SSRI.has_methods`,[i])).map(e=>t.mol.BoolVec.decode(e))}async version(){return(await this.assertExecutor().runScript(this.code,`SSRI.version`,[])).map(e=>{if(e.length!==4)throw Error(`Invalid U8`);return t.numFrom(e)})}},d=e({Executor:()=>c,ExecutorErrorDecode:()=>o,ExecutorErrorExecutionFailed:()=>a,ExecutorErrorUnknown:()=>i,ExecutorJsonRpc:()=>l,ExecutorResponse:()=>s,Trait:()=>u,getMethodPath:()=>r});export{c as Executor,o as ExecutorErrorDecode,a as ExecutorErrorExecutionFailed,i as ExecutorErrorUnknown,l as ExecutorJsonRpc,s as ExecutorResponse,u as Trait,r as getMethodPath,d as t};
|
|
2
|
+
//# sourceMappingURL=barrel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.mjs","names":[],"sources":["../src/utils.ts","../src/executor.ts","../src/trait.ts","../src/barrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\n\nexport function getMethodPath(method: string): ccc.Hex {\n return ccc.hashCkb(ccc.bytesFrom(method, \"utf8\")).slice(0, 18) as ccc.Hex;\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { cccA } from \"@ckb-ccc/core/advanced\";\nimport { getMethodPath } from \"./utils.js\";\n\nexport type ContextTransaction = {\n script?: ccc.ScriptLike | null;\n cell?: ccc.CellAnyLike | null;\n tx: ccc.TransactionLike;\n};\n\nexport type ContextCell = {\n script?: ccc.ScriptLike | null;\n cell: ccc.CellAnyLike;\n tx?: undefined | null;\n};\n\nexport type ContextScript = {\n script: ccc.ScriptLike;\n cell?: undefined | null;\n tx?: undefined | null;\n};\n\nexport class ExecutorErrorUnknown extends Error {\n constructor(msg?: string) {\n super(msg);\n }\n}\n\nexport class ExecutorErrorExecutionFailed extends Error {\n constructor(msg?: string) {\n super(msg);\n }\n}\n\nexport class ExecutorErrorDecode extends Error {\n constructor(msg?: string) {\n super(msg);\n }\n}\n\nexport type ContextCode =\n | undefined\n | {\n script?: undefined | null;\n cell?: undefined | null;\n tx?: undefined | null;\n };\n\nexport class ExecutorResponse<T> {\n constructor(\n public readonly res: T,\n public readonly cellDeps: ccc.OutPoint[],\n ) {}\n\n static new<T>(res: T, cellDeps?: ccc.OutPointLike[] | null) {\n return new ExecutorResponse(res, cellDeps?.map(ccc.OutPoint.from) ?? []);\n }\n\n map<U>(fn: (res: T) => U): ExecutorResponse<U> {\n try {\n return new ExecutorResponse(fn(this.res), this.cellDeps);\n } catch (err) {\n throw new ExecutorErrorDecode(JSON.stringify(err));\n }\n }\n}\n\n/**\n * Represents an SSRI executor.\n */\nexport abstract class Executor {\n abstract runScript(\n codeOutPoint: ccc.OutPointLike,\n method: string,\n args: ccc.HexLike[],\n context?: ContextCode | ContextScript | ContextCell | ContextTransaction,\n ): Promise<ExecutorResponse<ccc.Hex>>;\n\n async runScriptTry(\n codeOutPoint: ccc.OutPointLike,\n method: string,\n args: ccc.HexLike[],\n context?: ContextCode | ContextScript | ContextCell | ContextTransaction,\n ): Promise<ExecutorResponse<ccc.Hex> | undefined> {\n try {\n return await this.runScript(codeOutPoint, method, args, context);\n } catch (err) {\n if (err instanceof ExecutorErrorExecutionFailed) {\n return undefined;\n }\n throw err;\n }\n }\n}\n\nexport class ExecutorJsonRpc extends Executor {\n public readonly requestor: ccc.RequestorJsonRpc;\n\n /**\n * Creates an instance of SSRI executor through Json RPC.\n * @param {string} [url] - The external server URL.\n */\n constructor(\n url: string,\n config?: ccc.RequestorJsonRpcConfig & { requestor?: ccc.RequestorJsonRpc },\n ) {\n super();\n\n this.requestor =\n config?.requestor ??\n new ccc.RequestorJsonRpc(url, config, (errAny) => {\n if (\n typeof errAny !== \"object\" ||\n errAny === null ||\n !(\"code\" in errAny) ||\n typeof errAny.code !== \"number\"\n ) {\n throw new ExecutorErrorUnknown(JSON.stringify(errAny));\n }\n\n if (errAny.code === 1003 || errAny.code === 1004) {\n if (\"message\" in errAny && typeof errAny.message === \"string\") {\n throw new ExecutorErrorExecutionFailed(errAny.message);\n }\n throw new ExecutorErrorExecutionFailed();\n }\n\n if (\"message\" in errAny && typeof errAny.message === \"string\") {\n throw new ExecutorErrorUnknown(errAny.message);\n }\n throw new ExecutorErrorUnknown();\n });\n }\n\n get url() {\n return this.requestor.url;\n }\n\n /* Calls a method on the SSRI executor through SSRI Server.\n * @param codeOutPoint - The code OutPoint.\n * @param method - The SSRI method.\n * @param args - The arguments for the method.\n * @param context - The SSRI context for the method.\n * @param context.script - The script level parameters.\n * @param context.cell - The cell level parameters. Take precedence over script.\n * @param context.transaction - The transaction level parameters. Take precedence over cell.\n * @returns The result of the call.\n */\n async runScript(\n codeOutPoint: ccc.OutPointLike,\n method: string,\n args: ccc.HexLike[],\n context?: ContextCode | ContextScript | ContextCell | ContextTransaction,\n ): Promise<ExecutorResponse<ccc.Hex>> {\n const code = ccc.OutPoint.from(codeOutPoint);\n const [rpcMethod, rpcContext] = (() => {\n if (context?.tx) {\n const tx = ccc.Transaction.from(context.tx);\n return [\n \"run_script_level_transaction\",\n [\n {\n inner: cccA.JsonRpcTransformers.transactionFrom(tx),\n hash: tx.hash(),\n },\n ],\n ];\n }\n if (context?.cell) {\n const cell = ccc.CellAny.from(context.cell);\n\n return [\n \"run_script_level_cell\",\n [\n {\n cell_output: cccA.JsonRpcTransformers.cellOutputFrom(\n cell.cellOutput,\n cell.outputData,\n ),\n hex_data: ccc.hexFrom(cell.outputData),\n },\n ],\n ];\n }\n if (context?.script) {\n return [\n \"run_script_level_script\",\n [cccA.JsonRpcTransformers.scriptFrom(context.script)],\n ];\n }\n return [\"run_script_level_code\", []];\n })();\n\n const { content, cell_deps } = (await this.requestor.request(rpcMethod, [\n code.txHash,\n Number(code.index),\n [getMethodPath(method), ...args.map(ccc.hexFrom)],\n ...rpcContext,\n ])) as { content: ccc.Hex; cell_deps: cccA.JsonRpcOutPoint[] };\n\n return ExecutorResponse.new(\n content,\n cell_deps.map(cccA.JsonRpcTransformers.outPointTo),\n );\n }\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport {\n Executor,\n ExecutorErrorDecode,\n ExecutorErrorExecutionFailed,\n ExecutorResponse,\n} from \"./executor.js\";\nimport { getMethodPath } from \"./utils.js\";\n\n/**\n * Class representing an SSRI trait. Should be used as the base of all SSRI traits.\n */\nexport class Trait {\n public readonly code: ccc.OutPoint;\n public readonly executor?: Executor;\n\n /**\n * Creates an instance of SSRI trait.\n * @param code - The cell dependency.\n * @param executor - The SSRI executor instance.\n */\n constructor(code: ccc.OutPointLike, executor?: Executor | null) {\n this.code = ccc.OutPoint.from(code);\n this.executor = executor ?? undefined;\n }\n\n static async tryRun<T>(\n call: Promise<ExecutorResponse<T>>,\n ): Promise<ExecutorResponse<T | undefined>> {\n try {\n return await call;\n } catch (e) {\n if (\n e instanceof ExecutorErrorExecutionFailed ||\n e instanceof ExecutorErrorDecode\n ) {\n return ExecutorResponse.new(undefined);\n }\n throw e;\n }\n }\n\n async tryRun<T>(\n call: Promise<ExecutorResponse<T>>,\n ): Promise<ExecutorResponse<T | undefined>> {\n return Trait.tryRun(call);\n }\n\n assertExecutor() {\n if (!this.executor) {\n throw new Error(\"SSRI executor is not set\");\n }\n\n return this.executor;\n }\n\n /**\n * Retrieves a list of methods.\n * @param offset - The offset for the methods.\n * @param limit - The limit for the methods.\n * @returns {Promise<Bytes[]>} A promise that resolves to a list of methods.\n */\n async getMethods(\n offset: ccc.NumLike = 0,\n limit: ccc.NumLike = 0,\n ): Promise<ExecutorResponse<ccc.Hex[]>> {\n const res = await this.assertExecutor().runScript(\n this.code,\n \"SSRI.get_methods\",\n [ccc.numToBytes(offset ?? 0, 8), ccc.numToBytes(limit ?? 0, 8)],\n );\n\n return res.map((res) => ccc.mol.Byte8Vec.decode(res));\n }\n\n /**\n * Checks if the specified methods exist.\n * @param methodNames - The methods to check.\n * @returns A promise that resolves to an array of booleans indicating if methods exist.\n */\n async hasMethods(\n methodNames: string[],\n extraMethodPaths?: ccc.HexLike[],\n ): Promise<ExecutorResponse<boolean[]>> {\n const methodPaths = ccc.mol.Byte8Vec.encode(\n methodNames\n .map(getMethodPath)\n .concat(extraMethodPaths?.map(ccc.hexFrom) ?? []),\n );\n const res = await this.assertExecutor().runScript(\n this.code,\n \"SSRI.has_methods\",\n [methodPaths],\n );\n return res.map((res) => ccc.mol.BoolVec.decode(res));\n }\n\n /**\n * Retrieves the version of the trait.\n * @returns A promise that resolves to the version number.\n */\n async version(): Promise<ExecutorResponse<ccc.Num>> {\n const res = await this.assertExecutor().runScript(\n this.code,\n \"SSRI.version\",\n [],\n );\n\n return res.map((res) => {\n if (res.length !== 4) {\n throw new Error(\"Invalid U8\");\n }\n return ccc.numFrom(res);\n });\n }\n}\n","export * from \"./executor.js\";\nexport * from \"./trait.js\";\nexport * from \"./utils.js\";\n"],"mappings":"sIAEA,SAAgB,EAAc,EAAyB,CACrD,OAAO,EAAI,QAAQ,EAAI,UAAU,EAAQ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAG,EAAE,CAC/D,CCkBA,IAAa,EAAb,cAA0C,KAAM,CAC9C,YAAY,EAAc,CACxB,MAAM,CAAG,CACX,CACF,EAEa,EAAb,cAAkD,KAAM,CACtD,YAAY,EAAc,CACxB,MAAM,CAAG,CACX,CACF,EAEa,EAAb,cAAyC,KAAM,CAC7C,YAAY,EAAc,CACxB,MAAM,CAAG,CACX,CACF,EAUa,EAAb,MAAa,CAAoB,CAC/B,YACE,EACA,EACA,CAFgB,KAAA,IAAA,EACA,KAAA,SAAA,CACf,CAEH,OAAO,IAAO,EAAQ,EAAsC,CAC1D,OAAO,IAAI,EAAiB,EAAK,GAAU,IAAI,EAAI,S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K,GAAQ,EAAI,IAAI,SAAS,OAAO,CAAG,CAAC,CACtD,CAOA,MAAM,WACJ,EACA,EACsC,CACtC,IAAM,EAAc,EAAI,IAAI,SAAS,OACnC,EACG,IAAI,CAAa,CAAC,CAClB,OAAO,GAAkB,IAAI,EAAI,OAAO,GAAK,CAAC,CAAC,CACpD,EAMA,OAAO,MALW,KAAK,eAAe,CAAC,CAAC,UACtC,KAAK,KACL,mBACA,CAAC,CAAW,CACd,EAAA,CACW,IAAK,GAAQ,EAAI,IAAI,QAAQ,OAAO,CAAG,CAAC,CACrD,CAMA,MAAM,SAA8C,CAOlD,OAAO,MANW,KAAK,eAAe,CAAC,CAAC,UACtC,KAAK,KACL,eACA,CAAC,CACH,EAAA,CAEW,IAAK,GAAQ,CACtB,GAAI,EAAI,SAAW,EACjB,MAAU,MAAM,YAAY,EAE9B,OAAO,EAAI,QAAQ,CAAG,CACxB,CAAC,CACH,CACF"}
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./barrel.mjs";export{e as ssri};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};export{t};
|
|
@@ -1,4 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/executor.d.ts
|
|
6
|
+
type ContextTransaction = {
|
|
7
|
+
script?: ccc.ScriptLike | null;
|
|
8
|
+
cell?: ccc.CellAnyLike | null;
|
|
9
|
+
tx: ccc.TransactionLike;
|
|
10
|
+
};
|
|
11
|
+
type ContextCell = {
|
|
12
|
+
script?: ccc.ScriptLike | null;
|
|
13
|
+
cell: ccc.CellAnyLike;
|
|
14
|
+
tx?: undefined | null;
|
|
15
|
+
};
|
|
16
|
+
type ContextScript = {
|
|
17
|
+
script: ccc.ScriptLike;
|
|
18
|
+
cell?: undefined | null;
|
|
19
|
+
tx?: undefined | null;
|
|
20
|
+
};
|
|
21
|
+
declare class ExecutorErrorUnknown extends Error {
|
|
22
|
+
constructor(msg?: string);
|
|
23
|
+
}
|
|
24
|
+
declare class ExecutorErrorExecutionFailed extends Error {
|
|
25
|
+
constructor(msg?: string);
|
|
26
|
+
}
|
|
27
|
+
declare class ExecutorErrorDecode extends Error {
|
|
28
|
+
constructor(msg?: string);
|
|
29
|
+
}
|
|
30
|
+
type ContextCode = undefined | {
|
|
31
|
+
script?: undefined | null;
|
|
32
|
+
cell?: undefined | null;
|
|
33
|
+
tx?: undefined | null;
|
|
34
|
+
};
|
|
35
|
+
declare class ExecutorResponse<T> {
|
|
36
|
+
readonly res: T;
|
|
37
|
+
readonly cellDeps: ccc.OutPoint[];
|
|
38
|
+
constructor(res: T, cellDeps: ccc.OutPoint[]);
|
|
39
|
+
static new<T>(res: T, cellDeps?: ccc.OutPointLike[] | null): ExecutorResponse<T>;
|
|
40
|
+
map<U>(fn: (res: T) => U): ExecutorResponse<U>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Represents an SSRI executor.
|
|
44
|
+
*/
|
|
45
|
+
declare abstract class Executor {
|
|
46
|
+
abstract runScript(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex>>;
|
|
47
|
+
runScriptTry(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex> | undefined>;
|
|
48
|
+
}
|
|
49
|
+
declare class ExecutorJsonRpc extends Executor {
|
|
50
|
+
readonly requestor: ccc.RequestorJsonRpc;
|
|
51
|
+
/**
|
|
52
|
+
* Creates an instance of SSRI executor through Json RPC.
|
|
53
|
+
* @param {string} [url] - The external server URL.
|
|
54
|
+
*/
|
|
55
|
+
constructor(url: string, config?: ccc.RequestorJsonRpcConfig & {
|
|
56
|
+
requestor?: ccc.RequestorJsonRpc;
|
|
57
|
+
});
|
|
58
|
+
get url(): string;
|
|
59
|
+
runScript(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex>>;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/trait.d.ts
|
|
63
|
+
/**
|
|
64
|
+
* Class representing an SSRI trait. Should be used as the base of all SSRI traits.
|
|
65
|
+
*/
|
|
66
|
+
declare class Trait {
|
|
67
|
+
readonly code: ccc.OutPoint;
|
|
68
|
+
readonly executor?: Executor;
|
|
69
|
+
/**
|
|
70
|
+
* Creates an instance of SSRI trait.
|
|
71
|
+
* @param code - The cell dependency.
|
|
72
|
+
* @param executor - The SSRI executor instance.
|
|
73
|
+
*/
|
|
74
|
+
constructor(code: ccc.OutPointLike, executor?: Executor | null);
|
|
75
|
+
static tryRun<T>(call: Promise<ExecutorResponse<T>>): Promise<ExecutorResponse<T | undefined>>;
|
|
76
|
+
tryRun<T>(call: Promise<ExecutorResponse<T>>): Promise<ExecutorResponse<T | undefined>>;
|
|
77
|
+
assertExecutor(): Executor;
|
|
78
|
+
/**
|
|
79
|
+
* Retrieves a list of methods.
|
|
80
|
+
* @param offset - The offset for the methods.
|
|
81
|
+
* @param limit - The limit for the methods.
|
|
82
|
+
* @returns {Promise<Bytes[]>} A promise that resolves to a list of methods.
|
|
83
|
+
*/
|
|
84
|
+
getMethods(offset?: ccc.NumLike, limit?: ccc.NumLike): Promise<ExecutorResponse<ccc.Hex[]>>;
|
|
85
|
+
/**
|
|
86
|
+
* Checks if the specified methods exist.
|
|
87
|
+
* @param methodNames - The methods to check.
|
|
88
|
+
* @returns A promise that resolves to an array of booleans indicating if methods exist.
|
|
89
|
+
*/
|
|
90
|
+
hasMethods(methodNames: string[], extraMethodPaths?: ccc.HexLike[]): Promise<ExecutorResponse<boolean[]>>;
|
|
91
|
+
/**
|
|
92
|
+
* Retrieves the version of the trait.
|
|
93
|
+
* @returns A promise that resolves to the version number.
|
|
94
|
+
*/
|
|
95
|
+
version(): Promise<ExecutorResponse<ccc.Num>>;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/utils.d.ts
|
|
99
|
+
declare function getMethodPath(method: string): ccc.Hex;
|
|
100
|
+
declare namespace barrel_d_exports {
|
|
101
|
+
export { ContextCell, ContextCode, ContextScript, ContextTransaction, Executor, ExecutorErrorDecode, ExecutorErrorExecutionFailed, ExecutorErrorUnknown, ExecutorJsonRpc, ExecutorResponse, Trait, getMethodPath };
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { ContextCell, ContextCode, ContextScript, ContextTransaction, Executor, ExecutorErrorDecode, ExecutorErrorExecutionFailed, ExecutorErrorUnknown, ExecutorJsonRpc, ExecutorResponse, Trait, getMethodPath, barrel_d_exports as t };
|
|
4
105
|
//# sourceMappingURL=barrel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"barrel.d.ts","
|
|
1
|
+
{"version":3,"file":"barrel.d.ts","names":[],"sources":["../src/executor.ts","../src/trait.ts","../src/utils.ts","../src/barrel.ts"],"mappings":";;;;;KAIY,kBAAA;EACV,MAAA,GAAS,GAAA,CAAI,UAAA;EACb,IAAA,GAAO,GAAA,CAAI,WAAA;EACX,EAAA,EAAI,GAAA,CAAI,eAAA;AAAA;AAAA,KAGE,WAAA;EACV,MAAA,GAAS,GAAA,CAAI,UAAA;EACb,IAAA,EAAM,GAAA,CAAI,WAAW;EACrB,EAAA;AAAA;AAAA,KAGU,aAAA;EACV,MAAA,EAAQ,GAAA,CAAI,UAAU;EACtB,IAAA;EACA,EAAA;AAAA;AAAA,c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A,EAAc,GAAA,CAAI,YAAA,EAClB,MAAA,UACA,IAAA,EAAM,GAAA,CAAI,OAAA,IACV,OAAA,GAAU,WAAA,GAAc,aAAA,GAAgB,WAAA,GAAc,kBAAA,GACrD,OAAA,CAAQ,gBAAA,CAAiB,GAAA,CAAI,GAAA;AAAA;;;;;;cC7IrB,KAAA;EAAA,SACK,IAAA,EAAM,GAAA,CAAI,QAAA;EAAA,SACV,QAAA,GAAW,QAAA;;;;;;cAOf,IAAA,EAAM,GAAA,CAAI,YAAA,EAAc,QAAA,GAAW,QAAA;EAAA,OAKlC,MAAA,IACX,IAAA,EAAM,OAAA,CAAQ,gBAAA,CAAiB,CAAA,KAC9B,OAAA,CAAQ,gBAAA,CAAiB,CAAA;EActB,MAAA,IACJ,IAAA,EAAM,OAAA,CAAQ,gBAAA,CAAiB,CAAA,KAC9B,OAAA,CAAQ,gBAAA,CAAiB,CAAA;EAI5B,cAAA,IAAc,QAAA;;;;AD5ChB;;;EC0DQ,UAAA,CACJ,MAAA,GAAQ,GAAA,CAAI,OAAA,EACZ,KAAA,GAAO,GAAA,CAAI,OAAA,GACV,OAAA,CAAQ,gBAAA,CAAiB,GAAA,CAAI,GAAA;ED3DzB;;;;;EC0ED,UAAA,CACJ,WAAA,YACA,gBAAA,GAAmB,GAAA,CAAI,OAAA,KACtB,OAAA,CAAQ,gBAAA;ED9EE;;;;ECgGP,OAAA,IAAW,OAAA,CAAQ,gBAAA,CAAiB,GAAA,CAAI,GAAA;AAAA;;;iBCnGhC,aAAA,CAAc,MAAA,WAAiB,GAAA,CAAI,GAAG;AAAA"}
|
package/dist.commonjs/barrel.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./executor.js"), exports);
|
|
18
|
-
__exportStar(require("./trait.js"), exports);
|
|
19
|
-
__exportStar(require("./utils.js"), exports);
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};let n=require("@ckb-ccc/core"),r=require("@ckb-ccc/core/advanced");function i(e){return n.ccc.hashCkb(n.ccc.bytesFrom(e,`utf8`)).slice(0,18)}var a=class extends Error{constructor(e){super(e)}},o=class extends Error{constructor(e){super(e)}},s=class extends Error{constructor(e){super(e)}},c=class e{constructor(e,t){this.res=e,this.cellDeps=t}static new(t,r){return new e(t,r?.map(n.ccc.OutPoint.from)??[])}map(t){try{return new e(t(this.res),this.cellDeps)}catch(e){throw new s(JSON.stringify(e))}}},l=class{async runScriptTry(e,t,n,r){try{return await this.runScript(e,t,n,r)}catch(e){if(e instanceof o)return;throw e}}},u=class extends l{constructor(e,t){super(),this.requestor=t?.requestor??new n.ccc.RequestorJsonRpc(e,t,e=>{throw typeof e!=`object`||!e||!(`code`in e)||typeof e.code!=`number`?new a(JSON.stringify(e)):e.code===1003||e.code===1004?`message`in e&&typeof e.message==`string`?new o(e.message):new o:`message`in e&&typeof e.message==`string`?new a(e.message):new a})}get url(){return this.requestor.url}async runScript(e,t,a,o){let s=n.ccc.OutPoint.from(e),[l,u]=(()=>{if(o?.tx){let e=n.ccc.Transaction.from(o.tx);return[`run_script_level_transaction`,[{inner:r.cccA.JsonRpcTransformers.transactionFrom(e),hash:e.hash()}]]}if(o?.cell){let e=n.ccc.CellAny.from(o.cell);return[`run_script_level_cell`,[{cell_output:r.cccA.JsonRpcTransformers.cellOutputFrom(e.cellOutput,e.outputData),hex_data:n.ccc.hexFrom(e.outputData)}]]}return o?.script?[`run_script_level_script`,[r.cccA.JsonRpcTransformers.scriptFrom(o.script)]]:[`run_script_level_code`,[]]})(),{content:d,cell_deps:f}=await this.requestor.request(l,[s.txHash,Number(s.index),[i(t),...a.map(n.ccc.hexFrom)],...u]);return c.new(d,f.map(r.cccA.JsonRpcTransformers.outPointTo))}},d=class e{constructor(e,t){this.code=n.ccc.OutPoint.from(e),this.executor=t??void 0}static async tryRun(e){try{return await e}catch(e){if(e instanceof o||e instanceof s)return c.new(void 0);throw e}}async tryRun(t){return e.tryRun(t)}assertExecutor(){if(!this.executor)throw Error(`SSRI executor is not set`);return this.executor}async getMethods(e=0,t=0){return(await this.assertExecutor().runScript(this.code,`SSRI.get_methods`,[n.ccc.numToBytes(e??0,8),n.ccc.numToBytes(t??0,8)])).map(e=>n.ccc.mol.Byte8Vec.decode(e))}async hasMethods(e,t){let r=n.ccc.mol.Byte8Vec.encode(e.map(i).concat(t?.map(n.ccc.hexFrom)??[]));return(await this.assertExecutor().runScript(this.code,`SSRI.has_methods`,[r])).map(e=>n.ccc.mol.BoolVec.decode(e))}async version(){return(await this.assertExecutor().runScript(this.code,`SSRI.version`,[])).map(e=>{if(e.length!==4)throw Error(`Invalid U8`);return n.ccc.numFrom(e)})}},f=t({Executor:()=>l,ExecutorErrorDecode:()=>s,ExecutorErrorExecutionFailed:()=>o,ExecutorErrorUnknown:()=>a,ExecutorJsonRpc:()=>u,ExecutorResponse:()=>c,Trait:()=>d,getMethodPath:()=>i});exports.Executor=l,exports.ExecutorErrorDecode=s,exports.ExecutorErrorExecutionFailed=o,exports.ExecutorErrorUnknown=a,exports.ExecutorJsonRpc=u,exports.ExecutorResponse=c,exports.Trait=d,exports.getMethodPath=i,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return f}});
|
|
2
|
+
//# sourceMappingURL=barrel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel.js","names":["ccc","ccc","cccA","ccc"],"sources":["../src/utils.ts","../src/executor.ts","../src/trait.ts","../src/barrel.ts"],"sourcesContent":["import { ccc } from \"@ckb-ccc/core\";\n\nexport function getMethodPath(method: string): ccc.Hex {\n return ccc.hashCkb(ccc.bytesFrom(method, \"utf8\")).slice(0, 18) as ccc.Hex;\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport { cccA } from \"@ckb-ccc/core/advanced\";\nimport { getMethodPath } from \"./utils.js\";\n\nexport type ContextTransaction = {\n script?: ccc.ScriptLike | null;\n cell?: ccc.CellAnyLike | null;\n tx: ccc.TransactionLike;\n};\n\nexport type ContextCell = {\n script?: ccc.ScriptLike | null;\n cell: ccc.CellAnyLike;\n tx?: undefined | null;\n};\n\nexport type ContextScript = {\n script: ccc.ScriptLike;\n cell?: undefined | null;\n tx?: undefined | null;\n};\n\nexport class ExecutorErrorUnknown extends Error {\n constructor(msg?: string) {\n super(msg);\n }\n}\n\nexport class ExecutorErrorExecutionFailed extends Error {\n constructor(msg?: string) {\n super(msg);\n }\n}\n\nexport class ExecutorErrorDecode extends Error {\n constructor(msg?: string) {\n super(msg);\n }\n}\n\nexport type ContextCode =\n | undefined\n | {\n script?: undefined | null;\n cell?: undefined | null;\n tx?: undefined | null;\n };\n\nexport class ExecutorResponse<T> {\n constructor(\n public readonly res: T,\n public readonly cellDeps: ccc.OutPoint[],\n ) {}\n\n static new<T>(res: T, cellDeps?: ccc.OutPointLike[] | null) {\n return new ExecutorResponse(res, cellDeps?.map(ccc.OutPoint.from) ?? []);\n }\n\n map<U>(fn: (res: T) => U): ExecutorResponse<U> {\n try {\n return new ExecutorResponse(fn(this.res), this.cellDeps);\n } catch (err) {\n throw new ExecutorErrorDecode(JSON.stringify(err));\n }\n }\n}\n\n/**\n * Represents an SSRI executor.\n */\nexport abstract class Executor {\n abstract runScript(\n codeOutPoint: ccc.OutPointLike,\n method: string,\n args: ccc.HexLike[],\n context?: ContextCode | ContextScript | ContextCell | ContextTransaction,\n ): Promise<ExecutorResponse<ccc.Hex>>;\n\n async runScriptTry(\n codeOutPoint: ccc.OutPointLike,\n method: string,\n args: ccc.HexLike[],\n context?: ContextCode | ContextScript | ContextCell | ContextTransaction,\n ): Promise<ExecutorResponse<ccc.Hex> | undefined> {\n try {\n return await this.runScript(codeOutPoint, method, args, context);\n } catch (err) {\n if (err instanceof ExecutorErrorExecutionFailed) {\n return undefined;\n }\n throw err;\n }\n }\n}\n\nexport class ExecutorJsonRpc extends Executor {\n public readonly requestor: ccc.RequestorJsonRpc;\n\n /**\n * Creates an instance of SSRI executor through Json RPC.\n * @param {string} [url] - The external server URL.\n */\n constructor(\n url: string,\n config?: ccc.RequestorJsonRpcConfig & { requestor?: ccc.RequestorJsonRpc },\n ) {\n super();\n\n this.requestor =\n config?.requestor ??\n new ccc.RequestorJsonRpc(url, config, (errAny) => {\n if (\n typeof errAny !== \"object\" ||\n errAny === null ||\n !(\"code\" in errAny) ||\n typeof errAny.code !== \"number\"\n ) {\n throw new ExecutorErrorUnknown(JSON.stringify(errAny));\n }\n\n if (errAny.code === 1003 || errAny.code === 1004) {\n if (\"message\" in errAny && typeof errAny.message === \"string\") {\n throw new ExecutorErrorExecutionFailed(errAny.message);\n }\n throw new ExecutorErrorExecutionFailed();\n }\n\n if (\"message\" in errAny && typeof errAny.message === \"string\") {\n throw new ExecutorErrorUnknown(errAny.message);\n }\n throw new ExecutorErrorUnknown();\n });\n }\n\n get url() {\n return this.requestor.url;\n }\n\n /* Calls a method on the SSRI executor through SSRI Server.\n * @param codeOutPoint - The code OutPoint.\n * @param method - The SSRI method.\n * @param args - The arguments for the method.\n * @param context - The SSRI context for the method.\n * @param context.script - The script level parameters.\n * @param context.cell - The cell level parameters. Take precedence over script.\n * @param context.transaction - The transaction level parameters. Take precedence over cell.\n * @returns The result of the call.\n */\n async runScript(\n codeOutPoint: ccc.OutPointLike,\n method: string,\n args: ccc.HexLike[],\n context?: ContextCode | ContextScript | ContextCell | ContextTransaction,\n ): Promise<ExecutorResponse<ccc.Hex>> {\n const code = ccc.OutPoint.from(codeOutPoint);\n const [rpcMethod, rpcContext] = (() => {\n if (context?.tx) {\n const tx = ccc.Transaction.from(context.tx);\n return [\n \"run_script_level_transaction\",\n [\n {\n inner: cccA.JsonRpcTransformers.transactionFrom(tx),\n hash: tx.hash(),\n },\n ],\n ];\n }\n if (context?.cell) {\n const cell = ccc.CellAny.from(context.cell);\n\n return [\n \"run_script_level_cell\",\n [\n {\n cell_output: cccA.JsonRpcTransformers.cellOutputFrom(\n cell.cellOutput,\n cell.outputData,\n ),\n hex_data: ccc.hexFrom(cell.outputData),\n },\n ],\n ];\n }\n if (context?.script) {\n return [\n \"run_script_level_script\",\n [cccA.JsonRpcTransformers.scriptFrom(context.script)],\n ];\n }\n return [\"run_script_level_code\", []];\n })();\n\n const { content, cell_deps } = (await this.requestor.request(rpcMethod, [\n code.txHash,\n Number(code.index),\n [getMethodPath(method), ...args.map(ccc.hexFrom)],\n ...rpcContext,\n ])) as { content: ccc.Hex; cell_deps: cccA.JsonRpcOutPoint[] };\n\n return ExecutorResponse.new(\n content,\n cell_deps.map(cccA.JsonRpcTransformers.outPointTo),\n );\n }\n}\n","import { ccc } from \"@ckb-ccc/core\";\nimport {\n Executor,\n ExecutorErrorDecode,\n ExecutorErrorExecutionFailed,\n ExecutorResponse,\n} from \"./executor.js\";\nimport { getMethodPath } from \"./utils.js\";\n\n/**\n * Class representing an SSRI trait. Should be used as the base of all SSRI traits.\n */\nexport class Trait {\n public readonly code: ccc.OutPoint;\n public readonly executor?: Executor;\n\n /**\n * Creates an instance of SSRI trait.\n * @param code - The cell dependency.\n * @param executor - The SSRI executor instance.\n */\n constructor(code: ccc.OutPointLike, executor?: Executor | null) {\n this.code = ccc.OutPoint.from(code);\n this.executor = executor ?? undefined;\n }\n\n static async tryRun<T>(\n call: Promise<ExecutorResponse<T>>,\n ): Promise<ExecutorResponse<T | undefined>> {\n try {\n return await call;\n } catch (e) {\n if (\n e instanceof ExecutorErrorExecutionFailed ||\n e instanceof ExecutorErrorDecode\n ) {\n return ExecutorResponse.new(undefined);\n }\n throw e;\n }\n }\n\n async tryRun<T>(\n call: Promise<ExecutorResponse<T>>,\n ): Promise<ExecutorResponse<T | undefined>> {\n return Trait.tryRun(call);\n }\n\n assertExecutor() {\n if (!this.executor) {\n throw new Error(\"SSRI executor is not set\");\n }\n\n return this.executor;\n }\n\n /**\n * Retrieves a list of methods.\n * @param offset - The offset for the methods.\n * @param limit - The limit for the methods.\n * @returns {Promise<Bytes[]>} A promise that resolves to a list of methods.\n */\n async getMethods(\n offset: ccc.NumLike = 0,\n limit: ccc.NumLike = 0,\n ): Promise<ExecutorResponse<ccc.Hex[]>> {\n const res = await this.assertExecutor().runScript(\n this.code,\n \"SSRI.get_methods\",\n [ccc.numToBytes(offset ?? 0, 8), ccc.numToBytes(limit ?? 0, 8)],\n );\n\n return res.map((res) => ccc.mol.Byte8Vec.decode(res));\n }\n\n /**\n * Checks if the specified methods exist.\n * @param methodNames - The methods to check.\n * @returns A promise that resolves to an array of booleans indicating if methods exist.\n */\n async hasMethods(\n methodNames: string[],\n extraMethodPaths?: ccc.HexLike[],\n ): Promise<ExecutorResponse<boolean[]>> {\n const methodPaths = ccc.mol.Byte8Vec.encode(\n methodNames\n .map(getMethodPath)\n .concat(extraMethodPaths?.map(ccc.hexFrom) ?? []),\n );\n const res = await this.assertExecutor().runScript(\n this.code,\n \"SSRI.has_methods\",\n [methodPaths],\n );\n return res.map((res) => ccc.mol.BoolVec.decode(res));\n }\n\n /**\n * Retrieves the version of the trait.\n * @returns A promise that resolves to the version number.\n */\n async version(): Promise<ExecutorResponse<ccc.Num>> {\n const res = await this.assertExecutor().runScript(\n this.code,\n \"SSRI.version\",\n [],\n );\n\n return res.map((res) => {\n if (res.length !== 4) {\n throw new Error(\"Invalid U8\");\n }\n return ccc.numFrom(res);\n });\n }\n}\n","export * from \"./executor.js\";\nexport * from \"./trait.js\";\nexport * from \"./utils.js\";\n"],"mappings":"0RAEA,SAAgB,EAAc,EAAyB,CACrD,OAAOA,EAAAA,IAAI,QAAQA,EAAAA,IAAI,UAAU,EAAQ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAG,EAAE,CAC/D,CCkBA,IAAa,EAAb,cAA0C,KAAM,CAC9C,YAAY,EAAc,CACxB,MAAM,CAAG,CACX,CACF,EAEa,EAAb,cAAkD,KAAM,CACtD,YAAY,EAAc,CACxB,MAAM,CAAG,CACX,CACF,EAEa,EAAb,cAAyC,KAAM,CAC7C,YAAY,EAAc,CACxB,MAAM,CAAG,CACX,CACF,EAUa,EAAb,MAAa,CAAoB,CAC/B,YACE,EACA,EACA,CAFgB,KAAA,IAAA,EACA,KAAA,SAAA,CACf,CAEH,OAAO,IAAO,EAAQ,EAAsC,CAC1D,OAAO,IAAI,EAAiB,EAAK,GAAU,IAAIC,EAAAA,IAAI,SAAS,IAAI,GAAK,CAAC,CAAC,CACzE,CAEA,IAAO,EAAwC,CAC7C,GAAI,CACF,OAAO,IAAI,EAAiB,EAAG,KAAK,GAAG,EAAG,KAAK,QAAQ,CACzD,OAAS,EAAK,CACZ,MAAM,IAAI,EAAoB,KAAK,UAAU,CAAG,CAAC,CACnD,CACF,CACF,EAKsB,EAAtB,KAA+B,CAQ7B,MAAM,aACJ,EACA,EACA,EACA,EACgD,CAChD,GAAI,CACF,OAAO,MAAM,KAAK,UAAU,EAAc,EAAQ,EAAM,CAAO,CACjE,OAAS,EAAK,CACZ,GAAI,aAAe,EACjB,OAEF,MAAM,CACR,CACF,CACF,EAEa,EAAb,cAAqC,CAAS,CAO5C,YACE,EACA,EACA,C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AI,QAAQ,OAAO,CAAG,CAAC,CACrD,CAMA,MAAM,SAA8C,CAOlD,OAAO,MANW,KAAK,eAAe,CAAC,CAAC,UACtC,KAAK,KACL,eACA,CAAC,CACH,EAAA,CAEW,IAAK,GAAQ,CACtB,GAAI,EAAI,SAAW,EACjB,MAAU,MAAM,YAAY,EAE9B,OAAOA,EAAAA,IAAI,QAAQ,CAAG,CACxB,CAAC,CACH,CACF"}
|
package/dist.commonjs/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { t as barrel_d_exports } from "./barrel.js";
|
|
2
|
+
export { barrel_d_exports as ssri };
|
package/dist.commonjs/index.js
CHANGED
|
@@ -1,37 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.ssri = void 0;
|
|
37
|
-
exports.ssri = __importStar(require("./barrel.js"));
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./barrel.js");Object.defineProperty(exports,"ssri",{enumerable:!0,get:function(){return e.t}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/ssri",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "SSRI",
|
|
5
5
|
"author": "Alive24 <xct24@live.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,39 +11,40 @@
|
|
|
11
11
|
"url": "git://github.com/ckb-devrel/ccc.git"
|
|
12
12
|
},
|
|
13
13
|
"main": "./dist.commonjs/index.js",
|
|
14
|
-
"module": "./dist/index.
|
|
14
|
+
"module": "./dist/index.mjs",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"import": "./dist/index.
|
|
18
|
-
"
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"require": "./dist.commonjs/index.js"
|
|
19
19
|
},
|
|
20
20
|
"./barrel": {
|
|
21
|
-
"import": "./dist/barrel.
|
|
22
|
-
"
|
|
23
|
-
}
|
|
21
|
+
"import": "./dist/barrel.mjs",
|
|
22
|
+
"require": "./dist.commonjs/barrel.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@eslint/js": "^
|
|
27
|
-
"@types/node": "^
|
|
28
|
-
"
|
|
29
|
-
"eslint": "^9.34.0",
|
|
27
|
+
"@eslint/js": "^10.0.1",
|
|
28
|
+
"@types/node": "^26.0.0",
|
|
29
|
+
"eslint": "^10.5.0",
|
|
30
30
|
"eslint-config-prettier": "^10.1.8",
|
|
31
|
-
"eslint-plugin-prettier": "^5.5.
|
|
32
|
-
"prettier": "^3.
|
|
33
|
-
"prettier-plugin-organize-imports": "^4.
|
|
34
|
-
"
|
|
35
|
-
"typescript": "^
|
|
36
|
-
"typescript-eslint": "^8.41.0"
|
|
31
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
32
|
+
"prettier": "^3.8.4",
|
|
33
|
+
"prettier-plugin-organize-imports": "^4.3.0",
|
|
34
|
+
"typescript": "^6.0.3",
|
|
35
|
+
"typescript-eslint": "^8.61.1"
|
|
37
36
|
},
|
|
38
37
|
"publishConfig": {
|
|
39
38
|
"access": "public"
|
|
40
39
|
},
|
|
41
40
|
"dependencies": {
|
|
42
|
-
"
|
|
41
|
+
"tsdown": "^0.22.3",
|
|
42
|
+
"@ckb-ccc/core": "1.15.0"
|
|
43
43
|
},
|
|
44
|
+
"types": "./dist.commonjs/index.d.ts",
|
|
44
45
|
"scripts": {
|
|
45
46
|
"test": "jest",
|
|
46
|
-
"build": "
|
|
47
|
+
"build": "tsdown",
|
|
47
48
|
"lint": "eslint ./src",
|
|
48
49
|
"format": "prettier --write . && eslint --fix ./src"
|
|
49
50
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineConfig } from "tsdown";
|
|
2
|
+
|
|
3
|
+
const common = {
|
|
4
|
+
minify: true,
|
|
5
|
+
dts: true,
|
|
6
|
+
platform: "neutral" as const,
|
|
7
|
+
sourcemap: true,
|
|
8
|
+
exports: true,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const entry = {
|
|
12
|
+
index: "src/index.ts",
|
|
13
|
+
barrel: "src/barrel.ts",
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
const bundleDeps: string[] = [];
|
|
17
|
+
|
|
18
|
+
export default defineConfig(
|
|
19
|
+
(
|
|
20
|
+
[
|
|
21
|
+
{
|
|
22
|
+
entry,
|
|
23
|
+
deps: {
|
|
24
|
+
onlyBundle: [] as string[],
|
|
25
|
+
},
|
|
26
|
+
format: "esm",
|
|
27
|
+
copy: "./misc/basedirs/dist/*",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
entry,
|
|
31
|
+
deps: {
|
|
32
|
+
alwaysBundle: bundleDeps,
|
|
33
|
+
onlyBundle: bundleDeps,
|
|
34
|
+
},
|
|
35
|
+
format: "cjs",
|
|
36
|
+
outDir: "dist.commonjs",
|
|
37
|
+
copy: "./misc/basedirs/dist.commonjs/*",
|
|
38
|
+
},
|
|
39
|
+
] as const
|
|
40
|
+
).map((c) => ({ ...c, ...common })),
|
|
41
|
+
);
|
package/dist/barrel.d.ts
DELETED
package/dist/barrel.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"barrel.d.ts","sourceRoot":"","sources":["../src/barrel.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
package/dist/barrel.js
DELETED
package/dist/executor.d.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
export type ContextTransaction = {
|
|
3
|
-
script?: ccc.ScriptLike | null;
|
|
4
|
-
cell?: ccc.CellAnyLike | null;
|
|
5
|
-
tx: ccc.TransactionLike;
|
|
6
|
-
};
|
|
7
|
-
export type ContextCell = {
|
|
8
|
-
script?: ccc.ScriptLike | null;
|
|
9
|
-
cell: ccc.CellAnyLike;
|
|
10
|
-
tx?: undefined | null;
|
|
11
|
-
};
|
|
12
|
-
export type ContextScript = {
|
|
13
|
-
script: ccc.ScriptLike;
|
|
14
|
-
cell?: undefined | null;
|
|
15
|
-
tx?: undefined | null;
|
|
16
|
-
};
|
|
17
|
-
export declare class ExecutorErrorUnknown extends Error {
|
|
18
|
-
constructor(msg?: string);
|
|
19
|
-
}
|
|
20
|
-
export declare class ExecutorErrorExecutionFailed extends Error {
|
|
21
|
-
constructor(msg?: string);
|
|
22
|
-
}
|
|
23
|
-
export declare class ExecutorErrorDecode extends Error {
|
|
24
|
-
constructor(msg?: string);
|
|
25
|
-
}
|
|
26
|
-
export type ContextCode = undefined | {
|
|
27
|
-
script?: undefined | null;
|
|
28
|
-
cell?: undefined | null;
|
|
29
|
-
tx?: undefined | null;
|
|
30
|
-
};
|
|
31
|
-
export declare class ExecutorResponse<T> {
|
|
32
|
-
readonly res: T;
|
|
33
|
-
readonly cellDeps: ccc.OutPoint[];
|
|
34
|
-
constructor(res: T, cellDeps: ccc.OutPoint[]);
|
|
35
|
-
static new<T>(res: T, cellDeps?: ccc.OutPointLike[] | null): ExecutorResponse<T>;
|
|
36
|
-
map<U>(fn: (res: T) => U): ExecutorResponse<U>;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Represents an SSRI executor.
|
|
40
|
-
*/
|
|
41
|
-
export declare abstract class Executor {
|
|
42
|
-
abstract runScript(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex>>;
|
|
43
|
-
runScriptTry(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex> | undefined>;
|
|
44
|
-
}
|
|
45
|
-
export declare class ExecutorJsonRpc extends Executor {
|
|
46
|
-
readonly requestor: ccc.RequestorJsonRpc;
|
|
47
|
-
/**
|
|
48
|
-
* Creates an instance of SSRI executor through Json RPC.
|
|
49
|
-
* @param {string} [url] - The external server URL.
|
|
50
|
-
*/
|
|
51
|
-
constructor(url: string, config?: ccc.RequestorJsonRpcConfig & {
|
|
52
|
-
requestor?: ccc.RequestorJsonRpc;
|
|
53
|
-
});
|
|
54
|
-
get url(): string;
|
|
55
|
-
runScript(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex>>;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=executor.d.ts.map
|
package/dist/executor.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIpC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC;IAC/B,IAAI,CAAC,EAAE,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC;IAC9B,EAAE,EAAE,GAAG,CAAC,eAAe,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC;IAC/B,IAAI,EAAE,GAAG,CAAC,WAAW,CAAC;IACtB,EAAE,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,GAAG,CAAC,UAAU,CAAC;IACvB,IAAI,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,EAAE,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,GAAG,CAAC,EAAE,MAAM;CAGzB;AAED,qBAAa,4BAA6B,SAAQ,KAAK;gBACzC,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GAAG,CAAC,GAAG,SAAS,CAAC;CAUlD;AAED,qBAAa,eAAgB,SAAQ,QAAQ;IAC3C,SAAgB,SAAS,EAAE,GAAG,CAAC,gBAAgB,CAAC;IAEhD;;;OAGG;gBAED,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,GAAG,CAAC,sBAAsB,GAAG;QAAE,SAAS,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAA;KAAE;IA8B5E,IAAI,GAAG,WAEN;IAYK,SAAS,CACb,YAAY,EAAE,GAAG,CAAC,YAAY,EAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,EACnB,OAAO,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,WAAW,GAAG,kBAAkB,GACvE,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CAoDtC"}
|
package/dist/executor.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import { cccA } from "@ckb-ccc/core/advanced";
|
|
3
|
-
import { getMethodPath } from "./utils.js";
|
|
4
|
-
export class ExecutorErrorUnknown extends Error {
|
|
5
|
-
constructor(msg) {
|
|
6
|
-
super(msg);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export class ExecutorErrorExecutionFailed extends Error {
|
|
10
|
-
constructor(msg) {
|
|
11
|
-
super(msg);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export class ExecutorErrorDecode extends Error {
|
|
15
|
-
constructor(msg) {
|
|
16
|
-
super(msg);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export class ExecutorResponse {
|
|
20
|
-
constructor(res, cellDeps) {
|
|
21
|
-
this.res = res;
|
|
22
|
-
this.cellDeps = cellDeps;
|
|
23
|
-
}
|
|
24
|
-
static new(res, cellDeps) {
|
|
25
|
-
return new ExecutorResponse(res, cellDeps?.map(ccc.OutPoint.from) ?? []);
|
|
26
|
-
}
|
|
27
|
-
map(fn) {
|
|
28
|
-
try {
|
|
29
|
-
return new ExecutorResponse(fn(this.res), this.cellDeps);
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
throw new ExecutorErrorDecode(JSON.stringify(err));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Represents an SSRI executor.
|
|
38
|
-
*/
|
|
39
|
-
export class Executor {
|
|
40
|
-
async runScriptTry(codeOutPoint, method, args, context) {
|
|
41
|
-
try {
|
|
42
|
-
return await this.runScript(codeOutPoint, method, args, context);
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
if (err instanceof ExecutorErrorExecutionFailed) {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
export class ExecutorJsonRpc extends Executor {
|
|
53
|
-
/**
|
|
54
|
-
* Creates an instance of SSRI executor through Json RPC.
|
|
55
|
-
* @param {string} [url] - The external server URL.
|
|
56
|
-
*/
|
|
57
|
-
constructor(url, config) {
|
|
58
|
-
super();
|
|
59
|
-
this.requestor =
|
|
60
|
-
config?.requestor ??
|
|
61
|
-
new ccc.RequestorJsonRpc(url, config, (errAny) => {
|
|
62
|
-
if (typeof errAny !== "object" ||
|
|
63
|
-
errAny === null ||
|
|
64
|
-
!("code" in errAny) ||
|
|
65
|
-
typeof errAny.code !== "number") {
|
|
66
|
-
throw new ExecutorErrorUnknown(JSON.stringify(errAny));
|
|
67
|
-
}
|
|
68
|
-
if (errAny.code === 1003 || errAny.code === 1004) {
|
|
69
|
-
if ("message" in errAny && typeof errAny.message === "string") {
|
|
70
|
-
throw new ExecutorErrorExecutionFailed(errAny.message);
|
|
71
|
-
}
|
|
72
|
-
throw new ExecutorErrorExecutionFailed();
|
|
73
|
-
}
|
|
74
|
-
if ("message" in errAny && typeof errAny.message === "string") {
|
|
75
|
-
throw new ExecutorErrorUnknown(errAny.message);
|
|
76
|
-
}
|
|
77
|
-
throw new ExecutorErrorUnknown();
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
get url() {
|
|
81
|
-
return this.requestor.url;
|
|
82
|
-
}
|
|
83
|
-
/* Calls a method on the SSRI executor through SSRI Server.
|
|
84
|
-
* @param codeOutPoint - The code OutPoint.
|
|
85
|
-
* @param method - The SSRI method.
|
|
86
|
-
* @param args - The arguments for the method.
|
|
87
|
-
* @param context - The SSRI context for the method.
|
|
88
|
-
* @param context.script - The script level parameters.
|
|
89
|
-
* @param context.cell - The cell level parameters. Take precedence over script.
|
|
90
|
-
* @param context.transaction - The transaction level parameters. Take precedence over cell.
|
|
91
|
-
* @returns The result of the call.
|
|
92
|
-
*/
|
|
93
|
-
async runScript(codeOutPoint, method, args, context) {
|
|
94
|
-
const code = ccc.OutPoint.from(codeOutPoint);
|
|
95
|
-
const [rpcMethod, rpcContext] = (() => {
|
|
96
|
-
if (context?.tx) {
|
|
97
|
-
const tx = ccc.Transaction.from(context.tx);
|
|
98
|
-
return [
|
|
99
|
-
"run_script_level_transaction",
|
|
100
|
-
[
|
|
101
|
-
{
|
|
102
|
-
inner: cccA.JsonRpcTransformers.transactionFrom(tx),
|
|
103
|
-
hash: tx.hash(),
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
];
|
|
107
|
-
}
|
|
108
|
-
if (context?.cell) {
|
|
109
|
-
const cell = ccc.CellAny.from(context.cell);
|
|
110
|
-
return [
|
|
111
|
-
"run_script_level_cell",
|
|
112
|
-
[
|
|
113
|
-
{
|
|
114
|
-
cell_output: cccA.JsonRpcTransformers.cellOutputFrom(cell.cellOutput, cell.outputData),
|
|
115
|
-
hex_data: ccc.hexFrom(cell.outputData),
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
];
|
|
119
|
-
}
|
|
120
|
-
if (context?.script) {
|
|
121
|
-
return [
|
|
122
|
-
"run_script_level_script",
|
|
123
|
-
[cccA.JsonRpcTransformers.scriptFrom(context.script)],
|
|
124
|
-
];
|
|
125
|
-
}
|
|
126
|
-
return ["run_script_level_code", []];
|
|
127
|
-
})();
|
|
128
|
-
const { content, cell_deps } = (await this.requestor.request(rpcMethod, [
|
|
129
|
-
code.txHash,
|
|
130
|
-
Number(code.index),
|
|
131
|
-
[getMethodPath(method), ...args.map(ccc.hexFrom)],
|
|
132
|
-
...rpcContext,
|
|
133
|
-
]));
|
|
134
|
-
return ExecutorResponse.new(content, cell_deps.map(cccA.JsonRpcTransformers.outPointTo));
|
|
135
|
-
}
|
|
136
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as ssri from "./barrel.js";
|
package/dist/trait.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import { Executor, ExecutorResponse } from "./executor.js";
|
|
3
|
-
/**
|
|
4
|
-
* Class representing an SSRI trait. Should be used as the base of all SSRI traits.
|
|
5
|
-
*/
|
|
6
|
-
export declare class Trait {
|
|
7
|
-
readonly code: ccc.OutPoint;
|
|
8
|
-
readonly executor?: Executor;
|
|
9
|
-
/**
|
|
10
|
-
* Creates an instance of SSRI trait.
|
|
11
|
-
* @param code - The cell dependency.
|
|
12
|
-
* @param executor - The SSRI executor instance.
|
|
13
|
-
*/
|
|
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>>;
|
|
17
|
-
assertExecutor(): Executor;
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves a list of methods.
|
|
20
|
-
* @param offset - The offset for the methods.
|
|
21
|
-
* @param limit - The limit for the methods.
|
|
22
|
-
* @returns {Promise<Bytes[]>} A promise that resolves to a list of methods.
|
|
23
|
-
*/
|
|
24
|
-
getMethods(offset?: ccc.NumLike, limit?: ccc.NumLike): Promise<ExecutorResponse<ccc.Hex[]>>;
|
|
25
|
-
/**
|
|
26
|
-
* Checks if the specified methods exist.
|
|
27
|
-
* @param methodNames - The methods to check.
|
|
28
|
-
* @returns A promise that resolves to an array of booleans indicating if methods exist.
|
|
29
|
-
*/
|
|
30
|
-
hasMethods(methodNames: string[], extraMethodPaths?: ccc.HexLike[]): Promise<ExecutorResponse<boolean[]>>;
|
|
31
|
-
/**
|
|
32
|
-
* Retrieves the version of the trait.
|
|
33
|
-
* @returns A promise that resolves to the version number.
|
|
34
|
-
*/
|
|
35
|
-
version(): Promise<ExecutorResponse<ccc.Num>>;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=trait.d.ts.map
|
package/dist/trait.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import { ExecutorErrorDecode, ExecutorErrorExecutionFailed, ExecutorResponse, } from "./executor.js";
|
|
3
|
-
import { getMethodPath } from "./utils.js";
|
|
4
|
-
/**
|
|
5
|
-
* Class representing an SSRI trait. Should be used as the base of all SSRI traits.
|
|
6
|
-
*/
|
|
7
|
-
export class Trait {
|
|
8
|
-
/**
|
|
9
|
-
* Creates an instance of SSRI trait.
|
|
10
|
-
* @param code - The cell dependency.
|
|
11
|
-
* @param executor - The SSRI executor instance.
|
|
12
|
-
*/
|
|
13
|
-
constructor(code, executor) {
|
|
14
|
-
this.code = ccc.OutPoint.from(code);
|
|
15
|
-
this.executor = executor ?? undefined;
|
|
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
|
-
}
|
|
32
|
-
assertExecutor() {
|
|
33
|
-
if (!this.executor) {
|
|
34
|
-
throw new Error("SSRI executor is not set");
|
|
35
|
-
}
|
|
36
|
-
return this.executor;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Retrieves a list of methods.
|
|
40
|
-
* @param offset - The offset for the methods.
|
|
41
|
-
* @param limit - The limit for the methods.
|
|
42
|
-
* @returns {Promise<Bytes[]>} A promise that resolves to a list of methods.
|
|
43
|
-
*/
|
|
44
|
-
async getMethods(offset = 0, limit = 0) {
|
|
45
|
-
const res = await this.assertExecutor().runScript(this.code, "SSRI.get_methods", [ccc.numToBytes(offset ?? 0, 8), ccc.numToBytes(limit ?? 0, 8)]);
|
|
46
|
-
return res.map((res) => ccc.mol.Byte8Vec.decode(res));
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Checks if the specified methods exist.
|
|
50
|
-
* @param methodNames - The methods to check.
|
|
51
|
-
* @returns A promise that resolves to an array of booleans indicating if methods exist.
|
|
52
|
-
*/
|
|
53
|
-
async hasMethods(methodNames, extraMethodPaths) {
|
|
54
|
-
const methodPaths = ccc.mol.Byte8Vec.encode(methodNames
|
|
55
|
-
.map(getMethodPath)
|
|
56
|
-
.concat(extraMethodPaths?.map(ccc.hexFrom) ?? []));
|
|
57
|
-
const res = await this.assertExecutor().runScript(this.code, "SSRI.has_methods", [methodPaths]);
|
|
58
|
-
return res.map((res) => ccc.mol.BoolVec.decode(res));
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Retrieves the version of the trait.
|
|
62
|
-
* @returns A promise that resolves to the version number.
|
|
63
|
-
*/
|
|
64
|
-
async version() {
|
|
65
|
-
const res = await this.assertExecutor().runScript(this.code, "SSRI.version", []);
|
|
66
|
-
return res.map((res) => {
|
|
67
|
-
if (res.length !== 4) {
|
|
68
|
-
throw new Error("Invalid U8");
|
|
69
|
-
}
|
|
70
|
-
return ccc.numFrom(res);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
package/dist/utils.d.ts
DELETED
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,CAErD"}
|
package/dist/utils.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
export type ContextTransaction = {
|
|
3
|
-
script?: ccc.ScriptLike | null;
|
|
4
|
-
cell?: ccc.CellAnyLike | null;
|
|
5
|
-
tx: ccc.TransactionLike;
|
|
6
|
-
};
|
|
7
|
-
export type ContextCell = {
|
|
8
|
-
script?: ccc.ScriptLike | null;
|
|
9
|
-
cell: ccc.CellAnyLike;
|
|
10
|
-
tx?: undefined | null;
|
|
11
|
-
};
|
|
12
|
-
export type ContextScript = {
|
|
13
|
-
script: ccc.ScriptLike;
|
|
14
|
-
cell?: undefined | null;
|
|
15
|
-
tx?: undefined | null;
|
|
16
|
-
};
|
|
17
|
-
export declare class ExecutorErrorUnknown extends Error {
|
|
18
|
-
constructor(msg?: string);
|
|
19
|
-
}
|
|
20
|
-
export declare class ExecutorErrorExecutionFailed extends Error {
|
|
21
|
-
constructor(msg?: string);
|
|
22
|
-
}
|
|
23
|
-
export declare class ExecutorErrorDecode extends Error {
|
|
24
|
-
constructor(msg?: string);
|
|
25
|
-
}
|
|
26
|
-
export type ContextCode = undefined | {
|
|
27
|
-
script?: undefined | null;
|
|
28
|
-
cell?: undefined | null;
|
|
29
|
-
tx?: undefined | null;
|
|
30
|
-
};
|
|
31
|
-
export declare class ExecutorResponse<T> {
|
|
32
|
-
readonly res: T;
|
|
33
|
-
readonly cellDeps: ccc.OutPoint[];
|
|
34
|
-
constructor(res: T, cellDeps: ccc.OutPoint[]);
|
|
35
|
-
static new<T>(res: T, cellDeps?: ccc.OutPointLike[] | null): ExecutorResponse<T>;
|
|
36
|
-
map<U>(fn: (res: T) => U): ExecutorResponse<U>;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Represents an SSRI executor.
|
|
40
|
-
*/
|
|
41
|
-
export declare abstract class Executor {
|
|
42
|
-
abstract runScript(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex>>;
|
|
43
|
-
runScriptTry(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex> | undefined>;
|
|
44
|
-
}
|
|
45
|
-
export declare class ExecutorJsonRpc extends Executor {
|
|
46
|
-
readonly requestor: ccc.RequestorJsonRpc;
|
|
47
|
-
/**
|
|
48
|
-
* Creates an instance of SSRI executor through Json RPC.
|
|
49
|
-
* @param {string} [url] - The external server URL.
|
|
50
|
-
*/
|
|
51
|
-
constructor(url: string, config?: ccc.RequestorJsonRpcConfig & {
|
|
52
|
-
requestor?: ccc.RequestorJsonRpc;
|
|
53
|
-
});
|
|
54
|
-
get url(): string;
|
|
55
|
-
runScript(codeOutPoint: ccc.OutPointLike, method: string, args: ccc.HexLike[], context?: ContextCode | ContextScript | ContextCell | ContextTransaction): Promise<ExecutorResponse<ccc.Hex>>;
|
|
56
|
-
}
|
|
57
|
-
//# s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MAAM,EACd,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,EACnB,OAAO,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,WAAW,GAAG,kBAAkB,GACvE,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CAoDtC"}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExecutorJsonRpc = exports.Executor = exports.ExecutorResponse = exports.ExecutorErrorDecode = exports.ExecutorErrorExecutionFailed = exports.ExecutorErrorUnknown = void 0;
|
|
4
|
-
const core_1 = require("@ckb-ccc/core");
|
|
5
|
-
const advanced_1 = require("@ckb-ccc/core/advanced");
|
|
6
|
-
const utils_js_1 = require("./utils.js");
|
|
7
|
-
class ExecutorErrorUnknown extends Error {
|
|
8
|
-
constructor(msg) {
|
|
9
|
-
super(msg);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.ExecutorErrorUnknown = ExecutorErrorUnknown;
|
|
13
|
-
class ExecutorErrorExecutionFailed extends Error {
|
|
14
|
-
constructor(msg) {
|
|
15
|
-
super(msg);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.ExecutorErrorExecutionFailed = ExecutorErrorExecutionFailed;
|
|
19
|
-
class ExecutorErrorDecode extends Error {
|
|
20
|
-
constructor(msg) {
|
|
21
|
-
super(msg);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.ExecutorErrorDecode = ExecutorErrorDecode;
|
|
25
|
-
class ExecutorResponse {
|
|
26
|
-
constructor(res, cellDeps) {
|
|
27
|
-
this.res = res;
|
|
28
|
-
this.cellDeps = cellDeps;
|
|
29
|
-
}
|
|
30
|
-
static new(res, cellDeps) {
|
|
31
|
-
return new ExecutorResponse(res, cellDeps?.map(core_1.ccc.OutPoint.from) ?? []);
|
|
32
|
-
}
|
|
33
|
-
map(fn) {
|
|
34
|
-
try {
|
|
35
|
-
return new ExecutorResponse(fn(this.res), this.cellDeps);
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
throw new ExecutorErrorDecode(JSON.stringify(err));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.ExecutorResponse = ExecutorResponse;
|
|
43
|
-
/**
|
|
44
|
-
* Represents an SSRI executor.
|
|
45
|
-
*/
|
|
46
|
-
class Executor {
|
|
47
|
-
async runScriptTry(codeOutPoint, method, args, context) {
|
|
48
|
-
try {
|
|
49
|
-
return await this.runScript(codeOutPoint, method, args, context);
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
if (err instanceof ExecutorErrorExecutionFailed) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
throw err;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.Executor = Executor;
|
|
60
|
-
class ExecutorJsonRpc extends Executor {
|
|
61
|
-
/**
|
|
62
|
-
* Creates an instance of SSRI executor through Json RPC.
|
|
63
|
-
* @param {string} [url] - The external server URL.
|
|
64
|
-
*/
|
|
65
|
-
constructor(url, config) {
|
|
66
|
-
super();
|
|
67
|
-
this.requestor =
|
|
68
|
-
config?.requestor ??
|
|
69
|
-
new core_1.ccc.RequestorJsonRpc(url, config, (errAny) => {
|
|
70
|
-
if (typeof errAny !== "object" ||
|
|
71
|
-
errAny === null ||
|
|
72
|
-
!("code" in errAny) ||
|
|
73
|
-
typeof errAny.code !== "number") {
|
|
74
|
-
throw new ExecutorErrorUnknown(JSON.stringify(errAny));
|
|
75
|
-
}
|
|
76
|
-
if (errAny.code === 1003 || errAny.code === 1004) {
|
|
77
|
-
if ("message" in errAny && typeof errAny.message === "string") {
|
|
78
|
-
throw new ExecutorErrorExecutionFailed(errAny.message);
|
|
79
|
-
}
|
|
80
|
-
throw new ExecutorErrorExecutionFailed();
|
|
81
|
-
}
|
|
82
|
-
if ("message" in errAny && typeof errAny.message === "string") {
|
|
83
|
-
throw new ExecutorErrorUnknown(errAny.message);
|
|
84
|
-
}
|
|
85
|
-
throw new ExecutorErrorUnknown();
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
get url() {
|
|
89
|
-
return this.requestor.url;
|
|
90
|
-
}
|
|
91
|
-
/* Calls a method on the SSRI executor through SSRI Server.
|
|
92
|
-
* @param codeOutPoint - The code OutPoint.
|
|
93
|
-
* @param method - The SSRI method.
|
|
94
|
-
* @param args - The arguments for the method.
|
|
95
|
-
* @param context - The SSRI context for the method.
|
|
96
|
-
* @param context.script - The script level parameters.
|
|
97
|
-
* @param context.cell - The cell level parameters. Take precedence over script.
|
|
98
|
-
* @param context.transaction - The transaction level parameters. Take precedence over cell.
|
|
99
|
-
* @returns The result of the call.
|
|
100
|
-
*/
|
|
101
|
-
async runScript(codeOutPoint, method, args, context) {
|
|
102
|
-
const code = core_1.ccc.OutPoint.from(codeOutPoint);
|
|
103
|
-
const [rpcMethod, rpcContext] = (() => {
|
|
104
|
-
if (context?.tx) {
|
|
105
|
-
const tx = core_1.ccc.Transaction.from(context.tx);
|
|
106
|
-
return [
|
|
107
|
-
"run_script_level_transaction",
|
|
108
|
-
[
|
|
109
|
-
{
|
|
110
|
-
inner: advanced_1.cccA.JsonRpcTransformers.transactionFrom(tx),
|
|
111
|
-
hash: tx.hash(),
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
];
|
|
115
|
-
}
|
|
116
|
-
if (context?.cell) {
|
|
117
|
-
const cell = core_1.ccc.CellAny.from(context.cell);
|
|
118
|
-
return [
|
|
119
|
-
"run_script_level_cell",
|
|
120
|
-
[
|
|
121
|
-
{
|
|
122
|
-
cell_output: advanced_1.cccA.JsonRpcTransformers.cellOutputFrom(cell.cellOutput, cell.outputData),
|
|
123
|
-
hex_data: core_1.ccc.hexFrom(cell.outputData),
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
];
|
|
127
|
-
}
|
|
128
|
-
if (context?.script) {
|
|
129
|
-
return [
|
|
130
|
-
"run_script_level_script",
|
|
131
|
-
[advanced_1.cccA.JsonRpcTransformers.scriptFrom(context.script)],
|
|
132
|
-
];
|
|
133
|
-
}
|
|
134
|
-
return ["run_script_level_code", []];
|
|
135
|
-
})();
|
|
136
|
-
const { content, cell_deps } = (await this.requestor.request(rpcMethod, [
|
|
137
|
-
code.txHash,
|
|
138
|
-
Number(code.index),
|
|
139
|
-
[(0, utils_js_1.getMethodPath)(method), ...args.map(core_1.ccc.hexFrom)],
|
|
140
|
-
...rpcContext,
|
|
141
|
-
]));
|
|
142
|
-
return ExecutorResponse.new(content, cell_deps.map(advanced_1.cccA.JsonRpcTransformers.outPointTo));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.ExecutorJsonRpc = ExecutorJsonRpc;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC"}
|
package/dist.commonjs/trait.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ccc } from "@ckb-ccc/core";
|
|
2
|
-
import { Executor, ExecutorResponse } from "./executor.js";
|
|
3
|
-
/**
|
|
4
|
-
* Class representing an SSRI trait. Should be used as the base of all SSRI traits.
|
|
5
|
-
*/
|
|
6
|
-
export declare class Trait {
|
|
7
|
-
readonly code: ccc.OutPoint;
|
|
8
|
-
readonly executor?: Executor;
|
|
9
|
-
/**
|
|
10
|
-
* Creates an instance of SSRI trait.
|
|
11
|
-
* @param code - The cell dependency.
|
|
12
|
-
* @param executor - The SSRI executor instance.
|
|
13
|
-
*/
|
|
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>>;
|
|
17
|
-
assertExecutor(): Executor;
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves a list of methods.
|
|
20
|
-
* @param offset - The offset for the methods.
|
|
21
|
-
* @param limit - The limit for the methods.
|
|
22
|
-
* @returns {Promise<Bytes[]>} A promise that resolves to a list of methods.
|
|
23
|
-
*/
|
|
24
|
-
getMethods(offset?: ccc.NumLike, limit?: ccc.NumLike): Promise<ExecutorResponse<ccc.Hex[]>>;
|
|
25
|
-
/**
|
|
26
|
-
* Checks if the specified methods exist.
|
|
27
|
-
* @param methodNames - The methods to check.
|
|
28
|
-
* @returns A promise that resolves to an array of booleans indicating if methods exist.
|
|
29
|
-
*/
|
|
30
|
-
hasMethods(methodNames: string[], extraMethodPaths?: ccc.HexLike[]): Promise<ExecutorResponse<boolean[]>>;
|
|
31
|
-
/**
|
|
32
|
-
* Retrieves the version of the trait.
|
|
33
|
-
* @returns A promise that resolves to the version number.
|
|
34
|
-
*/
|
|
35
|
-
version(): Promise<ExecutorResponse<ccc.Num>>;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=trait.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Trait = void 0;
|
|
4
|
-
const core_1 = require("@ckb-ccc/core");
|
|
5
|
-
const executor_js_1 = require("./executor.js");
|
|
6
|
-
const utils_js_1 = require("./utils.js");
|
|
7
|
-
/**
|
|
8
|
-
* Class representing an SSRI trait. Should be used as the base of all SSRI traits.
|
|
9
|
-
*/
|
|
10
|
-
class Trait {
|
|
11
|
-
/**
|
|
12
|
-
* Creates an instance of SSRI trait.
|
|
13
|
-
* @param code - The cell dependency.
|
|
14
|
-
* @param executor - The SSRI executor instance.
|
|
15
|
-
*/
|
|
16
|
-
constructor(code, executor) {
|
|
17
|
-
this.code = core_1.ccc.OutPoint.from(code);
|
|
18
|
-
this.executor = executor ?? undefined;
|
|
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
|
-
}
|
|
35
|
-
assertExecutor() {
|
|
36
|
-
if (!this.executor) {
|
|
37
|
-
throw new Error("SSRI executor is not set");
|
|
38
|
-
}
|
|
39
|
-
return this.executor;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Retrieves a list of methods.
|
|
43
|
-
* @param offset - The offset for the methods.
|
|
44
|
-
* @param limit - The limit for the methods.
|
|
45
|
-
* @returns {Promise<Bytes[]>} A promise that resolves to a list of methods.
|
|
46
|
-
*/
|
|
47
|
-
async getMethods(offset = 0, limit = 0) {
|
|
48
|
-
const res = await this.assertExecutor().runScript(this.code, "SSRI.get_methods", [core_1.ccc.numToBytes(offset ?? 0, 8), core_1.ccc.numToBytes(limit ?? 0, 8)]);
|
|
49
|
-
return res.map((res) => core_1.ccc.mol.Byte8Vec.decode(res));
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Checks if the specified methods exist.
|
|
53
|
-
* @param methodNames - The methods to check.
|
|
54
|
-
* @returns A promise that resolves to an array of booleans indicating if methods exist.
|
|
55
|
-
*/
|
|
56
|
-
async hasMethods(methodNames, extraMethodPaths) {
|
|
57
|
-
const methodPaths = core_1.ccc.mol.Byte8Vec.encode(methodNames
|
|
58
|
-
.map(utils_js_1.getMethodPath)
|
|
59
|
-
.concat(extraMethodPaths?.map(core_1.ccc.hexFrom) ?? []));
|
|
60
|
-
const res = await this.assertExecutor().runScript(this.code, "SSRI.has_methods", [methodPaths]);
|
|
61
|
-
return res.map((res) => core_1.ccc.mol.BoolVec.decode(res));
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Retrieves the version of the trait.
|
|
65
|
-
* @returns A promise that resolves to the version number.
|
|
66
|
-
*/
|
|
67
|
-
async version() {
|
|
68
|
-
const res = await this.assertExecutor().runScript(this.code, "SSRI.version", []);
|
|
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
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.Trait = Trait;
|
package/dist.commonjs/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,CAErD"}
|
package/dist.commonjs/utils.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMethodPath = getMethodPath;
|
|
4
|
-
const core_1 = require("@ckb-ccc/core");
|
|
5
|
-
function getMethodPath(method) {
|
|
6
|
-
return core_1.ccc.hashCkb(core_1.ccc.bytesFrom(method, "utf8")).slice(0, 18);
|
|
7
|
-
}
|