12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- var SEA = require('./root');
- var shim = require('./shim');
- var S = require('./settings');
- SEA.name = SEA.name || (async (cb, opt) => { try {
- if(cb){ try{ cb() }catch(e){console.log(e)} }
- return;
- } catch(e) {
- console.log(e);
- SEA.err = e;
- if(SEA.throw){ throw e }
- if(cb){ cb() }
- return;
- }});
-
- SEA.pair = SEA.pair || (async (cb, opt) => { try {
- var ecdhSubtle = shim.ossl || shim.subtle;
-
- var sa = await shim.subtle.generateKey({name: 'ECDSA', namedCurve: 'P-256'}, true, [ 'sign', 'verify' ])
- .then(async (keys) => {
-
-
- var key = {};
- key.priv = (await shim.subtle.exportKey('jwk', keys.privateKey)).d;
- var pub = await shim.subtle.exportKey('jwk', keys.publicKey);
-
- key.pub = pub.x+'.'+pub.y;
-
-
-
- return key;
- })
-
-
-
-
- try{
- var dh = await ecdhSubtle.generateKey({name: 'ECDH', namedCurve: 'P-256'}, true, ['deriveKey'])
- .then(async (keys) => {
-
- var key = {};
- key.epriv = (await ecdhSubtle.exportKey('jwk', keys.privateKey)).d;
- var pub = await ecdhSubtle.exportKey('jwk', keys.publicKey);
-
- key.epub = pub.x+'.'+pub.y;
-
-
-
- return key;
- })
- }catch(e){
- if(SEA.window){ throw e }
- if(e == 'Error: ECDH is not a supported algorithm'){ console.log('Ignoring ECDH...') }
- else { throw e }
- } dh = dh || {};
- var r = { pub: sa.pub, priv: sa.priv, epub: dh.epub, epriv: dh.epriv }
- if(cb){ try{ cb(r) }catch(e){console.log(e)} }
- return r;
- } catch(e) {
- console.log(e);
- SEA.err = e;
- if(SEA.throw){ throw e }
- if(cb){ cb() }
- return;
- }});
- module.exports = SEA.pair;
-
|