@sovereign-sdk/web3 0.12.3 → 0.12.4
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/index.js +294 -397
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +294 -400
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,39 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
8
|
var __export = (target, all) => {
|
|
38
9
|
for (var name in all)
|
|
39
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -55,26 +26,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
55
26
|
mod
|
|
56
27
|
));
|
|
57
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
var __async = (__this, __arguments, generator) => {
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
var fulfilled = (value) => {
|
|
61
|
-
try {
|
|
62
|
-
step(generator.next(value));
|
|
63
|
-
} catch (e) {
|
|
64
|
-
reject(e);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var rejected = (value) => {
|
|
68
|
-
try {
|
|
69
|
-
step(generator.throw(value));
|
|
70
|
-
} catch (e) {
|
|
71
|
-
reject(e);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
75
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
29
|
|
|
79
30
|
// src/index.ts
|
|
80
31
|
var src_exports = {};
|
|
@@ -147,7 +98,6 @@ function httpToWebSocket(url) {
|
|
|
147
98
|
}
|
|
148
99
|
var _subscriptions = {};
|
|
149
100
|
function subscribe(url, callback) {
|
|
150
|
-
var _a;
|
|
151
101
|
const subscription = _subscriptions[url];
|
|
152
102
|
if (!subscription) {
|
|
153
103
|
const websocket = new import_partysocket.WebSocket(url, [], { WebSocket: import_isomorphic_ws.default });
|
|
@@ -157,9 +107,8 @@ function subscribe(url, callback) {
|
|
|
157
107
|
callbacks: [callback]
|
|
158
108
|
};
|
|
159
109
|
websocket.addEventListener("message", (message) => {
|
|
160
|
-
var _a2;
|
|
161
110
|
const data = JSON.parse(message.data);
|
|
162
|
-
const callbacks =
|
|
111
|
+
const callbacks = _subscriptions[url]?.callbacks;
|
|
163
112
|
if (callbacks) {
|
|
164
113
|
for (const cb of callbacks) {
|
|
165
114
|
cb(data);
|
|
@@ -173,7 +122,7 @@ function subscribe(url, callback) {
|
|
|
173
122
|
} else {
|
|
174
123
|
subscription.callbacks.push(callback);
|
|
175
124
|
}
|
|
176
|
-
const callbackIndex =
|
|
125
|
+
const callbackIndex = _subscriptions[url]?.callbacks.length - 1;
|
|
177
126
|
return {
|
|
178
127
|
get url() {
|
|
179
128
|
return url;
|
|
@@ -223,12 +172,10 @@ var Rollup = class {
|
|
|
223
172
|
* @param publicKey - The public key to dedup.
|
|
224
173
|
* TODO: How to add param for generation explicitly
|
|
225
174
|
*/
|
|
226
|
-
dedup(publicKey) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return response;
|
|
231
|
-
});
|
|
175
|
+
async dedup(publicKey) {
|
|
176
|
+
const credentialId = (0, import_utils2.bytesToHex)(publicKey);
|
|
177
|
+
const response = await this.rollup.addresses.dedup(credentialId);
|
|
178
|
+
return response;
|
|
232
179
|
}
|
|
233
180
|
/**
|
|
234
181
|
* Submits a transaction to the rollup.
|
|
@@ -239,30 +186,29 @@ var Rollup = class {
|
|
|
239
186
|
* @param transaction - The transaction to submit.
|
|
240
187
|
* @param {SovereignClient.RequestOptions} options - The options for the request.
|
|
241
188
|
*/
|
|
242
|
-
submitTransaction(transaction, options) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
189
|
+
async submitTransaction(transaction, options) {
|
|
190
|
+
const serializer = await this.serializer();
|
|
191
|
+
const serializedTx = serializer.serializeTx(transaction);
|
|
192
|
+
const { body: _, query: __, path, ...requestOptions } = options || {};
|
|
193
|
+
const txSubmissionEndpoint = path || this._config.txSubmissionEndpoint;
|
|
194
|
+
return this.http.post(txSubmissionEndpoint, {
|
|
195
|
+
body: { body: import_js_base64.Base64.fromUint8Array(serializedTx) },
|
|
196
|
+
...requestOptions
|
|
197
|
+
}).catch(async (e) => {
|
|
198
|
+
if (isVersionMismatchError(e)) {
|
|
199
|
+
const oldVersion = (0, import_utils2.bytesToHex)(await this.chainHash());
|
|
200
|
+
const { schema, chain_hash: newVersion } = await this.rollup.schema();
|
|
201
|
+
this._chainHash = (0, import_utils2.hexToBytes)(newVersion);
|
|
202
|
+
this._serializer = this._config.getSerializer(schema);
|
|
203
|
+
if (`0x${oldVersion}` !== newVersion) {
|
|
204
|
+
throw new VersionMismatchError(
|
|
205
|
+
"Schema version mismatch when submitting transaction",
|
|
206
|
+
newVersion,
|
|
207
|
+
oldVersion
|
|
208
|
+
);
|
|
263
209
|
}
|
|
264
|
-
|
|
265
|
-
|
|
210
|
+
}
|
|
211
|
+
throw e;
|
|
266
212
|
});
|
|
267
213
|
}
|
|
268
214
|
/**
|
|
@@ -274,12 +220,10 @@ var Rollup = class {
|
|
|
274
220
|
* @param {SovereignClient.RequestOptions} options - The options for the request.
|
|
275
221
|
* @param endpoint - Optional endpoint override. If not specified, uses the rollup's configured txSubmissionEndpoint.
|
|
276
222
|
*/
|
|
277
|
-
signAndSubmitTransaction(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return { transaction: tx, response: result };
|
|
282
|
-
});
|
|
223
|
+
async signAndSubmitTransaction(unsignedTx, { signer }, options) {
|
|
224
|
+
const tx = await this.signTransaction(unsignedTx, signer);
|
|
225
|
+
const result = await this.submitTransaction(tx, options);
|
|
226
|
+
return { transaction: tx, response: result };
|
|
283
227
|
}
|
|
284
228
|
/**
|
|
285
229
|
* Performs a runtime call transaction.
|
|
@@ -289,22 +233,20 @@ var Rollup = class {
|
|
|
289
233
|
* @param {CallParams<S>} params - The params for submitting a runtime call transaction.
|
|
290
234
|
* @param {SovereignClient.RequestOptions} options - The options for the request.
|
|
291
235
|
*/
|
|
292
|
-
call(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
);
|
|
307
|
-
});
|
|
236
|
+
async call(runtimeCall, { signer, overrides }, options) {
|
|
237
|
+
const context = {
|
|
238
|
+
runtimeCall,
|
|
239
|
+
rollup: this,
|
|
240
|
+
overrides: overrides ?? {}
|
|
241
|
+
};
|
|
242
|
+
const unsignedTx = await this._typeBuilder.unsignedTransaction(context);
|
|
243
|
+
return this.signAndSubmitTransaction(
|
|
244
|
+
unsignedTx,
|
|
245
|
+
{
|
|
246
|
+
signer
|
|
247
|
+
},
|
|
248
|
+
options
|
|
249
|
+
);
|
|
308
250
|
}
|
|
309
251
|
/**
|
|
310
252
|
* Prepares a runtime call by creating and signing a transaction without submitting it.
|
|
@@ -317,16 +259,14 @@ var Rollup = class {
|
|
|
317
259
|
* @param params.overrides - Optional overrides for the unsigned transaction.
|
|
318
260
|
* @returns A promise that resolves to the signed transaction.
|
|
319
261
|
*/
|
|
320
|
-
prepareCall(
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
return this.signTransaction(unsignedTx, signer);
|
|
329
|
-
});
|
|
262
|
+
async prepareCall(runtimeCall, { signer, overrides }) {
|
|
263
|
+
const context = {
|
|
264
|
+
runtimeCall,
|
|
265
|
+
rollup: this,
|
|
266
|
+
overrides: overrides ?? {}
|
|
267
|
+
};
|
|
268
|
+
const unsignedTx = await this._typeBuilder.unsignedTransaction(context);
|
|
269
|
+
return this.signTransaction(unsignedTx, signer);
|
|
330
270
|
}
|
|
331
271
|
/**
|
|
332
272
|
* Signs an unsigned transaction using the provided signer.
|
|
@@ -337,23 +277,21 @@ var Rollup = class {
|
|
|
337
277
|
* @param signer - The signer to use for signing the transaction.
|
|
338
278
|
* @returns A promise that resolves to the signed transaction.
|
|
339
279
|
*/
|
|
340
|
-
signTransaction(unsignedTx, signer) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
return this._typeBuilder.transaction(context);
|
|
356
|
-
});
|
|
280
|
+
async signTransaction(unsignedTx, signer) {
|
|
281
|
+
const serializer = await this.serializer();
|
|
282
|
+
const serializedUnsignedTx = serializer.serializeUnsignedTx(unsignedTx);
|
|
283
|
+
const chainHash = await this.chainHash();
|
|
284
|
+
const signature = await signer.sign(
|
|
285
|
+
new Uint8Array([...serializedUnsignedTx, ...chainHash])
|
|
286
|
+
);
|
|
287
|
+
const publicKey = await signer.publicKey();
|
|
288
|
+
const context = {
|
|
289
|
+
unsignedTx,
|
|
290
|
+
sender: publicKey,
|
|
291
|
+
signature,
|
|
292
|
+
rollup: this
|
|
293
|
+
};
|
|
294
|
+
return this._typeBuilder.transaction(context);
|
|
357
295
|
}
|
|
358
296
|
/**
|
|
359
297
|
* Create a subscription to events emitted over websockets by the rollup.
|
|
@@ -367,15 +305,13 @@ var Rollup = class {
|
|
|
367
305
|
* @param timeout - Request timeout in milliseconds.
|
|
368
306
|
* @returns `true` if the rollup is considered healthy otherwise `false`.
|
|
369
307
|
*/
|
|
370
|
-
healthcheck(timeout = 5e3) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
});
|
|
308
|
+
async healthcheck(timeout = 5e3) {
|
|
309
|
+
try {
|
|
310
|
+
await this.http.get("/healthcheck", { timeout, maxRetries: 1 });
|
|
311
|
+
return true;
|
|
312
|
+
} catch (e) {
|
|
313
|
+
return !(e instanceof import_client.default.APIConnectionError);
|
|
314
|
+
}
|
|
379
315
|
}
|
|
380
316
|
/**
|
|
381
317
|
* A ledger client that can be used to query the ledger.
|
|
@@ -407,13 +343,11 @@ var Rollup = class {
|
|
|
407
343
|
* The serializer for the rollup.
|
|
408
344
|
* Can be used to serialize transactions, runtime calls, etc.
|
|
409
345
|
*/
|
|
410
|
-
serializer() {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
return this._serializer;
|
|
416
|
-
});
|
|
346
|
+
async serializer() {
|
|
347
|
+
if (this._serializer) return this._serializer;
|
|
348
|
+
const { schema } = await this.rollup.schema();
|
|
349
|
+
this._serializer = this._config.getSerializer(schema);
|
|
350
|
+
return this._serializer;
|
|
417
351
|
}
|
|
418
352
|
/**
|
|
419
353
|
* The context for the rollup.
|
|
@@ -421,20 +355,17 @@ var Rollup = class {
|
|
|
421
355
|
get context() {
|
|
422
356
|
return this._config.context;
|
|
423
357
|
}
|
|
424
|
-
chainHash() {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
return this._chainHash;
|
|
430
|
-
});
|
|
358
|
+
async chainHash() {
|
|
359
|
+
if (this._chainHash) return this._chainHash;
|
|
360
|
+
const { chain_hash } = await this.rollup.schema();
|
|
361
|
+
this._chainHash = (0, import_utils2.hexToBytes)(chain_hash);
|
|
362
|
+
return this._chainHash;
|
|
431
363
|
}
|
|
432
364
|
};
|
|
433
365
|
function isVersionMismatchError(e) {
|
|
434
|
-
var _a, _b, _c;
|
|
435
366
|
if (
|
|
436
367
|
// biome-ignore lint/suspicious/noExplicitAny: yolo
|
|
437
|
-
|
|
368
|
+
e.error?.details?.error?.includes("Signature verification failed")
|
|
438
369
|
) {
|
|
439
370
|
return true;
|
|
440
371
|
}
|
|
@@ -445,42 +376,42 @@ function isVersionMismatchError(e) {
|
|
|
445
376
|
var import_client2 = __toESM(require("@sovereign-sdk/client"));
|
|
446
377
|
var import_serializers = require("@sovereign-sdk/serializers");
|
|
447
378
|
var import_utils3 = require("@sovereign-sdk/utils");
|
|
448
|
-
var useOrFetchUniqueness =
|
|
379
|
+
var useOrFetchUniqueness = async ({
|
|
449
380
|
overrides
|
|
450
|
-
}) {
|
|
451
|
-
if (overrides
|
|
381
|
+
}) => {
|
|
382
|
+
if (overrides?.uniqueness) {
|
|
452
383
|
return overrides.uniqueness;
|
|
453
384
|
}
|
|
454
385
|
return { generation: Date.now() };
|
|
455
|
-
}
|
|
386
|
+
};
|
|
456
387
|
function standardTypeBuilder() {
|
|
457
388
|
return {
|
|
458
|
-
unsignedTransaction(context) {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
389
|
+
async unsignedTransaction(context) {
|
|
390
|
+
const { rollup, runtimeCall } = context;
|
|
391
|
+
const { uniqueness: _, ...overrides } = context.overrides;
|
|
392
|
+
const uniqueness = await useOrFetchUniqueness(context);
|
|
393
|
+
const details = {
|
|
394
|
+
...rollup.context.defaultTxDetails,
|
|
395
|
+
...overrides.details
|
|
396
|
+
};
|
|
397
|
+
return {
|
|
398
|
+
runtime_call: runtimeCall,
|
|
399
|
+
uniqueness,
|
|
400
|
+
details
|
|
401
|
+
};
|
|
470
402
|
},
|
|
471
|
-
transaction(
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
});
|
|
403
|
+
async transaction({
|
|
404
|
+
sender,
|
|
405
|
+
signature,
|
|
406
|
+
unsignedTx
|
|
407
|
+
}) {
|
|
408
|
+
return {
|
|
409
|
+
V0: {
|
|
410
|
+
pub_key: (0, import_utils3.bytesToHex)(sender),
|
|
411
|
+
signature: (0, import_utils3.bytesToHex)(signature),
|
|
412
|
+
...unsignedTx
|
|
413
|
+
}
|
|
414
|
+
};
|
|
484
415
|
}
|
|
485
416
|
};
|
|
486
417
|
}
|
|
@@ -492,13 +423,11 @@ var StandardRollup = class extends Rollup {
|
|
|
492
423
|
*
|
|
493
424
|
* @param runtimeMessage - The runtime message to call.
|
|
494
425
|
*/
|
|
495
|
-
simulate(
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
return this.rollup.simulate({ sender, call });
|
|
501
|
-
});
|
|
426
|
+
async simulate(runtimeMessage, { signer }) {
|
|
427
|
+
const publicKey = await signer.publicKey();
|
|
428
|
+
const sender = (0, import_utils3.bytesToHex)(publicKey);
|
|
429
|
+
const call = runtimeMessage;
|
|
430
|
+
return this.rollup.simulate({ sender, call });
|
|
502
431
|
}
|
|
503
432
|
};
|
|
504
433
|
var DEFAULT_TX_DETAILS = {
|
|
@@ -506,36 +435,38 @@ var DEFAULT_TX_DETAILS = {
|
|
|
506
435
|
max_fee: "100000000",
|
|
507
436
|
gas_limit: null
|
|
508
437
|
};
|
|
509
|
-
function buildContext(client, context) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
438
|
+
async function buildContext(client, context) {
|
|
439
|
+
const defaultTxDetails = {
|
|
440
|
+
...DEFAULT_TX_DETAILS,
|
|
441
|
+
...context?.defaultTxDetails
|
|
442
|
+
};
|
|
443
|
+
if (!defaultTxDetails.chain_id) {
|
|
444
|
+
const { chain_id } = await client.rollup.constants();
|
|
445
|
+
defaultTxDetails.chain_id = chain_id;
|
|
446
|
+
}
|
|
447
|
+
return {
|
|
448
|
+
defaultTxDetails
|
|
449
|
+
};
|
|
520
450
|
}
|
|
521
|
-
function createStandardRollup(rollupConfig, typeBuilderOverrides) {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
451
|
+
async function createStandardRollup(rollupConfig, typeBuilderOverrides) {
|
|
452
|
+
const config = rollupConfig ?? {};
|
|
453
|
+
const client = config.client ?? new import_client2.default({ baseURL: config.url });
|
|
454
|
+
const getSerializer = config.getSerializer ?? ((schema) => new import_serializers.JsSerializer(schema));
|
|
455
|
+
const context = await buildContext(client, config.context);
|
|
456
|
+
const txSubmissionEndpoint = config.txSubmissionEndpoint ?? "/sequencer/txs";
|
|
457
|
+
return new StandardRollup(
|
|
458
|
+
{
|
|
459
|
+
...config,
|
|
460
|
+
client,
|
|
461
|
+
getSerializer,
|
|
462
|
+
context,
|
|
463
|
+
txSubmissionEndpoint
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
...standardTypeBuilder(),
|
|
467
|
+
...typeBuilderOverrides
|
|
468
|
+
}
|
|
469
|
+
);
|
|
539
470
|
}
|
|
540
471
|
|
|
541
472
|
// src/rollup/solana-signable-rollup.ts
|
|
@@ -588,120 +519,104 @@ var SolanaSignableRollup = class {
|
|
|
588
519
|
/**
|
|
589
520
|
* Submits serialized data to the Solana endpoint.
|
|
590
521
|
*/
|
|
591
|
-
submitSerializedMessage(serializedMessage) {
|
|
592
|
-
return
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
);
|
|
599
|
-
});
|
|
522
|
+
async submitSerializedMessage(serializedMessage) {
|
|
523
|
+
return await this.inner.http.post(
|
|
524
|
+
this.solanaEndpoint,
|
|
525
|
+
{
|
|
526
|
+
body: import_js_base642.Base64.fromUint8Array(serializedMessage)
|
|
527
|
+
}
|
|
528
|
+
);
|
|
600
529
|
}
|
|
601
530
|
/**
|
|
602
531
|
* Submits a Solana offchain message to the rollup.
|
|
603
532
|
*/
|
|
604
|
-
submitSolanaMessage(solanaMessage) {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
return this.submitSerializedMessage(serializedMessage);
|
|
608
|
-
});
|
|
533
|
+
async submitSolanaMessage(solanaMessage) {
|
|
534
|
+
const serializedMessage = this.serializeSolanaMessage(solanaMessage);
|
|
535
|
+
return this.submitSerializedMessage(serializedMessage);
|
|
609
536
|
}
|
|
610
537
|
/**
|
|
611
538
|
* Submits a Solana spec-compliant message to the rollup.
|
|
612
539
|
*/
|
|
613
|
-
submitSolanaSpecMessage(solanaMessage) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
return this.submitSerializedMessage(serializedMessage);
|
|
617
|
-
});
|
|
540
|
+
async submitSolanaSpecMessage(solanaMessage) {
|
|
541
|
+
const serializedMessage = this.serializeSolanaSpecMessage(solanaMessage);
|
|
542
|
+
return this.submitSerializedMessage(serializedMessage);
|
|
618
543
|
}
|
|
619
544
|
/**
|
|
620
545
|
* Helper to build an unsigned transaction using the standard type builder.
|
|
621
546
|
*/
|
|
622
|
-
buildUnsignedTransaction(runtimeCall, overrides) {
|
|
623
|
-
return
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
rollup: this.inner
|
|
628
|
-
});
|
|
547
|
+
async buildUnsignedTransaction(runtimeCall, overrides) {
|
|
548
|
+
return this.typeBuilder.unsignedTransaction({
|
|
549
|
+
runtimeCall,
|
|
550
|
+
overrides: overrides ?? {},
|
|
551
|
+
rollup: this.inner
|
|
629
552
|
});
|
|
630
553
|
}
|
|
631
554
|
/**
|
|
632
555
|
* Helper to build a transaction result object.
|
|
633
556
|
*/
|
|
634
|
-
buildTransactionResult(response, unsignedTx, pubkey, signature) {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
rollup: this.inner
|
|
641
|
-
});
|
|
642
|
-
return { response, transaction };
|
|
557
|
+
async buildTransactionResult(response, unsignedTx, pubkey, signature) {
|
|
558
|
+
const transaction = await this.typeBuilder.transaction({
|
|
559
|
+
unsignedTx,
|
|
560
|
+
sender: pubkey,
|
|
561
|
+
signature,
|
|
562
|
+
rollup: this.inner
|
|
643
563
|
});
|
|
564
|
+
return { response, transaction };
|
|
644
565
|
}
|
|
645
566
|
/**
|
|
646
567
|
* Helper to create and serialize a SolanaOffchainUnsignedTransaction to JSON bytes.
|
|
647
568
|
*/
|
|
648
|
-
createSolanaJsonBytes(unsignedTx) {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
return new TextEncoder().encode(JSON.stringify(solanaUnsignedTx));
|
|
660
|
-
});
|
|
569
|
+
async createSolanaJsonBytes(unsignedTx) {
|
|
570
|
+
const serializer = await this.inner.serializer();
|
|
571
|
+
const schema = serializer.schema;
|
|
572
|
+
const chainName = schema.chain_name || "";
|
|
573
|
+
const solanaUnsignedTx = {
|
|
574
|
+
runtime_call: unsignedTx.runtime_call,
|
|
575
|
+
uniqueness: unsignedTx.uniqueness,
|
|
576
|
+
details: unsignedTx.details,
|
|
577
|
+
chain_name: chainName
|
|
578
|
+
};
|
|
579
|
+
return new TextEncoder().encode(JSON.stringify(solanaUnsignedTx));
|
|
661
580
|
}
|
|
662
581
|
/**
|
|
663
582
|
* Signs an unsigned transaction using Solana offchain simple signing and submits it.
|
|
664
583
|
* Returns the transaction result in the same format as standard rollup.
|
|
665
584
|
*/
|
|
666
|
-
signWithSolanaSimpleAndSubmit(unsignedTx, signer) {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
return this.buildTransactionResult(response, unsignedTx, pubkey, signature);
|
|
680
|
-
});
|
|
585
|
+
async signWithSolanaSimpleAndSubmit(unsignedTx, signer) {
|
|
586
|
+
const jsonBytes = await this.createSolanaJsonBytes(unsignedTx);
|
|
587
|
+
const pubkey = await signer.publicKey();
|
|
588
|
+
const chainHash = await this.inner.chainHash();
|
|
589
|
+
const signature = await signer.sign(jsonBytes);
|
|
590
|
+
const solanaMessage = {
|
|
591
|
+
signed_message: jsonBytes,
|
|
592
|
+
chain_hash: chainHash,
|
|
593
|
+
pubkey,
|
|
594
|
+
signature
|
|
595
|
+
};
|
|
596
|
+
const response = await this.submitSolanaMessage(solanaMessage);
|
|
597
|
+
return this.buildTransactionResult(response, unsignedTx, pubkey, signature);
|
|
681
598
|
}
|
|
682
599
|
/**
|
|
683
600
|
* Signs an unsigned transaction using Solana spec-compliant signing and submits it.
|
|
684
601
|
* Returns the transaction result in the same format as standard rollup.
|
|
685
602
|
*/
|
|
686
|
-
signWithSolanaSpecAndSubmit(unsignedTx, signer) {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
return this.buildTransactionResult(response, unsignedTx, pubkey, signature);
|
|
704
|
-
});
|
|
603
|
+
async signWithSolanaSpecAndSubmit(unsignedTx, signer) {
|
|
604
|
+
const jsonBytes = await this.createSolanaJsonBytes(unsignedTx);
|
|
605
|
+
const pubkey = await signer.publicKey();
|
|
606
|
+
const chainHash = await this.inner.chainHash();
|
|
607
|
+
const preamble = createSolanaPreamble(pubkey, chainHash, jsonBytes.length);
|
|
608
|
+
const signedMessageWithPreamble = new Uint8Array(
|
|
609
|
+
preamble.length + jsonBytes.length
|
|
610
|
+
);
|
|
611
|
+
signedMessageWithPreamble.set(preamble, 0);
|
|
612
|
+
signedMessageWithPreamble.set(jsonBytes, preamble.length);
|
|
613
|
+
const signature = await signer.sign(signedMessageWithPreamble);
|
|
614
|
+
const solanaMessage = {
|
|
615
|
+
signed_message_with_preamble: signedMessageWithPreamble,
|
|
616
|
+
signature
|
|
617
|
+
};
|
|
618
|
+
const response = await this.submitSolanaSpecMessage(solanaMessage);
|
|
619
|
+
return this.buildTransactionResult(response, unsignedTx, pubkey, signature);
|
|
705
620
|
}
|
|
706
621
|
/**
|
|
707
622
|
* Performs a runtime call transaction with the specified authenticator.
|
|
@@ -711,37 +626,35 @@ var SolanaSignableRollup = class {
|
|
|
711
626
|
* @param options - Optional request options
|
|
712
627
|
* @returns The transaction result including hash and transaction object
|
|
713
628
|
*/
|
|
714
|
-
call(runtimeCall, params, options) {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
return this.signWithSolanaSimpleAndSubmit(unsignedTx, params.signer);
|
|
733
|
-
}
|
|
734
|
-
case "solana": {
|
|
735
|
-
const unsignedTx = yield this.buildUnsignedTransaction(
|
|
736
|
-
runtimeCall,
|
|
737
|
-
params.overrides
|
|
738
|
-
);
|
|
739
|
-
return this.signWithSolanaSpecAndSubmit(unsignedTx, params.signer);
|
|
740
|
-
}
|
|
741
|
-
default:
|
|
742
|
-
throw new Error(`Unsupported authenticator: ${authenticator}`);
|
|
629
|
+
async call(runtimeCall, params, options) {
|
|
630
|
+
const authenticator = params.authenticator === "solanaAuto" ? this.getAutoAuthenticator(params.signer) : params.authenticator;
|
|
631
|
+
switch (authenticator) {
|
|
632
|
+
case "standard":
|
|
633
|
+
return this.inner.call(
|
|
634
|
+
runtimeCall,
|
|
635
|
+
{
|
|
636
|
+
signer: params.signer,
|
|
637
|
+
overrides: params.overrides
|
|
638
|
+
},
|
|
639
|
+
options
|
|
640
|
+
);
|
|
641
|
+
case "solanaSimple": {
|
|
642
|
+
const unsignedTx = await this.buildUnsignedTransaction(
|
|
643
|
+
runtimeCall,
|
|
644
|
+
params.overrides
|
|
645
|
+
);
|
|
646
|
+
return this.signWithSolanaSimpleAndSubmit(unsignedTx, params.signer);
|
|
743
647
|
}
|
|
744
|
-
|
|
648
|
+
case "solana": {
|
|
649
|
+
const unsignedTx = await this.buildUnsignedTransaction(
|
|
650
|
+
runtimeCall,
|
|
651
|
+
params.overrides
|
|
652
|
+
);
|
|
653
|
+
return this.signWithSolanaSpecAndSubmit(unsignedTx, params.signer);
|
|
654
|
+
}
|
|
655
|
+
default:
|
|
656
|
+
throw new Error(`Unsupported authenticator: ${authenticator}`);
|
|
657
|
+
}
|
|
745
658
|
}
|
|
746
659
|
/**
|
|
747
660
|
* Signs and submits a transaction with the specified authenticator.
|
|
@@ -751,26 +664,24 @@ var SolanaSignableRollup = class {
|
|
|
751
664
|
* @param options - Optional request options
|
|
752
665
|
* @returns The transaction result
|
|
753
666
|
*/
|
|
754
|
-
signAndSubmitTransaction(unsignedTx, params, options) {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
}
|
|
773
|
-
});
|
|
667
|
+
async signAndSubmitTransaction(unsignedTx, params, options) {
|
|
668
|
+
const authenticator = params.authenticator === "solanaAuto" ? this.getAutoAuthenticator(params.signer) : params.authenticator;
|
|
669
|
+
switch (authenticator) {
|
|
670
|
+
case "standard":
|
|
671
|
+
return this.inner.signAndSubmitTransaction(
|
|
672
|
+
unsignedTx,
|
|
673
|
+
{
|
|
674
|
+
signer: params.signer
|
|
675
|
+
},
|
|
676
|
+
options
|
|
677
|
+
);
|
|
678
|
+
case "solanaSimple":
|
|
679
|
+
return this.signWithSolanaSimpleAndSubmit(unsignedTx, params.signer);
|
|
680
|
+
case "solana":
|
|
681
|
+
return this.signWithSolanaSpecAndSubmit(unsignedTx, params.signer);
|
|
682
|
+
default:
|
|
683
|
+
throw new Error(`Unsupported authenticator: ${authenticator}`);
|
|
684
|
+
}
|
|
774
685
|
}
|
|
775
686
|
/**
|
|
776
687
|
* Submits a transaction with the specified authenticator.
|
|
@@ -780,51 +691,39 @@ var SolanaSignableRollup = class {
|
|
|
780
691
|
* @param options - Optional request options
|
|
781
692
|
* @returns The transaction response
|
|
782
693
|
*/
|
|
783
|
-
submitTransaction(transaction, authenticator, options) {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
return yield this.submitSolanaMessage(solanaMessage);
|
|
794
|
-
}
|
|
795
|
-
case "solana": {
|
|
796
|
-
const solanaMessage = transaction;
|
|
797
|
-
return yield this.submitSolanaSpecMessage(solanaMessage);
|
|
798
|
-
}
|
|
799
|
-
default:
|
|
800
|
-
throw new Error(`Unsupported authenticator: ${authenticator}`);
|
|
694
|
+
async submitTransaction(transaction, authenticator, options) {
|
|
695
|
+
switch (authenticator) {
|
|
696
|
+
case "standard":
|
|
697
|
+
return this.inner.submitTransaction(
|
|
698
|
+
transaction,
|
|
699
|
+
options
|
|
700
|
+
);
|
|
701
|
+
case "solanaSimple": {
|
|
702
|
+
const solanaMessage = transaction;
|
|
703
|
+
return await this.submitSolanaMessage(solanaMessage);
|
|
801
704
|
}
|
|
802
|
-
|
|
705
|
+
case "solana": {
|
|
706
|
+
const solanaMessage = transaction;
|
|
707
|
+
return await this.submitSolanaSpecMessage(solanaMessage);
|
|
708
|
+
}
|
|
709
|
+
default:
|
|
710
|
+
throw new Error(`Unsupported authenticator: ${authenticator}`);
|
|
711
|
+
}
|
|
803
712
|
}
|
|
804
|
-
simulate(runtimeMessage, params) {
|
|
805
|
-
return
|
|
806
|
-
return this.inner.simulate(runtimeMessage, params);
|
|
807
|
-
});
|
|
713
|
+
async simulate(runtimeMessage, params) {
|
|
714
|
+
return this.inner.simulate(runtimeMessage, params);
|
|
808
715
|
}
|
|
809
|
-
dedup(address) {
|
|
810
|
-
return
|
|
811
|
-
return this.inner.dedup(address);
|
|
812
|
-
});
|
|
716
|
+
async dedup(address) {
|
|
717
|
+
return this.inner.dedup(address);
|
|
813
718
|
}
|
|
814
|
-
serializer() {
|
|
815
|
-
return
|
|
816
|
-
return this.inner.serializer();
|
|
817
|
-
});
|
|
719
|
+
async serializer() {
|
|
720
|
+
return this.inner.serializer();
|
|
818
721
|
}
|
|
819
|
-
chainHash() {
|
|
820
|
-
return
|
|
821
|
-
return this.inner.chainHash();
|
|
822
|
-
});
|
|
722
|
+
async chainHash() {
|
|
723
|
+
return this.inner.chainHash();
|
|
823
724
|
}
|
|
824
|
-
healthcheck(timeout) {
|
|
825
|
-
return
|
|
826
|
-
return this.inner.healthcheck(timeout);
|
|
827
|
-
});
|
|
725
|
+
async healthcheck(timeout) {
|
|
726
|
+
return this.inner.healthcheck(timeout);
|
|
828
727
|
}
|
|
829
728
|
subscribe(type, callback) {
|
|
830
729
|
return this.inner.subscribe(type, callback);
|
|
@@ -899,11 +798,9 @@ var SolanaSignableRollup = class {
|
|
|
899
798
|
return buffer;
|
|
900
799
|
}
|
|
901
800
|
};
|
|
902
|
-
function createSolanaSignableRollup(rollupConfig, solanaEndpoint = "/sequencer/accept-solana-offchain-tx") {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
return new SolanaSignableRollup(standardRollup, solanaEndpoint);
|
|
906
|
-
});
|
|
801
|
+
async function createSolanaSignableRollup(rollupConfig, solanaEndpoint = "/sequencer/accept-solana-offchain-tx") {
|
|
802
|
+
const standardRollup = await createStandardRollup(rollupConfig);
|
|
803
|
+
return new SolanaSignableRollup(standardRollup, solanaEndpoint);
|
|
907
804
|
}
|
|
908
805
|
|
|
909
806
|
// src/index.ts
|