@appliedblockchain/silentdatarollup-ethers-provider 1.0.6 → 1.0.8

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Silent Data [Rollup] Providers - Ethers Provider Package
1
+ # Silent Data Providers - Ethers Provider Package
2
2
 
3
3
  ## Table of Contents
4
4
 
@@ -21,7 +21,7 @@
21
21
 
22
22
  ## Introduction
23
23
 
24
- Custom providers for Silent Data [Rollup], compatible with ethers.js.
24
+ Custom providers for Silent Data, compatible with ethers.js.
25
25
 
26
26
  ## Prerequisites
27
27
 
@@ -230,5 +230,5 @@ If you encounter any issues, please check the following:
230
230
 
231
231
  ## Additional Resources
232
232
 
233
- - [Silent Data [Rollup] Documentation](https://docs.silentdata.com)
233
+ - [Silent Data Documentation](https://docs.silentdata.com)
234
234
  - [Ethers.js Documentation](https://docs.ethers.org/v6/)
package/dist/index.d.mts CHANGED
@@ -10,6 +10,7 @@ interface SilentDataRollupProviderConfig extends BaseConfig {
10
10
  privateKey?: string;
11
11
  signer?: Signer;
12
12
  options?: JsonRpcApiProviderOptions;
13
+ smartWalletAddress?: string;
13
14
  }
14
15
  /**
15
16
  * Extended filter type that includes a special flag for private events
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ interface SilentDataRollupProviderConfig extends BaseConfig {
10
10
  privateKey?: string;
11
11
  signer?: Signer;
12
12
  options?: JsonRpcApiProviderOptions;
13
+ smartWalletAddress?: string;
13
14
  }
14
15
  /**
15
16
  * Extended filter type that includes a special flag for private events
package/dist/index.js CHANGED
@@ -40,28 +40,77 @@ module.exports = __toCommonJS(index_exports);
40
40
  var DEBUG_NAMESPACE = "silentdata:ethers-provider";
41
41
 
42
42
  // src/provider.ts
43
+ var import_debug = __toESM(require("debug"));
43
44
  var import_silentdatarollup_core = require("@appliedblockchain/silentdatarollup-core");
45
+ var import_ethers2 = require("ethers");
46
+
47
+ // src/signer.ts
44
48
  var import_ethers = require("ethers");
49
+ var SilentDataRollupSigner = class extends import_ethers.AbstractSigner {
50
+ constructor(provider, signer) {
51
+ if (!provider) {
52
+ throw new Error("Provider is required");
53
+ }
54
+ if (!signer) {
55
+ throw new Error("Signer is required");
56
+ }
57
+ super(provider);
58
+ this.signer = signer;
59
+ }
60
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
61
+ connect(provider) {
62
+ (0, import_ethers.assert)(
63
+ false,
64
+ "cannot reconnect SilentDataRollupSigner",
65
+ "UNSUPPORTED_OPERATION",
66
+ {
67
+ operation: "signer.connect"
68
+ }
69
+ );
70
+ }
71
+ async getAddress() {
72
+ return this.signer.getAddress();
73
+ }
74
+ async signTransaction(tx) {
75
+ return this.signer.signTransaction(tx);
76
+ }
77
+ async signMessage(message) {
78
+ return this.signer.signMessage(message);
79
+ }
80
+ signTypedData(domain, types, value) {
81
+ return this.signer.signTypedData(domain, types, value);
82
+ }
83
+ async sendTransaction(tx) {
84
+ let gasLimit = tx.gasLimit;
85
+ if (!gasLimit) {
86
+ gasLimit = await this.estimateGas(tx);
87
+ }
88
+ return this.signer.sendTransaction({ ...tx, gasLimit });
89
+ }
90
+ };
91
+
92
+ // src/provider.ts
93
+ var log = (0, import_debug.default)(import_silentdatarollup_core.DEBUG_NAMESPACE);
45
94
  function isPromise(value) {
46
95
  return value && typeof value.then === "function";
47
96
  }
48
97
  function getNetwork(networkName, chainId) {
49
98
  if (chainId) {
50
- return new import_ethers.Network(networkName ?? "custom", chainId);
99
+ return new import_ethers2.Network(networkName ?? "custom", chainId);
51
100
  }
52
101
  if (networkName === import_silentdatarollup_core.NetworkName.MAINNET) {
53
- return new import_ethers.Network(networkName, import_silentdatarollup_core.ChainId.MAINNET);
102
+ return new import_ethers2.Network(networkName, import_silentdatarollup_core.ChainId.MAINNET);
54
103
  } else if (networkName === import_silentdatarollup_core.NetworkName.TESTNET) {
55
- return new import_ethers.Network(networkName, import_silentdatarollup_core.ChainId.TESTNET);
104
+ return new import_ethers2.Network(networkName, import_silentdatarollup_core.ChainId.TESTNET);
56
105
  }
57
106
  return void 0;
58
107
  }
59
108
  var providerDefaultOptions = {
60
109
  batchMaxCount: 1
61
110
  };
62
- var SilentDataRollupProvider = class _SilentDataRollupProvider extends import_ethers.JsonRpcProvider {
111
+ var SilentDataRollupProvider = class _SilentDataRollupProvider extends import_ethers2.JsonRpcProvider {
63
112
  constructor(config) {
64
- (0, import_ethers.assertArgument)(config.rpcUrl, "rpcUrl is mandatory", "config", config);
113
+ (0, import_ethers2.assertArgument)(config.rpcUrl, "rpcUrl is mandatory", "config", config);
65
114
  const network = getNetwork(config.network, config.chainId);
66
115
  const request = _SilentDataRollupProvider.getRequest({
67
116
  rpcUrl: config.rpcUrl
@@ -71,7 +120,7 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends import_et
71
120
  ...config.options
72
121
  };
73
122
  super(request, network, combinedOptions);
74
- (0, import_ethers.assertArgument)(
123
+ (0, import_ethers2.assertArgument)(
75
124
  config.signer || config.privateKey,
76
125
  "signer or privateKey is mandatory",
77
126
  "config",
@@ -84,10 +133,10 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends import_et
84
133
  try {
85
134
  this.signer = config.signer.connect(this);
86
135
  } catch {
87
- this.signer = config.signer;
136
+ this.signer = new SilentDataRollupSigner(this, config.signer);
88
137
  }
89
138
  } else {
90
- const wallet = new import_ethers.Wallet(config.privateKey);
139
+ const wallet = new import_ethers2.Wallet(config.privateKey);
91
140
  this.signer = wallet.connect(this);
92
141
  }
93
142
  }
@@ -95,6 +144,9 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends import_et
95
144
  if (Array.isArray(payload)) {
96
145
  throw new Error("Batch requests are not currently supported");
97
146
  }
147
+ if (["eth_getBlockByNumber", "eth_getBlockByHash"].includes(payload.method) && Array.isArray(payload.params) && payload.params.length > 1) {
148
+ payload.params[1] = false;
149
+ }
98
150
  const isEthCallOrEstimateGas = payload.method === "eth_call" || payload.method === "eth_estimateGas";
99
151
  if (isEthCallOrEstimateGas && Array.isArray(payload.params)) {
100
152
  const txParams = payload.params[0];
@@ -135,6 +187,10 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends import_et
135
187
  );
136
188
  }
137
189
  }
190
+ if (this.config.smartWalletAddress) {
191
+ log("Setting smart wallet header:", this.config.smartWalletAddress);
192
+ request.setHeader(import_silentdatarollup_core.HEADER_SIGNER_SWC, this.config.smartWalletAddress);
193
+ }
138
194
  const {
139
195
  [import_silentdatarollup_core.HEADER_TIMESTAMP]: xTimestamp,
140
196
  [import_silentdatarollup_core.HEADER_SIGNATURE]: xSignature,
@@ -157,7 +213,7 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends import_et
157
213
  return resp;
158
214
  }
159
215
  static getRequest({ rpcUrl }) {
160
- const request = new import_ethers.FetchRequest(rpcUrl);
216
+ const request = new import_ethers2.FetchRequest(rpcUrl);
161
217
  request.allowGzip = true;
162
218
  return request;
163
219
  }
@@ -253,7 +309,7 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends import_et
253
309
  enumerable: false
254
310
  });
255
311
  }
256
- const { network, params } = await (0, import_ethers.resolveProperties)({
312
+ const { network, params } = await (0, import_ethers2.resolveProperties)({
257
313
  network: this.getNetwork(),
258
314
  params: this._perform({ method: "getLogs", filter })
259
315
  });
@@ -262,17 +318,17 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends import_et
262
318
  };
263
319
 
264
320
  // src/sdInterface.ts
265
- var import_debug = __toESM(require("debug"));
266
- var import_ethers2 = require("ethers");
267
- var debugLog = (0, import_debug.default)(DEBUG_NAMESPACE);
268
- var SDInterface = class extends import_ethers2.Interface {
321
+ var import_debug2 = __toESM(require("debug"));
322
+ var import_ethers3 = require("ethers");
323
+ var debugLog = (0, import_debug2.default)(DEBUG_NAMESPACE);
324
+ var SDInterface = class extends import_ethers3.Interface {
269
325
  /**
270
326
  * Extends the parseLog method to handle PrivateEvent logs
271
327
  * @param log - The log to parse
272
328
  * @returns The parsed log description with additional private event details if applicable
273
329
  */
274
- parseLog(log) {
275
- const parsedLog = super.parseLog(log);
330
+ parseLog(log2) {
331
+ const parsedLog = super.parseLog(log2);
276
332
  if (!parsedLog) {
277
333
  debugLog(
278
334
  "Failed to parse log - no matching event found or event is anonymous"
package/dist/index.mjs CHANGED
@@ -2,14 +2,17 @@
2
2
  var DEBUG_NAMESPACE = "silentdata:ethers-provider";
3
3
 
4
4
  // src/provider.ts
5
+ import debug from "debug";
5
6
  import {
6
7
  calculateEventTypeHash,
7
8
  ChainId,
9
+ DEBUG_NAMESPACE as DEBUG_NAMESPACE2,
8
10
  HEADER_DELEGATE,
9
11
  HEADER_DELEGATE_SIGNATURE,
10
12
  HEADER_EIP712_DELEGATE_SIGNATURE,
11
13
  HEADER_EIP712_SIGNATURE,
12
14
  HEADER_SIGNATURE,
15
+ HEADER_SIGNER_SWC,
13
16
  HEADER_TIMESTAMP,
14
17
  isSignableContractCall,
15
18
  NetworkName,
@@ -26,6 +29,57 @@ import {
26
29
  resolveProperties,
27
30
  Wallet
28
31
  } from "ethers";
32
+
33
+ // src/signer.ts
34
+ import {
35
+ AbstractSigner,
36
+ assert
37
+ } from "ethers";
38
+ var SilentDataRollupSigner = class extends AbstractSigner {
39
+ constructor(provider, signer) {
40
+ if (!provider) {
41
+ throw new Error("Provider is required");
42
+ }
43
+ if (!signer) {
44
+ throw new Error("Signer is required");
45
+ }
46
+ super(provider);
47
+ this.signer = signer;
48
+ }
49
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
50
+ connect(provider) {
51
+ assert(
52
+ false,
53
+ "cannot reconnect SilentDataRollupSigner",
54
+ "UNSUPPORTED_OPERATION",
55
+ {
56
+ operation: "signer.connect"
57
+ }
58
+ );
59
+ }
60
+ async getAddress() {
61
+ return this.signer.getAddress();
62
+ }
63
+ async signTransaction(tx) {
64
+ return this.signer.signTransaction(tx);
65
+ }
66
+ async signMessage(message) {
67
+ return this.signer.signMessage(message);
68
+ }
69
+ signTypedData(domain, types, value) {
70
+ return this.signer.signTypedData(domain, types, value);
71
+ }
72
+ async sendTransaction(tx) {
73
+ let gasLimit = tx.gasLimit;
74
+ if (!gasLimit) {
75
+ gasLimit = await this.estimateGas(tx);
76
+ }
77
+ return this.signer.sendTransaction({ ...tx, gasLimit });
78
+ }
79
+ };
80
+
81
+ // src/provider.ts
82
+ var log = debug(DEBUG_NAMESPACE2);
29
83
  function isPromise(value) {
30
84
  return value && typeof value.then === "function";
31
85
  }
@@ -68,7 +122,7 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends JsonRpcPr
68
122
  try {
69
123
  this.signer = config.signer.connect(this);
70
124
  } catch {
71
- this.signer = config.signer;
125
+ this.signer = new SilentDataRollupSigner(this, config.signer);
72
126
  }
73
127
  } else {
74
128
  const wallet = new Wallet(config.privateKey);
@@ -79,6 +133,9 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends JsonRpcPr
79
133
  if (Array.isArray(payload)) {
80
134
  throw new Error("Batch requests are not currently supported");
81
135
  }
136
+ if (["eth_getBlockByNumber", "eth_getBlockByHash"].includes(payload.method) && Array.isArray(payload.params) && payload.params.length > 1) {
137
+ payload.params[1] = false;
138
+ }
82
139
  const isEthCallOrEstimateGas = payload.method === "eth_call" || payload.method === "eth_estimateGas";
83
140
  if (isEthCallOrEstimateGas && Array.isArray(payload.params)) {
84
141
  const txParams = payload.params[0];
@@ -119,6 +176,10 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends JsonRpcPr
119
176
  );
120
177
  }
121
178
  }
179
+ if (this.config.smartWalletAddress) {
180
+ log("Setting smart wallet header:", this.config.smartWalletAddress);
181
+ request.setHeader(HEADER_SIGNER_SWC, this.config.smartWalletAddress);
182
+ }
122
183
  const {
123
184
  [HEADER_TIMESTAMP]: xTimestamp,
124
185
  [HEADER_SIGNATURE]: xSignature,
@@ -246,17 +307,17 @@ var SilentDataRollupProvider = class _SilentDataRollupProvider extends JsonRpcPr
246
307
  };
247
308
 
248
309
  // src/sdInterface.ts
249
- import debug from "debug";
310
+ import debug2 from "debug";
250
311
  import { Interface } from "ethers";
251
- var debugLog = debug(DEBUG_NAMESPACE);
312
+ var debugLog = debug2(DEBUG_NAMESPACE);
252
313
  var SDInterface = class extends Interface {
253
314
  /**
254
315
  * Extends the parseLog method to handle PrivateEvent logs
255
316
  * @param log - The log to parse
256
317
  * @returns The parsed log description with additional private event details if applicable
257
318
  */
258
- parseLog(log) {
259
- const parsedLog = super.parseLog(log);
319
+ parseLog(log2) {
320
+ const parsedLog = super.parseLog(log2);
260
321
  if (!parsedLog) {
261
322
  debugLog(
262
323
  "Failed to parse log - no matching event found or event is anonymous"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@appliedblockchain/silentdatarollup-ethers-provider",
3
- "version": "1.0.6",
4
- "description": "Ethers.js provider for Silent Data [Rollup]",
3
+ "version": "1.0.8",
4
+ "description": "Ethers.js provider for Silent Data",
5
5
  "author": "Applied Blockchain",
6
6
  "homepage": "https://github.com/appliedblockchain/silent-data-rollup-providers#readme",
7
7
  "keywords": [
@@ -32,7 +32,7 @@
32
32
  "test": "jest"
33
33
  },
34
34
  "dependencies": {
35
- "@appliedblockchain/silentdatarollup-core": "1.0.6",
35
+ "@appliedblockchain/silentdatarollup-core": "1.0.8",
36
36
  "debug": "4.3.7",
37
37
  "ethers": "6.13.2"
38
38
  },