From 6dc98d1db967082e4c5e050b871570935bca08c5 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Tue, 6 Nov 2018 12:57:57 -0500 Subject: [PATCH] ensure proper XY coordinate generation from key for contact code --- app/utils/ecdsa.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/utils/ecdsa.js b/app/utils/ecdsa.js index 84359b2..743b7e3 100644 --- a/app/utils/ecdsa.js +++ b/app/utils/ecdsa.js @@ -2,18 +2,18 @@ import { ec } from 'elliptic'; const EC = new ec('secp256k1'); -export const generateXY = pub => { - const stripped = pub.slice(2); - const key = EC.keyFromPublic(stripped, 'hex'); - const pubPoint = key.getPublic(); - const x = '0x' + pubPoint.getX().toString(16); - const y = '0x'+ pubPoint.getY().toString(16); - return { x, y }; +export function generateXY (pub) { + const stripped = pub.slice(2) + const key = EC.keyFromPublic(stripped, 'hex') + const pubPoint = key.getPublic() + const x = '0x' + pubPoint.getX().toString(16, 64) + const y = '0x'+ pubPoint.getY().toString(16, 64) + return { x, y } } -export const keyFromXY = (X, Y) => { - const x = Buffer.from(X.substring(2), 'hex'); - const y = Buffer.from(Y.substring(2), 'hex'); - const keys = EC.keyFromPublic({ x, y }, 'hex'); - return `0x${keys.getPublic().encode('hex')}`; +export function keyFromXY (X, Y) { + const x = Buffer.from(X.substring(2), 'hex') + const y = Buffer.from(Y.substring(2), 'hex') + const keys = EC.keyFromPublic({ x, y }, 'hex') + return `0x${keys.getPublic().encode('hex')}` }