@chainlink/cre-sdk 1.17.0-alpha.3 → 1.17.0-alpha.4

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 (61) hide show
  1. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.d.ts +1035 -0
  2. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.js +290 -0
  3. package/dist/generated/sdk/v1alpha/sdk_pb.d.ts +6 -2
  4. package/dist/generated/sdk/v1alpha/sdk_pb.js +5 -1
  5. package/dist/generated/workflows/v2/cre_info_pb.d.ts +123 -0
  6. package/dist/generated/workflows/v2/cre_info_pb.js +17 -0
  7. package/dist/generated/workflows/v2/workflow_key_pb.d.ts +55 -0
  8. package/dist/generated/workflows/v2/workflow_key_pb.js +17 -0
  9. package/dist/generated/workflows/v2/workflow_user_metric_pb.d.ts +118 -0
  10. package/dist/generated/workflows/v2/workflow_user_metric_pb.js +41 -0
  11. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.d.ts +63 -0
  12. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.js +247 -0
  13. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +13 -0
  14. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +94 -0
  15. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +15 -0
  16. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +116 -0
  17. package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.d.ts +5 -1
  18. package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.js +22 -0
  19. package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.d.ts +4 -0
  20. package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.js +12 -0
  21. package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.d.ts +12 -2
  22. package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.js +12 -0
  23. package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.d.ts +2 -0
  24. package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.js +2 -0
  25. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.d.ts +2 -0
  26. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +2 -0
  27. package/dist/sdk/cre/index.d.ts +30 -15
  28. package/dist/sdk/cre/index.js +29 -14
  29. package/dist/sdk/impl/runtime-impl.d.ts +29 -2
  30. package/dist/sdk/impl/runtime-impl.js +55 -6
  31. package/dist/sdk/runtime.d.ts +24 -2
  32. package/dist/sdk/tee-constraints.d.ts +68 -0
  33. package/dist/sdk/tee-constraints.js +59 -0
  34. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.d.ts +25 -0
  35. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.js +111 -0
  36. package/dist/sdk/test/generated/index.d.ts +1 -0
  37. package/dist/sdk/test/generated/index.js +1 -0
  38. package/dist/sdk/testutils/index.d.ts +1 -1
  39. package/dist/sdk/testutils/index.js +1 -1
  40. package/dist/sdk/testutils/test-runtime.d.ts +17 -4
  41. package/dist/sdk/testutils/test-runtime.js +31 -5
  42. package/dist/sdk/testutils/test-writer.d.ts +7 -1
  43. package/dist/sdk/testutils/test-writer.js +13 -1
  44. package/dist/sdk/types/global.d.ts +8 -0
  45. package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.js +1 -1
  46. package/dist/sdk/utils/values/consensus_aggregators.d.ts +16 -8
  47. package/dist/sdk/utils/values/consensus_aggregators.js +20 -3
  48. package/dist/sdk/utils/values/serializer_types.d.ts +1 -1
  49. package/dist/sdk/wasm/host-bindings.d.ts +4 -0
  50. package/dist/sdk/wasm/host-bindings.js +4 -0
  51. package/dist/sdk/wasm/runner.d.ts +10 -4
  52. package/dist/sdk/wasm/runner.js +86 -13
  53. package/dist/sdk/wasm/runtime.d.ts +4 -1
  54. package/dist/sdk/wasm/runtime.js +9 -1
  55. package/dist/sdk/workflow.d.ts +16 -7
  56. package/dist/sdk/workflow.js +10 -2
  57. package/dist/workflows/standard_tests/frequency_list/test.ts +75 -0
  58. package/dist/workflows/standard_tests/restrictions/test.ts +41 -0
  59. package/dist/workflows/standard_tests/tee_runtime/test.ts +29 -0
  60. package/package.json +2 -2
  61. package/scripts/src/generate-sdks.ts +6 -0
@@ -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
- export declare class Runner<TConfig> {
5
+ declare class RunnerBase<TConfig> {
6
6
  private readonly config;
7
7
  private readonly request;
8
- private constructor();
9
- static newRunner<TConfig, TIntermediateConfig = TConfig>(configHandlerParams?: ConfigHandlerParams<TConfig, TIntermediateConfig>): Promise<Runner<TConfig>>;
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<TConfig>(req: ExecuteRequest, workflow: Workflow<TConfig>, runtime: Runtime<TConfig>): Promise<ExecutionResult>;
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 {};
@@ -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,75 @@
1
+ import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
2
+ import { BasicActionCapability as NodeActionCapability } from '@cre/generated-sdk/capabilities/internal/nodeaction/v1/basicaction_sdk_gen'
3
+ import { cre, type Runtime } from '@cre/sdk/cre'
4
+ import type { NodeRuntime } from '@cre/sdk/runtime'
5
+ import {
6
+ ConsensusAggregationByFields,
7
+ type FrequencyListEntry,
8
+ frequencyList,
9
+ identical,
10
+ } from '@cre/sdk/utils'
11
+ import { Runner } from '@cre/sdk/wasm'
12
+
13
+ class NodeObservation {
14
+ constructor(
15
+ public payload: Uint8Array,
16
+ public signatures: Uint8Array,
17
+ ) {}
18
+ }
19
+
20
+ type ConsensusResult = {
21
+ payload: Uint8Array
22
+ signatures: FrequencyListEntry<Uint8Array>[]
23
+ }
24
+
25
+ const bytesToHex = (bytes: Uint8Array): string =>
26
+ Array.from(bytes)
27
+ .map((b) => b.toString(16).padStart(2, '0'))
28
+ .join('')
29
+
30
+ const formatFrequencyList = (entries: FrequencyListEntry<Uint8Array>[]): string =>
31
+ entries.map((entry) => `${bytesToHex(entry.value)}x${entry.count.value}`).join(',')
32
+
33
+ const formatResult = (result: ConsensusResult): string =>
34
+ `${bytesToHex(result.payload)}|${formatFrequencyList(result.signatures)}`
35
+
36
+ const handler = (runtime: Runtime<Uint8Array>) => {
37
+ const encoder = new TextEncoder()
38
+ const result = runtime
39
+ .runInNodeMode(
40
+ (nodeRuntime: NodeRuntime<Uint8Array>): NodeObservation => {
41
+ const nodeResponse = new NodeActionCapability()
42
+ .performAction(nodeRuntime, { inputThing: true })
43
+ .result()
44
+
45
+ return new NodeObservation(
46
+ encoder.encode(`payload-${nodeResponse.outputThing}`),
47
+ encoder.encode(`sig-${nodeResponse.outputThing}`),
48
+ )
49
+ },
50
+ ConsensusAggregationByFields<NodeObservation, ConsensusResult>({
51
+ payload: identical,
52
+ signatures: frequencyList,
53
+ }),
54
+ )()
55
+ .result()
56
+
57
+ return formatResult(result)
58
+ }
59
+
60
+ const initWorkflow = () => {
61
+ const basicTrigger = new BasicTriggerCapability()
62
+
63
+ return [cre.handler(basicTrigger.trigger({}), handler)]
64
+ }
65
+
66
+ export async function main() {
67
+ console.log(`TS workflow: standard test: frequency_list [${new Date().toISOString()}]`)
68
+
69
+ const runner = await Runner.newRunner<Uint8Array>({
70
+ configParser: (c) => c,
71
+ })
72
+ await runner.run(initWorkflow)
73
+ }
74
+
75
+ await main()
@@ -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.17.0-alpha.3",
3
+ "version": "1.17.0-alpha.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -61,7 +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",
64
+ "@chainlink/cre-sdk-javy-plugin": "1.8.0-alpha.2",
65
65
  "@noble/hashes": "2.2.0",
66
66
  "@noble/curves": "2.2.0",
67
67
  "@solana/addresses": "6.10.0",
@@ -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),