@appliedblockchain/silentdatarollup-custom-rpc 1.0.3 → 1.0.5

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -12
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -56,8 +56,9 @@ function validateRFC3339Timestamp(timestamp) {
56
56
  );
57
57
  return timestampDate >= minAllowedTime && timestampDate <= maxAllowedTime;
58
58
  }
59
- function recoverSerialSigner(message, signature) {
59
+ function recoverSerialSigner(message, signature, chainId) {
60
60
  try {
61
+ message = chainId.toString() + message;
61
62
  const messageHash = import_ethers.ethers.hashMessage(message);
62
63
  const recoveredAddress = import_ethers.ethers.recoverAddress(messageHash, signature);
63
64
  return recoveredAddress;
@@ -65,9 +66,9 @@ function recoverSerialSigner(message, signature) {
65
66
  return null;
66
67
  }
67
68
  }
68
- function recoverTypedSigner(data, signature) {
69
+ function recoverTypedSigner(data, signature, chainId) {
69
70
  try {
70
- const domain = import_silentdatarollup_core.eip721Domain;
71
+ const domain = { ...import_silentdatarollup_core.eip721Domain, chainId };
71
72
  const types = {
72
73
  Request: [
73
74
  { name: "method", type: "string" },
@@ -86,7 +87,7 @@ function recoverTypedSigner(data, signature) {
86
87
  return null;
87
88
  }
88
89
  }
89
- function recoverSignerWithDelegate(delegateTicket, delegateSignature, message, isEIP712) {
90
+ function recoverSignerWithDelegate(delegateTicket, delegateSignature, message, isEIP712, chainId) {
90
91
  try {
91
92
  const ticket = JSON.parse(delegateTicket);
92
93
  if (!ticket.expires || !ticket.ephemeralAddress) {
@@ -103,9 +104,9 @@ function recoverSignerWithDelegate(delegateTicket, delegateSignature, message, i
103
104
  params: JSON.stringify(JSON.parse(message).params),
104
105
  timestamp: ticket.timestamp
105
106
  };
106
- delegateAddress = recoverTypedSigner(data, delegateSignature);
107
+ delegateAddress = recoverTypedSigner(data, delegateSignature, chainId);
107
108
  } else {
108
- delegateAddress = recoverSerialSigner(message, delegateSignature);
109
+ delegateAddress = recoverSerialSigner(message, delegateSignature, chainId);
109
110
  }
110
111
  if (!delegateAddress || delegateAddress.toLowerCase() !== ticket.ephemeralAddress.toLowerCase()) {
111
112
  return null;
@@ -115,7 +116,7 @@ function recoverSignerWithDelegate(delegateTicket, delegateSignature, message, i
115
116
  ephemeralAddress: ticket.ephemeralAddress
116
117
  };
117
118
  const delegatorAddress = import_ethers.ethers.verifyTypedData(
118
- import_silentdatarollup_core.eip721Domain,
119
+ { ...import_silentdatarollup_core.eip721Domain, chainId },
119
120
  import_silentdatarollup_core.delegateEIP721Types,
120
121
  ticketData,
121
122
  ticket.signature
@@ -128,7 +129,7 @@ function recoverSignerWithDelegate(delegateTicket, delegateSignature, message, i
128
129
  return null;
129
130
  }
130
131
  }
131
- function recoverSigner(headers, body) {
132
+ function recoverSigner(headers, body, chainId) {
132
133
  const timestamp = headers[import_silentdatarollup_core.HEADER_TIMESTAMP];
133
134
  if (!timestamp) {
134
135
  return null;
@@ -149,13 +150,14 @@ function recoverSigner(headers, body) {
149
150
  delegateTicket,
150
151
  delegateSignature || eip712DelegateSignature || "",
151
152
  body,
152
- !!eip712DelegateSignature
153
+ !!eip712DelegateSignature,
154
+ chainId
153
155
  );
154
156
  return result ? result.delegator : null;
155
157
  }
156
158
  if (signature) {
157
159
  const message = `${body}${timestamp}`;
158
- return recoverSerialSigner(message, signature);
160
+ return recoverSerialSigner(message, signature, chainId);
159
161
  }
160
162
  if (eip712Signature) {
161
163
  try {
@@ -165,7 +167,7 @@ function recoverSigner(headers, body) {
165
167
  params: JSON.stringify(parsedBody.params),
166
168
  timestamp
167
169
  };
168
- return recoverTypedSigner(data, eip712Signature);
170
+ return recoverTypedSigner(data, eip712Signature, chainId);
169
171
  } catch {
170
172
  return null;
171
173
  }
@@ -393,9 +395,11 @@ function createRpcValidationMiddleware(provider2) {
393
395
  next();
394
396
  return;
395
397
  }
398
+ const { chainId } = await provider2.getNetwork();
396
399
  const signer = recoverSigner(
397
400
  req.headers,
398
- bodyString
401
+ bodyString,
402
+ chainId
399
403
  );
400
404
  if (["eth_getTransactionByHash", "eth_getTransactionReceipt"].includes(method)) {
401
405
  const transaction = await validateTransactionMethod(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appliedblockchain/silentdatarollup-custom-rpc",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Custom RPC for Silent Data [Rollup]",
5
5
  "author": "Applied Blockchain",
6
6
  "homepage": "https://github.com/appliedblockchain/silent-data-rollup-providers#readme",
@@ -19,13 +19,13 @@
19
19
  ],
20
20
  "bin": "dist/index.js",
21
21
  "scripts": {
22
- "build": "tsup src/index.ts --format cjs --clean",
22
+ "build": "tsc --noEmit && tsup src/index.ts --format cjs --clean",
23
23
  "check-exports": "attw --pack . --profile node16",
24
24
  "dev": "concurrently --kill-others-on-fail -s all -p '[{name}]' -n 'HARDHAT,CUSTOM RPC' -c 'bgGreen.bold,bgBlue.bold' 'hardhat node' 'nodemon'",
25
25
  "prepack": "npm run build"
26
26
  },
27
27
  "dependencies": {
28
- "@appliedblockchain/silentdatarollup-core": "1.0.3",
28
+ "@appliedblockchain/silentdatarollup-core": "1.0.5",
29
29
  "body-parser": "1.20.3",
30
30
  "dotenv": "16.4.7",
31
31
  "ethers": "6.13.2",