Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

elliptic test vectors

node v10.24.1
version: master
endpointsharetweet
let elliptic = require('elliptic') let BigNum = require('bn.js') function hexToBytes(array) { // assert(array.length % 2 === 0) return (new BigNum(array, 16)).toArray(null, array.length / 2) } function bytesToHex(array) { return array.map(function(byteValue) { const hex = byteValue.toString(16).toLowerCase() return hex.length > 1 ? hex : '0' + hex }).join('') } let secp256k1 = elliptic.ec('secp256k1')
// https://github.com/btccom/secp256k1-go/blob/f7178bcde5780809c6f819d62c3e7a37c635e749/secp256k1/sign_vectors.yaml#L3-L5 privateKeyBytes = hexToBytes('31a84594060e103f5a63eb742bd46cf5f5900d8406e2726dedfc61c7cf43ebad') messageHash = hexToBytes('9e5755ec2f328cc8635a55415d0e9a09c2b6f2c9b0343c945fbbfe08247a4cbe') signature = secp256k1.sign(messageHash, privateKeyBytes, {canonical: true}) // note: have to remove the trailing 0x01 byte from the test vector signature // https://github.com/btccom/secp256k1-go/issues/2 bytesToHex(signature.toDER()) == '30440220132382ca59240c2e14ee7ff61d90fc63276325f4cbe8169fc53ade4a407c2fc802204d86fbe3bde6975dd5a91fdc95ad6544dcdf0dab206f02224ce7e2b151bd82ab'
// https://github.com/btccom/secp256k1-go/blob/master/secp256k1/sign_vectors.yaml#L8-L10 privateKeyBytes = hexToBytes('39dfc615f2b718397f6903b0c46c47c5687e97d3d2a5e1f2b200f459f7b1219b') messageHash = hexToBytes('dfeb2092955572ce0695aa038f58df5499949e18f58785553c3e83343cd5eb93') signature = secp256k1.sign(messageHash, privateKeyBytes, {canonical: true}) bytesToHex(signature.toDER()) == '30440220692c01edf8aeab271df3ed4e8d57a170f014f8f9d65031aac28b5e1840acfb5602205075f9d1fdbf5079ee052e5f3572d518b3594ef49582899ec44d065f71a55192'
messageDigest = hexToBytes('72433bc7d340eafce749fd7238dce1e638e0109d19ae55348b7c2556619ddc25') privateKeyBytes = hexToBytes('7c17d833b65f64ec6db50da5da1a26e59289df44da6208fdbf7c8136fc5ddaa7') signature = secp256k1.sign(messageHash, privateKeyBytes, {canonical: true}) bytesToHex(signature.toDER())
messageDigest = hexToBytes('34C19028C80D21F3F48C9354895F8D5BF0D5EE7FF457647CF655F5530A3022A7') privateKeyBytes = hexToBytes('AA921417E7E5C299DA4EEC16D1CAA92F19B19F2A68511F68EC73BBB2F5236F3D') signature = secp256k1.sign(messageHash, privateKeyBytes, {canonical: true}) bytesToHex(signature.toDER())
messageDigest = hexToBytes('34C19028C80D21F3F48C9354895F8D5BF0D5EE7FF457647CF655F5530A3022A7') key = secp256k1.keyFromPublic('025096EB12D3E924234E7162369C11D8BF877EDA238778E7A31FF0AAC5D0DBCF37', 'hex') sig1 = hexToBytes('3045022100B49D07F0E934BA468C0EFC78117791408D1FB8B63A6492AD395AC2F360F246600220508739DB0A2EF81676E39F459C8BBB07A09C3E9F9BEB696294D524D479D62740') sig2 = hexToBytes('3046022100B49D07F0E934BA468C0EFC78117791408D1FB8B63A6492AD395AC2F360F24660022100AF78C624F5D107E9891C60BA637444F71A129E47135D36D92AFD39B856601A01') ;[key.verify(messageDigest, sig1), key.verify(messageDigest, sig2)]
Loading…

no comments

    sign in to comment