@sovereign-sdk/web3 0.8.1 → 0.9.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 +11 -83
- package/dist/index.d.ts +11 -83
- package/dist/index.js +29 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.d.mts
CHANGED
|
@@ -2,9 +2,8 @@ import { HexString } from '@sovereign-sdk/utils';
|
|
|
2
2
|
import SovereignClient__default from '@sovereign-sdk/client';
|
|
3
3
|
import * as SovereignClient from '@sovereign-sdk/client';
|
|
4
4
|
export { SovereignClient };
|
|
5
|
+
import { RollupSchema, Serializer } from '@sovereign-sdk/serializers';
|
|
5
6
|
import { Signer } from '@sovereign-sdk/signers';
|
|
6
|
-
import { Schema } from '@sovereign-sdk/universal-wallet-wasm';
|
|
7
|
-
export { Schema } from '@sovereign-sdk/universal-wallet-wasm';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Encodes a public key as a bech32m address with the given human-readable part (hrp).
|
|
@@ -17,77 +16,6 @@ export { Schema } from '@sovereign-sdk/universal-wallet-wasm';
|
|
|
17
16
|
*/
|
|
18
17
|
declare function addressFromPublicKey(publicKey: HexString | Uint8Array, hrp: string, concatPublicKey?: number): string;
|
|
19
18
|
|
|
20
|
-
/**
|
|
21
|
-
* A rollup schema is a description of the types that are utilized in the rollup.
|
|
22
|
-
* It is used to serialize and deserialize the types.
|
|
23
|
-
* As well as display them in a human-readable way that is verified by the rollup.
|
|
24
|
-
*/
|
|
25
|
-
type RollupSchema = object;
|
|
26
|
-
/**
|
|
27
|
-
* A serializer is used to serialize rollup types to Borsh bytes.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const serializer = createSerializer(yourSchema);
|
|
32
|
-
* const runtimeCall = {
|
|
33
|
-
* value_setter: {
|
|
34
|
-
* set_value: {
|
|
35
|
-
* value: 100,
|
|
36
|
-
* gas: null
|
|
37
|
-
* },
|
|
38
|
-
* },
|
|
39
|
-
* };
|
|
40
|
-
* const borshBytes = serializer.serializeRuntimeCall(runtimeCall);
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
type RollupSerializer = {
|
|
44
|
-
/**
|
|
45
|
-
* Serialize an input to Borsh bytes.
|
|
46
|
-
*
|
|
47
|
-
* Treats `Uint8Array` as a plain array of numbers as this is the format used by universal-wallet-wasm
|
|
48
|
-
* to represent Borsh bytes.
|
|
49
|
-
*
|
|
50
|
-
* @param input - The input to serialize.
|
|
51
|
-
* @param index - The index of the type in the schema to serialize.
|
|
52
|
-
* @returns The serialized Borsh bytes.
|
|
53
|
-
*/
|
|
54
|
-
serialize(input: unknown, index: number): Uint8Array;
|
|
55
|
-
/**
|
|
56
|
-
* Serialize a runtime call to Borsh bytes.
|
|
57
|
-
*
|
|
58
|
-
* @param input - The runtime call to serialize.
|
|
59
|
-
* @returns The serialized Borsh bytes.
|
|
60
|
-
*/
|
|
61
|
-
serializeRuntimeCall(input: unknown): Uint8Array;
|
|
62
|
-
/**
|
|
63
|
-
* Serialize an unsigned transaction to Borsh bytes.
|
|
64
|
-
*
|
|
65
|
-
* @param input - The unsigned transaction to serialize.
|
|
66
|
-
* @returns The serialized Borsh bytes.
|
|
67
|
-
*/
|
|
68
|
-
serializeUnsignedTx(input: unknown): Uint8Array;
|
|
69
|
-
/**
|
|
70
|
-
* Serialize a transaction to Borsh bytes.
|
|
71
|
-
*
|
|
72
|
-
* @param input - The transaction to serialize.
|
|
73
|
-
* @returns The serialized Borsh bytes.
|
|
74
|
-
*/
|
|
75
|
-
serializeTx(input: unknown): Uint8Array;
|
|
76
|
-
/**
|
|
77
|
-
* Returns the `Schema` used by the serializer.
|
|
78
|
-
*/
|
|
79
|
-
get schema(): Schema;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Create a serializer for a rollup schema.
|
|
83
|
-
*
|
|
84
|
-
* @throws {@link SovereignError} - If the schema is invalid.
|
|
85
|
-
* @param schemaObject - The rollup schema.
|
|
86
|
-
* @returns The serializer.
|
|
87
|
-
*/
|
|
88
|
-
declare function createSerializer(schemaObject: RollupSchema): RollupSerializer;
|
|
89
|
-
declare function createSerializerFromHttp(client: SovereignClient__default): Promise<RollupSerializer>;
|
|
90
|
-
|
|
91
19
|
type Url = string;
|
|
92
20
|
type Subscription = {
|
|
93
21
|
/** Url providing the subscription. */
|
|
@@ -221,10 +149,12 @@ type RollupConfig<C extends RollupContext> = {
|
|
|
221
149
|
*/
|
|
222
150
|
client: SovereignClient__default;
|
|
223
151
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
152
|
+
* Creates the serializer instance to use for the rollup.
|
|
153
|
+
*
|
|
154
|
+
* This can be called more than once, for example if the chain hash changes (i.e a new rollup version)
|
|
155
|
+
* is detected then it will be called again with the new rollup schema.
|
|
226
156
|
*/
|
|
227
|
-
|
|
157
|
+
getSerializer: (schema: RollupSchema) => Serializer;
|
|
228
158
|
/**
|
|
229
159
|
* Arbitrary context that is associated with the rollup.
|
|
230
160
|
*/
|
|
@@ -270,6 +200,8 @@ type CallParams<S extends BaseTypeSpec> = {
|
|
|
270
200
|
declare class Rollup<S extends BaseTypeSpec, C extends RollupContext> {
|
|
271
201
|
private readonly _config;
|
|
272
202
|
private readonly _typeBuilder;
|
|
203
|
+
private _chainHash?;
|
|
204
|
+
private _serializer?;
|
|
273
205
|
/**
|
|
274
206
|
* Creates a new rollup client.
|
|
275
207
|
*
|
|
@@ -340,17 +272,13 @@ declare class Rollup<S extends BaseTypeSpec, C extends RollupContext> {
|
|
|
340
272
|
/**
|
|
341
273
|
* The serializer for the rollup.
|
|
342
274
|
* Can be used to serialize transactions, runtime calls, etc.
|
|
343
|
-
* See {@link RollupSerializer} for more information.
|
|
344
275
|
*/
|
|
345
|
-
|
|
276
|
+
serializer(): Promise<Serializer>;
|
|
346
277
|
/**
|
|
347
278
|
* The context for the rollup.
|
|
348
279
|
*/
|
|
349
280
|
get context(): C;
|
|
350
|
-
|
|
351
|
-
* The chain hash of the rollup.
|
|
352
|
-
*/
|
|
353
|
-
get chainHash(): Uint8Array;
|
|
281
|
+
chainHash(): Promise<Uint8Array>;
|
|
354
282
|
}
|
|
355
283
|
|
|
356
284
|
type TxDetails = {
|
|
@@ -434,4 +362,4 @@ declare class SchemaError extends SovereignError {
|
|
|
434
362
|
constructor(message: string, reason: string, schema: object);
|
|
435
363
|
}
|
|
436
364
|
|
|
437
|
-
export { type BaseTypeSpec, type CallParams, DEFAULT_TX_DETAILS, type Dedup, type EventPayload, InvalidRollupConfigError, Rollup, type RollupConfig, type RollupContext, type
|
|
365
|
+
export { type BaseTypeSpec, type CallParams, DEFAULT_TX_DETAILS, type Dedup, type EventPayload, InvalidRollupConfigError, Rollup, type RollupConfig, type RollupContext, type RollupTypeSpec, SchemaError, type SignerParams, type SimulateParams, SovereignError, StandardRollup, type StandardRollupContext, type StandardRollupSpec, type Subscription, type Transaction, type TransactionContext, type TransactionResult, type TransactionV0, type TxDetails, type TypeBuilder, type UnsignedTransaction, type UnsignedTransactionContext, VersionMismatchError, addressFromPublicKey, createStandardRollup, standardTypeBuilder };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,8 @@ import { HexString } from '@sovereign-sdk/utils';
|
|
|
2
2
|
import SovereignClient__default from '@sovereign-sdk/client';
|
|
3
3
|
import * as SovereignClient from '@sovereign-sdk/client';
|
|
4
4
|
export { SovereignClient };
|
|
5
|
+
import { RollupSchema, Serializer } from '@sovereign-sdk/serializers';
|
|
5
6
|
import { Signer } from '@sovereign-sdk/signers';
|
|
6
|
-
import { Schema } from '@sovereign-sdk/universal-wallet-wasm';
|
|
7
|
-
export { Schema } from '@sovereign-sdk/universal-wallet-wasm';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Encodes a public key as a bech32m address with the given human-readable part (hrp).
|
|
@@ -17,77 +16,6 @@ export { Schema } from '@sovereign-sdk/universal-wallet-wasm';
|
|
|
17
16
|
*/
|
|
18
17
|
declare function addressFromPublicKey(publicKey: HexString | Uint8Array, hrp: string, concatPublicKey?: number): string;
|
|
19
18
|
|
|
20
|
-
/**
|
|
21
|
-
* A rollup schema is a description of the types that are utilized in the rollup.
|
|
22
|
-
* It is used to serialize and deserialize the types.
|
|
23
|
-
* As well as display them in a human-readable way that is verified by the rollup.
|
|
24
|
-
*/
|
|
25
|
-
type RollupSchema = object;
|
|
26
|
-
/**
|
|
27
|
-
* A serializer is used to serialize rollup types to Borsh bytes.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const serializer = createSerializer(yourSchema);
|
|
32
|
-
* const runtimeCall = {
|
|
33
|
-
* value_setter: {
|
|
34
|
-
* set_value: {
|
|
35
|
-
* value: 100,
|
|
36
|
-
* gas: null
|
|
37
|
-
* },
|
|
38
|
-
* },
|
|
39
|
-
* };
|
|
40
|
-
* const borshBytes = serializer.serializeRuntimeCall(runtimeCall);
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
type RollupSerializer = {
|
|
44
|
-
/**
|
|
45
|
-
* Serialize an input to Borsh bytes.
|
|
46
|
-
*
|
|
47
|
-
* Treats `Uint8Array` as a plain array of numbers as this is the format used by universal-wallet-wasm
|
|
48
|
-
* to represent Borsh bytes.
|
|
49
|
-
*
|
|
50
|
-
* @param input - The input to serialize.
|
|
51
|
-
* @param index - The index of the type in the schema to serialize.
|
|
52
|
-
* @returns The serialized Borsh bytes.
|
|
53
|
-
*/
|
|
54
|
-
serialize(input: unknown, index: number): Uint8Array;
|
|
55
|
-
/**
|
|
56
|
-
* Serialize a runtime call to Borsh bytes.
|
|
57
|
-
*
|
|
58
|
-
* @param input - The runtime call to serialize.
|
|
59
|
-
* @returns The serialized Borsh bytes.
|
|
60
|
-
*/
|
|
61
|
-
serializeRuntimeCall(input: unknown): Uint8Array;
|
|
62
|
-
/**
|
|
63
|
-
* Serialize an unsigned transaction to Borsh bytes.
|
|
64
|
-
*
|
|
65
|
-
* @param input - The unsigned transaction to serialize.
|
|
66
|
-
* @returns The serialized Borsh bytes.
|
|
67
|
-
*/
|
|
68
|
-
serializeUnsignedTx(input: unknown): Uint8Array;
|
|
69
|
-
/**
|
|
70
|
-
* Serialize a transaction to Borsh bytes.
|
|
71
|
-
*
|
|
72
|
-
* @param input - The transaction to serialize.
|
|
73
|
-
* @returns The serialized Borsh bytes.
|
|
74
|
-
*/
|
|
75
|
-
serializeTx(input: unknown): Uint8Array;
|
|
76
|
-
/**
|
|
77
|
-
* Returns the `Schema` used by the serializer.
|
|
78
|
-
*/
|
|
79
|
-
get schema(): Schema;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Create a serializer for a rollup schema.
|
|
83
|
-
*
|
|
84
|
-
* @throws {@link SovereignError} - If the schema is invalid.
|
|
85
|
-
* @param schemaObject - The rollup schema.
|
|
86
|
-
* @returns The serializer.
|
|
87
|
-
*/
|
|
88
|
-
declare function createSerializer(schemaObject: RollupSchema): RollupSerializer;
|
|
89
|
-
declare function createSerializerFromHttp(client: SovereignClient__default): Promise<RollupSerializer>;
|
|
90
|
-
|
|
91
19
|
type Url = string;
|
|
92
20
|
type Subscription = {
|
|
93
21
|
/** Url providing the subscription. */
|
|
@@ -221,10 +149,12 @@ type RollupConfig<C extends RollupContext> = {
|
|
|
221
149
|
*/
|
|
222
150
|
client: SovereignClient__default;
|
|
223
151
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
152
|
+
* Creates the serializer instance to use for the rollup.
|
|
153
|
+
*
|
|
154
|
+
* This can be called more than once, for example if the chain hash changes (i.e a new rollup version)
|
|
155
|
+
* is detected then it will be called again with the new rollup schema.
|
|
226
156
|
*/
|
|
227
|
-
|
|
157
|
+
getSerializer: (schema: RollupSchema) => Serializer;
|
|
228
158
|
/**
|
|
229
159
|
* Arbitrary context that is associated with the rollup.
|
|
230
160
|
*/
|
|
@@ -270,6 +200,8 @@ type CallParams<S extends BaseTypeSpec> = {
|
|
|
270
200
|
declare class Rollup<S extends BaseTypeSpec, C extends RollupContext> {
|
|
271
201
|
private readonly _config;
|
|
272
202
|
private readonly _typeBuilder;
|
|
203
|
+
private _chainHash?;
|
|
204
|
+
private _serializer?;
|
|
273
205
|
/**
|
|
274
206
|
* Creates a new rollup client.
|
|
275
207
|
*
|
|
@@ -340,17 +272,13 @@ declare class Rollup<S extends BaseTypeSpec, C extends RollupContext> {
|
|
|
340
272
|
/**
|
|
341
273
|
* The serializer for the rollup.
|
|
342
274
|
* Can be used to serialize transactions, runtime calls, etc.
|
|
343
|
-
* See {@link RollupSerializer} for more information.
|
|
344
275
|
*/
|
|
345
|
-
|
|
276
|
+
serializer(): Promise<Serializer>;
|
|
346
277
|
/**
|
|
347
278
|
* The context for the rollup.
|
|
348
279
|
*/
|
|
349
280
|
get context(): C;
|
|
350
|
-
|
|
351
|
-
* The chain hash of the rollup.
|
|
352
|
-
*/
|
|
353
|
-
get chainHash(): Uint8Array;
|
|
281
|
+
chainHash(): Promise<Uint8Array>;
|
|
354
282
|
}
|
|
355
283
|
|
|
356
284
|
type TxDetails = {
|
|
@@ -434,4 +362,4 @@ declare class SchemaError extends SovereignError {
|
|
|
434
362
|
constructor(message: string, reason: string, schema: object);
|
|
435
363
|
}
|
|
436
364
|
|
|
437
|
-
export { type BaseTypeSpec, type CallParams, DEFAULT_TX_DETAILS, type Dedup, type EventPayload, InvalidRollupConfigError, Rollup, type RollupConfig, type RollupContext, type
|
|
365
|
+
export { type BaseTypeSpec, type CallParams, DEFAULT_TX_DETAILS, type Dedup, type EventPayload, InvalidRollupConfigError, Rollup, type RollupConfig, type RollupContext, type RollupTypeSpec, SchemaError, type SignerParams, type SimulateParams, SovereignError, StandardRollup, type StandardRollupContext, type StandardRollupSpec, type Subscription, type Transaction, type TransactionContext, type TransactionResult, type TransactionV0, type TxDetails, type TypeBuilder, type UnsignedTransaction, type UnsignedTransactionContext, VersionMismatchError, addressFromPublicKey, createStandardRollup, standardTypeBuilder };
|
package/dist/index.js
CHANGED
|
@@ -82,15 +82,12 @@ __export(src_exports, {
|
|
|
82
82
|
DEFAULT_TX_DETAILS: () => DEFAULT_TX_DETAILS,
|
|
83
83
|
InvalidRollupConfigError: () => InvalidRollupConfigError,
|
|
84
84
|
Rollup: () => Rollup,
|
|
85
|
-
Schema: () => import_universal_wallet_wasm2.Schema,
|
|
86
85
|
SchemaError: () => SchemaError,
|
|
87
86
|
SovereignClient: () => SovereignClient3,
|
|
88
87
|
SovereignError: () => SovereignError,
|
|
89
88
|
StandardRollup: () => StandardRollup,
|
|
90
89
|
VersionMismatchError: () => VersionMismatchError,
|
|
91
90
|
addressFromPublicKey: () => addressFromPublicKey,
|
|
92
|
-
createSerializer: () => createSerializer,
|
|
93
|
-
createSerializerFromHttp: () => createSerializerFromHttp,
|
|
94
91
|
createStandardRollup: () => createStandardRollup,
|
|
95
92
|
standardTypeBuilder: () => standardTypeBuilder
|
|
96
93
|
});
|
|
@@ -139,70 +136,6 @@ var SchemaError = class extends SovereignError {
|
|
|
139
136
|
}
|
|
140
137
|
};
|
|
141
138
|
|
|
142
|
-
// src/serialization.ts
|
|
143
|
-
var import_universal_wallet_wasm = require("@sovereign-sdk/universal-wallet-wasm");
|
|
144
|
-
function loadSchema(schemaObject) {
|
|
145
|
-
try {
|
|
146
|
-
return import_universal_wallet_wasm.Schema.fromJSON(JSON.stringify(schemaObject));
|
|
147
|
-
} catch (err) {
|
|
148
|
-
throw new SchemaError(
|
|
149
|
-
"Failed to create runtime schema",
|
|
150
|
-
err.message,
|
|
151
|
-
schemaObject
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
function createSerializer(schemaObject) {
|
|
156
|
-
const schema = loadSchema(schemaObject);
|
|
157
|
-
return {
|
|
158
|
-
schema,
|
|
159
|
-
serialize(input, index) {
|
|
160
|
-
try {
|
|
161
|
-
return schema.jsonToBorsh(
|
|
162
|
-
index,
|
|
163
|
-
JSON.stringify(input, (_, value) => {
|
|
164
|
-
if (value instanceof Uint8Array) {
|
|
165
|
-
return Array.from(value);
|
|
166
|
-
}
|
|
167
|
-
return value;
|
|
168
|
-
})
|
|
169
|
-
);
|
|
170
|
-
} catch (err) {
|
|
171
|
-
throw new SchemaError(
|
|
172
|
-
"Input serialization failed",
|
|
173
|
-
err.message,
|
|
174
|
-
schemaObject
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
serializeRuntimeCall(input) {
|
|
179
|
-
return this.serialize(
|
|
180
|
-
input,
|
|
181
|
-
schema.knownTypeIndex(import_universal_wallet_wasm.KnownTypeId.RuntimeCall)
|
|
182
|
-
);
|
|
183
|
-
},
|
|
184
|
-
serializeUnsignedTx(input) {
|
|
185
|
-
return this.serialize(
|
|
186
|
-
input,
|
|
187
|
-
schema.knownTypeIndex(import_universal_wallet_wasm.KnownTypeId.UnsignedTransaction)
|
|
188
|
-
);
|
|
189
|
-
},
|
|
190
|
-
serializeTx(input) {
|
|
191
|
-
return this.serialize(
|
|
192
|
-
input,
|
|
193
|
-
schema.knownTypeIndex(import_universal_wallet_wasm.KnownTypeId.Transaction)
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
function createSerializerFromHttp(client) {
|
|
199
|
-
return __async(this, null, function* () {
|
|
200
|
-
const response = yield client.rollup.schema.retrieve();
|
|
201
|
-
const schema = response;
|
|
202
|
-
return createSerializer(schema);
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
|
|
206
139
|
// src/subscriptions.ts
|
|
207
140
|
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
208
141
|
var import_partysocket = require("partysocket");
|
|
@@ -295,12 +228,14 @@ var Rollup = class {
|
|
|
295
228
|
*/
|
|
296
229
|
submitTransaction(transaction, options) {
|
|
297
230
|
return __async(this, null, function* () {
|
|
298
|
-
const
|
|
231
|
+
const serializer = yield this.serializer();
|
|
232
|
+
const serializedTx = serializer.serializeTx(transaction);
|
|
299
233
|
return this.sequencer.txs.create({ body: import_js_base64.Base64.fromUint8Array(serializedTx) }, options).catch((e) => __async(this, null, function* () {
|
|
300
234
|
if (isVersionMismatchError(e)) {
|
|
301
|
-
const oldVersion = (0, import_utils2.bytesToHex)(this.chainHash);
|
|
302
|
-
|
|
303
|
-
|
|
235
|
+
const oldVersion = (0, import_utils2.bytesToHex)(yield this.chainHash());
|
|
236
|
+
const { schema, chain_hash: newVersion } = yield this.rollup.schema.retrieve();
|
|
237
|
+
this._chainHash = (0, import_utils2.hexToBytes)(newVersion);
|
|
238
|
+
this._serializer = this._config.getSerializer(schema);
|
|
304
239
|
if (oldVersion !== newVersion) {
|
|
305
240
|
throw new VersionMismatchError(
|
|
306
241
|
"Schema version mismatch when submitting transaction",
|
|
@@ -323,9 +258,11 @@ var Rollup = class {
|
|
|
323
258
|
*/
|
|
324
259
|
signAndSubmitTransaction(_0, _1, _2) {
|
|
325
260
|
return __async(this, arguments, function* (unsignedTx, { signer }, options) {
|
|
326
|
-
const
|
|
261
|
+
const serializer = yield this.serializer();
|
|
262
|
+
const serializedUnsignedTx = serializer.serializeUnsignedTx(unsignedTx);
|
|
263
|
+
const chainHash = yield this.chainHash();
|
|
327
264
|
const signature = yield signer.sign(
|
|
328
|
-
new Uint8Array([...serializedUnsignedTx, ...
|
|
265
|
+
new Uint8Array([...serializedUnsignedTx, ...chainHash])
|
|
329
266
|
);
|
|
330
267
|
const publicKey = yield signer.publicKey();
|
|
331
268
|
const context = {
|
|
@@ -415,10 +352,14 @@ var Rollup = class {
|
|
|
415
352
|
/**
|
|
416
353
|
* The serializer for the rollup.
|
|
417
354
|
* Can be used to serialize transactions, runtime calls, etc.
|
|
418
|
-
* See {@link RollupSerializer} for more information.
|
|
419
355
|
*/
|
|
420
|
-
|
|
421
|
-
return this
|
|
356
|
+
serializer() {
|
|
357
|
+
return __async(this, null, function* () {
|
|
358
|
+
if (this._serializer) return this._serializer;
|
|
359
|
+
const { schema } = yield this.rollup.schema.retrieve();
|
|
360
|
+
this._serializer = this._config.getSerializer(schema);
|
|
361
|
+
return this._serializer;
|
|
362
|
+
});
|
|
422
363
|
}
|
|
423
364
|
/**
|
|
424
365
|
* The context for the rollup.
|
|
@@ -426,11 +367,13 @@ var Rollup = class {
|
|
|
426
367
|
get context() {
|
|
427
368
|
return this._config.context;
|
|
428
369
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
370
|
+
chainHash() {
|
|
371
|
+
return __async(this, null, function* () {
|
|
372
|
+
if (this._chainHash) return this._chainHash;
|
|
373
|
+
const { chain_hash } = yield this.rollup.schema.retrieve();
|
|
374
|
+
this._chainHash = (0, import_utils2.hexToBytes)(chain_hash);
|
|
375
|
+
return this._chainHash;
|
|
376
|
+
});
|
|
434
377
|
}
|
|
435
378
|
};
|
|
436
379
|
function isVersionMismatchError(e) {
|
|
@@ -446,6 +389,7 @@ function isVersionMismatchError(e) {
|
|
|
446
389
|
|
|
447
390
|
// src/rollup/standard-rollup.ts
|
|
448
391
|
var import_client2 = __toESM(require("@sovereign-sdk/client"));
|
|
392
|
+
var import_serializers = require("@sovereign-sdk/serializers");
|
|
449
393
|
var import_utils3 = require("@sovereign-sdk/utils");
|
|
450
394
|
var useOrFetchGeneration = (_0) => __async(void 0, [_0], function* ({
|
|
451
395
|
overrides
|
|
@@ -502,7 +446,8 @@ var StandardRollup = class extends Rollup {
|
|
|
502
446
|
*/
|
|
503
447
|
simulate(_0, _1) {
|
|
504
448
|
return __async(this, arguments, function* (runtimeMessage, { signer, txDetails, generation: overrideGeneration }) {
|
|
505
|
-
const
|
|
449
|
+
const serializer = yield this.serializer();
|
|
450
|
+
const runtimeCall = serializer.serializeRuntimeCall(runtimeMessage);
|
|
506
451
|
const publicKey = yield signer.publicKey();
|
|
507
452
|
const generation = yield useOrFetchGeneration({
|
|
508
453
|
rollup: this,
|
|
@@ -545,10 +490,10 @@ function createStandardRollup(rollupConfig, typeBuilderOverrides) {
|
|
|
545
490
|
var _a, _b;
|
|
546
491
|
const config = rollupConfig != null ? rollupConfig : {};
|
|
547
492
|
const client = (_a = config.client) != null ? _a : new import_client2.default({ baseURL: config.url });
|
|
548
|
-
const
|
|
493
|
+
const getSerializer = (_b = config.getSerializer) != null ? _b : (schema) => new import_serializers.JsSerializer(schema);
|
|
549
494
|
const context = yield buildContext(client, config.context);
|
|
550
495
|
return new StandardRollup(
|
|
551
|
-
__spreadProps(__spreadValues({}, config), { client,
|
|
496
|
+
__spreadProps(__spreadValues({}, config), { client, getSerializer, context }),
|
|
552
497
|
__spreadValues(__spreadValues({}, standardTypeBuilder()), typeBuilderOverrides)
|
|
553
498
|
);
|
|
554
499
|
});
|
|
@@ -556,21 +501,17 @@ function createStandardRollup(rollupConfig, typeBuilderOverrides) {
|
|
|
556
501
|
|
|
557
502
|
// src/index.ts
|
|
558
503
|
var SovereignClient3 = __toESM(require("@sovereign-sdk/client"));
|
|
559
|
-
var import_universal_wallet_wasm2 = require("@sovereign-sdk/universal-wallet-wasm");
|
|
560
504
|
// Annotate the CommonJS export names for ESM import in node:
|
|
561
505
|
0 && (module.exports = {
|
|
562
506
|
DEFAULT_TX_DETAILS,
|
|
563
507
|
InvalidRollupConfigError,
|
|
564
508
|
Rollup,
|
|
565
|
-
Schema,
|
|
566
509
|
SchemaError,
|
|
567
510
|
SovereignClient,
|
|
568
511
|
SovereignError,
|
|
569
512
|
StandardRollup,
|
|
570
513
|
VersionMismatchError,
|
|
571
514
|
addressFromPublicKey,
|
|
572
|
-
createSerializer,
|
|
573
|
-
createSerializerFromHttp,
|
|
574
515
|
createStandardRollup,
|
|
575
516
|
standardTypeBuilder
|
|
576
517
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/addresses.ts","../src/rollup/rollup.ts","../src/errors.ts","../src/serialization.ts","../src/subscriptions.ts","../src/rollup/standard-rollup.ts"],"sourcesContent":["export * from \"./addresses\";\nexport * from \"./rollup\";\nexport * from \"./serialization\";\nexport * from \"./errors\";\nexport * from \"./type-spec\";\nexport { type EventPayload, Subscription } from \"./subscriptions\";\nexport * as SovereignClient from \"@sovereign-sdk/client\";\nexport { Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\n","import { type HexString, ensureBytes } from \"@sovereign-sdk/utils\";\nimport { bech32m } from \"bech32\";\n\n/**\n * Encodes a public key as a bech32m address with the given human-readable part (hrp).\n *\n * @param publicKey - The public key to encode, as a hex string or Uint8Array.\n * @param hrp - The human-readable part for the bech32m address (e.g., \"sov\").\n * @param concatPublicKey - Optional. If provided, only the first `concatPublicKey` bytes of the public key are used.\n * @returns The bech32m-encoded address as a string.\n * @throws {Error} If the public key is not a valid hex string or Uint8Array.\n */\nexport function addressFromPublicKey(\n publicKey: HexString | Uint8Array,\n hrp: string,\n concatPublicKey = 28,\n): string {\n let publicKeyBytes = ensureBytes(publicKey);\n\n if (concatPublicKey !== publicKey.length) {\n publicKeyBytes = publicKeyBytes.slice(0, concatPublicKey);\n }\n\n const words = bech32m.toWords(publicKeyBytes);\n return bech32m.encode(hrp, words);\n}\n","import 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 { 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 // 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 */\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 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 * 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 response = await this.rollup.addresses.dedup(bytesToHex(address));\n return response as S[\"Dedup\"];\n }\n\n /**\n * Submits a transaction to the rollup.\n *\n * @param transaction - The transaction to submit.\n * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async submitTransaction(\n transaction: S[\"Transaction\"],\n options?: SovereignClient.RequestOptions,\n ): Promise<SovereignClient.Sequencer.TxCreateResponse> {\n const serializedTx = this.serializer.serializeTx(transaction);\n\n return this.sequencer.txs\n .create({ body: Base64.fromUint8Array(serializedTx) }, options)\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 * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async signAndSubmitTransaction(\n unsignedTx: S[\"UnsignedTransaction\"],\n { signer }: SignerParams,\n options?: SovereignClient.RequestOptions,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const serializedUnsignedTx =\n this.serializer.serializeUnsignedTx(unsignedTx);\n const signature = await signer.sign(\n new Uint8Array([...serializedUnsignedTx, ...this.chainHash]),\n );\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, options);\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 * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async call(\n runtimeCall: S[\"RuntimeCall\"],\n { signer, overrides }: CallParams<S>,\n options?: SovereignClient.RequestOptions,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const context = {\n runtimeCall,\n rollup: this,\n overrides: overrides ?? ({} as DeepPartial<S[\"UnsignedTransaction\"]>),\n };\n const unsignedTx = await this._typeBuilder.unsignedTransaction(context);\n\n return this.signAndSubmitTransaction(\n unsignedTx,\n {\n signer,\n },\n options,\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 * Performs a healthcheck against the rollup to determine if it is currently healthy.\n *\n * @param timeout - Request timeout in milliseconds.\n * @returns `true` if the rollup is considered healthy otherwise `false`.\n */\n async healthcheck(timeout = 5000): Promise<boolean> {\n try {\n await this.http.get(\"/healthcheck\", { timeout, maxRetries: 1 });\n return true;\n } catch (e) {\n return !(e instanceof SovereignClient.APIConnectionError);\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)?.details?.error?.includes(\"Signature verification failed\")\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 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}: ${reason}`);\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 { 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 response = await client.rollup.schema.retrieve();\n const schema = response as RollupSchema;\n\n return createSerializer(schema);\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 // bun compatibility: https://github.com/partykit/partykit/issues/774\n websocket.binaryType = \"arraybuffer\";\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 websocket.addEventListener(\"error\", (e) =>\n console.log(\"Websocket error\", e),\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\nexport type 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 type { DeepPartial } from \"../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: 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 TransactionV0<RuntimeCall> = {\n pub_key: { pub_key: Uint8Array };\n signature: { msg_sig: Uint8Array };\n} & UnsignedTransaction<RuntimeCall>;\n\nexport type Transaction<RuntimeCall> = {\n versioned_tx: { V0: TransactionV0<RuntimeCall> };\n};\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 Date.now();\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 versioned_tx: {\n V0: {\n pub_key: {\n pub_key: sender,\n },\n signature: {\n msg_sig: signature,\n },\n ...unsignedTx,\n },\n },\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 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 return response;\n }\n}\n\nexport const DEFAULT_TX_DETAILS: Omit<TxDetails, \"chain_id\"> = {\n max_priority_fee_bips: 0,\n max_fee: \"100000000\",\n gas_limit: null,\n};\n\nasync function buildContext<C extends StandardRollupContext>(\n client: SovereignClient,\n context?: DeepPartial<C>,\n): Promise<C> {\n const defaultTxDetails = {\n ...DEFAULT_TX_DETAILS,\n ...context?.defaultTxDetails,\n };\n\n if (!defaultTxDetails.chain_id) {\n const { chain_id } = await client.rollup.constants.retrieve();\n\n defaultTxDetails.chain_id = chain_id;\n }\n\n return {\n defaultTxDetails,\n } as C;\n}\n\nexport async function createStandardRollup<\n RuntimeCall,\n C extends StandardRollupContext = StandardRollupContext,\n>(\n rollupConfig?: Partial<RollupConfig<DeepPartial<C>>>,\n typeBuilderOverrides?: Partial<\n TypeBuilder<StandardRollupSpec<RuntimeCall>, C>\n >,\n) {\n const config = rollupConfig ?? {};\n const client = config.client ?? new SovereignClient({ baseURL: config.url });\n const serializer =\n config.serializer ?? (await createSerializerFromHttp(client));\n const context = await buildContext<C>(client, config.context);\n\n return new StandardRollup<RuntimeCall>(\n { ...config, client, serializer, context },\n {\n ...standardTypeBuilder(),\n ...typeBuilderOverrides,\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,YAAO,eAAP,YAAsB,MAAM,yBAAyB,MAAM;AAC7D,UAAM,UAAU,MAAM,aAAgB,QAAQ,OAAO,OAAO;AAE5D,WAAO,IAAI;AAAA,MACT,iCAAK,SAAL,EAAa,QAAQ,YAAY,QAAQ;AAAA,MACzC,kCACK,oBAAoB,IACpB;AAAA,IAEP;AAAA,EACF;AAAA;;;ANvMA,IAAAC,mBAAiC;AACjC,IAAAC,gCAAuB;","names":["SovereignClient","import_utils","IsoWebSocket","_a","subscription","SovereignClient","import_client","import_utils","_a","SovereignClient","SovereignClient","import_universal_wallet_wasm"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/addresses.ts","../src/rollup/rollup.ts","../src/errors.ts","../src/subscriptions.ts","../src/rollup/standard-rollup.ts"],"sourcesContent":["export * from \"./addresses\";\nexport * from \"./rollup\";\nexport * from \"./errors\";\nexport * from \"./type-spec\";\nexport { type EventPayload, Subscription } from \"./subscriptions\";\nexport * as SovereignClient from \"@sovereign-sdk/client\";\n","import { type HexString, ensureBytes } from \"@sovereign-sdk/utils\";\nimport { bech32m } from \"bech32\";\n\n/**\n * Encodes a public key as a bech32m address with the given human-readable part (hrp).\n *\n * @param publicKey - The public key to encode, as a hex string or Uint8Array.\n * @param hrp - The human-readable part for the bech32m address (e.g., \"sov\").\n * @param concatPublicKey - Optional. If provided, only the first `concatPublicKey` bytes of the public key are used.\n * @returns The bech32m-encoded address as a string.\n * @throws {Error} If the public key is not a valid hex string or Uint8Array.\n */\nexport function addressFromPublicKey(\n publicKey: HexString | Uint8Array,\n hrp: string,\n concatPublicKey = 28,\n): string {\n let publicKeyBytes = ensureBytes(publicKey);\n\n if (concatPublicKey !== publicKey.length) {\n publicKeyBytes = publicKeyBytes.slice(0, concatPublicKey);\n }\n\n const words = bech32m.toWords(publicKeyBytes);\n return bech32m.encode(hrp, words);\n}\n","import SovereignClient from \"@sovereign-sdk/client\";\nimport type { APIError } from \"@sovereign-sdk/client\";\nimport type { RollupSchema, Serializer } from \"@sovereign-sdk/serializers\";\nimport type { Signer } from \"@sovereign-sdk/signers\";\nimport { bytesToHex, hexToBytes } from \"@sovereign-sdk/utils\";\nimport { Base64 } from \"js-base64\";\nimport { VersionMismatchError } from \"../errors\";\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 // 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 */\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 PartialRollupConfig.url}.\n */\n client: SovereignClient;\n /**\n * Creates the serializer instance to use for the rollup.\n *\n * This can be called more than once, for example if the chain hash changes (i.e a new rollup version)\n * is detected then it will be called again with the new rollup schema.\n */\n getSerializer: (schema: RollupSchema) => Serializer;\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 _typeBuilder: TypeBuilder<S, C>;\n private _chainHash?: Uint8Array;\n private _serializer?: Serializer;\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 response = await this.rollup.addresses.dedup(bytesToHex(address));\n return response as S[\"Dedup\"];\n }\n\n /**\n * Submits a transaction to the rollup.\n *\n * @param transaction - The transaction to submit.\n * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async submitTransaction(\n transaction: S[\"Transaction\"],\n options?: SovereignClient.RequestOptions,\n ): Promise<SovereignClient.Sequencer.TxCreateResponse> {\n const serializer = await this.serializer();\n const serializedTx = serializer.serializeTx(transaction);\n\n return this.sequencer.txs\n .create({ body: Base64.fromUint8Array(serializedTx) }, options)\n .catch(async (e) => {\n if (isVersionMismatchError(e as APIError)) {\n const oldVersion = bytesToHex(await this.chainHash());\n const { schema, chain_hash: newVersion } =\n await this.rollup.schema.retrieve();\n this._chainHash = hexToBytes(newVersion);\n this._serializer = this._config.getSerializer(schema);\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 * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async signAndSubmitTransaction(\n unsignedTx: S[\"UnsignedTransaction\"],\n { signer }: SignerParams,\n options?: SovereignClient.RequestOptions,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const serializer = await this.serializer();\n const serializedUnsignedTx = serializer.serializeUnsignedTx(unsignedTx);\n const chainHash = await this.chainHash();\n const signature = await signer.sign(\n new Uint8Array([...serializedUnsignedTx, ...chainHash]),\n );\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, options);\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 * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async call(\n runtimeCall: S[\"RuntimeCall\"],\n { signer, overrides }: CallParams<S>,\n options?: SovereignClient.RequestOptions,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const context = {\n runtimeCall,\n rollup: this,\n overrides: overrides ?? ({} as DeepPartial<S[\"UnsignedTransaction\"]>),\n };\n const unsignedTx = await this._typeBuilder.unsignedTransaction(context);\n\n return this.signAndSubmitTransaction(\n unsignedTx,\n {\n signer,\n },\n options,\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 * Performs a healthcheck against the rollup to determine if it is currently healthy.\n *\n * @param timeout - Request timeout in milliseconds.\n * @returns `true` if the rollup is considered healthy otherwise `false`.\n */\n async healthcheck(timeout = 5000): Promise<boolean> {\n try {\n await this.http.get(\"/healthcheck\", { timeout, maxRetries: 1 });\n return true;\n } catch (e) {\n return !(e instanceof SovereignClient.APIConnectionError);\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 */\n async serializer(): Promise<Serializer> {\n if (this._serializer) return this._serializer;\n const { schema } = await this.rollup.schema.retrieve();\n this._serializer = this._config.getSerializer(schema);\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 async chainHash(): Promise<Uint8Array> {\n if (this._chainHash) return this._chainHash;\n const { chain_hash } = await this.rollup.schema.retrieve();\n this._chainHash = hexToBytes(chain_hash);\n return this._chainHash;\n }\n}\n\nfunction isVersionMismatchError(e: APIError): boolean {\n if (\n // biome-ignore lint/suspicious/noExplicitAny: yolo\n (e.error as any)?.details?.error?.includes(\"Signature verification failed\")\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 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}: ${reason}`);\n\n this.reason = reason;\n this.schema = schema;\n }\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 // bun compatibility: https://github.com/partykit/partykit/issues/774\n websocket.binaryType = \"arraybuffer\";\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 websocket.addEventListener(\"error\", (e) =>\n console.log(\"Websocket error\", e),\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\nexport type 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 { JsSerializer } from \"@sovereign-sdk/serializers\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport type { DeepPartial } from \"../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: 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 TransactionV0<RuntimeCall> = {\n pub_key: { pub_key: Uint8Array };\n signature: { msg_sig: Uint8Array };\n} & UnsignedTransaction<RuntimeCall>;\n\nexport type Transaction<RuntimeCall> = {\n versioned_tx: { V0: TransactionV0<RuntimeCall> };\n};\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 Date.now();\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 versioned_tx: {\n V0: {\n pub_key: {\n pub_key: sender,\n },\n signature: {\n msg_sig: signature,\n },\n ...unsignedTx,\n },\n },\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 serializer = await this.serializer();\n const runtimeCall = serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const generation = await useOrFetchGeneration({\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 return response;\n }\n}\n\nexport const DEFAULT_TX_DETAILS: Omit<TxDetails, \"chain_id\"> = {\n max_priority_fee_bips: 0,\n max_fee: \"100000000\",\n gas_limit: null,\n};\n\nasync function buildContext<C extends StandardRollupContext>(\n client: SovereignClient,\n context?: DeepPartial<C>,\n): Promise<C> {\n const defaultTxDetails = {\n ...DEFAULT_TX_DETAILS,\n ...context?.defaultTxDetails,\n };\n\n if (!defaultTxDetails.chain_id) {\n const { chain_id } = await client.rollup.constants.retrieve();\n\n defaultTxDetails.chain_id = chain_id;\n }\n\n return {\n defaultTxDetails,\n } as C;\n}\n\nexport async function createStandardRollup<\n RuntimeCall,\n C extends StandardRollupContext = StandardRollupContext,\n>(\n rollupConfig?: Partial<RollupConfig<DeepPartial<C>>>,\n typeBuilderOverrides?: Partial<\n TypeBuilder<StandardRollupSpec<RuntimeCall>, C>\n >,\n) {\n const config = rollupConfig ?? {};\n const client = config.client ?? new SovereignClient({ baseURL: config.url });\n const getSerializer =\n config.getSerializer ?? ((schema) => new JsSerializer(schema));\n const context = await buildContext<C>(client, config.context);\n\n return new StandardRollup<RuntimeCall>(\n { ...config, client, getSerializer, context },\n {\n ...standardTypeBuilder(),\n ...typeBuilderOverrides,\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAC7D,uBAAuB;AAAA,EACvB,SAAS;AAAA,EACT,WAAW;AACb;AAEA,SAAe,aACb,QACA,SACY;AAAA;AACZ,UAAM,mBAAmB,kCACpB,qBACA,mCAAS;AAGd,QAAI,CAAC,iBAAiB,UAAU;AAC9B,YAAM,EAAE,SAAS,IAAI,MAAM,OAAO,OAAO,UAAU,SAAS;AAE5D,uBAAiB,WAAW;AAAA,IAC9B;AAEA,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA;AAEA,SAAsB,qBAIpB,cACA,sBAGA;AAAA;AAhMF;AAiME,UAAM,SAAS,sCAAgB,CAAC;AAChC,UAAM,UAAS,YAAO,WAAP,YAAiB,IAAI,eAAAC,QAAgB,EAAE,SAAS,OAAO,IAAI,CAAC;AAC3E,UAAM,iBACJ,YAAO,kBAAP,YAAyB,CAAC,WAAW,IAAI,gCAAa,MAAM;AAC9D,UAAM,UAAU,MAAM,aAAgB,QAAQ,OAAO,OAAO;AAE5D,WAAO,IAAI;AAAA,MACT,iCAAK,SAAL,EAAa,QAAQ,eAAe,QAAQ;AAAA,MAC5C,kCACK,oBAAoB,IACpB;AAAA,IAEP;AAAA,EACF;AAAA;;;ALzMA,IAAAC,mBAAiC;","names":["SovereignClient","import_utils","IsoWebSocket","_a","subscription","SovereignClient","import_client","import_utils","_a","SovereignClient","SovereignClient"]}
|
package/dist/index.mjs
CHANGED
|
@@ -64,7 +64,7 @@ function addressFromPublicKey(publicKey, hrp, concatPublicKey = 28) {
|
|
|
64
64
|
|
|
65
65
|
// src/rollup/rollup.ts
|
|
66
66
|
import SovereignClient from "@sovereign-sdk/client";
|
|
67
|
-
import { bytesToHex } from "@sovereign-sdk/utils";
|
|
67
|
+
import { bytesToHex, hexToBytes } from "@sovereign-sdk/utils";
|
|
68
68
|
import { Base64 } from "js-base64";
|
|
69
69
|
|
|
70
70
|
// src/errors.ts
|
|
@@ -93,70 +93,6 @@ var SchemaError = class extends SovereignError {
|
|
|
93
93
|
}
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
// src/serialization.ts
|
|
97
|
-
import { KnownTypeId, Schema } from "@sovereign-sdk/universal-wallet-wasm";
|
|
98
|
-
function loadSchema(schemaObject) {
|
|
99
|
-
try {
|
|
100
|
-
return Schema.fromJSON(JSON.stringify(schemaObject));
|
|
101
|
-
} catch (err) {
|
|
102
|
-
throw new SchemaError(
|
|
103
|
-
"Failed to create runtime schema",
|
|
104
|
-
err.message,
|
|
105
|
-
schemaObject
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function createSerializer(schemaObject) {
|
|
110
|
-
const schema = loadSchema(schemaObject);
|
|
111
|
-
return {
|
|
112
|
-
schema,
|
|
113
|
-
serialize(input, index) {
|
|
114
|
-
try {
|
|
115
|
-
return schema.jsonToBorsh(
|
|
116
|
-
index,
|
|
117
|
-
JSON.stringify(input, (_, value) => {
|
|
118
|
-
if (value instanceof Uint8Array) {
|
|
119
|
-
return Array.from(value);
|
|
120
|
-
}
|
|
121
|
-
return value;
|
|
122
|
-
})
|
|
123
|
-
);
|
|
124
|
-
} catch (err) {
|
|
125
|
-
throw new SchemaError(
|
|
126
|
-
"Input serialization failed",
|
|
127
|
-
err.message,
|
|
128
|
-
schemaObject
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
serializeRuntimeCall(input) {
|
|
133
|
-
return this.serialize(
|
|
134
|
-
input,
|
|
135
|
-
schema.knownTypeIndex(KnownTypeId.RuntimeCall)
|
|
136
|
-
);
|
|
137
|
-
},
|
|
138
|
-
serializeUnsignedTx(input) {
|
|
139
|
-
return this.serialize(
|
|
140
|
-
input,
|
|
141
|
-
schema.knownTypeIndex(KnownTypeId.UnsignedTransaction)
|
|
142
|
-
);
|
|
143
|
-
},
|
|
144
|
-
serializeTx(input) {
|
|
145
|
-
return this.serialize(
|
|
146
|
-
input,
|
|
147
|
-
schema.knownTypeIndex(KnownTypeId.Transaction)
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function createSerializerFromHttp(client) {
|
|
153
|
-
return __async(this, null, function* () {
|
|
154
|
-
const response = yield client.rollup.schema.retrieve();
|
|
155
|
-
const schema = response;
|
|
156
|
-
return createSerializer(schema);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
96
|
// src/subscriptions.ts
|
|
161
97
|
import IsoWebSocket from "isomorphic-ws";
|
|
162
98
|
import { WebSocket } from "partysocket";
|
|
@@ -249,12 +185,14 @@ var Rollup = class {
|
|
|
249
185
|
*/
|
|
250
186
|
submitTransaction(transaction, options) {
|
|
251
187
|
return __async(this, null, function* () {
|
|
252
|
-
const
|
|
188
|
+
const serializer = yield this.serializer();
|
|
189
|
+
const serializedTx = serializer.serializeTx(transaction);
|
|
253
190
|
return this.sequencer.txs.create({ body: Base64.fromUint8Array(serializedTx) }, options).catch((e) => __async(this, null, function* () {
|
|
254
191
|
if (isVersionMismatchError(e)) {
|
|
255
|
-
const oldVersion = bytesToHex(this.chainHash);
|
|
256
|
-
|
|
257
|
-
|
|
192
|
+
const oldVersion = bytesToHex(yield this.chainHash());
|
|
193
|
+
const { schema, chain_hash: newVersion } = yield this.rollup.schema.retrieve();
|
|
194
|
+
this._chainHash = hexToBytes(newVersion);
|
|
195
|
+
this._serializer = this._config.getSerializer(schema);
|
|
258
196
|
if (oldVersion !== newVersion) {
|
|
259
197
|
throw new VersionMismatchError(
|
|
260
198
|
"Schema version mismatch when submitting transaction",
|
|
@@ -277,9 +215,11 @@ var Rollup = class {
|
|
|
277
215
|
*/
|
|
278
216
|
signAndSubmitTransaction(_0, _1, _2) {
|
|
279
217
|
return __async(this, arguments, function* (unsignedTx, { signer }, options) {
|
|
280
|
-
const
|
|
218
|
+
const serializer = yield this.serializer();
|
|
219
|
+
const serializedUnsignedTx = serializer.serializeUnsignedTx(unsignedTx);
|
|
220
|
+
const chainHash = yield this.chainHash();
|
|
281
221
|
const signature = yield signer.sign(
|
|
282
|
-
new Uint8Array([...serializedUnsignedTx, ...
|
|
222
|
+
new Uint8Array([...serializedUnsignedTx, ...chainHash])
|
|
283
223
|
);
|
|
284
224
|
const publicKey = yield signer.publicKey();
|
|
285
225
|
const context = {
|
|
@@ -369,10 +309,14 @@ var Rollup = class {
|
|
|
369
309
|
/**
|
|
370
310
|
* The serializer for the rollup.
|
|
371
311
|
* Can be used to serialize transactions, runtime calls, etc.
|
|
372
|
-
* See {@link RollupSerializer} for more information.
|
|
373
312
|
*/
|
|
374
|
-
|
|
375
|
-
return this
|
|
313
|
+
serializer() {
|
|
314
|
+
return __async(this, null, function* () {
|
|
315
|
+
if (this._serializer) return this._serializer;
|
|
316
|
+
const { schema } = yield this.rollup.schema.retrieve();
|
|
317
|
+
this._serializer = this._config.getSerializer(schema);
|
|
318
|
+
return this._serializer;
|
|
319
|
+
});
|
|
376
320
|
}
|
|
377
321
|
/**
|
|
378
322
|
* The context for the rollup.
|
|
@@ -380,11 +324,13 @@ var Rollup = class {
|
|
|
380
324
|
get context() {
|
|
381
325
|
return this._config.context;
|
|
382
326
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
327
|
+
chainHash() {
|
|
328
|
+
return __async(this, null, function* () {
|
|
329
|
+
if (this._chainHash) return this._chainHash;
|
|
330
|
+
const { chain_hash } = yield this.rollup.schema.retrieve();
|
|
331
|
+
this._chainHash = hexToBytes(chain_hash);
|
|
332
|
+
return this._chainHash;
|
|
333
|
+
});
|
|
388
334
|
}
|
|
389
335
|
};
|
|
390
336
|
function isVersionMismatchError(e) {
|
|
@@ -400,6 +346,7 @@ function isVersionMismatchError(e) {
|
|
|
400
346
|
|
|
401
347
|
// src/rollup/standard-rollup.ts
|
|
402
348
|
import SovereignClient2 from "@sovereign-sdk/client";
|
|
349
|
+
import { JsSerializer } from "@sovereign-sdk/serializers";
|
|
403
350
|
import { bytesToHex as bytesToHex2 } from "@sovereign-sdk/utils";
|
|
404
351
|
var useOrFetchGeneration = (_0) => __async(void 0, [_0], function* ({
|
|
405
352
|
overrides
|
|
@@ -456,7 +403,8 @@ var StandardRollup = class extends Rollup {
|
|
|
456
403
|
*/
|
|
457
404
|
simulate(_0, _1) {
|
|
458
405
|
return __async(this, arguments, function* (runtimeMessage, { signer, txDetails, generation: overrideGeneration }) {
|
|
459
|
-
const
|
|
406
|
+
const serializer = yield this.serializer();
|
|
407
|
+
const runtimeCall = serializer.serializeRuntimeCall(runtimeMessage);
|
|
460
408
|
const publicKey = yield signer.publicKey();
|
|
461
409
|
const generation = yield useOrFetchGeneration({
|
|
462
410
|
rollup: this,
|
|
@@ -499,10 +447,10 @@ function createStandardRollup(rollupConfig, typeBuilderOverrides) {
|
|
|
499
447
|
var _a, _b;
|
|
500
448
|
const config = rollupConfig != null ? rollupConfig : {};
|
|
501
449
|
const client = (_a = config.client) != null ? _a : new SovereignClient2({ baseURL: config.url });
|
|
502
|
-
const
|
|
450
|
+
const getSerializer = (_b = config.getSerializer) != null ? _b : (schema) => new JsSerializer(schema);
|
|
503
451
|
const context = yield buildContext(client, config.context);
|
|
504
452
|
return new StandardRollup(
|
|
505
|
-
__spreadProps(__spreadValues({}, config), { client,
|
|
453
|
+
__spreadProps(__spreadValues({}, config), { client, getSerializer, context }),
|
|
506
454
|
__spreadValues(__spreadValues({}, standardTypeBuilder()), typeBuilderOverrides)
|
|
507
455
|
);
|
|
508
456
|
});
|
|
@@ -510,20 +458,16 @@ function createStandardRollup(rollupConfig, typeBuilderOverrides) {
|
|
|
510
458
|
|
|
511
459
|
// src/index.ts
|
|
512
460
|
import * as SovereignClient3 from "@sovereign-sdk/client";
|
|
513
|
-
import { Schema as Schema2 } from "@sovereign-sdk/universal-wallet-wasm";
|
|
514
461
|
export {
|
|
515
462
|
DEFAULT_TX_DETAILS,
|
|
516
463
|
InvalidRollupConfigError,
|
|
517
464
|
Rollup,
|
|
518
|
-
Schema2 as Schema,
|
|
519
465
|
SchemaError,
|
|
520
466
|
SovereignClient3 as SovereignClient,
|
|
521
467
|
SovereignError,
|
|
522
468
|
StandardRollup,
|
|
523
469
|
VersionMismatchError,
|
|
524
470
|
addressFromPublicKey,
|
|
525
|
-
createSerializer,
|
|
526
|
-
createSerializerFromHttp,
|
|
527
471
|
createStandardRollup,
|
|
528
472
|
standardTypeBuilder
|
|
529
473
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/addresses.ts","../src/rollup/rollup.ts","../src/errors.ts","../src/serialization.ts","../src/subscriptions.ts","../src/rollup/standard-rollup.ts","../src/index.ts"],"sourcesContent":["import { type HexString, ensureBytes } from \"@sovereign-sdk/utils\";\nimport { bech32m } from \"bech32\";\n\n/**\n * Encodes a public key as a bech32m address with the given human-readable part (hrp).\n *\n * @param publicKey - The public key to encode, as a hex string or Uint8Array.\n * @param hrp - The human-readable part for the bech32m address (e.g., \"sov\").\n * @param concatPublicKey - Optional. If provided, only the first `concatPublicKey` bytes of the public key are used.\n * @returns The bech32m-encoded address as a string.\n * @throws {Error} If the public key is not a valid hex string or Uint8Array.\n */\nexport function addressFromPublicKey(\n publicKey: HexString | Uint8Array,\n hrp: string,\n concatPublicKey = 28,\n): string {\n let publicKeyBytes = ensureBytes(publicKey);\n\n if (concatPublicKey !== publicKey.length) {\n publicKeyBytes = publicKeyBytes.slice(0, concatPublicKey);\n }\n\n const words = bech32m.toWords(publicKeyBytes);\n return bech32m.encode(hrp, words);\n}\n","import 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 { 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 // 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 */\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 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 * 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 response = await this.rollup.addresses.dedup(bytesToHex(address));\n return response as S[\"Dedup\"];\n }\n\n /**\n * Submits a transaction to the rollup.\n *\n * @param transaction - The transaction to submit.\n * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async submitTransaction(\n transaction: S[\"Transaction\"],\n options?: SovereignClient.RequestOptions,\n ): Promise<SovereignClient.Sequencer.TxCreateResponse> {\n const serializedTx = this.serializer.serializeTx(transaction);\n\n return this.sequencer.txs\n .create({ body: Base64.fromUint8Array(serializedTx) }, options)\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 * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async signAndSubmitTransaction(\n unsignedTx: S[\"UnsignedTransaction\"],\n { signer }: SignerParams,\n options?: SovereignClient.RequestOptions,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const serializedUnsignedTx =\n this.serializer.serializeUnsignedTx(unsignedTx);\n const signature = await signer.sign(\n new Uint8Array([...serializedUnsignedTx, ...this.chainHash]),\n );\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, options);\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 * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async call(\n runtimeCall: S[\"RuntimeCall\"],\n { signer, overrides }: CallParams<S>,\n options?: SovereignClient.RequestOptions,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const context = {\n runtimeCall,\n rollup: this,\n overrides: overrides ?? ({} as DeepPartial<S[\"UnsignedTransaction\"]>),\n };\n const unsignedTx = await this._typeBuilder.unsignedTransaction(context);\n\n return this.signAndSubmitTransaction(\n unsignedTx,\n {\n signer,\n },\n options,\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 * Performs a healthcheck against the rollup to determine if it is currently healthy.\n *\n * @param timeout - Request timeout in milliseconds.\n * @returns `true` if the rollup is considered healthy otherwise `false`.\n */\n async healthcheck(timeout = 5000): Promise<boolean> {\n try {\n await this.http.get(\"/healthcheck\", { timeout, maxRetries: 1 });\n return true;\n } catch (e) {\n return !(e instanceof SovereignClient.APIConnectionError);\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)?.details?.error?.includes(\"Signature verification failed\")\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 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}: ${reason}`);\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 { 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 response = await client.rollup.schema.retrieve();\n const schema = response as RollupSchema;\n\n return createSerializer(schema);\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 // bun compatibility: https://github.com/partykit/partykit/issues/774\n websocket.binaryType = \"arraybuffer\";\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 websocket.addEventListener(\"error\", (e) =>\n console.log(\"Websocket error\", e),\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\nexport type 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 type { DeepPartial } from \"../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: 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 TransactionV0<RuntimeCall> = {\n pub_key: { pub_key: Uint8Array };\n signature: { msg_sig: Uint8Array };\n} & UnsignedTransaction<RuntimeCall>;\n\nexport type Transaction<RuntimeCall> = {\n versioned_tx: { V0: TransactionV0<RuntimeCall> };\n};\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 Date.now();\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 versioned_tx: {\n V0: {\n pub_key: {\n pub_key: sender,\n },\n signature: {\n msg_sig: signature,\n },\n ...unsignedTx,\n },\n },\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 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 return response;\n }\n}\n\nexport const DEFAULT_TX_DETAILS: Omit<TxDetails, \"chain_id\"> = {\n max_priority_fee_bips: 0,\n max_fee: \"100000000\",\n gas_limit: null,\n};\n\nasync function buildContext<C extends StandardRollupContext>(\n client: SovereignClient,\n context?: DeepPartial<C>,\n): Promise<C> {\n const defaultTxDetails = {\n ...DEFAULT_TX_DETAILS,\n ...context?.defaultTxDetails,\n };\n\n if (!defaultTxDetails.chain_id) {\n const { chain_id } = await client.rollup.constants.retrieve();\n\n defaultTxDetails.chain_id = chain_id;\n }\n\n return {\n defaultTxDetails,\n } as C;\n}\n\nexport async function createStandardRollup<\n RuntimeCall,\n C extends StandardRollupContext = StandardRollupContext,\n>(\n rollupConfig?: Partial<RollupConfig<DeepPartial<C>>>,\n typeBuilderOverrides?: Partial<\n TypeBuilder<StandardRollupSpec<RuntimeCall>, C>\n >,\n) {\n const config = rollupConfig ?? {};\n const client = config.client ?? new SovereignClient({ baseURL: config.url });\n const serializer =\n config.serializer ?? (await createSerializerFromHttp(client));\n const context = await buildContext<C>(client, config.context);\n\n return new StandardRollup<RuntimeCall>(\n { ...config, client, serializer, context },\n {\n ...standardTypeBuilder(),\n ...typeBuilderOverrides,\n },\n );\n}\n","export * from \"./addresses\";\nexport * from \"./rollup\";\nexport * from \"./serialization\";\nexport * from \"./errors\";\nexport * from \"./type-spec\";\nexport { type EventPayload, Subscription } from \"./subscriptions\";\nexport * as SovereignClient from \"@sovereign-sdk/client\";\nexport { Schema } from \"@sovereign-sdk/universal-wallet-wasm\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAyB,mBAAmB;AAC5C,SAAS,eAAe;AAWjB,SAAS,qBACd,WACA,KACA,kBAAkB,IACV;AACR,MAAI,iBAAiB,YAAY,SAAS;AAE1C,MAAI,oBAAoB,UAAU,QAAQ;AACxC,qBAAiB,eAAe,MAAM,GAAG,eAAe;AAAA,EAC1D;AAEA,QAAM,QAAQ,QAAQ,QAAQ,cAAc;AAC5C,SAAO,QAAQ,OAAO,KAAK,KAAK;AAClC;;;ACzBA,OAAO,qBAAqB;AAG5B,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,EAKvD,YAAY,SAAiB,YAAoB,gBAAwB;AACvE,UAAM,OAAO;AAEb,SAAK,aAAa;AAClB,SAAK,iBAAiB;AACtB,SAAK,YAAY,eAAe;AAAA,EAClC;AACF;AAEO,IAAM,cAAN,cAA0B,eAAe;AAAA,EAI9C,YAAY,SAAiB,QAAgB,QAAgB;AAC3D,UAAM,GAAG,OAAO,KAAK,MAAM,EAAE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,MACL;AAAA,IACF;AAAA,EACF;AAAA;AAEA,SAAsB,qBAIpB,cACA,sBAGA;AAAA;AA/LF;AAgME,UAAM,SAAS,sCAAgB,CAAC;AAChC,UAAM,UAAS,YAAO,WAAP,YAAiB,IAAIC,iBAAgB,EAAE,SAAS,OAAO,IAAI,CAAC;AAC3E,UAAM,cACJ,YAAO,eAAP,YAAsB,MAAM,yBAAyB,MAAM;AAC7D,UAAM,UAAU,MAAM,aAAgB,QAAQ,OAAO,OAAO;AAE5D,WAAO,IAAI;AAAA,MACT,iCAAK,SAAL,EAAa,QAAQ,YAAY,QAAQ;AAAA,MACzC,kCACK,oBAAoB,IACpB;AAAA,IAEP;AAAA,EACF;AAAA;;;ACvMA,YAAYC,sBAAqB;AACjC,SAAS,UAAAC,eAAc;","names":["_a","subscription","SovereignClient","bytesToHex","_a","bytesToHex","SovereignClient","SovereignClient","Schema"]}
|
|
1
|
+
{"version":3,"sources":["../src/addresses.ts","../src/rollup/rollup.ts","../src/errors.ts","../src/subscriptions.ts","../src/rollup/standard-rollup.ts","../src/index.ts"],"sourcesContent":["import { type HexString, ensureBytes } from \"@sovereign-sdk/utils\";\nimport { bech32m } from \"bech32\";\n\n/**\n * Encodes a public key as a bech32m address with the given human-readable part (hrp).\n *\n * @param publicKey - The public key to encode, as a hex string or Uint8Array.\n * @param hrp - The human-readable part for the bech32m address (e.g., \"sov\").\n * @param concatPublicKey - Optional. If provided, only the first `concatPublicKey` bytes of the public key are used.\n * @returns The bech32m-encoded address as a string.\n * @throws {Error} If the public key is not a valid hex string or Uint8Array.\n */\nexport function addressFromPublicKey(\n publicKey: HexString | Uint8Array,\n hrp: string,\n concatPublicKey = 28,\n): string {\n let publicKeyBytes = ensureBytes(publicKey);\n\n if (concatPublicKey !== publicKey.length) {\n publicKeyBytes = publicKeyBytes.slice(0, concatPublicKey);\n }\n\n const words = bech32m.toWords(publicKeyBytes);\n return bech32m.encode(hrp, words);\n}\n","import SovereignClient from \"@sovereign-sdk/client\";\nimport type { APIError } from \"@sovereign-sdk/client\";\nimport type { RollupSchema, Serializer } from \"@sovereign-sdk/serializers\";\nimport type { Signer } from \"@sovereign-sdk/signers\";\nimport { bytesToHex, hexToBytes } from \"@sovereign-sdk/utils\";\nimport { Base64 } from \"js-base64\";\nimport { VersionMismatchError } from \"../errors\";\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 // 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 */\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 PartialRollupConfig.url}.\n */\n client: SovereignClient;\n /**\n * Creates the serializer instance to use for the rollup.\n *\n * This can be called more than once, for example if the chain hash changes (i.e a new rollup version)\n * is detected then it will be called again with the new rollup schema.\n */\n getSerializer: (schema: RollupSchema) => Serializer;\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 _typeBuilder: TypeBuilder<S, C>;\n private _chainHash?: Uint8Array;\n private _serializer?: Serializer;\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 response = await this.rollup.addresses.dedup(bytesToHex(address));\n return response as S[\"Dedup\"];\n }\n\n /**\n * Submits a transaction to the rollup.\n *\n * @param transaction - The transaction to submit.\n * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async submitTransaction(\n transaction: S[\"Transaction\"],\n options?: SovereignClient.RequestOptions,\n ): Promise<SovereignClient.Sequencer.TxCreateResponse> {\n const serializer = await this.serializer();\n const serializedTx = serializer.serializeTx(transaction);\n\n return this.sequencer.txs\n .create({ body: Base64.fromUint8Array(serializedTx) }, options)\n .catch(async (e) => {\n if (isVersionMismatchError(e as APIError)) {\n const oldVersion = bytesToHex(await this.chainHash());\n const { schema, chain_hash: newVersion } =\n await this.rollup.schema.retrieve();\n this._chainHash = hexToBytes(newVersion);\n this._serializer = this._config.getSerializer(schema);\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 * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async signAndSubmitTransaction(\n unsignedTx: S[\"UnsignedTransaction\"],\n { signer }: SignerParams,\n options?: SovereignClient.RequestOptions,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const serializer = await this.serializer();\n const serializedUnsignedTx = serializer.serializeUnsignedTx(unsignedTx);\n const chainHash = await this.chainHash();\n const signature = await signer.sign(\n new Uint8Array([...serializedUnsignedTx, ...chainHash]),\n );\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, options);\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 * @param {SovereignClient.RequestOptions} options - The options for the request.\n */\n async call(\n runtimeCall: S[\"RuntimeCall\"],\n { signer, overrides }: CallParams<S>,\n options?: SovereignClient.RequestOptions,\n ): Promise<TransactionResult<S[\"Transaction\"]>> {\n const context = {\n runtimeCall,\n rollup: this,\n overrides: overrides ?? ({} as DeepPartial<S[\"UnsignedTransaction\"]>),\n };\n const unsignedTx = await this._typeBuilder.unsignedTransaction(context);\n\n return this.signAndSubmitTransaction(\n unsignedTx,\n {\n signer,\n },\n options,\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 * Performs a healthcheck against the rollup to determine if it is currently healthy.\n *\n * @param timeout - Request timeout in milliseconds.\n * @returns `true` if the rollup is considered healthy otherwise `false`.\n */\n async healthcheck(timeout = 5000): Promise<boolean> {\n try {\n await this.http.get(\"/healthcheck\", { timeout, maxRetries: 1 });\n return true;\n } catch (e) {\n return !(e instanceof SovereignClient.APIConnectionError);\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 */\n async serializer(): Promise<Serializer> {\n if (this._serializer) return this._serializer;\n const { schema } = await this.rollup.schema.retrieve();\n this._serializer = this._config.getSerializer(schema);\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 async chainHash(): Promise<Uint8Array> {\n if (this._chainHash) return this._chainHash;\n const { chain_hash } = await this.rollup.schema.retrieve();\n this._chainHash = hexToBytes(chain_hash);\n return this._chainHash;\n }\n}\n\nfunction isVersionMismatchError(e: APIError): boolean {\n if (\n // biome-ignore lint/suspicious/noExplicitAny: yolo\n (e.error as any)?.details?.error?.includes(\"Signature verification failed\")\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 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}: ${reason}`);\n\n this.reason = reason;\n this.schema = schema;\n }\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 // bun compatibility: https://github.com/partykit/partykit/issues/774\n websocket.binaryType = \"arraybuffer\";\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 websocket.addEventListener(\"error\", (e) =>\n console.log(\"Websocket error\", e),\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\nexport type 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 { JsSerializer } from \"@sovereign-sdk/serializers\";\nimport { bytesToHex } from \"@sovereign-sdk/utils\";\nimport type { DeepPartial } from \"../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: 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 TransactionV0<RuntimeCall> = {\n pub_key: { pub_key: Uint8Array };\n signature: { msg_sig: Uint8Array };\n} & UnsignedTransaction<RuntimeCall>;\n\nexport type Transaction<RuntimeCall> = {\n versioned_tx: { V0: TransactionV0<RuntimeCall> };\n};\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 Date.now();\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 versioned_tx: {\n V0: {\n pub_key: {\n pub_key: sender,\n },\n signature: {\n msg_sig: signature,\n },\n ...unsignedTx,\n },\n },\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 serializer = await this.serializer();\n const runtimeCall = serializer.serializeRuntimeCall(runtimeMessage);\n const publicKey = await signer.publicKey();\n const generation = await useOrFetchGeneration({\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 return response;\n }\n}\n\nexport const DEFAULT_TX_DETAILS: Omit<TxDetails, \"chain_id\"> = {\n max_priority_fee_bips: 0,\n max_fee: \"100000000\",\n gas_limit: null,\n};\n\nasync function buildContext<C extends StandardRollupContext>(\n client: SovereignClient,\n context?: DeepPartial<C>,\n): Promise<C> {\n const defaultTxDetails = {\n ...DEFAULT_TX_DETAILS,\n ...context?.defaultTxDetails,\n };\n\n if (!defaultTxDetails.chain_id) {\n const { chain_id } = await client.rollup.constants.retrieve();\n\n defaultTxDetails.chain_id = chain_id;\n }\n\n return {\n defaultTxDetails,\n } as C;\n}\n\nexport async function createStandardRollup<\n RuntimeCall,\n C extends StandardRollupContext = StandardRollupContext,\n>(\n rollupConfig?: Partial<RollupConfig<DeepPartial<C>>>,\n typeBuilderOverrides?: Partial<\n TypeBuilder<StandardRollupSpec<RuntimeCall>, C>\n >,\n) {\n const config = rollupConfig ?? {};\n const client = config.client ?? new SovereignClient({ baseURL: config.url });\n const getSerializer =\n config.getSerializer ?? ((schema) => new JsSerializer(schema));\n const context = await buildContext<C>(client, config.context);\n\n return new StandardRollup<RuntimeCall>(\n { ...config, client, getSerializer, context },\n {\n ...standardTypeBuilder(),\n ...typeBuilderOverrides,\n },\n );\n}\n","export * from \"./addresses\";\nexport * from \"./rollup\";\nexport * from \"./errors\";\nexport * from \"./type-spec\";\nexport { type EventPayload, Subscription } from \"./subscriptions\";\nexport * as SovereignClient from \"@sovereign-sdk/client\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAyB,mBAAmB;AAC5C,SAAS,eAAe;AAWjB,SAAS,qBACd,WACA,KACA,kBAAkB,IACV;AACR,MAAI,iBAAiB,YAAY,SAAS;AAE1C,MAAI,oBAAoB,UAAU,QAAQ;AACxC,qBAAiB,eAAe,MAAM,GAAG,eAAe;AAAA,EAC1D;AAEA,QAAM,QAAQ,QAAQ,QAAQ,cAAc;AAC5C,SAAO,QAAQ,OAAO,KAAK,KAAK;AAClC;;;ACzBA,OAAO,qBAAqB;AAI5B,SAAS,YAAY,kBAAkB;AACvC,SAAS,cAAc;;;ACFhB,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,EAKvD,YAAY,SAAiB,YAAoB,gBAAwB;AACvE,UAAM,OAAO;AAEb,SAAK,aAAa;AAClB,SAAK,iBAAiB;AACtB,SAAK,YAAY,eAAe;AAAA,EAClC;AACF;AAEO,IAAM,cAAN,cAA0B,eAAe;AAAA,EAI9C,YAAY,SAAiB,QAAgB,QAAgB;AAC3D,UAAM,GAAG,OAAO,KAAK,MAAM,EAAE;AAE7B,SAAK,SAAS;AACd,SAAK,SAAS;AAAA,EAChB;AACF;;;ACrCA,OAAO,kBAAkB;AACzB,SAAS,iBAAiB;AAKnB,SAAS,gBAAgB,KAAa;AAC3C,SAAO,IAAI,QAAQ,kBAAkB,CAAC,GAAG,MAAM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,MACF,CAAC;AAED,aAAO;AAAA,IACT;AAAA;AACF;AAEO,IAAM,qBAAkD;AAAA,EAC7D,uBAAuB;AAAA,EACvB,SAAS;AAAA,EACT,WAAW;AACb;AAEA,SAAe,aACb,QACA,SACY;AAAA;AACZ,UAAM,mBAAmB,kCACpB,qBACA,mCAAS;AAGd,QAAI,CAAC,iBAAiB,UAAU;AAC9B,YAAM,EAAE,SAAS,IAAI,MAAM,OAAO,OAAO,UAAU,SAAS;AAE5D,uBAAiB,WAAW;AAAA,IAC9B;AAEA,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAAA;AAEA,SAAsB,qBAIpB,cACA,sBAGA;AAAA;AAhMF;AAiME,UAAM,SAAS,sCAAgB,CAAC;AAChC,UAAM,UAAS,YAAO,WAAP,YAAiB,IAAIC,iBAAgB,EAAE,SAAS,OAAO,IAAI,CAAC;AAC3E,UAAM,iBACJ,YAAO,kBAAP,YAAyB,CAAC,WAAW,IAAI,aAAa,MAAM;AAC9D,UAAM,UAAU,MAAM,aAAgB,QAAQ,OAAO,OAAO;AAE5D,WAAO,IAAI;AAAA,MACT,iCAAK,SAAL,EAAa,QAAQ,eAAe,QAAQ;AAAA,MAC5C,kCACK,oBAAoB,IACpB;AAAA,IAEP;AAAA,EACF;AAAA;;;ACzMA,YAAYC,sBAAqB;","names":["_a","subscription","SovereignClient","bytesToHex","_a","bytesToHex","SovereignClient","SovereignClient"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sovereign-sdk/web3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"repository": "github:Sovereign-Labs/sovereign-sdk-web3-js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -24,13 +24,14 @@
|
|
|
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.36",
|
|
28
28
|
"bech32": "^2.0.0",
|
|
29
29
|
"isomorphic-ws": "^5.0.0",
|
|
30
30
|
"js-base64": "^3.7.7",
|
|
31
31
|
"partysocket": "^1.1.3",
|
|
32
32
|
"ws": "^8.18.1",
|
|
33
33
|
"@sovereign-sdk/signers": "^0.2.1",
|
|
34
|
+
"@sovereign-sdk/serializers": "^0.1.0",
|
|
34
35
|
"@sovereign-sdk/universal-wallet-wasm": "^0.4.0",
|
|
35
36
|
"@sovereign-sdk/utils": "^0.0.4"
|
|
36
37
|
},
|