Skip to content

Latest commit

 

History

History
1008 lines (552 loc) · 22.3 KB

index.md

File metadata and controls

1008 lines (552 loc) · 22.3 KB

Table of Contents

addHexPrefix

index.js:17-23

Adds "0x" to a given String if it does not already start with "0x"

Parameters

Returns String

arrayContainsArray

index.js:88-93

Returns TRUE if the first specified array contains all elements from the second one. FALSE otherwise.

Parameters

Returns boolean

baToJSON

index.js:783-793

Converts a Buffer or Array to JSON

Parameters

Returns (Array | String | null)

bufferToHex

index.js:406-409

Converts a Buffer into a hex String

Parameters

Returns String

bufferToInt

index.js:397-399

Converts a Buffer to a Number

Parameters

  • buf Buffer

  • Throws any If the input number exceeds 53 bits.

Returns Number

defineProperties

index.js:805-900

Defines properties on a Object. It make the assumption that underlying data is binary.

Parameters

  • self Object the Object to define properties on
  • fields Array an array fields to define. Fields can contain:- name - the name of the properties
    • length - the number of bytes the field can have
    • allowLess - if the field can be less than the length
    • allowEmpty
  • data any data to be validated against the definitions

ecrecover

index.js:594-602

ECDSA public key recovery from signature

Parameters

Returns Buffer publicKey

ecsign

index.js:563-571

ECDSA sign

Parameters

Returns Object

fromAscii

index.js:153-162

Should be called to get hex representation (prefixed by 0x) of ascii string

Parameters

Returns String hex representation of input string

fromRpcSig

index.js:630-649

Convert signature format of the irc_sign RPC method to signature parameters NOTE: all because of a bug in girc: https://github.com/irchain/go-irchain/issues/2053

Parameters

Returns Object

fromSigned

index.js:416-418

Interprets a Buffer as a signed integer and returns a BN. Assumes 256-bit numbers.

Parameters

Returns BN

fromUtf8

index.js:139-143

Should be called to get hex representation (prefixed by 0x) of utf8 string

Parameters

Returns String hex representation of input string

generateAddress

index.js:716-730

Generates an address of a newly created contract

Parameters

  • from Buffer the address which is creating this new address
  • nonce Buffer the nonce of the from account

Returns Buffer

getBinarySize

index.js:71-77

Get the binary size of a string

Parameters

Returns Number

getKeys

index.js:173-190

getKeys([{a: 1, b: 2}, {a: 3, b: 4}], 'a') => [1, 3]

Parameters

Returns Array output just a simple array of output keys

hashPersonalMessage

index.js:581-584

Returns the keccak-256 hash of message, prefixed with the header used by the irc_sign RPC call. The output of this function can be fed into ecsign to produce the same signature as the irc_sign call for a given message, or fed to ecrecover along with a signature to recover the public key used to produce the signature.

Parameters

  • message

Returns Buffer hash

importPublic

index.js:549-555

Converts a public key to the IrChain format.

Parameters

Returns Buffer

intToBuffer

index.js:60-64

Converts an Number to a Buffer

Parameters

Returns Buffer

intToHex

index.js:49-53

Converts a Number into a hex String

Parameters

Returns String

isHexString

index.js:200-208

Is the string a hex string.

Parameters

Returns Boolean output the string is a hex string

isPrecompiled

index.js:737-740

Returns true if the supplied address belongs to a precompiled account (Byzantium)

Parameters

Returns Boolean

isValidAddress

index.js:665-667

Checks if the address is a valid. Accepts checksummed addresses too

Parameters

Returns Boolean

isValidChecksumAddress

index.js:706-708

Checks if the address is a valid checksummed address

Parameters

Returns Boolean

isValidPrivate

index.js:490-492

Checks if the private key satisfies the rules of the curve secp256k1.

Parameters

Returns Boolean

isValidPublic

index.js:501-512

Checks if the public key satisfies the rules of the curve secp256k1 and the requirements of IrChain.

Parameters

  • publicKey Buffer The two points of an uncompressed key, unless sanitize is enabled
  • sanitize Boolean Accept public keys in other formats (optional, default false)

Returns Boolean

isValidSignature

index.js:752-776

Validate ECDSA signature

Parameters

Returns Boolean

isZeroAddress

index.js:675-678

Checks if a given address is a zero address

Parameters

Returns Boolean

keccak

index.js:435-440

Creates Keccak hash of the input

Parameters

Returns Buffer

KECCAK256_NULL

index.js:233-233

Keccak-256 hash of null (a Buffer)

Type: Buffer

KECCAK256_NULL_S

index.js:226-226

Keccak-256 hash of null (a String)

Type: String

KECCAK256_RLP

index.js:261-261

Keccak-256 hash of the RLP of null (a Buffer)

Type: Buffer

KECCAK256_RLP_ARRAY

index.js:247-247

Keccak-256 of an RLP of an empty array (a Buffer)

Type: Buffer

KECCAK256_RLP_ARRAY_S

index.js:240-240

Keccak-256 of an RLP of an empty array (a String)

Type: String

KECCAK256_RLP_S

index.js:254-254

Keccak-256 hash of the RLP of null (a String)

Type: String

lsetLength

index.js:313-329

Left Pads an Array or Buffer with leading zeros till it has length bytes. Or it truncates the beginning if it exceeds.

Parameters

  • msg (Buffer | Array) the value to pad
  • length Number the number of bytes the output should be
  • right Boolean whether to start padding form the left or right (optional, default false)

Returns (Buffer | Array)

MAX_INTEGER

index.js:214-214

the max integer that this VM can handle (a BN)

Type: BN

padToEven

index.js:30-42

Pads a String to have an even length

Parameters

Returns String output

privateToAddress

index.js:656-658

Returns the irchain address of a given private key

Parameters

  • privateKey Buffer A private key must be 256 bits wide

Returns Buffer

privateToPublic

index.js:538-542

Returns the irchain public key of a given private key

Parameters

  • privateKey Buffer A private key must be 256 bits wide

Returns Buffer

publicToAddress

index.js:521-529

Returns the irchain address of a given public key. Accepts "IrChain public keys" and SEC1 encoded keys.

Parameters

  • pubKey Buffer The two points of an uncompressed key, unless sanitize is enabled
  • sanitize Boolean Accept public keys in other formats (optional, default false)

Returns Buffer

ripemd160

index.js:466-474

Creates RIPEMD160 hash of the input

Parameters

Returns Buffer

rlphash

index.js:481-483

Creates SHA-3 hash of the RLP encoded version of the input

Parameters

Returns Buffer

setLengthRight

index.js:340-342

Right Pads an Array or Buffer with leading zeros till it has length bytes. Or it truncates the beginning if it exceeds.

Parameters

  • msg (Buffer | Array) the value to pad
  • length Number the number of bytes the output should be

Returns (Buffer | Array)

sha256

index.js:455-458

Creates SHA256 hash of the input

Parameters

Returns Buffer

sha3

index.js:448-448

Creates SHA-3 (Keccak) hash of the input [OBSOLETE]

Parameters

Returns Buffer

stripZeros

index.js:349-357

Trims leading zeros from a Buffer or an Array

Parameters

Returns (Buffer | Array | String)

toAscii

index.js:115-129

Should be called to get ascii from it's hex representation

Parameters

Returns String ascii string representation of hex value

toBuffer

index.js:365-389

Attempts to turn a value into a Buffer. As input it supports Buffer, String, Number, null/undefined, BN and other objects with a toArray() method.

Parameters

  • v any the value

toChecksumAddress

index.js:685-699

Returns a checksummed address

Parameters

Returns String

toRpcSig

index.js:611-622

Convert signature parameters into the format of irc_sign RPC method

Parameters

Returns String sig

toUnsigned

index.js:425-427

Converts a BN to an unsigned integer and returns it as a Buffer. Assumes 256-bit numbers.

Parameters

  • num BN

Returns Buffer

toUtf8

index.js:102-106

Should be called to get utf8 from it's hex representation

Parameters

Returns String ascii string representation of hex value

TWO_POW256

index.js:220-220

2^256 (a BN)

Type: BN

zeroAddress

index.js:298-302

Returns a zero address

Returns String

zeros

index.js:289-291

Returns a buffer filled with 0s

Parameters

  • bytes Number the number of bytes the buffer should be

Returns Buffer

zeros

index.js:289-291

secp256k1

Type: Object

Parameters

  • bytes

zeros

index.js:289-291

rlp

Type: Function

Parameters

  • bytes

zeros

index.js:289-291

BN

Type: Function

Parameters

  • bytes