@chainlink/cre-sdk 1.17.0-alpha.1 → 1.17.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -2
- package/dist/generated/chain-selectors/testnet/evm/glamsterdam-devnet-6.d.ts +3 -0
- package/dist/generated/chain-selectors/testnet/evm/glamsterdam-devnet-6.js +12 -0
- package/dist/generated/chain-selectors/testnet/evm/t-rex-testnet.d.ts +3 -0
- package/dist/generated/chain-selectors/testnet/evm/t-rex-testnet.js +12 -0
- package/dist/generated/networks.d.ts +1 -1
- package/dist/generated/networks.js +14 -0
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +0 -13
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +0 -94
- package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +0 -15
- package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +0 -116
- package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.d.ts +1 -5
- package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.js +0 -22
- package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.d.ts +0 -4
- package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.js +0 -12
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.d.ts +1 -11
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.js +0 -12
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.d.ts +0 -2
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.js +0 -2
- package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.d.ts +0 -2
- package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +0 -2
- package/dist/sdk/cre/index.d.ts +16 -31
- package/dist/sdk/cre/index.js +15 -30
- package/dist/sdk/impl/runtime-impl.d.ts +1 -28
- package/dist/sdk/impl/runtime-impl.js +1 -52
- package/dist/sdk/runtime.d.ts +1 -23
- package/dist/sdk/test/contract-mock-core.d.ts +16 -0
- package/dist/sdk/test/contract-mock-core.js +21 -0
- package/dist/sdk/test/evm-contract-mock.js +60 -58
- package/dist/sdk/test/generated/index.d.ts +0 -1
- package/dist/sdk/test/generated/index.js +0 -1
- package/dist/sdk/test/index.d.ts +1 -0
- package/dist/sdk/test/index.js +1 -0
- package/dist/sdk/test/solana-contract-mock.d.ts +54 -0
- package/dist/sdk/test/solana-contract-mock.js +63 -0
- package/dist/sdk/testutils/index.d.ts +1 -1
- package/dist/sdk/testutils/index.js +1 -1
- package/dist/sdk/testutils/test-runtime.d.ts +4 -17
- package/dist/sdk/testutils/test-runtime.js +5 -31
- package/dist/sdk/testutils/test-writer.d.ts +1 -7
- package/dist/sdk/testutils/test-writer.js +1 -13
- package/dist/sdk/types/global.d.ts +0 -8
- package/dist/sdk/utils/capabilities/blockchain/{blockchain-helpers.d.ts → evm/evm-helpers.d.ts} +7 -6
- package/dist/sdk/utils/capabilities/blockchain/{blockchain-helpers.js → evm/evm-helpers.js} +6 -8
- package/dist/sdk/utils/capabilities/blockchain/report-helpers.d.ts +19 -0
- package/dist/sdk/utils/capabilities/blockchain/report-helpers.js +16 -0
- package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.d.ts +165 -0
- package/dist/sdk/utils/capabilities/blockchain/solana/solana-helpers.js +176 -0
- package/dist/sdk/utils/hex-utils.d.ts +6 -0
- package/dist/sdk/utils/hex-utils.js +8 -0
- package/dist/sdk/utils/index.d.ts +4 -1
- package/dist/sdk/utils/index.js +3 -1
- package/dist/sdk/utils/triggers/trigger-interface.d.ts +7 -0
- package/dist/sdk/utils/triggers/trigger-interface.js +13 -1
- package/dist/sdk/wasm/host-bindings.d.ts +0 -4
- package/dist/sdk/wasm/host-bindings.js +0 -4
- package/dist/sdk/wasm/runner.d.ts +4 -10
- package/dist/sdk/wasm/runner.js +13 -86
- package/dist/sdk/wasm/runtime.d.ts +1 -4
- package/dist/sdk/wasm/runtime.js +1 -9
- package/dist/sdk/workflow.d.ts +7 -16
- package/dist/sdk/workflow.js +2 -10
- package/package.json +7 -4
- package/scripts/src/generate-sdks.ts +0 -6
- package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.d.ts +0 -1035
- package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.js +0 -290
- package/dist/generated/workflows/v2/cre_info_pb.d.ts +0 -123
- package/dist/generated/workflows/v2/cre_info_pb.js +0 -17
- package/dist/generated/workflows/v2/workflow_key_pb.d.ts +0 -55
- package/dist/generated/workflows/v2/workflow_key_pb.js +0 -17
- package/dist/generated/workflows/v2/workflow_user_metric_pb.d.ts +0 -118
- package/dist/generated/workflows/v2/workflow_user_metric_pb.js +0 -41
- package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.d.ts +0 -63
- package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.js +0 -247
- package/dist/sdk/tee-constraints.d.ts +0 -68
- package/dist/sdk/tee-constraints.js +0 -59
- package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.d.ts +0 -25
- package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.js +0 -111
- package/dist/workflows/standard_tests/restrictions/test.ts +0 -41
- package/dist/workflows/standard_tests/tee_runtime/test.ts +0 -29
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Test-only utilities for the CRE SDK runtime. Not part of the public API.
|
|
3
3
|
* Use for unit testing runtime logic without the WASM execution environment.
|
|
4
4
|
*/
|
|
5
|
-
export { type CapabilityHandler, DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, type NewTestRuntimeOptions, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, type Secrets, TestRuntime, type TestRuntimeState,
|
|
5
|
+
export { type CapabilityHandler, DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, type NewTestRuntimeOptions, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, type Secrets, TestRuntime, type TestRuntimeState, test, } from './test-runtime';
|
|
6
6
|
export { TestWriter } from './test-writer';
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Test-only utilities for the CRE SDK runtime. Not part of the public API.
|
|
3
3
|
* Use for unit testing runtime logic without the WASM execution environment.
|
|
4
4
|
*/
|
|
5
|
-
export { DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, TestRuntime,
|
|
5
|
+
export { DEFAULT_MAX_RESPONSE_SIZE_BYTES, getTestCapabilityHandler, newTestRuntime, REPORT_METADATA_HEADER_LENGTH, RESPONSE_BUFFER_TOO_SMALL, registerTestCapability, TestRuntime, test, } from './test-runtime';
|
|
6
6
|
export { TestWriter } from './test-writer';
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Registry is scoped per test via AsyncLocalStorage; use testWithRuntime to run tests with a registry.
|
|
4
4
|
*/
|
|
5
5
|
import type { Any } from '@bufbuild/protobuf/wkt';
|
|
6
|
-
import type { WorkflowUserMetric } from '../../generated/workflows/v2/workflow_user_metric_pb';
|
|
7
6
|
import type { RuntimeHelpers } from '../impl/runtime-impl';
|
|
8
|
-
import { RuntimeImpl
|
|
7
|
+
import { RuntimeImpl } from '../impl/runtime-impl';
|
|
9
8
|
import { TestWriter } from './test-writer';
|
|
10
9
|
/** Error message when response exceeds max size. Used by the harness when its await implements the size check. */
|
|
11
10
|
export declare const RESPONSE_BUFFER_TOO_SMALL = "response buffer too small";
|
|
@@ -71,27 +70,15 @@ export declare function test(title: string, fn: () => void | Promise<void>): voi
|
|
|
71
70
|
/**
|
|
72
71
|
* Creates a test runtime. This must be called from within a test in this package.
|
|
73
72
|
*/
|
|
74
|
-
export declare function newTestRuntime
|
|
73
|
+
export declare function newTestRuntime(secrets?: Secrets | null, options?: NewTestRuntimeOptions): TestRuntime;
|
|
75
74
|
/**
|
|
76
75
|
* TestRuntime is a Runtime implementation for unit tests. Extends RuntimeImpl; construct via newTestRuntime.
|
|
77
76
|
* Adds getLogs() and setTimeProvider(). Registry is accessed via getTestCapabilityHandler when inside testWithRuntime.
|
|
78
77
|
*/
|
|
79
|
-
export declare class TestRuntime
|
|
78
|
+
export declare class TestRuntime extends RuntimeImpl<unknown> {
|
|
80
79
|
private readonly testWriter;
|
|
81
80
|
private readonly state;
|
|
82
|
-
constructor(helpers: RuntimeHelpers, maxResponseSize: bigint, testWriter: TestWriter, state: TestRuntimeState
|
|
81
|
+
constructor(helpers: RuntimeHelpers, maxResponseSize: bigint, testWriter: TestWriter, state: TestRuntimeState);
|
|
83
82
|
getLogs(): string[];
|
|
84
83
|
setTimeProvider(timeProvider: () => number): void;
|
|
85
84
|
}
|
|
86
|
-
/**
|
|
87
|
-
* TestTeeRuntime is a TeeRuntime implementation for unit tests. Extends TeeRuntimeImpl; construct via newTestTEERuntime.
|
|
88
|
-
* Adds getLogs() and setTimeProvider(). Registry is accessed via getTestCapabilityHandler when inside testWithRuntime.
|
|
89
|
-
*/
|
|
90
|
-
export declare class TestTeeRuntime<T> extends TeeRuntimeImpl<T> {
|
|
91
|
-
private readonly testWriter;
|
|
92
|
-
private readonly state;
|
|
93
|
-
constructor(helpers: RuntimeHelpers, maxResponseSize: bigint, testWriter: TestWriter, state: TestRuntimeState, config: T);
|
|
94
|
-
getLogs(): string[];
|
|
95
|
-
getMetrics(): WorkflowUserMetric[];
|
|
96
|
-
setTimeProvider(timeProvider: () => number): void;
|
|
97
|
-
}
|
|
@@ -8,7 +8,7 @@ import { create, toBinary } from '@bufbuild/protobuf';
|
|
|
8
8
|
import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
|
|
9
9
|
import { AttributedSignatureSchema, AwaitCapabilitiesResponseSchema, AwaitSecretsResponseSchema, CapabilityResponseSchema, ReportRequestSchema, ReportResponseSchema, SecretErrorSchema, SecretResponseSchema, SecretResponsesSchema, SecretSchema, SimpleConsensusInputsSchema, } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
10
10
|
import { ValueSchema } from '../../generated/values/v1/values_pb';
|
|
11
|
-
import { RuntimeImpl
|
|
11
|
+
import { RuntimeImpl } from '../impl/runtime-impl';
|
|
12
12
|
import { TestWriter } from './test-writer';
|
|
13
13
|
/** Error message when response exceeds max size. Used by the harness when its await implements the size check. */
|
|
14
14
|
export const RESPONSE_BUFFER_TOO_SMALL = 'response buffer too small';
|
|
@@ -239,10 +239,6 @@ function createTestRuntimeHelpers(registry, secrets, testWriter, state, _maxResp
|
|
|
239
239
|
log(message) {
|
|
240
240
|
testWriter.log(message);
|
|
241
241
|
},
|
|
242
|
-
emitMetric(payload) {
|
|
243
|
-
testWriter.emitMetric(payload);
|
|
244
|
-
return true;
|
|
245
|
-
},
|
|
246
242
|
};
|
|
247
243
|
}
|
|
248
244
|
/**
|
|
@@ -262,7 +258,7 @@ export function test(title, fn) {
|
|
|
262
258
|
/**
|
|
263
259
|
* Creates a test runtime. This must be called from within a test in this package.
|
|
264
260
|
*/
|
|
265
|
-
export function newTestRuntime(secrets, options = {}
|
|
261
|
+
export function newTestRuntime(secrets, options = {}) {
|
|
266
262
|
const secretsMap = secrets ?? new Map();
|
|
267
263
|
const testWriter = new TestWriter();
|
|
268
264
|
const registry = registryStorage.getStore() ?? new Registry();
|
|
@@ -301,7 +297,7 @@ export function newTestRuntime(secrets, options = {}, config = undefined) {
|
|
|
301
297
|
}
|
|
302
298
|
const maxResponseSize = BigInt(configuredMaxResponseSize);
|
|
303
299
|
const helpers = createTestRuntimeHelpers(registry, secretsMap, testWriter, state, maxResponseSize);
|
|
304
|
-
return new TestRuntime(helpers, maxResponseSize, testWriter, state
|
|
300
|
+
return new TestRuntime(helpers, maxResponseSize, testWriter, state);
|
|
305
301
|
}
|
|
306
302
|
/**
|
|
307
303
|
* TestRuntime is a Runtime implementation for unit tests. Extends RuntimeImpl; construct via newTestRuntime.
|
|
@@ -310,36 +306,14 @@ export function newTestRuntime(secrets, options = {}, config = undefined) {
|
|
|
310
306
|
export class TestRuntime extends RuntimeImpl {
|
|
311
307
|
testWriter;
|
|
312
308
|
state;
|
|
313
|
-
constructor(helpers, maxResponseSize, testWriter, state
|
|
314
|
-
super(
|
|
315
|
-
this.testWriter = testWriter;
|
|
316
|
-
this.state = state;
|
|
317
|
-
}
|
|
318
|
-
getLogs() {
|
|
319
|
-
return this.testWriter.getLogs();
|
|
320
|
-
}
|
|
321
|
-
setTimeProvider(timeProvider) {
|
|
322
|
-
this.state.timeProvider = timeProvider;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* TestTeeRuntime is a TeeRuntime implementation for unit tests. Extends TeeRuntimeImpl; construct via newTestTEERuntime.
|
|
327
|
-
* Adds getLogs() and setTimeProvider(). Registry is accessed via getTestCapabilityHandler when inside testWithRuntime.
|
|
328
|
-
*/
|
|
329
|
-
export class TestTeeRuntime extends TeeRuntimeImpl {
|
|
330
|
-
testWriter;
|
|
331
|
-
state;
|
|
332
|
-
constructor(helpers, maxResponseSize, testWriter, state, config) {
|
|
333
|
-
super(config, 0, helpers, maxResponseSize);
|
|
309
|
+
constructor(helpers, maxResponseSize, testWriter, state) {
|
|
310
|
+
super({}, 0, helpers, maxResponseSize);
|
|
334
311
|
this.testWriter = testWriter;
|
|
335
312
|
this.state = state;
|
|
336
313
|
}
|
|
337
314
|
getLogs() {
|
|
338
315
|
return this.testWriter.getLogs();
|
|
339
316
|
}
|
|
340
|
-
getMetrics() {
|
|
341
|
-
return this.testWriter.getMetrics();
|
|
342
|
-
}
|
|
343
317
|
setTimeProvider(timeProvider) {
|
|
344
318
|
this.state.timeProvider = timeProvider;
|
|
345
319
|
}
|
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import { type WorkflowUserMetric } from '../../generated/workflows/v2/workflow_user_metric_pb';
|
|
2
1
|
/**
|
|
3
2
|
* In-memory log sink for tests. Captures messages so tests can assert on log output.
|
|
4
3
|
* Equivalent to Go's cre/testutils/test_writer.go.
|
|
5
4
|
*/
|
|
6
5
|
export declare class TestWriter {
|
|
7
6
|
private logs;
|
|
8
|
-
private metrics;
|
|
9
7
|
/** Appends a message to the captured log buffer. */
|
|
10
8
|
log(message: string): void;
|
|
11
9
|
/** Returns a copy of all captured log messages in order. */
|
|
12
10
|
getLogs(): string[];
|
|
13
|
-
/**
|
|
14
|
-
emitMetric(payload: Uint8Array): void;
|
|
15
|
-
/** Returns captured metric payloads decoded as `WorkflowUserMetric` protos. */
|
|
16
|
-
getMetrics(): WorkflowUserMetric[];
|
|
17
|
-
/** Clears captured logs and metrics. */
|
|
11
|
+
/** Clears the captured log buffer. */
|
|
18
12
|
clear(): void;
|
|
19
13
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { fromBinary } from '@bufbuild/protobuf';
|
|
2
|
-
import { WorkflowUserMetricSchema, } from '../../generated/workflows/v2/workflow_user_metric_pb';
|
|
3
1
|
/**
|
|
4
2
|
* In-memory log sink for tests. Captures messages so tests can assert on log output.
|
|
5
3
|
* Equivalent to Go's cre/testutils/test_writer.go.
|
|
6
4
|
*/
|
|
7
5
|
export class TestWriter {
|
|
8
6
|
logs = [];
|
|
9
|
-
metrics = [];
|
|
10
7
|
/** Appends a message to the captured log buffer. */
|
|
11
8
|
log(message) {
|
|
12
9
|
this.logs.push(message);
|
|
@@ -15,17 +12,8 @@ export class TestWriter {
|
|
|
15
12
|
getLogs() {
|
|
16
13
|
return [...this.logs];
|
|
17
14
|
}
|
|
18
|
-
/**
|
|
19
|
-
emitMetric(payload) {
|
|
20
|
-
this.metrics.push(payload);
|
|
21
|
-
}
|
|
22
|
-
/** Returns captured metric payloads decoded as `WorkflowUserMetric` protos. */
|
|
23
|
-
getMetrics() {
|
|
24
|
-
return this.metrics.map((bytes) => fromBinary(WorkflowUserMetricSchema, bytes));
|
|
25
|
-
}
|
|
26
|
-
/** Clears captured logs and metrics. */
|
|
15
|
+
/** Clears the captured log buffer. */
|
|
27
16
|
clear() {
|
|
28
17
|
this.logs = [];
|
|
29
|
-
this.metrics = [];
|
|
30
18
|
}
|
|
31
19
|
}
|
|
@@ -45,14 +45,6 @@ declare global {
|
|
|
45
45
|
*/
|
|
46
46
|
function log(message: string): void
|
|
47
47
|
|
|
48
|
-
/**
|
|
49
|
-
* Emits a user metric to the host. The payload is a protobuf-encoded
|
|
50
|
-
* `workflows.v2.WorkflowUserMetric` message.
|
|
51
|
-
* @param payload - protobuf-encoded WorkflowUserMetric bytes
|
|
52
|
-
* @returns 0 on success, negative on error (rate-limited, oversized, invalid name, etc.)
|
|
53
|
-
*/
|
|
54
|
-
function emitMetric(payload: Uint8Array): number
|
|
55
|
-
|
|
56
48
|
/**
|
|
57
49
|
* Sends a response back to the host
|
|
58
50
|
* @param response - bytes response
|
package/dist/sdk/utils/capabilities/blockchain/{blockchain-helpers.d.ts → evm/evm-helpers.d.ts}
RENAMED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { CallMsgJson, FilterLogTriggerRequestJson } from '
|
|
2
|
-
import type { ReportRequestJson } from '
|
|
3
|
-
import { type BigInt as GeneratedBigInt } from '
|
|
1
|
+
import type { CallMsgJson, FilterLogTriggerRequestJson } from '../../../../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
2
|
+
import type { ReportRequestJson } from '../../../../../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
+
import { type BigInt as GeneratedBigInt } from '../../../../../generated/values/v1/values_pb';
|
|
4
4
|
import type { Address, Hex } from 'viem';
|
|
5
|
+
import { type ReportEncoder } from '../report-helpers';
|
|
5
6
|
/**
|
|
6
7
|
* Protobuf BigInt structure returned by SDK methods (e.g., headerByNumber).
|
|
7
8
|
* Uses Pick to extract just the data fields from the generated type.
|
|
@@ -20,7 +21,7 @@ export type ProtoBigInt = Pick<GeneratedBigInt, 'absVal' | 'sign'>;
|
|
|
20
21
|
* @param n - The native bigint, number, or string value.
|
|
21
22
|
* @returns The protobuf BigInt JSON representation.
|
|
22
23
|
*/
|
|
23
|
-
export declare const bigintToProtoBigInt: (n: number | bigint | string) => import("
|
|
24
|
+
export declare const bigintToProtoBigInt: (n: number | bigint | string) => import("../../../../../generated/values/v1/values_pb").BigIntJson;
|
|
24
25
|
/**
|
|
25
26
|
* Converts a protobuf BigInt to a native JS bigint.
|
|
26
27
|
* Use this when extracting bigint values from SDK responses.
|
|
@@ -41,7 +42,7 @@ export declare const protoBigIntToBigint: (pb: ProtoBigInt) => bigint;
|
|
|
41
42
|
* @param n - The block number.
|
|
42
43
|
* @returns The protobuf BigInt JSON representation.
|
|
43
44
|
*/
|
|
44
|
-
export declare const blockNumber: (n: number | bigint | string) => import("
|
|
45
|
+
export declare const blockNumber: (n: number | bigint | string) => import("../../../../../generated/values/v1/values_pb").BigIntJson;
|
|
45
46
|
/**
|
|
46
47
|
* EVM Capability Helper.
|
|
47
48
|
*
|
|
@@ -106,7 +107,7 @@ export declare const EVM_DEFAULT_REPORT_ENCODER: {
|
|
|
106
107
|
* @param reportEncoder - The report encoder to be used. Defaults to EVM_DEFAULT_REPORT_ENCODER.
|
|
107
108
|
* @returns The prepared report request.
|
|
108
109
|
*/
|
|
109
|
-
export declare const prepareReportRequest: (hexEncodedPayload: Hex, reportEncoder?:
|
|
110
|
+
export declare const prepareReportRequest: (hexEncodedPayload: Hex, reportEncoder?: ReportEncoder) => ReportRequestJson;
|
|
110
111
|
export interface LogTriggerConfigOptions {
|
|
111
112
|
/** EVM addresses to monitor — hex strings with 0x prefix (20 bytes each) */
|
|
112
113
|
addresses: Hex[];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { create, toJson } from '@bufbuild/protobuf';
|
|
2
|
-
import { BigIntSchema } from '
|
|
3
|
-
import { EVMClient } from '
|
|
4
|
-
import { bigintToBytes, bytesToBigint, hexToBase64, hexToBytes } from '
|
|
5
|
-
import { assertSafeIntegerNumber } from '
|
|
2
|
+
import { BigIntSchema } from '../../../../../generated/values/v1/values_pb';
|
|
3
|
+
import { EVMClient } from '../../../../cre';
|
|
4
|
+
import { bigintToBytes, bytesToBigint, hexToBase64, hexToBytes } from '../../../hex-utils';
|
|
5
|
+
import { assertSafeIntegerNumber } from '../../../safe-integer';
|
|
6
|
+
import { prepareReportRequestFromBytes } from '../report-helpers';
|
|
6
7
|
/**
|
|
7
8
|
* Converts a native JS bigint to a protobuf BigInt JSON representation.
|
|
8
9
|
* Use this when passing bigint values to SDK methods.
|
|
@@ -126,10 +127,7 @@ export const EVM_DEFAULT_REPORT_ENCODER = {
|
|
|
126
127
|
* @param reportEncoder - The report encoder to be used. Defaults to EVM_DEFAULT_REPORT_ENCODER.
|
|
127
128
|
* @returns The prepared report request.
|
|
128
129
|
*/
|
|
129
|
-
export const prepareReportRequest = (hexEncodedPayload, reportEncoder = EVM_DEFAULT_REPORT_ENCODER) => (
|
|
130
|
-
encodedPayload: hexToBase64(hexEncodedPayload),
|
|
131
|
-
...reportEncoder,
|
|
132
|
-
});
|
|
130
|
+
export const prepareReportRequest = (hexEncodedPayload, reportEncoder = EVM_DEFAULT_REPORT_ENCODER) => prepareReportRequestFromBytes(hexToBytes(hexEncodedPayload), reportEncoder);
|
|
133
131
|
/**
|
|
134
132
|
* Validates a hex string and checks that the decoded bytes have the expected length.
|
|
135
133
|
*/
|
|
@@ -0,0 +1,19 @@
|
|
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { AccountMetaJson, ComputeConfigJson, CPIFilterConfigJson, Log } from '../../../../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
|
|
2
|
+
import type { ReportRequestJson } from '../../../../../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
+
import { type ReportEncoder } from '../report-helpers';
|
|
4
|
+
/**
|
|
5
|
+
* An account passed to the Solana capability's `remainingAccounts` list.
|
|
6
|
+
* Build instances with {@link solanaAccountMeta}; generated bindings convert
|
|
7
|
+
* to the capability's protobuf JSON shape internally.
|
|
8
|
+
*/
|
|
9
|
+
export interface SolanaAccountMeta {
|
|
10
|
+
publicKey: Uint8Array;
|
|
11
|
+
isWritable: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Compute settings for a Solana write-report request. Mirrors the
|
|
15
|
+
* capability's `ComputeConfig` protobuf JSON shape.
|
|
16
|
+
*/
|
|
17
|
+
export type SolanaComputeConfig = ComputeConfigJson;
|
|
18
|
+
/**
|
|
19
|
+
* The minimal account shape needed by {@link calculateAccountsHash} —
|
|
20
|
+
* only the public key participates in the hash. Structurally compatible
|
|
21
|
+
* with both {@link SolanaAccountMeta} and the capability's protobuf
|
|
22
|
+
* `AccountMeta`.
|
|
23
|
+
*/
|
|
24
|
+
export type SolanaAccountInput = Pick<SolanaAccountMeta, 'publicKey'> & Partial<Pick<SolanaAccountMeta, 'isWritable'>>;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a base58-encoded Solana address to its 32 raw bytes.
|
|
27
|
+
*
|
|
28
|
+
* @param base58Address - The base58-encoded address (validated).
|
|
29
|
+
* @returns The 32-byte public key.
|
|
30
|
+
*/
|
|
31
|
+
export declare const solanaAddressToBytes: (base58Address: string) => Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Builds an account entry for the Solana capability's `remainingAccounts` list.
|
|
34
|
+
*
|
|
35
|
+
* @param publicKey - The account's public key, as 32 raw bytes or a base58 string.
|
|
36
|
+
* @param isWritable - Whether the account is writable. Defaults to false.
|
|
37
|
+
* @returns The account meta.
|
|
38
|
+
*/
|
|
39
|
+
export declare const solanaAccountMeta: (publicKey: Uint8Array | string, isWritable?: boolean) => SolanaAccountMeta;
|
|
40
|
+
/**
|
|
41
|
+
* Converts {@link SolanaAccountMeta} entries to the capability's protobuf
|
|
42
|
+
* JSON `AccountMeta` shape (base64 public keys), as expected by
|
|
43
|
+
* `SolanaClient.writeReport`. Used by generated bindings.
|
|
44
|
+
*/
|
|
45
|
+
export declare const solanaAccountMetasToJson: (accounts: ReadonlyArray<SolanaAccountMeta>) => AccountMetaJson[];
|
|
46
|
+
/**
|
|
47
|
+
* Computes the SHA-256 hash of the concatenated public keys of the given
|
|
48
|
+
* accounts, matching the keystone-forwarder's on-chain account hash
|
|
49
|
+
* verification. Nullish entries are skipped; account order matters.
|
|
50
|
+
*
|
|
51
|
+
* Mirrors Go `bindings.CalculateAccountsHash`.
|
|
52
|
+
*
|
|
53
|
+
* @param accounts - The accounts whose public keys are hashed.
|
|
54
|
+
* @returns The 32-byte account hash.
|
|
55
|
+
*/
|
|
56
|
+
export declare const calculateAccountsHash: (accounts: ReadonlyArray<SolanaAccountInput | null | undefined>) => Uint8Array;
|
|
57
|
+
export interface ForwarderReport {
|
|
58
|
+
/** The 32-byte hash from `calculateAccountsHash`. */
|
|
59
|
+
accountHash: Uint8Array;
|
|
60
|
+
/** The Borsh-encoded report payload the receiver's `on_report` deserializes. */
|
|
61
|
+
payload: Uint8Array;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Borsh-encodes a `ForwarderReport` for the keystone-forwarder:
|
|
65
|
+
* `[32-byte accountHash][u32-LE payload length][payload bytes]`.
|
|
66
|
+
*
|
|
67
|
+
* Mirrors Go `bindings.ForwarderReport.Marshal`.
|
|
68
|
+
*
|
|
69
|
+
* @param report - The account hash and payload to encode.
|
|
70
|
+
* @returns The encoded forwarder report.
|
|
71
|
+
*/
|
|
72
|
+
export declare const encodeForwarderReport: (report: ForwarderReport) => Uint8Array;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the Anchor/Borsh encoding of a Vec whose elements are opaque byte
|
|
75
|
+
* payloads: `[u32-LE element count][concatenated element payloads]`.
|
|
76
|
+
* Each element must already be fully serialized for one Vec item on the wire.
|
|
77
|
+
*
|
|
78
|
+
* Mirrors Go's generated `EncodeBorshVecU32`.
|
|
79
|
+
*
|
|
80
|
+
* @param elementPayloads - The pre-encoded Vec elements.
|
|
81
|
+
* @returns The encoded Vec.
|
|
82
|
+
*/
|
|
83
|
+
export declare const encodeBorshVecU32: (elementPayloads: ReadonlyArray<Uint8Array>) => Uint8Array;
|
|
84
|
+
/**
|
|
85
|
+
* Default values expected by the Solana capability for report encoding.
|
|
86
|
+
* Mirrors the constants emitted by the Go Solana bindings generator.
|
|
87
|
+
*/
|
|
88
|
+
export declare const SOLANA_DEFAULT_REPORT_ENCODER: {
|
|
89
|
+
encoderName: string;
|
|
90
|
+
signingAlgo: string;
|
|
91
|
+
hashingAlgo: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Prepares a report request for the Solana capability to pass to `.report()`.
|
|
95
|
+
* Takes raw bytes (typically an encoded `ForwarderReport`), not hex.
|
|
96
|
+
*
|
|
97
|
+
* @param payload - The encoded payload bytes to be signed.
|
|
98
|
+
* @param reportEncoder - The report encoder to use. Defaults to SOLANA_DEFAULT_REPORT_ENCODER.
|
|
99
|
+
* @returns The prepared report request.
|
|
100
|
+
*/
|
|
101
|
+
export declare const prepareSolanaReportRequest: (payload: Uint8Array, reportEncoder?: ReportEncoder) => ReportRequestJson;
|
|
102
|
+
/**
|
|
103
|
+
* A filter value accepted by {@link prepareSubkeyValue}.
|
|
104
|
+
* Solana public keys must be passed as their 32 raw bytes
|
|
105
|
+
* (see {@link solanaAddressToBytes}), not as base58 strings.
|
|
106
|
+
*/
|
|
107
|
+
export type SolanaSubkeyValue = Uint8Array | string | bigint | number;
|
|
108
|
+
/**
|
|
109
|
+
* Encodes a filter value for use in a `SubkeyConfig` `ValueComparator`,
|
|
110
|
+
* matching the byte representation the Solana log-trigger capability indexes.
|
|
111
|
+
*
|
|
112
|
+
* Encodings (mirrors Go `bindings.PrepareSubkeyValue`):
|
|
113
|
+
* - `Uint8Array` — used as-is (public keys, fixed byte arrays, `bytes` fields)
|
|
114
|
+
* - `string` — UTF-8 bytes
|
|
115
|
+
* - `bigint` / integer `number` — 8-byte big-endian two's complement
|
|
116
|
+
*
|
|
117
|
+
* For `f32`/`f64` event fields use {@link prepareSubkeyFloatValue}; passing a
|
|
118
|
+
* non-integer `number` here throws.
|
|
119
|
+
*
|
|
120
|
+
* @param value - The filter value to encode.
|
|
121
|
+
* @returns The encoded comparator value bytes.
|
|
122
|
+
*/
|
|
123
|
+
export declare const prepareSubkeyValue: (value: SolanaSubkeyValue) => Uint8Array;
|
|
124
|
+
/**
|
|
125
|
+
* Encodes an `f32`/`f64` filter value into the 8-byte big-endian
|
|
126
|
+
* representation the Solana log-trigger capability indexes.
|
|
127
|
+
*
|
|
128
|
+
* Byte-compatible with Go `bindings.EncodeIndexedValue` for floats: positive
|
|
129
|
+
* values map to `float64bits + 2^63`, others to `2^63 - float64bits`
|
|
130
|
+
* (modulo 2^64). Ordering is preserved among values of the same sign.
|
|
131
|
+
*
|
|
132
|
+
* @param value - The float filter value to encode.
|
|
133
|
+
* @returns The encoded comparator value bytes.
|
|
134
|
+
*/
|
|
135
|
+
export declare const prepareSubkeyFloatValue: (value: number) => Uint8Array;
|
|
136
|
+
/**
|
|
137
|
+
* A Solana log paired with its decoded event data. Generated log-trigger
|
|
138
|
+
* bindings adapt raw `Log` payloads into this shape.
|
|
139
|
+
*
|
|
140
|
+
* Mirrors Go `bindings.DecodedLog[T]`.
|
|
141
|
+
*/
|
|
142
|
+
export type SolanaDecodedLog<T> = {
|
|
143
|
+
log: Log;
|
|
144
|
+
data: T;
|
|
145
|
+
};
|
|
146
|
+
/** Options for generated Solana log-trigger bindings. */
|
|
147
|
+
export interface SolanaLogTriggerOptions {
|
|
148
|
+
/**
|
|
149
|
+
* Listen for events emitted via Anchor's `emit_cpi!` (self-CPI) instead of
|
|
150
|
+
* program logs. Sets the trigger's CPI filter to the program's
|
|
151
|
+
* `anchor:event` method (see {@link anchorCPILogTriggerConfig}).
|
|
152
|
+
*/
|
|
153
|
+
cpi?: boolean;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Builds the `CPIFilterConfig` for log triggers on events emitted via
|
|
157
|
+
* Anchor's `emit_cpi!`: destination is the program itself, method is
|
|
158
|
+
* `anchor:event`.
|
|
159
|
+
*
|
|
160
|
+
* Mirrors Go `bindings.AnchorCPILogTriggerConfig`.
|
|
161
|
+
*
|
|
162
|
+
* @param programId - The program's public key, as 32 raw bytes or a base58 string.
|
|
163
|
+
* @returns The CPI filter config in protobuf JSON shape.
|
|
164
|
+
*/
|
|
165
|
+
export declare const anchorCPILogTriggerConfig: (programId: Uint8Array | string) => CPIFilterConfigJson;
|