1.6.1 • Published 6 years ago
ala-ecc1 v1.6.1
Elliptic curve cryptography functions (ECC)
Private Key, Public Key, Signature, AES, Encryption / Decryption
Import
import ecc from 'ala-ecc1'
// or
const ecc = require('ala-ecc1')Common API
wif
Type: string
ecc
randomKey
Parameters
cpuEntropyBitsnumber gather additional entropy from a CPU mining algorithm. Set to 0 for testing. (optional, default128)
Examples
ecc.randomKey()Returns wif
seedPrivate
Parameters
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.
Examples
ecc.seedPrivate('secret') === wifReturns wif
privateToPublic
Parameters
wifwif
Examples
ecc.privateToPublic(wif) === pubkeyReturns pubkey
isValidPublic
Parameters
pubkeypubkey like ALAKey..
Examples
ecc.isValidPublic(pubkey) === trueReturns boolean valid
isValidPrivate
Parameters
wifwif
Examples
ecc.isValidPrivate(wif) === trueReturns boolean valid
sign
Create a signature using data or a hash.
Parameters
data(string | Buffer)privateKey(wif | PrivateKey)hashDataboolean 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)hashDataboolean sha256 hash data before verify (optional, defaulttrue)
Examples
ecc.verify(signature, 'I am alive', pubkey) === trueReturns boolean
recover
Recover the public key used to create the signature.
Parameters
signatureString (hex, etc..)data(String | Buffer)hashDataboolean sha256 hash data before recover (optional, defaulttrue)
Examples
ecc.recover(signature, 'I am alive') === pubkeyReturns pubkey
sha256
Parameters
Examples
ecc.sha256('hashme') === '02208b..'Returns (string | Buffer) Buffer when encoding is null, or string
pubkey
ALAKey..
Type: string
Usage (Object API)
let {PrivateKey, PublicKey, Signature, Aes, key_utils, config} = require('ala-ecc1')
// Create a new random private key
privateWif = PrivateKey.randomKey().toWif()
// Convert to a public key
pubkey = PrivateKey.fromWif(privateWif).toPublic().toString()Browser
git clone https://github.com/ALADIN-Network/ala-ecc1.git
cd ala-ecc1
npm install
npm run build
# builds: ./dist/ala-ecc1.js
# Verify release hash<script src=ala-ecc1.js></script>var ecc = alaexplorerjs_ecc
var privateWif = ecc.randomKey()
var pubkey = ecc.privateToPublic(privateWif)
console.log(pubkey)Configure
const {config} = require('ala-ecc1')
// Change the public key address prefix
// config.address_prefix = 'XXX'See Config
1.6.1
6 years ago