import { URL_REGEX } from '@celo/base/lib/io' ; import { isValidPublic , toChecksumAddress } from 'ethereumjs-util' ; import { either } from 'fp-ts/lib/Either' ; import * as t from 'io-ts' ; import { isValidAddress } from './address' ; import { isE164NumberStrict } from './phoneNumbers' ; export { isValidUrl , URL_REGEX } from '@celo/base/lib/io' ; export const UrlType = new t . Type < string , string , unknown > ( 'Url' , t . string . is , ( input , context ) => either . chain ( t . string . validate ( input , context ) , ( stringValue ) => URL_REGEX . test ( stringValue ) ? t . success ( stringValue ) : t . failure ( stringValue , context , 'is not a valid url' ) ) , String ) ; export const JSONStringType = new t . Type < string , string , unknown > ( 'JSONString' , t . string . is , ( input , context ) => either . chain ( t . string . validate ( input , context ) , ( stringValue ) => { try { JSON . parse ( stringValue ) ; return t . success ( stringValue ) ; } catch ( error ) { return t . failure ( stringValue , context , 'can not be parsed as JSON' ) ; } } ) , String ) ; deprecated celo export const E164PhoneNumberType = new t . Type < string , string , unknown > ( 'E164Number' , t . string . is , ( input , context ) => either . chain ( t . string . validate ( input , context ) , ( stringValue ) => isE164NumberStrict ( stringValue ) ? t . success ( stringValue ) : t . failure ( stringValue , context , 'is not a valid e164 number' ) ) , String ) ; export const AddressType = new t . Type < string , string , unknown > ( 'Address' , t . string . is , ( input , context ) => either . chain ( t . string . validate ( input , context ) , ( stringValue ) => isValidAddress ( stringValue ) ? t . success ( toChecksumAddress ( stringValue ) ) : t . failure ( stringValue , context , 'is not a valid address' ) ) , String ) ; export const PublicKeyType = new t . Type < string , string , unknown > ( 'Public Key' , t . string . is , ( input , context ) => either . chain ( t . string . validate ( input , context ) , ( stringValue ) => stringValue . startsWith ( '0x' ) && isValidPublic ( Buffer . from ( stringValue . slice ( 2 ) , 'hex' ) , true ) ? t . success ( toChecksumAddress ( stringValue ) ) : t . failure ( stringValue , context , 'is not a valid public key' ) ) , String ) ; export const SignatureType = t . string ; export const SaltType = t . string ; deprecated celo export const AttestationServiceStatusResponseType = t . type ( { status : t . literal ( 'ok' ) , smsProviders : t . array ( t . string ) , blacklistedRegionCodes : t . union ( [ t . array ( t . string ) , t . undefined ] ) , accountAddress : AddressType , signature : t . union ( [ SignatureType , t . undefined ] ) , version : t . string , latestBlock : t . number , ageOfLatestBlock : t . number , isNodeSyncing : t . boolean , appSignature : t . string , smsProvidersRandomized : t . boolean , maxDeliveryAttempts : t . number , maxRerequestMins : t . number , twilioVerifySidProvided : t . boolean } ) ; deprecated celo export const AttestationServiceTestRequestType = t . type ( { phoneNumber : E164PhoneNumberType , message : t . string , signature : SignatureType , provider : t . union ( [ t . string , t . undefined ] ) } ) ; deprecated celo export type AttestationServiceTestRequest = t . TypeOf < typeof AttestationServiceTestRequestType > ; export type Signature = t . TypeOf < typeof SignatureType > ; export type Address = t . TypeOf < typeof AddressType > ; deprecated celo export type E164Number = t . TypeOf < typeof E164PhoneNumberType > ; deprecated celo export const AttestationRequestType = t . type ( { phoneNumber : E164PhoneNumberType , account : AddressType , issuer : AddressType , salt : t . union ( [ t . undefined , SaltType ] ) , smsRetrieverAppSig : t . union ( [ t . undefined , t . string ] ) , securityCodePrefix : t . union ( [ t . undefined , t . string ] ) , language : t . union ( [ t . undefined , t . string ] ) } ) ; deprecated celo export type AttestationRequest = t . TypeOf < typeof AttestationRequestType > ; deprecated celo export const GetAttestationRequestType = t . type ( { phoneNumber : E164PhoneNumberType , account : AddressType , issuer : AddressType , salt : t . union ( [ t . undefined , SaltType ] ) , securityCode : t . union ( [ t . undefined , t . string ] ) } ) ; deprecated celo export type GetAttestationRequest = t . TypeOf < typeof GetAttestationRequestType > ; export const AttestationResponseType = t . type ( { success : t . boolean , error : t . union ( [ t . undefined , t . string ] ) , errors : t . union ( [ t . undefined , t . string ] ) , provider : t . union ( [ t . undefined , t . string ] ) , identifier : t . union ( [ t . undefined , t . string ] ) , account : t . union ( [ t . undefined , AddressType ] ) , issuer : t . union ( [ t . undefined , AddressType ] ) , status : t . union ( [ t . undefined , t . string ] ) , attempt : t . union ( [ t . undefined , t . number ] ) , countryCode : t . union ( [ t . undefined , t . string ] ) , duration : t . union ( [ t . undefined , t . number ] ) , salt : t . union ( [ t . undefined , t . string ] ) , attestationCode : t . union ( [ t . undefined , t . string ] ) } ) ; export type AttestationResponse = t . TypeOf < typeof AttestationResponseType > ;