From dc9af6eaff606cd3239779e7b563befe06464ca9 Mon Sep 17 00:00:00 2001 From: Francisco Tobar Date: Tue, 13 Feb 2024 13:38:59 -0600 Subject: [PATCH] refactor: allowed destinations --- Readme.md | 1 - config/default.json5 | 1 - package-lock.json | 99 ++++++++++++++++++++-------------- src/RelayServer.ts | 3 -- src/ServerConfigParams.ts | 1 - src/relayServerUtils.ts | 14 ----- src/serverConfigParamsUtils.ts | 1 - 7 files changed, 59 insertions(+), 61 deletions(-) diff --git a/Readme.md b/Readme.md index dc16826..6bb462a 100644 --- a/Readme.md +++ b/Readme.md @@ -113,7 +113,6 @@ File [./config/default.json5](config/default.json5) contains all configuration p fixedUsdFee: 0 , sponsoredDestinations: [], - allowedDestinations: [], requestMinValidSeconds: 43200, }, diff --git a/config/default.json5 b/config/default.json5 index 63ef2ba..daf92d3 100644 --- a/config/default.json5 +++ b/config/default.json5 @@ -51,7 +51,6 @@ fixedUsdFee: 0 , sponsoredDestinations: [], - allowedDestinations: [], requestMinValidSeconds: 43200, }, diff --git a/package-lock.json b/package-lock.json index bfded9b..f6c8b97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2240,7 +2240,7 @@ }, "node_modules/@rsksmart/rif-relay-client": { "version": "2.1.0", - "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#987434ae5a4932ac1aecd66f15c261f0af733a57", + "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#93c7149a7e455c23a44c26f29d97ffbb8195d523", "license": "MIT", "dependencies": { "bignumber.js": "^9.1.1", @@ -2267,7 +2267,7 @@ }, "node_modules/@rsksmart/rif-relay-contracts": { "version": "2.0.0-beta.1", - "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-contracts.git#5f164560512301319f5a41aa80a8dfb3ab3d4ad2", + "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-contracts.git#93c1e5337beb796d018f4940fe2ad178a8064f20", "license": "MIT", "dependencies": { "@metamask/eth-sig-util": "^4.0.1", @@ -4015,14 +4015,15 @@ } }, "node_modules/call-bind": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.6.tgz", - "integrity": "sha512-Mj50FLHtlsoVfRfnHaZvyrooHcrlceNZdL/QBvJJVd9Ta55qCQK0gs4ss2oZDeV9zFCs6ewzYgVE5yfVmfFpVg==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", "dependencies": { + "es-define-property": "^1.0.0", "es-errors": "^1.3.0", "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.3", - "set-function-length": "^1.2.0" + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" }, "engines": { "node": ">= 0.4" @@ -5006,14 +5007,13 @@ "peer": true }, "node_modules/define-data-property": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.3.tgz", - "integrity": "sha512-h3GBouC+RPtNX2N0hHVLo2ZwPYurq8mLmXpOLTsw71gr7lHt5VaI4vVkDUNOfiWmm48JEXe3VM7PmLX45AMmmg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", "dependencies": { + "es-define-property": "^1.0.0", "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.4", - "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.1" + "gopd": "^1.0.1" }, "engines": { "node": ">= 0.4" @@ -5190,9 +5190,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.667", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.667.tgz", - "integrity": "sha512-66L3pLlWhTNVUhnmSA5+qDM3fwnXsM6KAqE36e2w4KN0g6pkEtlT5bs41FQtQwVwKnfhNBXiWRLPs30HSxd7Kw==" + "version": "1.4.668", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.668.tgz", + "integrity": "sha512-ZOBocMYCehr9W31+GpMclR+KBaDZOoAEabLdhpZ8oU1JFDwIaFY0UDbpXVEUFc0BIP2O2Qn3rkfCjQmMR4T/bQ==" }, "node_modules/elliptic": { "version": "6.5.4", @@ -5311,6 +5311,17 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es-errors": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", @@ -7176,11 +7187,11 @@ } }, "node_modules/has-property-descriptors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz", - "integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", "dependencies": { - "get-intrinsic": "^1.2.2" + "es-define-property": "^1.0.0" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -13989,7 +14000,7 @@ "integrity": "sha512-z0zMCjyhhp4y7XKAcDAi3Vgms4T2PstwBdahiO0+9NaGICQKjynK3wduSRplTgk4LXmoO1yfDGO5RbjKYxtuxA==" }, "@rsksmart/rif-relay-client": { - "version": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#987434ae5a4932ac1aecd66f15c261f0af733a57", + "version": "git+ssh://git@github.com/rsksmart/rif-relay-client.git#93c7149a7e455c23a44c26f29d97ffbb8195d523", "from": "@rsksmart/rif-relay-client@github:rsksmart/rif-relay-client#PP-885/explore-solution-b2", "requires": { "bignumber.js": "^9.1.1", @@ -14006,7 +14017,7 @@ } }, "@rsksmart/rif-relay-contracts": { - "version": "git+ssh://git@github.com/rsksmart/rif-relay-contracts.git#5f164560512301319f5a41aa80a8dfb3ab3d4ad2", + "version": "git+ssh://git@github.com/rsksmart/rif-relay-contracts.git#93c1e5337beb796d018f4940fe2ad178a8064f20", "from": "@rsksmart/rif-relay-contracts@github:rsksmart/rif-relay-contracts#PP-885/explore-solution-b2", "requires": { "@metamask/eth-sig-util": "^4.0.1", @@ -15462,14 +15473,15 @@ "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==" }, "call-bind": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.6.tgz", - "integrity": "sha512-Mj50FLHtlsoVfRfnHaZvyrooHcrlceNZdL/QBvJJVd9Ta55qCQK0gs4ss2oZDeV9zFCs6ewzYgVE5yfVmfFpVg==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", "requires": { + "es-define-property": "^1.0.0", "es-errors": "^1.3.0", "function-bind": "^1.1.2", - "get-intrinsic": "^1.2.3", - "set-function-length": "^1.2.0" + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" } }, "call-me-maybe": { @@ -16181,14 +16193,13 @@ "peer": true }, "define-data-property": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.3.tgz", - "integrity": "sha512-h3GBouC+RPtNX2N0hHVLo2ZwPYurq8mLmXpOLTsw71gr7lHt5VaI4vVkDUNOfiWmm48JEXe3VM7PmLX45AMmmg==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", "requires": { + "es-define-property": "^1.0.0", "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.4", - "gopd": "^1.0.1", - "has-property-descriptors": "^1.0.1" + "gopd": "^1.0.1" } }, "delayed-stream": { @@ -16316,9 +16327,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "electron-to-chromium": { - "version": "1.4.667", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.667.tgz", - "integrity": "sha512-66L3pLlWhTNVUhnmSA5+qDM3fwnXsM6KAqE36e2w4KN0g6pkEtlT5bs41FQtQwVwKnfhNBXiWRLPs30HSxd7Kw==" + "version": "1.4.668", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.668.tgz", + "integrity": "sha512-ZOBocMYCehr9W31+GpMclR+KBaDZOoAEabLdhpZ8oU1JFDwIaFY0UDbpXVEUFc0BIP2O2Qn3rkfCjQmMR4T/bQ==" }, "elliptic": { "version": "6.5.4", @@ -16417,6 +16428,14 @@ "is-arrayish": "^0.2.1" } }, + "es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "requires": { + "get-intrinsic": "^1.2.4" + } + }, "es-errors": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", @@ -17833,11 +17852,11 @@ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" }, "has-property-descriptors": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz", - "integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", "requires": { - "get-intrinsic": "^1.2.2" + "es-define-property": "^1.0.0" } }, "has-proto": { diff --git a/src/RelayServer.ts b/src/RelayServer.ts index d826e58..a548f42 100644 --- a/src/RelayServer.ts +++ b/src/RelayServer.ts @@ -61,7 +61,6 @@ import { convertGasToTokenAndNative, calculateFee, validateExpirationTime, - isDestinationAllowed, } from './relayServerUtils'; import { getPastEventsForHub } from './getPastEventsForHub'; import type { PastEventOptions } from './definitions'; @@ -295,8 +294,6 @@ export class RelayServer extends EventEmitter { relayRequest.request.validUntilTime, requestMinValidSeconds ); - - await isDestinationAllowed(relayRequest, this.config.app); } async validateVerifier( diff --git a/src/ServerConfigParams.ts b/src/ServerConfigParams.ts index 511956d..2a81c81 100644 --- a/src/ServerConfigParams.ts +++ b/src/ServerConfigParams.ts @@ -21,7 +21,6 @@ type AppConfig = { gasFeePercentage: number; disableSponsoredTx: boolean; sponsoredDestinations: Array; - allowedDestinations: Array; requestMinValidSeconds: number; transferFeePercentage: number; fixedUsdFee: number; diff --git a/src/relayServerUtils.ts b/src/relayServerUtils.ts index c4431c9..80b726e 100644 --- a/src/relayServerUtils.ts +++ b/src/relayServerUtils.ts @@ -176,19 +176,6 @@ async function isSponsorshipAllowed( ); } -async function isDestinationAllowed( - envelopingRequest: EnvelopingRequest, - config: AppConfig -): Promise { - const { allowedDestinations } = config; - - const to = await envelopingRequest.request.to; - - if (to != constants.AddressZero && !allowedDestinations.includes(to)) { - throw new Error('Destination contract is not allowed'); - } -} - function getMethodHashFromData(data: string) { return data.substring(2, 10); } @@ -413,7 +400,6 @@ export { calculateFee, convertGasToTokenAndNative, isSponsorshipAllowed, - isDestinationAllowed, TRANSFER_HASH, TRANSFER_FROM_HASH, validateExpirationTime, diff --git a/src/serverConfigParamsUtils.ts b/src/serverConfigParamsUtils.ts index c158b97..152303f 100644 --- a/src/serverConfigParamsUtils.ts +++ b/src/serverConfigParamsUtils.ts @@ -66,7 +66,6 @@ const appSchema = Joi.object({ fixedUsdFee: Joi.number().optional(), disableSponsoredTx: Joi.boolean().required(), sponsoredDestinations: Joi.array().items(Joi.string().custom(isAddress)), - allowedDestinations: Joi.array().items(Joi.string().custom(isAddress)), requestMinValidSeconds: Joi.number().min(0).required(), });