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