simple-js-ecdsa
Advanced tools
Comparing version 1.5.0 to 1.5.1
{ | ||
"name": "simple-js-ecdsa", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "easy and light weight ecdsa implementation", | ||
@@ -29,3 +29,3 @@ "main": "./src/index.js", | ||
"bs58": "^4.0.1", | ||
"simple-js-ec-math": "^1.3.2", | ||
"simple-js-ec-math": "^1.4.0", | ||
"simple-js-secp256k1": "github:Azero123/simple-js-secp256k1#master", | ||
@@ -32,0 +32,0 @@ "simple-js-sha2-256": "^1.0.2" |
@@ -51,14 +51,10 @@ const bigInt = require('big-integer') | ||
const x = bigInt(sec1.substr(2, 64), 16) | ||
const y = bigInt(sec1.substr(66, 130), 16) | ||
/* | ||
compressed guide | ||
https://crypto.stackexchange.com/questions/8914/ecdsa-compressed-public-key-point-back-to-uncompressed-public-key-point | ||
𝑍=𝑌/𝑋 | ||
𝑍2+𝑍=𝑋+𝑎+𝑏𝑋2 | ||
𝑌=𝑋𝑍 | ||
const w = secp256k1.b.divmod(x.modPow(2, secp256k1.p), secp256k1.p) | ||
console.log(w) | ||
const z2z = x.add(secp256k1.a).add(w) | ||
console.log(z2z) | ||
*/ | ||
let y = bigInt(sec1.substr(66, 130), 16) | ||
const compressed = (mode === '03' || mode === '02') | ||
if (compressed) { | ||
const y2 = secp256k1.modSet.add(secp256k1.modSet.power(x, 3), secp256k1.b) | ||
y = secp256k1.modSet.squareRoots(y2)[mode === '03' ? 1 : 0] | ||
} | ||
const identity = new Identity() | ||
@@ -69,3 +65,4 @@ identity.curve = curve | ||
(mode === '04' && sec1.length !== 130) || | ||
((mode === '03' || mode === '02') && sec1.length !== 66) || | ||
(compressed && sec1.length !== 66) || | ||
(mode !== '04' && mode !== '03' && mode !== '02') || | ||
!secp256k1.verify(identity.publicPoint) | ||
@@ -72,0 +69,0 @@ ) { |
@@ -148,3 +148,2 @@ try { | ||
;(()=>{ | ||
const Identity = require('../src/index.js') | ||
const identity = Identity.fromWif('5JJQHQSZP9z5wHjerG8QL3mPXVpCgrWR8dw1TfiJHhjR5DieHTX') | ||
@@ -213,7 +212,7 @@ if (identity.sec1Compressed !== '02d2cb1636c8800502112f346f10a62e256d42b5ea46b3a55e2ff4607167afd2fd') { | ||
// threwError = false | ||
// try { Identity.fromSec1(identity.sec1Compressed) } catch (e) { threwError = true; console.error(e) } | ||
// if (threwError) { | ||
// throw 'should not have thrown an error when making an identity from sec1 format (compressed)' | ||
// } | ||
threwError = false | ||
try { Identity.fromSec1(identity.sec1Compressed) } catch (e) { threwError = true; console.error(e) } | ||
if (threwError) { | ||
throw 'should not have thrown an error when making an identity from sec1 format (compressed)' | ||
} | ||
@@ -228,8 +227,7 @@ threwError = false | ||
try { | ||
const sec1 = identity.sec1Compressed.replace('8800', '1111') | ||
sec1[8] = '3' | ||
const sec1 = identity.sec1Uncompressed.replace('8800', '1111') | ||
Identity.fromSec1(sec1) | ||
} catch (e) { threwError = true; } | ||
} catch (e) { threwError = true } | ||
if (!threwError) { | ||
throw 'should have thrown an error when provided a bad sec1 point (compressed)' | ||
throw 'should have thrown an error when provided a bad sec1 point (uncompressed)' | ||
} | ||
@@ -239,11 +237,8 @@ | ||
try { | ||
const sec1 = identity.sec1Uncompressed.replace('8800', '1111') | ||
const sec1 = identity.sec1Uncompressed.replace('04', '05') | ||
Identity.fromSec1(sec1) | ||
} catch (e) { threwError = true } | ||
} catch (e) { threwError = true; } | ||
if (!threwError) { | ||
throw 'should have thrown an error when provided a bad sec1 point (uncompressed)' | ||
throw 'should have thrown an error when provided a bad sec1 format' | ||
} | ||
console.log('✅ formats passed') | ||
@@ -250,0 +245,0 @@ })() |
Sorry, the diff of this file is not supported yet
45799
835
Updatedsimple-js-ec-math@^1.4.0