bcoin-native
The missing crypto and encoding bindings for node.js.
This module provides native bindings to all lowlevel optimizable things used in bitcoin.
Used in bcoin.
Functions
hash(alg, data)
hmac(alg, data)
ripemd160(data)
sha1(data)
sha256(data)
hash160(data)
hash256(data)
root256(left, right)
toBase58(data)
fromBase58(data)
toBech32(hrp, version, hash)
fromBech32(str)
scrypt(pass, salt, n, r, p, klen)
scryptAsync(pass, salt, n, r, p, klen)
murmur3(data, seed)
siphash(data, key)
siphash256(data, key)
cleanse(data)
encipher(data, key, iv)
decipher(data, key, iv)
Objects
Poly1305()
#init(key)
#update(data)
#finish()
.verify(mac1, mac2)
.auth(data, key)
ChaCha20()
#init(key?, iv?, counter?)
#initKey(key)
#initIV(iv, counter?)
#encrypt(data)
#getCounter()
#setCounter(counter)
Usage
var native = ;var data = Buffer;var key = Buffer;var hash1 = native;var hash2 = native;console;console;
Outputs:
sha256: 9f64a747e1b97f131fabb6b447296c9b6f0201e79fb3c5356e6c77e89b6a806a
double sha256: 8de472e2399610baaa7f84840547cd409434e31f5d3bd71e4d947f283874f9c0
Benchmarks
$ node bench.jscrypto.sha256: ops=100000, time=0.41668067, rate=239991.93435native.sha256: ops=100000, time=0.328309021, rate=304591.08219crypto.hash160: ops=100000, time=0.698852504, rate=143091.71024native.hash160: ops=100000, time=0.32359362, rate=309029.57852crypto.hash256: ops=100000, time=0.65909456, rate=151723.29749native.hash256: ops=100000, time=0.313477282, rate=319002.38308crypto.sha256hmac: ops=100000, time=0.589858488, rate=169532.18786native.sha256hmac: ops=100000, time=0.444996526, rate=224720.85546utils.toBase58: ops=100000, time=0.808880157, rate=123627.70818native.toBase58: ops=100000, time=0.458057275, rate=218313.31027utils.fromBase58: ops=100000, time=0.77960898, rate=128269.43066native.fromBase58: ops=100000, time=0.746901487, rate=133886.46527js poly1305.update: ops=31250, time=1.6195938239999998, rate=19294.96120js poly1305.finish: ops=31250, time=2.9935169999999998, rate=10439.22583c poly1305.update: ops=31250, time=0.184753504, rate=169144.28860c poly1305.finish: ops=31250, time=1.434867264, rate=21779.01802js murmur3: ops=1000000, time=4.714874642, rate=212094.71639c murmur3: ops=1000000, time=0.412050096, rate=2426889.37512js siphash256: ops=1000000, time=13.218189886, rate=75653.32384c siphash256: ops=1000000, time=1.19912212, rate=833943.41854
License
Copyright (c) 2016, Christopher Jeffrey. (MIT License)
See LICENSE for more info.