Skip to content

Commit

Permalink
Use csprng for uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Jan 11, 2022
1 parent 41ca0c1 commit 05391bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/helpers/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"webpack-cli": "3.3.10"
},
"dependencies": {
"@exodus/walletconnect-crypto": "^1.0.1-exodus.0",
"@exodus/walletconnect-encoding": "^1.0.0-exodus.0",
"@exodus/walletconnect-jsonrpc-utils": "^1.0.0-exodus.0",
"@exodus/walletconnect-types": "^1.7.0-exodus.0",
Expand Down
18 changes: 7 additions & 11 deletions packages/helpers/utils/src/misc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as encoding from "@exodus/walletconnect-encoding";
import * as jsonRpcUtils from "@exodus/walletconnect-jsonrpc-utils";
import * as crypto from "@exodus/walletconnect-crypto";

// -- hex -------------------------------------------------- //

Expand All @@ -24,15 +25,10 @@ export function removeHexLeadingZeros(hex: string): string {
export const payloadId = jsonRpcUtils.payloadId;

export function uuid(): string {
const result: string = ((a?: any, b?: any) => {
for (
b = a = "";
a++ < 36;
b += (a * 51) & 52 ? (a ^ 15 ? 8 ^ (Math.random() * (a ^ 20 ? 16 : 4)) : 4).toString(16) : "-"
) {
// empty
}
return b;
})();
return result;
const bytes = crypto.randomBytes(36)
const chars: Array<String> = []
for (let a = 1; a <= 36; a++) {
chars.push((a * 51) & 52 ? (a ^ 15 ? 8 ^ (bytes[a - 1] % (a ^ 20 ? 16 : 4)) : 4).toString(16) : "-")
}
return chars.join('');
}

0 comments on commit 05391bb

Please sign in to comment.