solui
  • Getting Started
  • Docs
  • Github
  • Twitter
  • Telegram

@solui/utils

This is a utility belt library for solUI.

Note: This relies on a forked version of the IPFS HTTP Client.

Installation

npm install @solui/utils

Example usage

const { isEthereumAddress } = require('@solui/utils')

console.log( isEthereumAddress('0x0000000000000000000000000000000000000001') )

Read full documentation.

License

Copyright 2019 solUI Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

recoverSigningAccount

Get account which signed given string to obtain given signature.

Parameters

  • str String The input string.
  • signature String The flat-format signature.

Returns String Ethereum address.

hash

Calculate Keccak256 hash of given data.

Parameters

  • data any Input data. If not a String it will transform it via JSON.stringify() first.

Returns String Hex hash with the 0x prefix.

toDate

Parse given string, number or Date into a Date instance.

Parameters

Returns Date

prettyDate

Parse given date string, number or Date and return a pretty string representation (format: MMM d, YYYY).

Parameters

  • d (String | Number | Date) Input date
  • formatStr String? Format, default is MMM d, yyyy (optional, default 'MMM d, yyyy')

Returns String e.g. Oct 27, 2019

createErrorWithDetails

Create Error instance with details member set to passed-in parameter.

Parameters

  • msg String Error message.
  • details any? Details to attach to Error object.

Returns Error

getNodeConnection

Get node connection pointing to given http endpoint URL.

This will check to ensure that it is a valid Ethereum node endpoint.

Parameters

  • url String The node endpoint.

Returns Promise<Node>

getNetworkInfoFromWeb3

Get network information from given Web3 connection.

Parameters

  • web3 Web3 Web3 instance.

Returns Promise<NetworkInfo>

NetworkInfo

Type: Object

Properties

getNetworkInfoFromGlobalScope

Get network information from the node exposed in the Javascript global scope.

This attemps to construct a node connection pointing to the Ethereum endpoint accessible via the Global scope (whether in browser or server-side).

Returns Promise<NetworkInfo>

signMessage

Sign a message.

Parameters

Returns Promise<String> Signature.

getContractAt

Construct contract interface object for existing contract.

Parameters

  • params Object Parameters.
    • params.abi Object contract ABI
    • params.node Node connection
    • params.address String on-chain address.

Returns Object

getContractDeployer

Construct contract interface object for deploying new contract instances.

Parameters

  • params Object Parameters.
    • params.abi Object contract ABI
    • params.bytecode String contract bytecode
    • params.node Node connection
    • params.address String on-chain address.

Returns Object

getBytecode

Get bytecode at given on-chain address.

Parameters

  • node Node node.
  • address String Address of contract.

Returns Promise<String> Bytecode in hex format.

assertEthAddressIsValidOnChain

Check that given Ethereum address is valid.

Parameters

  • value String Ethereum address.
  • node Node node.
  • options Object? Additional options. (optional, default {})
    • options.allowContract Boolean If false then address must not be a contract address. (optional, default true)
    • options.allowEoa Boolean If false then address must not be a non-contract address. (optional, default true)

Returns Promise Resolves if checks pass, rejects if they fail.

GLOBAL_SCOPE

Isomorphic, cross-platform global scope.

Type: Object

alert

Alert user to message.

Parameters

Returns void

getQueryString

Get query string value from current browser URL.

Parameters

  • key String Querystring key to look for.

Returns (String | null) Returns null if not found or not running in browser.

promiseSerial

Process each item in given array (using async callback) in serial mode.

Like Promise.all() but processing serially instead of in parallel.

Parameters

Returns Promise

obfuscate

Obfuscate given string.

This replaces most characters in the string with the * character, and intelligently handles email addresses such that their general structure is left untouched.

Parameters

Examples

obfuscate('password') // p*******
obfuscate('test@me.com') // t***@m*.c**

Returns String

slugify

Slugify given string.

Note that this concatenates a random suffix in each call in order to ensure slugs are somewhat unique, and as such is not idempotent.

Parameters

Returns String

parseQueryString

Parse given query string.

Parameters

Returns Object

parseUrl

Parse URL.

Parameters

Returns Object

isEmail

Check if given value represents a valid email address.

Parameters

  • val String Input email address.

Returns (Boolean | null) true if valid, false if not, null if input is empty.