From 3a4f4dc9565a73711ada4a4c769e5321b5a6c2fc Mon Sep 17 00:00:00 2001 From: sophian Date: Thu, 27 Jul 2023 09:46:35 -0400 Subject: [PATCH] Query evm chain id on substrate --- onboarding-api/env-vars/altair.env | 3 +-- onboarding-api/env-vars/catalyst.env | 3 +-- onboarding-api/env-vars/demo.env | 1 - onboarding-api/env-vars/development.env | 3 +-- onboarding-api/env-vars/production.env | 3 +-- onboarding-api/src/controllers/kyb/verifyBusiness.ts | 4 ++-- onboarding-api/src/middleware/verifyAuth.ts | 2 +- onboarding-api/src/utils/centrifuge.ts | 8 +++++--- 8 files changed, 12 insertions(+), 15 deletions(-) diff --git a/onboarding-api/env-vars/altair.env b/onboarding-api/env-vars/altair.env index bdd6a93b3f..6acc781566 100644 --- a/onboarding-api/env-vars/altair.env +++ b/onboarding-api/env-vars/altair.env @@ -4,5 +4,4 @@ COLLATOR_WSS_URL=wss://fullnode.altair.centrifuge.io RELAY_WSS_URL=wss://kusama-rpc.polkadot.io INFURA_KEY=bf808e7d3d924fbeb74672d9341d0550 EVM_NETWORK=goerli -ONBOARDING_STORAGE_BUCKET=altair-onboarding-api -EVM_ON_SUBSTRATE_CHAIN_ID=2000 \ No newline at end of file +ONBOARDING_STORAGE_BUCKET=altair-onboarding-api \ No newline at end of file diff --git a/onboarding-api/env-vars/catalyst.env b/onboarding-api/env-vars/catalyst.env index e626d718d8..018a586e20 100644 --- a/onboarding-api/env-vars/catalyst.env +++ b/onboarding-api/env-vars/catalyst.env @@ -4,5 +4,4 @@ COLLATOR_WSS_URL=wss://fullnode.catalyst.cntrfg.com RELAY_WSS_URL=wss://rococo-rpc.polkadot.io INFURA_KEY=bf808e7d3d924fbeb74672d9341d0550 EVM_NETWORK=goerli -ONBOARDING_STORAGE_BUCKET=centrifuge-onboarding-api-dev -EVM_ON_SUBSTRATE_CHAIN_ID=2000 \ No newline at end of file +ONBOARDING_STORAGE_BUCKET=centrifuge-onboarding-api-dev \ No newline at end of file diff --git a/onboarding-api/env-vars/demo.env b/onboarding-api/env-vars/demo.env index cc0705d2de..38a44ff4bb 100644 --- a/onboarding-api/env-vars/demo.env +++ b/onboarding-api/env-vars/demo.env @@ -5,4 +5,3 @@ RELAY_WSS_URL=wss://fullnode-relay.demo.cntrfg.com INFURA_KEY=bf808e7d3d924fbeb74672d9341d0550 EVM_NETWORK=goerli ONBOARDING_STORAGE_BUCKET=centrifuge-onboarding-api-dev -EVM_ON_SUBSTRATE_CHAIN_ID=2000 diff --git a/onboarding-api/env-vars/development.env b/onboarding-api/env-vars/development.env index 3488a5761f..6d8ef3377b 100644 --- a/onboarding-api/env-vars/development.env +++ b/onboarding-api/env-vars/development.env @@ -4,5 +4,4 @@ COLLATOR_WSS_URL=wss://fullnode.development.cntrfg.com RELAY_WSS_URL=wss://fullnode-relay.development.cntrfg.com INFURA_KEY=bf808e7d3d924fbeb74672d9341d0550 EVM_NETWORK=goerli -ONBOARDING_STORAGE_BUCKET=centrifuge-onboarding-api-dev -EVM_ON_SUBSTRATE_CHAIN_ID=2000 \ No newline at end of file +ONBOARDING_STORAGE_BUCKET=centrifuge-onboarding-api-dev \ No newline at end of file diff --git a/onboarding-api/env-vars/production.env b/onboarding-api/env-vars/production.env index e287fdb2b6..4b1dac63da 100644 --- a/onboarding-api/env-vars/production.env +++ b/onboarding-api/env-vars/production.env @@ -4,5 +4,4 @@ COLLATOR_WSS_URL=wss://fullnode.parachain.centrifuge.io RELAY_WSS_URL=wss://rpc.polkadot.io INFURA_KEY=bf808e7d3d924fbeb74672d9341d0550 EVM_NETWORK=mainnet -ONBOARDING_STORAGE_BUCKET=centrifuge-onboarding-api -EVM_ON_SUBSTRATE_CHAIN_ID=2000 \ No newline at end of file +ONBOARDING_STORAGE_BUCKET=centrifuge-onboarding-api \ No newline at end of file diff --git a/onboarding-api/src/controllers/kyb/verifyBusiness.ts b/onboarding-api/src/controllers/kyb/verifyBusiness.ts index da5be7b927..57c5fcd16e 100644 --- a/onboarding-api/src/controllers/kyb/verifyBusiness.ts +++ b/onboarding-api/src/controllers/kyb/verifyBusiness.ts @@ -48,7 +48,7 @@ export const verifyBusinessController = async ( investorType: 'entity', address: null, kycReference: '', - manualKybReference: null, + manualKybReference: '', wallets: { evm: [], substrate: [], @@ -78,7 +78,7 @@ export const verifyBusinessController = async ( poolSteps: {}, } - if (!(jurisdictionCode in KYB_COUNTRY_CODES)) { + if (!(jurisdictionCode.slice(0, 2) in KYB_COUNTRY_CODES)) { return startManualKyb(req, res, user) } diff --git a/onboarding-api/src/middleware/verifyAuth.ts b/onboarding-api/src/middleware/verifyAuth.ts index 09d9862ee6..31d6811acb 100644 --- a/onboarding-api/src/middleware/verifyAuth.ts +++ b/onboarding-api/src/middleware/verifyAuth.ts @@ -20,7 +20,7 @@ export const verifyAuth = async (req: Request, _res: Response, next: NextFunctio } if ( (network.includes('evm') && !isAddress(address)) || - (network === 'substrate' && !getValidSubstrateAddress({ address, network })) + (network === 'substrate' && !(await getValidSubstrateAddress({ address, network }))) ) { throw new HttpError(401, 'Invalid address') } diff --git a/onboarding-api/src/utils/centrifuge.ts b/onboarding-api/src/utils/centrifuge.ts index 47221d163c..3465b9b452 100644 --- a/onboarding-api/src/utils/centrifuge.ts +++ b/onboarding-api/src/utils/centrifuge.ts @@ -44,7 +44,7 @@ export const addCentInvestorToMemberList = async (wallet: Request['wallet'], poo const cent = getCentrifuge() const api = cent.getApi() const { metadata } = await getPoolById(poolId) - const walletAddress = getValidSubstrateAddress(wallet) + const walletAddress = await getValidSubstrateAddress(wallet) const hasPodReadAccess = (await firstValueFrom(cent.pools.getPoolPermissions([poolId])))?.[ walletAddress @@ -173,10 +173,12 @@ export const checkBalanceBeforeSigningRemark = async (wallet: Request['wallet']) } // https://polkadot.js.org/docs/util-crypto/examples/validate-address/ -export const getValidSubstrateAddress = (wallet: Request['wallet']) => { +export const getValidSubstrateAddress = async (wallet: Request['wallet']) => { try { if (wallet.network === 'evmOnSubstrate') { - return evmToSubstrateAddress(wallet.address, Number(process.env.EVM_ON_SUBSTRATE_CHAIN_ID)) + const cent = getCentrifuge() + const chainId = await firstValueFrom(cent.getApi().pipe(switchMap((api) => api.query.evmChainId.chainId()))) + return cent.utils.formatAddress(evmToSubstrateAddress(wallet.address, Number(chainId.toString()))) } const validAddress = encodeAddress( isHex(wallet.address) ? hexToU8a(wallet.address) : decodeAddress(wallet.address),