diff options
Diffstat (limited to 'node_modules/elliptic/README.md')
-rw-r--r-- | node_modules/elliptic/README.md | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/node_modules/elliptic/README.md b/node_modules/elliptic/README.md index 808984501..96219e55b 100644 --- a/node_modules/elliptic/README.md +++ b/node_modules/elliptic/README.md @@ -55,35 +55,46 @@ var ec = new EC('secp256k1'); // Generate keys var key = ec.genKeyPair(); -// Sign message (must be an array, or it'll be treated as a hex sequence) -var msg = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; -var signature = key.sign(msg); +// Sign the message's hash (input must be an array, or a hex-string) +var msgHash = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; +var signature = key.sign(msgHash); // Export DER encoded signature in Array var derSign = signature.toDER(); // Verify signature -console.log(key.verify(msg, derSign)); +console.log(key.verify(msgHash, derSign)); // CHECK WITH NO PRIVATE KEY -// Public key as '04 + x + y' -var pub = '04bb1fa3...'; +var pubPoint = key.getPublic(); +var x = pubPoint.getX(); +var y = pubPoint.getY(); + +// Public Key MUST be either: +// 1) '04' + hex string of x + hex string of y; or +// 2) object with two hex string properties (x and y); or +// 3) object with two buffer properties (x and y) +var pub = pubPoint.encode('hex'); // case 1 +var pub = { x: x.toString('hex'), y: y.toString('hex') }; // case 2 +var pub = { x: x.toBuffer(), y: y.toBuffer() }; // case 3 +var pub = { x: x.toArrayLike(Buffer), y: y.toArrayLike(Buffer) }; // case 3 + +// Import public key +var key = ec.keyFromPublic(pub, 'hex'); // Signature MUST be either: -// 1) hex-string of DER-encoded signature; or +// 1) DER-encoded signature as hex-string; or // 2) DER-encoded signature as buffer; or -// 3) object with two hex-string properties (r and s) +// 3) object with two hex-string properties (r and s); or +// 4) object with two buffer properties (r and s) -var signature = 'b102ac...'; // case 1 +var signature = '3046022100...'; // case 1 var signature = new Buffer('...'); // case 2 var signature = { r: 'b1fc...', s: '9c42...' }; // case 3 -// Import public key -var key = ec.keyFromPublic(pub, 'hex'); - // Verify signature -console.log(key.verify(msg, signature)); +console.log(key.verify(msgHash, signature)); ``` ### EdDSA @@ -98,12 +109,12 @@ var ec = new EdDSA('ed25519'); // Create key pair from secret var key = ec.keyFromSecret('693e3c...'); // hex string, array or Buffer -// Sign message (must be an array, or it'll be treated as a hex sequence) -var msg = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; -var signature = key.sign(msg).toHex(); +// Sign the message's hash (input must be an array, or a hex-string) +var msgHash = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]; +var signature = key.sign(msgHash).toHex(); // Verify signature -console.log(key.verify(msg, signature)); +console.log(key.verify(msgHash, signature)); // CHECK WITH NO PRIVATE KEY @@ -113,7 +124,7 @@ var key = ec.keyFromPublic(pub, 'hex'); // Verify signature var signature = '70bed1...'; -console.log(key.verify(msg, signature)); +console.log(key.verify(msgHash, signature)); ``` ### ECDH |