@statsig/sha256 0.0.1-beta.8 → 1.0.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/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # Statsig - SHA256
2
2
 
3
- > [!IMPORTANT]
4
- > This version of the SDK is still in beta. The non-beta version can be found [here](https://github.com/statsig-io/js-client).
5
-
6
3
  A SHA 256 implementation used in Statsig Javascript packages.
7
4
 
8
5
  Learn more by visiting: https://docs.statsig.com/client/javascript-sdk
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statsig/sha256",
3
- "version": "0.0.1-beta.8",
3
+ "version": "1.0.0",
4
4
  "dependencies": {},
5
5
  "devDependencies": {
6
6
  "js-sha256": "0.10.1"
@@ -1,4 +1,4 @@
1
1
  export declare abstract class Base64 {
2
2
  static encodeArrayBuffer(buffer: ArrayBuffer): string;
3
- static _encodeBinary(value: string): string;
3
+ private static _encodeBinary;
4
4
  }
@@ -2,29 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Base64 = void 0;
4
4
  // Encoding logic from https://stackoverflow.com/a/246813/1524355, with slight modifications to make it work for binary strings
5
- var KEY_STR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
6
- var Base64 = /** @class */ (function () {
7
- function Base64() {
8
- }
9
- Base64.encodeArrayBuffer = function (buffer) {
10
- var binary = '';
11
- var bytes = new Uint8Array(buffer);
12
- var len = bytes.byteLength;
13
- for (var i = 0; i < len; i++) {
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++) {
14
12
  binary += String.fromCharCode(bytes[i]);
15
13
  }
16
14
  return this._encodeBinary(binary);
17
- };
18
- Base64._encodeBinary = function (value) {
19
- var output = '';
20
- var chr1;
21
- var chr2;
22
- var chr3;
23
- var enc1;
24
- var enc2;
25
- var enc3;
26
- var enc4;
27
- var i = 0;
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;
28
26
  while (i < value.length) {
29
27
  chr1 = value.charCodeAt(i++);
30
28
  chr2 = value.charCodeAt(i++);
@@ -47,7 +45,6 @@ var Base64 = /** @class */ (function () {
47
45
  KEY_STR.charAt(enc4);
48
46
  }
49
47
  return output;
50
- };
51
- return Base64;
52
- }());
48
+ }
49
+ }
53
50
  exports.Base64 = Base64;
package/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SHA256 = void 0;
4
- var sha256_1 = require("./sha256");
4
+ const sha256_1 = require("./sha256");
5
5
  Object.defineProperty(exports, "SHA256", { enumerable: true, get: function () { return sha256_1.SHA256; } });
package/src/sha256.js CHANGED
@@ -5,9 +5,9 @@ function SHA256(input) {
5
5
  return new Sha256().update(input);
6
6
  }
7
7
  exports.SHA256 = SHA256;
8
- var EXTRA = [-2147483648, 8388608, 32768, 128];
9
- var SHIFT = [24, 16, 8, 0];
10
- var K = [
8
+ const EXTRA = [-2147483648, 8388608, 32768, 128];
9
+ const SHIFT = [24, 16, 8, 0];
10
+ const K = [
11
11
  0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
12
12
  0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
13
13
  0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
@@ -20,8 +20,8 @@ var K = [
20
20
  0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
21
21
  0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
22
22
  ];
23
- var Sha256 = /** @class */ (function () {
24
- function Sha256() {
23
+ class Sha256 {
24
+ constructor() {
25
25
  this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
26
26
  this.h0 = 0x6a09e667;
27
27
  this.h1 = 0xbb67ae85;
@@ -36,17 +36,17 @@ var Sha256 = /** @class */ (function () {
36
36
  this.first = true;
37
37
  this.lastByteIndex = -1;
38
38
  }
39
- Sha256.prototype.update = function (message) {
39
+ update(message) {
40
40
  if (this.finalized) {
41
41
  return this;
42
42
  }
43
43
  if (typeof message !== 'string') {
44
44
  throw new Error('Must be of type "string"');
45
45
  }
46
- var code;
47
- var index = 0;
48
- var i;
49
- var length = message.length, blocks = this.blocks;
46
+ let code;
47
+ let index = 0;
48
+ let i;
49
+ const length = message.length, blocks = this.blocks;
50
50
  while (index < length) {
51
51
  if (this.hashed) {
52
52
  this.hashed = false;
@@ -110,13 +110,13 @@ var Sha256 = /** @class */ (function () {
110
110
  this.bytes = this.bytes % 4294967296;
111
111
  }
112
112
  return this;
113
- };
114
- Sha256.prototype.finalize = function () {
113
+ }
114
+ finalize() {
115
115
  if (this.finalized) {
116
116
  return;
117
117
  }
118
118
  this.finalized = true;
119
- var blocks = this.blocks, i = this.lastByteIndex;
119
+ const blocks = this.blocks, i = this.lastByteIndex;
120
120
  blocks[16] = this.block;
121
121
  blocks[i >> 2] |= EXTRA[i & 3];
122
122
  this.block = blocks[16];
@@ -146,10 +146,10 @@ var Sha256 = /** @class */ (function () {
146
146
  blocks[14] = (this.hBytes << 3) | (this.bytes >>> 29);
147
147
  blocks[15] = this.bytes << 3;
148
148
  this.hash();
149
- };
150
- Sha256.prototype.hash = function () {
151
- var blocks = this.blocks;
152
- var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
149
+ }
150
+ hash() {
151
+ const blocks = this.blocks;
152
+ let a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
153
153
  for (j = 16; j < 64; ++j) {
154
154
  // rightrotate
155
155
  t1 = blocks[j - 15];
@@ -242,17 +242,17 @@ var Sha256 = /** @class */ (function () {
242
242
  this.h5 = (this.h5 + f) << 0;
243
243
  this.h6 = (this.h6 + g) << 0;
244
244
  this.h7 = (this.h7 + h) << 0;
245
- };
246
- Sha256.prototype.arrayBuffer = function () {
245
+ }
246
+ arrayBuffer() {
247
247
  return this._getOutputs().buffer;
248
- };
249
- Sha256.prototype.dataView = function () {
248
+ }
249
+ dataView() {
250
250
  return this._getOutputs().dataView;
251
- };
252
- Sha256.prototype._getOutputs = function () {
251
+ }
252
+ _getOutputs() {
253
253
  this.finalize();
254
- var buffer = new ArrayBuffer(32);
255
- var dataView = new DataView(buffer);
254
+ const buffer = new ArrayBuffer(32);
255
+ const dataView = new DataView(buffer);
256
256
  dataView.setUint32(0, this.h0);
257
257
  dataView.setUint32(4, this.h1);
258
258
  dataView.setUint32(8, this.h2);
@@ -261,7 +261,6 @@ var Sha256 = /** @class */ (function () {
261
261
  dataView.setUint32(20, this.h5);
262
262
  dataView.setUint32(24, this.h6);
263
263
  dataView.setUint32(28, this.h7);
264
- return { dataView: dataView, buffer: buffer };
265
- };
266
- return Sha256;
267
- }());
264
+ return { dataView, buffer };
265
+ }
266
+ }