import { createUnitConverters } from '@bitaccess/coinlib-common' ; import { DECIMAL_PLACES , XPRV_REGEX , XPUB_REGEX , ADDRESS_REGEX , EXTRA_ID_REGEX } from './constants' ; import { isNil } from '@faast/ts-common' ; const { toMainDenominationBigNumber , toMainDenominationString , toMainDenominationNumber , toBaseDenominationBigNumber , toBaseDenominationString , toBaseDenominationNumber , } = createUnitConverters ( DECIMAL_PLACES ) ; export { toMainDenominationBigNumber , toMainDenominationString , toMainDenominationNumber , toBaseDenominationBigNumber , toBaseDenominationString , toBaseDenominationNumber , } ; export function isValidXprv ( xprv ) { return typeof xprv === 'string' && XPRV_REGEX . test ( xprv ) ; } export function isValidXpub ( xpub ) { return typeof xpub === 'string' && XPUB_REGEX . test ( xpub ) ; } export function isValidAddress ( address ) { return typeof address === 'string' && ADDRESS_REGEX . test ( address ) ; } export function isValidExtraId ( extraId ) { return typeof extraId === 'string' && EXTRA_ID_REGEX . test ( extraId ) ; } export function assertValidAddress ( address ) { if ( ! isValidAddress ( address ) ) { throw new Error ( `Invalid ripple address: ${ address }` ) ; } } export function assertValidExtraId ( extraId ) { if ( ! isValidExtraId ( extraId ) ) { throw new Error ( `Invalid ripple extraId: ${ extraId }` ) ; } } export function assertValidExtraIdOrNil ( extraId ? ) { if ( ! isNil ( extraId ) && ! isValidExtraId ( extraId ) ) { throw new Error ( `Invalid ripple extraId: ${ extraId }` ) ; } }