From 11b978f5b9523ab5f8c528d8c11e5b3aaf03270c Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Wed, 16 May 2018 12:01:47 -0700 Subject: [PATCH 1/5] Add initial user.js --- user.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 user.js diff --git a/user.js b/user.js new file mode 100644 index 0000000..1ea6faf --- /dev/null +++ b/user.js @@ -0,0 +1,24 @@ +const { createECDH } = require('crypto'), + secp256k1 = 'secp256k1'; + +class User { + // I think ECDH and ECDSA keys are generally interchangable. + generateKeypair() { + this.ecdh = createECDH('secp256k1'); + this.keys = this.ecdh.generateKeys(); + } + sendBlindedKey() { + // copy the go implementation here: + // https://github.com/securepollingsystem/registrar/blob/c2a8102fc07cdc4f0ea3ae442707d50b3de6fb8f/voter/voter.go#L37 + // + // the bulk of this will be copying the blinding stuff from here: + // https://github.com/securepollingsystem/registrar/blob/c2a8102fc07cdc4f0ea3ae442707d50b3de6fb8f/blind/requester.go#L25 + } + getSignature() { + } +} + +function blindKey(pubKey) { +} + +Object.assign(module.exports, {User, blindKey}); From 31eaeb9741426f64a0a29a23b57820c1ed925a63 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Wed, 16 May 2018 12:02:22 -0700 Subject: [PATCH 2/5] Add initial tests --- test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test.js diff --git a/test.js b/test.js new file mode 100644 index 0000000..4e4d394 --- /dev/null +++ b/test.js @@ -0,0 +1,16 @@ +const assert = require('chai').assert, + {User, blindKey} = require('./user'); + +describe('User', function() { + beforeEach(function() { + this.user = new User(); + }); + + it("generates keys", function() { + this.user.generateKeypair(); + }); + + it('blindKey', function() { + }); +}) + From 801736750a919d58215351f3f366ce0039ab5b19 Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Wed, 16 May 2018 12:02:32 -0700 Subject: [PATCH 3/5] Add mocha and chai dependencies for testing. --- package.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1193d5e..136b977 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,13 @@ "description": "Browser-compatible client for Secure Polling System.", "main": "index.js", "scripts": { - "test": "node test.js" + "test": "mocha" }, "author": "Karissa McKelvey ", "license": "GPL", - "dependencies": { + "dependencies": {}, + "devDependencies": { + "chai": "^4.1.2", + "mocha": "^5.1.1" } } From ddf08cf8ca1f14ad0d97bf4786234bbcde4636ae Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Tue, 22 May 2018 17:44:19 -0700 Subject: [PATCH 4/5] Add bn.js as a dependency --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 136b977..732488f 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,9 @@ }, "author": "Karissa McKelvey ", "license": "GPL", - "dependencies": {}, + "dependencies": { + "bn.js": "^4.11.8" + }, "devDependencies": { "chai": "^4.1.2", "mocha": "^5.1.1" From e541ac43fc34a3ccb5d66bc42b2bba8e2cf7e3dd Mon Sep 17 00:00:00 2001 From: Blake Griffith Date: Tue, 22 May 2018 17:45:07 -0700 Subject: [PATCH 5/5] Add Secp256k parameters. --- user.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/user.js b/user.js index 1ea6faf..ce32292 100644 --- a/user.js +++ b/user.js @@ -21,4 +21,34 @@ class User { function blindKey(pubKey) { } +function newRequest(Q, R, m) { + // https://github.com/securepollingsystem/registrar/blob/c2a8102fc07cdc4f0ea3ae442707d50b3de6fb8f/blind/requester.go#L25 + let a, b, bInv, c; +} + +function randFieldElement() { + // https://github.com/securepollingsystem/registrar/blob/c2a8102fc07cdc4f0ea3ae442707d50b3de6fb8f/blind/random.go#L13 +} + +const BN = require('bn.js'); + +// https://github.com/securepollingsystem/registrar/blob/c2a8102fc07cdc4f0ea3ae442707d50b3de6fb8f/blind/secp256k1.go#L33 +const Secp256kParams = { + p: new BN('FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE FFFFFC2F', 16), + a: new BN('00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000', 16), + b: new BN('00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000007', 16), + // this is the compressed form of G... What does that mean? + G: new BN('02 79BE667E F9DCBBAC 55A06295 CE870B07 029BFCDB 2DCE28D9 59F2815B 16F81798', 16), + n: new BN('FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141', 16), + h: new BN('01', 16), +/* + P: curve.P, + N: curve.N, + B: curve.B, + Gx: curve.Gx, + Gy: curve.Gy, + BitSize: curve.BitSize, +*/ +} + Object.assign(module.exports, {User, blindKey});