UNPKG

crypto-wallet-core

Version:

A multi-currency support library for address derivation, private key creation, and transaction creation

30 lines (24 loc) 760 B
import { IValidation } from '..'; const utils = require('web3-utils'); export class EthValidation implements IValidation { regex: RegExp; constructor() { this.regex = /ethereum/i; } validateAddress(_network: string, address: string): boolean { return utils.isAddress(address); } validateUri(addressUri: string): boolean { if (!addressUri) { return false; } const address = this.extractAddress(addressUri); const prefix = this.regex.exec(addressUri); return !!prefix && utils.isAddress(address); } protected extractAddress(data) { const prefix = /^[a-z]+:/i; const params = /([\?\&](value|gas|gasPrice|gasLimit)=(\d+([\,\.]\d+)?))+/i; return data.replace(prefix, '').replace(params, ''); } }