Private Key, Public Key, Signature, AES, Encryption / Decryption
importeccfrom'eosjs-ecc'// orconstecc=require('eosjs-ecc')- Install with:
npm install eosjs-ecc - Html script tag, see releases for the correct version and its matching script integrity hash.
<html><head><metacharset="utf-8"><!-- sha512-cL+IQQaQ586s9DrXfGtDheRpj5iDKh2M+xlpfwbhNjRIp4BGQ1fkM/vB4Ta8mc+f51YBW9sJiPcyMDIreJe6gQ== lib/eosjs-ecc.js sha512-dYFDmK/d9r3/NCp6toLtfkwOjSMRBaEzaGAx1tfRItC0nsI0hVLERk05iNBQR7uDNI7ludYhcBI4vUiFHdjsTQ== lib/eosjs-ecc.min.js sha512-eq1SCoSe38uR1UVuQMwR73VgY8qKTBDc87n2nIiC5WLhn1o2y1U6c5wY8lrigVX7INM8fM0PxDlMX5WvpghKig== lib/eosjs-ecc.min.js.map --><scriptsrc="https://cdn.jsdelivr.net/npm/eosjs-ecc@4.0.4/lib/eosjs-ecc.min.js"
integrity="sha512-dYFDmK/d9r3/NCp6toLtfkwOjSMRBaEzaGAx1tfRItC0nsI0hVLERk05iNBQR7uDNI7ludYhcBI4vUiFHdjsTQ=="
crossorigin="anonymous"></script></head><body>
See console object: eosjs_ecc
</body></html>- wif
- ecc
- pubkey
Type: string
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
Does not pause to gather CPU entropy.
Returns Promise<PrivateKey> test key
cpuEntropyBitsnumber gather additional entropy from a CPU mining algorithm. This will already happen once by default. (optional, default0)
ecc.randomKey().then(privateKey=>{console.log('Private Key:\t',privateKey)// wifconsole.log('Public Key:\t',ecc.privateToPublic(privateKey))// EOSkey...})seedstring 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.
ecc.seedPrivate('secret')===wifReturns wif
ecc.privateToPublic(wif)===pubkeyReturns pubkey
ecc.isValidPublic(pubkey)===trueReturns boolean valid
wifwif
ecc.isValidPrivate(wif)===trueReturns boolean valid
Create a signature using data or a hash.
data(string | Buffer)privateKey(wif | PrivateKey)encodingString data encoding (if string) (optional, default'utf8')
ecc.sign('I am alive',wif)Returns string string signature
dataSha256(String | Buffer) sha256 hash 32 byte buffer or stringprivateKey(wif | PrivateKey)encodingString dataSha256 encoding (if string) (optional, default'hex')
Returns string string signature
Verify signed data.
signature(string | Buffer) buffer or hex stringdata(string | Buffer)pubkey(pubkey | PublicKey)encoding(optional, default'utf8')hashDataboolean sha256 hash data before verify (optional, defaulttrue)
ecc.verify(signature,'I am alive',pubkey)===trueReturns boolean
Recover the public key used to create the signature.
signature(String | Buffer) (EOSbase58sig.., Hex, Buffer)data(String | Buffer) full dataencodingString data encoding (if data is a string) (optional, default'utf8')
ecc.recover(signature,'I am alive')===pubkeyReturns pubkey
signature(String | Buffer) (EOSbase58sig.., Hex, Buffer)dataSha256(String | Buffer) sha256 hash 32 byte buffer or hex stringencodingString dataSha256 encoding (if dataSha256 is a string) (optional, default'hex')
Returns PublicKey
data(string | Buffer) always binary, you may need Buffer.from(data, 'hex')resultEncoding(optional, default'hex')encodingstring result encoding 'hex', 'binary' or 'base64' (optional, default'hex')
ecc.sha256('hashme')==='02208b..'ecc.sha256(Buffer.from('02208b','hex'))==='29a23..'Returns (string | Buffer) Buffer when encoding is null, or string
EOSKey..
Type: string
let{PrivateKey, PublicKey, Signature, Aes, key_utils, config}=require('eosjs-ecc')// Create a new random private keyletprivateWifPrivateKey.randomKey().then(privateKey=>privateWif=privateKey.toWif())// Convert to a public keypubkey=PrivateKey.fromString(privateWif).toPublic().toString()git clone https://github.com/EOSIO/eosjs-ecc.git
cd eosjs-ecc
npm install
npm run build_browser
# builds: ./dist/eosjs-ecc.js# Verify release hash<scriptsrc=eosjs-ecc.js></script>varecc=eosjs_eccecc.randomKey().then(privateWif=>{varpubkey=ecc.privateToPublic(privateWif)console.log(pubkey)})