@lukeburns/hyperswarm-crypto
v0.2.1
Published
Crypto bindings for HyperDHT and Hyperswarm
Downloads
292
Readme
hyperswarm-crypto
The crypto and Noise bindings used by HyperDHT and Hyperswarm.
npm install hyperswarm-cryptoUsage
const crypto = require("hyperswarm-crypto");
const keyPair = crypto.createKeyPair();
console.log(keyPair); // prints an ML-KEM identity + transport key pairAPI
keyPair = crypto.createKeyPair([seed])
Returns a HyperDHT identity key pair and transport key pair.
If seed is provided, the identity and transport key pairs are deterministically derived from separate namespaces.
digest = crypto.identityDigest(publicKey, [algorithm])
Hashes an identity public key and algorithm label into the fixed-size DHT routing identity.
digest = crypto.unslabbedIdentityDigest(publicKey, [algorithm])
Like identityDigest, but returns an unslabbed buffer.
signature = crypto.sign(data, keyPair)
Signs DHT records with the swarm identity signing scheme.
valid = crypto.verify(signature, data, publicKey, [algorithm])
Verifies a DHT record signature.
keyPair = crypto.transportKeyPair(keyPair)
Returns the transport key pair for a HyperDHT identity, falling back to the identity key pair when no separate transport key is present.
keyPair = crypto.createHandshakeKeyPair([seed], [opts])
Returns a key pair for the configured Noise KEM.
If seed is provided, it must match the selected KEM seed length.
noise = crypto.createHandshakeNoise(isInitiator, keyPair, remotePublicKey, pattern, [opts])
Creates and initializes a Noise handshake instance for secret streams.
noise = crypto.createTransportNoise(isInitiator, keyPair, remotePublicKey, prologue, [opts])
Creates and initializes a Noise handshake instance for HyperDHT peer handshakes.
opts = crypto.toNoiseOptions([opts])
Normalizes user options into the option object passed to the Noise implementation.
crypto.validateRemotePublicKey(remotePublicKey, [opts])
Validates that a remote public key matches the configured KEM shape.
crypto.validateHandshakeKeyPair(keyPair, [opts])
Validates that a handshake key pair matches the configured KEM shape.
bytes = crypto.getNoisePublicKeyBytes([opts])
Returns the configured Noise public key byte length.
hash = crypto.hash(data)
Hashes data with the swarm hash primitive.
hash = crypto.unslabbedHash(data)
Like hash, but returns an unslabbed buffer.
list = crypto.namespace(name, count)
Make a list of namespaces from a specific publicly known name. Use this to namespace capabilities or hashes / signatures across algorithms.
Constants
crypto.DEFAULT_HANDSHAKE_PATTERN
The default secret-stream handshake pattern.
crypto.DEFAULT_TRANSPORT_PATTERN
The default HyperDHT peer handshake pattern.
crypto.DEFAULT_KEM
The default Noise KEM.
crypto.MLKEM512, crypto.MLKEM768, crypto.MLKEM1024
The ML-KEM Noise bindings exposed for callers that need to override the default KEM.
License
Apache-2.0
