diff --git a/app/utils/ecdsa.js b/app/utils/ecdsa.js new file mode 100644 index 0000000..84359b2 --- /dev/null +++ b/app/utils/ecdsa.js @@ -0,0 +1,19 @@ +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 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')}`; +}