Normalize an Ethereum address
This method assumes the address is already validatated and is in the correct format.
Should the final value have a prefix?
The normalized string
Validate a BIP32 Ethereum Address
The 'hex' address to check
It only returns true if the string is a valid address format, otherwise an Error will be thrown and this will not finish execution.
Wrapper for the bn.js
constructor to use as an utility for big numbers
Make sure to inform the users that this is the preffered way of interacting with big numbers inside this library, as even if the underlying Big Number library will change, this API will (mostly) stay the same.
See: BigInt https://developers.google.com/web/updates/2018/05/bigint
the value to convert to a big number
The new bignumber instance
Serialize an derivation path object's props into it's string counterpart
The serialized path
In order to support EIP-155, it's necessary to specify various definitions for a given chain (e.g. the chain ID, network ID, hardforks).
Given a chain ID, this function returns a chain definition in the format
expected by ethereumjs-common
.
The given chain ID (as defined in EIP-155)
The common chain definition
A very basic polyfill method to generate randomness for use in wallet entropy.
This will fall back to nodejs's crypto
library if the browser that's using this doesn't have the webcrypto
API implemented yet.
An initial unsigned 8-bit integer array to generate randomness from
A new 8-bit unsigned integer array filled with random bytes
Normalize a hex string sequence.
Transforms it to lower case, and, depending on the prefix argument,
either add it (0x
) or remove it
This method assumes the address is already validatated and is in the correct format.
The hex string sequence to normalize
Should the final value have a prefix?
The normalized string
Validate a hex string
The hex
string to check
It only returns true if the string is a valid hex format, otherwise an Error will be thrown and this will not finish execution.
Validate a signature verification message object
The validated signature object containing the exact passed in values
Convert an object to a key (value) concatenated string. This is useful to list values inside of error messages, where you can only pass in a string and not the whole object.
The object to convert
The string containing the object's key (value) pairs
Recover a public key from a message and the signature of that message.
The recovered public key.
Validate an integer passed in to make sure is safe (< 9007199254740991) and positive
The integer to validate
It only returns true if the integer is safe and positive, otherwise an Error will be thrown and this will not finish execution.
Validate an transaction object
The validated transaction object containing the exact passed in values
Check if the user provided input is in the form of an Object and it's required props
If we're in dev
mode, show an warning to the console
This way you won't have to explicitly tell it which message from messages.js
to show
Arguments will be split into three types:
First arg will be the message string
Rest of them will be template literals that will replace %s values in the previous messsage string (with one exception)
If the last argument is an object that has only one prop named level
, it will be interpreted as an option object
(if level equals low
it will only warn, if the level equals high
, it will error)
Arguments array that will be passed down to console
methods (see above)
Generated using TypeDoc
@purser/core
A collection of
helpers
,utils
,validators
andnormalizers
to assist the individual purser modules.Unless you want something specific found in this module, it doesn't need to be manually required as each module already makes use of it internally.
Installation
(Usually you won't install this package just on its own. It's meant to be an accompanying peer-dependency to the other @purser modules)
Quick Usage
import { bigNumber } from '@purser/core/utils' const value = bigNumber('0.00000001').toWei(); console.log(value); // { negative: 0, words: Array(4), length: 4, red: null }
Documentation
You can find more in-depth description for this module's API in the purser docs.
Contributing
This package is part of the purser monorepo package.
Please read our Contributing Guidelines for how to get started.
License
The
@purser/core
library along with the whole purser monorepo are MIT licensed.