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

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 (80) hide show
  1. package/README.md +62 -2
  2. package/dist/generated/chain-selectors/testnet/evm/glamsterdam-devnet-6.d.ts +3 -0
  3. package/dist/generated/chain-selectors/testnet/evm/glamsterdam-devnet-6.js +12 -0
  4. package/dist/generated/chain-selectors/testnet/evm/t-rex-testnet.d.ts +3 -0
  5. package/dist/generated/chain-selectors/testnet/evm/t-rex-testnet.js +12 -0
  6. package/dist/generated/networks.d.ts +1 -1
  7. package/dist/generated/networks.js +14 -0
  8. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +0 -13
  9. package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +0 -94
  10. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +0 -15
  11. package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +0 -116
  12. package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.d.ts +1 -5
  13. package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.js +0 -22
  14. package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.d.ts +0 -4
  15. package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.js +0 -12
  16. package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.d.ts +1 -11
  17. package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.js +0 -12
  18. package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.d.ts +0 -2
  19. package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.js +0 -2
  20. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.d.ts +0 -2
  21. package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +0 -2
  22. package/dist/sdk/cre/index.d.ts +16 -31
  23. package/dist/sdk/cre/index.js +15 -30
  24. package/dist/sdk/impl/runtime-impl.d.ts +1 -28
  25. package/dist/sdk/impl/runtime-impl.js +1 -52
  26. package/dist/sdk/runtime.d.ts +1 -23
  27. package/dist/sdk/test/contract-mock-core.d.ts +16 -0
  28. package/dist/sdk/test/contract-mock-core.js +21 -0
  29. package/dist/sdk/test/evm-contract-mock.js +60 -58
  30. package/dist/sdk/test/generated/index.d.ts +0 -1
  31. package/dist/sdk/test/generated/index.js +0 -1
  32. package/dist/sdk/test/index.d.ts +1 -0
  33. package/dist/sdk/test/index.js +1 -0
  34. package/dist/sdk/test/solana-contract-mock.d.ts +54 -0
  35. package/dist/sdk/test/solana-contract-mock.js +63 -0
  36. package/dist/sdk/testutils/index.d.ts +1 -1
  37. package/dist/sdk/testutils/index.js +1 -1
  38. package/dist/sdk/testutils/test-runtime.d.ts +4 -17
  39. package/dist/sdk/testutils/test-runtime.js +5 -31
  40. package/dist/sdk/testutils/test-writer.d.ts +1 -7
  41. package/dist/sdk/testutils/test-writer.js +1 -13
  42. package/dist/sdk/types/global.d.ts +0 -8
  43. package/dist/sdk/utils/capabilities/blockchain/{blockchain-helpers.d.ts → evm/evm-helpers.d.ts} +7 -6
  44. package/dist/sdk/utils/capabilities/blockchain/{blockchain-helpers.js → evm/evm-helpers.js} +6 -8
  45. package/dist/sdk/utils/capabilities/blockchain/report-helpers.d.ts +19 -0
  46. package/dist/sdk/utils/capabilities/blockchain/report-helpers.js +16 -0
  47. package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.d.ts +165 -0
  48. package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.js +176 -0
  49. package/dist/sdk/utils/hex-utils.d.ts +6 -0
  50. package/dist/sdk/utils/hex-utils.js +8 -0
  51. package/dist/sdk/utils/index.d.ts +4 -1
  52. package/dist/sdk/utils/index.js +3 -1
  53. package/dist/sdk/utils/triggers/trigger-interface.d.ts +7 -0
  54. package/dist/sdk/utils/triggers/trigger-interface.js +13 -1
  55. package/dist/sdk/wasm/host-bindings.d.ts +0 -4
  56. package/dist/sdk/wasm/host-bindings.js +0 -4
  57. package/dist/sdk/wasm/runner.d.ts +4 -10
  58. package/dist/sdk/wasm/runner.js +13 -86
  59. package/dist/sdk/wasm/runtime.d.ts +1 -4
  60. package/dist/sdk/wasm/runtime.js +1 -9
  61. package/dist/sdk/workflow.d.ts +7 -16
  62. package/dist/sdk/workflow.js +2 -10
  63. package/package.json +8 -4
  64. package/scripts/src/generate-sdks.ts +0 -6
  65. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.d.ts +0 -1035
  66. package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.js +0 -290
  67. package/dist/generated/workflows/v2/cre_info_pb.d.ts +0 -123
  68. package/dist/generated/workflows/v2/cre_info_pb.js +0 -17
  69. package/dist/generated/workflows/v2/workflow_key_pb.d.ts +0 -55
  70. package/dist/generated/workflows/v2/workflow_key_pb.js +0 -17
  71. package/dist/generated/workflows/v2/workflow_user_metric_pb.d.ts +0 -118
  72. package/dist/generated/workflows/v2/workflow_user_metric_pb.js +0 -41
  73. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.d.ts +0 -63
  74. package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.js +0 -247
  75. package/dist/sdk/tee-constraints.d.ts +0 -68
  76. package/dist/sdk/tee-constraints.js +0 -59
  77. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.d.ts +0 -25
  78. package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.js +0 -111
  79. package/dist/workflows/standard_tests/restrictions/test.ts +0 -41
  80. package/dist/workflows/standard_tests/tee_runtime/test.ts +0 -29
@@ -0,0 +1,176 @@
1
+ import { bytesToBase64 } from '../../../hex-utils';
2
+ import { sha256 } from '@noble/hashes/sha2.js';
3
+ import { concatBytes } from '@noble/hashes/utils.js';
4
+ import { address, getAddressEncoder } from '@solana/addresses';
5
+ import { prepareReportRequestFromBytes } from '../report-helpers';
6
+ const ACCOUNT_HASH_LENGTH = 32;
7
+ const U32_LENGTH = 4;
8
+ // Stateless address encoder; hoisted so the encoder stack isn't rebuilt per call.
9
+ const ADDRESS_ENCODER = getAddressEncoder();
10
+ /** Encodes a number as a little-endian Borsh u32. */
11
+ const u32LE = (value) => {
12
+ const bytes = new Uint8Array(U32_LENGTH);
13
+ new DataView(bytes.buffer).setUint32(0, value, true);
14
+ return bytes;
15
+ };
16
+ /**
17
+ * Converts a base58-encoded Solana address to its 32 raw bytes.
18
+ *
19
+ * @param base58Address - The base58-encoded address (validated).
20
+ * @returns The 32-byte public key.
21
+ */
22
+ export const solanaAddressToBytes = (base58Address) => new Uint8Array(ADDRESS_ENCODER.encode(address(base58Address)));
23
+ /**
24
+ * Builds an account entry for the Solana capability's `remainingAccounts` list.
25
+ *
26
+ * @param publicKey - The account's public key, as 32 raw bytes or a base58 string.
27
+ * @param isWritable - Whether the account is writable. Defaults to false.
28
+ * @returns The account meta.
29
+ */
30
+ export const solanaAccountMeta = (publicKey, isWritable = false) => ({
31
+ publicKey: typeof publicKey === 'string' ? solanaAddressToBytes(publicKey) : publicKey,
32
+ isWritable,
33
+ });
34
+ /**
35
+ * Converts {@link SolanaAccountMeta} entries to the capability's protobuf
36
+ * JSON `AccountMeta` shape (base64 public keys), as expected by
37
+ * `SolanaClient.writeReport`. Used by generated bindings.
38
+ */
39
+ export const solanaAccountMetasToJson = (accounts) => accounts.map((account) => ({
40
+ publicKey: bytesToBase64(account.publicKey),
41
+ isWritable: account.isWritable,
42
+ }));
43
+ /**
44
+ * Computes the SHA-256 hash of the concatenated public keys of the given
45
+ * accounts, matching the keystone-forwarder's on-chain account hash
46
+ * verification. Nullish entries are skipped; account order matters.
47
+ *
48
+ * Mirrors Go `bindings.CalculateAccountsHash`.
49
+ *
50
+ * @param accounts - The accounts whose public keys are hashed.
51
+ * @returns The 32-byte account hash.
52
+ */
53
+ export const calculateAccountsHash = (accounts) => {
54
+ const publicKeys = accounts.filter((acc) => acc != null).map(({ publicKey }) => publicKey);
55
+ return sha256(concatBytes(...publicKeys));
56
+ };
57
+ /**
58
+ * Borsh-encodes a `ForwarderReport` for the keystone-forwarder:
59
+ * `[32-byte accountHash][u32-LE payload length][payload bytes]`.
60
+ *
61
+ * Mirrors Go `bindings.ForwarderReport.Marshal`.
62
+ *
63
+ * @param report - The account hash and payload to encode.
64
+ * @returns The encoded forwarder report.
65
+ */
66
+ export const encodeForwarderReport = (report) => {
67
+ if (report.accountHash.length !== ACCOUNT_HASH_LENGTH) {
68
+ throw new Error(`encodeForwarderReport: accountHash must be exactly ${ACCOUNT_HASH_LENGTH} bytes, got ${report.accountHash.length}`);
69
+ }
70
+ return concatBytes(report.accountHash, u32LE(report.payload.length), report.payload);
71
+ };
72
+ /**
73
+ * Returns the Anchor/Borsh encoding of a Vec whose elements are opaque byte
74
+ * payloads: `[u32-LE element count][concatenated element payloads]`.
75
+ * Each element must already be fully serialized for one Vec item on the wire.
76
+ *
77
+ * Mirrors Go's generated `EncodeBorshVecU32`.
78
+ *
79
+ * @param elementPayloads - The pre-encoded Vec elements.
80
+ * @returns The encoded Vec.
81
+ */
82
+ export const encodeBorshVecU32 = (elementPayloads) => concatBytes(u32LE(elementPayloads.length), ...elementPayloads);
83
+ /**
84
+ * Default values expected by the Solana capability for report encoding.
85
+ * Mirrors the constants emitted by the Go Solana bindings generator.
86
+ */
87
+ export const SOLANA_DEFAULT_REPORT_ENCODER = {
88
+ encoderName: 'solana',
89
+ signingAlgo: 'ecdsa',
90
+ hashingAlgo: 'keccak256',
91
+ };
92
+ /**
93
+ * Prepares a report request for the Solana capability to pass to `.report()`.
94
+ * Takes raw bytes (typically an encoded `ForwarderReport`), not hex.
95
+ *
96
+ * @param payload - The encoded payload bytes to be signed.
97
+ * @param reportEncoder - The report encoder to use. Defaults to SOLANA_DEFAULT_REPORT_ENCODER.
98
+ * @returns The prepared report request.
99
+ */
100
+ export const prepareSolanaReportRequest = (payload, reportEncoder = SOLANA_DEFAULT_REPORT_ENCODER) => prepareReportRequestFromBytes(payload, reportEncoder);
101
+ const U64_LENGTH = 8;
102
+ const U64_SIGN_BIT = 1n << 63n;
103
+ const UTF8_ENCODER = new TextEncoder();
104
+ /** Encodes a bigint as a big-endian u64, wrapping modulo 2^64 (two's complement). */
105
+ const u64BE = (value) => {
106
+ const bytes = new Uint8Array(U64_LENGTH);
107
+ new DataView(bytes.buffer).setBigUint64(0, BigInt.asUintN(64, value), false);
108
+ return bytes;
109
+ };
110
+ /**
111
+ * Encodes a filter value for use in a `SubkeyConfig` `ValueComparator`,
112
+ * matching the byte representation the Solana log-trigger capability indexes.
113
+ *
114
+ * Encodings (mirrors Go `bindings.PrepareSubkeyValue`):
115
+ * - `Uint8Array` — used as-is (public keys, fixed byte arrays, `bytes` fields)
116
+ * - `string` — UTF-8 bytes
117
+ * - `bigint` / integer `number` — 8-byte big-endian two's complement
118
+ *
119
+ * For `f32`/`f64` event fields use {@link prepareSubkeyFloatValue}; passing a
120
+ * non-integer `number` here throws.
121
+ *
122
+ * @param value - The filter value to encode.
123
+ * @returns The encoded comparator value bytes.
124
+ */
125
+ export const prepareSubkeyValue = (value) => {
126
+ if (value instanceof Uint8Array) {
127
+ return value;
128
+ }
129
+ if (typeof value === 'string') {
130
+ return UTF8_ENCODER.encode(value);
131
+ }
132
+ if (typeof value === 'bigint') {
133
+ return u64BE(value);
134
+ }
135
+ if (typeof value === 'number') {
136
+ if (!Number.isInteger(value)) {
137
+ throw new Error('prepareSubkeyValue: non-integer number; use prepareSubkeyFloatValue for f32/f64 values');
138
+ }
139
+ return u64BE(BigInt(value));
140
+ }
141
+ throw new Error(`prepareSubkeyValue: unsupported subkey value type ${typeof value}`);
142
+ };
143
+ /**
144
+ * Encodes an `f32`/`f64` filter value into the 8-byte big-endian
145
+ * representation the Solana log-trigger capability indexes.
146
+ *
147
+ * Byte-compatible with Go `bindings.EncodeIndexedValue` for floats: positive
148
+ * values map to `float64bits + 2^63`, others to `2^63 - float64bits`
149
+ * (modulo 2^64). Ordering is preserved among values of the same sign.
150
+ *
151
+ * @param value - The float filter value to encode.
152
+ * @returns The encoded comparator value bytes.
153
+ */
154
+ export const prepareSubkeyFloatValue = (value) => {
155
+ const view = new DataView(new ArrayBuffer(U64_LENGTH));
156
+ view.setFloat64(0, value, false);
157
+ const bits = view.getBigUint64(0, false);
158
+ return u64BE(value > 0 ? bits + U64_SIGN_BIT : U64_SIGN_BIT - bits);
159
+ };
160
+ /** Method name Anchor uses for `emit_cpi!` self-invocations. */
161
+ const ANCHOR_CPI_METHOD_NAME = 'anchor:event';
162
+ const ANCHOR_CPI_METHOD_NAME_B64 = bytesToBase64(UTF8_ENCODER.encode(ANCHOR_CPI_METHOD_NAME));
163
+ /**
164
+ * Builds the `CPIFilterConfig` for log triggers on events emitted via
165
+ * Anchor's `emit_cpi!`: destination is the program itself, method is
166
+ * `anchor:event`.
167
+ *
168
+ * Mirrors Go `bindings.AnchorCPILogTriggerConfig`.
169
+ *
170
+ * @param programId - The program's public key, as 32 raw bytes or a base58 string.
171
+ * @returns The CPI filter config in protobuf JSON shape.
172
+ */
173
+ export const anchorCPILogTriggerConfig = (programId) => ({
174
+ destAddress: bytesToBase64(typeof programId === 'string' ? solanaAddressToBytes(programId) : programId),
175
+ methodName: ANCHOR_CPI_METHOD_NAME_B64,
176
+ });
@@ -13,6 +13,12 @@ export declare const hexToBytes: (hexStr: string) => Uint8Array;
13
13
  * Convert Uint8Array to hex string with 0x prefix
14
14
  */
15
15
  export declare const bytesToHex: (bytes: Uint8Array) => Hex;
16
+ /**
17
+ * Encode raw bytes as base64 string
18
+ * @param bytes
19
+ * @returns
20
+ */
21
+ export declare const bytesToBase64: (bytes: Uint8Array) => string;
16
22
  /**
17
23
  * Encode hex as base64 string
18
24
  * @param hex
@@ -28,6 +28,14 @@ export const bytesToHex = (bytes) => {
28
28
  .map((b) => b.toString(16).padStart(2, '0'))
29
29
  .join('')}`;
30
30
  };
31
+ /**
32
+ * Encode raw bytes as base64 string
33
+ * @param bytes
34
+ * @returns
35
+ */
36
+ export const bytesToBase64 = (bytes) => {
37
+ return Buffer.from(bytes).toString('base64');
38
+ };
31
39
  /**
32
40
  * Encode hex as base64 string
33
41
  * @param hex
@@ -1,9 +1,12 @@
1
- export * from './capabilities/blockchain/blockchain-helpers';
1
+ export * from './capabilities/blockchain/evm/evm-helpers';
2
+ export type { ReportEncoder } from './capabilities/blockchain/report-helpers';
3
+ export * from './capabilities/blockchain/solana/solana-helpers';
2
4
  export * from './capabilities/http/http-helpers';
3
5
  export * from './chain-selectors';
4
6
  export * from './decode-json';
5
7
  export * from './hex-utils';
6
8
  export * from './safe-json-stringify';
9
+ export * from './triggers/trigger-interface';
7
10
  export * from './values/consensus_aggregators';
8
11
  export * from './values/serializer_types';
9
12
  export * from './values/value';
@@ -1,9 +1,11 @@
1
- export * from './capabilities/blockchain/blockchain-helpers';
1
+ export * from './capabilities/blockchain/evm/evm-helpers';
2
+ export * from './capabilities/blockchain/solana/solana-helpers';
2
3
  export * from './capabilities/http/http-helpers';
3
4
  export * from './chain-selectors';
4
5
  export * from './decode-json';
5
6
  export * from './hex-utils';
6
7
  export * from './safe-json-stringify';
8
+ export * from './triggers/trigger-interface';
7
9
  export * from './values/consensus_aggregators';
8
10
  export * from './values/serializer_types';
9
11
  export * from './values/value';
@@ -19,3 +19,10 @@ export interface Trigger<TRawTriggerOutput extends Message<string>, TTriggerOutp
19
19
  /** Transform the raw trigger output to the adapted type */
20
20
  adapt(rawOutput: TRawTriggerOutput): TTriggerOutput;
21
21
  }
22
+ /**
23
+ * Wraps a trigger with an extra output transformation, delegating everything
24
+ * else to the wrapped trigger. The TypeScript analog of Go bindings embedding
25
+ * `cre.Trigger` and overriding only `Adapt` — generated bindings use this to
26
+ * decode raw trigger outputs into typed data.
27
+ */
28
+ export declare const adaptTrigger: <TRaw extends Message<string>, TIn, TOut>(trigger: Trigger<TRaw, TIn>, adapt: (output: TIn) => TOut) => Trigger<TRaw, TOut>;
@@ -1 +1,13 @@
1
- export {};
1
+ /**
2
+ * Wraps a trigger with an extra output transformation, delegating everything
3
+ * else to the wrapped trigger. The TypeScript analog of Go bindings embedding
4
+ * `cre.Trigger` and overriding only `Adapt` — generated bindings use this to
5
+ * decode raw trigger outputs into typed data.
6
+ */
7
+ export const adaptTrigger = (trigger, adapt) => ({
8
+ capabilityId: () => trigger.capabilityId(),
9
+ method: () => trigger.method(),
10
+ outputSchema: () => trigger.outputSchema(),
11
+ configAsAny: () => trigger.configAsAny(),
12
+ adapt: (rawOutput) => adapt(trigger.adapt(rawOutput)),
13
+ });
@@ -11,7 +11,6 @@ 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>;
15
14
  sleep: z.ZodFunction<z.ZodTuple<[z.ZodNumber], z.ZodUnknown>, z.ZodVoid>;
16
15
  }, "strip", z.ZodTypeAny, {
17
16
  callCapability: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
@@ -19,7 +18,6 @@ export declare const globalHostBindingsSchema: z.ZodObject<{
19
18
  getSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => any;
20
19
  awaitSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>;
21
20
  log: (args_0: string, ...args: unknown[]) => void;
22
- emitMetric: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
23
21
  sendResponse: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
24
22
  switchModes: (args_0: Mode, ...args: unknown[]) => void;
25
23
  versionV2: (...args: unknown[]) => void;
@@ -32,7 +30,6 @@ export declare const globalHostBindingsSchema: z.ZodObject<{
32
30
  getSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => any;
33
31
  awaitSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>;
34
32
  log: (args_0: string, ...args: unknown[]) => void;
35
- emitMetric: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
36
33
  sendResponse: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
37
34
  switchModes: (args_0: Mode, ...args: unknown[]) => void;
38
35
  versionV2: (...args: unknown[]) => void;
@@ -46,7 +43,6 @@ export declare const hostBindings: {
46
43
  getSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => any;
47
44
  awaitSecrets: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, args_1: number, ...args: unknown[]) => Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>;
48
45
  log: (args_0: string, ...args: unknown[]) => void;
49
- emitMetric: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
50
46
  sendResponse: (args_0: Uint8Array<ArrayBufferLike> | Uint8Array<ArrayBuffer>, ...args: unknown[]) => number;
51
47
  switchModes: (args_0: Mode, ...args: unknown[]) => void;
52
48
  versionV2: (...args: unknown[]) => void;
@@ -27,10 +27,6 @@ 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()),
34
30
  sleep: z.function().args(z.number()).returns(z.void()),
35
31
  });
36
32
  // Validate global host functions at runtime
@@ -2,19 +2,13 @@ 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
- declare class RunnerBase<TConfig> {
5
+ export declare class Runner<TConfig> {
6
6
  private readonly config;
7
7
  private readonly request;
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>;
8
+ private constructor();
9
+ static newRunner<TConfig, TIntermediateConfig = TConfig>(configHandlerParams?: ConfigHandlerParams<TConfig, TIntermediateConfig>): Promise<Runner<TConfig>>;
10
10
  private static getRequest;
11
11
  run(initFn: (config: TConfig, secretsProvider: SecretsProvider) => Promise<Workflow<TConfig>> | Workflow<TConfig>): Promise<void>;
12
- handleExecutionPhase(req: ExecuteRequest, workflow: Workflow<TConfig>, runtime: Runtime<TConfig>): Promise<ExecutionResult>;
13
- handlePreHookPhase(req: ExecuteRequest, workflow: Workflow<TConfig>): ExecutionResult;
12
+ handleExecutionPhase<TConfig>(req: ExecuteRequest, workflow: Workflow<TConfig>, runtime: Runtime<TConfig>): Promise<ExecutionResult>;
14
13
  handleSubscribePhase(req: ExecuteRequest, workflow: Workflow<TConfig>): ExecutionResult;
15
14
  }
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, fromJson, toBinary } from '@bufbuild/protobuf';
2
- import { ExecuteRequestSchema, ExecutionResultSchema, RestrictionsSchema, TriggerSubscriptionRequestSchema, } from '../../generated/sdk/v1alpha/sdk_pb';
1
+ import { create, fromBinary, toBinary } from '@bufbuild/protobuf';
2
+ import { ExecuteRequestSchema, ExecutionResultSchema, 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, TeeRuntime } from './runtime';
7
- class RunnerBase {
6
+ import { Runtime } from './runtime';
7
+ export class Runner {
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 newRunnerHelper(newRunner, configHandlerParams) {
14
+ static async newRunner(configHandlerParams) {
15
15
  hostBindings.versionV2();
16
- const request = RunnerBase.getRequest();
16
+ const request = Runner.getRequest();
17
17
  const config = await configHandler(request, configHandlerParams);
18
- return newRunner(config, request);
18
+ return new Runner(config, request);
19
19
  }
20
20
  static getRequest() {
21
21
  const argsString = hostBindings.getWasiArgs();
@@ -38,15 +38,11 @@ class RunnerBase {
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
- };
47
41
  let result;
48
42
  try {
49
- const workflow = await initFn(this.config, sp);
43
+ const workflow = await initFn(this.config, {
44
+ getSecret: runtime.getSecret.bind(runtime),
45
+ });
50
46
  switch (this.request.request.case) {
51
47
  case 'subscribe':
52
48
  result = this.handleSubscribePhase(this.request, workflow);
@@ -54,11 +50,8 @@ class RunnerBase {
54
50
  case 'trigger':
55
51
  result = this.handleExecutionPhase(this.request, workflow, runtime);
56
52
  break;
57
- case 'preHook':
58
- result = this.handlePreHookPhase(this.request, workflow);
59
- break;
60
53
  default:
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`);
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`);
62
55
  }
63
56
  }
64
57
  catch (e) {
@@ -102,10 +95,8 @@ class RunnerBase {
102
95
  * */
103
96
  const decoded = fromBinary(schema, payloadAny.value);
104
97
  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;
107
98
  try {
108
- const result = await entry.fn(handlerRuntime, adapted);
99
+ const result = await entry.fn(runtime, adapted);
109
100
  const wrapped = Value.wrap(result);
110
101
  return create(ExecutionResultSchema, {
111
102
  result: { case: 'value', value: wrapped.proto() },
@@ -125,60 +116,6 @@ class RunnerBase {
125
116
  },
126
117
  });
127
118
  }
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
- }
182
119
  handleSubscribePhase(req, workflow) {
183
120
  if (req.request.case !== 'subscribe') {
184
121
  return create(ExecutionResultSchema, {
@@ -188,13 +125,11 @@ class RunnerBase {
188
125
  },
189
126
  });
190
127
  }
191
- // Build TriggerSubscriptionRequest from the workflow entries, including any per-handler requirements.
128
+ // Build TriggerSubscriptionRequest from the workflow entries
192
129
  const subscriptions = workflow.map((entry) => ({
193
130
  id: entry.trigger.capabilityId(),
194
131
  method: entry.trigger.method(),
195
132
  payload: entry.trigger.configAsAny(),
196
- requirements: entry.requirements,
197
- preHook: !!entry.hooks?.preHook,
198
133
  }));
199
134
  const subscriptionRequest = create(TriggerSubscriptionRequestSchema, {
200
135
  subscriptions,
@@ -204,11 +139,3 @@ class RunnerBase {
204
139
  });
205
140
  }
206
141
  }
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,10 +1,7 @@
1
- import { NodeRuntimeImpl, RuntimeImpl, TeeRuntimeImpl } from '../impl/runtime-impl';
1
+ import { NodeRuntimeImpl, RuntimeImpl } 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, TeeRuntimeImpl, } from '../impl/runtime-impl';
3
+ import { NodeRuntimeImpl, RuntimeImpl } 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,11 +12,6 @@ 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
- }
20
15
  /** Convert bigint maxResponseSize to i32 for WASM host binding, with range validation. */
21
16
  function toI32ResponseSize(maxResponseSize) {
22
17
  if (maxResponseSize > 2147483647n || maxResponseSize < -2147483648n) {
@@ -64,7 +59,4 @@ class WasmRuntimeHelpers {
64
59
  log(message) {
65
60
  hostBindings.log(message);
66
61
  }
67
- emitMetric(payload) {
68
- return hostBindings.emitMetric(payload) >= 0;
69
- }
70
62
  }
@@ -1,24 +1,15 @@
1
1
  import type { Message } from '@bufbuild/protobuf';
2
- import type { Requirements, RestrictionsJson, Secret, SecretRequest, SecretRequestJson } from '../generated/sdk/v1alpha/sdk_pb';
3
- import type { Runtime, TeeRuntime } from './runtime';
2
+ import type { Secret, SecretRequest, SecretRequestJson } from '../generated/sdk/v1alpha/sdk_pb';
3
+ import { type Runtime } from './runtime';
4
4
  import type { Trigger } from './utils/triggers/trigger-interface';
5
5
  import type { CreSerializable } from './utils';
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>> {
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> {
14
8
  trigger: Trigger<TRawTriggerOutput, TTriggerOutput>;
15
- fn: HandlerFn<TConfig, TTriggerOutput, TResult, TRuntime>;
16
- requirements?: Requirements;
17
- hooks?: Hooks<TConfig, TTriggerOutput>;
9
+ fn: HandlerFn<TConfig, TTriggerOutput, TResult>;
18
10
  }
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>>;
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>;
22
13
  export type SecretsProvider = {
23
14
  getSecret(request: SecretRequest | SecretRequestJson): {
24
15
  result: () => Secret;
@@ -1,13 +1,5 @@
1
- export { buildTeeRequirements, NITRO_REGIONS, REGIONS, teeConstraintSchema, } from './tee-constraints';
2
- import { buildTeeRequirements } from './tee-constraints';
3
- export const handler = (trigger, fn, hooks) => ({
1
+ import {} from './runtime';
2
+ export const handler = (trigger, fn) => ({
4
3
  trigger,
5
4
  fn,
6
- hooks,
7
- });
8
- export const handlerInTee = (trigger, fn, tees, hooks) => ({
9
- trigger,
10
- fn,
11
- requirements: buildTeeRequirements(tees),
12
- hooks,
13
5
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainlink/cre-sdk",
3
- "version": "1.17.0-alpha.1",
3
+ "version": "1.17.0-alpha.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -61,7 +61,11 @@
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.8.0-alpha.1",
64
+ "@chainlink/cre-sdk-javy-plugin": "1.7.0",
65
+ "@noble/hashes": "2.2.0",
66
+ "@noble/curves": "2.2.0",
67
+ "@solana/addresses": "6.10.0",
68
+ "@solana/codecs": "6.10.0",
65
69
  "@standard-schema/spec": "1.0.0",
66
70
  "viem": "2.34.0",
67
71
  "zod": "3.25.76"
@@ -70,11 +74,11 @@
70
74
  "@biomejs/biome": "2.3.14",
71
75
  "@bufbuild/buf": "1.56.0",
72
76
  "@types/bun": "1.3.8",
73
- "chain-selectors": "https://github.com/smartcontractkit/chain-selectors.git#3e718d1c9910b2952c50befe378b0fe8707e6647",
77
+ "chain-selectors": "https://github.com/smartcontractkit/chain-selectors.git#7d1e9798b28404818eba5246383c0688c4ee0e1f",
74
78
  "fast-glob": "3.3.3",
75
79
  "ts-proto": "2.7.5",
76
80
  "typescript": "5.9.3",
77
- "yaml": "2.8.1"
81
+ "yaml": "2.9.0"
78
82
  },
79
83
  "publishConfig": {
80
84
  "access": "public"
@@ -1,5 +1,4 @@
1
1
  import { rmSync } from 'node:fs'
2
- import { file_capabilities_blockchain_aptos_v1alpha_client } from '@cre/generated/capabilities/blockchain/aptos/v1alpha/client_pb'
3
2
  import { file_capabilities_blockchain_evm_v1alpha_client } from '@cre/generated/capabilities/blockchain/evm/v1alpha/client_pb'
4
3
  import { file_capabilities_blockchain_solana_v1alpha_client } from '@cre/generated/capabilities/blockchain/solana/v1alpha/client_pb'
5
4
  import { file_capabilities_internal_actionandtrigger_v1_action_and_trigger } from '@cre/generated/capabilities/internal/actionandtrigger/v1/action_and_trigger_pb'
@@ -65,11 +64,6 @@ export const main = () => {
65
64
  ...generateMocks(file_capabilities_blockchain_evm_v1alpha_client, TEST_GENERATED_DIR),
66
65
  )
67
66
 
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
-
73
67
  generateSdk(file_capabilities_blockchain_solana_v1alpha_client, './src/generated-sdk')
74
68
  allMockExports.push(
75
69
  ...generateMocks(file_capabilities_blockchain_solana_v1alpha_client, TEST_GENERATED_DIR),