@sovereign-sdk/web3 0.0.19 → 0.0.21
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.d.mts +35 -13
- package/dist/index.d.ts +35 -13
- package/dist/index.js +90 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import SovereignClient__default from '@sovereign-sdk/client';
|
|
|
2
2
|
import * as SovereignClient from '@sovereign-sdk/client';
|
|
3
3
|
export { SovereignClient };
|
|
4
4
|
import { Signer } from '@sovereign-sdk/signers';
|
|
5
|
+
import { Schema } from '@sovereign-sdk/universal-wallet-wasm';
|
|
5
6
|
export { Schema } from '@sovereign-sdk/universal-wallet-wasm';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -57,6 +58,10 @@ type RollupSerializer = {
|
|
|
57
58
|
* @returns The serialized Borsh bytes.
|
|
58
59
|
*/
|
|
59
60
|
serializeTx(input: unknown): Uint8Array;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the `Schema` used by the serializer.
|
|
63
|
+
*/
|
|
64
|
+
get schema(): Schema;
|
|
60
65
|
};
|
|
61
66
|
/**
|
|
62
67
|
* Create a serializer for a rollup schema.
|
|
@@ -66,6 +71,7 @@ type RollupSerializer = {
|
|
|
66
71
|
* @returns The serializer.
|
|
67
72
|
*/
|
|
68
73
|
declare function createSerializer(schemaObject: RollupSchema): RollupSerializer;
|
|
74
|
+
declare function createSerializerFromHttp(client: SovereignClient__default): Promise<RollupSerializer>;
|
|
69
75
|
|
|
70
76
|
/**
|
|
71
77
|
* The base type specification for a rollup.
|
|
@@ -167,24 +173,23 @@ type TypeBuilder<S extends BaseTypeSpec, C extends RollupContext> = {
|
|
|
167
173
|
type RollupContext = Record<string, unknown>;
|
|
168
174
|
/**
|
|
169
175
|
* The configuration for a rollup client.
|
|
176
|
+
* This is a partial version of the configuration object, using a partial version
|
|
177
|
+
* allows setup code to initialize fields automatically for SDK users, for example
|
|
178
|
+
* fetching a `serializer` instance from the rollups endpoint.
|
|
170
179
|
*/
|
|
171
|
-
type
|
|
180
|
+
type PartialRollupConfig<C extends RollupContext> = {
|
|
172
181
|
/**
|
|
173
182
|
* The base URL of the rollup full node API.
|
|
174
183
|
*/
|
|
175
184
|
url?: string;
|
|
176
185
|
/**
|
|
177
186
|
* The Sovereign SDK client to use for the rollup.
|
|
178
|
-
* If not provided, the default client will be used using {@link
|
|
187
|
+
* If not provided, the default client will be used using {@link PartialRollupConfig.url}.
|
|
179
188
|
*/
|
|
180
189
|
client?: SovereignClient__default;
|
|
181
|
-
/**
|
|
182
|
-
* The schema of the rollup.
|
|
183
|
-
*/
|
|
184
|
-
schema?: RollupSchema;
|
|
185
190
|
/**
|
|
186
191
|
* The serializer to use for the rollup.
|
|
187
|
-
* If not provided, a serializer will be created using the provided
|
|
192
|
+
* If not provided, a serializer will be created using the provided client and the rollup HTTP endpoint.
|
|
188
193
|
*/
|
|
189
194
|
serializer?: RollupSerializer;
|
|
190
195
|
/**
|
|
@@ -192,6 +197,13 @@ type RollupConfig<C extends RollupContext> = {
|
|
|
192
197
|
*/
|
|
193
198
|
context: C;
|
|
194
199
|
};
|
|
200
|
+
/**
|
|
201
|
+
* Fully initialized rollup configuration.
|
|
202
|
+
*/
|
|
203
|
+
type RollupConfig<C extends RollupContext> = Omit<PartialRollupConfig<C>, "client" | "serializer"> & {
|
|
204
|
+
client: SovereignClient__default;
|
|
205
|
+
serializer: RollupSerializer;
|
|
206
|
+
};
|
|
195
207
|
/**
|
|
196
208
|
* The result of signing and submitting a transaction.
|
|
197
209
|
*
|
|
@@ -231,14 +243,10 @@ type CallParams<S extends BaseTypeSpec> = {
|
|
|
231
243
|
*/
|
|
232
244
|
declare class Rollup<S extends BaseTypeSpec, C extends RollupContext> {
|
|
233
245
|
private readonly _config;
|
|
234
|
-
private readonly _client;
|
|
235
|
-
private readonly _serializer;
|
|
236
246
|
private readonly _typeBuilder;
|
|
237
247
|
/**
|
|
238
248
|
* Creates a new rollup client.
|
|
239
249
|
*
|
|
240
|
-
* @throws {@link InvalidRollupConfigError} - If no schema or serializer is provided.
|
|
241
|
-
*
|
|
242
250
|
* @param config - The configuration for the rollup client.
|
|
243
251
|
* @param typeBuilder - The type builder for the rollup.
|
|
244
252
|
*/
|
|
@@ -299,6 +307,10 @@ declare class Rollup<S extends BaseTypeSpec, C extends RollupContext> {
|
|
|
299
307
|
* The context for the rollup.
|
|
300
308
|
*/
|
|
301
309
|
get context(): C;
|
|
310
|
+
/**
|
|
311
|
+
* The chain hash of the rollup.
|
|
312
|
+
*/
|
|
313
|
+
get chainHash(): Uint8Array;
|
|
302
314
|
}
|
|
303
315
|
|
|
304
316
|
type TxDetails = {
|
|
@@ -353,7 +365,7 @@ declare class StandardRollup<RuntimeCall> extends Rollup<StandardRollupSpec<Runt
|
|
|
353
365
|
*/
|
|
354
366
|
simulate(runtimeMessage: StandardRollupSpec<RuntimeCall>["RuntimeCall"], { signer, txDetails, nonce: overrideNonce }: SimulateParams): Promise<SovereignClient__default.Rollup.SimulateExecutionResponse>;
|
|
355
367
|
}
|
|
356
|
-
declare function createStandardRollup<RuntimeCall, C extends StandardRollupContext = StandardRollupContext>(config:
|
|
368
|
+
declare function createStandardRollup<RuntimeCall, C extends StandardRollupContext = StandardRollupContext>(config: PartialRollupConfig<C>, typeBuilderOverrides?: Partial<TypeBuilder<StandardRollupSpec<RuntimeCall>, C>>): Promise<StandardRollup<RuntimeCall>>;
|
|
357
369
|
|
|
358
370
|
/**
|
|
359
371
|
* Base error class for Sovereign SDK Web3.
|
|
@@ -363,5 +375,15 @@ declare class SovereignError extends Error {
|
|
|
363
375
|
}
|
|
364
376
|
declare class InvalidRollupConfigError extends SovereignError {
|
|
365
377
|
}
|
|
378
|
+
declare class RollupInterfaceError extends SovereignError {
|
|
379
|
+
readonly method: string;
|
|
380
|
+
constructor(message: string, method: string);
|
|
381
|
+
}
|
|
382
|
+
declare class VersionMismatchError extends SovereignError {
|
|
383
|
+
readonly newVersion: string;
|
|
384
|
+
readonly currentVersion: string;
|
|
385
|
+
readonly retryable: boolean;
|
|
386
|
+
constructor(message: string, newVersion: string, currentVersion: string);
|
|
387
|
+
}
|
|
366
388
|
|
|
367
|
-
export { type BaseTypeSpec, type CallParams, type Dedup, InvalidRollupConfigError, Rollup, type RollupConfig, type RollupContext, type RollupSchema, type RollupSerializer, type RollupTypeSpec, type SignerParams, type SimulateParams, SovereignError, StandardRollup, type StandardRollupContext, type StandardRollupSpec, type Transaction, type TransactionContext, type TransactionResult, type TxDetails, type TypeBuilder, type UnsignedTransaction, type UnsignedTransactionContext, createSerializer, createStandardRollup, standardTypeBuilder };
|
|
389
|
+
export { type BaseTypeSpec, type CallParams, type Dedup, InvalidRollupConfigError, type PartialRollupConfig, Rollup, type RollupConfig, type RollupContext, RollupInterfaceError, type RollupSchema, type RollupSerializer, type RollupTypeSpec, type SignerParams, type SimulateParams, SovereignError, StandardRollup, type StandardRollupContext, type StandardRollupSpec, type Transaction, type TransactionContext, type TransactionResult, type TxDetails, type TypeBuilder, type UnsignedTransaction, type UnsignedTransactionContext, VersionMismatchError, createSerializer, createSerializerFromHttp, createStandardRollup, standardTypeBuilder };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import SovereignClient__default from '@sovereign-sdk/client';
|
|
|
2
2
|
import * as SovereignClient from '@sovereign-sdk/client';
|
|
3
3
|
export { SovereignClient };
|
|
4
4
|
import { Signer } from '@sovereign-sdk/signers';
|
|
5
|
+
import { Schema } from '@sovereign-sdk/universal-wallet-wasm';
|
|
5
6
|
export { Schema } from '@sovereign-sdk/universal-wallet-wasm';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -57,6 +58,10 @@ type RollupSerializer = {
|
|
|
57
58
|
* @returns The serialized Borsh bytes.
|
|
58
59
|
*/
|
|
59
60
|
serializeTx(input: unknown): Uint8Array;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the `Schema` used by the serializer.
|
|
63
|
+
*/
|
|
64
|
+
get schema(): Schema;
|
|
60
65
|
};
|
|
61
66
|
/**
|
|
62
67
|
* Create a serializer for a rollup schema.
|
|
@@ -66,6 +71,7 @@ type RollupSerializer = {
|
|
|
66
71
|
* @returns The serializer.
|
|
67
72
|
*/
|
|
68
73
|
declare function createSerializer(schemaObject: RollupSchema): RollupSerializer;
|
|
74
|
+
declare function createSerializerFromHttp(client: SovereignClient__default): Promise<RollupSerializer>;
|
|
69
75
|
|
|
70
76
|
/**
|
|
71
77
|
* The base type specification for a rollup.
|
|
@@ -167,24 +173,23 @@ type TypeBuilder<S extends BaseTypeSpec, C extends RollupContext> = {
|
|
|
167
173
|
type RollupContext = Record<string, unknown>;
|
|
168
174
|
/**
|
|
169
175
|
* The configuration for a rollup client.
|
|
176
|
+
* This is a partial version of the configuration object, using a partial version
|
|
177
|
+
* allows setup code to initialize fields automatically for SDK users, for example
|
|
178
|
+
* fetching a `serializer` instance from the rollups endpoint.
|
|
170
179
|
*/
|
|
171
|
-
type
|
|
180
|
+
type PartialRollupConfig<C extends RollupContext> = {
|
|
172
181
|
/**
|
|
173
182
|
* The base URL of the rollup full node API.
|
|
174
183
|
*/
|
|
175
184
|
url?: string;
|
|
176
185
|
/**
|
|
177
186
|
* The Sovereign SDK client to use for the rollup.
|
|
178
|
-
* If not provided, the default client will be used using {@link
|
|
187
|
+
* If not provided, the default client will be used using {@link PartialRollupConfig.url}.
|
|
179
188
|
*/
|
|
180
189
|
client?: SovereignClient__default;
|
|
181
|
-
/**
|
|
182
|
-
* The schema of the rollup.
|
|
183
|
-
*/
|
|
184
|
-
schema?: RollupSchema;
|
|
185
190
|
/**
|
|
186
191
|
* The serializer to use for the rollup.
|
|
187
|
-
* If not provided, a serializer will be created using the provided
|
|
192
|
+
* If not provided, a serializer will be created using the provided client and the rollup HTTP endpoint.
|
|
188
193
|
*/
|
|
189
194
|
serializer?: RollupSerializer;
|
|
190
195
|
/**
|
|
@@ -192,6 +197,13 @@ type RollupConfig<C extends RollupContext> = {
|
|
|
192
197
|
*/
|
|
193
198
|
context: C;
|
|
194
199
|
};
|
|
200
|
+
/**
|
|
201
|
+
* Fully initialized rollup configuration.
|
|
202
|
+
*/
|
|
203
|
+
type RollupConfig<C extends RollupContext> = Omit<PartialRollupConfig<C>, "client" | "serializer"> & {
|
|
204
|
+
client: SovereignClient__default;
|
|
205
|
+
serializer: RollupSerializer;
|
|
206
|
+
};
|
|
195
207
|
/**
|
|
196
208
|
* The result of signing and submitting a transaction.
|
|
197
209
|
*
|
|
@@ -231,14 +243,10 @@ type CallParams<S extends BaseTypeSpec> = {
|
|
|
231
243
|
*/
|
|
232
244
|
declare class Rollup<S extends BaseTypeSpec, C extends RollupContext> {
|
|
233
245
|
private readonly _config;
|
|
234
|
-
private readonly _client;
|
|
235
|
-
private readonly _serializer;
|
|
236
246
|
private readonly _typeBuilder;
|
|
237
247
|
/**
|
|
238
248
|
* Creates a new rollup client.
|
|
239
249
|
*
|
|
240
|
-
* @throws {@link InvalidRollupConfigError} - If no schema or serializer is provided.
|
|
241
|
-
*
|
|
242
250
|
* @param config - The configuration for the rollup client.
|
|
243
251
|
* @param typeBuilder - The type builder for the rollup.
|
|
244
252
|
*/
|
|
@@ -299,6 +307,10 @@ declare class Rollup<S extends BaseTypeSpec, C extends RollupContext> {
|
|
|
299
307
|
* The context for the rollup.
|
|
300
308
|
*/
|
|
301
309
|
get context(): C;
|
|
310
|
+
/**
|
|
311
|
+
* The chain hash of the rollup.
|
|
312
|
+
*/
|
|
313
|
+
get chainHash(): Uint8Array;
|
|
302
314
|
}
|
|
303
315
|
|
|
304
316
|
type TxDetails = {
|
|
@@ -353,7 +365,7 @@ declare class StandardRollup<RuntimeCall> extends Rollup<StandardRollupSpec<Runt
|
|
|
353
365
|
*/
|
|
354
366
|
simulate(runtimeMessage: StandardRollupSpec<RuntimeCall>["RuntimeCall"], { signer, txDetails, nonce: overrideNonce }: SimulateParams): Promise<SovereignClient__default.Rollup.SimulateExecutionResponse>;
|
|
355
367
|
}
|
|
356
|
-
declare function createStandardRollup<RuntimeCall, C extends StandardRollupContext = StandardRollupContext>(config:
|
|
368
|
+
declare function createStandardRollup<RuntimeCall, C extends StandardRollupContext = StandardRollupContext>(config: PartialRollupConfig<C>, typeBuilderOverrides?: Partial<TypeBuilder<StandardRollupSpec<RuntimeCall>, C>>): Promise<StandardRollup<RuntimeCall>>;
|
|
357
369
|
|
|
358
370
|
/**
|
|
359
371
|
* Base error class for Sovereign SDK Web3.
|
|
@@ -363,5 +375,15 @@ declare class SovereignError extends Error {
|
|
|
363
375
|
}
|
|
364
376
|
declare class InvalidRollupConfigError extends SovereignError {
|
|
365
377
|
}
|
|
378
|
+
declare class RollupInterfaceError extends SovereignError {
|
|
379
|
+
readonly method: string;
|
|
380
|
+
constructor(message: string, method: string);
|
|
381
|
+
}
|
|
382
|
+
declare class VersionMismatchError extends SovereignError {
|
|
383
|
+
readonly newVersion: string;
|
|
384
|
+
readonly currentVersion: string;
|
|
385
|
+
readonly retryable: boolean;
|
|
386
|
+
constructor(message: string, newVersion: string, currentVersion: string);
|
|
387
|
+
}
|
|
366
388
|
|
|
367
|
-
export { type BaseTypeSpec, type CallParams, type Dedup, InvalidRollupConfigError, Rollup, type RollupConfig, type RollupContext, type RollupSchema, type RollupSerializer, type RollupTypeSpec, type SignerParams, type SimulateParams, SovereignError, StandardRollup, type StandardRollupContext, type StandardRollupSpec, type Transaction, type TransactionContext, type TransactionResult, type TxDetails, type TypeBuilder, type UnsignedTransaction, type UnsignedTransactionContext, createSerializer, createStandardRollup, standardTypeBuilder };
|
|
389
|
+
export { type BaseTypeSpec, type CallParams, type Dedup, InvalidRollupConfigError, type PartialRollupConfig, Rollup, type RollupConfig, type RollupContext, RollupInterfaceError, type RollupSchema, type RollupSerializer, type RollupTypeSpec, type SignerParams, type SimulateParams, SovereignError, StandardRollup, type StandardRollupContext, type StandardRollupSpec, type Transaction, type TransactionContext, type TransactionResult, type TxDetails, type TypeBuilder, type UnsignedTransaction, type UnsignedTransactionContext, VersionMismatchError, createSerializer, createSerializerFromHttp, createStandardRollup, standardTypeBuilder };
|
package/dist/index.js
CHANGED
|
@@ -81,18 +81,20 @@ var src_exports = {};
|
|
|
81
81
|
__export(src_exports, {
|
|
82
82
|
InvalidRollupConfigError: () => InvalidRollupConfigError,
|
|
83
83
|
Rollup: () => Rollup,
|
|
84
|
+
RollupInterfaceError: () => RollupInterfaceError,
|
|
84
85
|
Schema: () => import_universal_wallet_wasm2.Schema,
|
|
85
86
|
SovereignClient: () => SovereignClient2,
|
|
86
87
|
SovereignError: () => SovereignError,
|
|
87
88
|
StandardRollup: () => StandardRollup,
|
|
89
|
+
VersionMismatchError: () => VersionMismatchError,
|
|
88
90
|
createSerializer: () => createSerializer,
|
|
91
|
+
createSerializerFromHttp: () => createSerializerFromHttp,
|
|
89
92
|
createStandardRollup: () => createStandardRollup,
|
|
90
93
|
standardTypeBuilder: () => standardTypeBuilder
|
|
91
94
|
});
|
|
92
95
|
module.exports = __toCommonJS(src_exports);
|
|
93
96
|
|
|
94
97
|
// src/rollup/rollup.ts
|
|
95
|
-
var import_client = __toESM(require("@sovereign-sdk/client"));
|
|
96
98
|
var import_utils = require("@sovereign-sdk/utils");
|
|
97
99
|
var import_js_base64 = require("js-base64");
|
|
98
100
|
|
|
@@ -106,6 +108,20 @@ var SovereignError = class extends Error {
|
|
|
106
108
|
};
|
|
107
109
|
var InvalidRollupConfigError = class extends SovereignError {
|
|
108
110
|
};
|
|
111
|
+
var RollupInterfaceError = class extends SovereignError {
|
|
112
|
+
constructor(message, method) {
|
|
113
|
+
super(message);
|
|
114
|
+
this.method = method;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var VersionMismatchError = class extends SovereignError {
|
|
118
|
+
constructor(message, newVersion, currentVersion) {
|
|
119
|
+
super(message);
|
|
120
|
+
this.newVersion = newVersion;
|
|
121
|
+
this.currentVersion = currentVersion;
|
|
122
|
+
this.retryable = newVersion !== currentVersion;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
109
125
|
|
|
110
126
|
// src/serialization.ts
|
|
111
127
|
var import_universal_wallet_wasm = require("@sovereign-sdk/universal-wallet-wasm");
|
|
@@ -119,6 +135,7 @@ function loadSchema(schemaObject) {
|
|
|
119
135
|
function createSerializer(schemaObject) {
|
|
120
136
|
const schema = loadSchema(schemaObject);
|
|
121
137
|
return {
|
|
138
|
+
schema,
|
|
122
139
|
serialize(input, index) {
|
|
123
140
|
try {
|
|
124
141
|
return schema.jsonToBorsh(
|
|
@@ -154,30 +171,28 @@ function createSerializer(schemaObject) {
|
|
|
154
171
|
}
|
|
155
172
|
};
|
|
156
173
|
}
|
|
174
|
+
function createSerializerFromHttp(client) {
|
|
175
|
+
return __async(this, null, function* () {
|
|
176
|
+
const { data: schema } = yield client.rollup.schema.retrieve();
|
|
177
|
+
if (!schema) {
|
|
178
|
+
throw new RollupInterfaceError(
|
|
179
|
+
"Endpoint returned empty response",
|
|
180
|
+
"schema"
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return createSerializer(schema);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
157
186
|
|
|
158
187
|
// src/rollup/rollup.ts
|
|
159
188
|
var Rollup = class {
|
|
160
189
|
/**
|
|
161
190
|
* Creates a new rollup client.
|
|
162
191
|
*
|
|
163
|
-
* @throws {@link InvalidRollupConfigError} - If no schema or serializer is provided.
|
|
164
|
-
*
|
|
165
192
|
* @param config - The configuration for the rollup client.
|
|
166
193
|
* @param typeBuilder - The type builder for the rollup.
|
|
167
194
|
*/
|
|
168
195
|
constructor(config, typeBuilder) {
|
|
169
|
-
var _a;
|
|
170
|
-
if (config.serializer) {
|
|
171
|
-
this._serializer = config.serializer;
|
|
172
|
-
} else {
|
|
173
|
-
if (!config.schema) {
|
|
174
|
-
throw new InvalidRollupConfigError(
|
|
175
|
-
"At least 1 of config.schema or config.serializer must be provided"
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
this._serializer = createSerializer(config.schema);
|
|
179
|
-
}
|
|
180
|
-
this._client = (_a = config.client) != null ? _a : new import_client.default({ baseURL: config.url });
|
|
181
196
|
this._config = config;
|
|
182
197
|
this._typeBuilder = typeBuilder;
|
|
183
198
|
}
|
|
@@ -188,8 +203,16 @@ var Rollup = class {
|
|
|
188
203
|
*/
|
|
189
204
|
dedup(address) {
|
|
190
205
|
return __async(this, null, function* () {
|
|
191
|
-
const
|
|
192
|
-
|
|
206
|
+
const { data: dedup } = yield this.rollup.addresses.dedup(
|
|
207
|
+
(0, import_utils.bytesToHex)(address)
|
|
208
|
+
);
|
|
209
|
+
if (dedup === void 0) {
|
|
210
|
+
throw new RollupInterfaceError(
|
|
211
|
+
"Endpoint returned empty response",
|
|
212
|
+
"dedup"
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
return dedup;
|
|
193
216
|
});
|
|
194
217
|
}
|
|
195
218
|
/**
|
|
@@ -200,9 +223,21 @@ var Rollup = class {
|
|
|
200
223
|
submitTransaction(transaction) {
|
|
201
224
|
return __async(this, null, function* () {
|
|
202
225
|
const serializedTx = this.serializer.serializeTx(transaction);
|
|
203
|
-
return this.sequencer.txs.create({
|
|
204
|
-
|
|
205
|
-
|
|
226
|
+
return this.sequencer.txs.create({ body: import_js_base64.Base64.fromUint8Array(serializedTx) }).catch((e) => __async(this, null, function* () {
|
|
227
|
+
if (isVersionMismatchError(e)) {
|
|
228
|
+
const oldVersion = (0, import_utils.bytesToHex)(this.chainHash);
|
|
229
|
+
this._config.serializer = yield createSerializerFromHttp(this.http);
|
|
230
|
+
const newVersion = (0, import_utils.bytesToHex)(this.chainHash);
|
|
231
|
+
if (oldVersion !== newVersion) {
|
|
232
|
+
throw new VersionMismatchError(
|
|
233
|
+
"Schema version mismatch when submitting transaction",
|
|
234
|
+
newVersion,
|
|
235
|
+
oldVersion
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
throw e;
|
|
240
|
+
}));
|
|
206
241
|
});
|
|
207
242
|
}
|
|
208
243
|
/**
|
|
@@ -274,7 +309,7 @@ var Rollup = class {
|
|
|
274
309
|
* if the operation is not supported by `ledger`, `sequencer`, or `rollup` clients.
|
|
275
310
|
*/
|
|
276
311
|
get http() {
|
|
277
|
-
return this.
|
|
312
|
+
return this._config.client;
|
|
278
313
|
}
|
|
279
314
|
/**
|
|
280
315
|
* The serializer for the rollup.
|
|
@@ -282,7 +317,7 @@ var Rollup = class {
|
|
|
282
317
|
* See {@link RollupSerializer} for more information.
|
|
283
318
|
*/
|
|
284
319
|
get serializer() {
|
|
285
|
-
return this.
|
|
320
|
+
return this._config.serializer;
|
|
286
321
|
}
|
|
287
322
|
/**
|
|
288
323
|
* The context for the rollup.
|
|
@@ -290,9 +325,28 @@ var Rollup = class {
|
|
|
290
325
|
get context() {
|
|
291
326
|
return this._config.context;
|
|
292
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* The chain hash of the rollup.
|
|
330
|
+
*/
|
|
331
|
+
get chainHash() {
|
|
332
|
+
return this.serializer.schema.chainHash;
|
|
333
|
+
}
|
|
293
334
|
};
|
|
335
|
+
function isVersionMismatchError(e) {
|
|
336
|
+
var _a, _b, _c;
|
|
337
|
+
if (
|
|
338
|
+
// biome-ignore lint/suspicious/noExplicitAny: yolo
|
|
339
|
+
(_c = (_b = (_a = e.error) == null ? void 0 : _a.errors[0]) == null ? void 0 : _b.details) == null ? void 0 : _c.message.includes(
|
|
340
|
+
"Signature verification failed"
|
|
341
|
+
)
|
|
342
|
+
) {
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
294
347
|
|
|
295
348
|
// src/rollup/standard-rollup.ts
|
|
349
|
+
var import_client = __toESM(require("@sovereign-sdk/client"));
|
|
296
350
|
var import_utils2 = require("@sovereign-sdk/utils");
|
|
297
351
|
var useOrFetchNonce = (_0) => __async(void 0, [_0], function* ({
|
|
298
352
|
sender,
|
|
@@ -302,8 +356,8 @@ var useOrFetchNonce = (_0) => __async(void 0, [_0], function* ({
|
|
|
302
356
|
if ((overrides == null ? void 0 : overrides.nonce) !== void 0 && overrides.nonce >= 0) {
|
|
303
357
|
return overrides.nonce;
|
|
304
358
|
}
|
|
305
|
-
const
|
|
306
|
-
return
|
|
359
|
+
const dedup = yield rollup.dedup(sender);
|
|
360
|
+
return dedup.nonce;
|
|
307
361
|
});
|
|
308
362
|
function standardTypeBuilder() {
|
|
309
363
|
return {
|
|
@@ -371,7 +425,15 @@ var StandardRollup = class extends Rollup {
|
|
|
371
425
|
}
|
|
372
426
|
};
|
|
373
427
|
function createStandardRollup(config, typeBuilderOverrides) {
|
|
374
|
-
return
|
|
428
|
+
return __async(this, null, function* () {
|
|
429
|
+
var _a, _b;
|
|
430
|
+
const client = (_a = config.client) != null ? _a : new import_client.default({ baseURL: config.url });
|
|
431
|
+
const serializer = (_b = config.serializer) != null ? _b : yield createSerializerFromHttp(client);
|
|
432
|
+
return new StandardRollup(
|
|
433
|
+
__spreadProps(__spreadValues({}, config), { client, serializer }),
|
|
434
|
+
__spreadValues(__spreadValues({}, standardTypeBuilder()), typeBuilderOverrides)
|
|
435
|
+
);
|
|
436
|
+
});
|
|
375
437
|
}
|
|
376
438
|
|
|
377
439
|
// src/index.ts
|
|
@@ -381,11 +443,14 @@ var import_universal_wallet_wasm2 = require("@sovereign-sdk/universal-wallet-was
|
|
|
381
443
|
0 && (module.exports = {
|
|
382
444
|
InvalidRollupConfigError,
|
|
383
445
|
Rollup,
|
|
446
|
+
RollupInterfaceError,
|
|
384
447
|
Schema,
|
|
385
448
|
SovereignClient,
|
|
386
449
|
SovereignError,
|
|
387
450
|
StandardRollup,
|
|
451
|
+
VersionMismatchError,
|
|
388
452
|
createSerializer,
|
|
453
|
+
createSerializerFromHttp,
|
|
389
454
|
createStandardRollup,
|
|
390
455
|
standardTypeBuilder
|
|
391
456
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/rollup/rollup.ts","../src/errors.ts","../src/serialization.ts","../src/rollup/standard-rollup.ts"],"sourcesContent":["export * from \"./rollup\";\nexport * from \"./serialization\";\nexport * from \"./errors\";\nexport * from \"./type-spec\";\nexport * as SovereignClient from \"@sovereign-sdk/client\";\nexport { Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\n","import SovereignClient from \"@sovereign-sdk/client\";\nimport type { Signer } from \"@sovereign-sdk/signers\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport { Base64 } from \"js-base64\";\nimport { InvalidRollupConfigError } from \"../errors\";\nimport {\n type RollupSchema,\n type RollupSerializer,\n createSerializer,\n} from \"../serialization\";\nimport type { BaseTypeSpec } from \"../type-spec\";\nimport type { DeepPartial } from \"../utils\";\n\nexport type UnsignedTransactionContext<\n S extends BaseTypeSpec,\n C extends RollupContext,\n> = {\n runtimeCall: S[\"RuntimeCall\"];\n sender: Uint8Array;\n // able to override nonce\n overrides: DeepPartial<S[\"UnsignedTransaction\"]>;\n rollup: Rollup<S, C>;\n};\n\nexport type TransactionContext<\n S extends BaseTypeSpec,\n C extends RollupContext,\n> = {\n unsignedTx: S[\"UnsignedTransaction\"];\n sender: Uint8Array;\n signature: Uint8Array;\n rollup: Rollup<S, C>;\n};\n\nexport type TypeBuilder<S extends BaseTypeSpec, C extends RollupContext> = {\n unsignedTransaction: (\n context: UnsignedTransactionContext<S, C>,\n ) => Promise<S[\"UnsignedTransaction\"]>;\n\n transaction: (context: TransactionContext<S, C>) => Promise<S[\"Transaction\"]>;\n};\n\n/**\n * Arbitrary context that is associated with the rollup.\n */\nexport type RollupContext = Record<string, unknown>;\n\n/**\n * The configuration for a rollup client.\n */\nexport type RollupConfig<C extends RollupContext> = {\n /**\n * The base URL of the rollup full node API.\n */\n url?: string;\n /**\n * The Sovereign SDK client to use for the rollup.\n * If not provided, the default client will be used using {@link RollupConfig.url}.\n */\n client?: SovereignClient;\n /**\n * The schema of the rollup.\n */\n schema?: RollupSchema;\n /**\n * The serializer to use for the rollup.\n * If not provided, a serializer will be created using the provided {@link RollupConfig.schema}.\n */\n serializer?: RollupSerializer;\n /**\n * Arbitrary context that is associated with the rollup.\n */\n context: C;\n};\n\n/**\n * The result of signing and submitting a transaction.\n *\n * @template Tx The type of the transaction\n */\nexport type TransactionResult<Tx> = {\n /**\n * The response from the sequencer.\n */\n response: SovereignClient.Sequencer.TxCreateResponse;\n /**\n * The transaction that was submitted.\n */\n transaction: Tx;\n};\n\n/**\n * The parameters for signing and submitting a transaction.\n */\nexport type SignerParams = {\n /**\n * The signer to use for signing the transaction.\n */\n signer: Signer;\n};\n\n/**\n * The parameters for calling executing a runtime call transaction.\n */\nexport type CallParams<S extends BaseTypeSpec> = {\n overrides?: DeepPartial<S[\"UnsignedTransaction\"]>;\n} & SignerParams;\n\n/**\n * A generic rollup client.\n *\n * @template S - The type specification for the rollup.\n * If not provided, the base type specification will be used which uses `any` for all types.\n * @template C - The context for the rollup.\n */\nexport class Rollup<S extends BaseTypeSpec, C extends RollupContext> {\n private readonly _config: RollupConfig<C>;\n private readonly _client: SovereignClient;\n private readonly _serializer: RollupSerializer;\n private readonly _typeBuilder: TypeBuilder<S, C>;\n\n /**\n * Creates a new rollup client.\n *\n * @throws {@link InvalidRollupConfigError} - If no schema or serializer is provided.\n *\n * @param config - The configuration for the rollup client.\n * @param typeBuilder - The type builder for the rollup.\n */\n constructor(config: RollupConfig<C>, typeBuilder: TypeBuilder<S, C>) {\n if (config.serializer) {\n this._serializer = config.serializer;\n } else {\n if (!config.schema) {\n throw new InvalidRollupConfigError(\n \"At least 1 of config.schema or config.serializer must be provided\",\n );\n }\n this._serializer = createSerializer(config.schema);\n }\n\n this._client =\n config.client ?? new SovereignClient({ baseURL: config.url });\n this._config = config;\n this._typeBuilder = typeBuilder;\n }\n\n /**\n * Retrieve dedup information about the provided address.\n *\n * @param address - The public key to dedup.\n */\n async dedup(address: Uint8Array): Promise<S[\"Dedup\"]> {\n const response = await this.rollup.addresses.dedup(bytesToHex(address));\n return response.data as S[\"Dedup\"];\n }\n\n /**\n * Submits a transaction to the rollup.\n *\n * @param transaction - The transaction to submit.\n */\n async submitTransaction(\n transaction: S[\"Transaction\"],\n ): Promise<SovereignClient.Sequencer.TxCreateResponse> {\n const serializedTx = this.serializer.serializeTx(transaction);\n\n return this.sequencer.txs.create({\n body: Base64.fromUint8Array(serializedTx),\n });\n }\n\n /**\n * Signs and submits a transaction to the rollup.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param unsignedTx - The unsigned transaction to sign and submit.\n * @param {SignerParams} params - The params for signing and submitting the transaction.\n */\n async signAndSubmitTransaction(\n unsignedTx: S[\"UnsignedTransaction\"],\n { signer }: SignerParams,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const serializedUnsignedTx =\n this.serializer.serializeUnsignedTx(unsignedTx);\n const signature = await signer.sign(serializedUnsignedTx);\n const publicKey = await signer.publicKey();\n const context = {\n unsignedTx,\n sender: publicKey,\n signature,\n rollup: this,\n };\n const tx = await this._typeBuilder.transaction(context);\n const result = await this.submitTransaction(tx);\n\n return { transaction: tx, response: result };\n }\n\n /**\n * Performs a runtime call transaction.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param runtimeCall - The runtime message to call.\n * @param {CallParams<S>} params - The params for submitting a runtime call transaction.\n */\n async call(\n runtimeCall: S[\"RuntimeCall\"],\n { signer, overrides }: CallParams<S>,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const publicKey = await signer.publicKey();\n const context = {\n runtimeCall,\n sender: publicKey,\n rollup: this,\n overrides: overrides ?? ({} as DeepPartial<S[\"UnsignedTransaction\"]>),\n };\n const unsignedTx = await this._typeBuilder.unsignedTransaction(context);\n\n return this.signAndSubmitTransaction(unsignedTx, {\n signer,\n });\n }\n\n /**\n * A ledger client that can be used to query the ledger.\n */\n get ledger(): SovereignClient.Ledger {\n return this.http.ledger;\n }\n\n /**\n * A sequencer client that can be used to submit transactions & batches to the rollup.\n */\n get sequencer(): SovereignClient.Sequencer {\n return this.http.sequencer;\n }\n\n /**\n * A rollup client that can be used to perform operations on the rollup.\n */\n get rollup(): SovereignClient.Rollup {\n return this.http.rollup;\n }\n\n /**\n * A client that can be used to perform HTTP requests to the Sovereign API.\n * This can be used as an escape hatch to execute arbitrary requests to the Sovereign API\n * if the operation is not supported by `ledger`, `sequencer`, or `rollup` clients.\n */\n get http(): SovereignClient {\n return this._client;\n }\n\n /**\n * The serializer for the rollup.\n * Can be used to serialize transactions, runtime calls, etc.\n * See {@link RollupSerializer} for more information.\n */\n get serializer(): RollupSerializer {\n return this._serializer;\n }\n\n /**\n * The context for the rollup.\n */\n get context(): C {\n return this._config.context;\n }\n}\n","/**\n * Base error class for Sovereign SDK Web3.\n */\nexport class SovereignError extends Error {\n constructor(message: string) {\n super(message);\n\n this.name = this.constructor.name;\n this.stack = new Error().stack;\n }\n}\n\nexport class InvalidRollupConfigError extends SovereignError {}\n","import { KnownTypeId, Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\nimport { SovereignError } from \"./errors\";\n\n/**\n * A rollup schema is a description of the types that are utilized in the rollup.\n * It is used to serialize and deserialize the types.\n * As well as display them in a human-readable way that is verified by the rollup.\n */\nexport type RollupSchema = object;\n\n/**\n * A serializer is used to serialize rollup types to Borsh bytes.\n *\n * @example\n * ```typescript\n * const serializer = createSerializer(yourSchema);\n * const runtimeCall = {\n * value_setter: {\n * set_value: 100,\n * },\n * };\n * const borshBytes = serializer.serializeRuntimeCall(runtimeCall);\n * ```\n */\nexport type RollupSerializer = {\n /**\n * Serialize an input to Borsh bytes.\n *\n * Treats `Uint8Array` as a plain array of numbers as this is the format used by universal-wallet-wasm\n * to represent Borsh bytes.\n *\n * @param input - The input to serialize.\n * @param index - The index of the type in the schema to serialize.\n * @returns The serialized Borsh bytes.\n */\n serialize(input: unknown, index: number): Uint8Array;\n\n /**\n * Serialize a runtime call to Borsh bytes.\n *\n * @param input - The runtime call to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeRuntimeCall(input: unknown): Uint8Array;\n\n /**\n * Serialize an unsigned transaction to Borsh bytes.\n *\n * @param input - The unsigned transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeUnsignedTx(input: unknown): Uint8Array;\n\n /**\n * Serialize a transaction to Borsh bytes.\n *\n * @param input - The transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeTx(input: unknown): Uint8Array;\n};\n\nfunction loadSchema(schemaObject: RollupSchema): Schema {\n try {\n return Schema.fromJSON(JSON.stringify(schemaObject));\n } catch (err) {\n throw new SovereignError(`Failed to create runtime schema due to: ${err}`);\n }\n}\n\n/**\n * Create a serializer for a rollup schema.\n *\n * @throws {@link SovereignError} - If the schema is invalid.\n * @param schemaObject - The rollup schema.\n * @returns The serializer.\n */\nexport function createSerializer(schemaObject: RollupSchema): RollupSerializer {\n const schema = loadSchema(schemaObject);\n\n return {\n serialize(input: unknown, index: number): Uint8Array {\n try {\n return schema.jsonToBorsh(\n index,\n JSON.stringify(input, (_, value) => {\n if (value instanceof Uint8Array) {\n return Array.from(value);\n }\n return value;\n }),\n );\n } catch (err) {\n throw new SovereignError(`Failed to serialize input due to: ${err}`);\n }\n },\n serializeRuntimeCall(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.RuntimeCall),\n );\n },\n serializeUnsignedTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.UnsignedTransaction),\n );\n },\n serializeTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.Transaction),\n );\n },\n };\n}\n","import type SovereignClient from \"@sovereign-sdk/client\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport {\n Rollup,\n type RollupConfig,\n type SignerParams,\n type TransactionContext,\n type TypeBuilder,\n type UnsignedTransactionContext,\n} from \"./rollup\";\n\nexport type TxDetails = {\n max_priority_fee_bips: number;\n max_fee: number;\n gas_limit: number[] | null;\n chain_id: number;\n};\n\nexport type UnsignedTransaction<RuntimeCall> = {\n runtime_call: RuntimeCall;\n nonce: number;\n details: TxDetails;\n};\n\nexport type Transaction<RuntimeCall> = {\n pub_key: { pub_key: Uint8Array };\n signature: { msg_sig: Uint8Array };\n} & UnsignedTransaction<RuntimeCall>;\n\nexport type Dedup = {\n nonce: number;\n};\n\nexport type StandardRollupContext = {\n defaultTxDetails: TxDetails;\n};\n\nexport type StandardRollupSpec<RuntimeCall> = {\n UnsignedTransaction: UnsignedTransaction<RuntimeCall>;\n Transaction: Transaction<RuntimeCall>;\n RuntimeCall: RuntimeCall;\n Dedup: Dedup;\n};\n\nconst useOrFetchNonce = async <S extends StandardRollupSpec<unknown>>({\n sender,\n rollup,\n overrides,\n}: Omit<\n UnsignedTransactionContext<S, StandardRollupContext>,\n \"runtimeCall\"\n>) => {\n if (overrides?.nonce !== undefined && overrides.nonce >= 0) {\n return overrides.nonce;\n }\n const { data } = await rollup.rollup.addresses.dedup(bytesToHex(sender));\n\n return (data as S[\"Dedup\"]).nonce;\n};\n\nexport function standardTypeBuilder<\n S extends StandardRollupSpec<unknown>,\n>(): TypeBuilder<S, StandardRollupContext> {\n return {\n async unsignedTransaction(\n context: UnsignedTransactionContext<S, StandardRollupContext>,\n ) {\n const { rollup, runtimeCall } = context;\n const { nonce: _, ...overrides } = context.overrides;\n const nonce = await useOrFetchNonce(context);\n const details: TxDetails = {\n ...rollup.context.defaultTxDetails,\n ...overrides.details,\n };\n\n return {\n runtime_call: runtimeCall,\n nonce,\n details,\n };\n },\n async transaction({\n sender,\n signature,\n unsignedTx,\n }: TransactionContext<S, StandardRollupContext>) {\n return {\n pub_key: {\n pub_key: sender,\n },\n signature: {\n msg_sig: signature,\n },\n ...unsignedTx,\n };\n },\n };\n}\n\n/**\n * The parameters for simulating a runtime call transaction.\n */\nexport type SimulateParams = {\n /**\n * The transaction details to use for the simulation.\n */\n txDetails: TxDetails;\n\n nonce?: number;\n} & SignerParams;\n\nexport class StandardRollup<RuntimeCall> extends Rollup<\n StandardRollupSpec<RuntimeCall>,\n StandardRollupContext\n> {\n /**\n * Simulates a runtime call transaction.\n *\n * This method can be useful to estimate the gas cost of a runtime call transaction.\n *\n * @param runtimeMessage - The runtime message to call.\n */\n async simulate(\n runtimeMessage: StandardRollupSpec<RuntimeCall>[\"RuntimeCall\"],\n { signer, txDetails, nonce: overrideNonce }: SimulateParams,\n ): Promise<SovereignClient.Rollup.SimulateExecutionResponse> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const nonce = await useOrFetchNonce({\n sender: publicKey,\n rollup: this,\n overrides: { nonce: overrideNonce },\n });\n const response = await this.rollup.simulate({\n body: {\n details: {\n ...txDetails,\n // simulate needs this field as `undefined` currently\n gas_limit: txDetails.gas_limit || undefined,\n },\n encoded_call_message: bytesToHex(runtimeCall),\n nonce,\n sender_pub_key: bytesToHex(publicKey),\n },\n });\n\n // biome-ignore lint/style/noNonNullAssertion: fix later\n return response.data!;\n }\n}\n\nexport function createStandardRollup<\n RuntimeCall,\n C extends StandardRollupContext = StandardRollupContext,\n>(\n config: RollupConfig<C>,\n typeBuilderOverrides?: Partial<\n TypeBuilder<StandardRollupSpec<RuntimeCall>, C>\n >,\n) {\n return new StandardRollup<RuntimeCall>(config, {\n ...standardTypeBuilder(),\n ...typeBuilderOverrides,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA4B;AAE5B,mBAA2B;AAC3B,uBAAuB;;;ACAhB,IAAM,iBAAN,cAA6B,MAAM;AAAA,EACxC,YAAY,SAAiB;AAC3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ACJ;AACH;;;AJhKA,IAAAC,mBAAiC;AACjC,IAAAC,gCAAuB;","names":["SovereignClient","SovereignClient","import_utils","_a","SovereignClient","import_universal_wallet_wasm"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/rollup/rollup.ts","../src/errors.ts","../src/serialization.ts","../src/rollup/standard-rollup.ts"],"sourcesContent":["export * from \"./rollup\";\nexport * from \"./serialization\";\nexport * from \"./errors\";\nexport * from \"./type-spec\";\nexport * as SovereignClient from \"@sovereign-sdk/client\";\nexport { Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\n","import type SovereignClient from \"@sovereign-sdk/client\";\nimport type { APIError } from \"@sovereign-sdk/client\";\nimport type { Signer } from \"@sovereign-sdk/signers\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport { Base64 } from \"js-base64\";\nimport { RollupInterfaceError, VersionMismatchError } from \"../errors\";\nimport {\n type RollupSerializer,\n createSerializerFromHttp,\n} from \"../serialization\";\nimport type { BaseTypeSpec } from \"../type-spec\";\nimport type { DeepPartial } from \"../utils\";\n\nexport type UnsignedTransactionContext<\n S extends BaseTypeSpec,\n C extends RollupContext,\n> = {\n runtimeCall: S[\"RuntimeCall\"];\n sender: Uint8Array;\n // Provides the ability to override the nonce instead of retrieving it automatically.\n overrides: DeepPartial<S[\"UnsignedTransaction\"]>;\n rollup: Rollup<S, C>;\n};\n\nexport type TransactionContext<\n S extends BaseTypeSpec,\n C extends RollupContext,\n> = {\n unsignedTx: S[\"UnsignedTransaction\"];\n sender: Uint8Array;\n signature: Uint8Array;\n rollup: Rollup<S, C>;\n};\n\nexport type TypeBuilder<S extends BaseTypeSpec, C extends RollupContext> = {\n unsignedTransaction: (\n context: UnsignedTransactionContext<S, C>,\n ) => Promise<S[\"UnsignedTransaction\"]>;\n\n transaction: (context: TransactionContext<S, C>) => Promise<S[\"Transaction\"]>;\n};\n\n/**\n * Arbitrary context that is associated with the rollup.\n */\nexport type RollupContext = Record<string, unknown>;\n\n/**\n * The configuration for a rollup client.\n * This is a partial version of the configuration object, using a partial version\n * allows setup code to initialize fields automatically for SDK users, for example\n * fetching a `serializer` instance from the rollups endpoint.\n */\nexport type PartialRollupConfig<C extends RollupContext> = {\n /**\n * The base URL of the rollup full node API.\n */\n url?: string;\n /**\n * The Sovereign SDK client to use for the rollup.\n * If not provided, the default client will be used using {@link PartialRollupConfig.url}.\n */\n client?: SovereignClient;\n /**\n * The serializer to use for the rollup.\n * If not provided, a serializer will be created using the provided client and the rollup HTTP endpoint.\n */\n serializer?: RollupSerializer;\n /**\n * Arbitrary context that is associated with the rollup.\n */\n context: C;\n};\n\n/**\n * Fully initialized rollup configuration.\n */\nexport type RollupConfig<C extends RollupContext> = Omit<\n PartialRollupConfig<C>,\n \"client\" | \"serializer\"\n> & {\n client: SovereignClient;\n serializer: RollupSerializer;\n};\n\n/**\n * The result of signing and submitting a transaction.\n *\n * @template Tx The type of the transaction\n */\nexport type TransactionResult<Tx> = {\n /**\n * The response from the sequencer.\n */\n response: SovereignClient.Sequencer.TxCreateResponse;\n /**\n * The transaction that was submitted.\n */\n transaction: Tx;\n};\n\n/**\n * The parameters for signing and submitting a transaction.\n */\nexport type SignerParams = {\n /**\n * The signer to use for signing the transaction.\n */\n signer: Signer;\n};\n\n/**\n * The parameters for calling executing a runtime call transaction.\n */\nexport type CallParams<S extends BaseTypeSpec> = {\n overrides?: DeepPartial<S[\"UnsignedTransaction\"]>;\n} & SignerParams;\n\n/**\n * A generic rollup client.\n *\n * @template S - The type specification for the rollup.\n * If not provided, the base type specification will be used which uses `any` for all types.\n * @template C - The context for the rollup.\n */\nexport class Rollup<S extends BaseTypeSpec, C extends RollupContext> {\n private readonly _config: RollupConfig<C>;\n private readonly _typeBuilder: TypeBuilder<S, C>;\n\n /**\n * Creates a new rollup client.\n *\n * @param config - The configuration for the rollup client.\n * @param typeBuilder - The type builder for the rollup.\n */\n constructor(config: RollupConfig<C>, typeBuilder: TypeBuilder<S, C>) {\n this._config = config;\n this._typeBuilder = typeBuilder;\n }\n\n /**\n * Retrieve dedup information about the provided address.\n *\n * @param address - The public key to dedup.\n */\n async dedup(address: Uint8Array): Promise<S[\"Dedup\"]> {\n const { data: dedup } = await this.rollup.addresses.dedup(\n bytesToHex(address),\n );\n\n if (dedup === undefined) {\n throw new RollupInterfaceError(\n \"Endpoint returned empty response\",\n \"dedup\",\n );\n }\n\n return dedup as S[\"Dedup\"];\n }\n\n /**\n * Submits a transaction to the rollup.\n *\n * @param transaction - The transaction to submit.\n */\n async submitTransaction(\n transaction: S[\"Transaction\"],\n ): Promise<SovereignClient.Sequencer.TxCreateResponse> {\n const serializedTx = this.serializer.serializeTx(transaction);\n\n return this.sequencer.txs\n .create({ body: Base64.fromUint8Array(serializedTx) })\n .catch(async (e) => {\n if (isVersionMismatchError(e as APIError)) {\n const oldVersion = bytesToHex(this.chainHash);\n this._config.serializer = await createSerializerFromHttp(this.http);\n const newVersion = bytesToHex(this.chainHash);\n\n if (oldVersion !== newVersion) {\n throw new VersionMismatchError(\n \"Schema version mismatch when submitting transaction\",\n newVersion,\n oldVersion,\n );\n }\n }\n throw e;\n });\n }\n\n /**\n * Signs and submits a transaction to the rollup.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param unsignedTx - The unsigned transaction to sign and submit.\n * @param {SignerParams} params - The params for signing and submitting the transaction.\n */\n async signAndSubmitTransaction(\n unsignedTx: S[\"UnsignedTransaction\"],\n { signer }: SignerParams,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const serializedUnsignedTx =\n this.serializer.serializeUnsignedTx(unsignedTx);\n const signature = await signer.sign(serializedUnsignedTx);\n const publicKey = await signer.publicKey();\n const context = {\n unsignedTx,\n sender: publicKey,\n signature,\n rollup: this,\n };\n const tx = await this._typeBuilder.transaction(context);\n const result = await this.submitTransaction(tx);\n\n return { transaction: tx, response: result };\n }\n\n /**\n * Performs a runtime call transaction.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param runtimeCall - The runtime message to call.\n * @param {CallParams<S>} params - The params for submitting a runtime call transaction.\n */\n async call(\n runtimeCall: S[\"RuntimeCall\"],\n { signer, overrides }: CallParams<S>,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const publicKey = await signer.publicKey();\n const context = {\n runtimeCall,\n sender: publicKey,\n rollup: this,\n overrides: overrides ?? ({} as DeepPartial<S[\"UnsignedTransaction\"]>),\n };\n const unsignedTx = await this._typeBuilder.unsignedTransaction(context);\n\n return this.signAndSubmitTransaction(unsignedTx, {\n signer,\n });\n }\n\n /**\n * A ledger client that can be used to query the ledger.\n */\n get ledger(): SovereignClient.Ledger {\n return this.http.ledger;\n }\n\n /**\n * A sequencer client that can be used to submit transactions & batches to the rollup.\n */\n get sequencer(): SovereignClient.Sequencer {\n return this.http.sequencer;\n }\n\n /**\n * A rollup client that can be used to perform operations on the rollup.\n */\n get rollup(): SovereignClient.Rollup {\n return this.http.rollup;\n }\n\n /**\n * A client that can be used to perform HTTP requests to the Sovereign API.\n * This can be used as an escape hatch to execute arbitrary requests to the Sovereign API\n * if the operation is not supported by `ledger`, `sequencer`, or `rollup` clients.\n */\n get http(): SovereignClient {\n return this._config.client;\n }\n\n /**\n * The serializer for the rollup.\n * Can be used to serialize transactions, runtime calls, etc.\n * See {@link RollupSerializer} for more information.\n */\n get serializer(): RollupSerializer {\n return this._config.serializer;\n }\n\n /**\n * The context for the rollup.\n */\n get context(): C {\n return this._config.context;\n }\n\n /**\n * The chain hash of the rollup.\n */\n get chainHash(): Uint8Array {\n return this.serializer.schema.chainHash;\n }\n}\n\nfunction isVersionMismatchError(e: APIError): boolean {\n if (\n // biome-ignore lint/suspicious/noExplicitAny: yolo\n (e.error as any)?.errors[0]?.details?.message.includes(\n \"Signature verification failed\",\n )\n ) {\n return true;\n }\n\n return false;\n}\n","/**\n * Base error class for Sovereign SDK Web3.\n */\nexport class SovereignError extends Error {\n constructor(message: string) {\n super(message);\n\n this.name = this.constructor.name;\n this.stack = new Error().stack;\n }\n}\n\nexport class InvalidRollupConfigError extends SovereignError {}\n\nexport class RollupInterfaceError extends SovereignError {\n public readonly method: string;\n\n constructor(message: string, method: string) {\n super(message);\n\n this.method = method;\n }\n}\n\nexport class VersionMismatchError extends SovereignError {\n public readonly newVersion: string;\n public readonly currentVersion: string;\n public readonly retryable: boolean;\n\n constructor(message: string, newVersion: string, currentVersion: string) {\n super(message);\n\n this.newVersion = newVersion;\n this.currentVersion = currentVersion;\n this.retryable = newVersion !== currentVersion;\n }\n}\n","import type SovereignClient from \"@sovereign-sdk/client\";\nimport { KnownTypeId, Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\nimport { RollupInterfaceError, SovereignError } from \"./errors\";\n\n/**\n * A rollup schema is a description of the types that are utilized in the rollup.\n * It is used to serialize and deserialize the types.\n * As well as display them in a human-readable way that is verified by the rollup.\n */\nexport type RollupSchema = object;\n\n/**\n * A serializer is used to serialize rollup types to Borsh bytes.\n *\n * @example\n * ```typescript\n * const serializer = createSerializer(yourSchema);\n * const runtimeCall = {\n * value_setter: {\n * set_value: 100,\n * },\n * };\n * const borshBytes = serializer.serializeRuntimeCall(runtimeCall);\n * ```\n */\nexport type RollupSerializer = {\n /**\n * Serialize an input to Borsh bytes.\n *\n * Treats `Uint8Array` as a plain array of numbers as this is the format used by universal-wallet-wasm\n * to represent Borsh bytes.\n *\n * @param input - The input to serialize.\n * @param index - The index of the type in the schema to serialize.\n * @returns The serialized Borsh bytes.\n */\n serialize(input: unknown, index: number): Uint8Array;\n\n /**\n * Serialize a runtime call to Borsh bytes.\n *\n * @param input - The runtime call to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeRuntimeCall(input: unknown): Uint8Array;\n\n /**\n * Serialize an unsigned transaction to Borsh bytes.\n *\n * @param input - The unsigned transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeUnsignedTx(input: unknown): Uint8Array;\n\n /**\n * Serialize a transaction to Borsh bytes.\n *\n * @param input - The transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeTx(input: unknown): Uint8Array;\n\n /**\n * Returns the `Schema` used by the serializer.\n */\n get schema(): Schema;\n};\n\nfunction loadSchema(schemaObject: RollupSchema): Schema {\n try {\n return Schema.fromJSON(JSON.stringify(schemaObject));\n } catch (err) {\n throw new SovereignError(`Failed to create runtime schema due to: ${err}`);\n }\n}\n\n/**\n * Create a serializer for a rollup schema.\n *\n * @throws {@link SovereignError} - If the schema is invalid.\n * @param schemaObject - The rollup schema.\n * @returns The serializer.\n */\nexport function createSerializer(schemaObject: RollupSchema): RollupSerializer {\n const schema = loadSchema(schemaObject);\n\n return {\n schema,\n serialize(input: unknown, index: number): Uint8Array {\n try {\n return schema.jsonToBorsh(\n index,\n JSON.stringify(input, (_, value) => {\n if (value instanceof Uint8Array) {\n return Array.from(value);\n }\n return value;\n }),\n );\n } catch (err) {\n throw new SovereignError(`Failed to serialize input due to: ${err}`);\n }\n },\n serializeRuntimeCall(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.RuntimeCall),\n );\n },\n serializeUnsignedTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.UnsignedTransaction),\n );\n },\n serializeTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.Transaction),\n );\n },\n };\n}\n\nexport async function createSerializerFromHttp(\n client: SovereignClient,\n): Promise<RollupSerializer> {\n const { data: schema } = await client.rollup.schema.retrieve();\n\n if (!schema) {\n throw new RollupInterfaceError(\n \"Endpoint returned empty response\",\n \"schema\",\n );\n }\n\n return createSerializer(schema as RollupSchema);\n}\n","import SovereignClient from \"@sovereign-sdk/client\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport { createSerializerFromHttp } from \"../serialization\";\nimport {\n type PartialRollupConfig,\n Rollup,\n type SignerParams,\n type TransactionContext,\n type TypeBuilder,\n type UnsignedTransactionContext,\n} from \"./rollup\";\n\nexport type TxDetails = {\n max_priority_fee_bips: number;\n max_fee: number;\n gas_limit: number[] | null;\n chain_id: number;\n};\n\nexport type UnsignedTransaction<RuntimeCall> = {\n runtime_call: RuntimeCall;\n nonce: number;\n details: TxDetails;\n};\n\nexport type Transaction<RuntimeCall> = {\n pub_key: { pub_key: Uint8Array };\n signature: { msg_sig: Uint8Array };\n} & UnsignedTransaction<RuntimeCall>;\n\nexport type Dedup = {\n nonce: number;\n};\n\nexport type StandardRollupContext = {\n defaultTxDetails: TxDetails;\n};\n\nexport type StandardRollupSpec<RuntimeCall> = {\n UnsignedTransaction: UnsignedTransaction<RuntimeCall>;\n Transaction: Transaction<RuntimeCall>;\n RuntimeCall: RuntimeCall;\n Dedup: Dedup;\n};\n\nconst useOrFetchNonce = async <S extends StandardRollupSpec<unknown>>({\n sender,\n rollup,\n overrides,\n}: Omit<\n UnsignedTransactionContext<S, StandardRollupContext>,\n \"runtimeCall\"\n>) => {\n if (overrides?.nonce !== undefined && overrides.nonce >= 0) {\n return overrides.nonce;\n }\n const dedup = await rollup.dedup(sender);\n\n return dedup.nonce;\n};\n\nexport function standardTypeBuilder<\n S extends StandardRollupSpec<unknown>,\n>(): TypeBuilder<S, StandardRollupContext> {\n return {\n async unsignedTransaction(\n context: UnsignedTransactionContext<S, StandardRollupContext>,\n ) {\n const { rollup, runtimeCall } = context;\n const { nonce: _, ...overrides } = context.overrides;\n const nonce = await useOrFetchNonce(context);\n const details: TxDetails = {\n ...rollup.context.defaultTxDetails,\n ...overrides.details,\n };\n\n return {\n runtime_call: runtimeCall,\n nonce,\n details,\n };\n },\n async transaction({\n sender,\n signature,\n unsignedTx,\n }: TransactionContext<S, StandardRollupContext>) {\n return {\n pub_key: {\n pub_key: sender,\n },\n signature: {\n msg_sig: signature,\n },\n ...unsignedTx,\n };\n },\n };\n}\n\n/**\n * The parameters for simulating a runtime call transaction.\n */\nexport type SimulateParams = {\n /**\n * The transaction details to use for the simulation.\n */\n txDetails: TxDetails;\n\n nonce?: number;\n} & SignerParams;\n\nexport class StandardRollup<RuntimeCall> extends Rollup<\n StandardRollupSpec<RuntimeCall>,\n StandardRollupContext\n> {\n /**\n * Simulates a runtime call transaction.\n *\n * This method can be useful to estimate the gas cost of a runtime call transaction.\n *\n * @param runtimeMessage - The runtime message to call.\n */\n async simulate(\n runtimeMessage: StandardRollupSpec<RuntimeCall>[\"RuntimeCall\"],\n { signer, txDetails, nonce: overrideNonce }: SimulateParams,\n ): Promise<SovereignClient.Rollup.SimulateExecutionResponse> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const nonce = await useOrFetchNonce({\n sender: publicKey,\n rollup: this,\n overrides: { nonce: overrideNonce },\n });\n const response = await this.rollup.simulate({\n body: {\n details: {\n ...txDetails,\n // simulate needs this field as `undefined` currently\n gas_limit: txDetails.gas_limit || undefined,\n },\n encoded_call_message: bytesToHex(runtimeCall),\n nonce,\n sender_pub_key: bytesToHex(publicKey),\n },\n });\n\n // biome-ignore lint/style/noNonNullAssertion: fix later\n return response.data!;\n }\n}\n\nexport async function createStandardRollup<\n RuntimeCall,\n C extends StandardRollupContext = StandardRollupContext,\n>(\n config: PartialRollupConfig<C>,\n typeBuilderOverrides?: Partial<\n TypeBuilder<StandardRollupSpec<RuntimeCall>, C>\n >,\n) {\n const client = config.client ?? new SovereignClient({ baseURL: config.url });\n const serializer =\n config.serializer ?? (await createSerializerFromHttp(client));\n\n return new StandardRollup<RuntimeCall>(\n { ...config, client, serializer },\n {\n ...standardTypeBuilder(),\n ...typeBuilderOverrides,\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,mBAA2B;AAC3B,uBAAuB;;;ACDhB,IAAM,iBAAN,cAA6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C,gCAAuB;","names":["SovereignClient","import_utils","_a","SovereignClient","SovereignClient","import_universal_wallet_wasm"]}
|
package/dist/index.mjs
CHANGED
|
@@ -51,7 +51,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
// src/rollup/rollup.ts
|
|
54
|
-
import SovereignClient from "@sovereign-sdk/client";
|
|
55
54
|
import { bytesToHex } from "@sovereign-sdk/utils";
|
|
56
55
|
import { Base64 } from "js-base64";
|
|
57
56
|
|
|
@@ -65,6 +64,20 @@ var SovereignError = class extends Error {
|
|
|
65
64
|
};
|
|
66
65
|
var InvalidRollupConfigError = class extends SovereignError {
|
|
67
66
|
};
|
|
67
|
+
var RollupInterfaceError = class extends SovereignError {
|
|
68
|
+
constructor(message, method) {
|
|
69
|
+
super(message);
|
|
70
|
+
this.method = method;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var VersionMismatchError = class extends SovereignError {
|
|
74
|
+
constructor(message, newVersion, currentVersion) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.newVersion = newVersion;
|
|
77
|
+
this.currentVersion = currentVersion;
|
|
78
|
+
this.retryable = newVersion !== currentVersion;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
68
81
|
|
|
69
82
|
// src/serialization.ts
|
|
70
83
|
import { KnownTypeId, Schema } from "@sovereign-sdk/universal-wallet-wasm";
|
|
@@ -78,6 +91,7 @@ function loadSchema(schemaObject) {
|
|
|
78
91
|
function createSerializer(schemaObject) {
|
|
79
92
|
const schema = loadSchema(schemaObject);
|
|
80
93
|
return {
|
|
94
|
+
schema,
|
|
81
95
|
serialize(input, index) {
|
|
82
96
|
try {
|
|
83
97
|
return schema.jsonToBorsh(
|
|
@@ -113,30 +127,28 @@ function createSerializer(schemaObject) {
|
|
|
113
127
|
}
|
|
114
128
|
};
|
|
115
129
|
}
|
|
130
|
+
function createSerializerFromHttp(client) {
|
|
131
|
+
return __async(this, null, function* () {
|
|
132
|
+
const { data: schema } = yield client.rollup.schema.retrieve();
|
|
133
|
+
if (!schema) {
|
|
134
|
+
throw new RollupInterfaceError(
|
|
135
|
+
"Endpoint returned empty response",
|
|
136
|
+
"schema"
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return createSerializer(schema);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
116
142
|
|
|
117
143
|
// src/rollup/rollup.ts
|
|
118
144
|
var Rollup = class {
|
|
119
145
|
/**
|
|
120
146
|
* Creates a new rollup client.
|
|
121
147
|
*
|
|
122
|
-
* @throws {@link InvalidRollupConfigError} - If no schema or serializer is provided.
|
|
123
|
-
*
|
|
124
148
|
* @param config - The configuration for the rollup client.
|
|
125
149
|
* @param typeBuilder - The type builder for the rollup.
|
|
126
150
|
*/
|
|
127
151
|
constructor(config, typeBuilder) {
|
|
128
|
-
var _a;
|
|
129
|
-
if (config.serializer) {
|
|
130
|
-
this._serializer = config.serializer;
|
|
131
|
-
} else {
|
|
132
|
-
if (!config.schema) {
|
|
133
|
-
throw new InvalidRollupConfigError(
|
|
134
|
-
"At least 1 of config.schema or config.serializer must be provided"
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
this._serializer = createSerializer(config.schema);
|
|
138
|
-
}
|
|
139
|
-
this._client = (_a = config.client) != null ? _a : new SovereignClient({ baseURL: config.url });
|
|
140
152
|
this._config = config;
|
|
141
153
|
this._typeBuilder = typeBuilder;
|
|
142
154
|
}
|
|
@@ -147,8 +159,16 @@ var Rollup = class {
|
|
|
147
159
|
*/
|
|
148
160
|
dedup(address) {
|
|
149
161
|
return __async(this, null, function* () {
|
|
150
|
-
const
|
|
151
|
-
|
|
162
|
+
const { data: dedup } = yield this.rollup.addresses.dedup(
|
|
163
|
+
bytesToHex(address)
|
|
164
|
+
);
|
|
165
|
+
if (dedup === void 0) {
|
|
166
|
+
throw new RollupInterfaceError(
|
|
167
|
+
"Endpoint returned empty response",
|
|
168
|
+
"dedup"
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return dedup;
|
|
152
172
|
});
|
|
153
173
|
}
|
|
154
174
|
/**
|
|
@@ -159,9 +179,21 @@ var Rollup = class {
|
|
|
159
179
|
submitTransaction(transaction) {
|
|
160
180
|
return __async(this, null, function* () {
|
|
161
181
|
const serializedTx = this.serializer.serializeTx(transaction);
|
|
162
|
-
return this.sequencer.txs.create({
|
|
163
|
-
|
|
164
|
-
|
|
182
|
+
return this.sequencer.txs.create({ body: Base64.fromUint8Array(serializedTx) }).catch((e) => __async(this, null, function* () {
|
|
183
|
+
if (isVersionMismatchError(e)) {
|
|
184
|
+
const oldVersion = bytesToHex(this.chainHash);
|
|
185
|
+
this._config.serializer = yield createSerializerFromHttp(this.http);
|
|
186
|
+
const newVersion = bytesToHex(this.chainHash);
|
|
187
|
+
if (oldVersion !== newVersion) {
|
|
188
|
+
throw new VersionMismatchError(
|
|
189
|
+
"Schema version mismatch when submitting transaction",
|
|
190
|
+
newVersion,
|
|
191
|
+
oldVersion
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
throw e;
|
|
196
|
+
}));
|
|
165
197
|
});
|
|
166
198
|
}
|
|
167
199
|
/**
|
|
@@ -233,7 +265,7 @@ var Rollup = class {
|
|
|
233
265
|
* if the operation is not supported by `ledger`, `sequencer`, or `rollup` clients.
|
|
234
266
|
*/
|
|
235
267
|
get http() {
|
|
236
|
-
return this.
|
|
268
|
+
return this._config.client;
|
|
237
269
|
}
|
|
238
270
|
/**
|
|
239
271
|
* The serializer for the rollup.
|
|
@@ -241,7 +273,7 @@ var Rollup = class {
|
|
|
241
273
|
* See {@link RollupSerializer} for more information.
|
|
242
274
|
*/
|
|
243
275
|
get serializer() {
|
|
244
|
-
return this.
|
|
276
|
+
return this._config.serializer;
|
|
245
277
|
}
|
|
246
278
|
/**
|
|
247
279
|
* The context for the rollup.
|
|
@@ -249,9 +281,28 @@ var Rollup = class {
|
|
|
249
281
|
get context() {
|
|
250
282
|
return this._config.context;
|
|
251
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* The chain hash of the rollup.
|
|
286
|
+
*/
|
|
287
|
+
get chainHash() {
|
|
288
|
+
return this.serializer.schema.chainHash;
|
|
289
|
+
}
|
|
252
290
|
};
|
|
291
|
+
function isVersionMismatchError(e) {
|
|
292
|
+
var _a, _b, _c;
|
|
293
|
+
if (
|
|
294
|
+
// biome-ignore lint/suspicious/noExplicitAny: yolo
|
|
295
|
+
(_c = (_b = (_a = e.error) == null ? void 0 : _a.errors[0]) == null ? void 0 : _b.details) == null ? void 0 : _c.message.includes(
|
|
296
|
+
"Signature verification failed"
|
|
297
|
+
)
|
|
298
|
+
) {
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
253
303
|
|
|
254
304
|
// src/rollup/standard-rollup.ts
|
|
305
|
+
import SovereignClient from "@sovereign-sdk/client";
|
|
255
306
|
import { bytesToHex as bytesToHex2 } from "@sovereign-sdk/utils";
|
|
256
307
|
var useOrFetchNonce = (_0) => __async(void 0, [_0], function* ({
|
|
257
308
|
sender,
|
|
@@ -261,8 +312,8 @@ var useOrFetchNonce = (_0) => __async(void 0, [_0], function* ({
|
|
|
261
312
|
if ((overrides == null ? void 0 : overrides.nonce) !== void 0 && overrides.nonce >= 0) {
|
|
262
313
|
return overrides.nonce;
|
|
263
314
|
}
|
|
264
|
-
const
|
|
265
|
-
return
|
|
315
|
+
const dedup = yield rollup.dedup(sender);
|
|
316
|
+
return dedup.nonce;
|
|
266
317
|
});
|
|
267
318
|
function standardTypeBuilder() {
|
|
268
319
|
return {
|
|
@@ -330,7 +381,15 @@ var StandardRollup = class extends Rollup {
|
|
|
330
381
|
}
|
|
331
382
|
};
|
|
332
383
|
function createStandardRollup(config, typeBuilderOverrides) {
|
|
333
|
-
return
|
|
384
|
+
return __async(this, null, function* () {
|
|
385
|
+
var _a, _b;
|
|
386
|
+
const client = (_a = config.client) != null ? _a : new SovereignClient({ baseURL: config.url });
|
|
387
|
+
const serializer = (_b = config.serializer) != null ? _b : yield createSerializerFromHttp(client);
|
|
388
|
+
return new StandardRollup(
|
|
389
|
+
__spreadProps(__spreadValues({}, config), { client, serializer }),
|
|
390
|
+
__spreadValues(__spreadValues({}, standardTypeBuilder()), typeBuilderOverrides)
|
|
391
|
+
);
|
|
392
|
+
});
|
|
334
393
|
}
|
|
335
394
|
|
|
336
395
|
// src/index.ts
|
|
@@ -339,11 +398,14 @@ import { Schema as Schema2 } from "@sovereign-sdk/universal-wallet-wasm";
|
|
|
339
398
|
export {
|
|
340
399
|
InvalidRollupConfigError,
|
|
341
400
|
Rollup,
|
|
401
|
+
RollupInterfaceError,
|
|
342
402
|
Schema2 as Schema,
|
|
343
403
|
SovereignClient2 as SovereignClient,
|
|
344
404
|
SovereignError,
|
|
345
405
|
StandardRollup,
|
|
406
|
+
VersionMismatchError,
|
|
346
407
|
createSerializer,
|
|
408
|
+
createSerializerFromHttp,
|
|
347
409
|
createStandardRollup,
|
|
348
410
|
standardTypeBuilder
|
|
349
411
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rollup/rollup.ts","../src/errors.ts","../src/serialization.ts","../src/rollup/standard-rollup.ts","../src/index.ts"],"sourcesContent":["import SovereignClient from \"@sovereign-sdk/client\";\nimport type { Signer } from \"@sovereign-sdk/signers\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport { Base64 } from \"js-base64\";\nimport { InvalidRollupConfigError } from \"../errors\";\nimport {\n type RollupSchema,\n type RollupSerializer,\n createSerializer,\n} from \"../serialization\";\nimport type { BaseTypeSpec } from \"../type-spec\";\nimport type { DeepPartial } from \"../utils\";\n\nexport type UnsignedTransactionContext<\n S extends BaseTypeSpec,\n C extends RollupContext,\n> = {\n runtimeCall: S[\"RuntimeCall\"];\n sender: Uint8Array;\n // able to override nonce\n overrides: DeepPartial<S[\"UnsignedTransaction\"]>;\n rollup: Rollup<S, C>;\n};\n\nexport type TransactionContext<\n S extends BaseTypeSpec,\n C extends RollupContext,\n> = {\n unsignedTx: S[\"UnsignedTransaction\"];\n sender: Uint8Array;\n signature: Uint8Array;\n rollup: Rollup<S, C>;\n};\n\nexport type TypeBuilder<S extends BaseTypeSpec, C extends RollupContext> = {\n unsignedTransaction: (\n context: UnsignedTransactionContext<S, C>,\n ) => Promise<S[\"UnsignedTransaction\"]>;\n\n transaction: (context: TransactionContext<S, C>) => Promise<S[\"Transaction\"]>;\n};\n\n/**\n * Arbitrary context that is associated with the rollup.\n */\nexport type RollupContext = Record<string, unknown>;\n\n/**\n * The configuration for a rollup client.\n */\nexport type RollupConfig<C extends RollupContext> = {\n /**\n * The base URL of the rollup full node API.\n */\n url?: string;\n /**\n * The Sovereign SDK client to use for the rollup.\n * If not provided, the default client will be used using {@link RollupConfig.url}.\n */\n client?: SovereignClient;\n /**\n * The schema of the rollup.\n */\n schema?: RollupSchema;\n /**\n * The serializer to use for the rollup.\n * If not provided, a serializer will be created using the provided {@link RollupConfig.schema}.\n */\n serializer?: RollupSerializer;\n /**\n * Arbitrary context that is associated with the rollup.\n */\n context: C;\n};\n\n/**\n * The result of signing and submitting a transaction.\n *\n * @template Tx The type of the transaction\n */\nexport type TransactionResult<Tx> = {\n /**\n * The response from the sequencer.\n */\n response: SovereignClient.Sequencer.TxCreateResponse;\n /**\n * The transaction that was submitted.\n */\n transaction: Tx;\n};\n\n/**\n * The parameters for signing and submitting a transaction.\n */\nexport type SignerParams = {\n /**\n * The signer to use for signing the transaction.\n */\n signer: Signer;\n};\n\n/**\n * The parameters for calling executing a runtime call transaction.\n */\nexport type CallParams<S extends BaseTypeSpec> = {\n overrides?: DeepPartial<S[\"UnsignedTransaction\"]>;\n} & SignerParams;\n\n/**\n * A generic rollup client.\n *\n * @template S - The type specification for the rollup.\n * If not provided, the base type specification will be used which uses `any` for all types.\n * @template C - The context for the rollup.\n */\nexport class Rollup<S extends BaseTypeSpec, C extends RollupContext> {\n private readonly _config: RollupConfig<C>;\n private readonly _client: SovereignClient;\n private readonly _serializer: RollupSerializer;\n private readonly _typeBuilder: TypeBuilder<S, C>;\n\n /**\n * Creates a new rollup client.\n *\n * @throws {@link InvalidRollupConfigError} - If no schema or serializer is provided.\n *\n * @param config - The configuration for the rollup client.\n * @param typeBuilder - The type builder for the rollup.\n */\n constructor(config: RollupConfig<C>, typeBuilder: TypeBuilder<S, C>) {\n if (config.serializer) {\n this._serializer = config.serializer;\n } else {\n if (!config.schema) {\n throw new InvalidRollupConfigError(\n \"At least 1 of config.schema or config.serializer must be provided\",\n );\n }\n this._serializer = createSerializer(config.schema);\n }\n\n this._client =\n config.client ?? new SovereignClient({ baseURL: config.url });\n this._config = config;\n this._typeBuilder = typeBuilder;\n }\n\n /**\n * Retrieve dedup information about the provided address.\n *\n * @param address - The public key to dedup.\n */\n async dedup(address: Uint8Array): Promise<S[\"Dedup\"]> {\n const response = await this.rollup.addresses.dedup(bytesToHex(address));\n return response.data as S[\"Dedup\"];\n }\n\n /**\n * Submits a transaction to the rollup.\n *\n * @param transaction - The transaction to submit.\n */\n async submitTransaction(\n transaction: S[\"Transaction\"],\n ): Promise<SovereignClient.Sequencer.TxCreateResponse> {\n const serializedTx = this.serializer.serializeTx(transaction);\n\n return this.sequencer.txs.create({\n body: Base64.fromUint8Array(serializedTx),\n });\n }\n\n /**\n * Signs and submits a transaction to the rollup.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param unsignedTx - The unsigned transaction to sign and submit.\n * @param {SignerParams} params - The params for signing and submitting the transaction.\n */\n async signAndSubmitTransaction(\n unsignedTx: S[\"UnsignedTransaction\"],\n { signer }: SignerParams,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const serializedUnsignedTx =\n this.serializer.serializeUnsignedTx(unsignedTx);\n const signature = await signer.sign(serializedUnsignedTx);\n const publicKey = await signer.publicKey();\n const context = {\n unsignedTx,\n sender: publicKey,\n signature,\n rollup: this,\n };\n const tx = await this._typeBuilder.transaction(context);\n const result = await this.submitTransaction(tx);\n\n return { transaction: tx, response: result };\n }\n\n /**\n * Performs a runtime call transaction.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param runtimeCall - The runtime message to call.\n * @param {CallParams<S>} params - The params for submitting a runtime call transaction.\n */\n async call(\n runtimeCall: S[\"RuntimeCall\"],\n { signer, overrides }: CallParams<S>,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const publicKey = await signer.publicKey();\n const context = {\n runtimeCall,\n sender: publicKey,\n rollup: this,\n overrides: overrides ?? ({} as DeepPartial<S[\"UnsignedTransaction\"]>),\n };\n const unsignedTx = await this._typeBuilder.unsignedTransaction(context);\n\n return this.signAndSubmitTransaction(unsignedTx, {\n signer,\n });\n }\n\n /**\n * A ledger client that can be used to query the ledger.\n */\n get ledger(): SovereignClient.Ledger {\n return this.http.ledger;\n }\n\n /**\n * A sequencer client that can be used to submit transactions & batches to the rollup.\n */\n get sequencer(): SovereignClient.Sequencer {\n return this.http.sequencer;\n }\n\n /**\n * A rollup client that can be used to perform operations on the rollup.\n */\n get rollup(): SovereignClient.Rollup {\n return this.http.rollup;\n }\n\n /**\n * A client that can be used to perform HTTP requests to the Sovereign API.\n * This can be used as an escape hatch to execute arbitrary requests to the Sovereign API\n * if the operation is not supported by `ledger`, `sequencer`, or `rollup` clients.\n */\n get http(): SovereignClient {\n return this._client;\n }\n\n /**\n * The serializer for the rollup.\n * Can be used to serialize transactions, runtime calls, etc.\n * See {@link RollupSerializer} for more information.\n */\n get serializer(): RollupSerializer {\n return this._serializer;\n }\n\n /**\n * The context for the rollup.\n */\n get context(): C {\n return this._config.context;\n }\n}\n","/**\n * Base error class for Sovereign SDK Web3.\n */\nexport class SovereignError extends Error {\n constructor(message: string) {\n super(message);\n\n this.name = this.constructor.name;\n this.stack = new Error().stack;\n }\n}\n\nexport class InvalidRollupConfigError extends SovereignError {}\n","import { KnownTypeId, Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\nimport { SovereignError } from \"./errors\";\n\n/**\n * A rollup schema is a description of the types that are utilized in the rollup.\n * It is used to serialize and deserialize the types.\n * As well as display them in a human-readable way that is verified by the rollup.\n */\nexport type RollupSchema = object;\n\n/**\n * A serializer is used to serialize rollup types to Borsh bytes.\n *\n * @example\n * ```typescript\n * const serializer = createSerializer(yourSchema);\n * const runtimeCall = {\n * value_setter: {\n * set_value: 100,\n * },\n * };\n * const borshBytes = serializer.serializeRuntimeCall(runtimeCall);\n * ```\n */\nexport type RollupSerializer = {\n /**\n * Serialize an input to Borsh bytes.\n *\n * Treats `Uint8Array` as a plain array of numbers as this is the format used by universal-wallet-wasm\n * to represent Borsh bytes.\n *\n * @param input - The input to serialize.\n * @param index - The index of the type in the schema to serialize.\n * @returns The serialized Borsh bytes.\n */\n serialize(input: unknown, index: number): Uint8Array;\n\n /**\n * Serialize a runtime call to Borsh bytes.\n *\n * @param input - The runtime call to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeRuntimeCall(input: unknown): Uint8Array;\n\n /**\n * Serialize an unsigned transaction to Borsh bytes.\n *\n * @param input - The unsigned transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeUnsignedTx(input: unknown): Uint8Array;\n\n /**\n * Serialize a transaction to Borsh bytes.\n *\n * @param input - The transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeTx(input: unknown): Uint8Array;\n};\n\nfunction loadSchema(schemaObject: RollupSchema): Schema {\n try {\n return Schema.fromJSON(JSON.stringify(schemaObject));\n } catch (err) {\n throw new SovereignError(`Failed to create runtime schema due to: ${err}`);\n }\n}\n\n/**\n * Create a serializer for a rollup schema.\n *\n * @throws {@link SovereignError} - If the schema is invalid.\n * @param schemaObject - The rollup schema.\n * @returns The serializer.\n */\nexport function createSerializer(schemaObject: RollupSchema): RollupSerializer {\n const schema = loadSchema(schemaObject);\n\n return {\n serialize(input: unknown, index: number): Uint8Array {\n try {\n return schema.jsonToBorsh(\n index,\n JSON.stringify(input, (_, value) => {\n if (value instanceof Uint8Array) {\n return Array.from(value);\n }\n return value;\n }),\n );\n } catch (err) {\n throw new SovereignError(`Failed to serialize input due to: ${err}`);\n }\n },\n serializeRuntimeCall(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.RuntimeCall),\n );\n },\n serializeUnsignedTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.UnsignedTransaction),\n );\n },\n serializeTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.Transaction),\n );\n },\n };\n}\n","import type SovereignClient from \"@sovereign-sdk/client\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport {\n Rollup,\n type RollupConfig,\n type SignerParams,\n type TransactionContext,\n type TypeBuilder,\n type UnsignedTransactionContext,\n} from \"./rollup\";\n\nexport type TxDetails = {\n max_priority_fee_bips: number;\n max_fee: number;\n gas_limit: number[] | null;\n chain_id: number;\n};\n\nexport type UnsignedTransaction<RuntimeCall> = {\n runtime_call: RuntimeCall;\n nonce: number;\n details: TxDetails;\n};\n\nexport type Transaction<RuntimeCall> = {\n pub_key: { pub_key: Uint8Array };\n signature: { msg_sig: Uint8Array };\n} & UnsignedTransaction<RuntimeCall>;\n\nexport type Dedup = {\n nonce: number;\n};\n\nexport type StandardRollupContext = {\n defaultTxDetails: TxDetails;\n};\n\nexport type StandardRollupSpec<RuntimeCall> = {\n UnsignedTransaction: UnsignedTransaction<RuntimeCall>;\n Transaction: Transaction<RuntimeCall>;\n RuntimeCall: RuntimeCall;\n Dedup: Dedup;\n};\n\nconst useOrFetchNonce = async <S extends StandardRollupSpec<unknown>>({\n sender,\n rollup,\n overrides,\n}: Omit<\n UnsignedTransactionContext<S, StandardRollupContext>,\n \"runtimeCall\"\n>) => {\n if (overrides?.nonce !== undefined && overrides.nonce >= 0) {\n return overrides.nonce;\n }\n const { data } = await rollup.rollup.addresses.dedup(bytesToHex(sender));\n\n return (data as S[\"Dedup\"]).nonce;\n};\n\nexport function standardTypeBuilder<\n S extends StandardRollupSpec<unknown>,\n>(): TypeBuilder<S, StandardRollupContext> {\n return {\n async unsignedTransaction(\n context: UnsignedTransactionContext<S, StandardRollupContext>,\n ) {\n const { rollup, runtimeCall } = context;\n const { nonce: _, ...overrides } = context.overrides;\n const nonce = await useOrFetchNonce(context);\n const details: TxDetails = {\n ...rollup.context.defaultTxDetails,\n ...overrides.details,\n };\n\n return {\n runtime_call: runtimeCall,\n nonce,\n details,\n };\n },\n async transaction({\n sender,\n signature,\n unsignedTx,\n }: TransactionContext<S, StandardRollupContext>) {\n return {\n pub_key: {\n pub_key: sender,\n },\n signature: {\n msg_sig: signature,\n },\n ...unsignedTx,\n };\n },\n };\n}\n\n/**\n * The parameters for simulating a runtime call transaction.\n */\nexport type SimulateParams = {\n /**\n * The transaction details to use for the simulation.\n */\n txDetails: TxDetails;\n\n nonce?: number;\n} & SignerParams;\n\nexport class StandardRollup<RuntimeCall> extends Rollup<\n StandardRollupSpec<RuntimeCall>,\n StandardRollupContext\n> {\n /**\n * Simulates a runtime call transaction.\n *\n * This method can be useful to estimate the gas cost of a runtime call transaction.\n *\n * @param runtimeMessage - The runtime message to call.\n */\n async simulate(\n runtimeMessage: StandardRollupSpec<RuntimeCall>[\"RuntimeCall\"],\n { signer, txDetails, nonce: overrideNonce }: SimulateParams,\n ): Promise<SovereignClient.Rollup.SimulateExecutionResponse> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const nonce = await useOrFetchNonce({\n sender: publicKey,\n rollup: this,\n overrides: { nonce: overrideNonce },\n });\n const response = await this.rollup.simulate({\n body: {\n details: {\n ...txDetails,\n // simulate needs this field as `undefined` currently\n gas_limit: txDetails.gas_limit || undefined,\n },\n encoded_call_message: bytesToHex(runtimeCall),\n nonce,\n sender_pub_key: bytesToHex(publicKey),\n },\n });\n\n // biome-ignore lint/style/noNonNullAssertion: fix later\n return response.data!;\n }\n}\n\nexport function createStandardRollup<\n RuntimeCall,\n C extends StandardRollupContext = StandardRollupContext,\n>(\n config: RollupConfig<C>,\n typeBuilderOverrides?: Partial<\n TypeBuilder<StandardRollupSpec<RuntimeCall>, C>\n >,\n) {\n return new StandardRollup<RuntimeCall>(config, {\n ...standardTypeBuilder(),\n ...typeBuilderOverrides,\n });\n}\n","export * from \"./rollup\";\nexport * from \"./serialization\";\nexport * from \"./errors\";\nexport * from \"./type-spec\";\nexport * as SovereignClient from \"@sovereign-sdk/client\";\nexport { Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,qBAAqB;AAE5B,SAAS,kBAAkB;AAC3B,SAAS,cAAc;;;ACAhB,IAAM,iBAAN,cAA6B,MAAM;AAAA,EACxC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AAEb,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,QAAQ,IAAI,MAAM,EAAE;AAAA,EAC3B;AACF;AAEO,IAAM,2BAAN,cAAuC,eAAe;AAAC;;;ACZ9D,SAAS,aAAa,cAAc;AA8DpC,SAAS,WAAW,cAAoC;AACtD,MAAI;AACF,WAAO,OAAO,SAAS,KAAK,UAAU,YAAY,CAAC;AAAA,EACrD,SAAS,KAAK;AACZ,UAAM,IAAI,eAAe,2CAA2C,GAAG,EAAE;AAAA,EAC3E;AACF;AASO,SAAS,iBAAiB,cAA8C;AAC7E,QAAM,SAAS,WAAW,YAAY;AAEtC,SAAO;AAAA,IACL,UAAU,OAAgB,OAA2B;AACnD,UAAI;AACF,eAAO,OAAO;AAAA,UACZ;AAAA,UACA,KAAK,UAAU,OAAO,CAAC,GAAG,UAAU;AAClC,gBAAI,iBAAiB,YAAY;AAC/B,qBAAO,MAAM,KAAK,KAAK;AAAA,YACzB;AACA,mBAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF,SAAS,KAAK;AACZ,cAAM,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K,WAAW,qBAAqB,cAAc;AACvE,YAAM,YAAY,MAAM,OAAO,UAAU;AACzC,YAAM,QAAQ,MAAM,gBAAgB;AAAA,QAClC,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,WAAW,EAAE,OAAO,cAAc;AAAA,MACpC,CAAC;AACD,YAAM,WAAW,MAAM,KAAK,OAAO,SAAS;AAAA,QAC1C,MAAM;AAAA,UACJ,SAAS,iCACJ,YADI;AAAA;AAAA,YAGP,WAAW,UAAU,aAAa;AAAA,UACpC;AAAA,UACA,sBAAsBD,YAAW,WAAW;AAAA,UAC5C;AAAA,UACA,gBAAgBA,YAAW,SAAS;AAAA,QACtC;AAAA,MACF,CAAC;AAGD,aAAO,SAAS;AAAA,IAClB;AAAA;AACF;AAEO,SAAS,qBAId,QACA,sBAGA;AACA,SAAO,IAAI,eAA4B,QAAQ,kCAC1C,oBAAoB,IACpB,qBACJ;AACH;;;AChKA,YAAYE,sBAAqB;AACjC,SAAS,UAAAC,eAAc;","names":["bytesToHex","bytesToHex","_a","SovereignClient","Schema"]}
|
|
1
|
+
{"version":3,"sources":["../src/rollup/rollup.ts","../src/errors.ts","../src/serialization.ts","../src/rollup/standard-rollup.ts","../src/index.ts"],"sourcesContent":["import type SovereignClient from \"@sovereign-sdk/client\";\nimport type { APIError } from \"@sovereign-sdk/client\";\nimport type { Signer } from \"@sovereign-sdk/signers\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport { Base64 } from \"js-base64\";\nimport { RollupInterfaceError, VersionMismatchError } from \"../errors\";\nimport {\n type RollupSerializer,\n createSerializerFromHttp,\n} from \"../serialization\";\nimport type { BaseTypeSpec } from \"../type-spec\";\nimport type { DeepPartial } from \"../utils\";\n\nexport type UnsignedTransactionContext<\n S extends BaseTypeSpec,\n C extends RollupContext,\n> = {\n runtimeCall: S[\"RuntimeCall\"];\n sender: Uint8Array;\n // Provides the ability to override the nonce instead of retrieving it automatically.\n overrides: DeepPartial<S[\"UnsignedTransaction\"]>;\n rollup: Rollup<S, C>;\n};\n\nexport type TransactionContext<\n S extends BaseTypeSpec,\n C extends RollupContext,\n> = {\n unsignedTx: S[\"UnsignedTransaction\"];\n sender: Uint8Array;\n signature: Uint8Array;\n rollup: Rollup<S, C>;\n};\n\nexport type TypeBuilder<S extends BaseTypeSpec, C extends RollupContext> = {\n unsignedTransaction: (\n context: UnsignedTransactionContext<S, C>,\n ) => Promise<S[\"UnsignedTransaction\"]>;\n\n transaction: (context: TransactionContext<S, C>) => Promise<S[\"Transaction\"]>;\n};\n\n/**\n * Arbitrary context that is associated with the rollup.\n */\nexport type RollupContext = Record<string, unknown>;\n\n/**\n * The configuration for a rollup client.\n * This is a partial version of the configuration object, using a partial version\n * allows setup code to initialize fields automatically for SDK users, for example\n * fetching a `serializer` instance from the rollups endpoint.\n */\nexport type PartialRollupConfig<C extends RollupContext> = {\n /**\n * The base URL of the rollup full node API.\n */\n url?: string;\n /**\n * The Sovereign SDK client to use for the rollup.\n * If not provided, the default client will be used using {@link PartialRollupConfig.url}.\n */\n client?: SovereignClient;\n /**\n * The serializer to use for the rollup.\n * If not provided, a serializer will be created using the provided client and the rollup HTTP endpoint.\n */\n serializer?: RollupSerializer;\n /**\n * Arbitrary context that is associated with the rollup.\n */\n context: C;\n};\n\n/**\n * Fully initialized rollup configuration.\n */\nexport type RollupConfig<C extends RollupContext> = Omit<\n PartialRollupConfig<C>,\n \"client\" | \"serializer\"\n> & {\n client: SovereignClient;\n serializer: RollupSerializer;\n};\n\n/**\n * The result of signing and submitting a transaction.\n *\n * @template Tx The type of the transaction\n */\nexport type TransactionResult<Tx> = {\n /**\n * The response from the sequencer.\n */\n response: SovereignClient.Sequencer.TxCreateResponse;\n /**\n * The transaction that was submitted.\n */\n transaction: Tx;\n};\n\n/**\n * The parameters for signing and submitting a transaction.\n */\nexport type SignerParams = {\n /**\n * The signer to use for signing the transaction.\n */\n signer: Signer;\n};\n\n/**\n * The parameters for calling executing a runtime call transaction.\n */\nexport type CallParams<S extends BaseTypeSpec> = {\n overrides?: DeepPartial<S[\"UnsignedTransaction\"]>;\n} & SignerParams;\n\n/**\n * A generic rollup client.\n *\n * @template S - The type specification for the rollup.\n * If not provided, the base type specification will be used which uses `any` for all types.\n * @template C - The context for the rollup.\n */\nexport class Rollup<S extends BaseTypeSpec, C extends RollupContext> {\n private readonly _config: RollupConfig<C>;\n private readonly _typeBuilder: TypeBuilder<S, C>;\n\n /**\n * Creates a new rollup client.\n *\n * @param config - The configuration for the rollup client.\n * @param typeBuilder - The type builder for the rollup.\n */\n constructor(config: RollupConfig<C>, typeBuilder: TypeBuilder<S, C>) {\n this._config = config;\n this._typeBuilder = typeBuilder;\n }\n\n /**\n * Retrieve dedup information about the provided address.\n *\n * @param address - The public key to dedup.\n */\n async dedup(address: Uint8Array): Promise<S[\"Dedup\"]> {\n const { data: dedup } = await this.rollup.addresses.dedup(\n bytesToHex(address),\n );\n\n if (dedup === undefined) {\n throw new RollupInterfaceError(\n \"Endpoint returned empty response\",\n \"dedup\",\n );\n }\n\n return dedup as S[\"Dedup\"];\n }\n\n /**\n * Submits a transaction to the rollup.\n *\n * @param transaction - The transaction to submit.\n */\n async submitTransaction(\n transaction: S[\"Transaction\"],\n ): Promise<SovereignClient.Sequencer.TxCreateResponse> {\n const serializedTx = this.serializer.serializeTx(transaction);\n\n return this.sequencer.txs\n .create({ body: Base64.fromUint8Array(serializedTx) })\n .catch(async (e) => {\n if (isVersionMismatchError(e as APIError)) {\n const oldVersion = bytesToHex(this.chainHash);\n this._config.serializer = await createSerializerFromHttp(this.http);\n const newVersion = bytesToHex(this.chainHash);\n\n if (oldVersion !== newVersion) {\n throw new VersionMismatchError(\n \"Schema version mismatch when submitting transaction\",\n newVersion,\n oldVersion,\n );\n }\n }\n throw e;\n });\n }\n\n /**\n * Signs and submits a transaction to the rollup.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param unsignedTx - The unsigned transaction to sign and submit.\n * @param {SignerParams} params - The params for signing and submitting the transaction.\n */\n async signAndSubmitTransaction(\n unsignedTx: S[\"UnsignedTransaction\"],\n { signer }: SignerParams,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const serializedUnsignedTx =\n this.serializer.serializeUnsignedTx(unsignedTx);\n const signature = await signer.sign(serializedUnsignedTx);\n const publicKey = await signer.publicKey();\n const context = {\n unsignedTx,\n sender: publicKey,\n signature,\n rollup: this,\n };\n const tx = await this._typeBuilder.transaction(context);\n const result = await this.submitTransaction(tx);\n\n return { transaction: tx, response: result };\n }\n\n /**\n * Performs a runtime call transaction.\n * Utilizes the provided signer to sign the transaction.\n *\n * @param runtimeCall - The runtime message to call.\n * @param {CallParams<S>} params - The params for submitting a runtime call transaction.\n */\n async call(\n runtimeCall: S[\"RuntimeCall\"],\n { signer, overrides }: CallParams<S>,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const publicKey = await signer.publicKey();\n const context = {\n runtimeCall,\n sender: publicKey,\n rollup: this,\n overrides: overrides ?? ({} as DeepPartial<S[\"UnsignedTransaction\"]>),\n };\n const unsignedTx = await this._typeBuilder.unsignedTransaction(context);\n\n return this.signAndSubmitTransaction(unsignedTx, {\n signer,\n });\n }\n\n /**\n * A ledger client that can be used to query the ledger.\n */\n get ledger(): SovereignClient.Ledger {\n return this.http.ledger;\n }\n\n /**\n * A sequencer client that can be used to submit transactions & batches to the rollup.\n */\n get sequencer(): SovereignClient.Sequencer {\n return this.http.sequencer;\n }\n\n /**\n * A rollup client that can be used to perform operations on the rollup.\n */\n get rollup(): SovereignClient.Rollup {\n return this.http.rollup;\n }\n\n /**\n * A client that can be used to perform HTTP requests to the Sovereign API.\n * This can be used as an escape hatch to execute arbitrary requests to the Sovereign API\n * if the operation is not supported by `ledger`, `sequencer`, or `rollup` clients.\n */\n get http(): SovereignClient {\n return this._config.client;\n }\n\n /**\n * The serializer for the rollup.\n * Can be used to serialize transactions, runtime calls, etc.\n * See {@link RollupSerializer} for more information.\n */\n get serializer(): RollupSerializer {\n return this._config.serializer;\n }\n\n /**\n * The context for the rollup.\n */\n get context(): C {\n return this._config.context;\n }\n\n /**\n * The chain hash of the rollup.\n */\n get chainHash(): Uint8Array {\n return this.serializer.schema.chainHash;\n }\n}\n\nfunction isVersionMismatchError(e: APIError): boolean {\n if (\n // biome-ignore lint/suspicious/noExplicitAny: yolo\n (e.error as any)?.errors[0]?.details?.message.includes(\n \"Signature verification failed\",\n )\n ) {\n return true;\n }\n\n return false;\n}\n","/**\n * Base error class for Sovereign SDK Web3.\n */\nexport class SovereignError extends Error {\n constructor(message: string) {\n super(message);\n\n this.name = this.constructor.name;\n this.stack = new Error().stack;\n }\n}\n\nexport class InvalidRollupConfigError extends SovereignError {}\n\nexport class RollupInterfaceError extends SovereignError {\n public readonly method: string;\n\n constructor(message: string, method: string) {\n super(message);\n\n this.method = method;\n }\n}\n\nexport class VersionMismatchError extends SovereignError {\n public readonly newVersion: string;\n public readonly currentVersion: string;\n public readonly retryable: boolean;\n\n constructor(message: string, newVersion: string, currentVersion: string) {\n super(message);\n\n this.newVersion = newVersion;\n this.currentVersion = currentVersion;\n this.retryable = newVersion !== currentVersion;\n }\n}\n","import type SovereignClient from \"@sovereign-sdk/client\";\nimport { KnownTypeId, Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\nimport { RollupInterfaceError, SovereignError } from \"./errors\";\n\n/**\n * A rollup schema is a description of the types that are utilized in the rollup.\n * It is used to serialize and deserialize the types.\n * As well as display them in a human-readable way that is verified by the rollup.\n */\nexport type RollupSchema = object;\n\n/**\n * A serializer is used to serialize rollup types to Borsh bytes.\n *\n * @example\n * ```typescript\n * const serializer = createSerializer(yourSchema);\n * const runtimeCall = {\n * value_setter: {\n * set_value: 100,\n * },\n * };\n * const borshBytes = serializer.serializeRuntimeCall(runtimeCall);\n * ```\n */\nexport type RollupSerializer = {\n /**\n * Serialize an input to Borsh bytes.\n *\n * Treats `Uint8Array` as a plain array of numbers as this is the format used by universal-wallet-wasm\n * to represent Borsh bytes.\n *\n * @param input - The input to serialize.\n * @param index - The index of the type in the schema to serialize.\n * @returns The serialized Borsh bytes.\n */\n serialize(input: unknown, index: number): Uint8Array;\n\n /**\n * Serialize a runtime call to Borsh bytes.\n *\n * @param input - The runtime call to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeRuntimeCall(input: unknown): Uint8Array;\n\n /**\n * Serialize an unsigned transaction to Borsh bytes.\n *\n * @param input - The unsigned transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeUnsignedTx(input: unknown): Uint8Array;\n\n /**\n * Serialize a transaction to Borsh bytes.\n *\n * @param input - The transaction to serialize.\n * @returns The serialized Borsh bytes.\n */\n serializeTx(input: unknown): Uint8Array;\n\n /**\n * Returns the `Schema` used by the serializer.\n */\n get schema(): Schema;\n};\n\nfunction loadSchema(schemaObject: RollupSchema): Schema {\n try {\n return Schema.fromJSON(JSON.stringify(schemaObject));\n } catch (err) {\n throw new SovereignError(`Failed to create runtime schema due to: ${err}`);\n }\n}\n\n/**\n * Create a serializer for a rollup schema.\n *\n * @throws {@link SovereignError} - If the schema is invalid.\n * @param schemaObject - The rollup schema.\n * @returns The serializer.\n */\nexport function createSerializer(schemaObject: RollupSchema): RollupSerializer {\n const schema = loadSchema(schemaObject);\n\n return {\n schema,\n serialize(input: unknown, index: number): Uint8Array {\n try {\n return schema.jsonToBorsh(\n index,\n JSON.stringify(input, (_, value) => {\n if (value instanceof Uint8Array) {\n return Array.from(value);\n }\n return value;\n }),\n );\n } catch (err) {\n throw new SovereignError(`Failed to serialize input due to: ${err}`);\n }\n },\n serializeRuntimeCall(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.RuntimeCall),\n );\n },\n serializeUnsignedTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.UnsignedTransaction),\n );\n },\n serializeTx(input: unknown): Uint8Array {\n return this.serialize(\n input,\n schema.knownTypeIndex(KnownTypeId.Transaction),\n );\n },\n };\n}\n\nexport async function createSerializerFromHttp(\n client: SovereignClient,\n): Promise<RollupSerializer> {\n const { data: schema } = await client.rollup.schema.retrieve();\n\n if (!schema) {\n throw new RollupInterfaceError(\n \"Endpoint returned empty response\",\n \"schema\",\n );\n }\n\n return createSerializer(schema as RollupSchema);\n}\n","import SovereignClient from \"@sovereign-sdk/client\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport { createSerializerFromHttp } from \"../serialization\";\nimport {\n type PartialRollupConfig,\n Rollup,\n type SignerParams,\n type TransactionContext,\n type TypeBuilder,\n type UnsignedTransactionContext,\n} from \"./rollup\";\n\nexport type TxDetails = {\n max_priority_fee_bips: number;\n max_fee: number;\n gas_limit: number[] | null;\n chain_id: number;\n};\n\nexport type UnsignedTransaction<RuntimeCall> = {\n runtime_call: RuntimeCall;\n nonce: number;\n details: TxDetails;\n};\n\nexport type Transaction<RuntimeCall> = {\n pub_key: { pub_key: Uint8Array };\n signature: { msg_sig: Uint8Array };\n} & UnsignedTransaction<RuntimeCall>;\n\nexport type Dedup = {\n nonce: number;\n};\n\nexport type StandardRollupContext = {\n defaultTxDetails: TxDetails;\n};\n\nexport type StandardRollupSpec<RuntimeCall> = {\n UnsignedTransaction: UnsignedTransaction<RuntimeCall>;\n Transaction: Transaction<RuntimeCall>;\n RuntimeCall: RuntimeCall;\n Dedup: Dedup;\n};\n\nconst useOrFetchNonce = async <S extends StandardRollupSpec<unknown>>({\n sender,\n rollup,\n overrides,\n}: Omit<\n UnsignedTransactionContext<S, StandardRollupContext>,\n \"runtimeCall\"\n>) => {\n if (overrides?.nonce !== undefined && overrides.nonce >= 0) {\n return overrides.nonce;\n }\n const dedup = await rollup.dedup(sender);\n\n return dedup.nonce;\n};\n\nexport function standardTypeBuilder<\n S extends StandardRollupSpec<unknown>,\n>(): TypeBuilder<S, StandardRollupContext> {\n return {\n async unsignedTransaction(\n context: UnsignedTransactionContext<S, StandardRollupContext>,\n ) {\n const { rollup, runtimeCall } = context;\n const { nonce: _, ...overrides } = context.overrides;\n const nonce = await useOrFetchNonce(context);\n const details: TxDetails = {\n ...rollup.context.defaultTxDetails,\n ...overrides.details,\n };\n\n return {\n runtime_call: runtimeCall,\n nonce,\n details,\n };\n },\n async transaction({\n sender,\n signature,\n unsignedTx,\n }: TransactionContext<S, StandardRollupContext>) {\n return {\n pub_key: {\n pub_key: sender,\n },\n signature: {\n msg_sig: signature,\n },\n ...unsignedTx,\n };\n },\n };\n}\n\n/**\n * The parameters for simulating a runtime call transaction.\n */\nexport type SimulateParams = {\n /**\n * The transaction details to use for the simulation.\n */\n txDetails: TxDetails;\n\n nonce?: number;\n} & SignerParams;\n\nexport class StandardRollup<RuntimeCall> extends Rollup<\n StandardRollupSpec<RuntimeCall>,\n StandardRollupContext\n> {\n /**\n * Simulates a runtime call transaction.\n *\n * This method can be useful to estimate the gas cost of a runtime call transaction.\n *\n * @param runtimeMessage - The runtime message to call.\n */\n async simulate(\n runtimeMessage: StandardRollupSpec<RuntimeCall>[\"RuntimeCall\"],\n { signer, txDetails, nonce: overrideNonce }: SimulateParams,\n ): Promise<SovereignClient.Rollup.SimulateExecutionResponse> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const nonce = await useOrFetchNonce({\n sender: publicKey,\n rollup: this,\n overrides: { nonce: overrideNonce },\n });\n const response = await this.rollup.simulate({\n body: {\n details: {\n ...txDetails,\n // simulate needs this field as `undefined` currently\n gas_limit: txDetails.gas_limit || undefined,\n },\n encoded_call_message: bytesToHex(runtimeCall),\n nonce,\n sender_pub_key: bytesToHex(publicKey),\n },\n });\n\n // biome-ignore lint/style/noNonNullAssertion: fix later\n return response.data!;\n }\n}\n\nexport async function createStandardRollup<\n RuntimeCall,\n C extends StandardRollupContext = StandardRollupContext,\n>(\n config: PartialRollupConfig<C>,\n typeBuilderOverrides?: Partial<\n TypeBuilder<StandardRollupSpec<RuntimeCall>, C>\n >,\n) {\n const client = config.client ?? new SovereignClient({ baseURL: config.url });\n const serializer =\n config.serializer ?? (await createSerializerFromHttp(client));\n\n return new StandardRollup<RuntimeCall>(\n { ...config, client, serializer },\n {\n ...standardTypeBuilder(),\n ...typeBuilderOverrides,\n },\n );\n}\n","export * from \"./rollup\";\nexport * from \"./serialization\";\nexport * from \"./errors\";\nexport * from \"./type-spec\";\nexport * as SovereignClient from \"@sovereign-sdk/client\";\nexport { Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAS,kBAAkB;AAC3B,SAAS,cAAc;;;ACDhB,IAAM,iBAAN,cAA6B,MAAM;AAAA,EACxC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AAEb,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,QAAQ,IAAI,MAAM,EAAE;AAAA,EAC3B;AACF;AAEO,IAAM,2BAAN,cAAuC,eAAe;AAAC;AAEvD,IAAM,uBAAN,cAAmC,eAAe;AAAA,EAGvD,YAAY,SAAiB,QAAgB;AAC3C,UAAM,OAAO;AAEb,SAAK,SAAS;AAAA,EAChB;AACF;AAEO,IAAM,uBAAN,cAAmC,eAAe;AAAA,EAKvD,YAAY,SAAiB,YAAoB,gBAAwB;AACvE,UAAM,OAAO;AAEb,SAAK,aAAa;AAClB,SAAK,iBAAiB;AACtB,SAAK,YAAY,eAAe;AAAA,EAClC;AACF;;;ACnCA,SAAS,aAAa,cAAc;AAmEpC,SAAS,WAAW,cAAoC;AACtD,MAAI;AACF,WAAO,OAAO,SAAS,KAAK,UAAU,YAAY,CAAC;AAAA,EACrD,SAAS,KAAK;AACZ,UAAM,IAAI,eAAe,2CAA2C,GAAG,EAAE;AAAA,EAC3E;AACF;AASO,SAAS,iBAAiB,cAA8C;AAC7E,QAAM,SAAS,WAAW,YAAY;AAEtC,SAAO;AAAA,IACL;AAAA,IACA,UAAU,OAAgB,OAA2B;AACnD,UAAI;AACF,eAAO,OAAO;AAAA,UACZ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tC;AAAA,MACF,CAAC;AAGD,aAAO,SAAS;AAAA,IAClB;AAAA;AACF;AAEA,SAAsB,qBAIpB,QACA,sBAGA;AAAA;AAhKF;AAiKE,UAAM,UAAS,YAAO,WAAP,YAAiB,IAAI,gBAAgB,EAAE,SAAS,OAAO,IAAI,CAAC;AAC3E,UAAM,cACJ,YAAO,eAAP,YAAsB,MAAM,yBAAyB,MAAM;AAE7D,WAAO,IAAI;AAAA,MACT,iCAAK,SAAL,EAAa,QAAQ,WAAW;AAAA,MAChC,kCACK,oBAAoB,IACpB;AAAA,IAEP;AAAA,EACF;AAAA;;;ACxKA,YAAYC,sBAAqB;AACjC,SAAS,UAAAC,eAAc;","names":["bytesToHex","_a","bytesToHex","SovereignClient","Schema"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sovereign-sdk/web3",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist",
|
|
6
6
|
"package.json"
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"typescript": "^5.0.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@sovereign-sdk/client": "0.1.0-alpha.
|
|
27
|
+
"@sovereign-sdk/client": "0.1.0-alpha.15",
|
|
28
28
|
"js-base64": "^3.7.7",
|
|
29
29
|
"@sovereign-sdk/signers": "^0.0.3",
|
|
30
|
-
"@sovereign-sdk/universal-wallet-wasm": "^0.1.
|
|
30
|
+
"@sovereign-sdk/universal-wallet-wasm": "^0.1.8",
|
|
31
31
|
"@sovereign-sdk/utils": "^0.0.2"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|