Elliptic curve cryptography functions (ECC)
Private Key, Public Key, Signature, AES, Encryption / Decryption
Import
// orconst ecc =
Common API
wif
Type: string
ecc
initialize
Initialize by running some self-checking code. This should take a second to gather additional CPU entropy used during private key generation.
Initialization happens once even if called multiple times.
Returns Promise
unsafeRandomKey
Does not pause to gather CPU entropy.
Returns Promise<PrivateKey> test key
randomKey
Parameters
cpuEntropyBits
number gather additional entropy from a CPU mining algorithm. This will already happen once by default. (optional, default0
)
Examples
ecc
seedPrivate
Parameters
seed
string any length string. This is private. The same seed produces the same private key every time. At least 128 random bits should be used to produce a good private key.
Examples
ecc === wif
Returns wif
privateToPublic
Parameters
wif
wif
Examples
ecc === pubkey
Returns pubkey
isValidPublic
Parameters
pubkey
pubkey like TTTKey..
Examples
ecc === true
Returns boolean valid
isValidPrivate
Parameters
wif
wif
Examples
ecc === true
Returns boolean valid
sign
Create a signature using data or a hash.
Parameters
data
(string | Buffer)privateKey
(wif | PrivateKey)encoding
String data encoding (if string) (optional, default'utf8'
)
Examples
ecc
Returns string string signature
signHash
Parameters
dataSha256
(String | Buffer) sha256 hash 32 byte buffer or stringprivateKey
(wif | PrivateKey)encoding
String dataSha256 encoding (if string) (optional, default'hex'
)
Returns string string signature
verify
Verify signed data.
Parameters
signature
(string | Buffer) buffer or hex stringdata
(string | Buffer)pubkey
(pubkey | PublicKey)encoding
(optional, default'utf8'
)hashData
boolean sha256 hash data before verify (optional, defaulttrue
)
Examples
ecc === true
Returns boolean
recover
Recover the public key used to create the signature.
Parameters
signature
(String | Buffer) (TTTbase58sig.., Hex, Buffer)data
(String | Buffer) full dataencoding
String data encoding (if data is a string) (optional, default'utf8'
)
Examples
ecc === pubkey
Returns pubkey
recoverHash
Parameters
signature
(String | Buffer) (TTTbase58sig.., Hex, Buffer)dataSha256
(String | Buffer) sha256 hash 32 byte buffer or hex stringencoding
String dataSha256 encoding (if dataSha256 is a string) (optional, default'hex'
)
Returns PublicKey
sha256
Parameters
Examples
ecc === '02208b..'
Returns (string | Buffer) Buffer when encoding is null, or string
pubkey
TTTKey..
Type: string
Usage (Object API)
let PrivateKey PublicKey Signature Aes key_utils config = // Create a new random private keylet privateWifPrivateKey // Convert to a public keypubkey = PrivateKey
Browser
git clone https://github.com/EOSIO/eosjs-ecc.gitcd eosjs-eccnpm installnpm run build_browser# builds: ./dist/eosjs-ecc.js # Verify release hash
var ecc = eosjs_ecc ecc