@bevel-software/platform-shared 0.37.0 → 0.38.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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * SHA-256 (FIPS 180-4) of a string's UTF-8 bytes, as lowercase hex.
3
+ *
4
+ * Synchronous and dependency-free, so the same digest is derivable in any
5
+ * browser context and on the server. `crypto.subtle` is not that: a browser
6
+ * offers it only in a secure context, so a deployment reached over plain
7
+ * HTTP would have no digest at all.
8
+ */
9
+ /** The digest of `text` exactly as given, nothing trimmed or normalised (a lone surrogate is U+FFFD, as `TextEncoder` writes it). */
10
+ export declare function sha256Hex(text: string): string;
11
+ //# sourceMappingURL=sha256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../../src/hash/sha256.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAeH,qIAAqI;AACrI,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA4C9C"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * SHA-256 (FIPS 180-4) of a string's UTF-8 bytes, as lowercase hex.
3
+ *
4
+ * Synchronous and dependency-free, so the same digest is derivable in any
5
+ * browser context and on the server. `crypto.subtle` is not that: a browser
6
+ * offers it only in a secure context, so a deployment reached over plain
7
+ * HTTP would have no digest at all.
8
+ */
9
+ const K = new Uint32Array([
10
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
11
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
12
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
13
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
14
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
15
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
16
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
17
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
18
+ ]);
19
+ const utf8 = new TextEncoder();
20
+ /** The digest of `text` exactly as given, nothing trimmed or normalised (a lone surrogate is U+FFFD, as `TextEncoder` writes it). */
21
+ export function sha256Hex(text) {
22
+ const bytes = utf8.encode(text);
23
+ const bitLength = bytes.length * 8;
24
+ // The message, a 1 bit, zeros, and the 64-bit length: a whole number of 64-byte blocks.
25
+ const padded = new Uint8Array((((bytes.length + 8) >> 6) + 1) << 6);
26
+ padded.set(bytes);
27
+ padded[bytes.length] = 0x80;
28
+ const view = new DataView(padded.buffer);
29
+ view.setUint32(padded.length - 8, Math.floor(bitLength / 0x1_0000_0000));
30
+ view.setUint32(padded.length - 4, bitLength >>> 0);
31
+ const h = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
32
+ const w = new Uint32Array(64);
33
+ const rotr = (x, n) => (x >>> n) | (x << (32 - n));
34
+ for (let offset = 0; offset < padded.length; offset += 64) {
35
+ for (let i = 0; i < 16; i++)
36
+ w[i] = view.getUint32(offset + i * 4);
37
+ for (let i = 16; i < 64; i++) {
38
+ const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
39
+ const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
40
+ w[i] = w[i - 16] + s0 + w[i - 7] + s1;
41
+ }
42
+ let [a, b, c, d, e, f, g, hh] = h;
43
+ for (let i = 0; i < 64; i++) {
44
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
45
+ const ch = (e & f) ^ (~e & g);
46
+ const t1 = (hh + S1 + ch + K[i] + w[i]) >>> 0;
47
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
48
+ const maj = (a & b) ^ (a & c) ^ (b & c);
49
+ const t2 = (S0 + maj) >>> 0;
50
+ hh = g;
51
+ g = f;
52
+ f = e;
53
+ e = (d + t1) >>> 0;
54
+ d = c;
55
+ c = b;
56
+ b = a;
57
+ a = (t1 + t2) >>> 0;
58
+ }
59
+ // A Uint32Array keeps each sum modulo 2^32.
60
+ [a, b, c, d, e, f, g, hh].forEach((x, i) => {
61
+ h[i] = h[i] + x;
62
+ });
63
+ }
64
+ return Array.from(h, (x) => x.toString(16).padStart(8, '0')).join('');
65
+ }
66
+ //# sourceMappingURL=sha256.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.js","sourceRoot":"","sources":["../../src/hash/sha256.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,GAAG,IAAI,WAAW,CAAC;IACxB,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAA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AAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;YACnB,CAAC,GAAG,CAAC,CAAC;YACN,CAAC,GAAG,CAAC,CAAC;YACN,CAAC,GAAG,CAAC,CAAC;YACN,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,4CAA4C;QAC5C,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACzC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACxE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from './workspace/placeholder.js';
13
13
  export * from './workspace/frontmatter-carriers.js';
14
14
  export * from './workspace/platform-files.js';
15
15
  export * from './workspace/access-verbs.js';
16
+ export * from './hash/sha256.js';
16
17
  export * from './git/types.js';
17
18
  export * from './git/pr.types.js';
18
19
  export * from './git/protected.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAG1C,cAAc,iBAAiB,CAAC;AAGhC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc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 export * from './workspace/placeholder.js';
16
16
  export * from './workspace/frontmatter-carriers.js';
17
17
  export * from './workspace/platform-files.js';
18
18
  export * from './workspace/access-verbs.js';
19
+ // Hashing
20
+ export * from './hash/sha256.js';
19
21
  // Git
20
22
  export * from './git/types.js';
21
23
  export * from './git/pr.types.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO;AACP,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAE1C,OAAO;AACP,cAAc,iBAAiB,CAAC;AAEhC,YAAY;AACZ,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAE5C,MAAM;AACN,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qCAAqC,CAAC;AAEpD,sFAAsF;AACtF,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO;AACP,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAE1C,OAAO;AACP,cAAc,iBAAiB,CAAC;AAEhC,YAAY;AACZ,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAE5C,UAAU;AACV,cAAc,kBAAkB,CAAC;AAEjC,MAAM;AACN,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qCAAqC,CAAC;AAEpD,sFAAsF;AACtF,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bevel-software/platform-shared",
3
- "version": "0.37.0",
3
+ "version": "0.38.0",
4
4
  "description": "Shared types and pure domain utilities of the Bevel core platform (auth, workspace, git/version-control contracts, branch registry).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -0,0 +1,68 @@
1
+ /**
2
+ * SHA-256 (FIPS 180-4) of a string's UTF-8 bytes, as lowercase hex.
3
+ *
4
+ * Synchronous and dependency-free, so the same digest is derivable in any
5
+ * browser context and on the server. `crypto.subtle` is not that: a browser
6
+ * offers it only in a secure context, so a deployment reached over plain
7
+ * HTTP would have no digest at all.
8
+ */
9
+
10
+ const K = new Uint32Array([
11
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
12
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
13
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
14
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
15
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
16
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
17
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
18
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
19
+ ]);
20
+
21
+ const utf8 = new TextEncoder();
22
+
23
+ /** The digest of `text` exactly as given, nothing trimmed or normalised (a lone surrogate is U+FFFD, as `TextEncoder` writes it). */
24
+ export function sha256Hex(text: string): string {
25
+ const bytes = utf8.encode(text);
26
+ const bitLength = bytes.length * 8;
27
+ // The message, a 1 bit, zeros, and the 64-bit length: a whole number of 64-byte blocks.
28
+ const padded = new Uint8Array((((bytes.length + 8) >> 6) + 1) << 6);
29
+ padded.set(bytes);
30
+ padded[bytes.length] = 0x80;
31
+ const view = new DataView(padded.buffer);
32
+ view.setUint32(padded.length - 8, Math.floor(bitLength / 0x1_0000_0000));
33
+ view.setUint32(padded.length - 4, bitLength >>> 0);
34
+
35
+ const h = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
36
+ const w = new Uint32Array(64);
37
+ const rotr = (x: number, n: number) => (x >>> n) | (x << (32 - n));
38
+ for (let offset = 0; offset < padded.length; offset += 64) {
39
+ for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4);
40
+ for (let i = 16; i < 64; i++) {
41
+ const s0 = rotr(w[i - 15]!, 7) ^ rotr(w[i - 15]!, 18) ^ (w[i - 15]! >>> 3);
42
+ const s1 = rotr(w[i - 2]!, 17) ^ rotr(w[i - 2]!, 19) ^ (w[i - 2]! >>> 10);
43
+ w[i] = w[i - 16]! + s0 + w[i - 7]! + s1;
44
+ }
45
+ let [a, b, c, d, e, f, g, hh] = h;
46
+ for (let i = 0; i < 64; i++) {
47
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
48
+ const ch = (e & f) ^ (~e & g);
49
+ const t1 = (hh + S1 + ch + K[i]! + w[i]!) >>> 0;
50
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
51
+ const maj = (a & b) ^ (a & c) ^ (b & c);
52
+ const t2 = (S0 + maj) >>> 0;
53
+ hh = g;
54
+ g = f;
55
+ f = e;
56
+ e = (d + t1) >>> 0;
57
+ d = c;
58
+ c = b;
59
+ b = a;
60
+ a = (t1 + t2) >>> 0;
61
+ }
62
+ // A Uint32Array keeps each sum modulo 2^32.
63
+ [a, b, c, d, e, f, g, hh].forEach((x, i) => {
64
+ h[i] = h[i]! + x;
65
+ });
66
+ }
67
+ return Array.from(h, (x) => x.toString(16).padStart(8, '0')).join('');
68
+ }
package/src/index.ts CHANGED
@@ -19,6 +19,9 @@ export * from './workspace/frontmatter-carriers.js';
19
19
  export * from './workspace/platform-files.js';
20
20
  export * from './workspace/access-verbs.js';
21
21
 
22
+ // Hashing
23
+ export * from './hash/sha256.js';
24
+
22
25
  // Git
23
26
  export * from './git/types.js';
24
27
  export * from './git/pr.types.js';