@nibssplc/cams-sdk-react 1.0.0-rc.43 → 1.0.0-rc.45

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/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import './utils/crypto-polyfill';
2
1
  export * from './hooks/useCAMSAuth';
3
2
  export * from './hooks/useCAMSMSALAuth';
4
3
  export { useWebAuthn } from './hooks/useFIDOAuth';
package/dist/index.esm.js CHANGED
@@ -20,162 +20,6 @@ import { motion } from 'framer-motion';
20
20
  import axios from 'axios';
21
21
  import https from 'https';
22
22
 
23
- // Crypto polyfill for MSAL browser compatibility
24
- if (typeof window !== "undefined") {
25
- // Run immediately and synchronously
26
- // Ensure crypto object exists
27
- if (!window.crypto) {
28
- window.crypto = {};
29
- }
30
- // Polyfill getRandomValues
31
- if (!window.crypto.getRandomValues) {
32
- window.crypto.getRandomValues = function (array) {
33
- var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
34
- for (var i = 0; i < bytes.length; i++) {
35
- bytes[i] = Math.floor(Math.random() * 256);
36
- }
37
- return array;
38
- };
39
- }
40
- var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
41
- var toUint8, bytes, hash, k, ml, msg, dv, high, low, i, w, j, j, s0, s1, a, b, c, d, e, f, g, h, j, S1, ch, temp1, S0, maj, temp2, result, i;
42
- return __generator(this, function (_a) {
43
- toUint8 = function (src) {
44
- if (src instanceof ArrayBuffer)
45
- return new Uint8Array(src);
46
- if (ArrayBuffer.isView(src)) {
47
- var view = src;
48
- return new Uint8Array(view.buffer, view.byteOffset || 0, view.byteLength);
49
- }
50
- throw new TypeError("Unsupported BufferSource");
51
- };
52
- bytes = toUint8(data);
53
- hash = new Uint32Array(8);
54
- k = new Uint32Array([
55
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
56
- 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
57
- 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
58
- 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
59
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
60
- 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
61
- 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
62
- 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
63
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
64
- 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
65
- 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
66
- ]);
67
- hash[0] = 0x6a09e667;
68
- hash[1] = 0xbb67ae85;
69
- hash[2] = 0x3c6ef372;
70
- hash[3] = 0xa54ff53a;
71
- hash[4] = 0x510e527f;
72
- hash[5] = 0x9b05688c;
73
- hash[6] = 0x1f83d9ab;
74
- hash[7] = 0x5be0cd19;
75
- ml = bytes.length * 8;
76
- msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
77
- msg.set(bytes);
78
- msg[bytes.length] = 0x80;
79
- dv = new DataView(msg.buffer);
80
- high = Math.floor(ml / 0x100000000);
81
- low = ml >>> 0;
82
- dv.setUint32(msg.length - 8, high, false);
83
- dv.setUint32(msg.length - 4, low, false);
84
- for (i = 0; i < msg.length; i += 64) {
85
- w = new Uint32Array(64);
86
- for (j = 0; j < 16; j++)
87
- w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
88
- for (j = 16; j < 64; j++) {
89
- s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^
90
- ((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^
91
- (w[j - 15] >>> 3);
92
- s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^
93
- ((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^
94
- (w[j - 2] >>> 10);
95
- w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
96
- }
97
- a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
98
- for (j = 0; j < 64; j++) {
99
- S1 = ((e >>> 6) | (e << 26)) ^
100
- ((e >>> 11) | (e << 21)) ^
101
- ((e >>> 25) | (e << 7));
102
- ch = (e & f) ^ (~e & g);
103
- temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
104
- S0 = ((a >>> 2) | (a << 30)) ^
105
- ((a >>> 13) | (a << 19)) ^
106
- ((a >>> 22) | (a << 10));
107
- maj = (a & b) ^ (a & c) ^ (b & c);
108
- temp2 = (S0 + maj) >>> 0;
109
- h = g;
110
- g = f;
111
- f = e;
112
- e = (d + temp1) >>> 0;
113
- d = c;
114
- c = b;
115
- b = a;
116
- a = (temp1 + temp2) >>> 0;
117
- }
118
- hash[0] = (hash[0] + a) >>> 0;
119
- hash[1] = (hash[1] + b) >>> 0;
120
- hash[2] = (hash[2] + c) >>> 0;
121
- hash[3] = (hash[3] + d) >>> 0;
122
- hash[4] = (hash[4] + e) >>> 0;
123
- hash[5] = (hash[5] + f) >>> 0;
124
- hash[6] = (hash[6] + g) >>> 0;
125
- hash[7] = (hash[7] + h) >>> 0;
126
- }
127
- result = new Uint8Array(32);
128
- for (i = 0; i < 8; i++)
129
- new DataView(result.buffer).setUint32(i * 4, hash[i], false);
130
- return [2 /*return*/, result.buffer];
131
- });
132
- }); };
133
- // Store reference to original subtle if it exists
134
- var originalSubtle_1 = window.crypto.subtle;
135
- // Create the polyfilled subtle object
136
- var polyfillSubtle = {
137
- digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
138
- var alg;
139
- return __generator(this, function (_a) {
140
- alg = typeof algorithm === "string"
141
- ? algorithm
142
- : algorithm.name;
143
- if (alg === "SHA-256")
144
- return [2 /*return*/, sha256_1(data)];
145
- if (originalSubtle_1 === null || originalSubtle_1 === void 0 ? void 0 : originalSubtle_1.digest)
146
- return [2 /*return*/, originalSubtle_1.digest(algorithm, data)];
147
- throw new Error("Unsupported algorithm: ".concat(alg));
148
- });
149
- }); },
150
- };
151
- // Try to define the property, fallback to assignment if needed
152
- try {
153
- Object.defineProperty(window.crypto, "subtle", {
154
- configurable: true,
155
- enumerable: true,
156
- writable: true,
157
- value: polyfillSubtle,
158
- });
159
- }
160
- catch (_a) {
161
- // Some environments prevent redefining built-ins
162
- window.crypto.subtle = polyfillSubtle;
163
- }
164
- // Polyfill randomUUID
165
- if (!window.crypto.randomUUID) {
166
- window.crypto.randomUUID =
167
- function () {
168
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
169
- var r = (Math.random() * 16) | 0;
170
- var v = c === "x" ? r : (r & 0x3) | 0x8;
171
- return v.toString(16);
172
- });
173
- };
174
- }
175
- // Log success for debugging
176
- console.log("Crypto polyfill loaded successfully");
177
- }
178
-
179
23
  /******************************************************************************
180
24
  Copyright (c) Microsoft Corporation.
181
25
 
@@ -405,6 +249,147 @@ function useCAMSAuth(options) {
405
249
  };
406
250
  }
407
251
 
252
+ var _a;
253
+ // Crypto polyfill for MSAL browser compatibility
254
+ // Only apply if crypto.subtle is completely missing
255
+ if (typeof window !== "undefined" && !((_a = window.crypto) === null || _a === void 0 ? void 0 : _a.subtle)) {
256
+ // Ensure crypto object exists
257
+ if (!window.crypto) {
258
+ window.crypto = {};
259
+ }
260
+ // Polyfill getRandomValues
261
+ if (!window.crypto.getRandomValues) {
262
+ window.crypto.getRandomValues = function (array) {
263
+ var bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength);
264
+ for (var i = 0; i < bytes.length; i++) {
265
+ bytes[i] = Math.floor(Math.random() * 256);
266
+ }
267
+ return array;
268
+ };
269
+ }
270
+ var sha256_1 = function (data) { return __awaiter(void 0, void 0, void 0, function () {
271
+ var toUint8, bytes, hash, k, ml, msg, dv, high, low, i, w, j, j, s0, s1, a, b, c, d, e, f, g, h, j, S1, ch, temp1, S0, maj, temp2, result, i;
272
+ return __generator(this, function (_a) {
273
+ toUint8 = function (src) {
274
+ if (src instanceof ArrayBuffer)
275
+ return new Uint8Array(src);
276
+ if (ArrayBuffer.isView(src)) {
277
+ var view = src;
278
+ return new Uint8Array(view.buffer, view.byteOffset || 0, view.byteLength);
279
+ }
280
+ throw new TypeError("Unsupported BufferSource");
281
+ };
282
+ bytes = toUint8(data);
283
+ hash = new Uint32Array(8);
284
+ k = new Uint32Array([
285
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
286
+ 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
287
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
288
+ 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
289
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
290
+ 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
291
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
292
+ 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
293
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
294
+ 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
295
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
296
+ ]);
297
+ hash[0] = 0x6a09e667;
298
+ hash[1] = 0xbb67ae85;
299
+ hash[2] = 0x3c6ef372;
300
+ hash[3] = 0xa54ff53a;
301
+ hash[4] = 0x510e527f;
302
+ hash[5] = 0x9b05688c;
303
+ hash[6] = 0x1f83d9ab;
304
+ hash[7] = 0x5be0cd19;
305
+ ml = bytes.length * 8;
306
+ msg = new Uint8Array(bytes.length + 64 + ((64 - ((bytes.length + 9) % 64)) % 64));
307
+ msg.set(bytes);
308
+ msg[bytes.length] = 0x80;
309
+ dv = new DataView(msg.buffer);
310
+ high = Math.floor(ml / 0x100000000);
311
+ low = ml >>> 0;
312
+ dv.setUint32(msg.length - 8, high, false);
313
+ dv.setUint32(msg.length - 4, low, false);
314
+ for (i = 0; i < msg.length; i += 64) {
315
+ w = new Uint32Array(64);
316
+ for (j = 0; j < 16; j++)
317
+ w[j] = new DataView(msg.buffer).getUint32(i + j * 4, false);
318
+ for (j = 16; j < 64; j++) {
319
+ s0 = ((w[j - 15] >>> 7) | (w[j - 15] << 25)) ^
320
+ ((w[j - 15] >>> 18) | (w[j - 15] << 14)) ^
321
+ (w[j - 15] >>> 3);
322
+ s1 = ((w[j - 2] >>> 17) | (w[j - 2] << 15)) ^
323
+ ((w[j - 2] >>> 19) | (w[j - 2] << 13)) ^
324
+ (w[j - 2] >>> 10);
325
+ w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
326
+ }
327
+ a = hash[0], b = hash[1], c = hash[2], d = hash[3], e = hash[4], f = hash[5], g = hash[6], h = hash[7];
328
+ for (j = 0; j < 64; j++) {
329
+ S1 = ((e >>> 6) | (e << 26)) ^
330
+ ((e >>> 11) | (e << 21)) ^
331
+ ((e >>> 25) | (e << 7));
332
+ ch = (e & f) ^ (~e & g);
333
+ temp1 = (h + S1 + ch + k[j] + w[j]) >>> 0;
334
+ S0 = ((a >>> 2) | (a << 30)) ^
335
+ ((a >>> 13) | (a << 19)) ^
336
+ ((a >>> 22) | (a << 10));
337
+ maj = (a & b) ^ (a & c) ^ (b & c);
338
+ temp2 = (S0 + maj) >>> 0;
339
+ h = g;
340
+ g = f;
341
+ f = e;
342
+ e = (d + temp1) >>> 0;
343
+ d = c;
344
+ c = b;
345
+ b = a;
346
+ a = (temp1 + temp2) >>> 0;
347
+ }
348
+ hash[0] = (hash[0] + a) >>> 0;
349
+ hash[1] = (hash[1] + b) >>> 0;
350
+ hash[2] = (hash[2] + c) >>> 0;
351
+ hash[3] = (hash[3] + d) >>> 0;
352
+ hash[4] = (hash[4] + e) >>> 0;
353
+ hash[5] = (hash[5] + f) >>> 0;
354
+ hash[6] = (hash[6] + g) >>> 0;
355
+ hash[7] = (hash[7] + h) >>> 0;
356
+ }
357
+ result = new Uint8Array(32);
358
+ for (i = 0; i < 8; i++)
359
+ new DataView(result.buffer).setUint32(i * 4, hash[i], false);
360
+ return [2 /*return*/, result.buffer];
361
+ });
362
+ }); };
363
+ // Create the polyfilled subtle object
364
+ var polyfillSubtle = {
365
+ digest: function (algorithm, data) { return __awaiter(void 0, void 0, void 0, function () {
366
+ var alg;
367
+ return __generator(this, function (_a) {
368
+ alg = typeof algorithm === "string"
369
+ ? algorithm
370
+ : algorithm.name;
371
+ if (alg === "SHA-256")
372
+ return [2 /*return*/, sha256_1(data)];
373
+ throw new Error("Unsupported algorithm: ".concat(alg));
374
+ });
375
+ }); },
376
+ };
377
+ // Set the polyfilled subtle object
378
+ window.crypto.subtle = polyfillSubtle;
379
+ // Polyfill randomUUID
380
+ if (!window.crypto.randomUUID) {
381
+ window.crypto.randomUUID =
382
+ function () {
383
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
384
+ var r = (Math.random() * 16) | 0;
385
+ var v = c === "x" ? r : (r & 0x3) | 0x8;
386
+ return v.toString(16);
387
+ });
388
+ };
389
+ }
390
+ console.log("Crypto polyfill applied (native crypto.subtle not available)");
391
+ }
392
+
408
393
  var setCookie = function (name, value, days) {
409
394
  if (days === void 0) { days = 1; }
410
395
  var expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();