Skip to content

Commit

Permalink
Merge pull request #8 from github/dg/secure-random
Browse files Browse the repository at this point in the history
Use crypto api for uuid generation
  • Loading branch information
dgreif authored Aug 15, 2024
2 parents f1a9375 + 37ce07d commit 688aa81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions target/braintree-1.3.10.js
Original file line number Diff line number Diff line change
Expand Up @@ -3734,7 +3734,7 @@ function isArray(value) {

function generateUUID() { // RFC 4122 v4 (pseudo-random) UUID without hyphens
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function (xORy) {
var randomHex = Math.floor(Math.random() * 16);
var randomHex = crypto.getRandomValues(new Uint8Array(1))[0] % 16;
var uuidHex = xORy === 'x' ? randomHex : randomHex & 0x3 | 0x8; // jshint ignore:line
return uuidHex.toString(16);
});
Expand Down Expand Up @@ -4786,7 +4786,7 @@ module.exports = {
// RFC 4122 v4 (pseudo-random) UUID
function generate() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0;
var r = crypto.getRandomValues(new Uint8Array(1))[0] % 16;
var v = c === 'x' ? r : r & 0x3 | 0x8;
return v.toString(16);
});
Expand Down Expand Up @@ -6127,7 +6127,7 @@ module.exports = eventEnum;

function _uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0;
var r = crypto.getRandomValues(new Uint8Array(1))[0] % 16;
var v = c === 'x' ? r : r & 0x3 | 0x8;
return v.toString(16);
});
Expand Down Expand Up @@ -10773,7 +10773,7 @@ function generateUid() {
var uid = '';

for (i = 0; i < 32; i++) {
r = Math.floor(Math.random() * 16);
r = crypto.getRandomValues(new Uint8Array(1))[0] % 16;
uid += r.toString(16);
}

Expand Down

0 comments on commit 688aa81

Please sign in to comment.