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
@@ -1,6 +1,3 @@
1
- // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
- // File: crypto-ts/interfaces/Cryptography.types.ts
3
-
4
1
  /**
5
2
  * JWK shapes and RFC 7638 thumbprints for ML-KEM and ML-DSA.
6
3
  *
@@ -22,110 +19,113 @@
22
19
  * @see https://csrc.nist.gov/pubs/fips/204/final // FIPS 204 ML-DSA (landing)
23
20
  * @see https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.204.pdf // FIPS 204 PDF
24
21
  */
25
-
26
22
  export type CurveMlKem512 = "ML-KEM-512";
27
23
  export type CurveMlKem768 = "ML-KEM-768";
28
24
  export type CurveMlKem1024 = "ML-KEM-1024";
29
-
30
25
  export type MlkemCurve = CurveMlKem512 | CurveMlKem768 | CurveMlKem1024;
31
-
32
26
  export type AlgMlDsa2 = "ML-DSA-44";
33
27
  export type AlgMlDsa3 = "ML-DSA-65";
34
- export type AlgMlDsa5 ="ML-DSA-87";
35
-
28
+ export type AlgMlDsa5 = "ML-DSA-87";
36
29
  export type MldsaAlg = AlgMlDsa2 | AlgMlDsa3 | AlgMlDsa5;
37
-
38
- // Base JWKs used for RFC 7638 thumbprint calculation
39
- export type MlkemBaseJwk = { kty: "OKP"; crv: MlkemCurve; x: string };
40
- export type MldsaBaseJwk = { kty: "AKP"; alg: MldsaAlg; pub: string };
41
- export type EcBaseJwk = { kty: "EC"; crv: string; x: string; y: string };
30
+ export type MlkemBaseJwk = {
31
+ kty: "OKP";
32
+ crv: MlkemCurve;
33
+ x: string;
34
+ };
35
+ export type MldsaBaseJwk = {
36
+ kty: "AKP";
37
+ alg: MldsaAlg;
38
+ pub: string;
39
+ };
40
+ export type EcBaseJwk = {
41
+ kty: "EC";
42
+ crv: string;
43
+ x: string;
44
+ y: string;
45
+ };
42
46
  export type BaseJwk = MlkemBaseJwk | MldsaBaseJwk | EcBaseJwk;
43
-
44
47
  export interface MlkemPublicJwk extends MlkemBaseJwk {
45
- kid?: string; // filled from thumbprint
46
- };
47
-
48
+ kid?: string;
49
+ }
48
50
  export interface MldsaPublicJwk extends MldsaBaseJwk {
49
- kid?: string; // filled from thumbprint
50
- };
51
-
51
+ kid?: string;
52
+ }
52
53
  /**
53
54
  * Represents a public key for classic cryptography algorithms like Elliptic Curve.
54
55
  */
55
56
  export interface ClassicPublicJwk {
56
57
  kty: "EC";
57
- crv: string; // e.g., "P-256"
58
+ crv: string;
58
59
  x: string;
59
60
  y: string;
60
61
  kid?: string;
61
62
  alg?: string;
62
63
  use?: string;
63
- };
64
-
64
+ }
65
65
  /**
66
66
  * Represents a public key in JWK format, suitable for public documents like DIDs.
67
67
  * This is a union of all supported public key types, both Post-Quantum and classic.
68
68
  */
69
69
  export type PublicJwk = MlkemPublicJwk | MldsaPublicJwk | ClassicPublicJwk;
70
-
71
- export interface MlkemPrivateJwk extends MlkemPublicJwk{
72
- // Private material (extended seed) must never be published:
70
+ export interface MlkemPrivateJwk extends MlkemPublicJwk {
73
71
  dBytes: Uint8Array;
74
- };
75
-
76
- export interface MldsaPrivateJwk extends MldsaPublicJwk{
77
- // Private material (extended seed) must never be published:
72
+ }
73
+ export interface MldsaPrivateJwk extends MldsaPublicJwk {
78
74
  privBytes: Uint8Array;
79
- };
80
-
75
+ }
81
76
  export interface RecipientInfo {
82
- tenantId: string;
83
- header?: Record<string, any>;
77
+ tenantId: string;
78
+ header?: Record<string, any>;
84
79
  }
85
-
86
80
  export interface SignerInfo {
87
- tenantId: string;
88
- protectedHeader: Record<string, any>;
89
- unprotectedHeader?: Record<string, any>;
81
+ tenantId: string;
82
+ protectedHeader: Record<string, any>;
83
+ unprotectedHeader?: Record<string, any>;
90
84
  }
91
-
92
85
  export interface ProtectRequest {
93
- stream: Uint8Array;
94
- recipients: RecipientInfo[];
95
- protectedHeader?: Record<string, any>; // is it meta.jws.protected?
96
- unprotectedHeader?: Record<string, any>; // is it meta.jws.unprotected?
97
- aad?: Uint8Array;// src/adapters/queue.ts
98
- input: Record<string, any>;
99
- meta?: {
100
- jws?: { protected?: Record<string, any>; unprotected?: Record<string, any>;}; // protected and unprotected headers
101
- jwe?: { header?: Record<string, any>; }; // public unencypted header from the JWE
102
- bearer?: { jwt: { header?: Record<string, any>; payload?: Record<string, any>; } }
103
- };
86
+ stream: Uint8Array;
87
+ recipients: RecipientInfo[];
88
+ protectedHeader?: Record<string, any>;
89
+ unprotectedHeader?: Record<string, any>;
90
+ aad?: Uint8Array;
91
+ input: Record<string, any>;
92
+ meta?: {
93
+ jws?: {
94
+ protected?: Record<string, any>;
95
+ unprotected?: Record<string, any>;
96
+ };
97
+ jwe?: {
98
+ header?: Record<string, any>;
99
+ };
100
+ bearer?: {
101
+ jwt: {
102
+ header?: Record<string, any>;
103
+ payload?: Record<string, any>;
104
+ };
105
+ };
106
+ };
104
107
  }
105
-
106
108
  export interface JWEData {
107
- protected?: string;
108
- unprotected?: Record<string, any>;
109
- recipients: Array<{
110
- header?: Record<string, any>;
111
- encrypted_key?: string;
112
- }>;
113
- aad?: string;
114
- iv: string;
115
- ciphertext: string;
116
- tag: string;
109
+ protected?: string;
110
+ unprotected?: Record<string, any>;
111
+ recipients: Array<{
112
+ header?: Record<string, any>;
113
+ encrypted_key?: string;
114
+ }>;
115
+ aad?: string;
116
+ iv: string;
117
+ ciphertext: string;
118
+ tag: string;
117
119
  }
118
-
119
120
  export interface SignRequest {
120
- payload: Uint8Array;
121
- signers: SignerInfo[];
121
+ payload: Uint8Array;
122
+ signers: SignerInfo[];
122
123
  }
123
-
124
124
  export interface JwsObject {
125
- payload: string;
126
- signatures: Array<{
127
- protected: string;
128
- unprotected?: Record<string, any>;
129
- signature: string;
130
- }>;
125
+ payload: string;
126
+ signatures: Array<{
127
+ protected: string;
128
+ unprotected?: Record<string, any>;
129
+ signature: string;
130
+ }>;
131
131
  }
@@ -0,0 +1,8 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/interfaces/Cryptography.types.ts
3
+ ;
4
+ ;
5
+ ;
6
+ ;
7
+ ;
8
+ export {};
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @interface ICryptoHelper
3
+ * Defines the contract for platform-specific cryptographic primitives.
4
+ * This is the "port" in a hexagonal architecture, allowing the agnostic
5
+ * core (CryptographyService) to be "plugged into" any runtime environment
6
+ * (like Expo, Node, or Web) without depending on its implementation details.
7
+ */
8
+ export interface ICryptoHelper {
9
+ /**
10
+ * Generates a specified number of cryptographically secure random bytes.
11
+ * @param byteCount The number of bytes to generate.
12
+ * @returns A Promise that resolves to a Uint8Array with the random bytes.
13
+ */
14
+ getRandomBytes(byteCount: number): Promise<Uint8Array>;
15
+ /**
16
+ * Computes the cryptographic digest of a string using a specified algorithm.
17
+ * The implementation is responsible for validating the algorithm string.
18
+ * @param data The string to hash.
19
+ * @param algorithm The hash algorithm to use (e.g., 'SHA-256', 'SHA-512').
20
+ * @returns A Promise that resolves to the digest as a hex string.
21
+ */
22
+ digestString(data: string, algorithm: any): Promise<string>;
23
+ /**
24
+ * Generates a platform-specific, cryptographically secure UUID v4.
25
+ * @returns A string representation of the UUID.
26
+ */
27
+ randomUUID(): string;
28
+ }
@@ -0,0 +1,3 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/interfaces/ICryptoHelper.ts
3
+ export {};
@@ -0,0 +1,154 @@
1
+ import { JweObject } from '../models/jwe';
2
+ import { ProtectedDataAES } from '../models/aes';
3
+ import { MlkemPublicJwk, MldsaPublicJwk, PublicJwk, MlkemPrivateJwk, MldsaAlg, MlkemCurve } from './Cryptography.types';
4
+ import { DataCompactJWT, JwtCompactParts } from '../models/jwt';
5
+ /**
6
+ * Defines the class for the low-level, stateless cryptography utility (the "Engine").
7
+ */
8
+ export interface ICryptography {
9
+ /**
10
+ * Generates a ML-KEM (Kyber) key pair.
11
+ * @param seedBytes Optional 64-byte seed for deterministic key generation.
12
+ * @param crv The desired security level. Defaults to 'ML-KEM-768'.
13
+ */
14
+ generateKeyPairMlKem(seedBytes?: Uint8Array, crv?: MlkemCurve): Promise<{
15
+ publicJWKey: MlkemPublicJwk & {
16
+ kid: string;
17
+ };
18
+ secretKeyBytes: Uint8Array;
19
+ }>;
20
+ /**
21
+ * Generates a ML-DSA (Dilithium) key pair.
22
+ * @param seedBytes Optional 32-byte seed for deterministic key generation.
23
+ * @param alg The desired security level. Defaults to 'ML-DSA-44'.
24
+ */
25
+ generateKeyPairMlDsa(seedBytes?: Uint8Array, alg?: MldsaAlg): Promise<{
26
+ publicJWKey: MldsaPublicJwk & {
27
+ kid: string;
28
+ };
29
+ secretKeyBytes: Uint8Array;
30
+ }>;
31
+ /**
32
+ * Encrypts a plaintext string using AES-GCM (a symmetric algorithm) and returns the components.
33
+ * This is the core symmetric encryption primitive.
34
+ * @param plaintext The stringified data to encrypt.
35
+ * @param cekBytes The 32-byte Content Encryption Key (Symmetric Key).
36
+ * @param aad The base64url-encoded 'JWE Protected Header', which serves as the 'Additional Authenticated Data' (AAD) for integrity verification.
37
+ * @returns A promise resolving to the JWE-compatible encrypted components (ciphertext, iv, tag).
38
+ */
39
+ encrypt(plaintext: string, cekBytes: Uint8Array, aad: string): Promise<ProtectedDataAES>;
40
+ /**
41
+ * Decrypts JWE-compatible encrypted components back to a plaintext string.
42
+ * @param encryptedData The object containing the base64url-encoded ciphertext, iv, and tag.
43
+ * @param cekBytes The 32-byte Content Encryption Key.
44
+ * @param aad The base64url-encoded 'JWE Protected Header', which serves as the 'Additional Authenticated Data' (AAD) for integrity verification.
45
+ * @returns A promise resolving to the decrypted plaintext string.
46
+ */
47
+ decrypt(encryptedData: ProtectedDataAES, cekBytes: Uint8Array, aad: string): Promise<string>;
48
+ /**
49
+ * Generates and protects (encapsulates) a symmetric shared key (32 bytes)
50
+ * @param cekSeedBytes
51
+ * @param secretKeyBytes
52
+ * @param recipientPublicKeyBytes
53
+ */
54
+ encapsulate(cekSeedBytes: Uint8Array, secretKeyBytes: Uint8Array, recipientPublicKeyBytes: Uint8Array): Promise<{
55
+ encapsulatedCekBytes: Uint8Array;
56
+ derivedCekBytes: Uint8Array;
57
+ }>;
58
+ /**
59
+ * Returns the unprotected shared symmetric key
60
+ * @param encapsulatedBytes
61
+ * @param secretKeyBytes
62
+ */
63
+ decapsulate(encapsulatedBytes: Uint8Array, secretKeyBytes: Uint8Array): Promise<Uint8Array>;
64
+ /**
65
+ * Signs a byte array using a specified ML-DSA algorithm.
66
+ * @param payloadBytes The raw data to sign.
67
+ * @param secretKeyBytes The private signing key.
68
+ * @param alg The ML-DSA algorithm to use (e.g., 'ML-DSA-44').
69
+ * @returns A promise resolving to the raw signature bytes.
70
+ */
71
+ signBytes(payloadBytes: Uint8Array, secretKeyBytes: Uint8Array, alg: MldsaAlg): Promise<Uint8Array>;
72
+ /**
73
+ * Verifies a signature against a byte array and a public key.
74
+ * The algorithm is inferred from the `alg` property of the publicJWKey.
75
+ * @param signatureBytes The raw signature to verify.
76
+ * @param dataBytes The original data that was signed.
77
+ * @param publicJWKey The public key to use for verification.
78
+ * @returns A promise resolving to true if the signature is valid, false otherwise.
79
+ */
80
+ verifyBytes(signatureBytes: Uint8Array, dataBytes: Uint8Array, publicJWKey: PublicJwk): Promise<boolean>;
81
+ /**
82
+ * Encrypts a payload into a JWE Object, suitable for JSON General Serialization.
83
+ * This method keeps protected and per-recipient headers separate, making it ideal
84
+ * for multi-recipient scenarios or storing as a structured object (e.g., ConfidentialStorage).
85
+ * @param payload The JSON object to encrypt.
86
+ * @param protectedHeader The main protected header (JWE Protected Header). Used as AAD.
87
+ * @param secretJWKey The sender's private ML-KEM key.
88
+ * @param recipientsJWKeys An array of public ML-KEM keys for the recipients.
89
+ * @returns A Promise resolving to a JweObject.
90
+ */
91
+ encryptJwe(payload: object, protectedHeader: object, secretJWKey: MlkemPrivateJwk, recipientsJWKeys: MlkemPublicJwk[]): Promise<JweObject>;
92
+ /**
93
+ * Encrypts a payload directly into a JWE Compact Serialization string.
94
+ * This method is optimized for single-recipient JWEs. It merges the protected and
95
+ * recipient headers *before* encryption to form the correct AAD for the compact format.
96
+ * @param payload The JSON object to encrypt or a nested JWS string (compact representation).
97
+ * @param protectedHeader The main protected header (e.g., specifying `enc`).
98
+ * @param secretJWKey The sender's private ML-KEM key.
99
+ * @param recipientJWKey The single recipient's public ML-KEM key.
100
+ * @returns A Promise resolving to the JWE as a compact string.
101
+ */
102
+ encryptJweToCompact(payload: object | string, protectedHeader: object, secretJWKey: MlkemPrivateJwk, recipientJWKey: MlkemPublicJwk): Promise<string>;
103
+ /**
104
+ * Decrypts a JWE (in Compact or JSON format) and returns the decrypted bytes and protected header.
105
+ * This method identifies the correct recipient using the `kid` from the provided private JWK.
106
+ * @param jwe The JWE object or Compact JWE string.
107
+ * @param secretKeyJwk The private key of the recipient, containing the `kid` to find the
108
+ * correct recipient and the `dBytes` for the decapsulation operation.
109
+ * @returns A promise resolving to an object containing the decrypted bytes and the decoded protected header.
110
+ */
111
+ decryptJwe(jwe: JweObject | string, secretKeyJwk: MlkemPrivateJwk): Promise<{
112
+ decryptedBytes: Uint8Array;
113
+ protectedHeader: object;
114
+ }>;
115
+ /**
116
+ * @param jwe The JWE object or Compact/JSON JWE string.
117
+ * @returns An array of strings, where each string is a recipient's `kid`. Returns an empty array if no kids are found.
118
+ */
119
+ getRecipientKidsFromJwe(jwe: JweObject | string): string[];
120
+ /**
121
+ * Creates a JWS using the payload and header objects, and the signer's private key bytes.
122
+ */
123
+ signDataJws(payload: object, protectedHeader: object, secretJWKey: Uint8Array): Promise<JwtCompactParts>;
124
+ /**
125
+ * Verifies the signature of a JWS Object against the signer's public key (JWK).
126
+ */
127
+ verifyJws(jws: JwtCompactParts | string, publicJWKey: PublicJwk): Promise<boolean>;
128
+ /**
129
+ * Verifies a detached JWS signature against the original payload.
130
+ * @param payloadBytes The original, unencoded byte stream that was signed.
131
+ * @param detachedJws The JWS in detached format ('header..signature').
132
+ * @param publicJWKey The signer's public key (JWK) to use for verification.
133
+ * @returns A boolean indicating if the signature is valid.
134
+ */
135
+ verifyDetachedJws(payloadBytes: Uint8Array, detachedJws: string, publicJWKey: PublicJwk): Promise<boolean>;
136
+ /**
137
+ * Converts a JWS Object (with decoded headers and payload) into Compact Serialization format.
138
+ * @param jws The JWS Object to convert.
139
+ * @returns The JWS in Compact Serialization format (three base64url strings joined by dots).
140
+ */
141
+ jwsToCompact(jws: DataCompactJWT): string;
142
+ /**
143
+ * Parses a JWS in Compact Serialization format into a JWS Object with decoded headers and payload.
144
+ * @param jwsString The compact JWS string.
145
+ * @returns A JWS Object with JSON objects for the header and payload.
146
+ */
147
+ parseCompactJws(jwsString: string): DataCompactJWT;
148
+ /**
149
+ * Parses a JWE in Compact Serialization format into a JWE Object.
150
+ * @param jweString The compact JWE string.
151
+ * @returns A JWE Object.
152
+ */
153
+ parseCompactJwe(jweString: string): JweObject;
154
+ }
@@ -0,0 +1,3 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/interfaces/ICryptography.ts
3
+ export {};
@@ -0,0 +1,55 @@
1
+ import { JwkSet } from '../models/jwk';
2
+ /**
3
+ * @interface IWallet
4
+ * Defines the contract for a client-side Wallet, acting as the "frontend KmsService".
5
+ * It provides high-level cryptographic capabilities without exposing low-level primitives.
6
+ * @sdk
7
+ */
8
+ export interface IWallet {
9
+ /**
10
+ * Provisions a new, full set of cryptographic keys for a given entity identifier.
11
+ * This is the primary method for creating a new cryptographic identity.
12
+ * @param entityId The unique identifier for the key set (e.g., a profile ID).
13
+ * @returns A Promise that resolves to the public parts of the generated keys in a JWKSet format.
14
+ */
15
+ provisionKeys(entityId: string): Promise<JwkSet>;
16
+ /**
17
+ * Creates a cryptographic digest (hash) of a string.
18
+ * @param data The string to hash.
19
+ * @param algorithm The digest algorithm to use.
20
+ * @returns A Promise that resolves to the hex-encoded hash string.
21
+ */
22
+ digest(data: string, algorithm: any): Promise<string>;
23
+ /**
24
+ * Encrypts a document for secure, local storage (at-rest).
25
+ * @param doc The document to protect, which must have a `.content` property.
26
+ * @param entityId The ID of the entity whose keys should be used for encryption.
27
+ * @returns A Promise that resolves to the protected document, where `.content` is replaced by `.jwe`.
28
+ */
29
+ protectConfidentialData(doc: any, entityId: string): Promise<any>;
30
+ /**
31
+ * Decrypts a document from secure storage.
32
+ * @param doc The protected document containing the `.jwe` property.
33
+ * @param entityId The ID of the entity whose keys should be used for decryption.
34
+ * @returns A Promise that resolves to the document with the decrypted `.content`.
35
+ */
36
+ unprotectConfidentialData(doc: any, entityId: string): Promise<any>;
37
+ /**
38
+ * (Optional) Packs a DIDComm message into a secure format (JWE/JARM) for a recipient.
39
+ * This is required for FAPI-compliant flows.
40
+ * @param content The DIDComm message content to pack.
41
+ * @param recipientDid The DID of the recipient.
42
+ * @returns A Promise that resolves to the packed, secure message string.
43
+ */
44
+ packForRecipient?(content: any, recipientDid: string): Promise<string>;
45
+ /**
46
+ * (Optional) Unpacks a secure message (JWE/JARM) received from a server.
47
+ * This is the counterpart to `packForRecipient`.
48
+ * @param packedMessage The secure message string (e.g., a compact JWE).
49
+ * @returns A Promise that resolves to an object containing the plaintext `content` and any cryptographic `meta` data.
50
+ */
51
+ unpack?(packedMessage: string): Promise<{
52
+ content: any;
53
+ meta: any;
54
+ }>;
55
+ }
@@ -0,0 +1,3 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/interfaces/IWallet.ts
3
+ export {};
@@ -0,0 +1,9 @@
1
+ export declare const MlDsaPubKeySizeLevel2 = 1312;
2
+ export declare const MlDsaPubKeySizeLevel3 = 1952;
3
+ export declare const MlDsaPubKeySizeLevel5 = 2592;
4
+ export declare const MlDsaPrivKeySizeLevel2 = 2528;
5
+ export declare const MlDsaPrivKeySizeLevel3 = 4000;
6
+ export declare const MlDsaPrivKeySizeLevel5 = 4864;
7
+ export declare const MlDsaSignatureSizeLevel2 = 2420;
8
+ export declare const MlDsaSignatureSizeLevel3 = 3293;
9
+ export declare const MlDsaSignatureSizeLevel5 = 4595;
@@ -1,6 +1,5 @@
1
1
  // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
2
  // File: crypto-ts/interfaces/MlDsa.ts
3
-
4
3
  /**
5
4
  * level 2: privateKeySize = 2528, publicKeySize = 1312, signatureSize = 2420
6
5
  * level 3: privateKeySize = 4000, publicKeySize = 1952, signatureSize = 3293
@@ -8,18 +7,15 @@
8
7
  * @see https://openquantumsafe.org/liboqs/algorithms/sig/dilithium.html
9
8
  */
10
9
  ;
11
-
12
10
  // Size of a packed public key: 32 + PolyT1Size*K
13
11
  export const MlDsaPubKeySizeLevel2 = 1312;
14
12
  export const MlDsaPubKeySizeLevel3 = 1952;
15
13
  export const MlDsaPubKeySizeLevel5 = 2592;
16
-
17
14
  // Size of a packed private key : 32 + 32 + 32 + polyLeqEtaSize*(l+k) + PolyT0Size*K
18
15
  export const MlDsaPrivKeySizeLevel2 = 2528;
19
16
  export const MlDsaPrivKeySizeLevel3 = 4000;
20
17
  export const MlDsaPrivKeySizeLevel5 = 4864;
21
-
22
18
  // Size of a packed signature: l*polyLeGamma1Size + omega + k + 32
23
19
  export const MlDsaSignatureSizeLevel2 = 2420;
24
20
  export const MlDsaSignatureSizeLevel3 = 3293;
25
- export const MlDsaSignatureSizeLevel5 = 4595;
21
+ export const MlDsaSignatureSizeLevel5 = 4595;
@@ -0,0 +1,11 @@
1
+ export declare const paramsSymBytes = 32;
2
+ export declare const paramsPolyBytes = 384;
3
+ export declare const paramsPolyvecBytesK512: number;
4
+ export declare const paramsPolyvecBytesK768: number;
5
+ export declare const paramsPolyvecBytesK1024: number;
6
+ /** Kyber512PKBytes is a constant representing the byte length of public keys in Kyber-512 */
7
+ export declare const Kyber512PKBytes: number;
8
+ /** Kyber768PKBytes is a constant representing the byte length of public keys in Kyber-768 */
9
+ export declare const Kyber768PKBytes: number;
10
+ /** Kyber1024PKBytes is a constant representing the byte length of public keys in Kyber-1024 */
11
+ export declare const Kyber1024PKBytes: number;
@@ -1,18 +1,13 @@
1
1
  // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
2
  // File: crypto-ts/interfaces/MlKem.ts
3
-
4
3
  export const paramsSymBytes = 32;
5
-
6
4
  export const paramsPolyBytes = 384;
7
5
  export const paramsPolyvecBytesK512 = 2 * paramsPolyBytes;
8
6
  export const paramsPolyvecBytesK768 = 3 * paramsPolyBytes;
9
7
  export const paramsPolyvecBytesK1024 = 4 * paramsPolyBytes;
10
-
11
8
  /** Kyber512PKBytes is a constant representing the byte length of public keys in Kyber-512 */
12
9
  export const Kyber512PKBytes = paramsPolyvecBytesK512 + paramsSymBytes;
13
-
14
10
  /** Kyber768PKBytes is a constant representing the byte length of public keys in Kyber-768 */
15
11
  export const Kyber768PKBytes = paramsPolyvecBytesK768 + paramsSymBytes;
16
-
17
12
  /** Kyber1024PKBytes is a constant representing the byte length of public keys in Kyber-1024 */
18
13
  export const Kyber1024PKBytes = paramsPolyvecBytesK1024 + paramsSymBytes;
@@ -0,0 +1,85 @@
1
+ export declare const WORD_BYTES = 4;
2
+ export declare const WORD_BITS: number;
3
+ export declare const AES_GCM_256_KEY_SIZE_BITS = 256;
4
+ export declare const AES_GCM_TAG_SIZE_BITS = 128;
5
+ export declare const AES_GCM_NONCE_SIZE_BITS = 128;
6
+ export declare const AES_GCM_JWA_ENC = "A256GCM";
7
+ /**
8
+ * Represents the raw, binary components of a payload encrypted with AES-GCM.
9
+ * This interface is used for in-memory cryptographic operations before any
10
+ * Base64Url encoding is applied. Its string-based counterpart for transport
11
+ * is `ProtectedDataAES`.
12
+ */
13
+ export interface AesGcmComponents {
14
+ /**
15
+ * The encrypted content as a raw byte array.
16
+ */
17
+ ciphertext: Uint8Array;
18
+ /**
19
+ * The Initialization Vector (IV) as a raw byte array.
20
+ */
21
+ iv: Uint8Array;
22
+ /**
23
+ * The Authentication Tag generated by the GCM mode.
24
+ */
25
+ authTag: Uint8Array;
26
+ }
27
+ /**
28
+ * Represents the components of an AES-GCM encrypted payload, with each
29
+ * component encoded as a Base64Url string. This is suitable for use in
30
+ * transport structures like a JWE. Its byte-based counterpart for in-memory
31
+ * operations is `AesGcmComponents`.
32
+ *
33
+ * - ciphertext: base64url encoded bytes of the plaintext
34
+ * - tag: base64url encoded
35
+ * - iv: base64url encoded (it is like a nonce)
36
+ */
37
+ export interface ProtectedDataAES {
38
+ ciphertext: string;
39
+ tag: string;
40
+ iv: string;
41
+ }
42
+ /** Use it instead of the SjclCipherDecryptParams to avoid problems with encryption / decryption
43
+ * iv: required random bytes created for Initialization Vector (nonce) created when doing the encryption, base64 encoded (but not Base64url nor BitArray).
44
+ * adata: AAD (Additional Authenticated Data) base64 encoded (e.g.: JWE protected headers), but not base64url nor BitArray. It can be and empty string "".
45
+ * ct: ciphertext and tag combined and then base64 encoded, but not base64url nor BitArray.
46
+ * ts: tagsize is only required if a value other than the sjcl default value (64 bits) is defined in the encryption options (to know what size authentication tag is part of the cipher text)
47
+ * mode: "ccm", "gcm" (the default is "ccm").
48
+ * ks: keysize is only required if a value other than the sjcl default value (128 bits) is defined in the encryption options (to know what size key to generate with Pbkdf2)
49
+ * iter: iterations for Pbkdf2
50
+ * v: scjl version
51
+ * cipher: "aes"
52
+ */
53
+ export interface DecryptionDataWithParametersSJCL {
54
+ iv: string;
55
+ adata: string;
56
+ ct: string;
57
+ ts?: number;
58
+ mode?: string;
59
+ ks?: number;
60
+ iter?: number;
61
+ v?: number;
62
+ cipher?: string;
63
+ }
64
+ /** Use it instead of the SjclCipherEncryptParams to avoid problems with encryption / decryption
65
+ * iv: required BitArray containing the random bytes for the Initialization Vector (nonce).
66
+ * adata: required BitArray containing the AAD (Additional Authenticated Data), e.g.: JWE protected headers.
67
+ * ts: tagsize is only required if a value other than the sjcl default value (64 bits) is used (to know what size authentication tag is part of the cipher text).
68
+ * mode: "ccm", "gcm" (the default is "ccm").
69
+ * ks: keysize is only required if a value other than the sjcl default value (128 bits) is used (to know what size key to generate with Pbkdf2)
70
+ * iter: iterations for Pbkdf2
71
+ * salt: BitArray, a 64 bits salt it is created automatically if not provided when generating the key from a password (KDF).
72
+ * v: scjl version
73
+ * cipher: "aes"
74
+ */
75
+ export interface EncryptionParametersSJCL {
76
+ iv: any;
77
+ adata: any;
78
+ ts?: number;
79
+ mode?: string;
80
+ ks?: number;
81
+ iter?: number;
82
+ salt?: any;
83
+ v?: number;
84
+ cipher?: string;
85
+ }
@@ -0,0 +1,10 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/models/aes.ts
3
+ export const WORD_BYTES = 4;
4
+ export const WORD_BITS = WORD_BYTES * 8; // sjcl BitArray are words of 32 bits.
5
+ export const AES_GCM_256_KEY_SIZE_BITS = 256; // key size is 32 bytes = 256 bits (by default it is 128 bits).
6
+ export const AES_GCM_TAG_SIZE_BITS = 128; // tag size is 16 bytes = 128 bits (by default it is 64 bits).
7
+ export const AES_GCM_NONCE_SIZE_BITS = 128; // NIST 800-38D 8.2.2 (RGB Construction of IV) allows to be 16 bytes (128 bits).
8
+ export const AES_GCM_JWA_ENC = 'A256GCM'; // AES GCM using 256-bit key, see https://datatracker.ietf.org/doc/html/rfc7518#section-5.1
9
+ ;
10
+ ;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Defines the structure of the claims object decoded from a bearer access token.
3
+ * This object is typically attached to the request object by an authentication middleware.
4
+ */
5
+ export interface IAccessTokenClaims {
6
+ /**
7
+ * Issuer of the token (e.g., the DID of the issuing tenant).
8
+ * This is the source of truth for identifying the tenant.
9
+ */
10
+ iss: string;
11
+ /**
12
+ * Subject of the token (e.g., the DID of the employee).
13
+ */
14
+ sub: string;
15
+ /**
16
+ * Audience for which the token is intended.
17
+ */
18
+ aud: string;
19
+ /**
20
+ * Expiration time (Unix timestamp).
21
+ */
22
+ exp: number;
23
+ /**
24
+ * Issued at time (Unix timestamp).
25
+ */
26
+ iat: number;
27
+ /**
28
+ * The scope of permissions granted by the token.
29
+ */
30
+ scope: string;
31
+ /**
32
+ * Client ID - The client that requested the token.
33
+ */
34
+ client_id: string;
35
+ }
@@ -0,0 +1,3 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: src/models/auth.ts
3
+ export {};