import { verify } from '@chainsafe/bls' ; import { DepositKeyInterface } from '../store/reducers' ; import { DOMAIN_DEPOSIT , EMPTY_ROOT , GENESIS_FORK_VERSION } from './envVars' ; import { bufferHex , ForkData , SigningData } from './SSZ' ; const computeForkDataRoot = ( currentVersion , genesisValidatorsRoot ) : Uint8Array => { const forkData = { currentVersion : currentVersion as Uint8Array , genesisValidatorsRoot , } ; return ForkData . hashTreeRoot ( forkData ) ; } ; const computeDomain = ( domainType , forkVersion = GENESIS_FORK_VERSION , genesisValidatorsRoot = EMPTY_ROOT ) : Uint8Array => { const forkDataRoot = computeForkDataRoot ( forkVersion as Uint8Array , genesisValidatorsRoot ) ; const domain = new Uint8Array ( 32 ) ; domain . set ( domainType ) ; domain . set ( forkDataRoot . subarray ( 0 , 28 ) , 4 ) ; return domain ; } ; const computeSigningRoot = ( sszObjectRoot , domain ) : Uint8Array => { const signingData = { objectRoot : sszObjectRoot , domain , } ; return SigningData . hashTreeRoot ( signingData ) ; } ; export const verifySignature = ( depositDatum ) : boolean => { const pubkeyBuffer = bufferHex ( depositDatum . pubkey ) ; const signatureBuffer = bufferHex ( depositDatum . signature ) ; const depositMessageBuffer = bufferHex ( depositDatum . deposit_message_root ) ; const domain = computeDomain ( DOMAIN_DEPOSIT ) ; const signingRoot = computeSigningRoot ( depositMessageBuffer , domain ) ; return verify ( pubkeyBuffer , signingRoot , signatureBuffer ) ; } ;