Elliptic curve cryptography functions
npm install eosjs-ecc

Private Key, Public Key, Signature, AES, Encryption / Decryption
``js`
import ecc from 'eosjs-ecc'
// or
const ecc = require('eosjs-ecc')
- Install with: yarn add eosjs-ecc
- Html script tag, see releases for the correct version and its matching script integrity hash.
`html
integrity="sha512-dYFDmK/d9r3/NCp6toLtfkwOjSMRBaEzaGAx1tfRItC0nsI0hVLERk05iNBQR7uDNI7ludYhcBI4vUiFHdjsTQ=="
crossorigin="anonymous">
Common API
$3
- wif
- ecc
- initialize
- unsafeRandomKey
- randomKey
- Parameters
- Examples
- seedPrivate
- Parameters
- Examples
- privateToPublic
- Parameters
- Examples
- isValidPublic
- Parameters
- Examples
- isValidPrivate
- Parameters
- Examples
- sign
- Parameters
- Examples
- signHash
- Parameters
- verify
- Parameters
- Examples
- recover
- Parameters
- Examples
- recoverHash
- Parameters
- sha256
- Parameters
- Examples
- pubkey
wif
Type: string
ecc
$3
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
$3
Does not pause to gather CPU entropy.
Returns Promise<PrivateKey> test key
$3
#### Parameters
-
cpuEntropyBits number gather additional entropy
from a CPU mining algorithm. This will already happen once by
default. (optional, default 0)#### Examples
`javascript
ecc.randomKey().then(privateKey => {
console.log('Private Key:\t', privateKey) // wif
console.log('Public Key:\t', ecc.privateToPublic(privateKey)) // EOSkey...
})
`$3
#### 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
`javascript
ecc.seedPrivate('secret') === wif
`Returns wif
$3
#### Parameters
-
wif wif
- pubkey_prefix string public key prefix (optional, default 'EOS')#### Examples
`javascript
ecc.privateToPublic(wif) === pubkey
`Returns pubkey
$3
#### Parameters
-
pubkey pubkey like EOSKey..
- pubkey_prefix string (optional, default 'EOS')#### Examples
`javascript
ecc.isValidPublic(pubkey) === true
`Returns boolean valid
$3
#### Parameters
-
wif wif #### Examples
`javascript
ecc.isValidPrivate(wif) === true
`Returns boolean valid
$3
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
`javascript
ecc.sign('I am alive', wif)
`Returns string string signature
$3
#### Parameters
-
dataSha256 (String \| Buffer) sha256 hash 32 byte buffer or string
- privateKey (wif | PrivateKey)
- encoding String dataSha256 encoding (if string) (optional, default 'hex')Returns string string signature
$3
Verify signed data.
#### Parameters
-
signature (string \| Buffer) buffer or hex string
- data (string \| Buffer)
- pubkey (pubkey | PublicKey)
- encoding (optional, default 'utf8')
- hashData boolean sha256 hash data before verify (optional, default true)#### Examples
`javascript
ecc.verify(signature, 'I am alive', pubkey) === true
`Returns boolean
$3
Recover the public key used to create the signature.
#### Parameters
-
signature (String \| Buffer) (EOSbase58sig.., Hex, Buffer)
- data (String \| Buffer) full data
- encoding String data encoding (if data is a string) (optional, default 'utf8')#### Examples
`javascript
ecc.recover(signature, 'I am alive') === pubkey
`Returns pubkey
$3
#### Parameters
-
signature (String \| Buffer) (EOSbase58sig.., Hex, Buffer)
- dataSha256 (String \| Buffer) sha256 hash 32 byte buffer or hex string
- encoding String dataSha256 encoding (if dataSha256 is a string) (optional, default 'hex')Returns PublicKey
$3
#### Parameters
-
data (string \| Buffer) always binary, you may need Buffer.from(data, 'hex')
- resultEncoding (optional, default 'hex')
- encoding string result encoding 'hex', 'binary' or 'base64' (optional, default 'hex')#### Examples
`javascript
ecc.sha256('hashme') === '02208b..'
``javascript
ecc.sha256(Buffer.from('02208b', 'hex')) === '29a23..'
`Returns (string \| Buffer) Buffer when encoding is null, or string
pubkey
EOSKey..
Type: string
Usage (Object API)
`js
let {PrivateKey, PublicKey, Signature, Aes, key_utils, config} = require('eosjs-ecc')// Create a new random private key
let privateWif
PrivateKey.randomKey().then(privateKey => privateWif = privateKey.toWif())
// Convert to a public key
pubkey = PrivateKey.fromString(privateWif).toPublic().toString()
`- PrivateKey
- PublicKey
- Signature
- Aes
- key_utils
- config
Browser
`bash
git clone https://github.com/EOSIO/eosjs-ecc.git
cd eosjs-ecc
yarn
yarn build_browser
builds: ./dist/eosjs-ecc.js
Verify release hash
``html
``js
var ecc = eosjs_eccecc.randomKey().then(privateWif => {
var pubkey = ecc.privateToPublic(privateWif)
console.log(pubkey)
})
``