Skip to content

message signing and verifying for Lightning Network

License

Notifications You must be signed in to change notification settings

dancju/ln-crypto

Repository files navigation

ln-crypto

license node npm type definitions npm bundle size build Quality Gate Status Coverage Maintainability Rating Reliability Rating Security Rating

Message signing and verifying for Lightning Network, without a connection to the network!

Usage

import { generatePrvkey, neuter, recover, sign, verify } from 'ln-crypto';

// an arbitrary message to be signed
const msg = 'The quick brown fox jumps over the lazy dog.';

// generate a pseudorandom private key
const prvkey = generatePrvkey();

// get the corresponding public key
const pubkey = neuter(prvkey);
console.log(pubkey.toString('hex')); // 0280f375eafb209d0255a3139f1013042d55d69005a935da46bea7279d598c366a

// sign the message with secp256k1 and convert the signature into zbase32, which
// is exactly what LND does
const sig = sign(msg, prvkey);
console.log(sig); // d1q3e5fdy96zp3syrhq8zphqnaa5fqbbh9rinozegr1bjr99hssq6hbhstm3pqbh7sfu4hnsyfjjkoewum1ay85gmem98u8wxshyxs5k

// The message receiver can verify the correctness of the signature,
console.log(verify(msg, sig, pubkey)); // true

// or recover a public key from the message and the signature, and compare it
// with the received public key.
console.log(recover(msg, sig).toString('hex')); // 0280f375eafb209d0255a3139f1013042d55d69005a935da46bea7279d598c366a

About

message signing and verifying for Lightning Network

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published