Skip to content

Instantly share code, notes, and snippets.

@matiu matiu/check.js
Created Mar 7, 2019

What would you like to do?
Checking a jsonPaymentProtocol signature witih bitcore-lib
const B = require('bitcore-lib');
// Example signature, from an actual jsonPaymentProtocol header.
const h ='6d580c9bc2fbaff7614e3a030d536417d07d6dfb93f7c8887aac4e67e27c3e32';
const s ='e7a6490572855eb8feedabe32872424a2aef5b0b0f6e8b7d1959f6621de8c15a3871283a8fa78fc292444c50dc578dc58bd924d947f2ecc4bb91c250885a518a';
const p ='03159069584176096f1c89763488b94dbc8d5e1fa7bf91f50b42f4befe4e45295a';
hbuf = Buffer.from(h,'hex');
sbuf = Buffer.from(s,'hex');
pbuf = Buffer.from(p,'hex');
// Signature is in the form: r[0..31]s[0..31]
// split it and convert it to a Bitcore Signature
s_r = new Buffer(32);
s_s = new Buffer(32);
s_rBN = B.crypto.BN.fromBuffer(s_r);
s_sBN = B.crypto.BN.fromBuffer(s_s);
sig = new B.crypto.Signature();
sig.set({r: s_rBN, s: s_sBN});
// Public key
pub = B.PublicKey.fromBuffer(pbuf);
console.log('Bitcore VERIFY:', B.crypto.ECDSA.verify(hbuf, sig, pub));
// => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.