@chainlink/cre-sdk 1.15.0 → 1.17.0-alpha.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/README.md +2 -62
- package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.d.ts +1035 -0
- package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.js +290 -0
- package/dist/generated/capabilities/blockchain/evm/v1alpha/client_pb.js +1 -1
- package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.d.ts +2885 -15
- package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.js +459 -7
- package/dist/generated/capabilities/networking/http/v1alpha/client_pb.js +1 -1
- package/dist/generated/sdk/v1alpha/sdk_pb.d.ts +505 -0
- package/dist/generated/sdk/v1alpha/sdk_pb.js +121 -15
- package/dist/generated/tools/generator/v1alpha/cre_metadata_pb.d.ts +30 -1
- package/dist/generated/tools/generator/v1alpha/cre_metadata_pb.js +20 -2
- package/dist/generated/workflows/v2/cre_info_pb.d.ts +123 -0
- package/dist/generated/workflows/v2/cre_info_pb.js +17 -0
- package/dist/generated/workflows/v2/workflow_key_pb.d.ts +55 -0
- package/dist/generated/workflows/v2/workflow_key_pb.js +17 -0
- package/dist/generated/workflows/v2/workflow_user_metric_pb.d.ts +118 -0
- package/dist/generated/workflows/v2/workflow_user_metric_pb.js +41 -0
- package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.d.ts +63 -0
- package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.js +247 -0
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +14 -0
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +95 -0
- package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +69 -2
- package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +403 -1
- package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.d.ts +5 -1
- package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.js +22 -0
- package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.d.ts +4 -0
- package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.js +12 -0
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.d.ts +11 -1
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.js +12 -0
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.d.ts +2 -0
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.js +2 -0
- package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.d.ts +2 -0
- package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +2 -0
- package/dist/sdk/cre/index.d.ts +30 -15
- package/dist/sdk/cre/index.js +29 -14
- package/dist/sdk/impl/runtime-impl.d.ts +28 -1
- package/dist/sdk/impl/runtime-impl.js +52 -1
- package/dist/sdk/runtime.d.ts +23 -1
- package/dist/sdk/tee-constraints.d.ts +68 -0
- package/dist/sdk/tee-constraints.js +59 -0
- package/dist/sdk/test/evm-contract-mock.js +58 -60
- package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.d.ts +25 -0
- package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.js +111 -0
- package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.d.ts +19 -1
- package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.js +141 -1
- package/dist/sdk/test/generated/index.d.ts +1 -0
- package/dist/sdk/test/generated/index.js +1 -0
- package/dist/sdk/test/index.d.ts +0 -1
- package/dist/sdk/test/index.js +0 -1
- package/dist/sdk/testutils/index.d.ts +1 -1
- package/dist/sdk/testutils/index.js +1 -1
- package/dist/sdk/testutils/test-runtime.d.ts +17 -4
- package/dist/sdk/testutils/test-runtime.js +31 -5
- package/dist/sdk/testutils/test-writer.d.ts +7 -1
- package/dist/sdk/testutils/test-writer.js +13 -1
- package/dist/sdk/types/global.d.ts +8 -0
- package/dist/sdk/utils/capabilities/blockchain/{evm/evm-helpers.d.ts → blockchain-helpers.d.ts} +6 -7
- package/dist/sdk/utils/capabilities/blockchain/{evm/evm-helpers.js → blockchain-helpers.js} +8 -6
- package/dist/sdk/utils/hex-utils.d.ts +0 -6
- package/dist/sdk/utils/hex-utils.js +0 -8
- package/dist/sdk/utils/index.d.ts +1 -3
- package/dist/sdk/utils/index.js +1 -2
- package/dist/sdk/wasm/host-bindings.d.ts +4 -0
- package/dist/sdk/wasm/host-bindings.js +4 -0
- package/dist/sdk/wasm/runner.d.ts +10 -4
- package/dist/sdk/wasm/runner.js +86 -13
- package/dist/sdk/wasm/runtime.d.ts +4 -1
- package/dist/sdk/wasm/runtime.js +9 -1
- package/dist/sdk/workflow.d.ts +16 -7
- package/dist/sdk/workflow.js +10 -2
- package/dist/workflows/standard_tests/restrictions/test.ts +41 -0
- package/dist/workflows/standard_tests/tee_runtime/test.ts +29 -0
- package/package.json +3 -6
- package/scripts/src/generate-sdks.ts +6 -0
- package/dist/sdk/test/contract-mock-core.d.ts +0 -16
- package/dist/sdk/test/contract-mock-core.js +0 -21
- package/dist/sdk/test/solana-contract-mock.d.ts +0 -54
- package/dist/sdk/test/solana-contract-mock.js +0 -63
- package/dist/sdk/utils/capabilities/blockchain/report-helpers.d.ts +0 -19
- package/dist/sdk/utils/capabilities/blockchain/report-helpers.js +0 -16
- package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.d.ts +0 -101
- package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.js +0 -100
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export * from './capabilities/blockchain/
|
|
2
|
-
export type { ReportEncoder } from './capabilities/blockchain/report-helpers';
|
|
3
|
-
export * from './capabilities/blockchain/solana/solana-helpers';
|
|
1
|
+
export * from './capabilities/blockchain/blockchain-helpers';
|
|
4
2
|
export * from './capabilities/http/http-helpers';
|
|
5
3
|
export * from './chain-selectors';
|
|
6
4
|
export * from './decode-json';
|
package/dist/sdk/utils/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export * from './capabilities/blockchain/
|
|
2
|
-
export * from './capabilities/blockchain/solana/solana-helpers';
|
|
1
|
+
export * from './capabilities/blockchain/blockchain-helpers';
|
|
3
2
|
export * from './capabilities/http/http-helpers';
|
|
4
3
|
export * from './chain-selectors';
|
|
5
4
|
export * from './decode-json';
|
|
@@ -11,6 +11,7 @@ export declare const globalHostBindingsSchema: z.ZodObject<{
|
|
|
11
11
|
awaitSecrets: z.ZodFunction<z.ZodTuple<[z.ZodUnion<[z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>, z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>]>, z.ZodNumber], z.ZodUnknown>, z.ZodUnion<[z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>, z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>]>>;
|
|
12
12
|
getWasiArgs: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodString>;
|
|
13
13
|
now: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodNumber>;
|
|
14
|
+
emitMetric: z.ZodFunction<z.ZodTuple<[z.ZodUnion<[z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>, z.ZodType<Uint8Array<ArrayBufferLike>, z.ZodTypeDef, Uint8Array<ArrayBufferLike>>]>], z.ZodUnknown>, z.ZodNumber>;
|
|
14
15
|
sleep: z.ZodFunction<z.ZodTuple<[z.ZodNumber], z.ZodUnknown>, z.ZodVoid>;
|
|
15
16
|
}, "strip", z.ZodTypeAny, {
|
|
16
17
|
callCapability: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
|
|
@@ -18,6 +19,7 @@ export declare const globalHostBindingsSchema: z.ZodObject<{
|
|
|
18
19
|
getSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => any;
|
|
19
20
|
awaitSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>;
|
|
20
21
|
log: (args_0: string, ...args: unknown[]) => void;
|
|
22
|
+
emitMetric: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
|
|
21
23
|
sendResponse: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
|
|
22
24
|
switchModes: (args_0: Mode, ...args: unknown[]) => void;
|
|
23
25
|
versionV2: (...args: unknown[]) => void;
|
|
@@ -30,6 +32,7 @@ export declare const globalHostBindingsSchema: z.ZodObject<{
|
|
|
30
32
|
getSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => any;
|
|
31
33
|
awaitSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>;
|
|
32
34
|
log: (args_0: string, ...args: unknown[]) => void;
|
|
35
|
+
emitMetric: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
|
|
33
36
|
sendResponse: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
|
|
34
37
|
switchModes: (args_0: Mode, ...args: unknown[]) => void;
|
|
35
38
|
versionV2: (...args: unknown[]) => void;
|
|
@@ -43,6 +46,7 @@ export declare const hostBindings: {
|
|
|
43
46
|
getSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => any;
|
|
44
47
|
awaitSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>;
|
|
45
48
|
log: (args_0: string, ...args: unknown[]) => void;
|
|
49
|
+
emitMetric: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
|
|
46
50
|
sendResponse: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
|
|
47
51
|
switchModes: (args_0: Mode, ...args: unknown[]) => void;
|
|
48
52
|
versionV2: (...args: unknown[]) => void;
|
|
@@ -27,6 +27,10 @@ export const globalHostBindingsSchema = z.object({
|
|
|
27
27
|
.returns(z.union([z.instanceof(Uint8Array), z.custom()])),
|
|
28
28
|
getWasiArgs: z.function().args().returns(z.string()),
|
|
29
29
|
now: z.function().args().returns(z.number()),
|
|
30
|
+
emitMetric: z
|
|
31
|
+
.function()
|
|
32
|
+
.args(z.union([z.instanceof(Uint8Array), z.custom()]))
|
|
33
|
+
.returns(z.number()),
|
|
30
34
|
sleep: z.function().args(z.number()).returns(z.void()),
|
|
31
35
|
});
|
|
32
36
|
// Validate global host functions at runtime
|
|
@@ -2,13 +2,19 @@ import { type ExecuteRequest, type ExecutionResult } from '../../generated/sdk/v
|
|
|
2
2
|
import { type ConfigHandlerParams } from '../utils/config';
|
|
3
3
|
import type { SecretsProvider, Workflow } from '../workflow';
|
|
4
4
|
import { Runtime } from './runtime';
|
|
5
|
-
|
|
5
|
+
declare class RunnerBase<TConfig> {
|
|
6
6
|
private readonly config;
|
|
7
7
|
private readonly request;
|
|
8
|
-
|
|
9
|
-
static
|
|
8
|
+
protected constructor(config: TConfig, request: ExecuteRequest);
|
|
9
|
+
protected static newRunnerHelper<TConfig, TIntermediateConfig, TRunner>(newRunner: (config: TConfig, request: ExecuteRequest) => TRunner, configHandlerParams?: ConfigHandlerParams<TConfig, TIntermediateConfig>): Promise<TRunner>;
|
|
10
10
|
private static getRequest;
|
|
11
11
|
run(initFn: (config: TConfig, secretsProvider: SecretsProvider) => Promise<Workflow<TConfig>> | Workflow<TConfig>): Promise<void>;
|
|
12
|
-
handleExecutionPhase
|
|
12
|
+
handleExecutionPhase(req: ExecuteRequest, workflow: Workflow<TConfig>, runtime: Runtime<TConfig>): Promise<ExecutionResult>;
|
|
13
|
+
handlePreHookPhase(req: ExecuteRequest, workflow: Workflow<TConfig>): ExecutionResult;
|
|
13
14
|
handleSubscribePhase(req: ExecuteRequest, workflow: Workflow<TConfig>): ExecutionResult;
|
|
14
15
|
}
|
|
16
|
+
export declare class Runner<TConfig> extends RunnerBase<TConfig> {
|
|
17
|
+
private constructor();
|
|
18
|
+
static newRunner<TConfig, TIntermediateConfig = TConfig>(configHandlerParams?: ConfigHandlerParams<TConfig, TIntermediateConfig>): Promise<Runner<TConfig>>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
package/dist/sdk/wasm/runner.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { create, fromBinary, toBinary } from '@bufbuild/protobuf';
|
|
2
|
-
import { ExecuteRequestSchema, ExecutionResultSchema, TriggerSubscriptionRequestSchema, } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
1
|
+
import { create, fromBinary, fromJson, toBinary } from '@bufbuild/protobuf';
|
|
2
|
+
import { ExecuteRequestSchema, ExecutionResultSchema, RestrictionsSchema, TriggerSubscriptionRequestSchema, } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
3
3
|
import { configHandler } from '../utils/config';
|
|
4
4
|
import { Value } from '../utils';
|
|
5
5
|
import { hostBindings } from './host-bindings';
|
|
6
|
-
import { Runtime } from './runtime';
|
|
7
|
-
|
|
6
|
+
import { Runtime, TeeRuntime } from './runtime';
|
|
7
|
+
class RunnerBase {
|
|
8
8
|
config;
|
|
9
9
|
request;
|
|
10
10
|
constructor(config, request) {
|
|
11
11
|
this.config = config;
|
|
12
12
|
this.request = request;
|
|
13
13
|
}
|
|
14
|
-
static async newRunner
|
|
14
|
+
static async newRunnerHelper(newRunner, configHandlerParams) {
|
|
15
15
|
hostBindings.versionV2();
|
|
16
|
-
const request =
|
|
16
|
+
const request = RunnerBase.getRequest();
|
|
17
17
|
const config = await configHandler(request, configHandlerParams);
|
|
18
|
-
return
|
|
18
|
+
return newRunner(config, request);
|
|
19
19
|
}
|
|
20
20
|
static getRequest() {
|
|
21
21
|
const argsString = hostBindings.getWasiArgs();
|
|
@@ -38,11 +38,15 @@ export class Runner {
|
|
|
38
38
|
}
|
|
39
39
|
async run(initFn) {
|
|
40
40
|
const runtime = new Runtime(this.config, 0, this.request.maxResponseSize);
|
|
41
|
+
// wrap runtime's getSecret so other methods cannot be used
|
|
42
|
+
const sp = {
|
|
43
|
+
getSecret: (request) => {
|
|
44
|
+
return runtime.getSecret(request);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
41
47
|
let result;
|
|
42
48
|
try {
|
|
43
|
-
const workflow = await initFn(this.config,
|
|
44
|
-
getSecret: runtime.getSecret.bind(runtime),
|
|
45
|
-
});
|
|
49
|
+
const workflow = await initFn(this.config, sp);
|
|
46
50
|
switch (this.request.request.case) {
|
|
47
51
|
case 'subscribe':
|
|
48
52
|
result = this.handleSubscribePhase(this.request, workflow);
|
|
@@ -50,8 +54,11 @@ export class Runner {
|
|
|
50
54
|
case 'trigger':
|
|
51
55
|
result = this.handleExecutionPhase(this.request, workflow, runtime);
|
|
52
56
|
break;
|
|
57
|
+
case 'preHook':
|
|
58
|
+
result = this.handlePreHookPhase(this.request, workflow);
|
|
59
|
+
break;
|
|
53
60
|
default:
|
|
54
|
-
throw new Error(`Unknown request type '${this.request.request.case}': expected 'subscribe' or '
|
|
61
|
+
throw new Error(`Unknown request type '${this.request.request.case}': expected 'subscribe', 'trigger', or 'preHook'. This may indicate a version mismatch between the SDK and the CRE runtime`);
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
catch (e) {
|
|
@@ -95,8 +102,10 @@ export class Runner {
|
|
|
95
102
|
* */
|
|
96
103
|
const decoded = fromBinary(schema, payloadAny.value);
|
|
97
104
|
const adapted = entry.trigger.adapt(decoded);
|
|
105
|
+
// If the handler has requirements (e.g. TEE), use TeeRuntime; otherwise use the default runtime.
|
|
106
|
+
const handlerRuntime = entry.requirements != null ? new TeeRuntime(this.config, 0, req.maxResponseSize) : runtime;
|
|
98
107
|
try {
|
|
99
|
-
const result = await entry.fn(
|
|
108
|
+
const result = await entry.fn(handlerRuntime, adapted);
|
|
100
109
|
const wrapped = Value.wrap(result);
|
|
101
110
|
return create(ExecutionResultSchema, {
|
|
102
111
|
result: { case: 'value', value: wrapped.proto() },
|
|
@@ -116,6 +125,60 @@ export class Runner {
|
|
|
116
125
|
},
|
|
117
126
|
});
|
|
118
127
|
}
|
|
128
|
+
handlePreHookPhase(req, workflow) {
|
|
129
|
+
if (req.request.case !== 'preHook') {
|
|
130
|
+
return create(ExecutionResultSchema, {
|
|
131
|
+
result: {
|
|
132
|
+
case: 'error',
|
|
133
|
+
value: `preHook request expected but received '${req.request.case}' in handlePreHookPhase. This is an internal SDK error`,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const triggerMsg = req.request.value;
|
|
138
|
+
const id = BigInt(triggerMsg.id);
|
|
139
|
+
if (id > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
140
|
+
return create(ExecutionResultSchema, {
|
|
141
|
+
result: {
|
|
142
|
+
case: 'error',
|
|
143
|
+
value: `Trigger ID ${id} exceeds JavaScript safe integer range (Number.MAX_SAFE_INTEGER = ${Number.MAX_SAFE_INTEGER}). This trigger ID cannot be safely represented as a number`,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const index = Number(triggerMsg.id);
|
|
148
|
+
if (!Number.isFinite(index) || index < 0 || index >= workflow.length) {
|
|
149
|
+
return create(ExecutionResultSchema, {
|
|
150
|
+
result: {
|
|
151
|
+
case: 'error',
|
|
152
|
+
value: `trigger not found: no workflow handler registered at index ${index} (trigger ID ${triggerMsg.id}). The workflow has ${workflow.length} handler(s) registered. Verify the trigger subscription matches a registered handler`,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const entry = workflow[index];
|
|
157
|
+
if (!entry.hooks?.preHook) {
|
|
158
|
+
return create(ExecutionResultSchema, {
|
|
159
|
+
result: {
|
|
160
|
+
case: 'error',
|
|
161
|
+
value: `no preHook registered for handler at index ${index} (trigger ID ${triggerMsg.id}). The handler was subscribed with preHook enabled but no preHook function was provided`,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (!triggerMsg.payload) {
|
|
166
|
+
return create(ExecutionResultSchema, {
|
|
167
|
+
result: {
|
|
168
|
+
case: 'error',
|
|
169
|
+
value: `trigger payload is missing for preHook at index ${index} (trigger ID ${triggerMsg.id}). The trigger event must include a payload`,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const schema = entry.trigger.outputSchema();
|
|
174
|
+
const decoded = fromBinary(schema, triggerMsg.payload.value);
|
|
175
|
+
const adapted = entry.trigger.adapt(decoded);
|
|
176
|
+
const restrictionsJson = entry.hooks.preHook(this.config, adapted);
|
|
177
|
+
const restrictions = fromJson(RestrictionsSchema, restrictionsJson);
|
|
178
|
+
return create(ExecutionResultSchema, {
|
|
179
|
+
result: { case: 'restrictions', value: restrictions },
|
|
180
|
+
});
|
|
181
|
+
}
|
|
119
182
|
handleSubscribePhase(req, workflow) {
|
|
120
183
|
if (req.request.case !== 'subscribe') {
|
|
121
184
|
return create(ExecutionResultSchema, {
|
|
@@ -125,11 +188,13 @@ export class Runner {
|
|
|
125
188
|
},
|
|
126
189
|
});
|
|
127
190
|
}
|
|
128
|
-
// Build TriggerSubscriptionRequest from the workflow entries
|
|
191
|
+
// Build TriggerSubscriptionRequest from the workflow entries, including any per-handler requirements.
|
|
129
192
|
const subscriptions = workflow.map((entry) => ({
|
|
130
193
|
id: entry.trigger.capabilityId(),
|
|
131
194
|
method: entry.trigger.method(),
|
|
132
195
|
payload: entry.trigger.configAsAny(),
|
|
196
|
+
requirements: entry.requirements,
|
|
197
|
+
preHook: !!entry.hooks?.preHook,
|
|
133
198
|
}));
|
|
134
199
|
const subscriptionRequest = create(TriggerSubscriptionRequestSchema, {
|
|
135
200
|
subscriptions,
|
|
@@ -139,3 +204,11 @@ export class Runner {
|
|
|
139
204
|
});
|
|
140
205
|
}
|
|
141
206
|
}
|
|
207
|
+
export class Runner extends RunnerBase {
|
|
208
|
+
constructor(config, request) {
|
|
209
|
+
super(config, request);
|
|
210
|
+
}
|
|
211
|
+
static async newRunner(configHandlerParams) {
|
|
212
|
+
return RunnerBase.newRunnerHelper((config, request) => new Runner(config, request), configHandlerParams);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { NodeRuntimeImpl, RuntimeImpl } from '../impl/runtime-impl';
|
|
1
|
+
import { NodeRuntimeImpl, RuntimeImpl, TeeRuntimeImpl } from '../impl/runtime-impl';
|
|
2
2
|
export declare class Runtime<C> extends RuntimeImpl<C> {
|
|
3
3
|
constructor(config: C, nextCallId: number, maxResponseSize: bigint);
|
|
4
4
|
}
|
|
5
5
|
export declare class NodeRuntime<C> extends NodeRuntimeImpl<C> {
|
|
6
6
|
constructor(config: C, nextCallId: number, maxResponseSize: bigint);
|
|
7
7
|
}
|
|
8
|
+
export declare class TeeRuntime<C> extends TeeRuntimeImpl<C> {
|
|
9
|
+
constructor(config: C, nextCallId: number, maxResponseSize: bigint);
|
|
10
|
+
}
|
package/dist/sdk/wasm/runtime.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { fromBinary, toBinary } from '@bufbuild/protobuf';
|
|
2
2
|
import { AwaitCapabilitiesRequestSchema, AwaitCapabilitiesResponseSchema, AwaitSecretsRequestSchema, AwaitSecretsResponseSchema, CapabilityRequestSchema, GetSecretsRequestSchema, } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
-
import { NodeRuntimeImpl, RuntimeImpl } from '../impl/runtime-impl';
|
|
3
|
+
import { NodeRuntimeImpl, RuntimeImpl, TeeRuntimeImpl, } from '../impl/runtime-impl';
|
|
4
4
|
import { hostBindings } from './host-bindings';
|
|
5
5
|
export class Runtime extends RuntimeImpl {
|
|
6
6
|
constructor(config, nextCallId, maxResponseSize) {
|
|
@@ -12,6 +12,11 @@ export class NodeRuntime extends NodeRuntimeImpl {
|
|
|
12
12
|
super(config, nextCallId, WasmRuntimeHelpers.getInstance(), maxResponseSize);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
export class TeeRuntime extends TeeRuntimeImpl {
|
|
16
|
+
constructor(config, nextCallId, maxResponseSize) {
|
|
17
|
+
super(config, nextCallId, WasmRuntimeHelpers.getInstance(), maxResponseSize);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
15
20
|
/** Convert bigint maxResponseSize to i32 for WASM host binding, with range validation. */
|
|
16
21
|
function toI32ResponseSize(maxResponseSize) {
|
|
17
22
|
if (maxResponseSize > 2147483647n || maxResponseSize < -2147483648n) {
|
|
@@ -59,4 +64,7 @@ class WasmRuntimeHelpers {
|
|
|
59
64
|
log(message) {
|
|
60
65
|
hostBindings.log(message);
|
|
61
66
|
}
|
|
67
|
+
emitMetric(payload) {
|
|
68
|
+
return hostBindings.emitMetric(payload) >= 0;
|
|
69
|
+
}
|
|
62
70
|
}
|
package/dist/sdk/workflow.d.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import type { Message } from '@bufbuild/protobuf';
|
|
2
|
-
import type { Secret, SecretRequest, SecretRequestJson } from '../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
-
import {
|
|
2
|
+
import type { Requirements, RestrictionsJson, Secret, SecretRequest, SecretRequestJson } from '../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
+
import type { Runtime, TeeRuntime } from './runtime';
|
|
4
4
|
import type { Trigger } from './utils/triggers/trigger-interface';
|
|
5
5
|
import type { CreSerializable } from './utils';
|
|
6
|
-
export type
|
|
7
|
-
export
|
|
6
|
+
export type { AnyTeeConstraint, NitroBinding, NitroRegion, OneOfTees, Region, TeeBinding, TeeConstraint, } from './tee-constraints';
|
|
7
|
+
export { buildTeeRequirements, NITRO_REGIONS, REGIONS, teeConstraintSchema, } from './tee-constraints';
|
|
8
|
+
import type { TeeConstraint } from './tee-constraints';
|
|
9
|
+
export type HandlerFn<TConfig, TTriggerOutput, TResult, TRuntime = Runtime<TConfig>> = (runtime: TRuntime, triggerOutput: TTriggerOutput) => Promise<CreSerializable<TResult>> | CreSerializable<TResult>;
|
|
10
|
+
export interface Hooks<TConfig, TTriggerOutput> {
|
|
11
|
+
preHook?: (config: TConfig, triggerOutput: TTriggerOutput) => RestrictionsJson;
|
|
12
|
+
}
|
|
13
|
+
export interface HandlerEntry<TConfig, TRawTriggerOutput extends Message<string>, TTriggerOutput, TResult, TRuntime = Runtime<TConfig>> {
|
|
8
14
|
trigger: Trigger<TRawTriggerOutput, TTriggerOutput>;
|
|
9
|
-
fn: HandlerFn<TConfig, TTriggerOutput, TResult>;
|
|
15
|
+
fn: HandlerFn<TConfig, TTriggerOutput, TResult, TRuntime>;
|
|
16
|
+
requirements?: Requirements;
|
|
17
|
+
hooks?: Hooks<TConfig, TTriggerOutput>;
|
|
10
18
|
}
|
|
11
|
-
export type Workflow<TConfig> = ReadonlyArray<HandlerEntry<TConfig, any, any, any>>;
|
|
12
|
-
export declare const handler: <TRawTriggerOutput extends Message<string>, TTriggerOutput, TConfig, TResult
|
|
19
|
+
export type Workflow<TConfig> = ReadonlyArray<HandlerEntry<TConfig, any, any, any, any>>;
|
|
20
|
+
export declare const handler: <TRawTriggerOutput extends Message<string>, TTriggerOutput, TConfig, TResult, TRuntime = Runtime<TConfig>>(trigger: Trigger<TRawTriggerOutput, TTriggerOutput>, fn: HandlerFn<TConfig, TTriggerOutput, TResult, TRuntime>, hooks?: Hooks<TConfig, TTriggerOutput>) => HandlerEntry<TConfig, TRawTriggerOutput, TTriggerOutput, TResult, TRuntime>;
|
|
21
|
+
export declare const handlerInTee: <TRawTriggerOutput extends Message<string>, TTriggerOutput, TConfig, TResult>(trigger: Trigger<TRawTriggerOutput, TTriggerOutput>, fn: HandlerFn<TConfig, TTriggerOutput, TResult, TeeRuntime<TConfig>>, tees: TeeConstraint, hooks?: Hooks<TConfig, TTriggerOutput>) => HandlerEntry<TConfig, TRawTriggerOutput, TTriggerOutput, TResult, TeeRuntime<TConfig>>;
|
|
13
22
|
export type SecretsProvider = {
|
|
14
23
|
getSecret(request: SecretRequest | SecretRequestJson): {
|
|
15
24
|
result: () => Secret;
|
package/dist/sdk/workflow.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { buildTeeRequirements, NITRO_REGIONS, REGIONS, teeConstraintSchema, } from './tee-constraints';
|
|
2
|
+
import { buildTeeRequirements } from './tee-constraints';
|
|
3
|
+
export const handler = (trigger, fn, hooks) => ({
|
|
3
4
|
trigger,
|
|
4
5
|
fn,
|
|
6
|
+
hooks,
|
|
7
|
+
});
|
|
8
|
+
export const handlerInTee = (trigger, fn, tees, hooks) => ({
|
|
9
|
+
trigger,
|
|
10
|
+
fn,
|
|
11
|
+
requirements: buildTeeRequirements(tees),
|
|
12
|
+
hooks,
|
|
5
13
|
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Outputs } from '@cre/generated/capabilities/internal/basictrigger/v1/basic_trigger_pb'
|
|
2
|
+
import type { RestrictionsJson } from '@cre/generated/sdk/v1alpha/sdk_pb'
|
|
3
|
+
import { BasicActionCapability } from '@cre/generated-sdk/capabilities/internal/basicaction/v1/basicaction_sdk_gen'
|
|
4
|
+
import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
|
|
5
|
+
import type { Workflow } from '@cre/sdk'
|
|
6
|
+
import { cre, type Runtime } from '@cre/sdk/cre'
|
|
7
|
+
import { Runner } from '@cre/sdk/wasm'
|
|
8
|
+
import type { ByteArray } from 'viem'
|
|
9
|
+
|
|
10
|
+
const trigger = (runtime: Runtime<Uint8Array>, __: Outputs): string => {
|
|
11
|
+
const basicCapability = new BasicActionCapability()
|
|
12
|
+
const result = basicCapability.performAction(runtime, { inputThing: true }).result()
|
|
13
|
+
return result.adaptedThing
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const preHook = (_: ByteArray, __: Outputs): RestrictionsJson => {
|
|
17
|
+
return {
|
|
18
|
+
capabilities: {
|
|
19
|
+
maxTotalCalls: 0,
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const initWorkflow = (_: ByteArray): Workflow<Uint8Array> => {
|
|
25
|
+
const basicTrigger = new BasicTriggerCapability()
|
|
26
|
+
|
|
27
|
+
return [
|
|
28
|
+
cre.handler(basicTrigger.trigger({ name: 'first-trigger', number: 100 }), trigger, {
|
|
29
|
+
preHook: preHook,
|
|
30
|
+
}),
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function main() {
|
|
35
|
+
const runner = await Runner.newRunner<Uint8Array>({
|
|
36
|
+
configParser: (c) => c,
|
|
37
|
+
})
|
|
38
|
+
await runner.run(initWorkflow)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
await main()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Outputs } from '@cre/generated/capabilities/internal/basictrigger/v1/basic_trigger_pb'
|
|
2
|
+
import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
|
|
3
|
+
import { cre, type Runtime, type TeeRuntime } from '@cre/sdk/cre'
|
|
4
|
+
import { Runner } from '@cre/sdk/wasm'
|
|
5
|
+
import { handlerInTee } from '@cre/sdk/workflow'
|
|
6
|
+
|
|
7
|
+
const teeTrigger = (_: TeeRuntime<Uint8Array>, __: Outputs) => 0
|
|
8
|
+
const regularTrigger = (_: Runtime<Uint8Array>, __: Outputs) => 0
|
|
9
|
+
|
|
10
|
+
const initWorkflow = () => {
|
|
11
|
+
const basicTrigger = new BasicTriggerCapability()
|
|
12
|
+
return [
|
|
13
|
+
handlerInTee(basicTrigger.trigger({ name: 'first-trigger', number: 100 }), teeTrigger, [
|
|
14
|
+
{ tee: 'nitro', regions: ['us-west-2'] },
|
|
15
|
+
]),
|
|
16
|
+
cre.handler(basicTrigger.trigger({ name: 'second-trigger', number: 200 }), regularTrigger),
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function main() {
|
|
21
|
+
console.log(`TS workflow: standard test: config [${new Date().toISOString()}]`)
|
|
22
|
+
|
|
23
|
+
const runner = await Runner.newRunner<Uint8Array>({
|
|
24
|
+
configParser: (c: Uint8Array) => c,
|
|
25
|
+
})
|
|
26
|
+
await runner.run(initWorkflow)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await main()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainlink/cre-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -61,10 +61,7 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@bufbuild/protobuf": "2.6.3",
|
|
63
63
|
"@bufbuild/protoc-gen-es": "2.6.3",
|
|
64
|
-
"@chainlink/cre-sdk-javy-plugin": "1.
|
|
65
|
-
"@noble/hashes": "2.2.0",
|
|
66
|
-
"@solana/addresses": "6.10.0",
|
|
67
|
-
"@solana/codecs": "6.10.0",
|
|
64
|
+
"@chainlink/cre-sdk-javy-plugin": "1.8.0-alpha.1",
|
|
68
65
|
"@standard-schema/spec": "1.0.0",
|
|
69
66
|
"viem": "2.34.0",
|
|
70
67
|
"zod": "3.25.76"
|
|
@@ -77,7 +74,7 @@
|
|
|
77
74
|
"fast-glob": "3.3.3",
|
|
78
75
|
"ts-proto": "2.7.5",
|
|
79
76
|
"typescript": "5.9.3",
|
|
80
|
-
"yaml": "2.
|
|
77
|
+
"yaml": "2.8.1"
|
|
81
78
|
},
|
|
82
79
|
"publishConfig": {
|
|
83
80
|
"access": "public"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { rmSync } from 'node:fs'
|
|
2
|
+
import { file_capabilities_blockchain_aptos_v1alpha_client } from '@cre/generated/capabilities/blockchain/aptos/v1alpha/client_pb'
|
|
2
3
|
import { file_capabilities_blockchain_evm_v1alpha_client } from '@cre/generated/capabilities/blockchain/evm/v1alpha/client_pb'
|
|
3
4
|
import { file_capabilities_blockchain_solana_v1alpha_client } from '@cre/generated/capabilities/blockchain/solana/v1alpha/client_pb'
|
|
4
5
|
import { file_capabilities_internal_actionandtrigger_v1_action_and_trigger } from '@cre/generated/capabilities/internal/actionandtrigger/v1/action_and_trigger_pb'
|
|
@@ -64,6 +65,11 @@ export const main = () => {
|
|
|
64
65
|
...generateMocks(file_capabilities_blockchain_evm_v1alpha_client, TEST_GENERATED_DIR),
|
|
65
66
|
)
|
|
66
67
|
|
|
68
|
+
generateSdk(file_capabilities_blockchain_aptos_v1alpha_client, './src/generated-sdk')
|
|
69
|
+
allMockExports.push(
|
|
70
|
+
...generateMocks(file_capabilities_blockchain_aptos_v1alpha_client, TEST_GENERATED_DIR),
|
|
71
|
+
)
|
|
72
|
+
|
|
67
73
|
generateSdk(file_capabilities_blockchain_solana_v1alpha_client, './src/generated-sdk')
|
|
68
74
|
allMockExports.push(
|
|
69
75
|
...generateMocks(file_capabilities_blockchain_solana_v1alpha_client, TEST_GENERATED_DIR),
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chain-agnostic core of the per-contract mock routing used by
|
|
3
|
-
* `addContractMock` (EVM) and `addSolanaContractMock` (Solana).
|
|
4
|
-
*
|
|
5
|
-
* Builds a handler that routes a request to `handle` when `matches` returns
|
|
6
|
-
* true, falls through to the previously installed handler otherwise, and
|
|
7
|
-
* throws `noMatchError` when there is nothing to fall through to. Installing
|
|
8
|
-
* the returned handler over the previous one is what lets multiple contract
|
|
9
|
-
* mocks chain on the same capability mock.
|
|
10
|
-
*/
|
|
11
|
-
export declare function chainContractHandler<TReq, TReply>(options: {
|
|
12
|
-
previous: ((req: TReq) => TReply) | undefined;
|
|
13
|
-
matches: (req: TReq) => boolean;
|
|
14
|
-
handle: (req: TReq) => TReply;
|
|
15
|
-
noMatchError: (req: TReq) => string;
|
|
16
|
-
}): (req: TReq) => TReply;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chain-agnostic core of the per-contract mock routing used by
|
|
3
|
-
* `addContractMock` (EVM) and `addSolanaContractMock` (Solana).
|
|
4
|
-
*
|
|
5
|
-
* Builds a handler that routes a request to `handle` when `matches` returns
|
|
6
|
-
* true, falls through to the previously installed handler otherwise, and
|
|
7
|
-
* throws `noMatchError` when there is nothing to fall through to. Installing
|
|
8
|
-
* the returned handler over the previous one is what lets multiple contract
|
|
9
|
-
* mocks chain on the same capability mock.
|
|
10
|
-
*/
|
|
11
|
-
export function chainContractHandler(options) {
|
|
12
|
-
const { previous, matches, handle, noMatchError } = options;
|
|
13
|
-
return (req) => {
|
|
14
|
-
if (!matches(req)) {
|
|
15
|
-
if (previous)
|
|
16
|
-
return previous(req);
|
|
17
|
-
throw new Error(noMatchError(req));
|
|
18
|
-
}
|
|
19
|
-
return handle(req);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { AccountMeta, ComputeConfig, WriteReportReply, WriteReportReplyJson } from '../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
|
|
2
|
-
import type { ReportResponse } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
-
import type { SolanaMock } from './generated';
|
|
4
|
-
/**
|
|
5
|
-
* Strict version of {@link WriteReportRequest} where `report` is guaranteed
|
|
6
|
-
* to be present. Used by mock handlers so tests don't need to check for
|
|
7
|
-
* undefined.
|
|
8
|
-
*/
|
|
9
|
-
export interface SolanaWriteReportMockInput {
|
|
10
|
-
receiver: Uint8Array;
|
|
11
|
-
report: ReportResponse;
|
|
12
|
-
remainingAccounts: AccountMeta[];
|
|
13
|
-
computeConfig?: ComputeConfig;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* A program mock returned by {@link addSolanaContractMock}.
|
|
17
|
-
*
|
|
18
|
-
* The Solana CRE capability is write-only, so the only routable handler is
|
|
19
|
-
* `writeReport`. When set, write-report calls targeting this program's ID are
|
|
20
|
-
* routed here; calls for other receivers chain to previously registered mocks.
|
|
21
|
-
*/
|
|
22
|
-
export interface SolanaContractMock {
|
|
23
|
-
writeReport?: (input: SolanaWriteReportMockInput) => WriteReportReply | WriteReportReplyJson;
|
|
24
|
-
}
|
|
25
|
-
export interface AddSolanaContractMockOptions {
|
|
26
|
-
/** The receiver program ID — base58 string or 32 raw bytes. */
|
|
27
|
-
programId: string | Uint8Array;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Registers a typed program mock on a {@link SolanaMock} instance.
|
|
31
|
-
*
|
|
32
|
-
* This is the Solana counterpart of {@link addContractMock}: it intercepts
|
|
33
|
-
* `writeReport` on the provided mock, routing calls by receiver program ID.
|
|
34
|
-
* Multiple programs can be mocked on the same `SolanaMock` — each call to
|
|
35
|
-
* `addSolanaContractMock` chains with the previous handler.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* const solanaMock = SolanaMock.testInstance(chainSelector);
|
|
40
|
-
*
|
|
41
|
-
* const dataStorage = addSolanaContractMock(solanaMock, {
|
|
42
|
-
* programId: 'ECL8142j2YQAvs9R9geSsRnkVH2wLEi7soJCRyJ74cfL',
|
|
43
|
-
* });
|
|
44
|
-
*
|
|
45
|
-
* dataStorage.writeReport = ({ report, remainingAccounts }) => {
|
|
46
|
-
* return { txSignature: new Uint8Array(64) };
|
|
47
|
-
* };
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* @param solanaMock - The `SolanaMock` instance to attach to.
|
|
51
|
-
* @param options - The receiver program ID to route on.
|
|
52
|
-
* @returns A mock object with a settable `writeReport` handler.
|
|
53
|
-
*/
|
|
54
|
-
export declare function addSolanaContractMock(solanaMock: SolanaMock, options: AddSolanaContractMockOptions): SolanaContractMock;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { solanaAddressToBytes } from '../utils/capabilities/blockchain/solana/solana-helpers';
|
|
2
|
-
import { chainContractHandler } from './contract-mock-core';
|
|
3
|
-
function bytesEqual(a, b) {
|
|
4
|
-
if (a.length !== b.length)
|
|
5
|
-
return false;
|
|
6
|
-
return a.every((byte, i) => byte === b[i]);
|
|
7
|
-
}
|
|
8
|
-
function describeReceiver(receiver) {
|
|
9
|
-
return receiver ? `0x${Buffer.from(receiver).toString('hex')}` : '(empty)';
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Registers a typed program mock on a {@link SolanaMock} instance.
|
|
13
|
-
*
|
|
14
|
-
* This is the Solana counterpart of {@link addContractMock}: it intercepts
|
|
15
|
-
* `writeReport` on the provided mock, routing calls by receiver program ID.
|
|
16
|
-
* Multiple programs can be mocked on the same `SolanaMock` — each call to
|
|
17
|
-
* `addSolanaContractMock` chains with the previous handler.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* const solanaMock = SolanaMock.testInstance(chainSelector);
|
|
22
|
-
*
|
|
23
|
-
* const dataStorage = addSolanaContractMock(solanaMock, {
|
|
24
|
-
* programId: 'ECL8142j2YQAvs9R9geSsRnkVH2wLEi7soJCRyJ74cfL',
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* dataStorage.writeReport = ({ report, remainingAccounts }) => {
|
|
28
|
-
* return { txSignature: new Uint8Array(64) };
|
|
29
|
-
* };
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @param solanaMock - The `SolanaMock` instance to attach to.
|
|
33
|
-
* @param options - The receiver program ID to route on.
|
|
34
|
-
* @returns A mock object with a settable `writeReport` handler.
|
|
35
|
-
*/
|
|
36
|
-
export function addSolanaContractMock(solanaMock, options) {
|
|
37
|
-
const mock = {};
|
|
38
|
-
const programIdBytes = typeof options.programId === 'string'
|
|
39
|
-
? solanaAddressToBytes(options.programId)
|
|
40
|
-
: options.programId;
|
|
41
|
-
const programIdLabel = typeof options.programId === 'string' ? options.programId : describeReceiver(options.programId);
|
|
42
|
-
const previousWriteReport = solanaMock.writeReport;
|
|
43
|
-
solanaMock.writeReport = chainContractHandler({
|
|
44
|
-
previous: previousWriteReport,
|
|
45
|
-
matches: (req) => !!req.receiver && bytesEqual(req.receiver, programIdBytes),
|
|
46
|
-
noMatchError: (req) => `addSolanaContractMock: no writeReport mock registered for receiver ${describeReceiver(req.receiver)}`,
|
|
47
|
-
handle: (req) => {
|
|
48
|
-
if (typeof mock.writeReport !== 'function') {
|
|
49
|
-
throw new Error(`addSolanaContractMock: no writeReport handler set for ${programIdLabel}`);
|
|
50
|
-
}
|
|
51
|
-
if (!req.report) {
|
|
52
|
-
throw new Error(`addSolanaContractMock: writeReport called without report for ${programIdLabel}`);
|
|
53
|
-
}
|
|
54
|
-
return mock.writeReport({
|
|
55
|
-
receiver: req.receiver,
|
|
56
|
-
report: req.report,
|
|
57
|
-
remainingAccounts: req.remainingAccounts,
|
|
58
|
-
computeConfig: req.computeConfig,
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
return mock;
|
|
63
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ReportRequestJson } from '../../../../generated/sdk/v1alpha/sdk_pb';
|
|
2
|
-
/**
|
|
3
|
-
* Report-encoder settings for a chain family (everything in a `ReportRequest`
|
|
4
|
-
* except the payload itself). See `EVM_DEFAULT_REPORT_ENCODER` and
|
|
5
|
-
* `SOLANA_DEFAULT_REPORT_ENCODER` for the per-chain defaults.
|
|
6
|
-
*/
|
|
7
|
-
export type ReportEncoder = Omit<ReportRequestJson, 'encodedPayload'>;
|
|
8
|
-
/**
|
|
9
|
-
* Chain-agnostic core for building a `ReportRequest` from raw payload bytes.
|
|
10
|
-
*
|
|
11
|
-
* Per-chain wrappers (`prepareReportRequest` for EVM hex payloads,
|
|
12
|
-
* `prepareSolanaReportRequest` for Solana Borsh payloads) delegate here so
|
|
13
|
-
* there is a single payload-assembly path.
|
|
14
|
-
*
|
|
15
|
-
* @param payload - The raw payload bytes to be signed.
|
|
16
|
-
* @param reportEncoder - The report encoder settings to use.
|
|
17
|
-
* @returns The prepared report request.
|
|
18
|
-
*/
|
|
19
|
-
export declare const prepareReportRequestFromBytes: (payload: Uint8Array, reportEncoder: ReportEncoder) => ReportRequestJson;
|