fix SEA pair typo

This commit is contained in:
Mark Nadal 2018-06-14 11:26:56 -07:00
parent 0449bbafa0
commit 26a4d7e02d
2 changed files with 16 additions and 23 deletions

2
gun.js
View File

@ -400,7 +400,7 @@
return n; return n;
} }
State.to = function(from, k, to){ State.to = function(from, k, to){
var val = from[k]; var val = from[k]; // BUGGY!
if(obj_is(val)){ if(obj_is(val)){
val = obj_copy(val); val = obj_copy(val);
} }

37
sea.js
View File

@ -45,7 +45,7 @@
function SeaArray() {} function SeaArray() {}
Object.assign(SeaArray, { from: Array.from }) Object.assign(SeaArray, { from: Array.from })
SeaArray.prototype = Object.create(Array.prototype) SeaArray.prototype = Object.create(Array.prototype)
SeaArray.prototype.toString = function(enc = 'utf8', start = 0, end) { SeaArray.prototype.toString = function(enc, start, end) { enc = enc || 'utf8'; start = start || 0;
const length = this.length const length = this.length
if (enc === 'hex') { if (enc === 'hex') {
const buf = new Uint8Array(this) const buf = new Uint8Array(this)
@ -342,47 +342,40 @@
const ecdhSubtle = shim.ossl || shim.subtle const ecdhSubtle = shim.ossl || shim.subtle
// First: ECDSA keys for signing/verifying... // First: ECDSA keys for signing/verifying...
const __gky = await shim.subtle.generateKey(S.ecdsa.pair, true, [ 'sign', 'verify' ]) const sa = await shim.subtle.generateKey(S.ecdsa.pair, true, [ 'sign', 'verify' ])
const pub = __gky.pub
const priv = __gky.priv
.then(async (keys) => { .then(async (keys) => {
// privateKey scope doesn't leak out from here! // privateKey scope doesn't leak out from here!
const __gky2 = await shim.subtle.exportKey('jwk', keys.privateKey) //const { d: priv } = await shim.subtle.exportKey('jwk', keys.privateKey)
const priv = __gky2.d const key = {};
const __gky3 = await shim.subtle.exportKey('jwk', keys.publicKey) key.priv = (await shim.subtle.exportKey('jwk', keys.privateKey)).d;
const x = __gky3.x const pub = await shim.subtle.exportKey('jwk', keys.publicKey)
const y = __gky3.y
//const pub = Buff.from([ x, y ].join(':')).toString('base64') // old //const pub = Buff.from([ x, y ].join(':')).toString('base64') // old
const pub = x+'.'+y // new key.pub = pub.x+'.'+pub.y // new
// x and y are already base64 // x and y are already base64
// pub is UTF8 but filename/URL safe (https://www.ietf.org/rfc/rfc3986.txt) // pub is UTF8 but filename/URL safe (https://www.ietf.org/rfc/rfc3986.txt)
// but split on a non-base64 letter. // but split on a non-base64 letter.
return { pub: pub, priv: priv } return key;
}) })
// To include PGPv4 kind of keyId: // To include PGPv4 kind of keyId:
// const pubId = await SEA.keyid(keys.pub) // const pubId = await SEA.keyid(keys.pub)
// Next: ECDH keys for encryption/decryption... // Next: ECDH keys for encryption/decryption...
const __gky4 = await ecdhSubtle.generateKey(S.ecdh, true, ['deriveKey']) const dh = await ecdhSubtle.generateKey(S.ecdh, true, ['deriveKey'])
const epub = __gky4.epub
const epriv = __gky4.epriv
.then(async (keys) => { .then(async (keys) => {
// privateKey scope doesn't leak out from here! // privateKey scope doesn't leak out from here!
const __gky5 = await ecdhSubtle.exportKey('jwk', keys.privateKey) const key = {};
const epriv = __gky5.d key.epriv = (await ecdhSubtle.exportKey('jwk', keys.privateKey)).d;
const __gky6 = await ecdhSubtle.exportKey('jwk', keys.publicKey) const pub = await ecdhSubtle.exportKey('jwk', keys.publicKey)
const x = __gky6.x
const y = __gky6.y
//const epub = Buff.from([ ex, ey ].join(':')).toString('base64') // old //const epub = Buff.from([ ex, ey ].join(':')).toString('base64') // old
const epub = x+'.'+y // new key.epub = pub.x+'.'+pub.y // new
// ex and ey are already base64 // ex and ey are already base64
// epub is UTF8 but filename/URL safe (https://www.ietf.org/rfc/rfc3986.txt) // epub is UTF8 but filename/URL safe (https://www.ietf.org/rfc/rfc3986.txt)
// but split on a non-base64 letter. // but split on a non-base64 letter.
return { epub: epub, epriv: epriv } return key;
}) })
const r = { pub: pub, priv: priv, /* pubId, */ epub: epub, epriv: epriv } const r = { pub: sa.pub, priv: sa.priv, /* pubId, */ epub: dh.epub, epriv: dh.epriv }
if(cb){ cb(r) } if(cb){ cb(r) }
return r; return r;
} catch(e) { } catch(e) {