Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 30 additions & 1 deletion 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 (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] = Math.floor(randomFloat * 256)
}
return abv
}

exports.randomUUID = function () {
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;

var rf = require('randomfill')

exports.randomFill = rf.randomFill
Expand Down Expand Up @@ -94,4 +123,4 @@ exports.constants = {
'POINT_CONVERSION_COMPRESSED': 2,
'POINT_CONVERSION_UNCOMPRESSED': 4,
'POINT_CONVERSION_HYBRID': 6
}
}
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