hypercore-crypto
Advanced tools
Comparing version 3.4.1 to 3.4.2
18
index.js
@@ -13,4 +13,6 @@ const sodium = require('sodium-universal') | ||
exports.keyPair = function (seed) { | ||
const publicKey = b4a.allocUnsafe(sodium.crypto_sign_PUBLICKEYBYTES) | ||
const secretKey = b4a.allocUnsafe(sodium.crypto_sign_SECRETKEYBYTES) | ||
// key pairs might stay around for a while, so better not to use a default slab to avoid retaining it completely | ||
const slab = b4a.allocUnsafeSlow(sodium.crypto_sign_PUBLICKEYBYTES + sodium.crypto_sign_SECRETKEYBYTES) | ||
const publicKey = slab.subarray(0, sodium.crypto_sign_PUBLICKEYBYTES) | ||
const secretKey = slab.subarray(sodium.crypto_sign_PUBLICKEYBYTES) | ||
@@ -33,3 +35,4 @@ if (seed) sodium.crypto_sign_seed_keypair(publicKey, secretKey, seed) | ||
exports.sign = function (message, secretKey) { | ||
const signature = b4a.allocUnsafe(sodium.crypto_sign_BYTES) | ||
// Dedicated slab for the signature, to avoid retaining unneeded mem and for security | ||
const signature = b4a.allocUnsafeSlow(sodium.crypto_sign_BYTES) | ||
sodium.crypto_sign_detached(signature, message, secretKey) | ||
@@ -108,3 +111,4 @@ return signature | ||
exports.discoveryKey = function (publicKey) { | ||
const digest = b4a.allocUnsafe(32) | ||
// Discovery keys might stay around for a while, so better not to use slab memory (for better gc) | ||
const digest = b4a.allocUnsafeSlow(32) | ||
sodium.crypto_generichash(digest, HYPERCORE, publicKey) | ||
@@ -124,5 +128,9 @@ return digest | ||
const ids = typeof count === 'number' ? range(count) : count | ||
const buf = b4a.allocUnsafe(32 * ids.length) | ||
// Namespaces are long-lived, so better to use a dedicated slab | ||
const buf = b4a.allocUnsafeSlow(32 * ids.length) | ||
const list = new Array(ids.length) | ||
// ns is emhemeral, so default slab | ||
const ns = b4a.allocUnsafe(33) | ||
@@ -129,0 +137,0 @@ sodium.crypto_generichash(ns.subarray(0, 32), typeof name === 'string' ? b4a.from(name) : name) |
{ | ||
"name": "hypercore-crypto", | ||
"version": "3.4.1", | ||
"version": "3.4.2", | ||
"description": "The crypto primitives used in hypercore, extracted into a separate module", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7268
116