1- import { cryptoWaitReady , decodeAddress , signatureVerify } from '@polkadot/util-crypto' ;
2- import { u8aToHex } from '@polkadot/util' ;
1+ import {
2+ cryptoWaitReady ,
3+ decodeAddress ,
4+ evmToAddress ,
5+ isEthereumAddress ,
6+ signatureVerify ,
7+ } from '@polkadot/util-crypto' ;
8+ import { stringToU8a , u8aToHex } from '@polkadot/util' ;
39import { inject , injectable } from 'inversify' ;
410import { IApiFactory } from '../client/ApiFactory' ;
511import { ContainerTypes } from '../containertypes' ;
612import { DappItem , NewDappItem } from '../models/Dapp' ;
713import { NetworkType } from '../networks' ;
814import { DappsStakingService , IDappsStakingService } from './DappsStakingService' ;
915import { IFirebaseService } from './FirebaseService' ;
16+ import { ethers } from 'ethers' ;
17+ import { ASTAR_SS58_FORMAT } from './TxQueryService' ;
1018
1119@injectable ( )
1220/**
@@ -56,10 +64,19 @@ export class DappsStakingService2 extends DappsStakingService implements IDappsS
5664 network : NetworkType ,
5765 ) : Promise < boolean > {
5866 const api = this . _apiFactory . getApiInstance ( network ) ;
67+ const isEvmSigner = isEthereumAddress ( senderAddress ) ;
68+ const ss58SenderAddress = isEvmSigner ? evmToAddress ( senderAddress , ASTAR_SS58_FORMAT ) : senderAddress ;
5969
6070 // Build signed payload and check signature
61- const signedMessage = await api . getRegisterDappPayload ( dappAddress , senderAddress ) ;
62- const isValidSignature = await this . isValidSignature ( signedMessage , signature , senderAddress ) ;
71+ const messageToVerify = await api . getRegisterDappPayload ( dappAddress , ss58SenderAddress ) ;
72+ let isValidSignature = false ;
73+
74+ if ( isEvmSigner ) {
75+ const signerAddress = ethers . verifyMessage ( messageToVerify , signature ) ;
76+ isValidSignature = signerAddress . toLowerCase ( ) === senderAddress . toLowerCase ( ) ;
77+ } else {
78+ isValidSignature = await this . isValidSignature ( messageToVerify , signature , senderAddress ) ;
79+ }
6380
6481 if ( isValidSignature ) {
6582 // Check if dapp and sender are already registered to a node.
@@ -69,7 +86,7 @@ export class DappsStakingService2 extends DappsStakingService implements IDappsS
6986 if ( registeredDapp ) {
7087 return (
7188 registeredDapp . state . toString ( ) === 'Registered' &&
72- registeredDapp . developer . toString ( ) === senderAddress
89+ registeredDapp . developer . toString ( ) === ss58SenderAddress
7390 ) ;
7491 } else {
7592 throw new Error ( `The dapp ${ dappAddress } is not registered with developer account ${ senderAddress } ` ) ;
0 commit comments