Socket
Socket
Sign inDemoInstall

hypercore-crypto

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hypercore-crypto - npm Package Compare versions

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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc