@chainlink/cre-sdk 1.9.0 → 1.10.0
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/dist/generated/capabilities/blockchain/evm/v1alpha/client_pb.js +1 -1
- package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.d.ts +268 -0
- package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.js +90 -0
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +10 -13
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +0 -4
- package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +42 -0
- package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +82 -0
- package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.d.ts +3 -2
- package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.d.ts +2 -1
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.d.ts +3 -2
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.d.ts +2 -1
- package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.d.ts +2 -1
- package/dist/pb.d.ts +1 -0
- package/dist/pb.js +1 -0
- package/dist/sdk/cre/index.d.ts +4 -0
- package/dist/sdk/cre/index.js +5 -0
- package/dist/sdk/impl/runtime-impl.d.ts +3 -0
- package/dist/sdk/impl/runtime-impl.js +9 -4
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.js +1 -0
- package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.d.ts +17 -0
- package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.js +53 -0
- package/dist/sdk/test/generated/index.d.ts +1 -0
- package/dist/sdk/test/generated/index.js +1 -0
- package/dist/sdk/testutils/test-runtime.js +9 -1
- package/dist/sdk/types/global.d.ts +6 -0
- package/dist/sdk/utils/capabilities/blockchain/blockchain-helpers.js +3 -2
- package/dist/sdk/utils/capabilities/confidentialhttp/confidential-http-helpers.d.ts +43 -0
- package/dist/sdk/utils/capabilities/confidentialhttp/confidential-http-helpers.js +58 -0
- package/dist/sdk/utils/capabilities/http/http-helpers.d.ts +20 -6
- package/dist/sdk/utils/capabilities/http/http-helpers.js +23 -4
- package/dist/sdk/utils/safe-integer.d.ts +8 -0
- package/dist/sdk/utils/safe-integer.js +15 -0
- package/dist/sdk/utils/types/no-excess.d.ts +32 -0
- package/dist/sdk/utils/types/no-excess.js +1 -0
- package/dist/sdk/utils/values/value.js +3 -4
- package/dist/sdk/wasm/host-bindings.d.ts +39 -0
- package/dist/sdk/wasm/host-bindings.js +2 -1
- package/dist/sdk/wasm/runtime.js +3 -0
- package/package.json +4 -3
- package/scripts/src/generate-sdks.ts +6 -0
package/dist/generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ConfidentialHTTPRequest, type ConfidentialHTTPRequestJson, type HTTPResponse } from '../../../../../generated/capabilities/networking/confidentialhttp/v1alpha/client_pb';
|
|
2
2
|
import type { Runtime } from '../../../../../sdk';
|
|
3
|
+
import type { CapabilityInput } from '../../../../../sdk/utils/types/no-excess';
|
|
3
4
|
/**
|
|
4
5
|
* Client Capability
|
|
5
6
|
*
|
|
@@ -12,7 +13,7 @@ export declare class ClientCapability {
|
|
|
12
13
|
static readonly CAPABILITY_ID = "confidential-http@1.0.0-alpha";
|
|
13
14
|
static readonly CAPABILITY_NAME = "confidential-http";
|
|
14
15
|
static readonly CAPABILITY_VERSION = "1.0.0-alpha";
|
|
15
|
-
sendRequest(runtime: Runtime<unknown>, input: ConfidentialHTTPRequest
|
|
16
|
+
sendRequest<TInput>(runtime: Runtime<unknown>, input: CapabilityInput<TInput, ConfidentialHTTPRequest, ConfidentialHTTPRequestJson>): {
|
|
16
17
|
result: () => HTTPResponse;
|
|
17
18
|
};
|
|
18
19
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type Request, type RequestJson, type Response } from '../../../../../generated/capabilities/networking/http/v1alpha/client_pb';
|
|
2
2
|
import type { NodeRuntime, Runtime } from '../../../../../sdk';
|
|
3
3
|
import type { ConsensusAggregation, PrimitiveTypes, UnwrapOptions } from '../../../../../sdk/utils';
|
|
4
|
+
import type { CapabilityInput } from '../../../../../sdk/utils/types/no-excess';
|
|
4
5
|
export declare class SendRequester {
|
|
5
6
|
private readonly runtime;
|
|
6
7
|
private readonly client;
|
|
7
8
|
constructor(runtime: NodeRuntime<unknown>, client: ClientCapability);
|
|
8
|
-
sendRequest(input: Request
|
|
9
|
+
sendRequest<TInput>(input: CapabilityInput<TInput, Request, RequestJson>): {
|
|
9
10
|
result: () => Response;
|
|
10
11
|
};
|
|
11
12
|
}
|
|
@@ -21,7 +22,7 @@ export declare class ClientCapability {
|
|
|
21
22
|
static readonly CAPABILITY_ID = "http-actions@1.0.0-alpha";
|
|
22
23
|
static readonly CAPABILITY_NAME = "http-actions";
|
|
23
24
|
static readonly CAPABILITY_VERSION = "1.0.0-alpha";
|
|
24
|
-
sendRequest(runtime: NodeRuntime<unknown>, input: Request
|
|
25
|
+
sendRequest<TInput>(runtime: NodeRuntime<unknown>, input: CapabilityInput<TInput, Request, RequestJson>): {
|
|
25
26
|
result: () => Response;
|
|
26
27
|
};
|
|
27
28
|
sendRequest<TArgs extends unknown[], TOutput>(runtime: Runtime<unknown>, fn: (sendRequester: SendRequester, ...args: TArgs) => TOutput, consensusAggregation: ConsensusAggregation<TOutput, true>, unwrapOptions?: TOutput extends PrimitiveTypes ? never : UnwrapOptions<TOutput>): (...args: TArgs) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Any } from '@bufbuild/protobuf/wkt';
|
|
2
2
|
import { type Config, type ConfigJson, type Payload } from '../../../../../generated/capabilities/networking/http/v1alpha/trigger_pb';
|
|
3
3
|
import type { Trigger } from '../../../../../sdk/utils/triggers/trigger-interface';
|
|
4
|
+
import type { NoExcess } from '../../../../../sdk/utils/types/no-excess';
|
|
4
5
|
/**
|
|
5
6
|
* HTTP Capability
|
|
6
7
|
*
|
|
@@ -13,7 +14,7 @@ export declare class HTTPCapability {
|
|
|
13
14
|
static readonly CAPABILITY_ID = "http-trigger@1.0.0-alpha";
|
|
14
15
|
static readonly CAPABILITY_NAME = "http-trigger";
|
|
15
16
|
static readonly CAPABILITY_VERSION = "1.0.0-alpha";
|
|
16
|
-
trigger(config: ConfigJson): HTTPTrigger;
|
|
17
|
+
trigger<TConfig extends ConfigJson>(config: NoExcess<TConfig, ConfigJson>): HTTPTrigger;
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Trigger implementation for Trigger
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Any } from '@bufbuild/protobuf/wkt';
|
|
2
2
|
import { type Config, type ConfigJson, type Payload } from '../../../../../generated/capabilities/scheduler/cron/v1/trigger_pb';
|
|
3
3
|
import type { Trigger } from '../../../../../sdk/utils/triggers/trigger-interface';
|
|
4
|
+
import type { NoExcess } from '../../../../../sdk/utils/types/no-excess';
|
|
4
5
|
/**
|
|
5
6
|
* Cron Capability
|
|
6
7
|
*
|
|
@@ -13,7 +14,7 @@ export declare class CronCapability {
|
|
|
13
14
|
static readonly CAPABILITY_ID = "cron-trigger@1.0.0";
|
|
14
15
|
static readonly CAPABILITY_NAME = "cron-trigger";
|
|
15
16
|
static readonly CAPABILITY_VERSION = "1.0.0";
|
|
16
|
-
trigger(config: ConfigJson): CronTrigger;
|
|
17
|
+
trigger<TConfig extends ConfigJson>(config: NoExcess<TConfig, ConfigJson>): CronTrigger;
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Trigger implementation for Trigger
|
package/dist/pb.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * as EVM_PB from './generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
2
|
+
export * as SOLANA_PB from './generated/capabilities/blockchain/solana/v1alpha/client_pb';
|
|
2
3
|
export * as CONFIDENTIAL_HTTP_CLIENT_PB from './generated/capabilities/networking/confidentialhttp/v1alpha/client_pb';
|
|
3
4
|
export * as HTTP_CLIENT_PB from './generated/capabilities/networking/http/v1alpha/client_pb';
|
|
4
5
|
export * as HTTP_TRIGGER_PB from './generated/capabilities/networking/http/v1alpha/trigger_pb';
|
package/dist/pb.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * as EVM_PB from './generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
2
|
+
export * as SOLANA_PB from './generated/capabilities/blockchain/solana/v1alpha/client_pb';
|
|
2
3
|
export * as CONFIDENTIAL_HTTP_CLIENT_PB from './generated/capabilities/networking/confidentialhttp/v1alpha/client_pb';
|
|
3
4
|
export * as HTTP_CLIENT_PB from './generated/capabilities/networking/http/v1alpha/client_pb';
|
|
4
5
|
export * as HTTP_TRIGGER_PB from './generated/capabilities/networking/http/v1alpha/trigger_pb';
|
package/dist/sdk/cre/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Public API for the CRE SDK.
|
|
3
3
|
*/
|
|
4
4
|
import { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
|
|
5
|
+
import { ClientCapability as SolanaClient } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
|
|
5
6
|
import { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
|
|
6
7
|
import { ClientCapability as HTTPClient } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
|
|
7
8
|
import { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
|
|
@@ -10,9 +11,11 @@ import { CronCapability } from '../../generated-sdk/capabilities/scheduler/cron/
|
|
|
10
11
|
* Public exports for the CRE SDK.
|
|
11
12
|
*/
|
|
12
13
|
export { type Log as EVMLog, TxStatus, } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
14
|
+
export { ReceiverContractExecutionStatus as SolanaReceiverContractExecutionStatus, TxStatus as SolanaTxStatus, } from '../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
|
|
13
15
|
export type { Payload as HTTPPayload } from '../../generated/capabilities/networking/http/v1alpha/trigger_pb';
|
|
14
16
|
export type { Payload as CronPayload } from '../../generated/capabilities/scheduler/cron/v1/trigger_pb';
|
|
15
17
|
export { ClientCapability as EVMClient, type WriteCreReportRequest, type WriteCreReportRequestJson, } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
|
|
18
|
+
export { ClientCapability as SolanaClient, type WriteCreReportRequest as SolanaWriteCreReportRequest, type WriteCreReportRequestJson as SolanaWriteCreReportRequestJson, } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
|
|
16
19
|
export { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
|
|
17
20
|
export { ClientCapability as HTTPClient, type SendRequester as HTTPSendRequester, } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
|
|
18
21
|
export { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
|
|
@@ -26,6 +29,7 @@ export declare const cre: {
|
|
|
26
29
|
ConfidentialHTTPClient: typeof ConfidentialHTTPClient;
|
|
27
30
|
HTTPClient: typeof HTTPClient;
|
|
28
31
|
EVMClient: typeof EVMClient;
|
|
32
|
+
SolanaClient: typeof SolanaClient;
|
|
29
33
|
};
|
|
30
34
|
handler: <TRawTriggerOutput extends import("@bufbuild/protobuf").Message<string>, TTriggerOutput, TConfig, TResult>(trigger: import("../utils/triggers/trigger-interface").Trigger<TRawTriggerOutput, TTriggerOutput>, fn: import("../workflow").HandlerFn<TConfig, TTriggerOutput, TResult>) => import("../workflow").HandlerEntry<TConfig, TRawTriggerOutput, TTriggerOutput, TResult>;
|
|
31
35
|
};
|
package/dist/sdk/cre/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Public API for the CRE SDK.
|
|
3
3
|
*/
|
|
4
4
|
import { ClientCapability as EVMClient } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
|
|
5
|
+
import { ClientCapability as SolanaClient } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
|
|
5
6
|
import { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
|
|
6
7
|
import { ClientCapability as HTTPClient } from '../../generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen';
|
|
7
8
|
import { HTTPCapability } from '../../generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen';
|
|
@@ -12,8 +13,11 @@ import { handler } from '../workflow';
|
|
|
12
13
|
* Public exports for the CRE SDK.
|
|
13
14
|
*/
|
|
14
15
|
export { TxStatus, } from '../../generated/capabilities/blockchain/evm/v1alpha/client_pb';
|
|
16
|
+
export { ReceiverContractExecutionStatus as SolanaReceiverContractExecutionStatus, TxStatus as SolanaTxStatus, } from '../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
|
|
15
17
|
// EVM Capability
|
|
16
18
|
export { ClientCapability as EVMClient, } from '../../generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen';
|
|
19
|
+
// Solana Capability
|
|
20
|
+
export { ClientCapability as SolanaClient, } from '../../generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen';
|
|
17
21
|
// Confidential HTTP Capability
|
|
18
22
|
export { ClientCapability as ConfidentialHTTPClient } from '../../generated-sdk/capabilities/networking/confidentialhttp/v1alpha/client_sdk_gen';
|
|
19
23
|
// HTTP Capability
|
|
@@ -30,6 +34,7 @@ export const cre = {
|
|
|
30
34
|
ConfidentialHTTPClient,
|
|
31
35
|
HTTPClient,
|
|
32
36
|
EVMClient,
|
|
37
|
+
SolanaClient,
|
|
33
38
|
},
|
|
34
39
|
handler,
|
|
35
40
|
};
|
|
@@ -42,6 +42,7 @@ export declare class BaseRuntimeImpl<C> implements BaseRuntime<C> {
|
|
|
42
42
|
private awaitAndUnwrapCapabilityResponse;
|
|
43
43
|
getNextCallId(): number;
|
|
44
44
|
now(): Date;
|
|
45
|
+
sleep(ms: number): void;
|
|
45
46
|
log(message: string): void;
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
@@ -110,6 +111,8 @@ export interface RuntimeHelpers {
|
|
|
110
111
|
switchModes(mode: Mode): void;
|
|
111
112
|
/** Returns current time in milliseconds since Unix epoch. */
|
|
112
113
|
now(): number;
|
|
114
|
+
/** Sleeps for the specified duration. */
|
|
115
|
+
sleep(ms: number): void;
|
|
113
116
|
/** Logs a message to the host environment. */
|
|
114
117
|
log(message: string): void;
|
|
115
118
|
}
|
|
@@ -5,6 +5,7 @@ import { ConsensusCapability } from '../../generated-sdk/capabilities/internal/c
|
|
|
5
5
|
import { Value, } from '../utils';
|
|
6
6
|
import { CapabilityError } from '../utils/capabilities/capability-error';
|
|
7
7
|
import { DonModeError, NodeModeError, SecretsError } from '../errors';
|
|
8
|
+
const DEFAULT_SECRET_NAMESPACE = 'main';
|
|
8
9
|
/**
|
|
9
10
|
* Base implementation shared by DON and Node runtimes.
|
|
10
11
|
*
|
|
@@ -136,6 +137,9 @@ export class BaseRuntimeImpl {
|
|
|
136
137
|
// date is already in milliseconds
|
|
137
138
|
return new Date(this.helpers.now());
|
|
138
139
|
}
|
|
140
|
+
sleep(ms) {
|
|
141
|
+
this.helpers.sleep(ms);
|
|
142
|
+
}
|
|
139
143
|
log(message) {
|
|
140
144
|
this.helpers.log(message);
|
|
141
145
|
}
|
|
@@ -254,10 +258,10 @@ export class RuntimeImpl extends BaseRuntimeImpl {
|
|
|
254
258
|
},
|
|
255
259
|
};
|
|
256
260
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
+
const secretRequest = create(SecretRequestSchema, {
|
|
262
|
+
id: request.id,
|
|
263
|
+
namespace: request.namespace || DEFAULT_SECRET_NAMESPACE,
|
|
264
|
+
});
|
|
261
265
|
// Allocate callback ID and send request
|
|
262
266
|
const id = this.nextCallId;
|
|
263
267
|
this.nextCallId++;
|
|
@@ -314,6 +318,7 @@ export class RuntimeImpl extends BaseRuntimeImpl {
|
|
|
314
318
|
*/
|
|
315
319
|
report(input) {
|
|
316
320
|
const consensus = new ConsensusCapability();
|
|
321
|
+
// Cast to native overload signature - the impl dispatches on $typeName.
|
|
317
322
|
const call = consensus.report(this, input);
|
|
318
323
|
return {
|
|
319
324
|
result: () => call.result(),
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type * from './runtime';
|
|
|
6
6
|
export * from './runtime';
|
|
7
7
|
export * from './types/bufbuild-types';
|
|
8
8
|
export * from './utils';
|
|
9
|
+
export * from './utils/capabilities/confidentialhttp/confidential-http-helpers';
|
|
9
10
|
export * from './utils/capabilities/http/http-helpers';
|
|
10
11
|
export * from './wasm';
|
|
11
12
|
export * from './workflow';
|
package/dist/sdk/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from './runtime';
|
|
|
6
6
|
export * from './types/bufbuild-types';
|
|
7
7
|
export * from './utils';
|
|
8
8
|
// Export HTTP response helpers
|
|
9
|
+
export * from './utils/capabilities/confidentialhttp/confidential-http-helpers';
|
|
9
10
|
export * from './utils/capabilities/http/http-helpers';
|
|
10
11
|
export * from './wasm';
|
|
11
12
|
export * from './workflow';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type WriteReportReply, type WriteReportReplyJson, type WriteReportRequest } from '../../../../../../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
|
|
2
|
+
/**
|
|
3
|
+
* Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
|
|
4
|
+
* Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SolanaMock {
|
|
7
|
+
static readonly CAPABILITY_ID = "solana@1.0.0";
|
|
8
|
+
/** Set to define the return value for WriteReport. May return a plain object (WriteReportReplyJson) or the message type. */
|
|
9
|
+
writeReport?: (input: WriteReportRequest) => WriteReportReply | WriteReportReplyJson;
|
|
10
|
+
private constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Returns the mock instance for this capability and the specified tags.
|
|
13
|
+
* Multiple calls with the same tag values return the same instance.
|
|
14
|
+
* Must be called within the test framework's test() method.
|
|
15
|
+
*/
|
|
16
|
+
static testInstance(chainSelector: bigint): SolanaMock;
|
|
17
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { fromJson } from '@bufbuild/protobuf';
|
|
2
|
+
import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
|
|
3
|
+
import { WriteReportReplySchema, WriteReportRequestSchema, } from '../../../../../../../generated/capabilities/blockchain/solana/v1alpha/client_pb';
|
|
4
|
+
import { __getTestMockInstance, __setTestMockInstance, registerTestCapability, } from '../../../../../../testutils/test-runtime';
|
|
5
|
+
/**
|
|
6
|
+
* Mock for ClientCapability. Use testInstance() to obtain an instance; do not construct directly.
|
|
7
|
+
* Set per-method properties (e.g. performAction) to define return values. If a method is invoked without a handler set, an error is thrown.
|
|
8
|
+
*/
|
|
9
|
+
export class SolanaMock {
|
|
10
|
+
static CAPABILITY_ID = 'solana@1.0.0';
|
|
11
|
+
/** Set to define the return value for WriteReport. May return a plain object (WriteReportReplyJson) or the message type. */
|
|
12
|
+
writeReport;
|
|
13
|
+
constructor(chainSelector) {
|
|
14
|
+
const self = this;
|
|
15
|
+
const qualifiedId = `solana:ChainSelector:${chainSelector}@1.0.0`;
|
|
16
|
+
try {
|
|
17
|
+
registerTestCapability(qualifiedId, (req) => {
|
|
18
|
+
switch (req.method) {
|
|
19
|
+
case 'WriteReport': {
|
|
20
|
+
const input = anyUnpack(req.payload, WriteReportRequestSchema);
|
|
21
|
+
const handler = self.writeReport;
|
|
22
|
+
if (typeof handler !== 'function')
|
|
23
|
+
throw new Error("WriteReport: no implementation provided; set the mock's writeReport property to define the return value.");
|
|
24
|
+
const raw = handler(input);
|
|
25
|
+
const output = raw && typeof raw.$typeName === 'string'
|
|
26
|
+
? raw
|
|
27
|
+
: fromJson(WriteReportReplySchema, raw);
|
|
28
|
+
return { response: { case: 'payload', value: anyPack(WriteReportReplySchema, output) } };
|
|
29
|
+
}
|
|
30
|
+
default:
|
|
31
|
+
return { response: { case: 'error', value: `unknown method ${req.method}` } };
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new Error("Capability mocks must be used within the CRE test framework's test() method.");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the mock instance for this capability and the specified tags.
|
|
41
|
+
* Multiple calls with the same tag values return the same instance.
|
|
42
|
+
* Must be called within the test framework's test() method.
|
|
43
|
+
*/
|
|
44
|
+
static testInstance(chainSelector) {
|
|
45
|
+
const qualifiedId = `solana:ChainSelector:${chainSelector}@1.0.0`;
|
|
46
|
+
let instance = __getTestMockInstance(qualifiedId);
|
|
47
|
+
if (!instance) {
|
|
48
|
+
instance = new SolanaMock(chainSelector);
|
|
49
|
+
__setTestMockInstance(qualifiedId, instance);
|
|
50
|
+
}
|
|
51
|
+
return instance;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Auto-generated barrel of capability mocks. Do not edit. */
|
|
2
2
|
export { EvmMock } from './capabilities/blockchain/evm/v1alpha/evm_mock_gen';
|
|
3
|
+
export { SolanaMock } from './capabilities/blockchain/solana/v1alpha/solana_mock_gen';
|
|
3
4
|
export { BasicTestActionTriggerMock } from './capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen';
|
|
4
5
|
export { BasicTestActionMock } from './capabilities/internal/basicaction/v1/basic_test_action_mock_gen';
|
|
5
6
|
export { ConsensusMock } from './capabilities/internal/consensus/v1alpha/consensus_mock_gen';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Auto-generated barrel of capability mocks. Do not edit. */
|
|
2
2
|
export { EvmMock } from './capabilities/blockchain/evm/v1alpha/evm_mock_gen';
|
|
3
|
+
export { SolanaMock } from './capabilities/blockchain/solana/v1alpha/solana_mock_gen';
|
|
3
4
|
export { BasicTestActionTriggerMock } from './capabilities/internal/actionandtrigger/v1/basic_test_action_trigger_mock_gen';
|
|
4
5
|
export { BasicTestActionMock } from './capabilities/internal/basicaction/v1/basic_test_action_mock_gen';
|
|
5
6
|
export { ConsensusMock } from './capabilities/internal/consensus/v1alpha/consensus_mock_gen';
|
|
@@ -143,6 +143,9 @@ function createTestRuntimeHelpers(registry, secrets, testWriter, state, _maxResp
|
|
|
143
143
|
function now() {
|
|
144
144
|
return state.timeProvider ? state.timeProvider() : Date.now();
|
|
145
145
|
}
|
|
146
|
+
function sleep(ms) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
146
149
|
return {
|
|
147
150
|
call(request) {
|
|
148
151
|
const handler = registry.get(request.id);
|
|
@@ -232,6 +235,7 @@ function createTestRuntimeHelpers(registry, secrets, testWriter, state, _maxResp
|
|
|
232
235
|
},
|
|
233
236
|
switchModes(_mode) { },
|
|
234
237
|
now,
|
|
238
|
+
sleep,
|
|
235
239
|
log(message) {
|
|
236
240
|
testWriter.log(message);
|
|
237
241
|
},
|
|
@@ -287,7 +291,11 @@ export function newTestRuntime(secrets, options = {}) {
|
|
|
287
291
|
const state = {
|
|
288
292
|
timeProvider: options.timeProvider,
|
|
289
293
|
};
|
|
290
|
-
const
|
|
294
|
+
const configuredMaxResponseSize = options.maxResponseSize ?? DEFAULT_MAX_RESPONSE_SIZE_BYTES;
|
|
295
|
+
if (!Number.isSafeInteger(configuredMaxResponseSize) || configuredMaxResponseSize < 0) {
|
|
296
|
+
throw new Error('newTestRuntime maxResponseSize must be a non-negative safe integer number');
|
|
297
|
+
}
|
|
298
|
+
const maxResponseSize = BigInt(configuredMaxResponseSize);
|
|
291
299
|
const helpers = createTestRuntimeHelpers(registry, secretsMap, testWriter, state, maxResponseSize);
|
|
292
300
|
return new TestRuntime(helpers, maxResponseSize, testWriter, state);
|
|
293
301
|
}
|
|
@@ -2,6 +2,7 @@ import { create, toJson } from '@bufbuild/protobuf';
|
|
|
2
2
|
import { BigIntSchema } from '../../../../generated/values/v1/values_pb';
|
|
3
3
|
import { EVMClient } from '../../../cre';
|
|
4
4
|
import { bigintToBytes, bytesToBigint, hexToBase64, hexToBytes } from '../../hex-utils';
|
|
5
|
+
import { assertSafeIntegerNumber } from '../../safe-integer';
|
|
5
6
|
/**
|
|
6
7
|
* Converts a native JS bigint to a protobuf BigInt JSON representation.
|
|
7
8
|
* Use this when passing bigint values to SDK methods.
|
|
@@ -16,8 +17,8 @@ import { bigintToBytes, bytesToBigint, hexToBase64, hexToBytes } from '../../hex
|
|
|
16
17
|
* @returns The protobuf BigInt JSON representation.
|
|
17
18
|
*/
|
|
18
19
|
export const bigintToProtoBigInt = (n) => {
|
|
19
|
-
if (typeof n === 'number'
|
|
20
|
-
|
|
20
|
+
if (typeof n === 'number') {
|
|
21
|
+
assertSafeIntegerNumber(n, 'bigintToProtoBigInt');
|
|
21
22
|
}
|
|
22
23
|
const val = BigInt(n);
|
|
23
24
|
const abs = val < 0n ? -val : val;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DurationJson } from '@bufbuild/protobuf/wkt';
|
|
2
|
+
import type { HTTPRequestJson as ConfidentialHTTPRequestJson, HeaderValuesJson } from '../../../../generated/capabilities/networking/confidentialhttp/v1alpha/client_pb';
|
|
3
|
+
/**
|
|
4
|
+
* Build an HTTPRequest JSON shape for the confidential-http capability.
|
|
5
|
+
*
|
|
6
|
+
* The proto defines `oneof body { string body_string = 3; bytes body_bytes = 8 }`,
|
|
7
|
+
* so the JSON wire keys are `bodyString` / `bodyBytes` — never plain `body`.
|
|
8
|
+
* Three mutually-exclusive ways to set the body, in order of preference:
|
|
9
|
+
*
|
|
10
|
+
* - `body` ergonomic; coerces by runtime type:
|
|
11
|
+
* - `string` -> bodyString (verbatim)
|
|
12
|
+
* - `Uint8Array` -> bodyBytes (base64)
|
|
13
|
+
* - object -> JSON.stringify -> bodyString
|
|
14
|
+
* (bigints as strings)
|
|
15
|
+
* - `bodyString` pass-through to the canonical proto field
|
|
16
|
+
* - `bodyBytes` `Uint8Array` is base64-encoded; a `string` is treated as
|
|
17
|
+
* already-encoded base64 and passed through verbatim
|
|
18
|
+
*
|
|
19
|
+
* Supplying more than one of these fields throws — the underlying proto is a
|
|
20
|
+
* oneof, so the call would otherwise be ambiguous.
|
|
21
|
+
*
|
|
22
|
+
* Headers can be passed in two ways:
|
|
23
|
+
* - `headers`: flat record with single or repeated values, mapped onto the
|
|
24
|
+
* `multiHeaders` shape under the hood.
|
|
25
|
+
* - `multiHeaders`: native proto shape `{ [name]: { values: string[] } }` —
|
|
26
|
+
* useful when forwarding headers already in canonical form.
|
|
27
|
+
*
|
|
28
|
+
* If both are supplied, `multiHeaders` is applied first and `headers` entries
|
|
29
|
+
* merge on top per-name (replacing the values list for that name).
|
|
30
|
+
*/
|
|
31
|
+
export interface HttpRequestOptions {
|
|
32
|
+
url: string;
|
|
33
|
+
method?: string;
|
|
34
|
+
body?: string | Uint8Array | object;
|
|
35
|
+
bodyString?: string;
|
|
36
|
+
bodyBytes?: Uint8Array | string;
|
|
37
|
+
headers?: Record<string, string | string[]>;
|
|
38
|
+
multiHeaders?: Record<string, HeaderValuesJson>;
|
|
39
|
+
templateValues?: Record<string, string>;
|
|
40
|
+
timeout?: DurationJson;
|
|
41
|
+
encryptOutput?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare function httpRequest(opts: HttpRequestOptions): ConfidentialHTTPRequestJson;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function httpRequest(opts) {
|
|
2
|
+
const out = {
|
|
3
|
+
url: opts.url,
|
|
4
|
+
method: opts.method ?? 'GET',
|
|
5
|
+
};
|
|
6
|
+
const bodyFieldsSet = (opts.body !== undefined ? 1 : 0) +
|
|
7
|
+
(opts.bodyString !== undefined ? 1 : 0) +
|
|
8
|
+
(opts.bodyBytes !== undefined ? 1 : 0);
|
|
9
|
+
if (bodyFieldsSet > 1) {
|
|
10
|
+
throw new Error('httpRequest: specify the request body using only one of: body, bodyString or bodyBytes');
|
|
11
|
+
}
|
|
12
|
+
if (opts.bodyString !== undefined) {
|
|
13
|
+
out.bodyString = opts.bodyString;
|
|
14
|
+
}
|
|
15
|
+
else if (opts.bodyBytes !== undefined) {
|
|
16
|
+
out.bodyBytes =
|
|
17
|
+
typeof opts.bodyBytes === 'string'
|
|
18
|
+
? opts.bodyBytes
|
|
19
|
+
: Buffer.from(opts.bodyBytes).toString('base64');
|
|
20
|
+
}
|
|
21
|
+
else if (typeof opts.body === 'string') {
|
|
22
|
+
out.bodyString = opts.body;
|
|
23
|
+
}
|
|
24
|
+
else if (opts.body instanceof Uint8Array) {
|
|
25
|
+
out.bodyBytes = Buffer.from(opts.body).toString('base64');
|
|
26
|
+
}
|
|
27
|
+
else if (opts.body !== undefined) {
|
|
28
|
+
// Compact JSON encoding; bigints serialise as strings.
|
|
29
|
+
try {
|
|
30
|
+
out.bodyString = JSON.stringify(opts.body, (_k, v) => typeof v === 'bigint' ? v.toString() : v);
|
|
31
|
+
}
|
|
32
|
+
catch (cause) {
|
|
33
|
+
throw new Error('httpRequest: failed to serialize body as JSON', {
|
|
34
|
+
cause,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (opts.multiHeaders || opts.headers) {
|
|
39
|
+
const merged = {};
|
|
40
|
+
for (const [name, value] of Object.entries(opts.multiHeaders ?? {})) {
|
|
41
|
+
merged[name] = { values: value.values ?? [] };
|
|
42
|
+
}
|
|
43
|
+
for (const [name, value] of Object.entries(opts.headers ?? {})) {
|
|
44
|
+
merged[name] = { values: Array.isArray(value) ? value : [value] };
|
|
45
|
+
}
|
|
46
|
+
out.multiHeaders = merged;
|
|
47
|
+
}
|
|
48
|
+
if (opts.templateValues) {
|
|
49
|
+
out.templatePublicValues = { ...opts.templateValues };
|
|
50
|
+
}
|
|
51
|
+
if (opts.timeout) {
|
|
52
|
+
out.timeout = opts.timeout;
|
|
53
|
+
}
|
|
54
|
+
if (opts.encryptOutput) {
|
|
55
|
+
out.encryptOutput = true;
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
@@ -3,6 +3,7 @@ import type { Request, RequestJson, Response } from '../../../../generated/capab
|
|
|
3
3
|
import type { ReportResponse } from '../../../../generated/sdk/v1alpha/sdk_pb';
|
|
4
4
|
import type { NodeRuntime } from '../../..';
|
|
5
5
|
import type { Report } from '../../../report';
|
|
6
|
+
type HeaderCapableResponse = Response | ConfidentialHTTPResponse;
|
|
6
7
|
/**
|
|
7
8
|
* HTTP Response Helper Functions
|
|
8
9
|
*
|
|
@@ -81,20 +82,32 @@ export declare function json(responseFn: () => {
|
|
|
81
82
|
result: () => unknown;
|
|
82
83
|
};
|
|
83
84
|
/**
|
|
84
|
-
*
|
|
85
|
+
* Returns all values for a header (case-insensitive).
|
|
86
|
+
* Reads `multiHeaders` first; falls back to the deprecated single-value `headers` map.
|
|
85
87
|
* @param response - The Response object
|
|
86
88
|
* @param name - The header name (case-insensitive)
|
|
87
|
-
* @returns
|
|
89
|
+
* @returns Array of header values; empty if not present
|
|
88
90
|
*/
|
|
89
|
-
export declare function
|
|
91
|
+
export declare function getHeaders(response: HeaderCapableResponse, name: string): string[];
|
|
90
92
|
/**
|
|
91
|
-
*
|
|
93
|
+
* Returns all values for a header (case-insensitive).
|
|
94
|
+
* Reads `multiHeaders` first; falls back to the deprecated single-value `headers` map.
|
|
92
95
|
* @param responseFn - Function that returns an object with result function that returns Response
|
|
93
96
|
* @param name - The header name (case-insensitive)
|
|
94
|
-
* @returns Object with result function that returns
|
|
97
|
+
* @returns Object with result function that returns array of header values; empty if not present
|
|
95
98
|
*/
|
|
99
|
+
export declare function getHeaders(responseFn: () => {
|
|
100
|
+
result: HeaderCapableResponse;
|
|
101
|
+
}, name: string): {
|
|
102
|
+
result: () => string[];
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Returns a header value (case-insensitive). Multiple values are joined with `, `;
|
|
106
|
+
* use `getHeaders` when boundaries between values must be preserved.
|
|
107
|
+
*/
|
|
108
|
+
export declare function getHeader(response: HeaderCapableResponse, name: string): string | undefined;
|
|
96
109
|
export declare function getHeader(responseFn: () => {
|
|
97
|
-
result:
|
|
110
|
+
result: HeaderCapableResponse;
|
|
98
111
|
}, name: string): {
|
|
99
112
|
result: () => string | undefined;
|
|
100
113
|
};
|
|
@@ -147,3 +160,4 @@ declare module '../../../../generated-sdk/capabilities/networking/http/v1alpha/c
|
|
|
147
160
|
};
|
|
148
161
|
}
|
|
149
162
|
}
|
|
163
|
+
export {};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { decodeJson } from '../../decode-json';
|
|
2
|
+
function findCaseInsensitive(map, name) {
|
|
3
|
+
if (!map)
|
|
4
|
+
return undefined;
|
|
5
|
+
const lowerName = name.toLowerCase();
|
|
6
|
+
return Object.entries(map).find(([key]) => key.toLowerCase() === lowerName)?.[1];
|
|
7
|
+
}
|
|
2
8
|
export function text(responseOrFn) {
|
|
3
9
|
if (typeof responseOrFn === 'function') {
|
|
4
10
|
return {
|
|
@@ -18,16 +24,27 @@ export function json(responseOrFn) {
|
|
|
18
24
|
}
|
|
19
25
|
return decodeJson(responseOrFn.body);
|
|
20
26
|
}
|
|
27
|
+
export function getHeaders(responseOrFn, name) {
|
|
28
|
+
if (typeof responseOrFn === 'function') {
|
|
29
|
+
return {
|
|
30
|
+
result: () => getHeaders(responseOrFn().result, name),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const multiHeader = findCaseInsensitive(responseOrFn.multiHeaders, name);
|
|
34
|
+
if (multiHeader) {
|
|
35
|
+
return [...multiHeader.values];
|
|
36
|
+
}
|
|
37
|
+
const singleHeader = findCaseInsensitive('headers' in responseOrFn ? responseOrFn.headers : undefined, name);
|
|
38
|
+
return singleHeader === undefined ? [] : [singleHeader];
|
|
39
|
+
}
|
|
21
40
|
export function getHeader(responseOrFn, name) {
|
|
22
41
|
if (typeof responseOrFn === 'function') {
|
|
23
42
|
return {
|
|
24
43
|
result: () => getHeader(responseOrFn().result, name),
|
|
25
44
|
};
|
|
26
45
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return Object.entries(responseOrFn.headers).find(([key]) => key.toLowerCase() === lowerName)?.[1];
|
|
30
|
-
}
|
|
46
|
+
const values = getHeaders(responseOrFn, name);
|
|
47
|
+
return values.length === 0 ? undefined : values.join(', ');
|
|
31
48
|
}
|
|
32
49
|
export function ok(responseOrFn) {
|
|
33
50
|
if (typeof responseOrFn === 'function') {
|
|
@@ -56,6 +73,7 @@ export function ok(responseOrFn) {
|
|
|
56
73
|
function sendReport(runtime, report, fn) {
|
|
57
74
|
const rawReport = report.x_generatedCodeOnly_unwrap();
|
|
58
75
|
const request = fn(rawReport);
|
|
76
|
+
// Cast to native overload signature - the impl dispatches on $typeName.
|
|
59
77
|
return this.sendRequest(runtime, request);
|
|
60
78
|
}
|
|
61
79
|
/**
|
|
@@ -71,6 +89,7 @@ function sendReport(runtime, report, fn) {
|
|
|
71
89
|
function sendRequesterSendReport(report, fn) {
|
|
72
90
|
const rawReport = report.x_generatedCodeOnly_unwrap();
|
|
73
91
|
const request = fn(rawReport);
|
|
92
|
+
// Cast to native overload signature - the impl dispatches on $typeName.
|
|
74
93
|
return this.sendRequest(request);
|
|
75
94
|
}
|
|
76
95
|
// ============================================================================
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates that a JS `number` represents a safe integer.
|
|
3
|
+
*
|
|
4
|
+
* The two failure modes are kept distinct so callers can tell apart
|
|
5
|
+
* "not an integer at all" (e.g. `1.5`, `NaN`) from "outside Number's safe
|
|
6
|
+
* integer range" (e.g. `2 ** 54`), which require different remediation.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assertSafeIntegerNumber(value: number, label: string): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates that a JS `number` represents a safe integer.
|
|
3
|
+
*
|
|
4
|
+
* The two failure modes are kept distinct so callers can tell apart
|
|
5
|
+
* "not an integer at all" (e.g. `1.5`, `NaN`) from "outside Number's safe
|
|
6
|
+
* integer range" (e.g. `2 ** 54`), which require different remediation.
|
|
7
|
+
*/
|
|
8
|
+
export function assertSafeIntegerNumber(value, label) {
|
|
9
|
+
if (!Number.isFinite(value) || !Number.isInteger(value)) {
|
|
10
|
+
throw new Error(`${label} requires an integer number, received ${value}`);
|
|
11
|
+
}
|
|
12
|
+
if (!Number.isSafeInteger(value)) {
|
|
13
|
+
throw new Error(`${label} requires a safe integer number, received ${value}. Pass a bigint or string for larger values`);
|
|
14
|
+
}
|
|
15
|
+
}
|