Skip to content

Commit

Permalink
Query evm chain id on substrate
Browse files Browse the repository at this point in the history
  • Loading branch information
sophialittlejohn committed Jul 27, 2023
1 parent 3c784f2 commit 3a4f4dc
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions onboarding-api/env-vars/altair.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
ONBOARDING_STORAGE_BUCKET=altair-onboarding-api
3 changes: 1 addition & 2 deletions onboarding-api/env-vars/catalyst.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
ONBOARDING_STORAGE_BUCKET=centrifuge-onboarding-api-dev
1 change: 0 additions & 1 deletion onboarding-api/env-vars/demo.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions onboarding-api/env-vars/development.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
ONBOARDING_STORAGE_BUCKET=centrifuge-onboarding-api-dev
3 changes: 1 addition & 2 deletions onboarding-api/env-vars/production.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
ONBOARDING_STORAGE_BUCKET=centrifuge-onboarding-api
4 changes: 2 additions & 2 deletions onboarding-api/src/controllers/kyb/verifyBusiness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const verifyBusinessController = async (
investorType: 'entity',
address: null,
kycReference: '',
manualKybReference: null,
manualKybReference: '',
wallets: {
evm: [],
substrate: [],
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion onboarding-api/src/middleware/verifyAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
8 changes: 5 additions & 3 deletions onboarding-api/src/utils/centrifuge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 3a4f4dc

Please sign in to comment.