@sovereign-sdk/web3 0.1.0 → 0.2.0

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 CHANGED
@@ -76,6 +76,28 @@ type RollupSerializer = {
76
76
  declare function createSerializer(schemaObject: RollupSchema): RollupSerializer;
77
77
  declare function createSerializerFromHttp(client: SovereignClient__default): Promise<RollupSerializer>;
78
78
 
79
+ type Url = string;
80
+ type Subscription = {
81
+ /** Url providing the subscription. */
82
+ url: Url;
83
+ /** Unsubscribe this subscription. */
84
+ unsubscribe: () => void;
85
+ };
86
+ type EventPayload = {
87
+ tx_hash: string;
88
+ type: "event";
89
+ number: number;
90
+ key: string;
91
+ value: Record<string, unknown>;
92
+ module: {
93
+ type: "moduleRef";
94
+ name: string;
95
+ };
96
+ };
97
+ interface SubscriptionToCallbackMap {
98
+ events: (event: EventPayload) => Promise<void>;
99
+ }
100
+
79
101
  /**
80
102
  * The base type specification for a rollup.
81
103
  *
@@ -282,6 +304,10 @@ declare class Rollup<S extends BaseTypeSpec, C extends RollupContext> {
282
304
  * @param {CallParams<S>} params - The params for submitting a runtime call transaction.
283
305
  */
284
306
  call(runtimeCall: S["RuntimeCall"], { signer, overrides }: CallParams<S>): Promise<TransactionResult<S["Transaction"]>>;
307
+ /**
308
+ * Create a subscription to events emitted over websockets by the rollup.
309
+ */
310
+ subscribe<T extends keyof SubscriptionToCallbackMap>(type: T, callback: SubscriptionToCallbackMap[T]): Subscription;
285
311
  /**
286
312
  * A ledger client that can be used to query the ledger.
287
313
  */
package/dist/index.d.ts CHANGED
@@ -76,6 +76,28 @@ type RollupSerializer = {
76
76
  declare function createSerializer(schemaObject: RollupSchema): RollupSerializer;
77
77
  declare function createSerializerFromHttp(client: SovereignClient__default): Promise<RollupSerializer>;
78
78
 
79
+ type Url = string;
80
+ type Subscription = {
81
+ /** Url providing the subscription. */
82
+ url: Url;
83
+ /** Unsubscribe this subscription. */
84
+ unsubscribe: () => void;
85
+ };
86
+ type EventPayload = {
87
+ tx_hash: string;
88
+ type: "event";
89
+ number: number;
90
+ key: string;
91
+ value: Record<string, unknown>;
92
+ module: {
93
+ type: "moduleRef";
94
+ name: string;
95
+ };
96
+ };
97
+ interface SubscriptionToCallbackMap {
98
+ events: (event: EventPayload) => Promise<void>;
99
+ }
100
+
79
101
  /**
80
102
  * The base type specification for a rollup.
81
103
  *
@@ -282,6 +304,10 @@ declare class Rollup<S extends BaseTypeSpec, C extends RollupContext> {
282
304
  * @param {CallParams<S>} params - The params for submitting a runtime call transaction.
283
305
  */
284
306
  call(runtimeCall: S["RuntimeCall"], { signer, overrides }: CallParams<S>): Promise<TransactionResult<S["Transaction"]>>;
307
+ /**
308
+ * Create a subscription to events emitted over websockets by the rollup.
309
+ */
310
+ subscribe<T extends keyof SubscriptionToCallbackMap>(type: T, callback: SubscriptionToCallbackMap[T]): Subscription;
285
311
  /**
286
312
  * A ledger client that can be used to query the ledger.
287
313
  */
package/dist/index.js CHANGED
@@ -200,6 +200,62 @@ function createSerializerFromHttp(client) {
200
200
  });
201
201
  }
202
202
 
203
+ // src/subscriptions.ts
204
+ var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
205
+ var import_partysocket = require("partysocket");
206
+ function httpToWebSocket(url) {
207
+ return url.replace(/^http(s?):\/\//, (_, s) => `ws${s}://`);
208
+ }
209
+ var _subscriptions = {};
210
+ function subscribe(url, callback) {
211
+ var _a;
212
+ const subscription = _subscriptions[url];
213
+ if (!subscription) {
214
+ const websocket = new import_partysocket.WebSocket(url, [], { WebSocket: import_isomorphic_ws.default });
215
+ _subscriptions[url] = {
216
+ websocket,
217
+ callbacks: [callback]
218
+ };
219
+ websocket.addEventListener("message", (message) => {
220
+ var _a2;
221
+ const data = JSON.parse(message.data);
222
+ (_a2 = _subscriptions[url]) == null ? void 0 : _a2.callbacks.forEach((cb) => cb(data));
223
+ });
224
+ } else {
225
+ subscription.callbacks.push(callback);
226
+ }
227
+ const callbackIndex = ((_a = _subscriptions[url]) == null ? void 0 : _a.callbacks.length) - 1;
228
+ return {
229
+ get url() {
230
+ return url;
231
+ },
232
+ unsubscribe() {
233
+ const subscription2 = _subscriptions[url];
234
+ if (!subscription2) {
235
+ return;
236
+ }
237
+ subscription2.callbacks.splice(callbackIndex, 1);
238
+ if (!subscription2.callbacks.length) {
239
+ subscription2.websocket.close();
240
+ delete _subscriptions[url];
241
+ }
242
+ }
243
+ };
244
+ }
245
+ function createSubscription(subscription, callback, client) {
246
+ switch (subscription) {
247
+ case "events": {
248
+ const url = client.buildURL("/sequencer/events/ws", {});
249
+ return subscribe(
250
+ httpToWebSocket(url),
251
+ callback
252
+ );
253
+ }
254
+ default:
255
+ throw new SovereignError(`Invalid subscription type '${subscription}'`);
256
+ }
257
+ }
258
+
203
259
  // src/rollup/rollup.ts
204
260
  var Rollup = class {
205
261
  /**
@@ -301,6 +357,12 @@ var Rollup = class {
301
357
  });
302
358
  });
303
359
  }
360
+ /**
361
+ * Create a subscription to events emitted over websockets by the rollup.
362
+ */
363
+ subscribe(type, callback) {
364
+ return createSubscription(type, callback, this.http);
365
+ }
304
366
  /**
305
367
  * A ledger client that can be used to query the ledger.
306
368
  */
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 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 generation data 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\nexport class SchemaError extends SovereignError {\n public readonly schema: object;\n public readonly reason: string;\n\n constructor(message: string, reason: string, schema: object) {\n super(message);\n\n this.reason = reason;\n this.schema = schema;\n }\n}\n","import type SovereignClient from \"@sovereign-sdk/client\";\nimport { KnownTypeId, Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\nimport { RollupInterfaceError, SchemaError } 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: {\n * value: 100,\n * gas: null\n * },\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 SchemaError(\n \"Failed to create runtime schema\",\n (err as Error).message,\n schemaObject,\n );\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 SchemaError(\n \"Input serialization failed\",\n (err as Error).message,\n schemaObject,\n );\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: string;\n gas_limit: number[] | null;\n chain_id: number;\n};\n\nexport type UnsignedTransaction<RuntimeCall> = {\n runtime_call: RuntimeCall;\n generation: 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 useOrFetchGeneration = async <S extends StandardRollupSpec<unknown>>({\n overrides,\n}: Omit<\n UnsignedTransactionContext<S, StandardRollupContext>,\n \"runtimeCall\"\n>) => {\n if (overrides?.generation !== undefined && overrides.generation >= 0) {\n return overrides.generation;\n }\n\n return new Date().getTime();\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 { generation: _, ...overrides } = context.overrides;\n const generation = await useOrFetchGeneration(context);\n const details: TxDetails = {\n ...rollup.context.defaultTxDetails,\n ...overrides.details,\n };\n\n return {\n runtime_call: runtimeCall,\n generation,\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 /** The generation of the transaction for uniquness purposes. */\n generation?: 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, generation: overrideGeneration }: SimulateParams,\n ): Promise<SovereignClient.Rollup.SimulateExecutionResponse> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const generation = await useOrFetchGeneration({\n sender: publicKey,\n rollup: this,\n overrides: { generation: overrideGeneration },\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 generation,\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;AAAA,yBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,mBAA2B;AAC3B,uBAAuB;;;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;A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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQM,SACJ,IACA,IAC2D;AAAA,+CAF3D,gBACA,EAAE,QAAQ,WAAW,YAAY,mBAAmB,GACO;AAC3D,YAAM,cAAc,KAAK,WAAW,qBAAqB,cAAc;AACvE,YAAM,YAAY,MAAM,OAAO,UAAU;AACzC,YAAM,aAAa,MAAM,qBAAqB;AAAA,QAC5C,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,WAAW,EAAE,YAAY,mBAAmB;AAAA,MAC9C,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,0BAAsB,0BAAW,WAAW;AAAA,UAC5C;AAAA,UACA,oBAAgB,0BAAW,SAAS;AAAA,QACtC;AAAA,MACF,CAAC;AAGD,aAAO,SAAS;AAAA,IAClB;AAAA;AACF;AAEA,SAAsB,qBAIpB,QACA,sBAGA;AAAA;AA9JF;AA+JE,UAAM,UAAS,YAAO,WAAP,YAAiB,IAAI,cAAAC,QAAgB,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;;;AJtKA,IAAAC,mBAAiC;AACjC,IAAAC,gCAAuB;","names":["SovereignClient","import_utils","_a","SovereignClient","SovereignClient","import_universal_wallet_wasm"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/rollup/rollup.ts","../src/errors.ts","../src/serialization.ts","../src/subscriptions.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 {\n type Subscription,\n type SubscriptionToCallbackMap,\n createSubscription,\n} from \"../subscriptions\";\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 generation data 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 * Create a subscription to events emitted over websockets by the rollup.\n */\n subscribe<T extends keyof SubscriptionToCallbackMap>(\n type: T,\n callback: SubscriptionToCallbackMap[T],\n ): Subscription {\n return createSubscription(type, callback, this.http);\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\nexport class SchemaError extends SovereignError {\n public readonly schema: object;\n public readonly reason: string;\n\n constructor(message: string, reason: string, schema: object) {\n super(message);\n\n this.reason = reason;\n this.schema = schema;\n }\n}\n","import type SovereignClient from \"@sovereign-sdk/client\";\nimport { KnownTypeId, Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\nimport { RollupInterfaceError, SchemaError } 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: {\n * value: 100,\n * gas: null\n * },\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 SchemaError(\n \"Failed to create runtime schema\",\n (err as Error).message,\n schemaObject,\n );\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 SchemaError(\n \"Input serialization failed\",\n (err as Error).message,\n schemaObject,\n );\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 type SovereignSDK from \"@sovereign-sdk/client\";\nimport IsoWebSocket from \"isomorphic-ws\";\nimport { WebSocket } from \"partysocket\";\nimport { SovereignError } from \"./errors\";\n\ntype Url = string;\n\nexport function httpToWebSocket(url: string) {\n return url.replace(/^http(s?):\\/\\//, (_, s) => `ws${s}://`);\n}\n\nexport type Subscription = {\n /** Url providing the subscription. */\n url: Url;\n /** Unsubscribe this subscription. */\n unsubscribe: () => void;\n};\n\ntype SubscriptionEntry = {\n websocket: WebSocket;\n // biome-ignore lint/suspicious/noExplicitAny: allow\n callbacks: Array<(...args: any[]) => void>;\n};\n\nexport const _subscriptions: Record<Url, SubscriptionEntry> = {};\n\n/** Subscribe to the provided websocket url & call the provided callback on messages received. */\nexport function subscribe(\n url: Url,\n // biome-ignore lint/suspicious/noExplicitAny: allow\n callback: (...args: any[]) => void,\n): Subscription {\n const subscription = _subscriptions[url];\n\n if (!subscription) {\n const websocket = new WebSocket(url, [], { WebSocket: IsoWebSocket });\n\n _subscriptions[url] = {\n websocket,\n callbacks: [callback],\n };\n\n websocket.addEventListener(\"message\", (message) => {\n const data = JSON.parse(message.data);\n _subscriptions[url]?.callbacks.forEach((cb) => cb(data));\n });\n } else {\n subscription.callbacks.push(callback);\n }\n\n const callbackIndex = _subscriptions[url]?.callbacks.length - 1;\n\n return {\n get url() {\n return url;\n },\n unsubscribe() {\n const subscription = _subscriptions[url];\n\n if (!subscription) {\n return;\n }\n\n subscription.callbacks.splice(callbackIndex, 1);\n\n if (!subscription.callbacks.length) {\n subscription.websocket.close();\n delete _subscriptions[url];\n }\n },\n };\n}\n\ntype EventPayload = {\n tx_hash: string;\n type: \"event\";\n number: number;\n key: string;\n value: Record<string, unknown>;\n module: {\n type: \"moduleRef\";\n name: string;\n };\n};\n\nexport interface SubscriptionToCallbackMap {\n events: (event: EventPayload) => Promise<void>;\n}\n\nexport function createSubscription<T extends keyof SubscriptionToCallbackMap>(\n subscription: T,\n callback: SubscriptionToCallbackMap[T],\n client: SovereignSDK,\n): Subscription {\n switch (subscription) {\n case \"events\": {\n const url = client.buildURL(\"/sequencer/events/ws\", {});\n return subscribe(\n httpToWebSocket(url),\n callback as SubscriptionToCallbackMap[\"events\"],\n );\n }\n default:\n throw new SovereignError(`Invalid subscription type '${subscription}'`);\n }\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: string;\n gas_limit: number[] | null;\n chain_id: number;\n};\n\nexport type UnsignedTransaction<RuntimeCall> = {\n runtime_call: RuntimeCall;\n generation: 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 useOrFetchGeneration = async <S extends StandardRollupSpec<unknown>>({\n overrides,\n}: Omit<\n UnsignedTransactionContext<S, StandardRollupContext>,\n \"runtimeCall\"\n>) => {\n if (overrides?.generation !== undefined && overrides.generation >= 0) {\n return overrides.generation;\n }\n\n return new Date().getTime();\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 { generation: _, ...overrides } = context.overrides;\n const generation = await useOrFetchGeneration(context);\n const details: TxDetails = {\n ...rollup.context.defaultTxDetails,\n ...overrides.details,\n };\n\n return {\n runtime_call: runtimeCall,\n generation,\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 /** The generation of the transaction for uniquness purposes. */\n generation?: 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, generation: overrideGeneration }: SimulateParams,\n ): Promise<SovereignClient.Rollup.SimulateExecutionResponse> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const generation = await useOrFetchGeneration({\n sender: publicKey,\n rollup: this,\n overrides: { generation: overrideGeneration },\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 generation,\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":";;;;;;;;;;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,WAAW,MAAM,KAAK,OAAO,SAAS;AAAA,QAC1C,MAAM;AAAA,UACJ,SAAS,iCACJ,YADI;AAAA;AAAA,YAGP,WAAW,UAAU,aAAa;AAAA,UACpC;AAAA,UACA,0BAAsB,0BAAW,WAAW;AAAA,UAC5C;AAAA,UACA,oBAAgB,0BAAW,SAAS;AAAA,QACtC;AAAA,MACF,CAAC;AAGD,aAAO,SAAS;AAAA,IAClB;AAAA;AACF;AAEA,SAAsB,qBAIpB,QACA,sBAGA;AAAA;AA9JF;AA+JE,UAAM,UAAS,YAAO,WAAP,YAAiB,IAAI,cAAAC,QAAgB,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;;;ALtKA,IAAAC,mBAAiC;AACjC,IAAAC,gCAAuB;","names":["SovereignClient","IsoWebSocket","_a","subscription","import_utils","_a","SovereignClient","SovereignClient","import_universal_wallet_wasm"]}
package/dist/index.mjs CHANGED
@@ -155,6 +155,62 @@ function createSerializerFromHttp(client) {
155
155
  });
156
156
  }
157
157
 
158
+ // src/subscriptions.ts
159
+ import IsoWebSocket from "isomorphic-ws";
160
+ import { WebSocket } from "partysocket";
161
+ function httpToWebSocket(url) {
162
+ return url.replace(/^http(s?):\/\//, (_, s) => `ws${s}://`);
163
+ }
164
+ var _subscriptions = {};
165
+ function subscribe(url, callback) {
166
+ var _a;
167
+ const subscription = _subscriptions[url];
168
+ if (!subscription) {
169
+ const websocket = new WebSocket(url, [], { WebSocket: IsoWebSocket });
170
+ _subscriptions[url] = {
171
+ websocket,
172
+ callbacks: [callback]
173
+ };
174
+ websocket.addEventListener("message", (message) => {
175
+ var _a2;
176
+ const data = JSON.parse(message.data);
177
+ (_a2 = _subscriptions[url]) == null ? void 0 : _a2.callbacks.forEach((cb) => cb(data));
178
+ });
179
+ } else {
180
+ subscription.callbacks.push(callback);
181
+ }
182
+ const callbackIndex = ((_a = _subscriptions[url]) == null ? void 0 : _a.callbacks.length) - 1;
183
+ return {
184
+ get url() {
185
+ return url;
186
+ },
187
+ unsubscribe() {
188
+ const subscription2 = _subscriptions[url];
189
+ if (!subscription2) {
190
+ return;
191
+ }
192
+ subscription2.callbacks.splice(callbackIndex, 1);
193
+ if (!subscription2.callbacks.length) {
194
+ subscription2.websocket.close();
195
+ delete _subscriptions[url];
196
+ }
197
+ }
198
+ };
199
+ }
200
+ function createSubscription(subscription, callback, client) {
201
+ switch (subscription) {
202
+ case "events": {
203
+ const url = client.buildURL("/sequencer/events/ws", {});
204
+ return subscribe(
205
+ httpToWebSocket(url),
206
+ callback
207
+ );
208
+ }
209
+ default:
210
+ throw new SovereignError(`Invalid subscription type '${subscription}'`);
211
+ }
212
+ }
213
+
158
214
  // src/rollup/rollup.ts
159
215
  var Rollup = class {
160
216
  /**
@@ -256,6 +312,12 @@ var Rollup = class {
256
312
  });
257
313
  });
258
314
  }
315
+ /**
316
+ * Create a subscription to events emitted over websockets by the rollup.
317
+ */
318
+ subscribe(type, callback) {
319
+ return createSubscription(type, callback, this.http);
320
+ }
259
321
  /**
260
322
  * A ledger client that can be used to query the ledger.
261
323
  */
@@ -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 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 generation data 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\nexport class SchemaError extends SovereignError {\n public readonly schema: object;\n public readonly reason: string;\n\n constructor(message: string, reason: string, schema: object) {\n super(message);\n\n this.reason = reason;\n this.schema = schema;\n }\n}\n","import type SovereignClient from \"@sovereign-sdk/client\";\nimport { KnownTypeId, Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\nimport { RollupInterfaceError, SchemaError } 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: {\n * value: 100,\n * gas: null\n * },\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 SchemaError(\n \"Failed to create runtime schema\",\n (err as Error).message,\n schemaObject,\n );\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 SchemaError(\n \"Input serialization failed\",\n (err as Error).message,\n schemaObject,\n );\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: string;\n gas_limit: number[] | null;\n chain_id: number;\n};\n\nexport type UnsignedTransaction<RuntimeCall> = {\n runtime_call: RuntimeCall;\n generation: 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 useOrFetchGeneration = async <S extends StandardRollupSpec<unknown>>({\n overrides,\n}: Omit<\n UnsignedTransactionContext<S, StandardRollupContext>,\n \"runtimeCall\"\n>) => {\n if (overrides?.generation !== undefined && overrides.generation >= 0) {\n return overrides.generation;\n }\n\n return new Date().getTime();\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 { generation: _, ...overrides } = context.overrides;\n const generation = await useOrFetchGeneration(context);\n const details: TxDetails = {\n ...rollup.context.defaultTxDetails,\n ...overrides.details,\n };\n\n return {\n runtime_call: runtimeCall,\n generation,\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 /** The generation of the transaction for uniquness purposes. */\n generation?: 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, generation: overrideGeneration }: SimulateParams,\n ): Promise<SovereignClient.Rollup.SimulateExecutionResponse> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const generation = await useOrFetchGeneration({\n sender: publicKey,\n rollup: this,\n overrides: { generation: overrideGeneration },\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 generation,\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;AAEO,IAA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AC2D;AAAA,+CAF3D,gBACA,EAAE,QAAQ,WAAW,YAAY,mBAAmB,GACO;AAC3D,YAAM,cAAc,KAAK,WAAW,qBAAqB,cAAc;AACvE,YAAM,YAAY,MAAM,OAAO,UAAU;AACzC,YAAM,aAAa,MAAM,qBAAqB;AAAA,QAC5C,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,WAAW,EAAE,YAAY,mBAAmB;AAAA,MAC9C,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,sBAAsBC,YAAW,WAAW;AAAA,UAC5C;AAAA,UACA,gBAAgBA,YAAW,SAAS;AAAA,QACtC;AAAA,MACF,CAAC;AAGD,aAAO,SAAS;AAAA,IAClB;AAAA;AACF;AAEA,SAAsB,qBAIpB,QACA,sBAGA;AAAA;AA9JF;AA+JE,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;;;ACtKA,YAAYC,sBAAqB;AACjC,SAAS,UAAAC,eAAc;","names":["bytesToHex","_a","bytesToHex","SovereignClient","Schema"]}
1
+ {"version":3,"sources":["../src/rollup/rollup.ts","../src/errors.ts","../src/serialization.ts","../src/subscriptions.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 {\n type Subscription,\n type SubscriptionToCallbackMap,\n createSubscription,\n} from \"../subscriptions\";\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 generation data 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 * Create a subscription to events emitted over websockets by the rollup.\n */\n subscribe<T extends keyof SubscriptionToCallbackMap>(\n type: T,\n callback: SubscriptionToCallbackMap[T],\n ): Subscription {\n return createSubscription(type, callback, this.http);\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\nexport class SchemaError extends SovereignError {\n public readonly schema: object;\n public readonly reason: string;\n\n constructor(message: string, reason: string, schema: object) {\n super(message);\n\n this.reason = reason;\n this.schema = schema;\n }\n}\n","import type SovereignClient from \"@sovereign-sdk/client\";\nimport { KnownTypeId, Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\nimport { RollupInterfaceError, SchemaError } 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: {\n * value: 100,\n * gas: null\n * },\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 SchemaError(\n \"Failed to create runtime schema\",\n (err as Error).message,\n schemaObject,\n );\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 SchemaError(\n \"Input serialization failed\",\n (err as Error).message,\n schemaObject,\n );\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 type SovereignSDK from \"@sovereign-sdk/client\";\nimport IsoWebSocket from \"isomorphic-ws\";\nimport { WebSocket } from \"partysocket\";\nimport { SovereignError } from \"./errors\";\n\ntype Url = string;\n\nexport function httpToWebSocket(url: string) {\n return url.replace(/^http(s?):\\/\\//, (_, s) => `ws${s}://`);\n}\n\nexport type Subscription = {\n /** Url providing the subscription. */\n url: Url;\n /** Unsubscribe this subscription. */\n unsubscribe: () => void;\n};\n\ntype SubscriptionEntry = {\n websocket: WebSocket;\n // biome-ignore lint/suspicious/noExplicitAny: allow\n callbacks: Array<(...args: any[]) => void>;\n};\n\nexport const _subscriptions: Record<Url, SubscriptionEntry> = {};\n\n/** Subscribe to the provided websocket url & call the provided callback on messages received. */\nexport function subscribe(\n url: Url,\n // biome-ignore lint/suspicious/noExplicitAny: allow\n callback: (...args: any[]) => void,\n): Subscription {\n const subscription = _subscriptions[url];\n\n if (!subscription) {\n const websocket = new WebSocket(url, [], { WebSocket: IsoWebSocket });\n\n _subscriptions[url] = {\n websocket,\n callbacks: [callback],\n };\n\n websocket.addEventListener(\"message\", (message) => {\n const data = JSON.parse(message.data);\n _subscriptions[url]?.callbacks.forEach((cb) => cb(data));\n });\n } else {\n subscription.callbacks.push(callback);\n }\n\n const callbackIndex = _subscriptions[url]?.callbacks.length - 1;\n\n return {\n get url() {\n return url;\n },\n unsubscribe() {\n const subscription = _subscriptions[url];\n\n if (!subscription) {\n return;\n }\n\n subscription.callbacks.splice(callbackIndex, 1);\n\n if (!subscription.callbacks.length) {\n subscription.websocket.close();\n delete _subscriptions[url];\n }\n },\n };\n}\n\ntype EventPayload = {\n tx_hash: string;\n type: \"event\";\n number: number;\n key: string;\n value: Record<string, unknown>;\n module: {\n type: \"moduleRef\";\n name: string;\n };\n};\n\nexport interface SubscriptionToCallbackMap {\n events: (event: EventPayload) => Promise<void>;\n}\n\nexport function createSubscription<T extends keyof SubscriptionToCallbackMap>(\n subscription: T,\n callback: SubscriptionToCallbackMap[T],\n client: SovereignSDK,\n): Subscription {\n switch (subscription) {\n case \"events\": {\n const url = client.buildURL(\"/sequencer/events/ws\", {});\n return subscribe(\n httpToWebSocket(url),\n callback as SubscriptionToCallbackMap[\"events\"],\n );\n }\n default:\n throw new SovereignError(`Invalid subscription type '${subscription}'`);\n }\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: string;\n gas_limit: number[] | null;\n chain_id: number;\n};\n\nexport type UnsignedTransaction<RuntimeCall> = {\n runtime_call: RuntimeCall;\n generation: 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 useOrFetchGeneration = async <S extends StandardRollupSpec<unknown>>({\n overrides,\n}: Omit<\n UnsignedTransactionContext<S, StandardRollupContext>,\n \"runtimeCall\"\n>) => {\n if (overrides?.generation !== undefined && overrides.generation >= 0) {\n return overrides.generation;\n }\n\n return new Date().getTime();\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 { generation: _, ...overrides } = context.overrides;\n const generation = await useOrFetchGeneration(context);\n const details: TxDetails = {\n ...rollup.context.defaultTxDetails,\n ...overrides.details,\n };\n\n return {\n runtime_call: runtimeCall,\n generation,\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 /** The generation of the transaction for uniquness purposes. */\n generation?: 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, generation: overrideGeneration }: SimulateParams,\n ): Promise<SovereignClient.Rollup.SimulateExecutionResponse> {\n const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const generation = await useOrFetchGeneration({\n sender: publicKey,\n rollup: this,\n overrides: { generation: overrideGeneration },\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 generation,\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,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AAA,QACtC;AAAA,MACF,CAAC;AAGD,aAAO,SAAS;AAAA,IAClB;AAAA;AACF;AAEA,SAAsB,qBAIpB,QACA,sBAGA;AAAA;AA9JF;AA+JE,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;;;ACtKA,YAAYC,sBAAqB;AACjC,SAAS,UAAAC,eAAc;","names":["_a","subscription","bytesToHex","_a","bytesToHex","SovereignClient","Schema"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sovereign-sdk/web3",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "files": [
5
5
  "dist",
6
6
  "package.json"
@@ -23,10 +23,13 @@
23
23
  "typescript": "^5.0.0"
24
24
  },
25
25
  "dependencies": {
26
- "@sovereign-sdk/client": "0.1.0-alpha.23",
26
+ "@sovereign-sdk/client": "0.1.0-alpha.28",
27
+ "isomorphic-ws": "^5.0.0",
27
28
  "js-base64": "^3.7.7",
28
- "@sovereign-sdk/universal-wallet-wasm": "^0.2.0",
29
+ "partysocket": "^1.1.3",
30
+ "ws": "^8.18.1",
29
31
  "@sovereign-sdk/signers": "^0.0.3",
32
+ "@sovereign-sdk/universal-wallet-wasm": "^0.2.0",
30
33
  "@sovereign-sdk/utils": "^0.0.2"
31
34
  },
32
35
  "publishConfig": {