Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subtle undefined fix #227

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
'use strict'

var floor = Math.floor

exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes')

exports.getRandomValues = function getRandomValues(abv) {
var l = abv.length
while (l--) {
var bytes = exports.randomBytes(7)
var randomFloat = (bytes[0] % 32) / 32

for (var i = 0; i < bytes.length; i++) {
var byte = bytes[i]
randomFloat = (randomFloat + byte) / 256
}

abv[l] = floor(randomFloat * 256)
}
return abv
}

exports.randomUUID = function randomUUID() {
return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, function (c) {
return (c ^ (exports.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
})
}

exports.createHash = exports.Hash = require('create-hash')
exports.createHmac = exports.Hmac = require('create-hmac')

Expand Down Expand Up @@ -65,6 +90,10 @@ exports.privateDecrypt = publicEncrypt.privateDecrypt
// }
// })

var { Crypto } = require('@peculiar/webcrypto')
var crypto = new Crypto()
exports.webcrypto = crypto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peculiar/webcrypto seems not browser compatible as it says in their README:

Module is based on NodeJS v10 Crypto API. It would work only with Node v10 and higher.


var rf = require('randomfill')

exports.randomFill = rf.randomFill
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"pbkdf2": "^3.0.3",
"public-encrypt": "^4.0.0",
"randombytes": "^2.0.0",
"randomfill": "^1.0.3"
"randomfill": "^1.0.3",
"@peculiar/webcrypto": "1.4.3"
},
"devDependencies": {
"hash-test-vectors": "~1.3.2",
Expand Down