gdc-common-utils-ts 1.0.4 → 1.0.7

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/AesManager.d.ts +27 -0
  2. package/dist/AesManager.js +62 -0
  3. package/dist/CryptographyService.d.ts +76 -0
  4. package/dist/CryptographyService.js +403 -0
  5. package/dist/constants/Schemas.d.ts +45 -0
  6. package/dist/constants/Schemas.js +48 -0
  7. package/dist/constants/index.js +1 -0
  8. package/{src/constants/schemaorg.ts → dist/constants/schemaorg.d.ts} +24 -116
  9. package/dist/constants/schemaorg.js +185 -0
  10. package/dist/cryptoDecode.d.ts +3 -0
  11. package/dist/cryptoDecode.js +90 -0
  12. package/dist/cryptoEncode.d.ts +1 -0
  13. package/dist/cryptoEncode.js +30 -0
  14. package/dist/cryptography.abstract.d.ts +13 -0
  15. package/{src/cryptography.abstract.ts → dist/cryptography.abstract.js} +6 -14
  16. package/dist/hmac.d.ts +2 -0
  17. package/{src/hmac.ts → dist/hmac.js} +4 -7
  18. package/dist/index.js +3 -0
  19. package/{src/interfaces/Cryptography.types.ts → dist/interfaces/Cryptography.types.d.ts} +71 -71
  20. package/dist/interfaces/Cryptography.types.js +8 -0
  21. package/dist/interfaces/ICryptoHelper.d.ts +28 -0
  22. package/dist/interfaces/ICryptoHelper.js +3 -0
  23. package/dist/interfaces/ICryptography.d.ts +154 -0
  24. package/dist/interfaces/ICryptography.js +3 -0
  25. package/dist/interfaces/IWallet.d.ts +55 -0
  26. package/dist/interfaces/IWallet.js +3 -0
  27. package/dist/interfaces/MlDsa.d.ts +9 -0
  28. package/{src/interfaces/MlDsa.ts → dist/interfaces/MlDsa.js} +1 -5
  29. package/dist/interfaces/MlKem.d.ts +11 -0
  30. package/{src/interfaces/MlKem.ts → dist/interfaces/MlKem.js} +0 -5
  31. package/dist/models/aes.d.ts +85 -0
  32. package/dist/models/aes.js +10 -0
  33. package/dist/models/auth.d.ts +35 -0
  34. package/dist/models/auth.js +3 -0
  35. package/{src/models/bundle.ts → dist/models/bundle.d.ts} +41 -63
  36. package/dist/models/bundle.js +26 -0
  37. package/dist/models/clinical-sections.d.ts +36 -0
  38. package/dist/models/clinical-sections.en.d.ts +75 -0
  39. package/dist/models/clinical-sections.en.js +81 -0
  40. package/dist/models/clinical-sections.js +32 -0
  41. package/dist/models/comm.d.ts +44 -0
  42. package/dist/models/comm.js +4 -0
  43. package/{src/models/confidential-job.ts → dist/models/confidential-job.d.ts} +23 -45
  44. package/dist/models/confidential-job.js +20 -0
  45. package/dist/models/confidential-message.d.ts +97 -0
  46. package/dist/models/confidential-message.js +4 -0
  47. package/{src/models/confidential-storage.ts → dist/models/confidential-storage.d.ts} +35 -56
  48. package/dist/models/confidential-storage.js +3 -0
  49. package/{src/models/consent-rule.ts → dist/models/consent-rule.d.ts} +22 -42
  50. package/dist/models/consent-rule.js +21 -0
  51. package/{src/models/crypto.ts → dist/models/crypto.d.ts} +5 -13
  52. package/dist/models/crypto.js +3 -0
  53. package/dist/models/device-license.d.ts +133 -0
  54. package/dist/models/device-license.js +3 -0
  55. package/{src/models/did.ts → dist/models/did.d.ts} +21 -30
  56. package/dist/models/did.js +3 -0
  57. package/dist/models/index.js +31 -0
  58. package/dist/models/indexing.d.ts +11 -0
  59. package/dist/models/indexing.js +18 -0
  60. package/dist/models/issue.d.ts +57 -0
  61. package/dist/models/issue.js +75 -0
  62. package/dist/models/jsonapi.d.ts +13 -0
  63. package/dist/models/jsonapi.js +3 -0
  64. package/{src/models/jwe.ts → dist/models/jwe.d.ts} +10 -22
  65. package/dist/models/jwe.js +3 -0
  66. package/{src/models/jwk.ts → dist/models/jwk.d.ts} +0 -11
  67. package/dist/models/jwk.js +3 -0
  68. package/{src/models/jws.ts → dist/models/jws.d.ts} +0 -7
  69. package/dist/models/jws.js +3 -0
  70. package/dist/models/jwt.d.ts +9 -0
  71. package/dist/models/jwt.js +3 -0
  72. package/dist/models/multibase58.d.ts +13 -0
  73. package/dist/models/multibase58.js +40 -0
  74. package/dist/models/oidc4ida.common.model.d.ts +33 -0
  75. package/dist/models/oidc4ida.common.model.js +3 -0
  76. package/dist/models/oidc4ida.document.model.d.ts +50 -0
  77. package/dist/models/oidc4ida.document.model.js +3 -0
  78. package/{src/models/oidc4ida.electronicRecord.model.ts → dist/models/oidc4ida.electronicRecord.model.d.ts} +18 -37
  79. package/dist/models/oidc4ida.electronicRecord.model.js +3 -0
  80. package/{src/models/oidc4ida.evidence.model.ts → dist/models/oidc4ida.evidence.model.d.ts} +17 -35
  81. package/dist/models/oidc4ida.evidence.model.js +5 -0
  82. package/dist/models/openid-device.d.ts +119 -0
  83. package/dist/models/openid-device.js +3 -0
  84. package/dist/models/operation-outcome.d.ts +26 -0
  85. package/dist/models/operation-outcome.js +3 -0
  86. package/{src/models/params.ts → dist/models/params.d.ts} +20 -29
  87. package/dist/models/params.js +3 -0
  88. package/dist/models/resource-document.d.ts +14 -0
  89. package/dist/models/resource-document.js +3 -0
  90. package/dist/models/response.d.ts +1 -0
  91. package/dist/models/response.js +3 -0
  92. package/dist/models/urlPath.d.ts +58 -0
  93. package/dist/models/urlPath.js +76 -0
  94. package/dist/models/verifiable-credential.d.ts +45 -0
  95. package/dist/models/verifiable-credential.js +8 -0
  96. package/dist/utils/actor.d.ts +18 -0
  97. package/dist/utils/actor.js +36 -0
  98. package/dist/utils/base-convert.d.ts +20 -0
  99. package/{src/utils/base-convert.ts → dist/utils/base-convert.js} +23 -36
  100. package/dist/utils/baseN.d.ts +35 -0
  101. package/dist/utils/baseN.js +174 -0
  102. package/dist/utils/bundle.d.ts +6 -0
  103. package/dist/utils/bundle.js +32 -0
  104. package/dist/utils/content.d.ts +55 -0
  105. package/{src/utils/content.ts → dist/utils/content.js} +4 -10
  106. package/dist/utils/did.d.ts +67 -0
  107. package/dist/utils/did.js +123 -0
  108. package/dist/utils/format-converter.d.ts +21 -0
  109. package/dist/utils/format-converter.js +109 -0
  110. package/dist/utils/index.js +13 -0
  111. package/dist/utils/jwt.d.ts +52 -0
  112. package/dist/utils/jwt.js +153 -0
  113. package/dist/utils/manager-error.d.ts +15 -0
  114. package/dist/utils/manager-error.js +23 -0
  115. package/dist/utils/multibase58.d.ts +13 -0
  116. package/dist/utils/multibase58.js +40 -0
  117. package/dist/utils/multibasehash.d.ts +8 -0
  118. package/{src/utils/multibasehash.ts → dist/utils/multibasehash.js} +8 -13
  119. package/dist/utils/normalize.d.ts +16 -0
  120. package/{src/utils/normalize.ts → dist/utils/normalize.js} +15 -18
  121. package/dist/utils/object-convert.d.ts +20 -0
  122. package/{src/utils/object-convert.ts → dist/utils/object-convert.js} +10 -16
  123. package/dist/utils/string-convert.d.ts +24 -0
  124. package/{src/utils/string-convert.ts → dist/utils/string-convert.js} +5 -14
  125. package/dist/utils/string-utils.d.ts +25 -0
  126. package/{src/utils/string-utils.ts → dist/utils/string-utils.js} +12 -16
  127. package/dist/utils/url.d.ts +27 -0
  128. package/{src/utils/url.ts → dist/utils/url.js} +6 -7
  129. package/package.json +56 -14
  130. package/PUBLISHING.md +0 -33
  131. package/__tests__/AesManager.test.ts +0 -53
  132. package/__tests__/CryptographyService.test.ts +0 -194
  133. package/__tests__/bundle.test.ts +0 -29
  134. package/__tests__/content.test.ts +0 -72
  135. package/__tests__/crypto-encode-decode.test.ts +0 -52
  136. package/__tests__/crypto-hmac.test.ts +0 -21
  137. package/__tests__/did-generateServiceId.errors.test.ts +0 -8
  138. package/__tests__/did-generateServiceId.test.ts +0 -18
  139. package/__tests__/models-clinical-sections.test.ts +0 -32
  140. package/__tests__/models-multibase58.test.ts +0 -33
  141. package/__tests__/multibase58.errors.test.ts +0 -7
  142. package/__tests__/multibase58.test.ts +0 -28
  143. package/__tests__/multibasehash.test.ts +0 -25
  144. package/__tests__/utils-actor.test.ts +0 -46
  145. package/__tests__/utils-base-convert.test.ts +0 -57
  146. package/__tests__/utils-baseN.test.ts +0 -40
  147. package/__tests__/utils-did-extra.test.ts +0 -33
  148. package/__tests__/utils-format-converter.test.ts +0 -87
  149. package/__tests__/utils-jwt.test.ts +0 -57
  150. package/__tests__/utils-manager-error.test.ts +0 -11
  151. package/__tests__/utils-normalize.test.ts +0 -15
  152. package/__tests__/utils-object-convert.test.ts +0 -38
  153. package/__tests__/utils-string-convert.test.ts +0 -20
  154. package/__tests__/utils-string-utils.test.ts +0 -25
  155. package/__tests__/utils-url.test.ts +0 -21
  156. package/babel.config.cjs +0 -5
  157. package/jest.config.ts +0 -47
  158. package/src/AesManager.ts +0 -82
  159. package/src/CryptographyService.ts +0 -461
  160. package/src/JweManager.ts.txt +0 -365
  161. package/src/KmsService.txt +0 -493
  162. package/src/constants/Schemas.ts +0 -61
  163. package/src/cryptoDecode.ts +0 -104
  164. package/src/cryptoEncode.ts +0 -36
  165. package/src/interfaces/ICryptoHelper.ts +0 -33
  166. package/src/interfaces/ICryptography.ts +0 -177
  167. package/src/interfaces/IWallet.ts +0 -62
  168. package/src/models/aes.ts +0 -93
  169. package/src/models/auth.ts +0 -38
  170. package/src/models/bundle.txt +0 -93
  171. package/src/models/clinical-sections.en.ts +0 -82
  172. package/src/models/clinical-sections.ts +0 -64
  173. package/src/models/comm.ts +0 -63
  174. package/src/models/confidential-message.ts +0 -137
  175. package/src/models/device-license.ts +0 -161
  176. package/src/models/indexing.ts +0 -20
  177. package/src/models/issue.ts +0 -85
  178. package/src/models/jsonapi.ts +0 -19
  179. package/src/models/jwt.ts +0 -15
  180. package/src/models/multibase58.ts +0 -46
  181. package/src/models/oidc4ida.common.model.ts +0 -39
  182. package/src/models/oidc4ida.document.model.ts +0 -61
  183. package/src/models/openid-device.ts +0 -146
  184. package/src/models/operation-outcome.ts +0 -34
  185. package/src/models/resource-document.ts +0 -21
  186. package/src/models/response.ts +0 -5
  187. package/src/models/urlPath.ts +0 -76
  188. package/src/models/verifiable-credential.ts +0 -52
  189. package/src/types/noble-hashes.d.ts +0 -4
  190. package/src/utils/actor.ts +0 -56
  191. package/src/utils/baseN.ts +0 -203
  192. package/src/utils/bundle.ts +0 -30
  193. package/src/utils/did.ts +0 -155
  194. package/src/utils/format-converter.ts +0 -119
  195. package/src/utils/jwt.ts +0 -165
  196. package/src/utils/manager-error.ts +0 -27
  197. package/src/utils/multibase58.ts +0 -46
  198. package/tsconfig.json +0 -15
  199. /package/{src/constants/index.ts → dist/constants/index.d.ts} +0 -0
  200. /package/{src/index.ts → dist/index.d.ts} +0 -0
  201. /package/{src/models/index.ts → dist/models/index.d.ts} +0 -0
  202. /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
@@ -0,0 +1,18 @@
1
+ export type ParsedActor = {
2
+ /**
3
+ * The token subject / authenticated actor identifier (as provided in the token request).
4
+ * Examples:
5
+ * - did:web:api.acme.org:employee:doctor1@acme.org:ISCO-08|2211
6
+ * - did:web:api.acme.org:employee:doctor1@acme.org:ISCO-08|2211:<device-uuid>
7
+ * - did:web:api.acme.org:family:<id>:v3-RoleCode|ONESELF
8
+ * - did:web:api.acme.org:family:<id>:v3-RoleCode|CHILD:<device-uuid>
9
+ */
10
+ sub: string;
11
+ /** The actor identifier (employee email, familyId, or raw email). */
12
+ identifier?: string;
13
+ /** The employee role code if present (e.g. "ISCO-08|2211"). */
14
+ role?: string;
15
+ /** The base organization did:web if `sub` is did:web (e.g. "did:web:api.acme.org"). */
16
+ organization?: string;
17
+ };
18
+ export declare function parseActorFromSub(sub: string): ParsedActor;
@@ -0,0 +1,36 @@
1
+ // src/utils/actor.ts
2
+ export function parseActorFromSub(sub) {
3
+ const trimmed = (sub || '').trim();
4
+ const parsed = { sub: trimmed };
5
+ if (!trimmed)
6
+ return parsed;
7
+ if (trimmed.startsWith('did:web:')) {
8
+ // Base org DID is always the first component after did:web:
9
+ // did:web:<host>[:...]
10
+ const after = trimmed.replace(/^did:web:/, '');
11
+ const host = after.split(':')[0];
12
+ if (host)
13
+ parsed.organization = `did:web:${host}`;
14
+ // Extract email and role from endpoint-style DID shapes:
15
+ // did:web:<host>:(employee|family):<id>:<roleSystem>|<roleCode>[:<uuid>]
16
+ const parts = after.split(':');
17
+ const employeeIdx = parts.indexOf('employee');
18
+ const familyIdx = parts.indexOf('family');
19
+ const idIdx = employeeIdx >= 0 ? employeeIdx + 1 : familyIdx >= 0 ? familyIdx + 1 : -1;
20
+ const identifier = idIdx >= 0 ? parts[idIdx] : undefined;
21
+ if (identifier) {
22
+ parsed.identifier = identifier.includes('@') ? identifier.toLowerCase() : identifier;
23
+ }
24
+ if (idIdx >= 0 && parts.length > idIdx + 1) {
25
+ const roleCandidate = parts[idIdx + 1];
26
+ if (roleCandidate && roleCandidate.includes('|'))
27
+ parsed.role = roleCandidate;
28
+ }
29
+ return parsed;
30
+ }
31
+ // Raw email actor identifier
32
+ if (trimmed.includes('@') && !/\s/.test(trimmed)) {
33
+ parsed.identifier = trimmed.toLowerCase();
34
+ }
35
+ return parsed;
36
+ }
@@ -0,0 +1,20 @@
1
+ /** Converts a Uint8Array to a hexadecimal string. */
2
+ export declare function bytesToHexString(bytes: Uint8Array): string;
3
+ /** Encodes a Uint8Array into a Base58 string. */
4
+ export declare function bytesToBase58(bytes: Uint8Array): string;
5
+ /** Decodes a Base58 string into a Uint8Array. */
6
+ export declare function base58ToBytes(base58str: string): Uint8Array;
7
+ /** Encodes a string into a standard Base64 string (with padding). */
8
+ export declare function stringToStdBase64(str: string): string;
9
+ /** Converts a standard Base64 string to a Base64URL string. */
10
+ export declare function base64ToBase64Url(encodedData: string): string;
11
+ /** Encodes a string into a Base64URL string. */
12
+ export declare function stringToBase64Url(stringifiedData: string): string;
13
+ /** Converts a Base64URL string to a standard Base64 string. */
14
+ export declare function base64UrlToBase64(encodedData: string): string;
15
+ /** Decodes a string that is either Base64 or Base64URL into a Uint8Array. */
16
+ export declare function base64OrUrlSafeToBytes(base64OrUrlSafe: string): Uint8Array;
17
+ /** Encodes a Uint8Array into a standard Base64 string (with padding). */
18
+ export declare function bytesToBase64(bytes: Uint8Array): string;
19
+ /** Encodes a Uint8Array into a raw Base64URL string (no padding). */
20
+ export declare function bytesToRawBase64UrlSafe(bytes: Uint8Array): string;
@@ -1,77 +1,64 @@
1
1
  // crypto-ts/utils/base-convert.ts
2
-
3
- import {
4
- encode as encodeBase64,
5
- decode as decodeBase64,
6
- decodeURLSafe,
7
- encodeURLSafe,
8
- } from "@stablelib/base64";
9
- import { alphabetBase58, decodeN, encodeN } from './baseN';
10
- import { stringToBytesUTF8 } from './string-convert';
11
-
2
+ import { encode as encodeBase64, decode as decodeBase64, decodeURLSafe, encodeURLSafe, } from "@stablelib/base64";
3
+ import { alphabetBase58, decodeN, encodeN } from './baseN.js';
4
+ import { stringToBytesUTF8 } from './string-convert.js';
12
5
  /** Converts a Uint8Array to a hexadecimal string. */
13
- export function bytesToHexString(bytes: Uint8Array): string {
6
+ export function bytesToHexString(bytes) {
14
7
  return Array.from(bytes, (byte) => {
15
8
  return ('0' + (byte & 0xff).toString(16)).slice(-2);
16
9
  }).join('');
17
- };
18
-
10
+ }
11
+ ;
19
12
  /** Encodes a Uint8Array into a Base58 string. */
20
- export function bytesToBase58(bytes: Uint8Array): string {
13
+ export function bytesToBase58(bytes) {
21
14
  return encodeN(bytes, alphabetBase58, undefined);
22
15
  }
23
-
24
16
  /** Decodes a Base58 string into a Uint8Array. */
25
- export function base58ToBytes(base58str: string): Uint8Array {
17
+ export function base58ToBytes(base58str) {
26
18
  return decodeN(base58str, alphabetBase58);
27
19
  }
28
-
29
20
  /** Encodes a string into a standard Base64 string (with padding). */
30
- export function stringToStdBase64(str: string): string {
31
- const dataBytes: Uint8Array = stringToBytesUTF8(str);
21
+ export function stringToStdBase64(str) {
22
+ const dataBytes = stringToBytesUTF8(str);
32
23
  return encodeBase64(dataBytes);
33
24
  }
34
-
35
25
  /** Converts a standard Base64 string to a Base64URL string. */
36
- export function base64ToBase64Url(encodedData: string): string {
26
+ export function base64ToBase64Url(encodedData) {
37
27
  if (encodedData && (encodedData.indexOf("+") !== -1 || encodedData.indexOf("/") !== -1)) {
38
28
  return encodedData.split("+").join("-").split("/").join("_");
39
- } else {
29
+ }
30
+ else {
40
31
  return encodedData;
41
32
  }
42
33
  }
43
-
44
34
  /** Encodes a string into a Base64URL string. */
45
- export function stringToBase64Url(stringifiedData: string): string {
35
+ export function stringToBase64Url(stringifiedData) {
46
36
  const encodedData = stringToStdBase64(stringifiedData);
47
37
  return base64ToBase64Url(encodedData);
48
38
  }
49
-
50
39
  /** Converts a Base64URL string to a standard Base64 string. */
51
- export function base64UrlToBase64(encodedData: string): string {
40
+ export function base64UrlToBase64(encodedData) {
52
41
  if (encodedData && (encodedData.indexOf("-") !== -1 || encodedData.indexOf("_") !== -1)) {
53
42
  return encodedData.split("-").join("+").split("_").join("/");
54
- } else {
43
+ }
44
+ else {
55
45
  return encodedData;
56
46
  }
57
47
  }
58
-
59
48
  /** Decodes a string that is either Base64 or Base64URL into a Uint8Array. */
60
- export function base64OrUrlSafeToBytes(base64OrUrlSafe: string): Uint8Array {
49
+ export function base64OrUrlSafeToBytes(base64OrUrlSafe) {
61
50
  if (String(base64OrUrlSafe).includes("+") || String(base64OrUrlSafe).includes("/")) {
62
- return new Uint8Array(decodeBase64(base64OrUrlSafe));
63
- } else {
51
+ return new Uint8Array(decodeBase64(base64OrUrlSafe));
52
+ }
53
+ else {
64
54
  return new Uint8Array(decodeURLSafe(base64OrUrlSafe));
65
55
  }
66
56
  }
67
-
68
57
  /** Encodes a Uint8Array into a standard Base64 string (with padding). */
69
- export function bytesToBase64(bytes: Uint8Array): string {
58
+ export function bytesToBase64(bytes) {
70
59
  return encodeBase64(bytes);
71
60
  }
72
-
73
61
  /** Encodes a Uint8Array into a raw Base64URL string (no padding). */
74
- export function bytesToRawBase64UrlSafe(bytes: Uint8Array): string {
62
+ export function bytesToRawBase64UrlSafe(bytes) {
75
63
  return encodeURLSafe(bytes).replace(/=/g, "");
76
64
  }
77
-
@@ -0,0 +1,35 @@
1
+ export declare const alphabetBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
2
+ export declare class BaseN {
3
+ constructor();
4
+ /** BaseN-encodes a Uint8Array using the given alphabet */
5
+ static encodeN(input: Uint8Array, alphabet: string, maxline: string | undefined): string;
6
+ /** Decodes a baseN-encoded (using the given alphabet) string to a Uint8Array. */
7
+ static decodeN(input: string, alphabet: string): Uint8Array;
8
+ /** Base58-encodes a Uint8Array using the Bitcoin alphabet '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' */
9
+ static encodeBytesToBase58(inputBytes: Uint8Array): string;
10
+ /** Base58-encodes a Uint8Array using the Bitcoin alphabet '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' */
11
+ static encodeStrToBase58(inputStr: string): string;
12
+ /** Decodes a base58-encoded string to a Uint8Array (using the Bitcoin alphabet '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz') */
13
+ static decodeBytesFromBase58(base58Str: string): Uint8Array;
14
+ /** Decodes a base58-encoded string to a Uint8Array (using the Bitcoin alphabet '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz') */
15
+ static decodeStrFromBase58(base58Str: string): string;
16
+ }
17
+ /**
18
+ * BaseN-encodes a Uint8Array using the given alphabet.
19
+ *
20
+ * @param {Uint8Array} input the bytes to encode in a Uint8Array.
21
+ * @param {number} maxline the maximum number of encoded characters per line to
22
+ * use, defaults to none.
23
+ *
24
+ * @return {string} the baseN-encoded output string.
25
+ */
26
+ export declare function encodeN(input: Uint8Array, alphabet: string, maxline: string | undefined): string;
27
+ /**
28
+ * Decodes a baseN-encoded (using the given alphabet) string to a
29
+ * Uint8Array.
30
+ *
31
+ * @param {string} input the baseN-encoded input string.
32
+ *
33
+ * @return {Uint8Array} the decoded bytes in a Uint8Array.
34
+ */
35
+ export declare function decodeN(input: string, alphabet: string): Uint8Array;
@@ -0,0 +1,174 @@
1
+ /**
2
+ * From https://raw.githubusercontent.com/digitalbazaar/base58-universal/master/baseN.js
3
+ * Base-N/Base-X encoding/decoding functions.
4
+ *
5
+ * Original implementation from base-x:
6
+ * https://github.com/cryptocoinjs/base-x
7
+ *
8
+ * Which is MIT licensed:
9
+ *
10
+ * The MIT License (MIT)
11
+ *
12
+ * Copyright base-x contributors (c) 2016
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ * of this software and associated documentation files (the "Software"), to deal
16
+ * in the Software without restriction, including without limitation the rights
17
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ * copies of the Software, and to permit persons to whom the Software is
19
+ * furnished to do so, subject to the following conditions:
20
+ *
21
+ * The above copyright notice and this permission notice shall be included in
22
+ * all copies or substantial portions of the Software.
23
+ *
24
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30
+ * DEALINGS IN THE SOFTWARE.
31
+ */
32
+ 'use strict';
33
+ import { bytesToStringUTF8, stringToBytesUTF8 } from './string-convert.js';
34
+ // baseN alphabet indexes
35
+ const _reverseAlphabets = [];
36
+ // base58 characters (Bitcoin alphabet)
37
+ export const alphabetBase58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
38
+ export class BaseN {
39
+ constructor() { }
40
+ /** BaseN-encodes a Uint8Array using the given alphabet */
41
+ static encodeN(input, alphabet, maxline) {
42
+ return encodeN(input, alphabet, maxline);
43
+ }
44
+ /** Decodes a baseN-encoded (using the given alphabet) string to a Uint8Array. */
45
+ static decodeN(input, alphabet) {
46
+ return decodeN(input, alphabet);
47
+ }
48
+ /** Base58-encodes a Uint8Array using the Bitcoin alphabet '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' */
49
+ static encodeBytesToBase58(inputBytes) {
50
+ return encodeN(inputBytes, alphabetBase58, undefined);
51
+ }
52
+ /** Base58-encodes a Uint8Array using the Bitcoin alphabet '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' */
53
+ static encodeStrToBase58(inputStr) {
54
+ const inputBytes = stringToBytesUTF8(inputStr);
55
+ return this.encodeBytesToBase58(inputBytes);
56
+ }
57
+ /** Decodes a base58-encoded string to a Uint8Array (using the Bitcoin alphabet '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz') */
58
+ static decodeBytesFromBase58(base58Str) {
59
+ return decodeN(base58Str, alphabetBase58);
60
+ }
61
+ /** Decodes a base58-encoded string to a Uint8Array (using the Bitcoin alphabet '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz') */
62
+ static decodeStrFromBase58(base58Str) {
63
+ const inputBytes = this.decodeBytesFromBase58(base58Str);
64
+ return bytesToStringUTF8(inputBytes);
65
+ }
66
+ }
67
+ /**
68
+ * BaseN-encodes a Uint8Array using the given alphabet.
69
+ *
70
+ * @param {Uint8Array} input the bytes to encode in a Uint8Array.
71
+ * @param {number} maxline the maximum number of encoded characters per line to
72
+ * use, defaults to none.
73
+ *
74
+ * @return {string} the baseN-encoded output string.
75
+ */
76
+ export function encodeN(input, alphabet, maxline) {
77
+ if (!(input instanceof Uint8Array)) {
78
+ throw new TypeError('"input" must be a Uint8Array.');
79
+ }
80
+ if (typeof alphabet !== 'string') {
81
+ throw new TypeError('"alphabet" must be a string.');
82
+ }
83
+ if (maxline !== undefined && typeof maxline !== 'number') {
84
+ throw new TypeError('"maxline" must be a number.');
85
+ }
86
+ if (input.length === 0) {
87
+ return '';
88
+ }
89
+ let output = '';
90
+ let i = 0;
91
+ const base = alphabet.length;
92
+ const first = alphabet.charAt(0);
93
+ const digits = [0];
94
+ for (i = 0; i < input.length; ++i) {
95
+ let carry = input[i];
96
+ for (let j = 0; j < digits.length; ++j) {
97
+ carry += digits[j] << 8;
98
+ digits[j] = carry % base;
99
+ carry = (carry / base) | 0;
100
+ }
101
+ while (carry > 0) {
102
+ digits.push(carry % base);
103
+ carry = (carry / base) | 0;
104
+ }
105
+ }
106
+ // deal with leading zeros
107
+ for (i = 0; input[i] === 0 && i < input.length - 1; ++i) {
108
+ output += first;
109
+ }
110
+ // convert digits to a string
111
+ for (i = digits.length - 1; i >= 0; --i) {
112
+ output += alphabet[digits[i]];
113
+ }
114
+ if (maxline) {
115
+ const match = output.match(new RegExp('.{1,' + maxline + '}', 'g'));
116
+ if (match) {
117
+ output = match.join('\r\n');
118
+ }
119
+ }
120
+ return output;
121
+ }
122
+ /**
123
+ * Decodes a baseN-encoded (using the given alphabet) string to a
124
+ * Uint8Array.
125
+ *
126
+ * @param {string} input the baseN-encoded input string.
127
+ *
128
+ * @return {Uint8Array} the decoded bytes in a Uint8Array.
129
+ */
130
+ export function decodeN(input, alphabet) {
131
+ if (typeof input !== 'string') {
132
+ throw new TypeError('"input" must be a string.');
133
+ }
134
+ if (typeof alphabet !== 'string') {
135
+ throw new TypeError('"alphabet" must be a string.');
136
+ }
137
+ if (input.length === 0) {
138
+ return new Uint8Array(0);
139
+ }
140
+ let table = _reverseAlphabets[alphabet];
141
+ if (!table) {
142
+ // compute reverse alphabet
143
+ table = _reverseAlphabets[alphabet] = [];
144
+ for (let i = 0; i < alphabet.length; ++i) {
145
+ table[alphabet.charCodeAt(i)] = i;
146
+ }
147
+ }
148
+ // remove whitespace characters
149
+ input = input.replace(/\s/g, '');
150
+ const base = alphabet.length;
151
+ const first = alphabet.charAt(0);
152
+ const bytes = [0];
153
+ for (let i = 0; i < input.length; i++) {
154
+ const value = table[input.charCodeAt(i)];
155
+ if (value === undefined) {
156
+ return new Uint8Array(0); // empty
157
+ }
158
+ let carry = value;
159
+ for (let j = 0; j < bytes.length; ++j) {
160
+ carry += bytes[j] * base;
161
+ bytes[j] = carry & 0xff;
162
+ carry >>= 8;
163
+ }
164
+ while (carry > 0) {
165
+ bytes.push(carry & 0xff);
166
+ carry >>= 8;
167
+ }
168
+ }
169
+ // deal with leading zeros
170
+ for (let k = 0; input[k] === first && k < input.length - 1; ++k) {
171
+ bytes.push(0);
172
+ }
173
+ return new Uint8Array(bytes.reverse());
174
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Normalizes either FHIR Bundle (entry[]) or JSON:API bundle (data[])
3
+ * into an array of resources.
4
+ */
5
+ export declare function extractResources(bundle: any): any[];
6
+ export declare function getNextLink(bundle: any): string | null;
@@ -0,0 +1,32 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ /**
3
+ * Normalizes either FHIR Bundle (entry[]) or JSON:API bundle (data[])
4
+ * into an array of resources.
5
+ */
6
+ export function extractResources(bundle) {
7
+ if (!bundle)
8
+ return [];
9
+ if (Array.isArray(bundle.entry)) {
10
+ return bundle.entry
11
+ .map((e) => e && (e.resource || e))
12
+ .filter(Boolean);
13
+ }
14
+ if (Array.isArray(bundle.data)) {
15
+ return bundle.data
16
+ .map((d) => d && (d.resource || d))
17
+ .filter(Boolean);
18
+ }
19
+ if (bundle.resourceType)
20
+ return [bundle];
21
+ return [];
22
+ }
23
+ export function getNextLink(bundle) {
24
+ if (Array.isArray(bundle?.link)) {
25
+ const next = bundle.link.find((l) => l.relation === 'next');
26
+ if (next?.url)
27
+ return next.url;
28
+ }
29
+ if (bundle?.links?.next)
30
+ return bundle.links.next;
31
+ return null;
32
+ }
@@ -0,0 +1,55 @@
1
+ import * as baseConvert from './base-convert';
2
+ import * as objectConvert from './object-convert';
3
+ import * as stringConvert from './string-convert';
4
+ import * as stringUtils from './string-utils';
5
+ /**
6
+ * A unified facade class for all data conversion and utility functions.
7
+ * This class encapsulates functionality from the various utility modules
8
+ * (base-convert, object-convert, etc.) into a single, consistent interface.
9
+ */
10
+ export declare class Content {
11
+ /** Encodes a string into a Uint8Array of strictly-validated UTF-8 bytes. */
12
+ static stringToBytesUTF8: typeof stringConvert.stringToBytesUTF8;
13
+ /** Decodes a Uint8Array of strictly-validated UTF-8 bytes back into a string. */
14
+ static bytesToStringUTF8: typeof stringConvert.bytesToStringUTF8;
15
+ /** Decodes a Uint8Array containing binary/ASCII data into a string. */
16
+ static bytesToStringASCII: typeof stringConvert.bytesToStringASCII;
17
+ /** Capitalizes the first letter of a string. */
18
+ static capitalize: typeof stringUtils.capitalize;
19
+ /** A simple string sanitizer. */
20
+ static sanitizeString: typeof stringUtils.sanitizeString;
21
+ /** Converts a string to a string of its ASCII character codes. */
22
+ static stringToASCII: typeof stringUtils.stringToASCII;
23
+ /** Converts a string to an array of numbers representing its byte values. */
24
+ static stringToBytesArrayOfNumbers: typeof stringUtils.stringToBytesArrayOfNumbers;
25
+ /** Converts a Uint8Array to a hexadecimal string. */
26
+ static bytesToHexString: typeof baseConvert.bytesToHexString;
27
+ /** Encodes a Uint8Array into a Base58 string. */
28
+ static bytesToBase58: typeof baseConvert.bytesToBase58;
29
+ /** Decodes a Base58 string into a Uint8Array. */
30
+ static base58ToBytes: typeof baseConvert.base58ToBytes;
31
+ /** Encodes a string into a standard Base64 string (with padding). */
32
+ static stringToStdBase64: typeof baseConvert.stringToStdBase64;
33
+ /** Converts a standard Base64 string to a Base64URL string. */
34
+ static base64ToBase64Url: typeof baseConvert.base64ToBase64Url;
35
+ /** Encodes a string into a Base64URL string. */
36
+ static stringToBase64Url: typeof baseConvert.stringToBase64Url;
37
+ /** Converts a Base64URL string to a standard Base64 string. */
38
+ static base64UrlToBase64: typeof baseConvert.base64UrlToBase64;
39
+ /** Decodes a string that is either Base64 or Base64URL into a Uint8Array. */
40
+ static base64ToBytes: typeof baseConvert.base64OrUrlSafeToBytes;
41
+ /** Encodes a Uint8Array into a standard Base64 string (with padding). */
42
+ static bytesToBase64: typeof baseConvert.bytesToBase64;
43
+ /** Encodes a Uint8Array into a raw Base64URL string (no padding). */
44
+ static bytesToRawBase64UrlSafe: typeof baseConvert.bytesToRawBase64UrlSafe;
45
+ /** Compares two arrays and returns true if they are the same, false otherwise. */
46
+ static arrayCompare: typeof objectConvert.arrayCompare;
47
+ /** Merges two Uint8Arrays into a single Uint8Array. */
48
+ static arrayMerge: typeof objectConvert.arrayMerge;
49
+ /** Serializes a JavaScript object to a Uint8Array of UTF-8 bytes. */
50
+ static objectToBytes: typeof objectConvert.objectToBytes;
51
+ /** Serializes a JavaScript object to a raw Base64URL string. */
52
+ static objectToRawBase64UrlSafe: typeof objectConvert.objectToRawBase64UrlSafe;
53
+ /** Deserializes a Base64URL string back into a JavaScript object. */
54
+ static base64UrlSafeToJSON: typeof objectConvert.base64UrlSafeToJSON;
55
+ }
@@ -1,10 +1,8 @@
1
1
  // crypto-ts/utils/convert.ts
2
-
3
- import * as baseConvert from './base-convert';
4
- import * as objectConvert from './object-convert';
5
- import * as stringConvert from './string-convert';
6
- import * as stringUtils from './string-utils';
7
-
2
+ import * as baseConvert from './base-convert.js';
3
+ import * as objectConvert from './object-convert.js';
4
+ import * as stringConvert from './string-convert.js';
5
+ import * as stringUtils from './string-utils.js';
8
6
  /**
9
7
  * A unified facade class for all data conversion and utility functions.
10
8
  * This class encapsulates functionality from the various utility modules
@@ -18,7 +16,6 @@ export class Content {
18
16
  static bytesToStringUTF8 = stringConvert.bytesToStringUTF8;
19
17
  /** Decodes a Uint8Array containing binary/ASCII data into a string. */
20
18
  static bytesToStringASCII = stringConvert.bytesToStringASCII;
21
-
22
19
  // --- String Utilities (from string-utils.ts) ---
23
20
  /** Capitalizes the first letter of a string. */
24
21
  static capitalize = stringUtils.capitalize;
@@ -28,7 +25,6 @@ export class Content {
28
25
  static stringToASCII = stringUtils.stringToASCII;
29
26
  /** Converts a string to an array of numbers representing its byte values. */
30
27
  static stringToBytesArrayOfNumbers = stringUtils.stringToBytesArrayOfNumbers;
31
-
32
28
  // --- Base Conversions (from base-convert.ts) ---
33
29
  /** Converts a Uint8Array to a hexadecimal string. */
34
30
  static bytesToHexString = baseConvert.bytesToHexString;
@@ -50,7 +46,6 @@ export class Content {
50
46
  static bytesToBase64 = baseConvert.bytesToBase64;
51
47
  /** Encodes a Uint8Array into a raw Base64URL string (no padding). */
52
48
  static bytesToRawBase64UrlSafe = baseConvert.bytesToRawBase64UrlSafe;
53
-
54
49
  // --- Object & Array Conversions (from object-convert.ts) ---
55
50
  /** Compares two arrays and returns true if they are the same, false otherwise. */
56
51
  static arrayCompare = objectConvert.arrayCompare;
@@ -63,4 +58,3 @@ export class Content {
63
58
  /** Deserializes a Base64URL string back into a JavaScript object. */
64
59
  static base64UrlSafeToJSON = objectConvert.base64UrlSafeToJSON;
65
60
  }
66
-
@@ -0,0 +1,67 @@
1
+ import { ServiceEndpointSelector } from "../models/did";
2
+ /**
3
+ * Generates a DID Service ID fragment from a selector object.
4
+ * The format is always `#<section>:<format>:<resourceType>:<action>`.
5
+ *
6
+ * This utility's only job is to correctly assemble the string. It contains no
7
+ * conditional logic about DID types, as that is handled by the data layer.
8
+ *
9
+ * @param selector The structured object containing the endpoint parts.
10
+ * @returns The formatted service ID fragment string.
11
+ */
12
+ export declare function generateServiceId(selector: ServiceEndpointSelector): string;
13
+ /**
14
+ * Normalizes a did:web string to a canonical format to prevent resolution errors
15
+ * due to case sensitivity in the path component of the underlying URL.
16
+ *
17
+ * The rule is:
18
+ * - All segments are lowercased, EXCEPT the final segment.
19
+ * - If the final segment represents a `system|code` pair (e.g., for a role),
20
+ * the `system` part is lowercased, but the `code` is preserved as-is.
21
+ * - If the final segment is a unique identifier (like a Tax ID), it is preserved as-is.
22
+ *
23
+ * @param did The did:web string to normalize.
24
+ * @returns The canonicalized did:web string.
25
+ */
26
+ export declare function normalizeDidWeb(did: string): string;
27
+ /**
28
+ * Creates the deterministic "hosted" did:web for a tenant (Organization).
29
+ *
30
+ * @param hostDidWeb The DID of the host (e.g., 'did:web:host.example.com').
31
+ * @param tenantAlternateName The alternate name of the tenant (e.g., 'acme').
32
+ * @param context An object containing jurisdiction, version, and sector.
33
+ * @returns The tenant's full, correctly formatted hosted did:web.
34
+ * Example: 'did:web:host.example.com:acme:cds-es:v1:health-care'
35
+ */
36
+ export declare function createHostedDidWeb(hostDidWeb: string, tenantAlternateName: string, context: {
37
+ jurisdiction: string;
38
+ version: string;
39
+ sector: string;
40
+ }): string;
41
+ /**
42
+ * Builds the canonical details (URL and did:web URN) for a hosted DID.
43
+ * This is the single source of truth for constructing hosted identifiers in the app.
44
+ *
45
+ * @param options An object with the components of the DID.
46
+ * @param options.host The provider's domain (e.g., 'provider.com').
47
+ * @param options.alternateName The tenant's identifier (e.g., 'acme').
48
+ * @param options.jurisdiction The legal jurisdiction (defaults to 'ES').
49
+ * @param options.sector The business sector (defaults to 'health-care').
50
+ * @returns An object with the full URL (with trailing /) and the canonical did:web.
51
+ */
52
+ export declare function buildHostedDidDetails({ host, alternateName, jurisdiction, sector, }: {
53
+ host: string;
54
+ alternateName: string;
55
+ jurisdiction?: string;
56
+ sector?: string;
57
+ }): {
58
+ did: string;
59
+ url: string;
60
+ };
61
+ /**
62
+ * Converts a did:web identifier into a full HTTPS or HTTP base URL with a trailing slash.
63
+ * It correctly decodes percent-encoded ports for local development.
64
+ * @param did The did:web string (e.g., 'did:web:example.com' or 'did:web:localhost%3A3000:acme:cds-es:v1:health-care').
65
+ * @returns The full base URL (e.g., 'https://example.com/acme/cds-es/v1/health-care/').
66
+ */
67
+ export declare function getBaseUrlFromDidWeb(did: string): string;