lemojs-ecc
v1.0.1
Published
Elliptic curve cryptography functions
Downloads
4
Maintainers
Readme
Elliptic curve cryptography functions (ECC)
Private Key, Public Key, Signature, AES, Encryption / Decryption
Import
import ecc from 'lemojs-ecc'
// or
const ecc = require('lemojs-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.randomKey().then(privateKey => {
console.log(privateKey.toString())
})
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.seedPrivate('secret') === wif
Returns wif
privateToPublic
Parameters
wif
wif
Examples
ecc.privateToPublic(wif) === pubkey
Returns pubkey
isValidPublic
Parameters
pubkey
pubkey like LEMOKey..
Examples
ecc.isValidPublic(pubkey) === true
Returns boolean valid
isValidPrivate
Parameters
wif
wif
Examples
ecc.isValidPrivate(wif) === true
Returns boolean valid
sign
Create a signature using data or a hash.
Parameters
data
(string | Buffer)privateKey
(wif | PrivateKey)hashData
boolean sha256 hash data before signing (optional, defaulttrue
)
Examples
ecc.sign('I am alive', wif)
Returns string hex signature
verify
Verify signed data.
Parameters
signature
(string | Buffer) buffer or hex stringdata
(string | Buffer)pubkey
(pubkey | PublicKey)hashData
boolean sha256 hash data before verify (optional, defaulttrue
)
Examples
ecc.verify(signature, 'I am alive', pubkey) === true
Returns boolean
recover
Recover the public key used to create the signature.
Parameters
signature
String (hex, etc..)data
(String | Buffer)hashData
boolean sha256 hash data before recover (optional, defaulttrue
)
Examples
ecc.recover(signature, 'I am alive') === pubkey
Returns pubkey
sha256
Parameters
Examples
ecc.sha256('hashme') === '02208b..'
Returns (string | Buffer) Buffer when encoding is null, or string
pubkey
LEMOKey..
Type: string
Usage (Object API)
let {PrivateKey, PublicKey, Signature, Aes, key_utils, config} = require('lemojs-ecc')
// Create a new random private key
let privateWif
PrivateKey.randomKey().then(privateKey => privateWif = privateKey.toWif())
// Convert to a public key
pubkey = PrivateKey.fromWif(privateWif).toPublic().toString()
Browser
git clone https://github.com/LemoFoundationLtd/lemojs-ecc.git
cd lemojs-ecc
npm install
npm run build
# builds: ./dist/lemojs-ecc.js
# Verify release hash
<script src=lemojs-ecc.js></script>
var ecc = lemojs_ecc
ecc.randomKey().then(privateWif => {
var pubkey = ecc.privateToPublic(privateWif)
console.log(pubkey)
})
Configure
const {config} = require('lemojs-ecc')
// Change the public key address prefix
// config.address_prefix = 'XXX'
See Config