mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
Removed from derive decomposing of the subtle methods
This commit is contained in:
parent
e4b396a45d
commit
9c2fd0607e
10
sea.js
10
sea.js
@ -497,7 +497,7 @@
|
||||
// Derive shared secret from other's pub and my epub/epriv
|
||||
async derive(pub, { epub, epriv }) {
|
||||
try {
|
||||
const { importKey, deriveKey, exportKey } = ossl || subtle
|
||||
const ecdhSubtle = ossl || subtle
|
||||
const keystoecdhjwk = (pub, priv) => {
|
||||
const [ x, y ] = Buffer.from(pub, 'base64').toString('utf8').split(':')
|
||||
const jwk = priv ? { d: priv, key_ops: ['decrypt'] } : { key_ops: ['encrypt'] }
|
||||
@ -509,13 +509,13 @@
|
||||
y
|
||||
})
|
||||
}
|
||||
const pubLic = await importKey('jwk', keystoecdhjwk(pub), ecdhKeyProps, false, ['deriveKey'])
|
||||
const pubLic = await ecdhSubtle.importKey('jwk', keystoecdhjwk(pub), ecdhKeyProps, false, ['deriveKey'])
|
||||
const props = Object.assign({}, ecdhKeyProps, { public: pubLic })
|
||||
const derived = await importKey('jwk', keystoecdhjwk(epub, epriv), ecdhKeyProps, false, ['deriveKey'])
|
||||
const derived = await ecdhSubtle.importKey('jwk', keystoecdhjwk(epub, epriv), ecdhKeyProps, false, ['deriveKey'])
|
||||
.then(async (privKey) => {
|
||||
// privateKey scope doesn't leak out from here!
|
||||
const derivedKey = await deriveKey(props, privKey, { name: 'AES-CBC', length: 256 }, true, [ 'encrypt', 'decrypt' ])
|
||||
return exportKey('jwk', derivedKey).then(({ k }) => k)
|
||||
const derivedKey = await ecdhSubtle.deriveKey(props, privKey, { name: 'AES-CBC', length: 256 }, true, [ 'encrypt', 'decrypt' ])
|
||||
return ecdhSubtle.exportKey('jwk', derivedKey).then(({ k }) => k)
|
||||
})
|
||||
return derived
|
||||
} catch (e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user