Skip to content

Commit

Permalink
fix: force use of isomorphiccrypto on react-native
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Jan 7, 2020
1 parent 4b14e7c commit f287887
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sea.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
var o = {};

if(SEA.window){
api.crypto = window.crypto || window.msCrypto || require('isomorphic-webcrypto');
api.crypto = navigator && navigator.product === 'ReactNative' ? require('isomorphic-webcrypto') : window.crypto || window.msCrypto || require('isomorphic-webcrypto');
api.subtle = (api.crypto||o).subtle || (api.crypto||o).webkitSubtle;
api.TextEncoder = window.TextEncoder;
api.TextDecoder = window.TextDecoder;
Expand Down
2 changes: 1 addition & 1 deletion sea/pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
// Next: ECDH keys for encryption/decryption...

try{
var dh = await ecdhSubtle.generateKey({name: 'ECDH', namedCurve: 'P-256'};, true, ['deriveKey'])
var dh = await ecdhSubtle.generateKey({name: 'ECDH', namedCurve: 'P-256'}, true, ['deriveKey'])
.then(async (keys) => {
// privateKey scope doesn't leak out from here!
var key = {};
Expand Down
4 changes: 2 additions & 2 deletions sea/secret.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
var epriv = pair.epriv;
var ecdhSubtle = shim.ossl || shim.subtle;
var pubKeyData = keysToEcdhJwk(pub);
var props = Object.assign({ public: await ecdhSubtle.importKey(...pubKeyData, true, []) },{name: 'ECDH', namedCurve: 'P-256'};); // Thanks to @sirpy !
var props = Object.assign({ public: await ecdhSubtle.importKey(...pubKeyData, true, []) },{name: 'ECDH', namedCurve: 'P-256'}); // Thanks to @sirpy !
var privKeyData = keysToEcdhJwk(epub, epriv);
var derived = await ecdhSubtle.importKey(...privKeyData, false, ['deriveBits']).then(async (privKey) => {
// privateKey scope doesn't leak out from here!
Expand Down Expand Up @@ -44,7 +44,7 @@
jwk,
{ x: x, y: y, kty: 'EC', crv: 'P-256', ext: true }
), // ??? refactor
{name: 'ECDH', namedCurve: 'P-256'};
{name: 'ECDH', namedCurve: 'P-256'}
]
}

Expand Down
2 changes: 1 addition & 1 deletion sea/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var o = {};

if(SEA.window){
api.crypto = window.crypto || window.msCrypto || require('isomorphic-webcrypto');
api.crypto = navigator && navigator.product === 'ReactNative' ? require('isomorphic-webcrypto') : window.crypto || window.msCrypto || require('isomorphic-webcrypto');
api.subtle = (api.crypto||o).subtle || (api.crypto||o).webkitSubtle;
api.TextEncoder = window.TextEncoder;
api.TextDecoder = window.TextDecoder;
Expand Down

0 comments on commit f287887

Please sign in to comment.