@chainlink/cre-sdk 0.0.1-alpha → 0.0.2-alpha
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/internal/nodeaction/v1/node_action_pb.d.ts +69 -0
- package/dist/generated/capabilities/internal/nodeaction/v1/node_action_pb.js +29 -0
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +13 -18
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +71 -260
- package/dist/generated-sdk/capabilities/internal/actionandtrigger/v1/basic_sdk_gen.d.ts +4 -9
- package/dist/generated-sdk/capabilities/internal/actionandtrigger/v1/basic_sdk_gen.js +14 -45
- package/dist/generated-sdk/capabilities/internal/basicaction/v1/basicaction_sdk_gen.d.ts +3 -7
- package/dist/generated-sdk/capabilities/internal/basicaction/v1/basicaction_sdk_gen.js +9 -36
- package/dist/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen.d.ts +2 -8
- package/dist/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen.js +8 -21
- package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.d.ts +5 -8
- package/dist/generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen.js +16 -60
- package/dist/generated-sdk/capabilities/internal/nodeaction/v1/basicaction_sdk_gen.d.ts +19 -0
- package/dist/generated-sdk/capabilities/internal/nodeaction/v1/basicaction_sdk_gen.js +36 -0
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.d.ts +3 -7
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/client_sdk_gen.js +9 -36
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.d.ts +2 -8
- package/dist/generated-sdk/capabilities/networking/http/v1alpha/http_sdk_gen.js +8 -21
- package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.d.ts +2 -8
- package/dist/generated-sdk/capabilities/scheduler/cron/v1/cron_sdk_gen.js +8 -21
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/sdk/cre/index.d.ts +5 -19
- package/dist/sdk/cre/index.js +1 -17
- package/dist/sdk/errors.d.ts +12 -0
- package/dist/sdk/errors.js +21 -0
- package/dist/sdk/impl/runtime-impl.d.ts +38 -0
- package/dist/sdk/impl/runtime-impl.js +190 -0
- package/dist/sdk/impl/runtime-impl.test.js +334 -0
- package/dist/sdk/index.d.ts +3 -0
- package/dist/sdk/index.js +2 -0
- package/dist/sdk/runtime.d.ts +24 -0
- package/dist/sdk/utils/capabilities/capability-error.d.ts +0 -3
- package/dist/sdk/utils/capabilities/capability-error.js +0 -2
- package/dist/sdk/utils/config/configHandler.test.d.ts +1 -0
- package/dist/sdk/utils/config/configHandler.test.js +193 -0
- package/dist/sdk/utils/config/index.d.ts +4 -6
- package/dist/sdk/utils/config/index.js +10 -34
- package/dist/sdk/utils/index.d.ts +0 -3
- package/dist/sdk/utils/index.js +0 -3
- package/dist/sdk/utils/values/consensus_aggregators.d.ts +1 -1
- package/dist/sdk/{runtime → wasm}/host-bindings.d.ts +0 -1
- package/dist/sdk/{runtime → wasm}/host-bindings.js +0 -4
- package/dist/sdk/wasm/index.d.ts +1 -0
- package/dist/sdk/wasm/index.js +1 -0
- package/dist/sdk/wasm/runner.d.ts +14 -0
- package/dist/sdk/wasm/runner.js +114 -0
- package/dist/sdk/wasm/runner.test.d.ts +1 -0
- package/dist/sdk/wasm/runner.test.js +270 -0
- package/dist/sdk/wasm/runtime.d.ts +7 -0
- package/dist/sdk/wasm/runtime.js +55 -0
- package/dist/sdk/workflow.d.ts +13 -15
- package/dist/sdk/workflow.js +1 -21
- package/package.json +2 -2
- package/dist/sdk/engine/execute.d.ts +0 -4
- package/dist/sdk/engine/execute.js +0 -12
- package/dist/sdk/engine/execute.test.js +0 -129
- package/dist/sdk/engine/handleExecutionPhase.d.ts +0 -4
- package/dist/sdk/engine/handleExecutionPhase.js +0 -34
- package/dist/sdk/engine/handleSubscribePhase.d.ts +0 -3
- package/dist/sdk/engine/handleSubscribePhase.js +0 -23
- package/dist/sdk/logger.d.ts +0 -7
- package/dist/sdk/logger.js +0 -18
- package/dist/sdk/runtime/errors.d.ts +0 -23
- package/dist/sdk/runtime/errors.js +0 -30
- package/dist/sdk/runtime/index.d.ts +0 -3
- package/dist/sdk/runtime/index.js +0 -2
- package/dist/sdk/runtime/run-in-node-mode.d.ts +0 -12
- package/dist/sdk/runtime/run-in-node-mode.js +0 -47
- package/dist/sdk/runtime/run-in-node-mode.test.js +0 -116
- package/dist/sdk/runtime/runtime.d.ts +0 -36
- package/dist/sdk/runtime/runtime.js +0 -84
- package/dist/sdk/runtime/runtime.test.d.ts +0 -1
- package/dist/sdk/runtime/runtime.test.js +0 -58
- package/dist/sdk/testhelpers/dangerously-call-capability.d.ts +0 -10
- package/dist/sdk/testhelpers/dangerously-call-capability.js +0 -26
- package/dist/sdk/testhelpers/mock-host-bindings.d.ts +0 -15
- package/dist/sdk/testhelpers/mock-host-bindings.js +0 -25
- package/dist/sdk/testhelpers/mock-runtime.d.ts +0 -2
- package/dist/sdk/testhelpers/mock-runtime.js +0 -16
- package/dist/sdk/utils/await-async-request.d.ts +0 -9
- package/dist/sdk/utils/await-async-request.js +0 -27
- package/dist/sdk/utils/capabilities/call-capability.d.ts +0 -22
- package/dist/sdk/utils/capabilities/call-capability.js +0 -33
- package/dist/sdk/utils/capabilities/callback-id.d.ts +0 -3
- package/dist/sdk/utils/capabilities/callback-id.js +0 -22
- package/dist/sdk/utils/capabilities/http/fetch.d.ts +0 -44
- package/dist/sdk/utils/capabilities/http/fetch.js +0 -63
- package/dist/sdk/utils/do-request-async.d.ts +0 -12
- package/dist/sdk/utils/do-request-async.js +0 -17
- package/dist/sdk/utils/error-boundary.d.ts +0 -2
- package/dist/sdk/utils/error-boundary.js +0 -30
- package/dist/sdk/utils/get-request.d.ts +0 -1
- package/dist/sdk/utils/get-request.js +0 -15
- package/dist/sdk/utils/lazy-promise.d.ts +0 -59
- package/dist/sdk/utils/lazy-promise.js +0 -81
- package/dist/sdk/utils/random/get-rand.d.ts +0 -3
- package/dist/sdk/utils/random/get-rand.js +0 -6
- package/dist/sdk/utils/random/random.d.ts +0 -35
- package/dist/sdk/utils/random/random.js +0 -123
- package/dist/sdk/utils/secrets/await-async-secret.d.ts +0 -1
- package/dist/sdk/utils/secrets/await-async-secret.js +0 -29
- package/dist/sdk/utils/secrets/do-get-secret.d.ts +0 -1
- package/dist/sdk/utils/secrets/do-get-secret.js +0 -14
- package/dist/sdk/utils/secrets/get-secret.d.ts +0 -1
- package/dist/sdk/utils/secrets/get-secret.js +0 -10
- package/dist/sdk/utils/send-error.d.ts +0 -1
- package/dist/sdk/utils/send-error.js +0 -16
- package/dist/sdk/utils/send-response-value.d.ts +0 -2
- package/dist/sdk/utils/send-response-value.js +0 -15
- package/dist/sdk/utils/time/get-time.d.ts +0 -16
- package/dist/sdk/utils/time/get-time.js +0 -21
- /package/dist/sdk/{engine/execute.test.d.ts → impl/runtime-impl.test.d.ts} +0 -0
- /package/dist/sdk/{runtime/run-in-node-mode.test.d.ts → runtime.js} +0 -0
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// Full TypeScript port of Go's math/rand
|
|
2
|
-
// Complete API: Int63, Uint64, Uint32, Int31, Int, Float64, Float32, Int63n, Int31n, Intn, Perm, Seed
|
|
3
|
-
// See: https://cs.opensource.google/go/go/+/refs/tags/go1.22.0:src/math/rand/rand.go
|
|
4
|
-
export class Source {
|
|
5
|
-
s0 = 0n;
|
|
6
|
-
s1 = 0n;
|
|
7
|
-
constructor(seed) {
|
|
8
|
-
this.Seed(seed);
|
|
9
|
-
}
|
|
10
|
-
Seed(seed) {
|
|
11
|
-
seed = BigInt.asUintN(64, seed);
|
|
12
|
-
this.s0 = this.splitMix64(seed);
|
|
13
|
-
this.s1 = this.splitMix64(this.s0);
|
|
14
|
-
}
|
|
15
|
-
splitMix64(seed) {
|
|
16
|
-
seed = (seed + 0x9e3779b97f4a7c15n) & 0xffffffffffffffffn;
|
|
17
|
-
let z = seed;
|
|
18
|
-
z = ((z ^ (z >> 30n)) * 0xbf58476d1ce4e5b9n) & 0xffffffffffffffffn;
|
|
19
|
-
z = ((z ^ (z >> 27n)) * 0x94d049bb133111ebn) & 0xffffffffffffffffn;
|
|
20
|
-
return z ^ (z >> 31n);
|
|
21
|
-
}
|
|
22
|
-
next() {
|
|
23
|
-
const s1 = this.s0;
|
|
24
|
-
let s0 = this.s1;
|
|
25
|
-
this.s0 = s0;
|
|
26
|
-
s0 ^= s0 << 23n;
|
|
27
|
-
this.s1 = s0 ^ s1 ^ (s0 >> 17n) ^ (s1 >> 26n);
|
|
28
|
-
return BigInt.asUintN(64, this.s1 + s1);
|
|
29
|
-
}
|
|
30
|
-
Int63() {
|
|
31
|
-
return this.next() & 0x7fffffffffffffffn;
|
|
32
|
-
}
|
|
33
|
-
Uint32() {
|
|
34
|
-
return Number(this.next() >> 32n) >>> 0;
|
|
35
|
-
}
|
|
36
|
-
Uint64() {
|
|
37
|
-
return this.next();
|
|
38
|
-
}
|
|
39
|
-
Int31() {
|
|
40
|
-
return Number(this.Int63() >> 32n);
|
|
41
|
-
}
|
|
42
|
-
Float64() {
|
|
43
|
-
// Use top 53 bits like Go's implementation: Int63() >> 11
|
|
44
|
-
return Number(this.Int63() >> 11n) * (1.0 / 9007199254740992.0); // 1.0 / (1 << 53)
|
|
45
|
-
}
|
|
46
|
-
Int63n(n) {
|
|
47
|
-
if (n <= 0n)
|
|
48
|
-
throw new Error('invalid argument to Int63n');
|
|
49
|
-
const max = (1n << 63n) - ((1n << 63n) % n);
|
|
50
|
-
let v;
|
|
51
|
-
do {
|
|
52
|
-
v = this.Int63();
|
|
53
|
-
} while (v >= max);
|
|
54
|
-
return v % n;
|
|
55
|
-
}
|
|
56
|
-
Int31n(n) {
|
|
57
|
-
if (n <= 0)
|
|
58
|
-
throw new Error('invalid argument to Int31n');
|
|
59
|
-
return Number(this.Int63n(BigInt(n)));
|
|
60
|
-
}
|
|
61
|
-
Intn(n) {
|
|
62
|
-
return this.Int31n(n);
|
|
63
|
-
}
|
|
64
|
-
Int() {
|
|
65
|
-
return Number(this.Int63() >> 32n);
|
|
66
|
-
}
|
|
67
|
-
Float32() {
|
|
68
|
-
// Use top 24 bits for float32 precision
|
|
69
|
-
return Number(this.Int63() >> 40n) * (1.0 / 8388608.0); // 1.0 / (1 << 23)
|
|
70
|
-
}
|
|
71
|
-
Perm(n) {
|
|
72
|
-
const m = new Array(n);
|
|
73
|
-
for (let i = 0; i < n; i++)
|
|
74
|
-
m[i] = i;
|
|
75
|
-
for (let i = 1; i < n; i++) {
|
|
76
|
-
const j = Number(this.Int63n(BigInt(i + 1)));
|
|
77
|
-
[m[i], m[j]] = [m[j], m[i]];
|
|
78
|
-
}
|
|
79
|
-
return m;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export class Rand {
|
|
83
|
-
src;
|
|
84
|
-
constructor(seed) {
|
|
85
|
-
this.src = new Source(seed);
|
|
86
|
-
}
|
|
87
|
-
Float64() {
|
|
88
|
-
return this.src.Float64();
|
|
89
|
-
}
|
|
90
|
-
Float32() {
|
|
91
|
-
return this.src.Float32();
|
|
92
|
-
}
|
|
93
|
-
Int63() {
|
|
94
|
-
return this.src.Int63();
|
|
95
|
-
}
|
|
96
|
-
Int63n(n) {
|
|
97
|
-
return this.src.Int63n(n);
|
|
98
|
-
}
|
|
99
|
-
Int31() {
|
|
100
|
-
return this.src.Int31();
|
|
101
|
-
}
|
|
102
|
-
Int31n(n) {
|
|
103
|
-
return this.src.Int31n(n);
|
|
104
|
-
}
|
|
105
|
-
Int() {
|
|
106
|
-
return this.src.Int();
|
|
107
|
-
}
|
|
108
|
-
Intn(n) {
|
|
109
|
-
return this.src.Intn(n);
|
|
110
|
-
}
|
|
111
|
-
Uint32() {
|
|
112
|
-
return this.src.Uint32();
|
|
113
|
-
}
|
|
114
|
-
Uint64() {
|
|
115
|
-
return this.src.Uint64();
|
|
116
|
-
}
|
|
117
|
-
Perm(n) {
|
|
118
|
-
return this.src.Perm(n);
|
|
119
|
-
}
|
|
120
|
-
Seed(seed) {
|
|
121
|
-
this.src.Seed(seed);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const awaitAsyncSecret: (callbackId: number) => Promise<string>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { create, fromBinary, toBinary } from '@bufbuild/protobuf';
|
|
2
|
-
import { AwaitSecretsRequestSchema, AwaitSecretsResponseSchema, } from '../../../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
-
import { SecretsError } from '../secrets-error';
|
|
4
|
-
export const awaitAsyncSecret = async (callbackId) => {
|
|
5
|
-
// Create proper AwaitSecretsRequest protobuf message
|
|
6
|
-
const awaitSecretRequest = create(AwaitSecretsRequestSchema, {
|
|
7
|
-
ids: [callbackId],
|
|
8
|
-
});
|
|
9
|
-
// Encode to protobuf bytes
|
|
10
|
-
const awaitSecretRequestBytes = toBinary(AwaitSecretsRequestSchema, awaitSecretRequest);
|
|
11
|
-
const response = awaitSecrets(awaitSecretRequestBytes, 1024 * 1024);
|
|
12
|
-
// Convert array of numbers to Uint8Array if needed
|
|
13
|
-
const responseBytes = Array.isArray(response) ? new Uint8Array(response) : response;
|
|
14
|
-
// Decode as AwaitSecretsResponse first
|
|
15
|
-
const awaitResponse = fromBinary(AwaitSecretsResponseSchema, responseBytes);
|
|
16
|
-
// Get the specific secretId response for our callback ID
|
|
17
|
-
const secretResponses = awaitResponse.responses[callbackId];
|
|
18
|
-
if (!secretResponses || !secretResponses.responses.length) {
|
|
19
|
-
throw new Error(`No response found for callback ID ${callbackId}`);
|
|
20
|
-
}
|
|
21
|
-
const secretResponse = secretResponses.responses[0];
|
|
22
|
-
if (secretResponse.response.case === 'secret') {
|
|
23
|
-
return secretResponse.response.value.value;
|
|
24
|
-
}
|
|
25
|
-
if (secretResponse.response.case === 'error') {
|
|
26
|
-
throw new SecretsError(secretResponse.response.value.error);
|
|
27
|
-
}
|
|
28
|
-
throw new Error(`No secret found for callback ID ${callbackId}`);
|
|
29
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const doGetSecret: (id: string) => number;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { create, toBinary } from '@bufbuild/protobuf';
|
|
2
|
-
import { GetSecretsRequestSchema, Mode } from '../../../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
-
import { hostBindings } from '../../runtime/host-bindings';
|
|
4
|
-
import { getLastCallbackId, incrementCallbackId } from '../capabilities/callback-id';
|
|
5
|
-
export const doGetSecret = (id) => {
|
|
6
|
-
const callbackId = getLastCallbackId(Mode.DON);
|
|
7
|
-
incrementCallbackId(Mode.DON);
|
|
8
|
-
const request = create(GetSecretsRequestSchema, {
|
|
9
|
-
requests: [{ id }],
|
|
10
|
-
callbackId,
|
|
11
|
-
});
|
|
12
|
-
const result = hostBindings.getSecrets(toBinary(GetSecretsRequestSchema, request), 1024 * 1024);
|
|
13
|
-
return callbackId;
|
|
14
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getSecret: (id: string) => Promise<any>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { runtimeGuards } from '../../runtime/runtime';
|
|
2
|
-
import { LazyPromise } from '../lazy-promise';
|
|
3
|
-
import { awaitAsyncSecret } from './await-async-secret';
|
|
4
|
-
import { doGetSecret } from './do-get-secret';
|
|
5
|
-
export const getSecret = (id) => {
|
|
6
|
-
// Getting secrets should only be possible in DON mode
|
|
7
|
-
runtimeGuards.assertDonSafe();
|
|
8
|
-
const callbackId = doGetSecret(id);
|
|
9
|
-
return new LazyPromise(async () => awaitAsyncSecret(callbackId));
|
|
10
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const sendError: (error: string | Error) => void;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { create, toBinary } from '@bufbuild/protobuf';
|
|
2
|
-
import { ExecutionResultSchema } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
-
import { hostBindings } from '../runtime/host-bindings';
|
|
4
|
-
export const sendError = (error) => {
|
|
5
|
-
// Create ExecutionResult with error
|
|
6
|
-
const execResult = create(ExecutionResultSchema, {
|
|
7
|
-
result: {
|
|
8
|
-
case: 'error',
|
|
9
|
-
value: error instanceof Error ? error.message : error,
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
// Marshal to protobuf bytes
|
|
13
|
-
const encoded = toBinary(ExecutionResultSchema, execResult);
|
|
14
|
-
// Send the result
|
|
15
|
-
hostBindings.sendResponse(encoded);
|
|
16
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { create, toBinary } from '@bufbuild/protobuf';
|
|
2
|
-
import { ExecutionResultSchema } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
3
|
-
export const sendResponseValue = (value) => {
|
|
4
|
-
// Insert into the correct oneof field: 'payload'
|
|
5
|
-
const execResult = create(ExecutionResultSchema, {
|
|
6
|
-
result: {
|
|
7
|
-
case: 'value',
|
|
8
|
-
value: value.proto(),
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
// Marshal to protobuf bytes
|
|
12
|
-
const encoded = toBinary(ExecutionResultSchema, execResult);
|
|
13
|
-
// Send the result
|
|
14
|
-
sendResponse(encoded);
|
|
15
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gets the current time from the host runtime
|
|
3
|
-
* This function calls the host's `now` function which respects the current mode
|
|
4
|
-
* (DON or NODE) and calls the appropriate time function on the host.
|
|
5
|
-
*
|
|
6
|
-
* The Rust plugin handles all the low-level WASM memory management internally,
|
|
7
|
-
* so we just get a clean Unix timestamp in milliseconds.
|
|
8
|
-
*
|
|
9
|
-
* @returns The current time as a Unix timestamp in milliseconds
|
|
10
|
-
*/
|
|
11
|
-
export declare const getTime: () => number;
|
|
12
|
-
/**
|
|
13
|
-
* Gets the current time as a Date object
|
|
14
|
-
* @returns The current time as a Date object
|
|
15
|
-
*/
|
|
16
|
-
export declare const getTimeAsDate: () => Date;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { hostBindings } from '../../runtime/host-bindings';
|
|
2
|
-
/**
|
|
3
|
-
* Gets the current time from the host runtime
|
|
4
|
-
* This function calls the host's `now` function which respects the current mode
|
|
5
|
-
* (DON or NODE) and calls the appropriate time function on the host.
|
|
6
|
-
*
|
|
7
|
-
* The Rust plugin handles all the low-level WASM memory management internally,
|
|
8
|
-
* so we just get a clean Unix timestamp in milliseconds.
|
|
9
|
-
*
|
|
10
|
-
* @returns The current time as a Unix timestamp in milliseconds
|
|
11
|
-
*/
|
|
12
|
-
export const getTime = () => {
|
|
13
|
-
return hostBindings.now();
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Gets the current time as a Date object
|
|
17
|
-
* @returns The current time as a Date object
|
|
18
|
-
*/
|
|
19
|
-
export const getTimeAsDate = () => {
|
|
20
|
-
return new Date(getTime());
|
|
21
|
-
};
|
|
File without changes
|
|
File without changes
|