@sovereign-sdk/web3 0.0.1 → 0.0.3

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.
@@ -0,0 +1,4 @@
1
+ export declare class SovereignError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAY5B"}
package/dist/errors.js ADDED
@@ -0,0 +1,15 @@
1
+ export class SovereignError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = this.constructor.name;
5
+ // `Error.captureStackTrace` is v8 specific API,
6
+ // add fallback for compatibility in other envs
7
+ if (Error.captureStackTrace) {
8
+ Error.captureStackTrace(this, this.constructor);
9
+ }
10
+ else {
11
+ this.stack = new Error().stack;
12
+ }
13
+ }
14
+ }
15
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAElC,gDAAgD;QAChD,+CAA+C;QAC/C,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC;QACjC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export * from "./signer";
2
+ export * from "./rollup";
3
+ export * from "./serialization";
4
+ export * from "./errors";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC"}
@@ -1,3 +1,5 @@
1
1
  export * from "./signer";
2
2
  export * from "./rollup";
3
3
  export * from "./serialization";
4
+ export * from "./errors";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
@@ -1,5 +1,5 @@
1
1
  import { expect, it } from "vitest";
2
-
3
2
  it("should work", () => {
4
- expect(true).toBe(true);
3
+ expect(true).toBe(true);
5
4
  });
5
+ //# sourceMappingURL=index.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEpC,EAAE,CAAC,aAAa,EAAE,GAAG,EAAE;IACrB,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC"}
@@ -0,0 +1,37 @@
1
+ import SovereignClient from "@sovereign-sdk/client";
2
+ import { type RollupSchema, type RollupSerializer } from "./serialization";
3
+ import type { Signer } from "./signer";
4
+ export type RollupCallResult = {
5
+ response: SovereignClient.Sequencer.TxCreateResponse;
6
+ unsignedTx: unknown;
7
+ };
8
+ export type RollupConfig = {
9
+ url?: string;
10
+ schema: RollupSchema;
11
+ defaultTxDetails: TxDetails;
12
+ };
13
+ type TxDetails = {
14
+ max_priority_fee_bips: number;
15
+ max_fee: bigint;
16
+ gas_limit?: bigint;
17
+ chain_id: bigint;
18
+ };
19
+ type SignerParams = {
20
+ signer: Signer;
21
+ };
22
+ type CallParams = {
23
+ txDetails?: TxDetails;
24
+ } & SignerParams;
25
+ export declare class StandardRollup<Tx = unknown, UnsignedTx = unknown> {
26
+ private readonly _config;
27
+ private readonly _client;
28
+ private readonly _serializer;
29
+ constructor(config: RollupConfig);
30
+ submitTransaction(transaction: Tx): Promise<SovereignClient.Sequencer.TxCreateResponse>;
31
+ signAndSubmitTransaction(unsignedTx: UnsignedTx, { signer }: SignerParams): Promise<SovereignClient.Sequencer.TxCreateResponse>;
32
+ call(runtimeMessage: unknown, { signer, txDetails }: CallParams): Promise<RollupCallResult>;
33
+ get client(): SovereignClient;
34
+ get serializer(): RollupSerializer;
35
+ }
36
+ export {};
37
+ //# sourceMappingURL=rollup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGvC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,eAAe,CAAC,SAAS,CAAC,gBAAgB,CAAC;IACrD,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,gBAAgB,EAAE,SAAS,CAAC;CAC7B,CAAC;AAEF,KAAK,SAAS,GAAG;IACf,qBAAqB,EAAE,MAAM,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,GAAG,YAAY,CAAC;AAEjB,qBAAa,cAAc,CAAC,EAAE,GAAG,OAAO,EAAE,UAAU,GAAG,OAAO;IAC5D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmB;gBAEnC,MAAM,EAAE,YAAY;IAM1B,iBAAiB,CACrB,WAAW,EAAE,EAAE,GACd,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,gBAAgB,CAAC;IAQhD,wBAAwB,CAC5B,UAAU,EAAE,UAAU,EACtB,EAAE,MAAM,EAAE,EAAE,YAAY,GACvB,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,gBAAgB,CAAC;IAgBhD,IAAI,CACR,cAAc,EAAE,OAAO,EACvB,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,UAAU,GAChC,OAAO,CAAC,gBAAgB,CAAC;IA0B5B,IAAI,MAAM,IAAI,eAAe,CAE5B;IAED,IAAI,UAAU,IAAI,gBAAgB,CAEjC;CACF"}
package/dist/rollup.js ADDED
@@ -0,0 +1,67 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import SovereignClient from "@sovereign-sdk/client";
11
+ import { Base64 } from "js-base64";
12
+ import { createSerializer, } from "./serialization";
13
+ import { bytesToHex } from "./utils";
14
+ export class StandardRollup {
15
+ constructor(config) {
16
+ this._client = new SovereignClient({ baseURL: config.url });
17
+ this._serializer = createSerializer(config.schema);
18
+ this._config = config;
19
+ }
20
+ submitTransaction(transaction) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const serializedTx = this.serializer.serializeTx(transaction);
23
+ return this.client.sequencer.txs.create({
24
+ body: Base64.fromUint8Array(serializedTx),
25
+ });
26
+ });
27
+ }
28
+ signAndSubmitTransaction(unsignedTx_1, _a) {
29
+ return __awaiter(this, arguments, void 0, function* (unsignedTx, { signer }) {
30
+ const serializedUnsignedTx = this.serializer.serializeUnsignedTx(unsignedTx);
31
+ const signature = yield signer.sign(serializedUnsignedTx);
32
+ const publicKey = yield signer.publicKey();
33
+ const tx = Object.assign({ pub_key: publicKey, signature: {
34
+ msg_sig: signature,
35
+ } }, unsignedTx);
36
+ return this.submitTransaction(tx);
37
+ });
38
+ }
39
+ call(runtimeMessage_1, _a) {
40
+ return __awaiter(this, arguments, void 0, function* (runtimeMessage, { signer, txDetails }) {
41
+ const runtimeCall = this.serializer.serializeRuntimeCall(runtimeMessage);
42
+ const publicKey = yield signer.publicKey();
43
+ const dedup = yield this.client.rollup.addresses.dedup.retrieve(bytesToHex(publicKey));
44
+ // biome-ignore lint/suspicious/noExplicitAny: fix later
45
+ const nonce = BigInt(dedup.data.nonce);
46
+ const unsignedTx = {
47
+ runtime_msg: runtimeCall,
48
+ nonce,
49
+ details: txDetails !== null && txDetails !== void 0 ? txDetails : this._config.defaultTxDetails,
50
+ };
51
+ const response = yield this.signAndSubmitTransaction(unsignedTx, {
52
+ signer,
53
+ });
54
+ return {
55
+ response,
56
+ unsignedTx,
57
+ };
58
+ });
59
+ }
60
+ get client() {
61
+ return this._client;
62
+ }
63
+ get serializer() {
64
+ return this._serializer;
65
+ }
66
+ }
67
+ //# sourceMappingURL=rollup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.js","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,eAAe,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAGL,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AA4BrC,MAAM,OAAO,cAAc;IAKzB,YAAY,MAAoB;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,eAAe,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,WAAW,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACnD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAEK,iBAAiB,CACrB,WAAe;;YAEf,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;YAE9D,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC;gBACtC,IAAI,EAAE,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC;aAC1C,CAAC,CAAC;QACL,CAAC;KAAA;IAEK,wBAAwB;6DAC5B,UAAsB,EACtB,EAAE,MAAM,EAAgB;YAExB,MAAM,oBAAoB,GACxB,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;YAClD,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAC1D,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;YAC3C,MAAM,EAAE,mBACN,OAAO,EAAE,SAAS,EAClB,SAAS,EAAE;oBACT,OAAO,EAAE,SAAS;iBACnB,IACE,UAAU,CACd,CAAC;YAEF,OAAO,IAAI,CAAC,iBAAiB,CAAC,EAAQ,CAAC,CAAC;QAC1C,CAAC;KAAA;IAEK,IAAI;6DACR,cAAuB,EACvB,EAAE,MAAM,EAAE,SAAS,EAAc;YAEjC,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;YACzE,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;YAC3C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAC7D,UAAU,CAAC,SAAS,CAAC,CACtB,CAAC;YACF,wDAAwD;YACxD,MAAM,KAAK,GAAG,MAAM,CAAE,KAAK,CAAC,IAAY,CAAC,KAAe,CAAC,CAAC;YAC1D,MAAM,UAAU,GAAG;gBACjB,WAAW,EAAE,WAAW;gBACxB,KAAK;gBACL,OAAO,EAAE,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,OAAO,CAAC,gBAAgB;aACpD,CAAC;YACF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,wBAAwB,CAClD,UAAwB,EACxB;gBACE,MAAM;aACP,CACF,CAAC;YAEF,OAAO;gBACL,QAAQ;gBACR,UAAU;aACX,CAAC;QACJ,CAAC;KAAA;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ export type RollupSchema = object;
2
+ export type RollupSerializer = {
3
+ serialize(input: unknown, index: number): Uint8Array;
4
+ serializeRuntimeCall(input: unknown): Uint8Array;
5
+ serializeUnsignedTx(input: unknown): Uint8Array;
6
+ serializeTx(input: unknown): Uint8Array;
7
+ };
8
+ export declare function createSerializer(schemaObject: RollupSchema): RollupSerializer;
9
+ //# sourceMappingURL=serialization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IACrD,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAAC;IACjD,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAAC;IAChD,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAAC;CACzC,CAAC;AAYF,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,YAAY,GAAG,gBAAgB,CAgC7E"}
@@ -0,0 +1,33 @@
1
+ import { KnownTypeId, Schema } from "@sovereign-sdk/universal-wallet-wasm";
2
+ import { SovereignError } from "./errors";
3
+ function loadSchema(schemaObject) {
4
+ try {
5
+ return Schema.fromJSON(JSON.stringify(schemaObject));
6
+ }
7
+ catch (err) {
8
+ throw new SovereignError(`Failed to create runtime schema due to: ${err.message}`);
9
+ }
10
+ }
11
+ export function createSerializer(schemaObject) {
12
+ const schema = loadSchema(schemaObject);
13
+ return {
14
+ serialize(input, index) {
15
+ try {
16
+ return schema.jsonToBorsh(index, JSON.stringify(input));
17
+ }
18
+ catch (err) {
19
+ throw new SovereignError(`Failed to serialize input due to: ${err.message}`);
20
+ }
21
+ },
22
+ serializeRuntimeCall(input) {
23
+ return this.serialize(input, schema.knownTypeIndex(KnownTypeId.RuntimeCall));
24
+ },
25
+ serializeUnsignedTx(input) {
26
+ return this.serialize(input, schema.knownTypeIndex(KnownTypeId.UnsignedTransaction));
27
+ },
28
+ serializeTx(input) {
29
+ return this.serialize(input, schema.knownTypeIndex(KnownTypeId.Transaction));
30
+ },
31
+ };
32
+ }
33
+ //# sourceMappingURL=serialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.js","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAW1C,SAAS,UAAU,CAAC,YAA0B;IAC5C,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,cAAc,CACtB,2CAA4C,GAAa,CAAC,OAAO,EAAE,CACpE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,YAA0B;IACzD,MAAM,MAAM,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAExC,OAAO;QACL,SAAS,CAAC,KAAc,EAAE,KAAa;YACrC,IAAI,CAAC;gBACH,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;YAC1D,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,IAAI,cAAc,CACtB,qCAAsC,GAAa,CAAC,OAAO,EAAE,CAC9D,CAAC;YACJ,CAAC;QACH,CAAC;QACD,oBAAoB,CAAC,KAAc;YACjC,OAAO,IAAI,CAAC,SAAS,CACnB,KAAK,EACL,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,WAAW,CAAC,CAC/C,CAAC;QACJ,CAAC;QACD,mBAAmB,CAAC,KAAc;YAChC,OAAO,IAAI,CAAC,SAAS,CACnB,KAAK,EACL,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,mBAAmB,CAAC,CACvD,CAAC;QACJ,CAAC;QACD,WAAW,CAAC,KAAc;YACxB,OAAO,IAAI,CAAC,SAAS,CACnB,KAAK,EACL,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,WAAW,CAAC,CAC/C,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ export interface Signer {
2
+ sign(message: Uint8Array): Promise<Uint8Array>;
3
+ publicKey(): Promise<Uint8Array>;
4
+ }
5
+ //# sourceMappingURL=signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/C,SAAS,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;CAClC"}
package/dist/signer.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signer.js","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export declare function hexToBytes(hex: string): Uint8Array;
2
+ export declare function bytesToHex(arr: Uint8Array): string;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,cAYrC;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM,CAUlD"}
package/dist/utils.js ADDED
@@ -0,0 +1,22 @@
1
+ export function hexToBytes(hex) {
2
+ if (hex.length && hex.length % 2 !== 0) {
3
+ throw new Error(`Invalid hex string length: ${hex.length}`);
4
+ }
5
+ const matches = hex.match(/[\da-f]{2}/gi);
6
+ if (!matches) {
7
+ throw new Error("Invalid hex string: No valid hex digits found");
8
+ }
9
+ return new Uint8Array(matches.map((h) => Number.parseInt(h, 16)));
10
+ }
11
+ export function bytesToHex(arr) {
12
+ let hex = "";
13
+ for (let i = 0; i < arr.length; i++) {
14
+ let hexValue = arr[i].toString(16);
15
+ if (hexValue.length === 1) {
16
+ hexValue = `0${hexValue}`;
17
+ }
18
+ hex += hexValue;
19
+ }
20
+ return hex;
21
+ }
22
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,8BAA8B,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAE1C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAe;IACxC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACnC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC5B,CAAC;QACD,GAAG,IAAI,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/package.json CHANGED
@@ -1,8 +1,18 @@
1
1
  {
2
2
  "name": "@sovereign-sdk/web3",
3
- "version": "0.0.1",
4
- "module": "index.ts",
5
- "type": "module",
3
+ "version": "0.0.3",
4
+ "files": [
5
+ "dist",
6
+ "package.json"
7
+ ],
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "module": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
6
16
  "devDependencies": {
7
17
  "@biomejs/biome": "^1.9.2",
8
18
  "vitest": "^2.1.1"
@@ -11,13 +21,15 @@
11
21
  "typescript": "^5.0.0"
12
22
  },
13
23
  "dependencies": {
14
- "@sovereign-sdk/client": "^0.1.0-alpha.7",
15
- "js-base64": "^3.7.7"
24
+ "@sovereign-sdk/client": "0.1.0-alpha.11",
25
+ "js-base64": "^3.7.7",
26
+ "@sovereign-sdk/universal-wallet-wasm": "^0.1.1"
16
27
  },
17
28
  "publishConfig": {
18
29
  "access": "public"
19
30
  },
20
31
  "scripts": {
32
+ "build": "tsc -p tsconfig.build.json",
21
33
  "ci": "biome ci",
22
34
  "fix": "biome check --write",
23
35
  "lint": "biome lint",
package/src/errors.ts DELETED
@@ -1,25 +0,0 @@
1
- export class SovereignError extends Error {
2
- constructor(message: string) {
3
- super(message);
4
- this.name = this.constructor.name;
5
-
6
- // `Error.captureStackTrace` is v8 specific API,
7
- // add fallback for compatibility in other envs
8
- if (Error.captureStackTrace) {
9
- Error.captureStackTrace(this, this.constructor);
10
- } else {
11
- this.stack = new Error().stack;
12
- }
13
- }
14
- }
15
-
16
- export class SovereignSerializeError extends SovereignError {
17
- constructor(
18
- readonly targetType: string,
19
- message?: string,
20
- ) {
21
- super(
22
- message ?? `Failed to serialize rollup of schema type "${targetType}"`,
23
- );
24
- }
25
- }
package/src/rollup.ts DELETED
@@ -1,110 +0,0 @@
1
- import SovereignClient from "@sovereign-sdk/client";
2
- import { Base64 } from "js-base64";
3
- import {
4
- type RollupSchema,
5
- type RollupSerializer,
6
- createSerializer,
7
- } from "./serialization";
8
- import type { Signer } from "./signer";
9
-
10
- export type RollupCallResult = {
11
- response: SovereignClient.Sequencer.TxCreateResponse;
12
- unsignedTx: unknown;
13
- };
14
-
15
- export type RollupConfig = {
16
- url?: string;
17
- schema: RollupSchema;
18
- defaultTxDetails: TxDetails;
19
- };
20
-
21
- type TxDetails = {
22
- max_priority_fee_bips: number;
23
- max_fee: bigint;
24
- gas_limit?: bigint;
25
- chain_id: bigint;
26
- };
27
-
28
- type UnsignedTransaction = {
29
- runtime_msg: Uint8Array;
30
- nonce: bigint;
31
- details: TxDetails;
32
- };
33
-
34
- type SignedTransaction = UnsignedTransaction & {
35
- signature: { msg_sig: Uint8Array };
36
- pub_key: Uint8Array;
37
- };
38
-
39
- type CallParams = {
40
- signer: Signer;
41
- txDetails?: TxDetails;
42
- };
43
-
44
- export class StandardRollup {
45
- private readonly _config: RollupConfig;
46
- private readonly _client: SovereignClient;
47
- private readonly _serializer: RollupSerializer;
48
-
49
- constructor(config: RollupConfig) {
50
- this._client = new SovereignClient({ baseURL: config.url });
51
- this._serializer = createSerializer(config.schema);
52
- this._config = config;
53
- }
54
-
55
- async call(
56
- message: unknown,
57
- { signer, txDetails }: CallParams,
58
- ): Promise<RollupCallResult> {
59
- const serializedCall = this.serializer.serializeCallMessage(message);
60
- const nonce = BigInt(0); // TODO: call "capability" endpoint
61
- const unsignedTx: UnsignedTransaction = {
62
- runtime_msg: serializedCall,
63
- nonce,
64
- details: txDetails ?? this._config.defaultTxDetails,
65
- };
66
- const response = await this.signAndSubmitTransaction(unsignedTx, signer);
67
-
68
- return {
69
- response,
70
- unsignedTx,
71
- };
72
- }
73
-
74
- async submitTransaction(
75
- transaction: unknown,
76
- ): Promise<SovereignClient.Sequencer.TxCreateResponse> {
77
- const serializedTx = this.serializer.serializeTx(transaction);
78
-
79
- return this.client.sequencer.txs.create({
80
- body: Base64.fromUint8Array(serializedTx),
81
- });
82
- }
83
-
84
- async signAndSubmitTransaction(
85
- unsignedTx: UnsignedTransaction,
86
- signer: Signer,
87
- ): Promise<SovereignClient.Sequencer.TxCreateResponse> {
88
- const serializedUnsignedTx =
89
- this.serializer.serializeUnsignedTx(unsignedTx);
90
- const signature = await signer.sign(serializedUnsignedTx);
91
- const publicKey = await signer.publicKey();
92
- const tx: SignedTransaction = {
93
- pub_key: publicKey,
94
- signature: {
95
- msg_sig: signature,
96
- },
97
- ...unsignedTx,
98
- };
99
-
100
- return this.submitTransaction(tx);
101
- }
102
-
103
- get client(): SovereignClient {
104
- return this._client;
105
- }
106
-
107
- get serializer(): RollupSerializer {
108
- return this._serializer;
109
- }
110
- }
@@ -1,33 +0,0 @@
1
- import { SovereignSerializeError } from "./errors";
2
-
3
- export type RollupSchema = unknown;
4
-
5
- export type RollupSerializer = {
6
- serialize(data: unknown, type: string): Uint8Array;
7
- serializeCallMessage(data: unknown): Uint8Array;
8
- serializeUnsignedTx(data: unknown): Uint8Array;
9
- serializeTx(data: unknown): Uint8Array;
10
- };
11
-
12
- export function createSerializer(schema: RollupSchema): RollupSerializer {
13
- return {
14
- serialize(data, type) {
15
- console.log(data, type, schema);
16
- try {
17
- // call wasm library
18
- return new Uint8Array([]);
19
- } catch (e) {
20
- throw new SovereignSerializeError(type);
21
- }
22
- },
23
- serializeCallMessage(data) {
24
- return this.serialize(data, "CallMessage");
25
- },
26
- serializeUnsignedTx(data) {
27
- return this.serialize(data, "UnsignedTransaction");
28
- },
29
- serializeTx(data) {
30
- return this.serialize(data, "Transaction");
31
- },
32
- };
33
- }
package/src/signer.ts DELETED
@@ -1,4 +0,0 @@
1
- export interface Signer {
2
- sign(message: Uint8Array): Promise<Uint8Array>;
3
- publicKey(): Promise<Uint8Array>;
4
- }