Options
All
  • Public
  • Public/Protected
  • All
Menu

codechain-primitives-js npm version Build Status codecov

JavaScript functions and classes for CodeChain primitives

Installing a package

# npm
npm install codechain-primitives
# yarn
yarn add codechain-primitives

Getting started

// Using require
var primitives = require("codechain-primitives");
var H256 = primitives.H256;
var blake256 = primitives.blake256;

// Using import
import { blake256, H256 } from "codechain-primitives";

Functions

  • blake256
  • blake256WithKey
  • ripemd160
  • signEcdsa
  • verifyEcdsa
  • recoverEcdsa
  • generatePrivateKey
  • getPublicFromPrivate
  • toHex
  • getAccountIdFromPrivate
  • getAccountIdFromPublic

Classes

  • H128, H160, H256, H512
  • U64, U128, U256
  • AssetAddres
  • PlatformAddress

API Documentation

Coming soon

Index

Type aliases

AssetAddressValue

AssetAddressValue: AssetAddress | string

EcdsaSignature

EcdsaSignature: string

H128Value

H128Value: H128 | string

H160Value

H160Value: H160 | string

H256Value

H256Value: H256 | string

H512Value

H512Value: H512 | string

Payload

PayloadValue

PlatformAddressValue

PlatformAddressValue: PlatformAddress | string

PublicKeyHash

PublicKeyHash: H160

PublicKeyHashValue

PublicKeyHashValue: H160 | string

U128Value

U128Value: U128 | U64Value

U256Value

U256Value: U256 | U128Value

U64Value

U64Value: U64 | BigNumber | number | string

Functions

Const blake128

  • blake128(data: Buffer | string): string
  • Gets data's 128 bit blake hash.

    Parameters

    • data: Buffer | string

      buffer or hexadecimal string

    Returns string

    16 byte hexadecimal string

Const blake128WithKey

  • blake128WithKey(data: Buffer | string, key: Uint8Array): string
  • Gets data's 128 bit blake hash by using the key.

    Parameters

    • data: Buffer | string

      buffer or hexadecimal string

    • key: Uint8Array

    Returns string

    16 byte hexadecimal string

Const blake160

  • blake160(data: Buffer | string): string
  • Gets data's 160 bit blake hash.

    Parameters

    • data: Buffer | string

      buffer or hexadecimal string

    Returns string

    20 byte hexadecimal string

Const blake160WithKey

  • blake160WithKey(data: Buffer | string, key: Uint8Array): string
  • Gets data's 160 bit blake hash by using the key.

    Parameters

    • data: Buffer | string

      buffer or hexadecimal string

    • key: Uint8Array

    Returns string

    20 byte hexadecimal string

Const blake256

  • blake256(data: Buffer | string): string
  • Gets data's 256 bit blake hash.

    Parameters

    • data: Buffer | string

      buffer or hexadecimal string

    Returns string

    32 byte hexadecimal string

Const blake256WithKey

  • blake256WithKey(data: Buffer | string, key: Uint8Array): string
  • Gets data's 256 bit blake hash by using the key.

    Parameters

    • data: Buffer | string

      buffer or hexadecimal string

    • key: Uint8Array

    Returns string

    32 byte hexadecimal string

encodePayload

Const generatePrivateKey

  • generatePrivateKey(): string
  • Generates a private key.

    Returns string

    32 byte hexadecimal string of private key

Const getAccountIdFromPrivate

  • getAccountIdFromPrivate(priv: string): string
  • Gets account id from private key.

    Parameters

    • priv: string

      32 byte hexadecimal string of private key

    Returns string

    20 byte hexadecimal string of account id

Const getAccountIdFromPublic

  • getAccountIdFromPublic(publicKey: string): string
  • Gets account id from the given public key.

    Parameters

    • publicKey: string

      64 byte hexadecimal string of uncompressed public key

    Returns string

    20 byte hexadecimal string of account id

Const getPublicFromPrivate

  • getPublicFromPrivate(priv: string): string
  • Gets public key from private key.

    Parameters

    • priv: string

      32 byte hexadecimal string of private key

    Returns string

    64 byte hexadecimal string of public key

Const recoverEcdsa

  • Gets public key from the message and ECDSA signature.

    Parameters

    • message: string

      32 byte hexademical string

    • signature: EcdsaSignature

      65 byte hexadecimal string of ECDSA signature

    Returns string

    64 byte hexadecimal string public key

Const recoverSchnorr

  • (Experimental) Gets public key from the message and Schnorr signature.

    Parameters

    • message: string

      32 byte hexademical string

    • signature: SchnorrSignature

      r, s of Schnorr signature

    Returns string

    64 byte hexadecimal string public key

Const ripemd160

  • ripemd160(data: Buffer | string): string
  • Gets data's 160 bit RIPEMD hash.

    Parameters

    • data: Buffer | string

      buffer or hexadecimal string

    Returns string

    20 byte hexadecimal string

Const signEcdsa

  • Gets ECDSA signature for message from private key.

    Parameters

    • message: string

      32 byte hexademical string

    • priv: string

      32 byte hexadecimal string of private key

    Returns EcdsaSignature

    65 byte hexadecimal string of ECDSA signature

Const signSchnorr

  • (Experimental) Gets Schnorr signature for message from private key.

    Parameters

    • message: string

      32 byte hexademical string

    • priv: string

      32 byte hexadecimal string of private key

    Returns SchnorrSignature

    r, s of Schnorr signature

Const toHex

  • toHex(buffer: Buffer): string
  • Converts buffer to hexadecimal string.

    Parameters

    • buffer: Buffer

      arbritrary length of data

    Returns string

    hexadecimal string

Const toLocaleString

  • toLocaleString(num: BigNumber): string
  • Converts BigNumber to formatted number string Default decimalSeparator is point: "." Default groupSeparator is comma; "," Default groupSize is 3

    Parameters

    • num: BigNumber

      BigNumber object

    Returns string

    formatted number string

Const verifyEcdsa

  • verifyEcdsa(message: string, signature: EcdsaSignature, pub: string): boolean
  • Checks if the signature from signEcdsa is correct.

    Parameters

    • message: string

      32 byte hexademical string

    • signature: EcdsaSignature

      65 byte hexadecimal string of ECDSA signature

    • pub: string

      64 byte hexadecimal string of public key

    Returns boolean

    if signature is valid, true. Else false.

Const verifySchnorr

  • verifySchnorr(message: string, signature: SchnorrSignature, pub: string): boolean
  • (Experimental) Checks if the signature from signSchnorr is correct.

    Parameters

    • message: string

      32 byte hexademical string

    • signature: SchnorrSignature

      r, s of Schnorr signature

    • pub: string

      64 byte hexadecimal string of public key

    Returns boolean

    if signature is valid, true. Else false.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc