@g9tm/syncdata 1.2.1

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.
Files changed (149) hide show
  1. package/LICENSE.md +21 -0
  2. package/PARITY.md +71 -0
  3. package/README.md +71 -0
  4. package/THIRD-PARTY-NOTICES.md +31 -0
  5. package/dist/abstractions/digest.d.ts +27 -0
  6. package/dist/abstractions/digest.js +78 -0
  7. package/dist/abstractions/digest.js.map +1 -0
  8. package/dist/abstractions/enums.d.ts +42 -0
  9. package/dist/abstractions/enums.js +60 -0
  10. package/dist/abstractions/enums.js.map +1 -0
  11. package/dist/abstractions/errors.d.ts +72 -0
  12. package/dist/abstractions/errors.js +90 -0
  13. package/dist/abstractions/errors.js.map +1 -0
  14. package/dist/abstractions/guid.d.ts +24 -0
  15. package/dist/abstractions/guid.js +93 -0
  16. package/dist/abstractions/guid.js.map +1 -0
  17. package/dist/abstractions/key.d.ts +16 -0
  18. package/dist/abstractions/key.js +47 -0
  19. package/dist/abstractions/key.js.map +1 -0
  20. package/dist/abstractions/long.d.ts +103 -0
  21. package/dist/abstractions/long.js +351 -0
  22. package/dist/abstractions/long.js.map +1 -0
  23. package/dist/abstractions/parameters.d.ts +49 -0
  24. package/dist/abstractions/parameters.js +153 -0
  25. package/dist/abstractions/parameters.js.map +1 -0
  26. package/dist/brotli-js/decode.d.ts +8 -0
  27. package/dist/brotli-js/decode.js +2004 -0
  28. package/dist/brotli-js/decode.js.map +1 -0
  29. package/dist/brotli-js/index.d.ts +5 -0
  30. package/dist/brotli-js/index.js +19 -0
  31. package/dist/brotli-js/index.js.map +1 -0
  32. package/dist/client/engine.d.ts +110 -0
  33. package/dist/client/engine.js +1158 -0
  34. package/dist/client/engine.js.map +1 -0
  35. package/dist/client/model.d.ts +61 -0
  36. package/dist/client/model.js +154 -0
  37. package/dist/client/model.js.map +1 -0
  38. package/dist/client/progress.d.ts +101 -0
  39. package/dist/client/progress.js +251 -0
  40. package/dist/client/progress.js.map +1 -0
  41. package/dist/client/runs.d.ts +219 -0
  42. package/dist/client/runs.js +239 -0
  43. package/dist/client/runs.js.map +1 -0
  44. package/dist/client/storeTypes.d.ts +428 -0
  45. package/dist/client/storeTypes.js +256 -0
  46. package/dist/client/storeTypes.js.map +1 -0
  47. package/dist/client/transport.d.ts +19 -0
  48. package/dist/client/transport.js +2 -0
  49. package/dist/client/transport.js.map +1 -0
  50. package/dist/index.d.ts +27 -0
  51. package/dist/index.js +35 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/internal/abort.d.ts +21 -0
  54. package/dist/internal/abort.js +125 -0
  55. package/dist/internal/abort.js.map +1 -0
  56. package/dist/internal/base64.d.ts +8 -0
  57. package/dist/internal/base64.js +85 -0
  58. package/dist/internal/base64.js.map +1 -0
  59. package/dist/internal/dotnetFormat.d.ts +32 -0
  60. package/dist/internal/dotnetFormat.js +207 -0
  61. package/dist/internal/dotnetFormat.js.map +1 -0
  62. package/dist/internal/md5.d.ts +2 -0
  63. package/dist/internal/md5.js +97 -0
  64. package/dist/internal/md5.js.map +1 -0
  65. package/dist/internal/sha256.d.ts +20 -0
  66. package/dist/internal/sha256.js +153 -0
  67. package/dist/internal/sha256.js.map +1 -0
  68. package/dist/internal/utf8.d.ts +8 -0
  69. package/dist/internal/utf8.js +143 -0
  70. package/dist/internal/utf8.js.map +1 -0
  71. package/dist/node/index.d.ts +9 -0
  72. package/dist/node/index.js +35 -0
  73. package/dist/node/index.js.map +1 -0
  74. package/dist/node/sqliteDriver.d.ts +11 -0
  75. package/dist/node/sqliteDriver.js +252 -0
  76. package/dist/node/sqliteDriver.js.map +1 -0
  77. package/dist/protocol/dtos.d.ts +280 -0
  78. package/dist/protocol/dtos.js +33 -0
  79. package/dist/protocol/dtos.js.map +1 -0
  80. package/dist/protocol/protocol.d.ts +36 -0
  81. package/dist/protocol/protocol.js +63 -0
  82. package/dist/protocol/protocol.js.map +1 -0
  83. package/dist/protocol/rowBatch/columnLayout.d.ts +4 -0
  84. package/dist/protocol/rowBatch/columnLayout.js +309 -0
  85. package/dist/protocol/rowBatch/columnLayout.js.map +1 -0
  86. package/dist/protocol/rowBatch/format.d.ts +74 -0
  87. package/dist/protocol/rowBatch/format.js +163 -0
  88. package/dist/protocol/rowBatch/format.js.map +1 -0
  89. package/dist/protocol/rowBatch/reader.d.ts +119 -0
  90. package/dist/protocol/rowBatch/reader.js +459 -0
  91. package/dist/protocol/rowBatch/reader.js.map +1 -0
  92. package/dist/protocol/rowBatch/writer.d.ts +101 -0
  93. package/dist/protocol/rowBatch/writer.js +412 -0
  94. package/dist/protocol/rowBatch/writer.js.map +1 -0
  95. package/dist/protocol/wire.d.ts +32 -0
  96. package/dist/protocol/wire.js +329 -0
  97. package/dist/protocol/wire.js.map +1 -0
  98. package/dist/signalr/index.d.ts +2 -0
  99. package/dist/signalr/index.js +5 -0
  100. package/dist/signalr/index.js.map +1 -0
  101. package/dist/signalr/protocols.d.ts +17 -0
  102. package/dist/signalr/protocols.js +109 -0
  103. package/dist/signalr/protocols.js.map +1 -0
  104. package/dist/signalr/transport.d.ts +67 -0
  105. package/dist/signalr/transport.js +286 -0
  106. package/dist/signalr/transport.js.map +1 -0
  107. package/dist/sqlite/apply.d.ts +91 -0
  108. package/dist/sqlite/apply.js +657 -0
  109. package/dist/sqlite/apply.js.map +1 -0
  110. package/dist/sqlite/commands.d.ts +24 -0
  111. package/dist/sqlite/commands.js +167 -0
  112. package/dist/sqlite/commands.js.map +1 -0
  113. package/dist/sqlite/connection.d.ts +81 -0
  114. package/dist/sqlite/connection.js +322 -0
  115. package/dist/sqlite/connection.js.map +1 -0
  116. package/dist/sqlite/driver.d.ts +63 -0
  117. package/dist/sqlite/driver.js +9 -0
  118. package/dist/sqlite/driver.js.map +1 -0
  119. package/dist/sqlite/index.d.ts +6 -0
  120. package/dist/sqlite/index.js +7 -0
  121. package/dist/sqlite/index.js.map +1 -0
  122. package/dist/sqlite/internals.d.ts +63 -0
  123. package/dist/sqlite/internals.js +194 -0
  124. package/dist/sqlite/internals.js.map +1 -0
  125. package/dist/sqlite/options.d.ts +78 -0
  126. package/dist/sqlite/options.js +78 -0
  127. package/dist/sqlite/options.js.map +1 -0
  128. package/dist/sqlite/push.d.ts +9 -0
  129. package/dist/sqlite/push.js +272 -0
  130. package/dist/sqlite/push.js.map +1 -0
  131. package/dist/sqlite/query.d.ts +38 -0
  132. package/dist/sqlite/query.js +476 -0
  133. package/dist/sqlite/query.js.map +1 -0
  134. package/dist/sqlite/revocation.d.ts +28 -0
  135. package/dist/sqlite/revocation.js +337 -0
  136. package/dist/sqlite/revocation.js.map +1 -0
  137. package/dist/sqlite/sql.d.ts +60 -0
  138. package/dist/sqlite/sql.js +324 -0
  139. package/dist/sqlite/sql.js.map +1 -0
  140. package/dist/sqlite/store.d.ts +116 -0
  141. package/dist/sqlite/store.js +664 -0
  142. package/dist/sqlite/store.js.map +1 -0
  143. package/dist/sqlite/values.d.ts +29 -0
  144. package/dist/sqlite/values.js +288 -0
  145. package/dist/sqlite/values.js.map +1 -0
  146. package/dist/testing/index.d.ts +61 -0
  147. package/dist/testing/index.js +175 -0
  148. package/dist/testing/index.js.map +1 -0
  149. package/package.json +104 -0
@@ -0,0 +1,207 @@
1
+ // Invariant-culture number text exactly as .NET writes it, where G9SyncData hashes or stores that text: a computed
2
+ // column's canonical text (G9CSyncDigest.CanonicalText) and the TEXT storage of decimals.
3
+ /**
4
+ * `double.ToString(CultureInfo.InvariantCulture)` (.NET Core 3.0+): the shortest round-trip digits, in fixed notation
5
+ * unless the decimal exponent is 17 or more, or below -4, then `d.dddE+XX` (the golden vectors pin both edges).
6
+ */
7
+ export function formatDouble(value) {
8
+ if (value !== value)
9
+ return 'NaN';
10
+ if (value === Infinity)
11
+ return 'Infinity';
12
+ if (value === -Infinity)
13
+ return '-Infinity';
14
+ if (value === 0)
15
+ return 1 / value < 0 ? '-0' : '0';
16
+ const negative = value < 0;
17
+ // toExponential() without an argument gives the shortest digits that round-trip, like .NET's.
18
+ const text = Math.abs(value).toExponential();
19
+ const e = text.indexOf('e');
20
+ const digits = text.slice(0, e).replace('.', '');
21
+ const exponent = parseInt(text.slice(e + 1), 10);
22
+ const scale = exponent + 1;
23
+ let out;
24
+ if (scale > 17 || scale < -3) {
25
+ const abs = Math.abs(exponent);
26
+ out = digits.charAt(0) + (digits.length > 1 ? '.' + digits.slice(1) : '') + 'E' + (exponent < 0 ? '-' : '+') + (abs < 10 ? '0' : '') + abs;
27
+ }
28
+ else if (scale <= 0) {
29
+ out = '0.' + repeat('0', -scale) + digits;
30
+ }
31
+ else if (scale >= digits.length) {
32
+ out = digits + repeat('0', scale - digits.length);
33
+ }
34
+ else {
35
+ out = digits.slice(0, scale) + '.' + digits.slice(scale);
36
+ }
37
+ return negative ? '-' + out : out;
38
+ }
39
+ function repeat(text, count) {
40
+ let out = '';
41
+ for (let i = 0; i < count; i++)
42
+ out += text;
43
+ return out;
44
+ }
45
+ /** Divides a 96-bit magnitude (three uint32 words, little-endian order) by a small divisor, in place; returns the remainder. */
46
+ function divide96(words, divisor) {
47
+ let remainder = 0;
48
+ for (let i = 2; i >= 0; i--) {
49
+ // Two 16-bit steps keep every intermediate below 2^53.
50
+ const word = words[i];
51
+ let v = remainder * 65536 + (word >>> 16);
52
+ const qHigh = Math.floor(v / divisor);
53
+ remainder = v - qHigh * divisor;
54
+ v = remainder * 65536 + (word & 0xffff);
55
+ const qLow = Math.floor(v / divisor);
56
+ remainder = v - qLow * divisor;
57
+ words[i] = ((qHigh << 16) | qLow) >>> 0;
58
+ }
59
+ return remainder;
60
+ }
61
+ /** `decimal.ToString(CultureInfo.InvariantCulture)`: every digit of the magnitude, the scale kept (`1.50`, `0.000`). */
62
+ export function formatDecimal(parts) {
63
+ const words = [parts.lo >>> 0, parts.mid >>> 0, parts.hi >>> 0];
64
+ let digits = '';
65
+ while (words[0] !== 0 || words[1] !== 0 || words[2] !== 0) {
66
+ const chunk = String(divide96(words, 10000000));
67
+ digits = (words[0] !== 0 || words[1] !== 0 || words[2] !== 0 ? '0000000'.slice(chunk.length) + chunk : chunk) + digits;
68
+ }
69
+ if (digits === '')
70
+ digits = '0';
71
+ const scale = parts.scale;
72
+ if (scale > 0) {
73
+ while (digits.length <= scale)
74
+ digits = '0' + digits;
75
+ digits = digits.slice(0, digits.length - scale) + '.' + digits.slice(digits.length - scale);
76
+ }
77
+ const zero = parts.lo === 0 && parts.mid === 0 && parts.hi === 0;
78
+ return parts.negative && !zero ? '-' + digits : digits;
79
+ }
80
+ const DOUBLE_POWERS_10 = [
81
+ 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22, 1e23, 1e24, 1e25,
82
+ 1e26, 1e27, 1e28,
83
+ ];
84
+ /**
85
+ * `(double)decimal` exactly as .NET computes it (`DecCalc.VarR8FromDec`): `((double)low64 + (double)high · 2^64) /
86
+ * 10^scale`, each step an IEEE double operation, so the result matches .NET to the bit (it is not always the correctly
87
+ * rounded value, and must not be: the server compares what .NET stored).
88
+ */
89
+ export function decimalToDouble(parts) {
90
+ const low64 = (parts.mid >>> 0) * 4294967296 + (parts.lo >>> 0);
91
+ const value = (low64 + (parts.hi >>> 0) * 18446744073709552000) / DOUBLE_POWERS_10[parts.scale];
92
+ return parts.negative ? -value : value;
93
+ }
94
+ /**
95
+ * Parses invariant decimal text (`decimal.Parse(text, NumberStyles.Number | NumberStyles.AllowExponent, Invariant)`
96
+ * for the forms SQLite and .NET produce: sign, digits, one '.', an optional exponent). Digits past 28 significant are
97
+ * rounded half to even… as .NET does (to the 96-bit limit). Returns null for text that is not a number.
98
+ */
99
+ export function parseDecimal(text) {
100
+ var _a, _b;
101
+ const m = /^\s*([+-]?)(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?\s*$/.exec(text);
102
+ if (!m)
103
+ return null;
104
+ const intPart = (_a = m[2]) !== null && _a !== void 0 ? _a : '';
105
+ const fracPart = (_b = m[3]) !== null && _b !== void 0 ? _b : '';
106
+ if (intPart === '' && fracPart === '')
107
+ return null;
108
+ let digits = (intPart + fracPart).replace(/^0+/, '');
109
+ let scale = fracPart.length - (m[4] ? parseInt(m[4], 10) : 0);
110
+ if (digits === '')
111
+ return { lo: 0, mid: 0, hi: 0, scale: Math.max(0, Math.min(28, scale)), negative: m[1] === '-' };
112
+ // Negative scale: append zeros (the value is an integer).
113
+ while (scale < 0) {
114
+ digits += '0';
115
+ scale++;
116
+ }
117
+ // Too many digits for 96 bits or a scale past 28: round away the excess, half to even.
118
+ while (scale > 28 || !fits96(digits)) {
119
+ if (scale === 0)
120
+ return null; // overflow
121
+ const last = digits.charCodeAt(digits.length - 1) - 48;
122
+ digits = digits.slice(0, -1);
123
+ scale--;
124
+ if (last > 5 || (last === 5 && (digits.length === 0 || (digits.charCodeAt(digits.length - 1) - 48) % 2 === 1)))
125
+ digits = incrementDigits(digits);
126
+ if (digits === '')
127
+ digits = '0';
128
+ }
129
+ const words = toWords(digits);
130
+ return { lo: words[0], mid: words[1], hi: words[2], scale, negative: m[1] === '-' };
131
+ }
132
+ function incrementDigits(digits) {
133
+ const chars = digits.split('');
134
+ let i = chars.length - 1;
135
+ while (i >= 0) {
136
+ if (chars[i] === '9') {
137
+ chars[i] = '0';
138
+ i--;
139
+ }
140
+ else {
141
+ chars[i] = String.fromCharCode(chars[i].charCodeAt(0) + 1);
142
+ return chars.join('');
143
+ }
144
+ }
145
+ return '1' + chars.join('');
146
+ }
147
+ const MAX_96 = '79228162514264337593543950335';
148
+ function fits96(digits) {
149
+ const d = digits.replace(/^0+/, '');
150
+ return d.length < MAX_96.length || (d.length === MAX_96.length && d <= MAX_96);
151
+ }
152
+ function toWords(digits) {
153
+ // 16-bit limbs, little-endian; value = value * 10 + digit.
154
+ const limbs = [0, 0, 0, 0, 0, 0];
155
+ for (let i = 0; i < digits.length; i++) {
156
+ let carry = digits.charCodeAt(i) - 48;
157
+ for (let k = 0; k < 6; k++) {
158
+ const v = limbs[k] * 10 + carry;
159
+ limbs[k] = v & 0xffff;
160
+ carry = Math.floor(v / 65536);
161
+ }
162
+ }
163
+ return [
164
+ ((limbs[1] << 16) | limbs[0]) >>> 0,
165
+ ((limbs[3] << 16) | limbs[2]) >>> 0,
166
+ ((limbs[5] << 16) | limbs[4]) >>> 0,
167
+ ];
168
+ }
169
+ /**
170
+ * `(decimal)double` exactly as .NET converts it (`new decimal(double)`, VarDecFromR8): the value rounded to 15
171
+ * significant digits, then trailing zeros dropped. Throws `RangeError` for NaN, infinities and |value| ≥ 7.9e28.
172
+ */
173
+ export function doubleToDecimal(value) {
174
+ if (!isFinite(value))
175
+ throw new RangeError('Value was either too large or too small for a Decimal.');
176
+ if (value === 0)
177
+ return { lo: 0, mid: 0, hi: 0, scale: 0, negative: false };
178
+ if (Math.abs(value) >= 7.9228162514264338e28)
179
+ throw new RangeError('Value was either too large or too small for a Decimal.');
180
+ if (Math.abs(value) < 1e-28)
181
+ return { lo: 0, mid: 0, hi: 0, scale: 0, negative: value < 0 };
182
+ // 15 significant digits (toExponential(14) rounds half-even on the exact binary value, like .NET's double→decimal).
183
+ const text = Math.abs(value).toExponential(14);
184
+ const e = text.indexOf('e');
185
+ let digits = text.slice(0, e).replace('.', '');
186
+ const exponent = parseInt(text.slice(e + 1), 10);
187
+ digits = digits.replace(/0+$/, '');
188
+ if (digits === '')
189
+ digits = '0';
190
+ // value = digits × 10^(exponent − (digits.length − 1))
191
+ let scale = digits.length - 1 - exponent;
192
+ if (scale > 28) {
193
+ // Fewer digits fit: drop to scale 28 with rounding.
194
+ const parsed = parseDecimal(digits + 'e' + String(-scale));
195
+ if (!parsed)
196
+ throw new RangeError('Value was either too large or too small for a Decimal.');
197
+ parsed.negative = value < 0;
198
+ return parsed;
199
+ }
200
+ while (scale < 0) {
201
+ digits += '0';
202
+ scale++;
203
+ }
204
+ const words = toWords(digits);
205
+ return { lo: words[0], mid: words[1], hi: words[2], scale,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GAAG,KAAK,GAAG,CAAC,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,GAAG,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,GAAG,CAAC;QACd,KAAK,EAAE,CAAC;IACV,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAW,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAW,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC;AACjH,CAAC","sourcesContent":["// Invariant-culture number text exactly as .NET writes it, where G9SyncData hashes or stores that text: a computed\n// column's canonical text (G9CSyncDigest.CanonicalText) and the TEXT storage of decimals.\n\n/**\n * `double.ToString(CultureInfo.InvariantCulture)` (.NET Core 3.0+): the shortest round-trip digits, in fixed notation\n * unless the decimal exponent is 17 or more, or below -4, then `d.dddE+XX` (the golden vectors pin both edges).\n */\nexport function formatDouble(value: number): string {\n if (value !== value) return 'NaN';\n if (value === Infinity) return 'Infinity';\n if (value === -Infinity) return '-Infinity';\n if (value === 0) return 1 / value < 0 ? '-0' : '0';\n const negative = value < 0;\n // toExponential() without an argument gives the shortest digits that round-trip, like .NET's.\n const text = Math.abs(value).toExponential();\n const e = text.indexOf('e');\n const digits = text.slice(0, e).replace('.', '');\n const exponent = parseInt(text.slice(e + 1), 10);\n const scale = exponent + 1;\n let out: string;\n if (scale > 17 || scale < -3) {\n const abs = Math.abs(exponent);\n out = digits.charAt(0) + (digits.length > 1 ? '.' + digits.slice(1) : '') + 'E' + (exponent < 0 ? '-' : '+') + (abs < 10 ? '0' : '') + abs;\n } else if (scale <= 0) {\n out = '0.' + repeat('0', -scale) + digits;\n } else if (scale >= digits.length) {\n out = digits + repeat('0', scale - digits.length);\n } else {\n out = digits.slice(0, scale) + '.' + digits.slice(scale);\n }\n return negative ? '-' + out : out;\n}\n\nfunction repeat(text: string, count: number): string {\n let out = '';\n for (let i = 0; i < count; i++) out += text;\n return out;\n}\n\n/** The parts of a .NET `decimal`: 96-bit magnitude as three 32-bit words, a scale 0..28 and a sign. */\nexport interface DecimalParts {\n lo: number;\n mid: number;\n hi: number;\n scale: number;\n negative: boolean;\n}\n\n/** Divides a 96-bit magnitude (three uint32 words, little-endian order) by a small divisor, in place; returns the remainder. */\nfunction divide96(words: number[], divisor: number): number {\n let remainder = 0;\n for (let i = 2; i >= 0; i--) {\n // Two 16-bit steps keep every intermediate below 2^53.\n const word = words[i] as number;\n let v = remainder * 65536 + (word >>> 16);\n const qHigh = Math.floor(v / divisor);\n remainder = v - qHigh * divisor;\n v = remainder * 65536 + (word & 0xffff);\n const qLow = Math.floor(v / divisor);\n remainder = v - qLow * divisor;\n words[i] = ((qHigh << 16) | qLow) >>> 0;\n }\n return remainder;\n}\n\n/** `decimal.ToString(CultureInfo.InvariantCulture)`: every digit of the magnitude, the scale kept (`1.50`, `0.000`). */\nexport function formatDecimal(parts: DecimalParts): string {\n const words = [parts.lo >>> 0, parts.mid >>> 0, parts.hi >>> 0];\n let digits = '';\n while (words[0] !== 0 || words[1] !== 0 || words[2] !== 0) {\n const chunk = String(divide96(words, 10000000));\n digits = (words[0] !== 0 || words[1] !== 0 || words[2] !== 0 ? '0000000'.slice(chunk.length) + chunk : chunk) + digits;\n }\n if (digits === '') digits = '0';\n const scale = parts.scale;\n if (scale > 0) {\n while (digits.length <= scale) digits = '0' + digits;\n digits = digits.slice(0, digits.length - scale) + '.' + digits.slice(digits.length - scale);\n }\n const zero = parts.lo === 0 && parts.mid === 0 && parts.hi === 0;\n return parts.negative && !zero ? '-' + digits : digits;\n}\n\nconst DOUBLE_POWERS_10 = [\n 1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22, 1e23, 1e24, 1e25,\n 1e26, 1e27, 1e28,\n];\n\n/**\n * `(double)decimal` exactly as .NET computes it (`DecCalc.VarR8FromDec`): `((double)low64 + (double)high · 2^64) /\n * 10^scale`, each step an IEEE double operation, so the result matches .NET to the bit (it is not always the correctly\n * rounded value, and must not be: the server compares what .NET stored).\n */\nexport function decimalToDouble(parts: DecimalParts): number {\n const low64 = (parts.mid >>> 0) * 4294967296 + (parts.lo >>> 0);\n const value = (low64 + (parts.hi >>> 0) * 18446744073709552000) / (DOUBLE_POWERS_10[parts.scale] as number);\n return parts.negative ? -value : value;\n}\n\n/**\n * Parses invariant decimal text (`decimal.Parse(text, NumberStyles.Number | NumberStyles.AllowExponent, Invariant)`\n * for the forms SQLite and .NET produce: sign, digits, one '.', an optional exponent). Digits past 28 significant are\n * rounded half to even… as .NET does (to the 96-bit limit). Returns null for text that is not a number.\n */\nexport function parseDecimal(text: string): DecimalParts | null {\n const m = /^\\s*([+-]?)(\\d*)(?:\\.(\\d*))?(?:[eE]([+-]?\\d+))?\\s*$/.exec(text);\n if (!m) return null;\n const intPart = m[2] ?? '';\n const fracPart = m[3] ?? '';\n if (intPart === '' && fracPart === '') return null;\n let digits = (intPart + fracPart).replace(/^0+/, '');\n let scale = fracPart.length - (m[4] ? parseInt(m[4], 10) : 0);\n if (digits === '') return { lo: 0, mid: 0, hi: 0, scale: Math.max(0, Math.min(28, scale)), negative: m[1] === '-' };\n // Negative scale: append zeros (the value is an integer).\n while (scale < 0) {\n digits += '0';\n scale++;\n }\n // Too many digits for 96 bits or a scale past 28: round away the excess, half to even.\n while (scale > 28 || !fits96(digits)) {\n if (scale === 0) return null; // overflow\n const last = digits.charCodeAt(digits.length - 1) - 48;\n digits = digits.slice(0, -1);\n scale--;\n if (last > 5 || (last === 5 && (digits.length === 0 || (digits.charCodeAt(digits.length - 1) - 48) % 2 === 1))) digits = incrementDigits(digits);\n if (digits === '') digits = '0';\n }\n const words = toWords(digits);\n return { lo: words[0] as number, mid: words[1] as number, hi: words[2] as number, scale, negative: m[1] === '-' };\n}\n\nfunction incrementDigits(digits: string): string {\n const chars = digits.split('');\n let i = chars.length - 1;\n while (i >= 0) {\n if (chars[i] === '9') {\n chars[i] = '0';\n i--;\n } else {\n chars[i] = String.fromCharCode((chars[i] as string).charCodeAt(0) + 1);\n return chars.join('');\n }\n }\n return '1' + chars.join('');\n}\n\nconst MAX_96 = '79228162514264337593543950335';\n\nfunction fits96(digits: string): boolean {\n const d = digits.replace(/^0+/, '');\n return d.length < MAX_96.length || (d.length === MAX_96.length && d <= MAX_96);\n}\n\nfunction toWords(digits: string): number[] {\n // 16-bit limbs, little-endian; value = value * 10 + digit.\n const limbs = [0, 0, 0, 0, 0, 0];\n for (let i = 0; i < digits.length; i++) {\n let carry = digits.charCodeAt(i) - 48;\n for (let k = 0; k < 6; k++) {\n const v = (limbs[k] as number) * 10 + carry;\n limbs[k] = v & 0xffff;\n carry = Math.floor(v / 65536);\n }\n }\n return [\n (((limbs[1] as number) << 16) | (limbs[0] as number)) >>> 0,\n (((limbs[3] as number) << 16) | (limbs[2] as number)) >>> 0,\n (((limbs[5] as number) << 16) | (limbs[4] as number)) >>> 0,\n ];\n}\n\n/**\n * `(decimal)double` exactly as .NET converts it (`new decimal(double)`, VarDecFromR8): the value rounded to 15\n * significant digits, then trailing zeros dropped. Throws `RangeError` for NaN, infinities and |value| ≥ 7.9e28.\n */\nexport function doubleToDecimal(value: number): DecimalParts {\n if (!isFinite(value)) throw new RangeError('Value was either too large or too small for a Decimal.');\n if (value === 0) return { lo: 0, mid: 0, hi: 0, scale: 0, negative: false };\n if (Math.abs(value) >= 7.9228162514264338e28) throw new RangeError('Value was either too large or too small for a Decimal.');\n if (Math.abs(value) < 1e-28) return { lo: 0, mid: 0, hi: 0, scale: 0, negative: value < 0 };\n // 15 significant digits (toExponential(14) rounds half-even on the exact binary value, like .NET's double→decimal).\n const text = Math.abs(value).toExponential(14);\n const e = text.indexOf('e');\n let digits = text.slice(0, e).replace('.', '');\n const exponent = parseInt(text.slice(e + 1), 10);\n digits = digits.replace(/0+$/, '');\n if (digits === '') digits = '0';\n // value = digits × 10^(exponent − (digits.length − 1))\n let scale = digits.length - 1 - exponent;\n if (scale > 28) {\n // Fewer digits fit: drop to scale 28 with rounding.\n const parsed = parseDecimal(digits + 'e' + String(-scale));\n if (!parsed) throw new RangeError('Value was either too large or too small for a Decimal.');\n parsed.negative = value < 0;\n return parsed;\n }\n while (scale < 0) {\n digits += '0';\n scale++;\n }\n const words = toWords(digits);\n return { lo: words[0] as number, mid: words[1] as number, hi: words[2] as number, scale, negative: value < 0 };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ /** Writes the 16-byte MD5 of `source` to `destination` (offset 0) and returns it. */
2
+ export declare function md5(source: Uint8Array, destination?: Uint8Array): Uint8Array;
@@ -0,0 +1,97 @@
1
+ // One-shot MD5 (RFC 1321), the twin of G9SyncData.Abstractions/G9CMd5.cs: the reconciliation hash's bucketing
2
+ // function (ADR-0012), not a security boundary. Lynx has no WebCrypto (and WebCrypto has no MD5).
3
+ const K = new Int32Array([
4
+ 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
5
+ 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
6
+ 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
7
+ 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
8
+ 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
9
+ 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
10
+ 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
11
+ 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
12
+ ]);
13
+ const S = [
14
+ 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4,
15
+ 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21,
16
+ ];
17
+ const G = new Int32Array(64);
18
+ for (let i = 0; i < 64; i++) {
19
+ G[i] = i < 16 ? i : i < 32 ? (5 * i + 1) & 15 : i < 48 ? (3 * i + 5) & 15 : (7 * i) & 15;
20
+ }
21
+ const M = new Int32Array(16);
22
+ const TAIL = new Uint8Array(128);
23
+ function block(data, offset, state) {
24
+ for (let i = 0; i < 16; i++) {
25
+ const j = offset + i * 4;
26
+ M[i] = data[j] | (data[j + 1] << 8) | (data[j + 2] << 16) | (data[j + 3] << 24);
27
+ }
28
+ let a = state[0];
29
+ let b = state[1];
30
+ let c = state[2];
31
+ let d = state[3];
32
+ for (let i = 0; i < 64; i++) {
33
+ let f;
34
+ switch (i >> 4) {
35
+ case 0:
36
+ f = (b & c) | (~b & d);
37
+ break;
38
+ case 1:
39
+ f = (d & b) | (~d & c);
40
+ break;
41
+ case 2:
42
+ f = b ^ c ^ d;
43
+ break;
44
+ default:
45
+ f = c ^ (b | ~d);
46
+ break;
47
+ }
48
+ const next = d;
49
+ d = c;
50
+ c = b;
51
+ const sum = (a + f + K[i] + M[G[i]]) | 0;
52
+ const s = S[i];
53
+ b = (b + ((sum << s) | (sum >>> (32 - s)))) | 0;
54
+ a = next;
55
+ }
56
+ state[0] = (state[0] + a) | 0;
57
+ state[1] = (state[1] + b) | 0;
58
+ state[2] = (state[2] + c) | 0;
59
+ state[3] = (state[3] + d) | 0;
60
+ }
61
+ /** Writes the 16-byte MD5 of `source` to `destination` (offset 0) and returns it. */
62
+ export function md5(source, destination = new Uint8Array(16)) {
63
+ const state = new Int32Array([0x67452301, 0xefcdab89 | 0, 0x98badcfe | 0, 0x10325476]);
64
+ const length = source.length;
65
+ const full = length - (length % 64);
66
+ for (let offset = 0; offset < full; offset += 64)
67
+ block(source, offset, state);
68
+ // The tail, the 0x80 marker and the bit length: one or two final blocks.
69
+ TAIL.fill(0);
70
+ const remaining = length - full;
71
+ for (let i = 0; i < remaining; i++)
72
+ TAIL[i] = source[full + i];
73
+ TAIL[remaining] = 0x80;
74
+ const tailBytes = remaining < 56 ? 64 : 128;
75
+ const bitsLow = (length * 8) >>> 0;
76
+ const bitsHigh = Math.floor(length / 0x20000000) >>> 0;
77
+ const at = tailBytes - 8;
78
+ TAIL[at] = bitsLow & 0xff;
79
+ TAIL[at + 1] = (bitsLow >>> 8) & 0xff;
80
+ TAIL[at + 2] = (bitsLow >>> 16) & 0xff;
81
+ TAIL[at + 3] = (bitsLow >>> 24) & 0xff;
82
+ TAIL[at + 4] = bitsHigh & 0xff;
83
+ TAIL[at + 5] = (bitsHigh >>> 8) & 0xff;
84
+ TAIL[at + 6] = (bitsHigh >>> 16) & 0xff;
85
+ TAIL[at + 7] = (bitsHigh >>> 24) & 0xff;
86
+ for (let offset = 0; offset < tailBytes; offset += 64)
87
+ block(TAIL, offset, state);
88
+ for (let i = 0; i < 4; i++) {
89
+ const word = state[i];
90
+ destination[i * 4] = word & 0xff;
91
+ destination[i * 4 + 1] = (word >>> 8) & 0xff;
92
+ destination[i * 4 + 2] = (word >>> 16) & 0xff;
93
+ destination[i * 4 + 3] = (word >>> 24) & 0xff;
94
+ }
95
+ return destination;
96
+ }
97
+ //# sourceMappingUR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G,QAAQ,GAAG,IAAI,CAAC;IAC/B,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;IACvC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACxC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACxC,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,IAAI,EAAE;QAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAElF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAW,CAAC;QAChC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;QACjC,WAAW,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;QAC7C,WAAW,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;QAC9C,WAAW,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAChD,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["// One-shot MD5 (RFC 1321), the twin of G9SyncData.Abstractions/G9CMd5.cs: the reconciliation hash's bucketing\n// function (ADR-0012), not a security boundary. Lynx has no WebCrypto (and WebCrypto has no MD5).\n\nconst K = new Int32Array([\n 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,\n 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,\n 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,\n 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,\n 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,\n 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,\n 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,\n 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,\n]);\n\nconst S = [\n 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4,\n 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21,\n];\n\nconst G = new Int32Array(64);\nfor (let i = 0; i < 64; i++) {\n G[i] = i < 16 ? i : i < 32 ? (5 * i + 1) & 15 : i < 48 ? (3 * i + 5) & 15 : (7 * i) & 15;\n}\n\nconst M = new Int32Array(16);\nconst TAIL = new Uint8Array(128);\n\nfunction block(data: Uint8Array, offset: number, state: Int32Array): void {\n for (let i = 0; i < 16; i++) {\n const j = offset + i * 4;\n M[i] = (data[j] as number) | ((data[j + 1] as number) << 8) | ((data[j + 2] as number) << 16) | ((data[j + 3] as number) << 24);\n }\n let a = state[0] as number;\n let b = state[1] as number;\n let c = state[2] as number;\n let d = state[3] as number;\n for (let i = 0; i < 64; i++) {\n let f: number;\n switch (i >> 4) {\n case 0:\n f = (b & c) | (~b & d);\n break;\n case 1:\n f = (d & b) | (~d & c);\n break;\n case 2:\n f = b ^ c ^ d;\n break;\n default:\n f = c ^ (b | ~d);\n break;\n }\n const next = d;\n d = c;\n c = b;\n const sum = (a + f + (K[i] as number) + (M[G[i] as number] as number)) | 0;\n const s = S[i] as number;\n b = (b + ((sum << s) | (sum >>> (32 - s)))) | 0;\n a = next;\n }\n state[0] = ((state[0] as number) + a) | 0;\n state[1] = ((state[1] as number) + b) | 0;\n state[2] = ((state[2] as number) + c) | 0;\n state[3] = ((state[3] as number) + d) | 0;\n}\n\n/** Writes the 16-byte MD5 of `source` to `destination` (offset 0) and returns it. */\nexport function md5(source: Uint8Array, destination: Uint8Array = new Uint8Array(16)): Uint8Array {\n const state = new Int32Array([0x67452301, 0xefcdab89 | 0, 0x98badcfe | 0, 0x10325476]);\n const length = source.length;\n const full = length - (length % 64);\n for (let offset = 0; offset < full; offset += 64) block(source, offset, state);\n\n // The tail, the 0x80 marker and the bit length: one or two final blocks.\n TAIL.fill(0);\n const remaining = length - full;\n for (let i = 0; i < remaining; i++) TAIL[i] = source[full + i] as number;\n TAIL[remaining] = 0x80;\n const tailBytes = remaining < 56 ? 64 : 128;\n const bitsLow = (length * 8) >>> 0;\n const bitsHigh = Math.floor(length / 0x20000000) >>> 0;\n const at = tailBytes - 8;\n TAIL[at] = bitsLow & 0xff;\n TAIL[at + 1] = (bitsLow >>> 8) & 0xff;\n TAIL[at + 2] = (bitsLow >>> 16) & 0xff;\n TAIL[at + 3] = (bitsLow >>> 24) & 0xff;\n TAIL[at + 4] = bitsHigh & 0xff;\n TAIL[at + 5] = (bitsHigh >>> 8) & 0xff;\n TAIL[at + 6] = (bitsHigh >>> 16) & 0xff;\n TAIL[at + 7] = (bitsHigh >>> 24) & 0xff;\n for (let offset = 0; offset < tailBytes; offset += 64) block(TAIL, offset, state);\n\n for (let i = 0; i < 4; i++) {\n const word = state[i] as number;\n destination[i * 4] = word & 0xff;\n destination[i * 4 + 1] = (word >>> 8) & 0xff;\n destination[i * 4 + 2] = (word >>> 16) & 0xff;\n destination[i * 4 + 3] = (word >>> 24) & 0xff;\n }\n return destination;\n}\n"]}
@@ -0,0 +1,20 @@
1
+ /** Incremental SHA-256 hasher (internal; the public entry point is {@link sha256Hex}). */
2
+ export declare class Sha256 {
3
+ private readonly _state;
4
+ private readonly _w;
5
+ private readonly _block;
6
+ private _blockLength;
7
+ private _totalBytes;
8
+ private _finished;
9
+ /** Adds `data` to the hash. */
10
+ update(data: Uint8Array): this;
11
+ /** Finishes the hash and returns the 32-byte digest. The hasher cannot be updated afterwards. */
12
+ digest(): Uint8Array;
13
+ /** Finishes the hash and returns it as lower-case hex. */
14
+ hexDigest(): string;
15
+ private _compress;
16
+ }
17
+ /** Lower-case hex of `bytes` (.NET `Convert.ToHexStringLower`). */
18
+ export declare function toHex(bytes: Uint8Array): string;
19
+ /** SHA-256 of `bytes`. */
20
+ export declare function sha256(bytes: Uint8Array): Uint8Array;
@@ -0,0 +1,153 @@
1
+ // FIPS 180-4 SHA-256 (copied from @g9tm/signalr-supernetcore-client, bytes only). Lynx has no WebCrypto.
2
+ const K = new Int32Array([
3
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
4
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
5
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
6
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
7
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
8
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
9
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
10
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
11
+ ]);
12
+ const INITIAL = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
13
+ /** Incremental SHA-256 hasher (internal; the public entry point is {@link sha256Hex}). */
14
+ export class Sha256 {
15
+ constructor() {
16
+ this._state = new Int32Array(INITIAL);
17
+ this._w = new Int32Array(64);
18
+ this._block = new Uint8Array(64);
19
+ this._blockLength = 0;
20
+ this._totalBytes = 0;
21
+ this._finished = false;
22
+ }
23
+ /** Adds `data` to the hash. */
24
+ update(data) {
25
+ if (this._finished)
26
+ throw new Error('SHA-256 digest was already computed; create a new hasher.');
27
+ const length = data.length;
28
+ this._totalBytes += length;
29
+ let offset = 0;
30
+ if (this._blockLength > 0) {
31
+ const take = Math.min(64 - this._blockLength, length);
32
+ this._block.set(data.subarray(0, take), this._blockLength);
33
+ this._blockLength += take;
34
+ offset = take;
35
+ if (this._blockLength === 64) {
36
+ this._compress(this._block, 0);
37
+ this._blockLength = 0;
38
+ }
39
+ }
40
+ while (offset + 64 <= length) {
41
+ this._compress(data, offset);
42
+ offset += 64;
43
+ }
44
+ if (offset < length) {
45
+ this._block.set(data.subarray(offset), 0);
46
+ this._blockLength = length - offset;
47
+ }
48
+ return this;
49
+ }
50
+ /** Finishes the hash and returns the 32-byte digest. The hasher cannot be updated afterwards. */
51
+ digest() {
52
+ if (this._finished)
53
+ throw new Error('SHA-256 digest was already computed; create a new hasher.');
54
+ this._finished = true;
55
+ const block = this._block;
56
+ let used = this._blockLength;
57
+ block[used++] = 0x80;
58
+ if (used > 56) {
59
+ block.fill(0, used);
60
+ this._compress(block, 0);
61
+ used = 0;
62
+ }
63
+ block.fill(0, used, 56);
64
+ // Message length in bits as a 64-bit big-endian integer (exact for inputs below 2^50 bytes).
65
+ const bytes = this._totalBytes;
66
+ const high = Math.floor(bytes / 0x20000000);
67
+ const low = (bytes * 8) >>> 0;
68
+ block[56] = high >>> 24;
69
+ block[57] = (high >>> 16) & 0xff;
70
+ block[58] = (high >>> 8) & 0xff;
71
+ block[59] = high & 0xff;
72
+ block[60] = low >>> 24;
73
+ block[61] = (low >>> 16) & 0xff;
74
+ block[62] = (low >>> 8) & 0xff;
75
+ block[63] = low & 0xff;
76
+ this._compress(block, 0);
77
+ const out = new Uint8Array(32);
78
+ for (let i = 0; i < 8; i++) {
79
+ const word = this._state[i];
80
+ out[i * 4] = word >>> 24;
81
+ out[i * 4 + 1] = (word >>> 16) & 0xff;
82
+ out[i * 4 + 2] = (word >>> 8) & 0xff;
83
+ out[i * 4 + 3] = word & 0xff;
84
+ }
85
+ return out;
86
+ }
87
+ /** Finishes the hash and returns it as lower-case hex. */
88
+ hexDigest() {
89
+ return toHex(this.digest());
90
+ }
91
+ _compress(data, offset) {
92
+ const w = this._w;
93
+ for (let i = 0; i < 16; i++) {
94
+ const j = offset + i * 4;
95
+ w[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | data[j + 3];
96
+ }
97
+ for (let i = 16; i < 64; i++) {
98
+ const x = w[i - 15];
99
+ const y = w[i - 2];
100
+ const s0 = ((x >>> 7) | (x << 25)) ^ ((x >>> 18) | (x << 14)) ^ (x >>> 3);
101
+ const s1 = ((y >>> 17) | (y << 15)) ^ ((y >>> 19) | (y << 13)) ^ (y >>> 10);
102
+ w[i] = (w[i - 16] + s0 + w[i - 7] + s1) | 0;
103
+ }
104
+ const state = this._state;
105
+ let a = state[0];
106
+ let b = state[1];
107
+ let c = state[2];
108
+ let d = state[3];
109
+ let e = state[4];
110
+ let f = state[5];
111
+ let g = state[6];
112
+ let h = state[7];
113
+ for (let i = 0; i < 64; i++) {
114
+ const s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
115
+ const ch = (e & f) ^ (~e & g);
116
+ const t1 = (h + s1 + ch + K[i] + w[i]) | 0;
117
+ const s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
118
+ const maj = (a & b) ^ (a & c) ^ (b & c);
119
+ const t2 = (s0 + maj) | 0;
120
+ h = g;
121
+ g = f;
122
+ f = e;
123
+ e = (d + t1) | 0;
124
+ d = c;
125
+ c = b;
126
+ b = a;
127
+ a = (t1 + t2) | 0;
128
+ }
129
+ state[0] = (state[0] + a) | 0;
130
+ state[1] = (state[1] + b) | 0;
131
+ state[2] = (state[2] + c) | 0;
132
+ state[3] = (state[3] + d) | 0;
133
+ state[4] = (state[4] + e) | 0;
134
+ state[5] = (state[5] + f) | 0;
135
+ state[6] = (state[6] + g) | 0;
136
+ state[7] = (state[7] + h) | 0;
137
+ }
138
+ }
139
+ const HEX = [];
140
+ for (let i = 0; i < 256; i++)
141
+ HEX.push((i < 16 ? '0' : '') + i.toString(16));
142
+ /** Lower-case hex of `bytes` (.NET `Convert.ToHexStringLower`). */
143
+ export function toHex(bytes) {
144
+ let out = '';
145
+ for (let i = 0; i < bytes.length; i++)
146
+ out += HEX[bytes[i]];
147
+ return out;
148
+ }
149
+ /** SHA-256 of `bytes`. */
150
+ export function sha256(bytes) {
151
+ return new Sha256().update(bytes).digest();
152
+ }
153
+ //# sourceMappingURL=sha256.js.map
@@ -0,0 +1 @@
1
+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AC,GAAG,CAAC,CAAC;QAC/B,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QAC/B,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;CACF;AAED,MAAM,GAAG,GAAa,EAAE,CAAC;AACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;IAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAE7E,mEAAmE;AACnE,MAAM,UAAU,KAAK,CAAC,KAAiB;IACrC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAW,CAAW,CAAC;IAChF,OAAO,GAAG,CAAC;AACb,CAAC;AAED,0BAA0B;AAC1B,MAAM,UAAU,MAAM,CAAC,KAAiB;IACtC,OAAO,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["// FIPS 180-4 SHA-256 (copied from @g9tm/signalr-supernetcore-client, bytes only). Lynx has no WebCrypto.\n\nconst K = new Int32Array([\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\n 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\n 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\n 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\n 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\n 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\n]);\n\nconst INITIAL = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];\n\n/** Incremental SHA-256 hasher (internal; the public entry point is {@link sha256Hex}). */\nexport class Sha256 {\n private readonly _state = new Int32Array(INITIAL);\n private readonly _w = new Int32Array(64);\n private readonly _block = new Uint8Array(64);\n private _blockLength = 0;\n private _totalBytes = 0;\n private _finished = false;\n\n /** Adds `data` to the hash. */\n update(data: Uint8Array): this {\n if (this._finished) throw new Error('SHA-256 digest was already computed; create a new hasher.');\n const length = data.length;\n this._totalBytes += length;\n let offset = 0;\n\n if (this._blockLength > 0) {\n const take = Math.min(64 - this._blockLength, length);\n this._block.set(data.subarray(0, take), this._blockLength);\n this._blockLength += take;\n offset = take;\n if (this._blockLength === 64) {\n this._compress(this._block, 0);\n this._blockLength = 0;\n }\n }\n\n while (offset + 64 <= length) {\n this._compress(data, offset);\n offset += 64;\n }\n\n if (offset < length) {\n this._block.set(data.subarray(offset), 0);\n this._blockLength = length - offset;\n }\n return this;\n }\n\n /** Finishes the hash and returns the 32-byte digest. The hasher cannot be updated afterwards. */\n digest(): Uint8Array {\n if (this._finished) throw new Error('SHA-256 digest was already computed; create a new hasher.');\n this._finished = true;\n\n const block = this._block;\n let used = this._blockLength;\n block[used++] = 0x80;\n if (used > 56) {\n block.fill(0, used);\n this._compress(block, 0);\n used = 0;\n }\n block.fill(0, used, 56);\n\n // Message length in bits as a 64-bit big-endian integer (exact for inputs below 2^50 bytes).\n const bytes = this._totalBytes;\n const high = Math.floor(bytes / 0x20000000);\n const low = (bytes * 8) >>> 0;\n block[56] = high >>> 24;\n block[57] = (high >>> 16) & 0xff;\n block[58] = (high >>> 8) & 0xff;\n block[59] = high & 0xff;\n block[60] = low >>> 24;\n block[61] = (low >>> 16) & 0xff;\n block[62] = (low >>> 8) & 0xff;\n block[63] = low & 0xff;\n this._compress(block, 0);\n\n const out = new Uint8Array(32);\n for (let i = 0; i < 8; i++) {\n const word = this._state[i]!;\n out[i * 4] = word >>> 24;\n out[i * 4 + 1] = (word >>> 16) & 0xff;\n out[i * 4 + 2] = (word >>> 8) & 0xff;\n out[i * 4 + 3] = word & 0xff;\n }\n return out;\n }\n\n /** Finishes the hash and returns it as lower-case hex. */\n hexDigest(): string {\n return toHex(this.digest());\n }\n\n private _compress(data: Uint8Array, offset: number): void {\n const w = this._w;\n for (let i = 0; i < 16; i++) {\n const j = offset + i * 4;\n w[i] = (data[j]! << 24) | (data[j + 1]! << 16) | (data[j + 2]! << 8) | data[j + 3]!;\n }\n for (let i = 16; i < 64; i++) {\n const x = w[i - 15]!;\n const y = w[i - 2]!;\n const s0 = ((x >>> 7) | (x << 25)) ^ ((x >>> 18) | (x << 14)) ^ (x >>> 3);\n const s1 = ((y >>> 17) | (y << 15)) ^ ((y >>> 19) | (y << 13)) ^ (y >>> 10);\n w[i] = (w[i - 16]! + s0 + w[i - 7]! + s1) | 0;\n }\n\n const state = this._state;\n let a = state[0]!;\n let b = state[1]!;\n let c = state[2]!;\n let d = state[3]!;\n let e = state[4]!;\n let f = state[5]!;\n let g = state[6]!;\n let h = state[7]!;\n\n for (let i = 0; i < 64; i++) {\n const s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));\n const ch = (e & f) ^ (~e & g);\n const t1 = (h + s1 + ch + K[i]! + w[i]!) | 0;\n const s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));\n const maj = (a & b) ^ (a & c) ^ (b & c);\n const t2 = (s0 + maj) | 0;\n h = g;\n g = f;\n f = e;\n e = (d + t1) | 0;\n d = c;\n c = b;\n b = a;\n a = (t1 + t2) | 0;\n }\n\n state[0] = (state[0]! + a) | 0;\n state[1] = (state[1]! + b) | 0;\n state[2] = (state[2]! + c) | 0;\n state[3] = (state[3]! + d) | 0;\n state[4] = (state[4]! + e) | 0;\n state[5] = (state[5]! + f) | 0;\n state[6] = (state[6]! + g) | 0;\n state[7] = (state[7]! + h) | 0;\n }\n}\n\nconst HEX: string[] = [];\nfor (let i = 0; i < 256; i++) HEX.push((i < 16 ? '0' : '') + i.toString(16));\n\n/** Lower-case hex of `bytes` (.NET `Convert.ToHexStringLower`). */\nexport function toHex(bytes: Uint8Array): string {\n let out = '';\n for (let i = 0; i < bytes.length; i++) out += HEX[bytes[i] as number] as string;\n return out;\n}\n\n/** SHA-256 of `bytes`. */\nexport function sha256(bytes: Uint8Array): Uint8Array {\n return new Sha256().update(bytes).digest();\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /** UTF-8 bytes of `text`. */
2
+ export declare function utf8Encode(text: string): Uint8Array;
3
+ /** Text of UTF-8 `bytes`. */
4
+ export declare function utf8Decode(bytes: Uint8Array): string;
5
+ /** The pure-JS encoder (exported for tests; use {@link utf8Encode}). */
6
+ export declare function utf8EncodeJs(text: string): Uint8Array;
7
+ /** The pure-JS decoder, the WHATWG UTF-8 decode algorithm (exported for tests; use {@link utf8Decode}). */
8
+ export declare function utf8DecodeJs(bytes: Uint8Array): string;