This repository has been archived by the owner on Sep 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.DS_Store | ||
webcrypto-shim.mjs | ||
|
||
# Logs | ||
logs | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./react-native.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./react-native.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./react-native.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./react-native.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./browser') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./index') |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const generateSecureRandom = require('react-native-securerandom').generateSecureRandom | ||
const EventEmitter = require('mitt') | ||
const crypto = require('msrcrypto') | ||
crypto.subtle.forceSync = true | ||
|
||
const secureWatch = new EventEmitter() | ||
|
||
let secured = !crypto.initPrng | ||
let secureRandomError | ||
if (!secured) { | ||
generateSecureRandom(48) | ||
.then(byteArray => { | ||
crypto.initPrng(Array.from(byteArray)) | ||
secured = true | ||
secureWatch.emit('secure') | ||
}) | ||
.catch(err => { | ||
secureRandomError = err | ||
secureWatch.emit('secureRandomError') | ||
}) | ||
} | ||
|
||
crypto.ensureSecure = function(cb) { | ||
if (secured) return cb() | ||
if (secureRandomError) return cb(secureRandomError) | ||
secureWatch.on('secure', () => cb()) | ||
secureWatch.on('secureRandomError', () => cb(secureRandomError)) | ||
} | ||
|
||
// wrap all methods to ensure they're secure | ||
const methods = [ | ||
'decrypt', | ||
'digest', | ||
'deriveKey', | ||
'encrypt', | ||
'exportKey', | ||
'generateKey', | ||
'importKey', | ||
'sign', | ||
'unwrapKey', | ||
'verify', | ||
'wrapKey' | ||
] | ||
methods.map(key => { | ||
const original = crypto.subtle[key] | ||
crypto.subtle[key] = function() { | ||
const args = Array.from(arguments) | ||
return new Promise((resolve, reject) => { | ||
crypto.ensureSecure(err => { | ||
if (err) return reject(err) | ||
resolve(original.apply(crypto.subtle, args)) | ||
}) | ||
}) | ||
} | ||
}) | ||
|
||
module.exports = crypto |