Private Key, Public Key, Signature, AES, Encryption / Decryption
import ecc from 'plasmajs-ecc'
// or
const ecc = require('plasmajs-ecc')
- Install with:
npm install @plasma/plasmajs-ecc
- 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
cpuEntropyBits
number 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) // wif
console.log('Public Key:\t', ecc.privateToPublic(privateKey)) // plasmakey...
})
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.
ecc.seedPrivate('secret') === wif
Returns wif
ecc.privateToPublic(wif) === pubkey
Returns pubkey
ecc.isValidPublic(pubkey) === true
Returns boolean valid
wif
wif
ecc.isValidPrivate(wif) === true
Returns boolean valid
Create a signature using data or a hash.
data
(string | Buffer)privateKey
(wif | PrivateKey)encoding
String 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)encoding
String 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'
)hashData
boolean sha256 hash data before verify (optional, defaulttrue
)
ecc.verify(signature, 'I am alive', pubkey) === true
Returns boolean
Recover the public key used to create the signature.
signature
(String | Buffer) (plasmabase58sig.., Hex, Buffer)data
(String | Buffer) full dataencoding
String data encoding (if data is a string) (optional, default'utf8'
)
ecc.recover(signature, 'I am alive') === pubkey
Returns pubkey
signature
(String | Buffer) (plasmabase58sig.., 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
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'
)
ecc.sha256('hashme') === '02208b..'
ecc.sha256(Buffer.from('02208b', 'hex')) === '29a23..'
Returns (string | Buffer) Buffer when encoding is null, or string
plasmaKey..
Type: string
let {PrivateKey, PublicKey, Signature, Aes, key_utils, config} = require('plasmajs-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()
git clone https://github.com/plasmadlt/plasmajs-ecc
cd plasmajs-ecc
npm install
npm run build_browser
# builds: ./lib/plasmajs-ecc.js
# Verify release hash
<script src=plasmajs-ecc.js></script>
var ecc = plasmajs_ecc
ecc.randomKey().then(privateWif => {
var pubkey = ecc.privateToPublic(privateWif)
console.log(pubkey)
})