Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@bochilteam/scraper/lib/esm/encryptions/crypto.js
1126 views
1
import crypto from 'crypto';
2
export function randomUUID(opts) {
3
if (typeof crypto.randomUUID === 'function') {
4
return crypto.randomUUID(opts);
5
}
6
const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
7
let poolPtr = rnds8Pool.length;
8
if (poolPtr > rnds8Pool.length - 16) {
9
crypto.randomFillSync(rnds8Pool);
10
poolPtr = 0;
11
}
12
// eslint-disable-next-line prefer-const
13
let rnds = rnds8Pool.slice(poolPtr, (poolPtr += 16));
14
rnds[6] = (rnds[6] & 0x0f) | 0x40;
15
rnds[8] = (rnds[8] & 0x3f) | 0x80;
16
return serializeUUID(rnds);
17
}
18
export function randomBytes(size) {
19
return crypto.randomBytes(size).toString('hex');
20
}
21
export function createHash(algorithm /* 'md4' | 'md5' | 'sha1' | 'sha256' | 'sha512 */, data) {
22
return crypto.createHash(algorithm).update(data).digest('hex');
23
}
24
const kHexBytes = [];
25
for (let i = 0; i < 256; ++i) {
26
kHexBytes.push((i + 0x100).toString(16).substr(1));
27
}
28
function serializeUUID(buf, offset = 0) {
29
return (kHexBytes[buf[offset]] +
30
kHexBytes[buf[offset + 1]] +
31
kHexBytes[buf[offset + 2]] +
32
kHexBytes[buf[offset + 3]] +
33
'-' +
34
kHexBytes[buf[offset + 4]] +
35
kHexBytes[buf[offset + 5]] +
36
'-' +
37
kHexBytes[(buf[offset + 6] & 0x0f) | 0x40] +
38
kHexBytes[buf[offset + 7]] +
39
'-' +
40
kHexBytes[(buf[offset + 8] & 0x3f) | 0x80] +
41
kHexBytes[buf[offset + 9]] +
42
'-' +
43
kHexBytes[buf[offset + 10]] +
44
kHexBytes[buf[offset + 11]] +
45
kHexBytes[buf[offset + 12]] +
46
kHexBytes[buf[offset + 13]] +
47
kHexBytes[buf[offset + 14]] +
48
kHexBytes[buf[offset + 15]]).toLowerCase();
49
}
50
//# sourceMappingURL=crypto.js.map
51