@statsig/sha256 3.26.0 → 3.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/base64.d.ts +4 -0
- package/src/base64.js +50 -0
- package/src/index.d.ts +2 -1
- package/src/index.js +3 -1
package/package.json
CHANGED
package/src/base64.d.ts
ADDED
package/src/base64.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Base64 = void 0;
|
|
4
|
+
// Encoding logic from https://stackoverflow.com/a/246813/1524355, with slight modifications to make it work for binary strings
|
|
5
|
+
const KEY_STR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
6
|
+
class Base64 {
|
|
7
|
+
static encodeArrayBuffer(buffer) {
|
|
8
|
+
let binary = '';
|
|
9
|
+
const bytes = new Uint8Array(buffer);
|
|
10
|
+
const len = bytes.byteLength;
|
|
11
|
+
for (let i = 0; i < len; i++) {
|
|
12
|
+
binary += String.fromCharCode(bytes[i]);
|
|
13
|
+
}
|
|
14
|
+
return this._encodeBinary(binary);
|
|
15
|
+
}
|
|
16
|
+
static _encodeBinary(value) {
|
|
17
|
+
let output = '';
|
|
18
|
+
let chr1;
|
|
19
|
+
let chr2;
|
|
20
|
+
let chr3;
|
|
21
|
+
let enc1;
|
|
22
|
+
let enc2;
|
|
23
|
+
let enc3;
|
|
24
|
+
let enc4;
|
|
25
|
+
let i = 0;
|
|
26
|
+
while (i < value.length) {
|
|
27
|
+
chr1 = value.charCodeAt(i++);
|
|
28
|
+
chr2 = value.charCodeAt(i++);
|
|
29
|
+
chr3 = value.charCodeAt(i++);
|
|
30
|
+
enc1 = chr1 >> 2;
|
|
31
|
+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
|
32
|
+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
|
33
|
+
enc4 = chr3 & 63;
|
|
34
|
+
if (isNaN(chr2)) {
|
|
35
|
+
enc3 = enc4 = 64;
|
|
36
|
+
}
|
|
37
|
+
else if (isNaN(chr3)) {
|
|
38
|
+
enc4 = 64;
|
|
39
|
+
}
|
|
40
|
+
output =
|
|
41
|
+
output +
|
|
42
|
+
KEY_STR.charAt(enc1) +
|
|
43
|
+
KEY_STR.charAt(enc2) +
|
|
44
|
+
KEY_STR.charAt(enc3) +
|
|
45
|
+
KEY_STR.charAt(enc4);
|
|
46
|
+
}
|
|
47
|
+
return output;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Base64 = Base64;
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SHA256 = void 0;
|
|
3
|
+
exports.Base64 = exports.SHA256 = void 0;
|
|
4
|
+
const base64_1 = require("./base64");
|
|
5
|
+
Object.defineProperty(exports, "Base64", { enumerable: true, get: function () { return base64_1.Base64; } });
|
|
4
6
|
const sha256_1 = require("./sha256");
|
|
5
7
|
Object.defineProperty(exports, "SHA256", { enumerable: true, get: function () { return sha256_1.SHA256; } });
|