import { base64ToHex , extractAttestationCodeFromMessage , getIdentifierPrefix , hashIdentifier as baseHashIdentifier , IdentifierType , isAccountConsideredVerified , messageContainsAttestationCode , sanitizeMessageBase64 , } from '@celo/base/lib/attestations' ; import { soliditySha3 } from 'web3-utils' ; import { privateKeyToAddress } from './address' ; import { Signature , SignatureUtils } from './signatureUtils' ; export { AttestationsStatus , base64ToHex , extractAttestationCodeFromMessage , getIdentifierPrefix , IdentifierType , isAccountConsideredVerified , messageContainsAttestationCode , sanitizeMessageBase64 , } from '@celo/base/lib/attestations' ; const sha3 = ( v ) : string | null => soliditySha3 ( { type : 'string' , value : v } ) ; export function hashIdentifier ( identifier , type , salt ? ) { return baseHashIdentifier ( sha3 , identifier , type , salt ) ; } export function getAttestationMessageToSignFromIdentifier ( identifier , account ) { const messageHash = soliditySha3 ( { type : 'bytes32' , value : identifier } , { type : 'address' , value : account } ) ! ; return messageHash ; } export function getAttestationMessageToSignFromPhoneNumber ( phoneNumber , account , phoneSalt ? ) { return getAttestationMessageToSignFromIdentifier ( hashIdentifier ( phoneNumber , IdentifierType . PHONE_NUMBER , phoneSalt ) , account ) ; } export function attestToIdentifier ( identifier , account , privateKey ) { const issuer = privateKeyToAddress ( privateKey ) ; const { v , r , s } = SignatureUtils . signMessage ( getAttestationMessageToSignFromIdentifier ( identifier , account ) , privateKey , issuer ) ; return { v , r , s } ; } export function extractSecurityCodeWithPrefix ( message ) { const matches = message . match ( '(\\d{8})' ) ; if ( matches && matches . length === 2 ) { return matches [ 1 ] ; } return null ; } export const AttestationUtils = { IdentifierType , getIdentifierPrefix , hashIdentifier , getAttestationMessageToSignFromIdentifier , getAttestationMessageToSignFromPhoneNumber , base64ToHex , attestToIdentifier , sanitizeMessageBase64 , messageContainsAttestationCode , extractAttestationCodeFromMessage , isAccountConsideredVerified , extractSecurityCodeWithPrefix } ;