@colony/purser-core

These docs serve to outline the public API format and methods provided by the @colony/purser-core library.

While there are many more methods available inside this library, only the ones that are documented here are public facing, and intended to be used externally.

Unlike other wallet libraries, this one works entirely in async mode, meaning every return will be a Promise that must resolve (or reject, if something goes wrong...).

Console output

In development mode there will be a number of warnings or errors outputted verbosely to the console.

When building with NODE_ENV=production all output will be silenced.

Imports:

There are different ways in which you can import the library in your project (as a module), but in the end they all bring in the same thing:

Using ES5 require() statements:

var utils = require('@colony/purser-core').utils; // utils.getRandomValues();

Using ES6 import statements:

import { utils } from '@colony/purser-core'; // utils.getRandomValues();

Methods

bigNumber

bigNumber(Number | String  | bigNumber): bigNumber

This method is a wrapper around the bn.js library, so for the full API docs, see this library's documentation.

This method will return an extended instance of bn.js (already instantiated) that has a couple of extra methods added to it's prototype:

toWei(): bigNumber: Converts from ETH to WEI (1 to the power of 18 multiplication). Returns the new value as a bigNumber instance.

fromWei(): bigNumber: Converts from WEI to ETH (1 to the power of 18 division). Returns the new value as a bigNumber instance.

toGwei(): bigNumber: Converts from ETH to GWEI (1 to the power of 9 multiplication). Returns the new value as a bigNumber instance.

fromGwei(): bigNumber: Converts from GWEI to ETH (1 to the power of 9 division). Returns the new value as a bigNumber instance.

This method is used to work with number values throughout the library:

import { open } from '@colony/purser-trezor';
import { bigNumber } from '@colony/purser-core/utils';

const gasPrice = bigNumber('0.00000001').toWei(); // { negative: 0, words: Array(4), length: 4, red: null }

const trezorWallet = await open(); // { address: "0x26eB...bAD1", type: "hardware", subtype: "trezor", ... }

const transactionSignature = await trezorWallet.sign({
  gasPrice,
  to: '0x3953...a4C1',
});

getRandomValues

getRandomValues(typedArray: Uint8Array<>)

A polyfill for the Web Crypto APIs getRandomValues() method.

It checks for both implementations (webkit or ms), and if it can't find any, it will try to polyfill it using node's crypto randomBytes method.

This method is used to provide randomness when creating a new wallet:

import { create } from '@colony/purser-software';
import { getRandomValues } from '@colony/purser-core/utils';

// a bigger array is better, up to a max. of 65536 (the limit of the 8 bit unsigned array)

const uintArray = new Uint8Array(10); // [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

const entropy = getRandomValues(uintArray); // [236, 157, 149, 236, 109, 233, 113, 151, 27, 93]

const newWallet = await create({ entropy });