@silvana-one/agent 1.0.32
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/LICENSE +201 -0
- package/dist/node/grpc.d.ts +128 -0
- package/dist/node/grpc.js +520 -0
- package/dist/node/grpc.js.map +1 -0
- package/dist/node/index.cjs +527 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +2 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/proto/silvana/coordinator/v1/coordinator_pb.d.ts +1990 -0
- package/dist/node/proto/silvana/coordinator/v1/coordinator_pb.js +306 -0
- package/dist/node/proto/silvana/coordinator/v1/coordinator_pb.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/tsconfig.web.tsbuildinfo +1 -0
- package/dist/web/grpc.d.ts +128 -0
- package/dist/web/grpc.js +520 -0
- package/dist/web/grpc.js.map +1 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +2 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/proto/silvana/coordinator/v1/coordinator_pb.d.ts +1990 -0
- package/dist/web/proto/silvana/coordinator/v1/coordinator_pb.js +306 -0
- package/dist/web/proto/silvana/coordinator/v1/coordinator_pb.js.map +1 -0
- package/package.json +65 -0
- package/src/grpc.ts +762 -0
- package/src/index.ts +1 -0
- package/src/proto/silvana/coordinator/v1/coordinator_pb.ts +2364 -0
package/src/grpc.ts
ADDED
|
@@ -0,0 +1,762 @@
|
|
|
1
|
+
import { createGrpcTransport } from "@connectrpc/connect-node";
|
|
2
|
+
import { createClient } from "@connectrpc/connect";
|
|
3
|
+
import {
|
|
4
|
+
CoordinatorService,
|
|
5
|
+
RetrieveSecretRequestSchema,
|
|
6
|
+
GetJobRequestSchema,
|
|
7
|
+
CompleteJobRequestSchema,
|
|
8
|
+
FailJobRequestSchema,
|
|
9
|
+
GetSequenceStatesRequestSchema,
|
|
10
|
+
SubmitProofRequestSchema,
|
|
11
|
+
SubmitStateRequestSchema,
|
|
12
|
+
GetProofRequestSchema,
|
|
13
|
+
GetBlockProofRequestSchema,
|
|
14
|
+
GetBlockRequestSchema,
|
|
15
|
+
GetBlockSettlementRequestSchema,
|
|
16
|
+
UpdateBlockSettlementRequestSchema,
|
|
17
|
+
TerminateJobRequestSchema,
|
|
18
|
+
ReadDataAvailabilityRequestSchema,
|
|
19
|
+
SetKVRequestSchema,
|
|
20
|
+
GetKVRequestSchema,
|
|
21
|
+
DeleteKVRequestSchema,
|
|
22
|
+
AddMetadataRequestSchema,
|
|
23
|
+
GetMetadataRequestSchema,
|
|
24
|
+
TryCreateBlockRequestSchema,
|
|
25
|
+
UpdateBlockStateDataAvailabilityRequestSchema,
|
|
26
|
+
UpdateBlockProofDataAvailabilityRequestSchema,
|
|
27
|
+
UpdateBlockSettlementTxHashRequestSchema,
|
|
28
|
+
UpdateBlockSettlementTxIncludedInBlockRequestSchema,
|
|
29
|
+
CreateAppJobRequestSchema,
|
|
30
|
+
RejectProofRequestSchema,
|
|
31
|
+
type GetJobResponse,
|
|
32
|
+
type CompleteJobResponse,
|
|
33
|
+
type FailJobResponse,
|
|
34
|
+
type TerminateJobResponse,
|
|
35
|
+
type GetSequenceStatesResponse,
|
|
36
|
+
type SubmitProofResponse,
|
|
37
|
+
type SubmitStateResponse,
|
|
38
|
+
type GetProofResponse,
|
|
39
|
+
type GetBlockProofResponse,
|
|
40
|
+
type GetBlockResponse,
|
|
41
|
+
type GetBlockSettlementResponse,
|
|
42
|
+
type UpdateBlockSettlementResponse,
|
|
43
|
+
type Block,
|
|
44
|
+
type BlockSettlement,
|
|
45
|
+
type Metadata,
|
|
46
|
+
type ReadDataAvailabilityResponse,
|
|
47
|
+
type RetrieveSecretResponse,
|
|
48
|
+
type SetKVResponse,
|
|
49
|
+
type GetKVResponse,
|
|
50
|
+
type DeleteKVResponse,
|
|
51
|
+
type AddMetadataResponse,
|
|
52
|
+
type GetMetadataResponse,
|
|
53
|
+
type TryCreateBlockResponse,
|
|
54
|
+
type UpdateBlockStateDataAvailabilityResponse,
|
|
55
|
+
type UpdateBlockProofDataAvailabilityResponse,
|
|
56
|
+
type UpdateBlockSettlementTxHashResponse,
|
|
57
|
+
type UpdateBlockSettlementTxIncludedInBlockResponse,
|
|
58
|
+
type CreateAppJobResponse,
|
|
59
|
+
type RejectProofResponse,
|
|
60
|
+
} from "./proto/silvana/coordinator/v1/coordinator_pb.js";
|
|
61
|
+
import { create } from "@bufbuild/protobuf";
|
|
62
|
+
|
|
63
|
+
// Static client instance to be reused
|
|
64
|
+
let coordinatorClient: ReturnType<
|
|
65
|
+
typeof createClient<typeof CoordinatorService>
|
|
66
|
+
> | null = null;
|
|
67
|
+
|
|
68
|
+
// Environment variables - cached after first initialization
|
|
69
|
+
let sessionId: string | null = null;
|
|
70
|
+
let jobId: string | null = null;
|
|
71
|
+
let chain: string | null = null;
|
|
72
|
+
let coordinatorId: string | null = null;
|
|
73
|
+
let sessionPrivateKey: string | null = null;
|
|
74
|
+
let developer: string | null = null;
|
|
75
|
+
let agent: string | null = null;
|
|
76
|
+
let agentMethod: string | null = null;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Gets the coordinator client instance and environment variables, initializing if necessary
|
|
80
|
+
* @returns Object containing the client and all required environment variables
|
|
81
|
+
*/
|
|
82
|
+
function getCoordinatorClient(): {
|
|
83
|
+
client: ReturnType<typeof createClient<typeof CoordinatorService>>;
|
|
84
|
+
sessionId: string;
|
|
85
|
+
chain: string;
|
|
86
|
+
coordinatorId: string;
|
|
87
|
+
sessionPrivateKey: string;
|
|
88
|
+
developer: string;
|
|
89
|
+
agent: string;
|
|
90
|
+
agentMethod: string;
|
|
91
|
+
} {
|
|
92
|
+
if (coordinatorClient === null) {
|
|
93
|
+
// Read all environment variables
|
|
94
|
+
sessionId = process.env.SESSION_ID || null;
|
|
95
|
+
chain = process.env.CHAIN || null;
|
|
96
|
+
coordinatorId = process.env.COORDINATOR_ID || null;
|
|
97
|
+
sessionPrivateKey = process.env.SESSION_PRIVATE_KEY || null;
|
|
98
|
+
developer = process.env.DEVELOPER || null;
|
|
99
|
+
agent = process.env.AGENT || null;
|
|
100
|
+
agentMethod = process.env.AGENT_METHOD || null;
|
|
101
|
+
|
|
102
|
+
// Check for required environment variables
|
|
103
|
+
if (!sessionId) {
|
|
104
|
+
throw new Error("SESSION_ID environment variable is required");
|
|
105
|
+
}
|
|
106
|
+
// if (!chain) {
|
|
107
|
+
// throw new Error("CHAIN environment variable is required");
|
|
108
|
+
// }
|
|
109
|
+
// if (!coordinatorId) {
|
|
110
|
+
// throw new Error("COORDINATOR_ID environment variable is required");
|
|
111
|
+
// }
|
|
112
|
+
// if (!sessionPrivateKey) {
|
|
113
|
+
// throw new Error("SESSION_PRIVATE_KEY environment variable is required");
|
|
114
|
+
// }
|
|
115
|
+
if (!developer) {
|
|
116
|
+
throw new Error("DEVELOPER environment variable is required");
|
|
117
|
+
}
|
|
118
|
+
if (!agent) {
|
|
119
|
+
throw new Error("AGENT environment variable is required");
|
|
120
|
+
}
|
|
121
|
+
if (!agentMethod) {
|
|
122
|
+
throw new Error("AGENT_METHOD environment variable is required");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Create gRPC client over TCP (accessible from Docker container)
|
|
126
|
+
const transport = createGrpcTransport({
|
|
127
|
+
baseUrl: "http://host.docker.internal:50051",
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
coordinatorClient = createClient(CoordinatorService, transport);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// At this point, all values are guaranteed to be non-null due to the checks above
|
|
134
|
+
return {
|
|
135
|
+
client: coordinatorClient as ReturnType<
|
|
136
|
+
typeof createClient<typeof CoordinatorService>
|
|
137
|
+
>,
|
|
138
|
+
sessionId: sessionId as string,
|
|
139
|
+
chain: chain as string,
|
|
140
|
+
coordinatorId: coordinatorId as string,
|
|
141
|
+
sessionPrivateKey: sessionPrivateKey as string,
|
|
142
|
+
developer: developer as string,
|
|
143
|
+
agent: agent as string,
|
|
144
|
+
agentMethod: agentMethod as string,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Retrieves a secret value from the coordinator service
|
|
150
|
+
* @param key The name/key of the secret to retrieve
|
|
151
|
+
* @returns The secret value if found, null otherwise
|
|
152
|
+
*/
|
|
153
|
+
export async function getSecret(key: string): Promise<string | null> {
|
|
154
|
+
if (!jobId) {
|
|
155
|
+
throw new Error("Call getJob() first");
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
159
|
+
|
|
160
|
+
// Create the request
|
|
161
|
+
const request = create(RetrieveSecretRequestSchema, {
|
|
162
|
+
jobId: jobId,
|
|
163
|
+
sessionId: sessionId,
|
|
164
|
+
name: key,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
console.log(`Retrieving secret: ${key}`);
|
|
168
|
+
|
|
169
|
+
// Make the gRPC call
|
|
170
|
+
const response = await client.retrieveSecret(request);
|
|
171
|
+
|
|
172
|
+
if (response.success && response.secretValue !== undefined) {
|
|
173
|
+
console.log(` Successfully retrieved secret: ${key}`);
|
|
174
|
+
return response.secretValue;
|
|
175
|
+
} else {
|
|
176
|
+
console.log(`L Failed to retrieve secret: ${key} - ${response.message}`);
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
} catch (error: any) {
|
|
180
|
+
console.error(`Error retrieving secret '${key}':`, error.message);
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Gets a job from the coordinator
|
|
187
|
+
*/
|
|
188
|
+
export async function getJob(): Promise<GetJobResponse> {
|
|
189
|
+
const { client, sessionId, developer, agent, agentMethod } =
|
|
190
|
+
getCoordinatorClient();
|
|
191
|
+
|
|
192
|
+
const request = create(GetJobRequestSchema, {
|
|
193
|
+
developer,
|
|
194
|
+
agent,
|
|
195
|
+
agentMethod,
|
|
196
|
+
sessionId,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const response = await client.getJob(request);
|
|
200
|
+
|
|
201
|
+
if (response.job) {
|
|
202
|
+
jobId = response.job.jobId;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return response;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Completes a job
|
|
210
|
+
*/
|
|
211
|
+
export async function completeJob(): Promise<CompleteJobResponse> {
|
|
212
|
+
if (!jobId) {
|
|
213
|
+
throw new Error("Call getJob() first");
|
|
214
|
+
}
|
|
215
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
216
|
+
|
|
217
|
+
const request = create(CompleteJobRequestSchema, {
|
|
218
|
+
sessionId,
|
|
219
|
+
jobId,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
jobId = null;
|
|
223
|
+
|
|
224
|
+
return await client.completeJob(request);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Fails a job
|
|
229
|
+
*/
|
|
230
|
+
export async function failJob(errorMessage: string): Promise<FailJobResponse> {
|
|
231
|
+
if (!jobId) {
|
|
232
|
+
throw new Error("Call getJob() first");
|
|
233
|
+
}
|
|
234
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
235
|
+
|
|
236
|
+
const request = create(FailJobRequestSchema, {
|
|
237
|
+
sessionId,
|
|
238
|
+
jobId,
|
|
239
|
+
errorMessage,
|
|
240
|
+
});
|
|
241
|
+
jobId = null;
|
|
242
|
+
|
|
243
|
+
return await client.failJob(request);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Terminates a job
|
|
248
|
+
*/
|
|
249
|
+
export async function terminateJob(): Promise<TerminateJobResponse> {
|
|
250
|
+
if (!jobId) {
|
|
251
|
+
throw new Error("Call getJob() first");
|
|
252
|
+
}
|
|
253
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
254
|
+
|
|
255
|
+
const request = create(TerminateJobRequestSchema, {
|
|
256
|
+
sessionId,
|
|
257
|
+
jobId,
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
jobId = null;
|
|
261
|
+
|
|
262
|
+
return await client.terminateJob(request);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Gets sequence states
|
|
267
|
+
*/
|
|
268
|
+
export async function getSequenceStates(
|
|
269
|
+
sequence: bigint
|
|
270
|
+
): Promise<GetSequenceStatesResponse> {
|
|
271
|
+
if (!jobId) {
|
|
272
|
+
throw new Error("Call getJob() first");
|
|
273
|
+
}
|
|
274
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
275
|
+
|
|
276
|
+
const request = create(GetSequenceStatesRequestSchema, {
|
|
277
|
+
sessionId,
|
|
278
|
+
jobId,
|
|
279
|
+
sequence,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
return await client.getSequenceStates(request);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Submits a proof
|
|
287
|
+
*/
|
|
288
|
+
export async function submitProof(
|
|
289
|
+
blockNumber: bigint,
|
|
290
|
+
sequences: bigint[],
|
|
291
|
+
proof: string,
|
|
292
|
+
cpuTime: bigint,
|
|
293
|
+
mergedSequences1?: bigint[],
|
|
294
|
+
mergedSequences2?: bigint[]
|
|
295
|
+
): Promise<SubmitProofResponse> {
|
|
296
|
+
if (!jobId) {
|
|
297
|
+
throw new Error("Call getJob() first");
|
|
298
|
+
}
|
|
299
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
300
|
+
|
|
301
|
+
const request = create(SubmitProofRequestSchema, {
|
|
302
|
+
sessionId,
|
|
303
|
+
jobId,
|
|
304
|
+
blockNumber,
|
|
305
|
+
sequences,
|
|
306
|
+
proof,
|
|
307
|
+
cpuTime,
|
|
308
|
+
mergedSequences1: mergedSequences1 || [],
|
|
309
|
+
mergedSequences2: mergedSequences2 || [],
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
return await client.submitProof(request);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Submits state
|
|
317
|
+
*/
|
|
318
|
+
export async function submitState(
|
|
319
|
+
sequence: bigint,
|
|
320
|
+
newStateData?: Uint8Array,
|
|
321
|
+
serializedState?: string
|
|
322
|
+
): Promise<SubmitStateResponse> {
|
|
323
|
+
if (!jobId) {
|
|
324
|
+
throw new Error("Call getJob() first");
|
|
325
|
+
}
|
|
326
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
327
|
+
|
|
328
|
+
const request = create(SubmitStateRequestSchema, {
|
|
329
|
+
sessionId,
|
|
330
|
+
jobId,
|
|
331
|
+
sequence,
|
|
332
|
+
newStateData,
|
|
333
|
+
serializedState,
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
return await client.submitState(request);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Gets a proof
|
|
341
|
+
*/
|
|
342
|
+
export async function getProof(
|
|
343
|
+
blockNumber: bigint,
|
|
344
|
+
sequences: bigint[]
|
|
345
|
+
): Promise<GetProofResponse> {
|
|
346
|
+
if (!jobId) {
|
|
347
|
+
throw new Error("Call getJob() first");
|
|
348
|
+
}
|
|
349
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
350
|
+
|
|
351
|
+
const request = create(GetProofRequestSchema, {
|
|
352
|
+
sessionId,
|
|
353
|
+
blockNumber,
|
|
354
|
+
sequences,
|
|
355
|
+
jobId,
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
return await client.getProof(request);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Gets a block proof
|
|
363
|
+
*/
|
|
364
|
+
export async function getBlockProof(
|
|
365
|
+
blockNumber: bigint
|
|
366
|
+
): Promise<GetBlockProofResponse> {
|
|
367
|
+
if (!jobId) {
|
|
368
|
+
throw new Error("Call getJob() first");
|
|
369
|
+
}
|
|
370
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
371
|
+
|
|
372
|
+
const request = create(GetBlockProofRequestSchema, {
|
|
373
|
+
sessionId,
|
|
374
|
+
blockNumber,
|
|
375
|
+
jobId,
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
return await client.getBlockProof(request);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Reads data availability
|
|
383
|
+
*/
|
|
384
|
+
export async function readDataAvailability(
|
|
385
|
+
daHash: string
|
|
386
|
+
): Promise<ReadDataAvailabilityResponse> {
|
|
387
|
+
if (!jobId) {
|
|
388
|
+
throw new Error("Call getJob() first");
|
|
389
|
+
}
|
|
390
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
391
|
+
|
|
392
|
+
const request = create(ReadDataAvailabilityRequestSchema, {
|
|
393
|
+
sessionId,
|
|
394
|
+
daHash,
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
return await client.readDataAvailability(request);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Sets a key-value pair in the app instance KV store
|
|
402
|
+
*/
|
|
403
|
+
export async function setKv(
|
|
404
|
+
key: string,
|
|
405
|
+
value: string
|
|
406
|
+
): Promise<SetKVResponse> {
|
|
407
|
+
if (!jobId) {
|
|
408
|
+
throw new Error("Call getJob() first");
|
|
409
|
+
}
|
|
410
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
411
|
+
|
|
412
|
+
const request = create(SetKVRequestSchema, {
|
|
413
|
+
sessionId,
|
|
414
|
+
jobId,
|
|
415
|
+
key,
|
|
416
|
+
value,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
return await client.setKV(request);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Gets a value from the app instance KV store
|
|
424
|
+
*/
|
|
425
|
+
export async function getKv(key: string): Promise<GetKVResponse> {
|
|
426
|
+
if (!jobId) {
|
|
427
|
+
throw new Error("Call getJob() first");
|
|
428
|
+
}
|
|
429
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
430
|
+
|
|
431
|
+
const request = create(GetKVRequestSchema, {
|
|
432
|
+
sessionId,
|
|
433
|
+
jobId,
|
|
434
|
+
key,
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
return await client.getKV(request);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Deletes a key-value pair from the app instance KV store
|
|
442
|
+
*/
|
|
443
|
+
export async function deleteKv(key: string): Promise<DeleteKVResponse> {
|
|
444
|
+
if (!jobId) {
|
|
445
|
+
throw new Error("Call getJob() first");
|
|
446
|
+
}
|
|
447
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
448
|
+
|
|
449
|
+
const request = create(DeleteKVRequestSchema, {
|
|
450
|
+
sessionId,
|
|
451
|
+
jobId,
|
|
452
|
+
key,
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
return await client.deleteKV(request);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Adds metadata to the app instance (write-once)
|
|
460
|
+
*/
|
|
461
|
+
export async function addMetadata(
|
|
462
|
+
key: string,
|
|
463
|
+
value: string
|
|
464
|
+
): Promise<AddMetadataResponse> {
|
|
465
|
+
if (!jobId) {
|
|
466
|
+
throw new Error("Call getJob() first");
|
|
467
|
+
}
|
|
468
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
469
|
+
|
|
470
|
+
const request = create(AddMetadataRequestSchema, {
|
|
471
|
+
sessionId,
|
|
472
|
+
jobId,
|
|
473
|
+
key,
|
|
474
|
+
value,
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
return await client.addMetadata(request);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Gets metadata from the app instance
|
|
482
|
+
* @param key Optional metadata key. If not provided, returns app instance info only
|
|
483
|
+
*/
|
|
484
|
+
export async function getMetadata(key?: string): Promise<GetMetadataResponse> {
|
|
485
|
+
if (!jobId) {
|
|
486
|
+
throw new Error("Call getJob() first");
|
|
487
|
+
}
|
|
488
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
489
|
+
|
|
490
|
+
const request = create(GetMetadataRequestSchema, {
|
|
491
|
+
sessionId,
|
|
492
|
+
jobId,
|
|
493
|
+
...(key && { key }),
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
return await client.getMetadata(request);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Gets app instance information without a specific metadata key
|
|
501
|
+
* Returns all AppInstance fields like sequence, block number, admin, etc.
|
|
502
|
+
*/
|
|
503
|
+
export async function getAppInstanceInfo(): Promise<GetMetadataResponse> {
|
|
504
|
+
return getMetadata(); // Call without key to get app instance info
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Tries to create a new block
|
|
509
|
+
*/
|
|
510
|
+
export async function tryCreateBlock(): Promise<TryCreateBlockResponse> {
|
|
511
|
+
if (!jobId) {
|
|
512
|
+
throw new Error("Call getJob() first");
|
|
513
|
+
}
|
|
514
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
515
|
+
|
|
516
|
+
const request = create(TryCreateBlockRequestSchema, {
|
|
517
|
+
sessionId,
|
|
518
|
+
jobId,
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
return await client.tryCreateBlock(request);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Updates block state data availability
|
|
526
|
+
*/
|
|
527
|
+
export async function updateBlockStateDataAvailability(
|
|
528
|
+
blockNumber: bigint,
|
|
529
|
+
stateDataAvailability: string
|
|
530
|
+
): Promise<UpdateBlockStateDataAvailabilityResponse> {
|
|
531
|
+
if (!jobId) {
|
|
532
|
+
throw new Error("Call getJob() first");
|
|
533
|
+
}
|
|
534
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
535
|
+
|
|
536
|
+
const request = create(UpdateBlockStateDataAvailabilityRequestSchema, {
|
|
537
|
+
sessionId,
|
|
538
|
+
jobId,
|
|
539
|
+
blockNumber,
|
|
540
|
+
stateDataAvailability,
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
return await client.updateBlockStateDataAvailability(request);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Updates block proof data availability
|
|
548
|
+
*/
|
|
549
|
+
export async function updateBlockProofDataAvailability(
|
|
550
|
+
blockNumber: bigint,
|
|
551
|
+
proofDataAvailability: string
|
|
552
|
+
): Promise<UpdateBlockProofDataAvailabilityResponse> {
|
|
553
|
+
if (!jobId) {
|
|
554
|
+
throw new Error("Call getJob() first");
|
|
555
|
+
}
|
|
556
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
557
|
+
|
|
558
|
+
const request = create(UpdateBlockProofDataAvailabilityRequestSchema, {
|
|
559
|
+
sessionId,
|
|
560
|
+
jobId,
|
|
561
|
+
blockNumber,
|
|
562
|
+
proofDataAvailability,
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
return await client.updateBlockProofDataAvailability(request);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Updates block settlement transaction hash
|
|
570
|
+
*/
|
|
571
|
+
export async function updateBlockSettlementTxHash(
|
|
572
|
+
blockNumber: bigint,
|
|
573
|
+
settlementTxHash: string,
|
|
574
|
+
settlementChain: string
|
|
575
|
+
): Promise<UpdateBlockSettlementTxHashResponse> {
|
|
576
|
+
if (!jobId) {
|
|
577
|
+
throw new Error("Call getJob() first");
|
|
578
|
+
}
|
|
579
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
580
|
+
|
|
581
|
+
const request = create(UpdateBlockSettlementTxHashRequestSchema, {
|
|
582
|
+
sessionId,
|
|
583
|
+
jobId,
|
|
584
|
+
blockNumber,
|
|
585
|
+
settlementTxHash,
|
|
586
|
+
chain: settlementChain,
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
return await client.updateBlockSettlementTxHash(request);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Updates block settlement transaction included in block
|
|
594
|
+
*/
|
|
595
|
+
export async function updateBlockSettlementTxIncludedInBlock(
|
|
596
|
+
blockNumber: bigint,
|
|
597
|
+
settledAt: bigint,
|
|
598
|
+
settlementChain: string
|
|
599
|
+
): Promise<UpdateBlockSettlementTxIncludedInBlockResponse> {
|
|
600
|
+
if (!jobId) {
|
|
601
|
+
throw new Error("Call getJob() first");
|
|
602
|
+
}
|
|
603
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
604
|
+
|
|
605
|
+
const request = create(UpdateBlockSettlementTxIncludedInBlockRequestSchema, {
|
|
606
|
+
sessionId,
|
|
607
|
+
jobId,
|
|
608
|
+
blockNumber,
|
|
609
|
+
settledAt,
|
|
610
|
+
chain: settlementChain,
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
return await client.updateBlockSettlementTxIncludedInBlock(request);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Creates a new app job
|
|
618
|
+
*/
|
|
619
|
+
export async function createAppJob(
|
|
620
|
+
methodName: string,
|
|
621
|
+
data: Uint8Array,
|
|
622
|
+
options?: {
|
|
623
|
+
jobDescription?: string;
|
|
624
|
+
blockNumber?: bigint;
|
|
625
|
+
sequences?: bigint[];
|
|
626
|
+
sequences1?: bigint[];
|
|
627
|
+
sequences2?: bigint[];
|
|
628
|
+
intervalMs?: bigint;
|
|
629
|
+
nextScheduledAt?: bigint;
|
|
630
|
+
settlementChain?: string;
|
|
631
|
+
}
|
|
632
|
+
): Promise<CreateAppJobResponse> {
|
|
633
|
+
if (!jobId) {
|
|
634
|
+
throw new Error("Call getJob() first");
|
|
635
|
+
}
|
|
636
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
637
|
+
|
|
638
|
+
const request = create(CreateAppJobRequestSchema, {
|
|
639
|
+
sessionId,
|
|
640
|
+
jobId,
|
|
641
|
+
methodName,
|
|
642
|
+
jobDescription: options?.jobDescription,
|
|
643
|
+
blockNumber: options?.blockNumber,
|
|
644
|
+
sequences: options?.sequences || [],
|
|
645
|
+
sequences1: options?.sequences1 || [],
|
|
646
|
+
sequences2: options?.sequences2 || [],
|
|
647
|
+
data,
|
|
648
|
+
intervalMs: options?.intervalMs,
|
|
649
|
+
nextScheduledAt: options?.nextScheduledAt,
|
|
650
|
+
settlementChain: options?.settlementChain,
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
return await client.createAppJob(request);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Gets a block by block number
|
|
658
|
+
*/
|
|
659
|
+
export async function getBlock(blockNumber: bigint): Promise<GetBlockResponse> {
|
|
660
|
+
if (!jobId) {
|
|
661
|
+
throw new Error("Call getJob() first");
|
|
662
|
+
}
|
|
663
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
664
|
+
|
|
665
|
+
const request = create(GetBlockRequestSchema, {
|
|
666
|
+
sessionId,
|
|
667
|
+
jobId,
|
|
668
|
+
blockNumber,
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
return await client.getBlock(request);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Rejects a proof for specific sequences
|
|
676
|
+
*/
|
|
677
|
+
export async function rejectProof(
|
|
678
|
+
blockNumber: bigint,
|
|
679
|
+
sequences: bigint[]
|
|
680
|
+
): Promise<RejectProofResponse> {
|
|
681
|
+
if (!jobId) {
|
|
682
|
+
throw new Error("Call getJob() first");
|
|
683
|
+
}
|
|
684
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
685
|
+
|
|
686
|
+
const request = create(RejectProofRequestSchema, {
|
|
687
|
+
sessionId,
|
|
688
|
+
blockNumber,
|
|
689
|
+
sequences,
|
|
690
|
+
jobId,
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
return await client.rejectProof(request);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* Gets a block settlement for a specific chain
|
|
698
|
+
*/
|
|
699
|
+
export async function getBlockSettlement(
|
|
700
|
+
blockNumber: bigint,
|
|
701
|
+
chain: string
|
|
702
|
+
): Promise<GetBlockSettlementResponse> {
|
|
703
|
+
if (!jobId) {
|
|
704
|
+
throw new Error("Call getJob() first");
|
|
705
|
+
}
|
|
706
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
707
|
+
|
|
708
|
+
const request = create(GetBlockSettlementRequestSchema, {
|
|
709
|
+
sessionId,
|
|
710
|
+
jobId,
|
|
711
|
+
blockNumber,
|
|
712
|
+
chain,
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
return await client.getBlockSettlement(request);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Updates a block settlement for a specific chain
|
|
720
|
+
*/
|
|
721
|
+
export async function updateBlockSettlement(
|
|
722
|
+
blockNumber: bigint,
|
|
723
|
+
chain: string,
|
|
724
|
+
settlementData: {
|
|
725
|
+
settlementTxHash?: string;
|
|
726
|
+
settlementTxIncludedInBlock?: boolean;
|
|
727
|
+
sentToSettlementAt?: bigint;
|
|
728
|
+
settledAt?: bigint;
|
|
729
|
+
}
|
|
730
|
+
): Promise<UpdateBlockSettlementResponse> {
|
|
731
|
+
if (!jobId) {
|
|
732
|
+
throw new Error("Call getJob() first");
|
|
733
|
+
}
|
|
734
|
+
const { client, sessionId } = getCoordinatorClient();
|
|
735
|
+
|
|
736
|
+
const request = create(UpdateBlockSettlementRequestSchema, {
|
|
737
|
+
sessionId,
|
|
738
|
+
jobId,
|
|
739
|
+
blockNumber,
|
|
740
|
+
chain,
|
|
741
|
+
settlementTxHash: settlementData.settlementTxHash,
|
|
742
|
+
settlementTxIncludedInBlock:
|
|
743
|
+
settlementData.settlementTxIncludedInBlock ?? false,
|
|
744
|
+
sentToSettlementAt: settlementData.sentToSettlementAt,
|
|
745
|
+
settledAt: settlementData.settledAt,
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
return await client.updateBlockSettlement(request);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// Re-export types for users to access
|
|
752
|
+
export type {
|
|
753
|
+
Block,
|
|
754
|
+
BlockSettlement,
|
|
755
|
+
Metadata,
|
|
756
|
+
RetrieveSecretResponse,
|
|
757
|
+
TerminateJobResponse,
|
|
758
|
+
GetBlockResponse,
|
|
759
|
+
GetBlockSettlementResponse,
|
|
760
|
+
UpdateBlockSettlementResponse,
|
|
761
|
+
RejectProofResponse,
|
|
762
|
+
};
|