@chainlink/cre-sdk 1.16.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.
Files changed (81) hide show
  1. package/README.md +2 -62
  2. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.d.ts +1035 -0
  3. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.js +290 -0
  4. package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.d.ts +2885 -15
  5. package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.js +459 -7
  6. package/dist/generated/capabilities/networking/http/v1alpha/client_pb.js +1 -1
  7. package/dist/generated/sdk/v1alpha/sdk_pb.d.ts +505 -0
  8. package/dist/generated/sdk/v1alpha/sdk_pb.js +121 -15
  9. package/dist/generated/tools/generator/v1alpha/cre_metadata_pb.d.ts +30 -1
  10. package/dist/generated/tools/generator/v1alpha/cre_metadata_pb.js +20 -2
  11. package/dist/generated/workflows/v2/cre_info_pb.d.ts +123 -0
  12. package/dist/generated/workflows/v2/cre_info_pb.js +17 -0
  13. package/dist/generated/workflows/v2/workflow_key_pb.d.ts +55 -0
  14. package/dist/generated/workflows/v2/workflow_key_pb.js +17 -0
  15. package/dist/generated/workflows/v2/workflow_user_metric_pb.d.ts +118 -0
  16. package/dist/generated/workflows/v2/workflow_user_metric_pb.js +41 -0
  17. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.d.ts +63 -0
  18. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.js +247 -0
  19. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +13 -0
  20. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +94 -0
  21. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +69 -2
  22. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +403 -1
  23. package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.d.ts +5 -1
  24. package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.js +22 -0
  25. package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.d.ts +4 -0
  26. package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.js +12 -0
  27. package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.d.ts +11 -1
  28. package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.js +12 -0
  29. package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.d.ts +2 -0
  30. package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.js +2 -0
  31. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.d.ts +2 -0
  32. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +2 -0
  33. package/dist/sdk/cre/index.d.ts +30 -15
  34. package/dist/sdk/cre/index.js +29 -14
  35. package/dist/sdk/impl/runtime-impl.d.ts +28 -1
  36. package/dist/sdk/impl/runtime-impl.js +52 -1
  37. package/dist/sdk/runtime.d.ts +23 -1
  38. package/dist/sdk/tee-constraints.d.ts +68 -0
  39. package/dist/sdk/tee-constraints.js +59 -0
  40. package/dist/sdk/test/evm-contract-mock.js +58 -60
  41. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.d.ts +25 -0
  42. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.js +111 -0
  43. package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.d.ts +19 -1
  44. package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.js +141 -1
  45. package/dist/sdk/test/generated/index.d.ts +1 -0
  46. package/dist/sdk/test/generated/index.js +1 -0
  47. package/dist/sdk/test/index.d.ts +0 -1
  48. package/dist/sdk/test/index.js +0 -1
  49. package/dist/sdk/testutils/index.d.ts +1 -1
  50. package/dist/sdk/testutils/index.js +1 -1
  51. package/dist/sdk/testutils/test-runtime.d.ts +17 -4
  52. package/dist/sdk/testutils/test-runtime.js +31 -5
  53. package/dist/sdk/testutils/test-writer.d.ts +7 -1
  54. package/dist/sdk/testutils/test-writer.js +13 -1
  55. package/dist/sdk/types/global.d.ts +8 -0
  56. package/dist/sdk/utils/capabilities/blockchain/{evm/evm-helpers.d.ts → blockchain-helpers.d.ts} +6 -7
  57. package/dist/sdk/utils/capabilities/blockchain/{evm/evm-helpers.js → blockchain-helpers.js} +8 -6
  58. package/dist/sdk/utils/hex-utils.d.ts +0 -6
  59. package/dist/sdk/utils/hex-utils.js +0 -8
  60. package/dist/sdk/utils/index.d.ts +1 -3
  61. package/dist/sdk/utils/index.js +1 -2
  62. package/dist/sdk/wasm/host-bindings.d.ts +4 -0
  63. package/dist/sdk/wasm/host-bindings.js +4 -0
  64. package/dist/sdk/wasm/runner.d.ts +10 -4
  65. package/dist/sdk/wasm/runner.js +86 -13
  66. package/dist/sdk/wasm/runtime.d.ts +4 -1
  67. package/dist/sdk/wasm/runtime.js +9 -1
  68. package/dist/sdk/workflow.d.ts +16 -7
  69. package/dist/sdk/workflow.js +10 -2
  70. package/dist/workflows/standard_tests/restrictions/test.ts +41 -0
  71. package/dist/workflows/standard_tests/tee_runtime/test.ts +29 -0
  72. package/package.json +3 -6
  73. package/scripts/src/generate-sdks.ts +6 -0
  74. package/dist/sdk/test/contract-mock-core.d.ts +0 -16
  75. package/dist/sdk/test/contract-mock-core.js +0 -21
  76. package/dist/sdk/test/solana-contract-mock.d.ts +0 -54
  77. package/dist/sdk/test/solana-contract-mock.js +0 -63
  78. package/dist/sdk/utils/capabilities/blockchain/report-helpers.d.ts +0 -19
  79. package/dist/sdk/utils/capabilities/blockchain/report-helpers.js +0 -16
  80. package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.d.ts +0 -101
  81. package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.js +0 -100
@@ -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
- export class Runner {
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(configHandlerParams) {
14
+ static async newRunnerHelper(newRunner, configHandlerParams) {
15
15
  hostBindings.versionV2();
16
- const request = Runner.getRequest();
16
+ const request = RunnerBase.getRequest();
17
17
  const config = await configHandler(request, configHandlerParams);
18
- return new Runner(config, request);
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 'trigger'. This may indicate a version mismatch between the SDK and the CRE runtime`);
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(runtime, adapted);
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
+ }
@@ -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
  }
@@ -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 { type Runtime } from './runtime';
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 HandlerFn<TConfig, TTriggerOutput, TResult> = (runtime: Runtime<TConfig>, triggerOutput: TTriggerOutput) => Promise<CreSerializable<TResult>> | CreSerializable<TResult>;
7
- export interface HandlerEntry<TConfig, TRawTriggerOutput extends Message<string>, TTriggerOutput, TResult> {
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>(trigger: Trigger<TRawTriggerOutput, TTriggerOutput>, fn: HandlerFn<TConfig, TTriggerOutput, TResult>) => HandlerEntry<TConfig, TRawTriggerOutput, TTriggerOutput, 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;
@@ -1,5 +1,13 @@
1
- import {} from './runtime';
2
- export const handler = (trigger, fn) => ({
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.16.0",
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.7.0",
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.9.0"
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;
@@ -1,16 +0,0 @@
1
- import { bytesToBase64 } from '../../hex-utils';
2
- /**
3
- * Chain-agnostic core for building a `ReportRequest` from raw payload bytes.
4
- *
5
- * Per-chain wrappers (`prepareReportRequest` for EVM hex payloads,
6
- * `prepareSolanaReportRequest` for Solana Borsh payloads) delegate here so
7
- * there is a single payload-assembly path.
8
- *
9
- * @param payload - The raw payload bytes to be signed.
10
- * @param reportEncoder - The report encoder settings to use.
11
- * @returns The prepared report request.
12
- */
13
- export const prepareReportRequestFromBytes = (payload, reportEncoder) => ({
14
- encodedPayload: bytesToBase64(payload),
15
- ...reportEncoder,
16
- });