UNPKG

@colony/purser-core

Version:

A collection of helpers, utils, validators and normalizers to assist the individual purser modules

192 lines (173 loc) 3.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.REQUIRED_PROPS = exports.HARDFORKS = exports.NETWORK_NAMES = exports.CHAIN_IDS = exports.HTTPS_PROTOCOL = exports.SIGNATURE = exports.TRANSACTION = exports.DESCRIPTORS = exports.GWEI_MINIFICATION = exports.WEI_MINIFICATION = exports.HEX_HASH_TYPE = exports.UNDEFINED = exports.SPLITTER = exports.MATCH = exports.PATH = exports.ENV = void 0; /* * Build environment */ var ENV = process && undefined || 'development'; exports.ENV = ENV; var PATH = { /* * Ethereum HD Wallet Bip32 Derivation path * * See the ongoing standardization discussions: * https://github.com/ethereum/EIPs/issues/84 */ /* * The default (and only one that is correct, as far as I know of) header key */ HEADER_KEY: 'm', /* * Ethereum reserved purpouse */ PURPOSE: 44, /* * ETH coin type is 60 for main net, and 1 for test nets */ COIN_MAINNET: 60, COIN_TESTNET: 1, ACCOUNT: 0, CHANGE: 0, /* * First address index */ INDEX: 0, /* * Characters seqeunce used as a deviation path delimiter */ DELIMITER: "'/" }; /* * Regex to use when validating strings */ exports.PATH = PATH; var MATCH = { DIGITS: /^\d+$/, ADDRESS: /^(0x)?([0-9a-fA-F]{40})$/, /* * Just like the address above, but without the character number limit */ HEX_STRING: /^(0x)?([0-9a-fA-F]*)$/, URL: /^.+:\/\/[^‌​/]+/ }; /* * Used to separate misc. derivation paths or urls */ exports.MATCH = MATCH; var SPLITTER = '/'; /* * Used to better inform the user when a variable doesn't have a value * (Used in Error messsages) */ exports.SPLITTER = SPLITTER; var UNDEFINED = 'undefined'; /* * Hash types */ exports.UNDEFINED = UNDEFINED; var HEX_HASH_TYPE = 'hex'; exports.HEX_HASH_TYPE = HEX_HASH_TYPE; var WEI_MINIFICATION = 1e18; exports.WEI_MINIFICATION = WEI_MINIFICATION; var GWEI_MINIFICATION = 1e9; /* * Default class descriptors. * Most likely to be used with `Object.defineProperty()` */ exports.GWEI_MINIFICATION = GWEI_MINIFICATION; var DESCRIPTORS = { GETTERS: { enumerable: true, configurable: true }, SETTERS: { enumerable: true, writable: true }, WALLET_PROPS: { enumerable: true, writable: false }, GENERIC_PROPS: { enumerable: true, writable: true, configurable: true } }; /* * Defaults for the transaction object */ exports.DESCRIPTORS = DESCRIPTORS; var TRANSACTION = { CHAIN_ID: 1, GAS_PRICE: 9000000000, // 9 Gwei GAS_LIMIT: 21000, NONCE: 0, VALUE: 0, INPUT_DATA: '' }; /* * Values used to seed the initial signature object */ exports.TRANSACTION = TRANSACTION; var SIGNATURE = { R: 0, S: 0, RECOVERY_ODD: 27, RECOVERY_EVEN: 28 }; exports.SIGNATURE = SIGNATURE; var HTTPS_PROTOCOL = 'https:'; /* * Chain IDs */ exports.HTTPS_PROTOCOL = HTTPS_PROTOCOL; var CHAIN_IDS = { HOMESTEAD: 1, ROPSTEN: 3, RINKEBY: 4, GOERLI: 5, KOVAN: 42, LOCAL: 1337 }; /* * Network names */ exports.CHAIN_IDS = CHAIN_IDS; var NETWORK_NAMES = { MAINNET: 'mainnet', ROPSTEN: 'ropsten', RINKEBY: 'rinkeby', KOVAN: 'kovan', GOERLI: 'goerli' }; /* * Hardforks */ exports.NETWORK_NAMES = NETWORK_NAMES; var HARDFORKS = { BYZANTIUM: 'byzantium', CHAINSTART: 'chainstart', CONSTANTINOPLE: 'constantinople', DAO: 'dao', HOMESTEAD: 'homestead', ISTANBUL: 'istanbul', PETERSBURG: 'petersburg', SPURIOUS_DRAGON: 'spuriousDragon', TANGERINE_WHISTLE: 'tangerineWhistle' }; /* * Prop names used to validate user input against */ exports.HARDFORKS = HARDFORKS; var REQUIRED_PROPS = { /* * Exactly one of these */ SIGN_MESSAGE: ['message', 'messageData'], VERIFY_MESSAGE: ['message', 'signature'] }; exports.REQUIRED_PROPS = REQUIRED_PROPS;