@azure/msal-browser 3.2.0 → 3.3.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.
Files changed (202) hide show
  1. package/dist/app/IPublicClientApplication.mjs +1 -1
  2. package/dist/app/PublicClientApplication.mjs +2 -2
  3. package/dist/app/PublicClientApplication.mjs.map +1 -1
  4. package/dist/app/PublicClientNext.d.ts +274 -0
  5. package/dist/app/PublicClientNext.d.ts.map +1 -0
  6. package/dist/app/PublicClientNext.mjs +362 -0
  7. package/dist/app/PublicClientNext.mjs.map +1 -0
  8. package/dist/broker/nativeBroker/NativeMessageHandler.mjs +1 -1
  9. package/dist/broker/nativeBroker/NativeStatusCodes.mjs +1 -1
  10. package/dist/cache/AsyncMemoryStorage.mjs +1 -1
  11. package/dist/cache/BrowserCacheManager.d.ts +2 -13
  12. package/dist/cache/BrowserCacheManager.d.ts.map +1 -1
  13. package/dist/cache/BrowserCacheManager.mjs +7 -64
  14. package/dist/cache/BrowserCacheManager.mjs.map +1 -1
  15. package/dist/cache/BrowserStorage.mjs +1 -1
  16. package/dist/cache/CryptoKeyStore.mjs +1 -1
  17. package/dist/cache/DatabaseStorage.mjs +1 -1
  18. package/dist/cache/MemoryStorage.mjs +1 -1
  19. package/dist/cache/TokenCache.mjs +1 -1
  20. package/dist/config/Configuration.d.ts +4 -0
  21. package/dist/config/Configuration.d.ts.map +1 -1
  22. package/dist/config/Configuration.mjs +2 -1
  23. package/dist/config/Configuration.mjs.map +1 -1
  24. package/dist/controllers/ControllerFactory.d.ts +2 -1
  25. package/dist/controllers/ControllerFactory.d.ts.map +1 -1
  26. package/dist/controllers/ControllerFactory.mjs +26 -19
  27. package/dist/controllers/ControllerFactory.mjs.map +1 -1
  28. package/dist/controllers/NestedAppAuthController.d.ts +96 -0
  29. package/dist/controllers/NestedAppAuthController.d.ts.map +1 -0
  30. package/dist/controllers/NestedAppAuthController.mjs +345 -0
  31. package/dist/controllers/NestedAppAuthController.mjs.map +1 -0
  32. package/dist/controllers/StandardController.d.ts.map +1 -1
  33. package/dist/controllers/StandardController.mjs +16 -13
  34. package/dist/controllers/StandardController.mjs.map +1 -1
  35. package/dist/controllers/UnknownOperatingContextController.d.ts +88 -0
  36. package/dist/controllers/UnknownOperatingContextController.d.ts.map +1 -0
  37. package/dist/controllers/UnknownOperatingContextController.mjs +275 -0
  38. package/dist/controllers/UnknownOperatingContextController.mjs.map +1 -0
  39. package/dist/crypto/BrowserCrypto.d.ts.map +1 -1
  40. package/dist/crypto/BrowserCrypto.mjs +3 -3
  41. package/dist/crypto/BrowserCrypto.mjs.map +1 -1
  42. package/dist/crypto/CryptoOps.d.ts.map +1 -1
  43. package/dist/crypto/CryptoOps.mjs +8 -5
  44. package/dist/crypto/CryptoOps.mjs.map +1 -1
  45. package/dist/crypto/PkceGenerator.mjs +1 -1
  46. package/dist/crypto/SignedHttpRequest.mjs +1 -1
  47. package/dist/encode/Base64Decode.mjs +1 -1
  48. package/dist/encode/Base64Encode.mjs +1 -1
  49. package/dist/error/BrowserAuthError.mjs +1 -1
  50. package/dist/error/BrowserAuthErrorCodes.mjs +1 -1
  51. package/dist/error/BrowserConfigurationAuthError.mjs +1 -1
  52. package/dist/error/BrowserConfigurationAuthErrorCodes.mjs +1 -1
  53. package/dist/error/NativeAuthError.mjs +1 -1
  54. package/dist/error/NativeAuthErrorCodes.mjs +1 -1
  55. package/dist/error/NestedAppAuthError.d.ts +15 -0
  56. package/dist/error/NestedAppAuthError.d.ts.map +1 -0
  57. package/dist/error/NestedAppAuthError.mjs +30 -0
  58. package/dist/error/NestedAppAuthError.mjs.map +1 -0
  59. package/dist/event/EventHandler.mjs +1 -1
  60. package/dist/event/EventMessage.mjs +1 -1
  61. package/dist/event/EventType.mjs +1 -1
  62. package/dist/index.d.ts +3 -5
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.mjs +4 -2
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/interaction_client/BaseInteractionClient.mjs +4 -4
  67. package/dist/interaction_client/HybridSpaAuthorizationCodeClient.mjs +1 -1
  68. package/dist/interaction_client/NativeInteractionClient.d.ts.map +1 -1
  69. package/dist/interaction_client/NativeInteractionClient.mjs +15 -4
  70. package/dist/interaction_client/NativeInteractionClient.mjs.map +1 -1
  71. package/dist/interaction_client/PopupClient.d.ts.map +1 -1
  72. package/dist/interaction_client/PopupClient.mjs +5 -4
  73. package/dist/interaction_client/PopupClient.mjs.map +1 -1
  74. package/dist/interaction_client/RedirectClient.mjs +7 -7
  75. package/dist/interaction_client/SilentAuthCodeClient.d.ts.map +1 -1
  76. package/dist/interaction_client/SilentAuthCodeClient.mjs +4 -4
  77. package/dist/interaction_client/SilentAuthCodeClient.mjs.map +1 -1
  78. package/dist/interaction_client/SilentCacheClient.d.ts.map +1 -1
  79. package/dist/interaction_client/SilentCacheClient.mjs +4 -3
  80. package/dist/interaction_client/SilentCacheClient.mjs.map +1 -1
  81. package/dist/interaction_client/SilentIframeClient.d.ts.map +1 -1
  82. package/dist/interaction_client/SilentIframeClient.mjs +27 -13
  83. package/dist/interaction_client/SilentIframeClient.mjs.map +1 -1
  84. package/dist/interaction_client/SilentRefreshClient.mjs +1 -1
  85. package/dist/interaction_client/StandardInteractionClient.mjs +5 -5
  86. package/dist/interaction_handler/InteractionHandler.mjs +1 -1
  87. package/dist/interaction_handler/RedirectHandler.mjs +1 -1
  88. package/dist/interaction_handler/SilentHandler.d.ts +13 -47
  89. package/dist/interaction_handler/SilentHandler.d.ts.map +1 -1
  90. package/dist/interaction_handler/SilentHandler.mjs +120 -155
  91. package/dist/interaction_handler/SilentHandler.mjs.map +1 -1
  92. package/dist/naa/AccountInfo.d.ts +13 -0
  93. package/dist/naa/AccountInfo.d.ts.map +1 -0
  94. package/dist/naa/AccountRequests.d.ts +10 -0
  95. package/dist/naa/AccountRequests.d.ts.map +1 -0
  96. package/dist/naa/AuthBridge.d.ts +6 -0
  97. package/dist/naa/AuthBridge.d.ts.map +1 -0
  98. package/dist/naa/BridgeCapabilities.d.ts +4 -0
  99. package/dist/naa/BridgeCapabilities.d.ts.map +1 -0
  100. package/dist/naa/BridgeError.d.ts +10 -0
  101. package/dist/naa/BridgeError.d.ts.map +1 -0
  102. package/dist/naa/BridgeError.mjs +12 -0
  103. package/dist/naa/BridgeError.mjs.map +1 -0
  104. package/dist/naa/BridgeProxy.d.ts +72 -0
  105. package/dist/naa/BridgeProxy.d.ts.map +1 -0
  106. package/dist/naa/BridgeProxy.mjs +154 -0
  107. package/dist/naa/BridgeProxy.mjs.map +1 -0
  108. package/dist/naa/BridgeRequest.d.ts +7 -0
  109. package/dist/naa/BridgeRequest.d.ts.map +1 -0
  110. package/dist/naa/BridgeRequestEnvelope.d.ts +14 -0
  111. package/dist/naa/BridgeRequestEnvelope.d.ts.map +1 -0
  112. package/dist/naa/BridgeResponseEnvelope.d.ts +11 -0
  113. package/dist/naa/BridgeResponseEnvelope.d.ts.map +1 -0
  114. package/dist/naa/BridgeStatusCode.d.ts +11 -0
  115. package/dist/naa/BridgeStatusCode.d.ts.map +1 -0
  116. package/dist/naa/BridgeStatusCode.mjs +20 -0
  117. package/dist/naa/BridgeStatusCode.mjs.map +1 -0
  118. package/dist/naa/IBridgeProxy.d.ts +11 -0
  119. package/dist/naa/IBridgeProxy.d.ts.map +1 -0
  120. package/dist/naa/InitializeBridgeResponse.d.ts +7 -0
  121. package/dist/naa/InitializeBridgeResponse.d.ts.map +1 -0
  122. package/dist/naa/TokenRequest.d.ts +22 -0
  123. package/dist/naa/TokenRequest.d.ts.map +1 -0
  124. package/dist/naa/TokenResponse.d.ts +17 -0
  125. package/dist/naa/TokenResponse.d.ts.map +1 -0
  126. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts +26 -0
  127. package/dist/naa/mapping/NestedAppAuthAdapter.d.ts.map +1 -0
  128. package/dist/naa/mapping/NestedAppAuthAdapter.mjs +178 -0
  129. package/dist/naa/mapping/NestedAppAuthAdapter.mjs.map +1 -0
  130. package/dist/navigation/NavigationClient.mjs +1 -1
  131. package/dist/network/FetchClient.mjs +1 -1
  132. package/dist/operatingcontext/BaseOperatingContext.mjs +1 -1
  133. package/dist/operatingcontext/StandardOperatingContext.mjs +1 -1
  134. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts +7 -0
  135. package/dist/operatingcontext/TeamsAppOperatingContext.d.ts.map +1 -1
  136. package/dist/operatingcontext/TeamsAppOperatingContext.mjs +45 -4
  137. package/dist/operatingcontext/TeamsAppOperatingContext.mjs.map +1 -1
  138. package/dist/operatingcontext/UnknownOperatingContext.d.ts +26 -0
  139. package/dist/operatingcontext/UnknownOperatingContext.d.ts.map +1 -0
  140. package/dist/operatingcontext/UnknownOperatingContext.mjs +49 -0
  141. package/dist/operatingcontext/UnknownOperatingContext.mjs.map +1 -0
  142. package/dist/packageMetadata.d.ts +1 -1
  143. package/dist/packageMetadata.mjs +2 -2
  144. package/dist/telemetry/BrowserPerformanceClient.mjs +1 -1
  145. package/dist/telemetry/BrowserPerformanceMeasurement.mjs +1 -1
  146. package/dist/utils/BrowserConstants.mjs +1 -1
  147. package/dist/utils/BrowserProtocolUtils.mjs +1 -1
  148. package/dist/utils/BrowserUtils.d.ts +54 -53
  149. package/dist/utils/BrowserUtils.d.ts.map +1 -1
  150. package/dist/utils/BrowserUtils.mjs +114 -102
  151. package/dist/utils/BrowserUtils.mjs.map +1 -1
  152. package/lib/msal-browser.cjs +61 -17728
  153. package/lib/msal-browser.cjs.map +1 -1
  154. package/lib/msal-browser.js +14625 -13223
  155. package/lib/msal-browser.js.map +1 -1
  156. package/lib/msal-browser.min.js +66 -68
  157. package/package.json +2 -2
  158. package/src/app/PublicClientApplication.ts +1 -1
  159. package/src/app/PublicClientNext.ts +442 -0
  160. package/src/cache/BrowserCacheManager.ts +11 -100
  161. package/src/config/Configuration.ts +5 -0
  162. package/src/controllers/ControllerFactory.ts +36 -25
  163. package/src/controllers/NestedAppAuthController.ts +525 -0
  164. package/src/controllers/StandardController.ts +8 -6
  165. package/src/controllers/UnknownOperatingContextController.ts +383 -0
  166. package/src/crypto/BrowserCrypto.ts +2 -2
  167. package/src/crypto/CryptoOps.ts +8 -5
  168. package/src/error/NestedAppAuthError.ts +32 -0
  169. package/src/index.ts +3 -10
  170. package/src/interaction_client/BaseInteractionClient.ts +1 -1
  171. package/src/interaction_client/NativeInteractionClient.ts +19 -3
  172. package/src/interaction_client/PopupClient.ts +2 -1
  173. package/src/interaction_client/RedirectClient.ts +1 -1
  174. package/src/interaction_client/SilentAuthCodeClient.ts +5 -4
  175. package/src/interaction_client/SilentCacheClient.ts +11 -3
  176. package/src/interaction_client/SilentIframeClient.ts +53 -17
  177. package/src/interaction_client/StandardInteractionClient.ts +1 -1
  178. package/src/interaction_handler/SilentHandler.ts +177 -233
  179. package/src/naa/AccountInfo.ts +17 -0
  180. package/src/naa/AccountRequests.ts +16 -0
  181. package/src/naa/AuthBridge.ts +16 -0
  182. package/src/naa/BridgeCapabilities.ts +8 -0
  183. package/src/naa/BridgeError.ts +18 -0
  184. package/src/naa/BridgeProxy.ts +230 -0
  185. package/src/naa/BridgeRequest.ts +12 -0
  186. package/src/naa/BridgeRequestEnvelope.ts +46 -0
  187. package/src/naa/BridgeResponseEnvelope.ts +21 -0
  188. package/src/naa/BridgeStatusCode.ts +15 -0
  189. package/src/naa/IBridgeProxy.ts +25 -0
  190. package/src/naa/InitializeBridgeResponse.ts +12 -0
  191. package/src/naa/TokenRequest.ts +26 -0
  192. package/src/naa/TokenResponse.ts +61 -0
  193. package/src/naa/mapping/NestedAppAuthAdapter.ts +252 -0
  194. package/src/operatingcontext/TeamsAppOperatingContext.ts +43 -3
  195. package/src/operatingcontext/UnknownOperatingContext.ts +48 -0
  196. package/src/packageMetadata.ts +1 -1
  197. package/src/utils/BrowserUtils.ts +133 -125
  198. package/dist/utils/BrowserStringUtils.d.ts +0 -22
  199. package/dist/utils/BrowserStringUtils.d.ts.map +0 -1
  200. package/dist/utils/BrowserStringUtils.mjs +0 -144
  201. package/dist/utils/BrowserStringUtils.mjs.map +0 -1
  202. package/src/utils/BrowserStringUtils.ts +0 -143
@@ -1,22 +0,0 @@
1
- /**
2
- * Utility functions for strings in a browser. See here for implementation details:
3
- * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64
4
- */
5
- export declare class BrowserStringUtils {
6
- /**
7
- * Converts string to Uint8Array
8
- * @param sDOMStr
9
- */
10
- static stringToUtf8Arr(sDOMStr: string): Uint8Array;
11
- /**
12
- * Converts Uint8Array to a string
13
- * @param aBytes
14
- */
15
- static utf8ArrToString(aBytes: Uint8Array): string;
16
- /**
17
- * Returns stringified jwk.
18
- * @param jwk
19
- */
20
- static getSortedObjectString(obj: object): string;
21
- }
22
- //# sourceMappingURL=BrowserStringUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BrowserStringUtils.d.ts","sourceRoot":"","sources":["../../src/utils/BrowserStringUtils.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,qBAAa,kBAAkB;IAC3B;;;OAGG;IACH,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU;IAkEnD;;;OAGG;IACH,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;IAiDlD;;;OAGG;IACH,MAAM,CAAC,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAGpD"}
@@ -1,144 +0,0 @@
1
- /*! @azure/msal-browser v3.2.0 2023-10-05 */
2
- 'use strict';
3
- import { Constants } from '@azure/msal-common';
4
-
5
- /*
6
- * Copyright (c) Microsoft Corporation. All rights reserved.
7
- * Licensed under the MIT License.
8
- */
9
- /**
10
- * Utility functions for strings in a browser. See here for implementation details:
11
- * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64
12
- */
13
- class BrowserStringUtils {
14
- /**
15
- * Converts string to Uint8Array
16
- * @param sDOMStr
17
- */
18
- static stringToUtf8Arr(sDOMStr) {
19
- let nChr;
20
- let nArrLen = 0;
21
- const nStrLen = sDOMStr.length;
22
- /* mapping... */
23
- for (let nMapIdx = 0; nMapIdx < nStrLen; nMapIdx++) {
24
- nChr = sDOMStr.charCodeAt(nMapIdx);
25
- nArrLen +=
26
- nChr < 0x80
27
- ? 1
28
- : nChr < 0x800
29
- ? 2
30
- : nChr < 0x10000
31
- ? 3
32
- : nChr < 0x200000
33
- ? 4
34
- : nChr < 0x4000000
35
- ? 5
36
- : 6;
37
- }
38
- const aBytes = new Uint8Array(nArrLen);
39
- /* transcription... */
40
- for (let nIdx = 0, nChrIdx = 0; nIdx < nArrLen; nChrIdx++) {
41
- nChr = sDOMStr.charCodeAt(nChrIdx);
42
- if (nChr < 128) {
43
- /* one byte */
44
- aBytes[nIdx++] = nChr;
45
- }
46
- else if (nChr < 0x800) {
47
- /* two bytes */
48
- aBytes[nIdx++] = 192 + (nChr >>> 6);
49
- aBytes[nIdx++] = 128 + (nChr & 63);
50
- }
51
- else if (nChr < 0x10000) {
52
- /* three bytes */
53
- aBytes[nIdx++] = 224 + (nChr >>> 12);
54
- aBytes[nIdx++] = 128 + ((nChr >>> 6) & 63);
55
- aBytes[nIdx++] = 128 + (nChr & 63);
56
- }
57
- else if (nChr < 0x200000) {
58
- /* four bytes */
59
- aBytes[nIdx++] = 240 + (nChr >>> 18);
60
- aBytes[nIdx++] = 128 + ((nChr >>> 12) & 63);
61
- aBytes[nIdx++] = 128 + ((nChr >>> 6) & 63);
62
- aBytes[nIdx++] = 128 + (nChr & 63);
63
- }
64
- else if (nChr < 0x4000000) {
65
- /* five bytes */
66
- aBytes[nIdx++] = 248 + (nChr >>> 24);
67
- aBytes[nIdx++] = 128 + ((nChr >>> 18) & 63);
68
- aBytes[nIdx++] = 128 + ((nChr >>> 12) & 63);
69
- aBytes[nIdx++] = 128 + ((nChr >>> 6) & 63);
70
- aBytes[nIdx++] = 128 + (nChr & 63);
71
- } /* if (nChr <= 0x7fffffff) */
72
- else {
73
- /* six bytes */
74
- aBytes[nIdx++] = 252 + (nChr >>> 30);
75
- aBytes[nIdx++] = 128 + ((nChr >>> 24) & 63);
76
- aBytes[nIdx++] = 128 + ((nChr >>> 18) & 63);
77
- aBytes[nIdx++] = 128 + ((nChr >>> 12) & 63);
78
- aBytes[nIdx++] = 128 + ((nChr >>> 6) & 63);
79
- aBytes[nIdx++] = 128 + (nChr & 63);
80
- }
81
- }
82
- return aBytes;
83
- }
84
- /**
85
- * Converts Uint8Array to a string
86
- * @param aBytes
87
- */
88
- static utf8ArrToString(aBytes) {
89
- let sView = Constants.EMPTY_STRING;
90
- for (let nPart, nLen = aBytes.length, nIdx = 0; nIdx < nLen; nIdx++) {
91
- nPart = aBytes[nIdx];
92
- sView += String.fromCharCode(nPart > 251 && nPart < 254 && nIdx + 5 < nLen /* six bytes */
93
- ? /* (nPart - 252 << 30) may be not so safe in ECMAScript! So...: */
94
- (nPart - 252) * 1073741824 +
95
- ((aBytes[++nIdx] - 128) << 24) +
96
- ((aBytes[++nIdx] - 128) << 18) +
97
- ((aBytes[++nIdx] - 128) << 12) +
98
- ((aBytes[++nIdx] - 128) << 6) +
99
- aBytes[++nIdx] -
100
- 128
101
- : nPart > 247 &&
102
- nPart < 252 &&
103
- nIdx + 4 < nLen /* five bytes */
104
- ? ((nPart - 248) << 24) +
105
- ((aBytes[++nIdx] - 128) << 18) +
106
- ((aBytes[++nIdx] - 128) << 12) +
107
- ((aBytes[++nIdx] - 128) << 6) +
108
- aBytes[++nIdx] -
109
- 128
110
- : nPart > 239 &&
111
- nPart < 248 &&
112
- nIdx + 3 < nLen /* four bytes */
113
- ? ((nPart - 240) << 18) +
114
- ((aBytes[++nIdx] - 128) << 12) +
115
- ((aBytes[++nIdx] - 128) << 6) +
116
- aBytes[++nIdx] -
117
- 128
118
- : nPart > 223 &&
119
- nPart < 240 &&
120
- nIdx + 2 < nLen /* three bytes */
121
- ? ((nPart - 224) << 12) +
122
- ((aBytes[++nIdx] - 128) << 6) +
123
- aBytes[++nIdx] -
124
- 128
125
- : nPart > 191 &&
126
- nPart < 224 &&
127
- nIdx + 1 < nLen /* two bytes */
128
- ? ((nPart - 192) << 6) + aBytes[++nIdx] - 128
129
- : /* nPart < 127 ? */ /* one byte */
130
- nPart);
131
- }
132
- return sView;
133
- }
134
- /**
135
- * Returns stringified jwk.
136
- * @param jwk
137
- */
138
- static getSortedObjectString(obj) {
139
- return JSON.stringify(obj, Object.keys(obj).sort());
140
- }
141
- }
142
-
143
- export { BrowserStringUtils };
144
- //# sourceMappingURL=BrowserStringUtils.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BrowserStringUtils.mjs","sources":["../../src/utils/BrowserStringUtils.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAOA;;;AAGG;AAEC;;;AAGG;AACH,MAAsB;AAkEtB;;;AAGG;AACH,IAAA,OAAO,eAAe,CAAC,OAAQ,EAAA;AAiD/B,QAAA,IAAA,IAAA,CAAA;;;AAGG;AACH,QAAA,KAA4B,IAAA,OAAA,GAAA,CAAA,EAAA,OAAM,GAAA,OAAS,EAAM,OAAA,EAAA,EAAA;AAGpD,YAAA,IAAA,GAAA,OAAA,CAAA,UAAA,CAAA,OAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,143 +0,0 @@
1
- /*
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { Constants } from "@azure/msal-common";
7
-
8
- /**
9
- * Utility functions for strings in a browser. See here for implementation details:
10
- * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Solution_2_%E2%80%93_JavaScript's_UTF-16_%3E_UTF-8_%3E_base64
11
- */
12
- export class BrowserStringUtils {
13
- /**
14
- * Converts string to Uint8Array
15
- * @param sDOMStr
16
- */
17
- static stringToUtf8Arr(sDOMStr: string): Uint8Array {
18
- let nChr;
19
- let nArrLen = 0;
20
- const nStrLen = sDOMStr.length;
21
- /* mapping... */
22
- for (let nMapIdx = 0; nMapIdx < nStrLen; nMapIdx++) {
23
- nChr = sDOMStr.charCodeAt(nMapIdx);
24
- nArrLen +=
25
- nChr < 0x80
26
- ? 1
27
- : nChr < 0x800
28
- ? 2
29
- : nChr < 0x10000
30
- ? 3
31
- : nChr < 0x200000
32
- ? 4
33
- : nChr < 0x4000000
34
- ? 5
35
- : 6;
36
- }
37
-
38
- const aBytes = new Uint8Array(nArrLen);
39
-
40
- /* transcription... */
41
-
42
- for (let nIdx = 0, nChrIdx = 0; nIdx < nArrLen; nChrIdx++) {
43
- nChr = sDOMStr.charCodeAt(nChrIdx);
44
- if (nChr < 128) {
45
- /* one byte */
46
- aBytes[nIdx++] = nChr;
47
- } else if (nChr < 0x800) {
48
- /* two bytes */
49
- aBytes[nIdx++] = 192 + (nChr >>> 6);
50
- aBytes[nIdx++] = 128 + (nChr & 63);
51
- } else if (nChr < 0x10000) {
52
- /* three bytes */
53
- aBytes[nIdx++] = 224 + (nChr >>> 12);
54
- aBytes[nIdx++] = 128 + ((nChr >>> 6) & 63);
55
- aBytes[nIdx++] = 128 + (nChr & 63);
56
- } else if (nChr < 0x200000) {
57
- /* four bytes */
58
- aBytes[nIdx++] = 240 + (nChr >>> 18);
59
- aBytes[nIdx++] = 128 + ((nChr >>> 12) & 63);
60
- aBytes[nIdx++] = 128 + ((nChr >>> 6) & 63);
61
- aBytes[nIdx++] = 128 + (nChr & 63);
62
- } else if (nChr < 0x4000000) {
63
- /* five bytes */
64
- aBytes[nIdx++] = 248 + (nChr >>> 24);
65
- aBytes[nIdx++] = 128 + ((nChr >>> 18) & 63);
66
- aBytes[nIdx++] = 128 + ((nChr >>> 12) & 63);
67
- aBytes[nIdx++] = 128 + ((nChr >>> 6) & 63);
68
- aBytes[nIdx++] = 128 + (nChr & 63);
69
- } /* if (nChr <= 0x7fffffff) */ else {
70
- /* six bytes */
71
- aBytes[nIdx++] = 252 + (nChr >>> 30);
72
- aBytes[nIdx++] = 128 + ((nChr >>> 24) & 63);
73
- aBytes[nIdx++] = 128 + ((nChr >>> 18) & 63);
74
- aBytes[nIdx++] = 128 + ((nChr >>> 12) & 63);
75
- aBytes[nIdx++] = 128 + ((nChr >>> 6) & 63);
76
- aBytes[nIdx++] = 128 + (nChr & 63);
77
- }
78
- }
79
-
80
- return aBytes;
81
- }
82
-
83
- /**
84
- * Converts Uint8Array to a string
85
- * @param aBytes
86
- */
87
- static utf8ArrToString(aBytes: Uint8Array): string {
88
- let sView = Constants.EMPTY_STRING;
89
- for (let nPart, nLen = aBytes.length, nIdx = 0; nIdx < nLen; nIdx++) {
90
- nPart = aBytes[nIdx];
91
- sView += String.fromCharCode(
92
- nPart > 251 && nPart < 254 && nIdx + 5 < nLen /* six bytes */
93
- ? /* (nPart - 252 << 30) may be not so safe in ECMAScript! So...: */
94
- (nPart - 252) * 1073741824 +
95
- ((aBytes[++nIdx] - 128) << 24) +
96
- ((aBytes[++nIdx] - 128) << 18) +
97
- ((aBytes[++nIdx] - 128) << 12) +
98
- ((aBytes[++nIdx] - 128) << 6) +
99
- aBytes[++nIdx] -
100
- 128
101
- : nPart > 247 &&
102
- nPart < 252 &&
103
- nIdx + 4 < nLen /* five bytes */
104
- ? ((nPart - 248) << 24) +
105
- ((aBytes[++nIdx] - 128) << 18) +
106
- ((aBytes[++nIdx] - 128) << 12) +
107
- ((aBytes[++nIdx] - 128) << 6) +
108
- aBytes[++nIdx] -
109
- 128
110
- : nPart > 239 &&
111
- nPart < 248 &&
112
- nIdx + 3 < nLen /* four bytes */
113
- ? ((nPart - 240) << 18) +
114
- ((aBytes[++nIdx] - 128) << 12) +
115
- ((aBytes[++nIdx] - 128) << 6) +
116
- aBytes[++nIdx] -
117
- 128
118
- : nPart > 223 &&
119
- nPart < 240 &&
120
- nIdx + 2 < nLen /* three bytes */
121
- ? ((nPart - 224) << 12) +
122
- ((aBytes[++nIdx] - 128) << 6) +
123
- aBytes[++nIdx] -
124
- 128
125
- : nPart > 191 &&
126
- nPart < 224 &&
127
- nIdx + 1 < nLen /* two bytes */
128
- ? ((nPart - 192) << 6) + aBytes[++nIdx] - 128
129
- : /* nPart < 127 ? */ /* one byte */
130
- nPart
131
- );
132
- }
133
- return sView;
134
- }
135
-
136
- /**
137
- * Returns stringified jwk.
138
- * @param jwk
139
- */
140
- static getSortedObjectString(obj: object): string {
141
- return JSON.stringify(obj, Object.keys(obj).sort());
142
- }
143
- }