@appliedblockchain/silentdatarollup-core 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,11 +3,11 @@ import debug2 from "debug";
3
3
 
4
4
  // src/constants.ts
5
5
  var SIGN_RPC_METHODS = [
6
+ "eth_estimateGas",
7
+ "eth_getProof",
6
8
  "eth_getTransactionByHash",
7
9
  "eth_getTransactionCount",
8
- "eth_getProof",
9
- "eth_getTransactionReceipt",
10
- "eth_estimateGas"
10
+ "eth_getTransactionReceipt"
11
11
  ];
12
12
  var eip721Domain = {
13
13
  name: "Silent Data [Rollup]",
@@ -27,7 +27,7 @@ var HEADER_EIP712_SIGNATURE = "x-eip712-signature";
27
27
  var HEADER_DELEGATE = "x-delegate";
28
28
  var HEADER_DELEGATE_SIGNATURE = "x-delegate-signature";
29
29
  var HEADER_EIP712_DELEGATE_SIGNATURE = "x-eip712-delegate-signature";
30
- var DEFAULT_DELEGATE_EXPIRES = 24 * 60 * 60;
30
+ var DEFAULT_DELEGATE_EXPIRES = 10 * 60 * 60;
31
31
  var DELEGATE_EXPIRATION_THRESHOLD_BUFFER = 5;
32
32
  var WHITELISTED_METHODS = [
33
33
  "eth_blockNumber",
@@ -79,8 +79,8 @@ var WHITELISTED_METHODS = [
79
79
 
80
80
  // src/types.ts
81
81
  var ChainId = /* @__PURE__ */ ((ChainId2) => {
82
- ChainId2[ChainId2["MAINNET"] = 51966] = "MAINNET";
83
- ChainId2[ChainId2["TESTNET"] = 1001] = "TESTNET";
82
+ ChainId2[ChainId2["MAINNET"] = 380929] = "MAINNET";
83
+ ChainId2[ChainId2["TESTNET"] = 381185] = "TESTNET";
84
84
  return ChainId2;
85
85
  })(ChainId || {});
86
86
  var NetworkName = /* @__PURE__ */ ((NetworkName2) => {
@@ -116,7 +116,7 @@ function getAuthEIP721Types(payload) {
116
116
  ]
117
117
  };
118
118
  }
119
- async function signAuthHeaderTypedData(signer, payload, timestamp) {
119
+ async function signAuthHeaderTypedData(signer, payload, timestamp, chainId) {
120
120
  log("Preparing payload for signTypedData");
121
121
  const preparePayload = (p) => ({
122
122
  ...p,
@@ -128,27 +128,25 @@ async function signAuthHeaderTypedData(signer, payload, timestamp) {
128
128
  timestamp
129
129
  };
130
130
  const types = getAuthEIP721Types(payload);
131
- log(
132
- "Signing typed data",
133
- JSON.stringify({ eip721Domain, types, message }, null, 2)
134
- );
135
- const signature = await signer.signTypedData(eip721Domain, types, message);
131
+ const domain = { ...eip721Domain, chainId };
132
+ log("Signing typed data", JSON.stringify({ domain, types, message }, null, 2));
133
+ const signature = await signer.signTypedData(domain, types, message);
136
134
  log("Signature generated:", signature);
137
135
  return signature;
138
136
  }
139
- async function signAuthHeaderRawMessage(signer, payload, timestamp) {
137
+ async function signAuthHeaderRawMessage(signer, payload, timestamp, chainId) {
140
138
  log("Preparing raw message for signing");
141
139
  const serialRequest = JSON.stringify(payload);
142
- const xMessage = serialRequest + timestamp;
140
+ const xMessage = chainId + serialRequest + timestamp;
143
141
  log("Raw message:", xMessage);
144
142
  const signature = await signer.signMessage(xMessage);
145
143
  log("Raw signature generated:", signature);
146
144
  return signature;
147
145
  }
148
- async function signTypedDelegateHeader(signer, message) {
149
- log("Signing typed delegate header");
146
+ async function signTypedDelegateHeader(signer, chainId, message) {
147
+ log("Signing typed delegate header", { chainId, message });
150
148
  const signature = await signer.signTypedData(
151
- eip721Domain,
149
+ { ...eip721Domain, chainId },
152
150
  delegateEIP721Types,
153
151
  message
154
152
  );
@@ -156,9 +154,8 @@ async function signTypedDelegateHeader(signer, message) {
156
154
  return signature;
157
155
  }
158
156
  async function signRawDelegateHeader(signer, message) {
159
- log("Signing raw delegate header");
160
- log("Raw message:", message);
161
- const signature = await signer.signMessage(JSON.stringify(message));
157
+ log("Signing raw delegate header", message);
158
+ const signature = await signer.signMessage(message);
162
159
  log("Raw signature generated:", signature);
163
160
  return signature;
164
161
  }
@@ -167,13 +164,15 @@ async function getAuthHeaders(signer, payload, signatureType) {
167
164
  const headers = {
168
165
  [HEADER_TIMESTAMP]: xTimestamp
169
166
  };
167
+ const chainId = (await signer.provider.getNetwork()).chainId.toString();
170
168
  switch (signatureType) {
171
169
  case "RAW" /* Raw */:
172
170
  log("Generating raw signature");
173
171
  headers[HEADER_SIGNATURE] = await signAuthHeaderRawMessage(
174
172
  signer,
175
173
  payload,
176
- xTimestamp
174
+ xTimestamp,
175
+ chainId
177
176
  );
178
177
  break;
179
178
  case "EIP712" /* EIP712 */:
@@ -181,7 +180,8 @@ async function getAuthHeaders(signer, payload, signatureType) {
181
180
  headers[HEADER_EIP712_SIGNATURE] = await signAuthHeaderTypedData(
182
181
  signer,
183
182
  payload,
184
- xTimestamp
183
+ xTimestamp,
184
+ chainId
185
185
  );
186
186
  break;
187
187
  default:
@@ -231,6 +231,7 @@ var SilentDataRollupBase = class {
231
231
  this.cachedHeadersExpiry = 0;
232
232
  this.contract = null;
233
233
  this.contractMethodsToSign = [];
234
+ this._cachedNetwork = null;
234
235
  this.config = {
235
236
  ...config,
236
237
  authSignatureType: config.authSignatureType ?? "RAW" /* Raw */
@@ -255,6 +256,18 @@ var SilentDataRollupBase = class {
255
256
  }
256
257
  return null;
257
258
  }
259
+ /**
260
+ * Get cached network with simple caching
261
+ * @param provider - The provider to get the network from
262
+ * @returns Promise<Network> - The cached or freshly fetched network
263
+ */
264
+ async getCachedNetwork(provider) {
265
+ if (!this._cachedNetwork) {
266
+ this._cachedNetwork = await provider.getNetwork();
267
+ log2("Network cached:", this._cachedNetwork);
268
+ }
269
+ return this._cachedNetwork;
270
+ }
258
271
  async getDelegateSigner(provider) {
259
272
  if (!this.delegateConfig) {
260
273
  log2("getDelegateSigner: No delegate config, returning null");
@@ -311,9 +324,8 @@ var SilentDataRollupBase = class {
311
324
  * @returns A promise that resolves to the signature string
312
325
  */
313
326
  async signRawDelegateHeader(provider, message) {
314
- log2("signRawDelegateHeader: Signing raw delegate header");
315
- log2("signRawDelegateHeader: Raw message:", JSON.stringify(message, null, 2));
316
- const signature = await provider.signer.signMessage(JSON.stringify(message));
327
+ log2("signRawDelegateHeader: Signing raw delegate header", message);
328
+ const signature = await provider.signer.signMessage(message);
317
329
  log2("signRawDelegateHeader: Raw signature generated:", signature);
318
330
  return signature;
319
331
  }
@@ -324,14 +336,14 @@ var SilentDataRollupBase = class {
324
336
  * @param message - The delegate signer message to be signed
325
337
  * @returns A promise that resolves to the signature string
326
338
  */
327
- async signTypedDelegateHeader(provider, message) {
339
+ async signTypedDelegateHeader(provider, chainId, message) {
328
340
  log2("signTypedDelegateHeader: Signing typed delegate header");
329
341
  log2(
330
342
  "signTypedDelegateHeader: Typed message:",
331
343
  JSON.stringify(message, null, 2)
332
344
  );
333
345
  const signature = await provider.signer.signTypedData(
334
- eip721Domain,
346
+ { ...eip721Domain, chainId },
335
347
  delegateEIP721Types,
336
348
  message
337
349
  );
@@ -359,17 +371,24 @@ var SilentDataRollupBase = class {
359
371
  const headers = {
360
372
  [HEADER_DELEGATE]: JSON.stringify(delegateSignerMessage)
361
373
  };
374
+ const chainId = (await this.getCachedNetwork(provider)).chainId.toString();
362
375
  switch (signatureType) {
363
- case "RAW" /* Raw */:
376
+ case "RAW" /* Raw */: {
364
377
  log2("Generating delegate raw signature");
378
+ const delegateMessageToSign = chainId + JSON.stringify(delegateSignerMessage);
365
379
  headers[HEADER_DELEGATE_SIGNATURE] = await this.signRawDelegateHeader(
366
380
  provider,
367
- delegateSignerMessage
381
+ delegateMessageToSign
368
382
  );
369
383
  break;
384
+ }
370
385
  case "EIP712" /* EIP712 */:
371
386
  log2("Generating delegate EIP712 signature");
372
- headers[HEADER_EIP712_DELEGATE_SIGNATURE] = await this.signTypedDelegateHeader(provider, delegateSignerMessage);
387
+ headers[HEADER_EIP712_DELEGATE_SIGNATURE] = await this.signTypedDelegateHeader(
388
+ provider,
389
+ chainId,
390
+ delegateSignerMessage
391
+ );
373
392
  break;
374
393
  default:
375
394
  throw new Error(`Unsupported signature type: ${signatureType}`);
@@ -388,6 +407,7 @@ var SilentDataRollupBase = class {
388
407
  const headers = {
389
408
  [HEADER_TIMESTAMP]: xTimestamp
390
409
  };
410
+ const chainId = (await this.getCachedNetwork(provider)).chainId.toString();
391
411
  const signatureType = this.config.authSignatureType;
392
412
  switch (signatureType) {
393
413
  case "RAW" /* Raw */:
@@ -395,7 +415,8 @@ var SilentDataRollupBase = class {
395
415
  headers[HEADER_SIGNATURE] = await this.signAuthHeaderRawMessage(
396
416
  provider,
397
417
  payload,
398
- xTimestamp
418
+ xTimestamp,
419
+ chainId
399
420
  );
400
421
  break;
401
422
  case "EIP712" /* EIP712 */:
@@ -403,7 +424,8 @@ var SilentDataRollupBase = class {
403
424
  headers[HEADER_EIP712_SIGNATURE] = await this.signAuthHeaderTypedData(
404
425
  provider,
405
426
  payload,
406
- xTimestamp
427
+ xTimestamp,
428
+ chainId
407
429
  );
408
430
  break;
409
431
  default:
@@ -412,29 +434,25 @@ var SilentDataRollupBase = class {
412
434
  log2("Auth headers:", JSON.stringify(headers, null, 2));
413
435
  return headers;
414
436
  }
415
- async signAuthHeaderRawMessage(provider, payload, timestamp) {
416
- const xMessage = this.prepareSignatureMessage(payload, timestamp);
437
+ async signAuthHeaderRawMessage(provider, payload, timestamp, chainId) {
438
+ const xMessage = this.prepareSignatureMessage(chainId, payload, timestamp);
417
439
  const delegateSigner = await this.getDelegateSigner(this);
418
440
  const signer = delegateSigner ?? provider.signer;
419
441
  const signature = await this.signMessage(signer, xMessage);
420
442
  log2("Message signed. Signature:", signature);
421
443
  return signature;
422
444
  }
423
- async signAuthHeaderTypedData(provider, payload, timestamp) {
445
+ async signAuthHeaderTypedData(provider, payload, timestamp, chainId) {
424
446
  const message = this.prepareSignatureTypedData(payload, timestamp);
425
447
  const types = getAuthEIP721Types(payload);
426
448
  const delegateSigner = await this.getDelegateSigner(this);
427
449
  const signer = delegateSigner ?? provider.signer;
450
+ const domain = { ...eip721Domain, chainId };
428
451
  log2(
429
452
  "Signing typed data",
430
- JSON.stringify({ message, types, eip721Domain }, null, 2)
431
- );
432
- const signature = await this.signTypedData(
433
- signer,
434
- eip721Domain,
435
- types,
436
- message
453
+ JSON.stringify({ message, types, domain }, null, 2)
437
454
  );
455
+ const signature = await this.signTypedData(signer, domain, types, message);
438
456
  log2("Message signed. Signature:", signature);
439
457
  return signature;
440
458
  }
@@ -468,13 +486,13 @@ var SilentDataRollupBase = class {
468
486
  /**
469
487
  * Prepares the message to be signed for the x-signature header.
470
488
  */
471
- prepareSignatureMessage(payload, timestamp) {
489
+ prepareSignatureMessage(chainId, payload, timestamp) {
472
490
  log2("Preparing raw message for signing", {
473
491
  payload: JSON.stringify(payload, null, 2),
474
492
  timestamp
475
493
  });
476
494
  const serialRequest = JSON.stringify(payload);
477
- const xMessage = serialRequest + timestamp;
495
+ const xMessage = chainId + serialRequest + timestamp;
478
496
  log2("Raw message to be signed:", xMessage);
479
497
  return xMessage;
480
498
  }
@@ -511,6 +529,9 @@ var CustomContractRunner = class {
511
529
  "latest"
512
530
  );
513
531
  tx.nonce = latestNonce;
532
+ if (!tx.gasLimit) {
533
+ tx.gasLimit = await this.provider.estimateGas(tx);
534
+ }
514
535
  return this.signer.sendTransaction(tx);
515
536
  }
516
537
  };
package/dist/index.d.mts CHANGED
@@ -29,8 +29,8 @@ declare const DELEGATE_EXPIRATION_THRESHOLD_BUFFER = 5;
29
29
  declare const WHITELISTED_METHODS: string[];
30
30
 
31
31
  declare enum ChainId {
32
- MAINNET = 51966,
33
- TESTNET = 1001
32
+ MAINNET = 380929,
33
+ TESTNET = 381185
34
34
  }
35
35
  declare enum NetworkName {
36
36
  MAINNET = "sdr",
@@ -111,8 +111,15 @@ declare class SilentDataRollupBase {
111
111
  private cachedHeadersExpiry;
112
112
  contract: Contract | null;
113
113
  contractMethodsToSign: string[];
114
+ private _cachedNetwork;
114
115
  constructor(config: BaseConfig);
115
116
  private resolveDelegateConfig;
117
+ /**
118
+ * Get cached network with simple caching
119
+ * @param provider - The provider to get the network from
120
+ * @returns Promise<Network> - The cached or freshly fetched network
121
+ */
122
+ getCachedNetwork(provider: any): Promise<any>;
116
123
  getDelegateSigner(provider: any): Promise<Signer | null>;
117
124
  getDelegateSignerMessage(provider: any): Promise<DelegateSignerMessage | null>;
118
125
  /**
@@ -122,7 +129,7 @@ declare class SilentDataRollupBase {
122
129
  * @param message - The delegate signer message to be signed
123
130
  * @returns A promise that resolves to the signature string
124
131
  */
125
- protected signRawDelegateHeader(provider: any, message: DelegateSignerMessage): Promise<string>;
132
+ protected signRawDelegateHeader(provider: any, message: string): Promise<string>;
126
133
  /**
127
134
  * Signs a typed delegate header message.
128
135
  * This method can be overridden by extending classes to customize the signing process.
@@ -130,11 +137,11 @@ declare class SilentDataRollupBase {
130
137
  * @param message - The delegate signer message to be signed
131
138
  * @returns A promise that resolves to the signature string
132
139
  */
133
- protected signTypedDelegateHeader(provider: any, message: DelegateSignerMessage): Promise<string>;
140
+ protected signTypedDelegateHeader(provider: any, chainId: string, message: DelegateSignerMessage): Promise<string>;
134
141
  getDelegateHeaders(provider: any): Promise<DelegateHeaders>;
135
142
  getAuthHeaders(provider: any, payload: JsonRpcPayload | JsonRpcPayload[]): Promise<AuthHeaders>;
136
- signAuthHeaderRawMessage(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
137
- signAuthHeaderTypedData(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
143
+ signAuthHeaderRawMessage(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string, chainId: string): Promise<string>;
144
+ signAuthHeaderTypedData(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string, chainId: string): Promise<string>;
138
145
  /**
139
146
  * Signs a message using the provided signer.
140
147
  * This method can be overridden to customize the signing process.
@@ -157,7 +164,7 @@ declare class SilentDataRollupBase {
157
164
  /**
158
165
  * Prepares the message to be signed for the x-signature header.
159
166
  */
160
- prepareSignatureMessage(payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): string;
167
+ prepareSignatureMessage(chainId: string, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): string;
161
168
  /**
162
169
  * Prepares the message to be signed for the x-eip712-signature header.
163
170
  */
@@ -178,10 +185,10 @@ declare function getAuthEIP721Types(payload: JsonRpcPayload | JsonRpcPayload[]):
178
185
  type: string;
179
186
  }[];
180
187
  };
181
- declare function signAuthHeaderTypedData(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
182
- declare function signAuthHeaderRawMessage(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
183
- declare function signTypedDelegateHeader(signer: any, message: DelegateSignerMessage): Promise<any>;
184
- declare function signRawDelegateHeader(signer: any, message: DelegateSignerMessage): Promise<string>;
188
+ declare function signAuthHeaderTypedData(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string, chainId: string): Promise<string>;
189
+ declare function signAuthHeaderRawMessage(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string, chainId: string): Promise<string>;
190
+ declare function signTypedDelegateHeader(signer: any, chainId: string, message: DelegateSignerMessage): Promise<any>;
191
+ declare function signRawDelegateHeader(signer: any, message: string): Promise<string>;
185
192
  declare function getAuthHeaders(signer: Signer, payload: JsonRpcPayload | JsonRpcPayload[], signatureType: SignatureType): Promise<AuthHeaders>;
186
193
  /**
187
194
  * Determines if a given JSON-RPC payload represents a call to a contract method that requires signing.
package/dist/index.d.ts CHANGED
@@ -29,8 +29,8 @@ declare const DELEGATE_EXPIRATION_THRESHOLD_BUFFER = 5;
29
29
  declare const WHITELISTED_METHODS: string[];
30
30
 
31
31
  declare enum ChainId {
32
- MAINNET = 51966,
33
- TESTNET = 1001
32
+ MAINNET = 380929,
33
+ TESTNET = 381185
34
34
  }
35
35
  declare enum NetworkName {
36
36
  MAINNET = "sdr",
@@ -111,8 +111,15 @@ declare class SilentDataRollupBase {
111
111
  private cachedHeadersExpiry;
112
112
  contract: Contract | null;
113
113
  contractMethodsToSign: string[];
114
+ private _cachedNetwork;
114
115
  constructor(config: BaseConfig);
115
116
  private resolveDelegateConfig;
117
+ /**
118
+ * Get cached network with simple caching
119
+ * @param provider - The provider to get the network from
120
+ * @returns Promise<Network> - The cached or freshly fetched network
121
+ */
122
+ getCachedNetwork(provider: any): Promise<any>;
116
123
  getDelegateSigner(provider: any): Promise<Signer | null>;
117
124
  getDelegateSignerMessage(provider: any): Promise<DelegateSignerMessage | null>;
118
125
  /**
@@ -122,7 +129,7 @@ declare class SilentDataRollupBase {
122
129
  * @param message - The delegate signer message to be signed
123
130
  * @returns A promise that resolves to the signature string
124
131
  */
125
- protected signRawDelegateHeader(provider: any, message: DelegateSignerMessage): Promise<string>;
132
+ protected signRawDelegateHeader(provider: any, message: string): Promise<string>;
126
133
  /**
127
134
  * Signs a typed delegate header message.
128
135
  * This method can be overridden by extending classes to customize the signing process.
@@ -130,11 +137,11 @@ declare class SilentDataRollupBase {
130
137
  * @param message - The delegate signer message to be signed
131
138
  * @returns A promise that resolves to the signature string
132
139
  */
133
- protected signTypedDelegateHeader(provider: any, message: DelegateSignerMessage): Promise<string>;
140
+ protected signTypedDelegateHeader(provider: any, chainId: string, message: DelegateSignerMessage): Promise<string>;
134
141
  getDelegateHeaders(provider: any): Promise<DelegateHeaders>;
135
142
  getAuthHeaders(provider: any, payload: JsonRpcPayload | JsonRpcPayload[]): Promise<AuthHeaders>;
136
- signAuthHeaderRawMessage(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
137
- signAuthHeaderTypedData(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
143
+ signAuthHeaderRawMessage(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string, chainId: string): Promise<string>;
144
+ signAuthHeaderTypedData(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string, chainId: string): Promise<string>;
138
145
  /**
139
146
  * Signs a message using the provided signer.
140
147
  * This method can be overridden to customize the signing process.
@@ -157,7 +164,7 @@ declare class SilentDataRollupBase {
157
164
  /**
158
165
  * Prepares the message to be signed for the x-signature header.
159
166
  */
160
- prepareSignatureMessage(payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): string;
167
+ prepareSignatureMessage(chainId: string, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): string;
161
168
  /**
162
169
  * Prepares the message to be signed for the x-eip712-signature header.
163
170
  */
@@ -178,10 +185,10 @@ declare function getAuthEIP721Types(payload: JsonRpcPayload | JsonRpcPayload[]):
178
185
  type: string;
179
186
  }[];
180
187
  };
181
- declare function signAuthHeaderTypedData(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
182
- declare function signAuthHeaderRawMessage(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
183
- declare function signTypedDelegateHeader(signer: any, message: DelegateSignerMessage): Promise<any>;
184
- declare function signRawDelegateHeader(signer: any, message: DelegateSignerMessage): Promise<string>;
188
+ declare function signAuthHeaderTypedData(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string, chainId: string): Promise<string>;
189
+ declare function signAuthHeaderRawMessage(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string, chainId: string): Promise<string>;
190
+ declare function signTypedDelegateHeader(signer: any, chainId: string, message: DelegateSignerMessage): Promise<any>;
191
+ declare function signRawDelegateHeader(signer: any, message: string): Promise<string>;
185
192
  declare function getAuthHeaders(signer: Signer, payload: JsonRpcPayload | JsonRpcPayload[], signatureType: SignatureType): Promise<AuthHeaders>;
186
193
  /**
187
194
  * Determines if a given JSON-RPC payload represents a call to a contract method that requires signing.
package/dist/index.js CHANGED
@@ -69,11 +69,11 @@ var import_debug2 = __toESM(require("debug"));
69
69
 
70
70
  // src/constants.ts
71
71
  var SIGN_RPC_METHODS = [
72
+ "eth_estimateGas",
73
+ "eth_getProof",
72
74
  "eth_getTransactionByHash",
73
75
  "eth_getTransactionCount",
74
- "eth_getProof",
75
- "eth_getTransactionReceipt",
76
- "eth_estimateGas"
76
+ "eth_getTransactionReceipt"
77
77
  ];
78
78
  var eip721Domain = {
79
79
  name: "Silent Data [Rollup]",
@@ -93,7 +93,7 @@ var HEADER_EIP712_SIGNATURE = "x-eip712-signature";
93
93
  var HEADER_DELEGATE = "x-delegate";
94
94
  var HEADER_DELEGATE_SIGNATURE = "x-delegate-signature";
95
95
  var HEADER_EIP712_DELEGATE_SIGNATURE = "x-eip712-delegate-signature";
96
- var DEFAULT_DELEGATE_EXPIRES = 24 * 60 * 60;
96
+ var DEFAULT_DELEGATE_EXPIRES = 10 * 60 * 60;
97
97
  var DELEGATE_EXPIRATION_THRESHOLD_BUFFER = 5;
98
98
  var WHITELISTED_METHODS = [
99
99
  "eth_blockNumber",
@@ -145,8 +145,8 @@ var WHITELISTED_METHODS = [
145
145
 
146
146
  // src/types.ts
147
147
  var ChainId = /* @__PURE__ */ ((ChainId2) => {
148
- ChainId2[ChainId2["MAINNET"] = 51966] = "MAINNET";
149
- ChainId2[ChainId2["TESTNET"] = 1001] = "TESTNET";
148
+ ChainId2[ChainId2["MAINNET"] = 380929] = "MAINNET";
149
+ ChainId2[ChainId2["TESTNET"] = 381185] = "TESTNET";
150
150
  return ChainId2;
151
151
  })(ChainId || {});
152
152
  var NetworkName = /* @__PURE__ */ ((NetworkName2) => {
@@ -182,7 +182,7 @@ function getAuthEIP721Types(payload) {
182
182
  ]
183
183
  };
184
184
  }
185
- async function signAuthHeaderTypedData(signer, payload, timestamp) {
185
+ async function signAuthHeaderTypedData(signer, payload, timestamp, chainId) {
186
186
  log("Preparing payload for signTypedData");
187
187
  const preparePayload = (p) => ({
188
188
  ...p,
@@ -194,27 +194,25 @@ async function signAuthHeaderTypedData(signer, payload, timestamp) {
194
194
  timestamp
195
195
  };
196
196
  const types = getAuthEIP721Types(payload);
197
- log(
198
- "Signing typed data",
199
- JSON.stringify({ eip721Domain, types, message }, null, 2)
200
- );
201
- const signature = await signer.signTypedData(eip721Domain, types, message);
197
+ const domain = { ...eip721Domain, chainId };
198
+ log("Signing typed data", JSON.stringify({ domain, types, message }, null, 2));
199
+ const signature = await signer.signTypedData(domain, types, message);
202
200
  log("Signature generated:", signature);
203
201
  return signature;
204
202
  }
205
- async function signAuthHeaderRawMessage(signer, payload, timestamp) {
203
+ async function signAuthHeaderRawMessage(signer, payload, timestamp, chainId) {
206
204
  log("Preparing raw message for signing");
207
205
  const serialRequest = JSON.stringify(payload);
208
- const xMessage = serialRequest + timestamp;
206
+ const xMessage = chainId + serialRequest + timestamp;
209
207
  log("Raw message:", xMessage);
210
208
  const signature = await signer.signMessage(xMessage);
211
209
  log("Raw signature generated:", signature);
212
210
  return signature;
213
211
  }
214
- async function signTypedDelegateHeader(signer, message) {
215
- log("Signing typed delegate header");
212
+ async function signTypedDelegateHeader(signer, chainId, message) {
213
+ log("Signing typed delegate header", { chainId, message });
216
214
  const signature = await signer.signTypedData(
217
- eip721Domain,
215
+ { ...eip721Domain, chainId },
218
216
  delegateEIP721Types,
219
217
  message
220
218
  );
@@ -222,9 +220,8 @@ async function signTypedDelegateHeader(signer, message) {
222
220
  return signature;
223
221
  }
224
222
  async function signRawDelegateHeader(signer, message) {
225
- log("Signing raw delegate header");
226
- log("Raw message:", message);
227
- const signature = await signer.signMessage(JSON.stringify(message));
223
+ log("Signing raw delegate header", message);
224
+ const signature = await signer.signMessage(message);
228
225
  log("Raw signature generated:", signature);
229
226
  return signature;
230
227
  }
@@ -233,13 +230,15 @@ async function getAuthHeaders(signer, payload, signatureType) {
233
230
  const headers = {
234
231
  [HEADER_TIMESTAMP]: xTimestamp
235
232
  };
233
+ const chainId = (await signer.provider.getNetwork()).chainId.toString();
236
234
  switch (signatureType) {
237
235
  case "RAW" /* Raw */:
238
236
  log("Generating raw signature");
239
237
  headers[HEADER_SIGNATURE] = await signAuthHeaderRawMessage(
240
238
  signer,
241
239
  payload,
242
- xTimestamp
240
+ xTimestamp,
241
+ chainId
243
242
  );
244
243
  break;
245
244
  case "EIP712" /* EIP712 */:
@@ -247,7 +246,8 @@ async function getAuthHeaders(signer, payload, signatureType) {
247
246
  headers[HEADER_EIP712_SIGNATURE] = await signAuthHeaderTypedData(
248
247
  signer,
249
248
  payload,
250
- xTimestamp
249
+ xTimestamp,
250
+ chainId
251
251
  );
252
252
  break;
253
253
  default:
@@ -297,6 +297,7 @@ var SilentDataRollupBase = class {
297
297
  this.cachedHeadersExpiry = 0;
298
298
  this.contract = null;
299
299
  this.contractMethodsToSign = [];
300
+ this._cachedNetwork = null;
300
301
  this.config = {
301
302
  ...config,
302
303
  authSignatureType: config.authSignatureType ?? "RAW" /* Raw */
@@ -321,6 +322,18 @@ var SilentDataRollupBase = class {
321
322
  }
322
323
  return null;
323
324
  }
325
+ /**
326
+ * Get cached network with simple caching
327
+ * @param provider - The provider to get the network from
328
+ * @returns Promise<Network> - The cached or freshly fetched network
329
+ */
330
+ async getCachedNetwork(provider) {
331
+ if (!this._cachedNetwork) {
332
+ this._cachedNetwork = await provider.getNetwork();
333
+ log2("Network cached:", this._cachedNetwork);
334
+ }
335
+ return this._cachedNetwork;
336
+ }
324
337
  async getDelegateSigner(provider) {
325
338
  if (!this.delegateConfig) {
326
339
  log2("getDelegateSigner: No delegate config, returning null");
@@ -377,9 +390,8 @@ var SilentDataRollupBase = class {
377
390
  * @returns A promise that resolves to the signature string
378
391
  */
379
392
  async signRawDelegateHeader(provider, message) {
380
- log2("signRawDelegateHeader: Signing raw delegate header");
381
- log2("signRawDelegateHeader: Raw message:", JSON.stringify(message, null, 2));
382
- const signature = await provider.signer.signMessage(JSON.stringify(message));
393
+ log2("signRawDelegateHeader: Signing raw delegate header", message);
394
+ const signature = await provider.signer.signMessage(message);
383
395
  log2("signRawDelegateHeader: Raw signature generated:", signature);
384
396
  return signature;
385
397
  }
@@ -390,14 +402,14 @@ var SilentDataRollupBase = class {
390
402
  * @param message - The delegate signer message to be signed
391
403
  * @returns A promise that resolves to the signature string
392
404
  */
393
- async signTypedDelegateHeader(provider, message) {
405
+ async signTypedDelegateHeader(provider, chainId, message) {
394
406
  log2("signTypedDelegateHeader: Signing typed delegate header");
395
407
  log2(
396
408
  "signTypedDelegateHeader: Typed message:",
397
409
  JSON.stringify(message, null, 2)
398
410
  );
399
411
  const signature = await provider.signer.signTypedData(
400
- eip721Domain,
412
+ { ...eip721Domain, chainId },
401
413
  delegateEIP721Types,
402
414
  message
403
415
  );
@@ -425,17 +437,24 @@ var SilentDataRollupBase = class {
425
437
  const headers = {
426
438
  [HEADER_DELEGATE]: JSON.stringify(delegateSignerMessage)
427
439
  };
440
+ const chainId = (await this.getCachedNetwork(provider)).chainId.toString();
428
441
  switch (signatureType) {
429
- case "RAW" /* Raw */:
442
+ case "RAW" /* Raw */: {
430
443
  log2("Generating delegate raw signature");
444
+ const delegateMessageToSign = chainId + JSON.stringify(delegateSignerMessage);
431
445
  headers[HEADER_DELEGATE_SIGNATURE] = await this.signRawDelegateHeader(
432
446
  provider,
433
- delegateSignerMessage
447
+ delegateMessageToSign
434
448
  );
435
449
  break;
450
+ }
436
451
  case "EIP712" /* EIP712 */:
437
452
  log2("Generating delegate EIP712 signature");
438
- headers[HEADER_EIP712_DELEGATE_SIGNATURE] = await this.signTypedDelegateHeader(provider, delegateSignerMessage);
453
+ headers[HEADER_EIP712_DELEGATE_SIGNATURE] = await this.signTypedDelegateHeader(
454
+ provider,
455
+ chainId,
456
+ delegateSignerMessage
457
+ );
439
458
  break;
440
459
  default:
441
460
  throw new Error(`Unsupported signature type: ${signatureType}`);
@@ -454,6 +473,7 @@ var SilentDataRollupBase = class {
454
473
  const headers = {
455
474
  [HEADER_TIMESTAMP]: xTimestamp
456
475
  };
476
+ const chainId = (await this.getCachedNetwork(provider)).chainId.toString();
457
477
  const signatureType = this.config.authSignatureType;
458
478
  switch (signatureType) {
459
479
  case "RAW" /* Raw */:
@@ -461,7 +481,8 @@ var SilentDataRollupBase = class {
461
481
  headers[HEADER_SIGNATURE] = await this.signAuthHeaderRawMessage(
462
482
  provider,
463
483
  payload,
464
- xTimestamp
484
+ xTimestamp,
485
+ chainId
465
486
  );
466
487
  break;
467
488
  case "EIP712" /* EIP712 */:
@@ -469,7 +490,8 @@ var SilentDataRollupBase = class {
469
490
  headers[HEADER_EIP712_SIGNATURE] = await this.signAuthHeaderTypedData(
470
491
  provider,
471
492
  payload,
472
- xTimestamp
493
+ xTimestamp,
494
+ chainId
473
495
  );
474
496
  break;
475
497
  default:
@@ -478,29 +500,25 @@ var SilentDataRollupBase = class {
478
500
  log2("Auth headers:", JSON.stringify(headers, null, 2));
479
501
  return headers;
480
502
  }
481
- async signAuthHeaderRawMessage(provider, payload, timestamp) {
482
- const xMessage = this.prepareSignatureMessage(payload, timestamp);
503
+ async signAuthHeaderRawMessage(provider, payload, timestamp, chainId) {
504
+ const xMessage = this.prepareSignatureMessage(chainId, payload, timestamp);
483
505
  const delegateSigner = await this.getDelegateSigner(this);
484
506
  const signer = delegateSigner ?? provider.signer;
485
507
  const signature = await this.signMessage(signer, xMessage);
486
508
  log2("Message signed. Signature:", signature);
487
509
  return signature;
488
510
  }
489
- async signAuthHeaderTypedData(provider, payload, timestamp) {
511
+ async signAuthHeaderTypedData(provider, payload, timestamp, chainId) {
490
512
  const message = this.prepareSignatureTypedData(payload, timestamp);
491
513
  const types = getAuthEIP721Types(payload);
492
514
  const delegateSigner = await this.getDelegateSigner(this);
493
515
  const signer = delegateSigner ?? provider.signer;
516
+ const domain = { ...eip721Domain, chainId };
494
517
  log2(
495
518
  "Signing typed data",
496
- JSON.stringify({ message, types, eip721Domain }, null, 2)
497
- );
498
- const signature = await this.signTypedData(
499
- signer,
500
- eip721Domain,
501
- types,
502
- message
519
+ JSON.stringify({ message, types, domain }, null, 2)
503
520
  );
521
+ const signature = await this.signTypedData(signer, domain, types, message);
504
522
  log2("Message signed. Signature:", signature);
505
523
  return signature;
506
524
  }
@@ -534,13 +552,13 @@ var SilentDataRollupBase = class {
534
552
  /**
535
553
  * Prepares the message to be signed for the x-signature header.
536
554
  */
537
- prepareSignatureMessage(payload, timestamp) {
555
+ prepareSignatureMessage(chainId, payload, timestamp) {
538
556
  log2("Preparing raw message for signing", {
539
557
  payload: JSON.stringify(payload, null, 2),
540
558
  timestamp
541
559
  });
542
560
  const serialRequest = JSON.stringify(payload);
543
- const xMessage = serialRequest + timestamp;
561
+ const xMessage = chainId + serialRequest + timestamp;
544
562
  log2("Raw message to be signed:", xMessage);
545
563
  return xMessage;
546
564
  }
@@ -573,6 +591,9 @@ var CustomContractRunner = class {
573
591
  "latest"
574
592
  );
575
593
  tx.nonce = latestNonce;
594
+ if (!tx.gasLimit) {
595
+ tx.gasLimit = await this.provider.estimateGas(tx);
596
+ }
576
597
  return this.signer.sendTransaction(tx);
577
598
  }
578
599
  };
package/dist/index.mjs CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  signAuthHeaderTypedData,
31
31
  signRawDelegateHeader,
32
32
  signTypedDelegateHeader
33
- } from "./chunk-XU34XEI3.mjs";
33
+ } from "./chunk-CH35C5Q7.mjs";
34
34
  export {
35
35
  ChainId,
36
36
  DEBUG_NAMESPACE,
package/dist/tests.js CHANGED
@@ -39,7 +39,7 @@ var import_debug2 = __toESM(require("debug"));
39
39
 
40
40
  // src/constants.ts
41
41
  var DEBUG_NAMESPACE = "silentdata:core";
42
- var DEFAULT_DELEGATE_EXPIRES = 24 * 60 * 60;
42
+ var DEFAULT_DELEGATE_EXPIRES = 10 * 60 * 60;
43
43
 
44
44
  // src/utils.ts
45
45
  var import_debug = __toESM(require("debug"));
@@ -62,7 +62,7 @@ var PRIVATE_EVENT_SIGNATURE_HASH = (0, import_ethers3.keccak256)(
62
62
  // tests/utils/mocked-custom-grpc.ts
63
63
  var import_http = __toESM(require("http"));
64
64
  var currentPort = 3e3;
65
- var CHAIN_ID = 1001 /* TESTNET */;
65
+ var CHAIN_ID = 381185 /* TESTNET */;
66
66
  function createCustomRpcServer(callback) {
67
67
  const port = currentPort++;
68
68
  const customRpcUrl = `http://localhost:${port}`;
package/dist/tests.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import "./chunk-XU34XEI3.mjs";
1
+ import "./chunk-CH35C5Q7.mjs";
2
2
 
3
3
  // tests/utils/mocked-custom-grpc.ts
4
4
  import http from "http";
5
5
  var currentPort = 3e3;
6
- var CHAIN_ID = 1001 /* TESTNET */;
6
+ var CHAIN_ID = 381185 /* TESTNET */;
7
7
  function createCustomRpcServer(callback) {
8
8
  const port = currentPort++;
9
9
  const customRpcUrl = `http://localhost:${port}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appliedblockchain/silentdatarollup-core",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Core library for Silent Data [Rollup]",
5
5
  "author": "Applied Blockchain",
6
6
  "homepage": "https://github.com/appliedblockchain/silent-data-rollup-providers#readme",
@@ -29,7 +29,7 @@
29
29
  "dist"
30
30
  ],
31
31
  "scripts": {
32
- "build": "tsup src/index.ts src/tests.ts --format cjs,esm --dts --clean",
32
+ "build": "tsc --noEmit && tsup src/index.ts src/tests.ts --format cjs,esm --dts --clean",
33
33
  "check-exports": "attw --pack . --profile node16",
34
34
  "prepack": "npm run build"
35
35
  },