@chainlink/cre-sdk 1.5.0 → 1.6.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -7
- package/bin/cre-compile.ts +17 -34
- package/dist/sdk/don-info.d.ts +10 -0
- package/dist/sdk/don-info.js +9 -0
- package/dist/sdk/errors.d.ts +24 -1
- package/dist/sdk/errors.js +46 -1
- package/dist/sdk/index.d.ts +2 -0
- package/dist/sdk/index.js +2 -0
- package/dist/sdk/report-internals.d.ts +6 -0
- package/dist/sdk/report-internals.js +3 -0
- package/dist/sdk/report.d.ts +38 -0
- package/dist/sdk/report.js +489 -2
- package/dist/sdk/testutils/test-runtime.js +4 -0
- package/package.json +3 -3
- package/scripts/run-standard-tests.sh +3 -3
- package/scripts/run.ts +1 -5
- package/scripts/src/compile-to-js.ts +7 -46
- package/scripts/src/compile-to-wasm.ts +32 -18
- package/scripts/src/compile-workflow.ts +27 -55
- package/scripts/src/generate-chain-selectors.ts +27 -9
- package/scripts/src/compile-cli-args.test.ts +0 -32
- package/scripts/src/compile-cli-args.ts +0 -35
- package/scripts/src/compile-to-js.test.ts +0 -90
- package/scripts/src/typecheck-workflow.test.ts +0 -77
- package/scripts/src/typecheck-workflow.ts +0 -96
package/README.md
CHANGED
|
@@ -58,16 +58,10 @@ CRE workflows are compiled to WASM and executed through Javy (QuickJS). This is
|
|
|
58
58
|
|
|
59
59
|
- Node built-ins like `node:fs`, `node:crypto`, `node:http`, `node:net`, etc. are not supported in workflows.
|
|
60
60
|
- Browser globals like `fetch`, `window`, and `setTimeout` are also not available in workflow runtime.
|
|
61
|
-
- `cre compile:workflow` / `cre-compile` now
|
|
61
|
+
- `cre compile:workflow` / `cre-compile` now validates workflow source and fails fast when unsupported APIs are used.
|
|
62
62
|
|
|
63
63
|
Use CRE capabilities (for example, `cre.capabilities.HTTPClient`) instead of direct Node/browser APIs.
|
|
64
64
|
|
|
65
|
-
If you need to compile despite TypeScript errors, pass `--skip-type-checks`:
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
bun x cre-compile src/workflow.ts dist/workflow.wasm --skip-type-checks
|
|
69
|
-
```
|
|
70
|
-
|
|
71
65
|
## Getting Started
|
|
72
66
|
|
|
73
67
|
We recommend you consult the [getting started docs](https://docs.chain.link/cre/getting-started/cli-installation) and install the CRE CLI.
|
package/bin/cre-compile.ts
CHANGED
|
@@ -1,55 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
3
|
import { main as compileWorkflow } from "../scripts/src/compile-workflow";
|
|
4
|
-
import {
|
|
5
|
-
parseCompileCliArgs,
|
|
6
|
-
skipTypeChecksFlag,
|
|
7
|
-
} from "../scripts/src/compile-cli-args";
|
|
8
|
-
import { WorkflowTypecheckError } from "../scripts/src/typecheck-workflow";
|
|
4
|
+
import { parseCompileFlags } from "../../cre-sdk-javy-plugin/scripts/parse-compile-flags";
|
|
9
5
|
import { WorkflowRuntimeCompatibilityError } from "../scripts/src/validate-workflow-runtime-compat";
|
|
10
6
|
|
|
11
7
|
const main = async () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let skipTypeChecks = false;
|
|
8
|
+
const cliArgs = process.argv.slice(2);
|
|
9
|
+
const { creExports, plugin, rest } = parseCompileFlags(cliArgs);
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
skipTypeChecks = parsed.skipTypeChecks;
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.error(error instanceof Error ? error.message : error);
|
|
11
|
+
const inputPath = rest[0];
|
|
12
|
+
const outputPathArg = rest[1];
|
|
13
|
+
|
|
14
|
+
if (!inputPath) {
|
|
23
15
|
console.error(
|
|
24
|
-
|
|
16
|
+
"Usage: cre-compile [--plugin <path>] [--cre-exports <crate-dir>]... <path/to/workflow.ts> [path/to/output.wasm]"
|
|
25
17
|
);
|
|
26
18
|
process.exit(1);
|
|
27
19
|
}
|
|
28
20
|
|
|
29
|
-
if (
|
|
30
|
-
console.error(
|
|
31
|
-
`Usage: cre-compile <path/to/workflow.ts> [path/to/output.wasm] [${skipTypeChecksFlag}]`,
|
|
32
|
-
);
|
|
33
|
-
console.error("Examples:");
|
|
34
|
-
console.error(" cre-compile src/standard_tests/secrets/test.ts");
|
|
35
|
-
console.error(
|
|
36
|
-
" cre-compile src/standard_tests/secrets/test.ts .temp/standard_tests/secrets/test.wasm",
|
|
37
|
-
);
|
|
38
|
-
console.error(
|
|
39
|
-
` cre-compile src/standard_tests/secrets/test.ts .temp/standard_tests/secrets/test.wasm ${skipTypeChecksFlag}`,
|
|
40
|
-
);
|
|
21
|
+
if (plugin !== null && creExports.length > 0) {
|
|
22
|
+
console.error("❌ Error: --plugin and --cre-exports are mutually exclusive.");
|
|
41
23
|
process.exit(1);
|
|
42
24
|
}
|
|
43
25
|
|
|
44
|
-
await compileWorkflow(
|
|
26
|
+
await compileWorkflow(
|
|
27
|
+
inputPath,
|
|
28
|
+
outputPathArg,
|
|
29
|
+
creExports.length > 0 ? creExports : undefined,
|
|
30
|
+
plugin ?? undefined,
|
|
31
|
+
);
|
|
45
32
|
};
|
|
46
33
|
|
|
47
|
-
// CLI entry point
|
|
48
34
|
main().catch((e) => {
|
|
49
|
-
if (
|
|
50
|
-
e instanceof WorkflowRuntimeCompatibilityError ||
|
|
51
|
-
e instanceof WorkflowTypecheckError
|
|
52
|
-
) {
|
|
35
|
+
if (e instanceof WorkflowRuntimeCompatibilityError) {
|
|
53
36
|
console.error(`\n❌ ${e.message}`);
|
|
54
37
|
} else {
|
|
55
38
|
console.error(e);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type Environment = {
|
|
2
|
+
chainSelector: bigint;
|
|
3
|
+
registryAddress: string;
|
|
4
|
+
};
|
|
5
|
+
export type Zone = {
|
|
6
|
+
environment: Environment;
|
|
7
|
+
donID: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function productionEnvironment(): Environment;
|
|
10
|
+
export declare function zoneFromEnvironment(environment: Environment, donID: number): Zone;
|
package/dist/sdk/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SecretRequest } from '../generated/sdk/v1alpha/sdk_pb';
|
|
2
2
|
export declare class DonModeError extends Error {
|
|
3
3
|
constructor();
|
|
4
4
|
}
|
|
@@ -10,3 +10,26 @@ export declare class SecretsError extends Error {
|
|
|
10
10
|
error: string;
|
|
11
11
|
constructor(secretRequest: SecretRequest, error: string);
|
|
12
12
|
}
|
|
13
|
+
export declare class NullReportError extends Error {
|
|
14
|
+
constructor();
|
|
15
|
+
}
|
|
16
|
+
export declare class WrongSignatureCountError extends Error {
|
|
17
|
+
constructor();
|
|
18
|
+
}
|
|
19
|
+
export declare class ParseSignatureError extends Error {
|
|
20
|
+
constructor();
|
|
21
|
+
}
|
|
22
|
+
export declare class RecoverSignerError extends Error {
|
|
23
|
+
constructor();
|
|
24
|
+
}
|
|
25
|
+
export declare class UnknownSignerError extends Error {
|
|
26
|
+
constructor();
|
|
27
|
+
}
|
|
28
|
+
export declare class DuplicateSignerError extends Error {
|
|
29
|
+
constructor();
|
|
30
|
+
}
|
|
31
|
+
export declare class RawReportTooShortError extends Error {
|
|
32
|
+
readonly need: number;
|
|
33
|
+
readonly got: number;
|
|
34
|
+
constructor(need: number, got: number);
|
|
35
|
+
}
|
package/dist/sdk/errors.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Mode } from '../generated/sdk/v1alpha/sdk_pb';
|
|
2
1
|
export class DonModeError extends Error {
|
|
3
2
|
constructor() {
|
|
4
3
|
super('cannot use Runtime inside RunInNodeMode');
|
|
@@ -21,3 +20,49 @@ export class SecretsError extends Error {
|
|
|
21
20
|
this.name = 'SecretsError';
|
|
22
21
|
}
|
|
23
22
|
}
|
|
23
|
+
export class NullReportError extends Error {
|
|
24
|
+
constructor() {
|
|
25
|
+
super('null report');
|
|
26
|
+
this.name = 'NullReportError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class WrongSignatureCountError extends Error {
|
|
30
|
+
constructor() {
|
|
31
|
+
super('wrong number of signatures');
|
|
32
|
+
this.name = 'WrongSignatureCountError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class ParseSignatureError extends Error {
|
|
36
|
+
constructor() {
|
|
37
|
+
super('failed to parse signature');
|
|
38
|
+
this.name = 'ParseSignatureError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class RecoverSignerError extends Error {
|
|
42
|
+
constructor() {
|
|
43
|
+
super('failed to recover signer address from signature');
|
|
44
|
+
this.name = 'RecoverSignerError';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export class UnknownSignerError extends Error {
|
|
48
|
+
constructor() {
|
|
49
|
+
super('invalid signature');
|
|
50
|
+
this.name = 'UnknownSignerError';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class DuplicateSignerError extends Error {
|
|
54
|
+
constructor() {
|
|
55
|
+
super('duplicate signer');
|
|
56
|
+
this.name = 'DuplicateSignerError';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class RawReportTooShortError extends Error {
|
|
60
|
+
need;
|
|
61
|
+
got;
|
|
62
|
+
constructor(need, got) {
|
|
63
|
+
super(`raw report too short to contain metadata header: need ${need} bytes, got ${got}`);
|
|
64
|
+
this.need = need;
|
|
65
|
+
this.got = got;
|
|
66
|
+
this.name = 'RawReportTooShortError';
|
|
67
|
+
}
|
|
68
|
+
}
|
package/dist/sdk/index.d.ts
CHANGED
package/dist/sdk/index.js
CHANGED
package/dist/sdk/report.d.ts
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
import { type ReportResponse, type ReportResponseJson } from '../generated/sdk/v1alpha/sdk_pb';
|
|
2
|
+
import { type Environment, type Zone } from './don-info';
|
|
3
|
+
import type { BaseRuntime } from './runtime';
|
|
4
|
+
export type ReportParseConfig = {
|
|
5
|
+
acceptedZones?: Zone[];
|
|
6
|
+
acceptedEnvironments?: Environment[];
|
|
7
|
+
skipSignatureVerification?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const REPORT_METADATA_HEADER_LENGTH = 109;
|
|
10
|
+
export type ReportMetadataHeader = {
|
|
11
|
+
version: number;
|
|
12
|
+
executionId: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
donId: number;
|
|
15
|
+
donConfigVersion: number;
|
|
16
|
+
workflowId: string;
|
|
17
|
+
workflowName: string;
|
|
18
|
+
workflowOwner: string;
|
|
19
|
+
reportId: string;
|
|
20
|
+
body: Uint8Array;
|
|
21
|
+
};
|
|
2
22
|
export declare class Report {
|
|
3
23
|
private readonly report;
|
|
24
|
+
private cachedHeader;
|
|
4
25
|
constructor(report: ReportResponse | ReportResponseJson);
|
|
26
|
+
static parse(runtime: BaseRuntime<unknown>, rawReport: Uint8Array, signatures: Uint8Array[], reportContext: Uint8Array, config?: ReportParseConfig): Promise<Report>;
|
|
27
|
+
private parseHeader;
|
|
28
|
+
private verifySignaturesWithConfig;
|
|
29
|
+
seqNr(): bigint;
|
|
30
|
+
configDigest(): Uint8Array;
|
|
31
|
+
reportContext(): Uint8Array;
|
|
32
|
+
rawReport(): Uint8Array;
|
|
33
|
+
version(): number;
|
|
34
|
+
executionId(): string;
|
|
35
|
+
timestamp(): number;
|
|
36
|
+
donId(): number;
|
|
37
|
+
donConfigVersion(): number;
|
|
38
|
+
workflowId(): string;
|
|
39
|
+
workflowName(): string;
|
|
40
|
+
workflowOwner(): string;
|
|
41
|
+
reportId(): string;
|
|
42
|
+
body(): Uint8Array;
|
|
5
43
|
x_generatedCodeOnly_unwrap(): ReportResponse;
|
|
6
44
|
}
|