mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00

* WIP: use isomorphic-webcrypto for RN * WIP: expo friendly exports * WIP: buffer for RN * WIP: textencoder for RN * WIP: aeskey from jwk instead of raw for RN * fix: missing taglength for msrcrypto * add: update isomorphic-webcrypto * add: match isocrypto api * add: failing test for 4e2 as 400 * fix: remove extra atob btoa * add: sea unbuild * refactor: according to mhelander review * refactor: shorter require * fix: make bug test pass, capitlize bug test. * fix: npm ci + sea test * add: restore old browser export and add react-native friendly exports * fix: import buffer into correct global/window * fix: bad comparison * fix: only include buffer if no btoa/atob
16 lines
655 B
JavaScript
16 lines
655 B
JavaScript
|
|
var shim = require('./shim');
|
|
var S = require('./settings');
|
|
var sha256hash = require('./sha256');
|
|
|
|
const importGen = async (key, salt, opt) => {
|
|
//const combo = shim.Buffer.concat([shim.Buffer.from(key, 'utf8'), salt || shim.random(8)]).toString('utf8') // old
|
|
var opt = opt || {};
|
|
const combo = key + (salt || shim.random(8)).toString('utf8'); // new
|
|
const hash = shim.Buffer.from(await sha256hash(combo), 'binary')
|
|
|
|
const jwkKey = S.keyToJwk(hash)
|
|
return await shim.subtle.importKey('jwk', jwkKey, {name:'AES-GCM'}, false, ['encrypt', 'decrypt'])
|
|
}
|
|
module.exports = importGen;
|
|
|