@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.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.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 =
|
|
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 =
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
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(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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
|
-
|
|
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 =
|
|
330
|
+
var useOrFetchUniqueness = async ({
|
|
403
331
|
overrides
|
|
404
|
-
}) {
|
|
405
|
-
if (overrides
|
|
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
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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(
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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(
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
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
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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
|
-
|
|
560
|
-
|
|
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
|
-
|
|
569
|
-
|
|
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
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
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
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
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
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
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
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
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
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
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
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
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
|
|
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
|
|
765
|
-
return this.inner.dedup(address);
|
|
766
|
-
});
|
|
667
|
+
async dedup(address) {
|
|
668
|
+
return this.inner.dedup(address);
|
|
767
669
|
}
|
|
768
|
-
serializer() {
|
|
769
|
-
return
|
|
770
|
-
return this.inner.serializer();
|
|
771
|
-
});
|
|
670
|
+
async serializer() {
|
|
671
|
+
return this.inner.serializer();
|
|
772
672
|
}
|
|
773
|
-
chainHash() {
|
|
774
|
-
return
|
|
775
|
-
return this.inner.chainHash();
|
|
776
|
-
});
|
|
673
|
+
async chainHash() {
|
|
674
|
+
return this.inner.chainHash();
|
|
777
675
|
}
|
|
778
|
-
healthcheck(timeout) {
|
|
779
|
-
return
|
|
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
|
-
|
|
858
|
-
|
|
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
|