gdc-common-utils-ts 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/PUBLISHING.md +33 -0
  2. package/__tests__/AesManager.test.ts +53 -0
  3. package/__tests__/CryptographyService.test.ts +194 -0
  4. package/__tests__/bundle.test.ts +29 -0
  5. package/__tests__/content.test.ts +72 -0
  6. package/__tests__/crypto-encode-decode.test.ts +52 -0
  7. package/__tests__/crypto-hmac.test.ts +21 -0
  8. package/__tests__/did-generateServiceId.errors.test.ts +8 -0
  9. package/__tests__/did-generateServiceId.test.ts +18 -0
  10. package/__tests__/models-clinical-sections.test.ts +32 -0
  11. package/__tests__/models-multibase58.test.ts +33 -0
  12. package/__tests__/multibase58.errors.test.ts +7 -0
  13. package/__tests__/multibase58.test.ts +28 -0
  14. package/__tests__/multibasehash.test.ts +25 -0
  15. package/__tests__/utils-actor.test.ts +22 -0
  16. package/__tests__/utils-base-convert.test.ts +57 -0
  17. package/__tests__/utils-baseN.test.ts +40 -0
  18. package/__tests__/utils-did-extra.test.ts +33 -0
  19. package/__tests__/utils-format-converter.test.ts +87 -0
  20. package/__tests__/utils-jwt.test.ts +57 -0
  21. package/__tests__/utils-manager-error.test.ts +11 -0
  22. package/__tests__/utils-normalize.test.ts +15 -0
  23. package/__tests__/utils-object-convert.test.ts +38 -0
  24. package/__tests__/utils-string-convert.test.ts +20 -0
  25. package/__tests__/utils-string-utils.test.ts +25 -0
  26. package/__tests__/utils-url.test.ts +21 -0
  27. package/babel.config.cjs +5 -0
  28. package/jest.config.ts +46 -0
  29. package/package.json +36 -0
  30. package/src/AesManager.ts +82 -0
  31. package/src/CryptographyService.ts +461 -0
  32. package/src/JweManager.ts.txt +365 -0
  33. package/src/KmsService.txt +493 -0
  34. package/src/constants/Schemas.ts +61 -0
  35. package/src/constants/index.ts +1 -0
  36. package/src/constants/schemaorg.ts +193 -0
  37. package/src/cryptoDecode.ts +104 -0
  38. package/src/cryptoEncode.ts +36 -0
  39. package/src/cryptography.abstract.ts +29 -0
  40. package/src/hmac.ts +15 -0
  41. package/src/index.ts +3 -0
  42. package/src/interfaces/Cryptography.types.ts +131 -0
  43. package/src/interfaces/ICryptoHelper.ts +33 -0
  44. package/src/interfaces/ICryptography.ts +177 -0
  45. package/src/interfaces/IWallet.ts +62 -0
  46. package/src/interfaces/MlDsa.ts +25 -0
  47. package/src/interfaces/MlKem.ts +18 -0
  48. package/src/models/aes.ts +93 -0
  49. package/src/models/auth.ts +38 -0
  50. package/src/models/bundle.ts +152 -0
  51. package/src/models/bundle.txt +93 -0
  52. package/src/models/clinical-sections.en.ts +82 -0
  53. package/src/models/clinical-sections.ts +64 -0
  54. package/src/models/comm.ts +63 -0
  55. package/src/models/confidential-job.ts +100 -0
  56. package/src/models/confidential-message.ts +137 -0
  57. package/src/models/confidential-storage.ts +170 -0
  58. package/src/models/consent-rule.ts +141 -0
  59. package/src/models/crypto.ts +43 -0
  60. package/src/models/device-license.ts +161 -0
  61. package/src/models/did.ts +81 -0
  62. package/src/models/index.ts +31 -0
  63. package/src/models/indexing.ts +20 -0
  64. package/src/models/issue.ts +85 -0
  65. package/src/models/jsonapi.ts +19 -0
  66. package/src/models/jwe.ts +132 -0
  67. package/src/models/jwk.ts +50 -0
  68. package/src/models/jws.ts +42 -0
  69. package/src/models/jwt.ts +15 -0
  70. package/src/models/multibase58.ts +46 -0
  71. package/src/models/oidc4ida.common.model.ts +39 -0
  72. package/src/models/oidc4ida.document.model.ts +61 -0
  73. package/src/models/oidc4ida.electronicRecord.model.ts +86 -0
  74. package/src/models/oidc4ida.evidence.model.ts +69 -0
  75. package/src/models/openid-device.ts +146 -0
  76. package/src/models/operation-outcome.ts +34 -0
  77. package/src/models/params.ts +142 -0
  78. package/src/models/resource-document.ts +21 -0
  79. package/src/models/response.ts +5 -0
  80. package/src/models/urlPath.ts +76 -0
  81. package/src/models/verifiable-credential.ts +52 -0
  82. package/src/types/noble-hashes.d.ts +4 -0
  83. package/src/utils/actor.ts +52 -0
  84. package/src/utils/base-convert.ts +77 -0
  85. package/src/utils/baseN.ts +203 -0
  86. package/src/utils/bundle.ts +30 -0
  87. package/src/utils/content.ts +66 -0
  88. package/src/utils/did.ts +155 -0
  89. package/src/utils/format-converter.ts +119 -0
  90. package/src/utils/index.ts +13 -0
  91. package/src/utils/jwt.ts +165 -0
  92. package/src/utils/manager-error.ts +27 -0
  93. package/src/utils/multibase58.ts +46 -0
  94. package/src/utils/multibasehash.ts +28 -0
  95. package/src/utils/normalize.ts +43 -0
  96. package/src/utils/object-convert.ts +57 -0
  97. package/src/utils/string-convert.ts +71 -0
  98. package/src/utils/string-utils.ts +70 -0
  99. package/src/utils/url.ts +46 -0
  100. package/tsconfig.json +13 -0
@@ -0,0 +1,146 @@
1
+ // src/models/openid-device.ts
2
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
3
+
4
+ /**
5
+ * @fileoverview Defines data models for device registration based on OpenID Connect Dynamic Client Registration 1.0,
6
+ * with custom extensions for native device information.
7
+ * @see https://openid.net/specs/openid-connect-registration-1_0.html
8
+ */
9
+
10
+ import { JwkSet } from "./jwk";
11
+
12
+ /**
13
+ * Represents the information about the physical device being registered.
14
+ * This is a custom extension to the OpenID DCR standard.
15
+ */
16
+ export interface OpenIdDeviceInfo {
17
+ /**
18
+ * The push notification token for the device.
19
+ * @example "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]"
20
+ */
21
+ push_token: string;
22
+
23
+ /**
24
+ * The push notification provider.
25
+ * @example "expo"
26
+ */
27
+ push_provider: string;
28
+
29
+ /**
30
+ * A unique identifier for the device, such as the OS internal build ID.
31
+ * @example "19.6.0"
32
+ */
33
+ device_id: string;
34
+
35
+ /**
36
+ * A user-friendly name for the device.
37
+ * @example "John's iPhone"
38
+ */
39
+ device_name: string;
40
+ }
41
+
42
+ /**
43
+ * Represents the request payload for Dynamic Client Registration,
44
+ * based on OpenID Connect Registration 1.0.
45
+ * The `body` of the DIDComm message will contain this object.
46
+ * @see https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationRequest
47
+ */
48
+ export interface DcrRegistrationRequest {
49
+ // --- Standard OIDC DCR Fields ---
50
+
51
+ /**
52
+ * Array of redirection URIs for use in redirect-based flows. For a native app,
53
+ * this could be a custom scheme URI.
54
+ * @example ["myapp://callback"]
55
+ */
56
+ redirect_uris: string[];
57
+
58
+ /**
59
+ * Kind of the application. The only supported value is 'native'.
60
+ */
61
+ application_type?: 'native';
62
+
63
+ /**
64
+ * Human-readable name of the client to be presented to the end-user.
65
+ * @example "My Awesome App"
66
+ */
67
+ client_name?: string;
68
+
69
+ /**
70
+ * URL of the home page of the client.
71
+ */
72
+ client_uri?: string;
73
+
74
+ /**
75
+ * Requested authentication method for the token endpoint.
76
+ * For apps using public keys, 'private_key_jwt' is common.
77
+ * 'none' can be used for public clients.
78
+ */
79
+ token_endpoint_auth_method?: 'none' | 'private_key_jwt';
80
+
81
+ /**
82
+ * A list of OAuth 2.0 grant types that the client will restrict itself to using.
83
+ */
84
+ grant_types?: ('authorization_code' | 'implicit' | 'refresh_token' | 'client_credentials')[];
85
+
86
+ /**
87
+ * URL for the client's JSON Web Key Set [JWK] document. If the client signs requests to the Server,
88
+ * it contains the signing key(s) the Server uses to validate signatures from the Client.
89
+ */
90
+ jwks_uri?: string;
91
+
92
+ /**
93
+ * JSON Web Key Set containing the client's public keys.
94
+ * REQUIRED if `jwks_uri` is not provided.
95
+ */
96
+ jwks?: JwkSet;
97
+
98
+ // --- Custom Extension Fields ---
99
+
100
+ /**
101
+ * Custom data about the specific device instance being registered.
102
+ * This is prefixed to avoid collision with standard fields.
103
+ */
104
+ ext_device_info?: OpenIdDeviceInfo;
105
+ }
106
+
107
+ /**
108
+ * Represents the response payload for a successful Dynamic Client Registration,
109
+ * based on OpenID Connect Registration 1.0.
110
+ * This object will be nested inside the `resource` of the final BundleEntry.
111
+ * @see https://openid.net/specs/openid-connect-registration-1_0.html#RegistrationResponse
112
+ */
113
+ export interface DcrRegistrationResponse {
114
+ /**
115
+ * Unique client identifier.
116
+ */
117
+ client_id: string;
118
+
119
+ /**
120
+ * Time at which the client_id was issued, represented as a Unix timestamp.
121
+ */
122
+ client_id_issued_at: number;
123
+
124
+ /**
125
+ * The client secret. For public clients or those using JWTs for client authentication,
126
+ * this may not be returned.
127
+ */
128
+ client_secret?: string;
129
+
130
+ /**
131
+ * Time at which the client_secret will expire, represented as a Unix timestamp.
132
+ * If 0, the secret does not expire.
133
+ */
134
+ client_secret_expires_at?: number;
135
+
136
+ /**
137
+ * A registration access token that can be used at the client configuration endpoint
138
+ * to perform subsequent operations upon the client registration.
139
+ */
140
+ registration_access_token?: string;
141
+
142
+ /**
143
+ * URL of the client's configuration endpoint.
144
+ */
145
+ registration_client_uri?: string;
146
+ }
@@ -0,0 +1,34 @@
1
+ // src/models/fhir/operation-outcome.ts
2
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
3
+
4
+ import { IssueLevel, IssueTypeCode } from './issue';
5
+
6
+ /**
7
+ * A single detail associated with an operation, based on a simplified FHIR structure.
8
+ * Renamed from 'Issue' to be more neutral for potential success reporting.
9
+ */
10
+ export interface OperationOutcomeDetails {
11
+ /**
12
+ * Indicates the severity of the detail.
13
+ */
14
+ severity: IssueLevel;
15
+
16
+ /**
17
+ * A code classifying the type of detail.
18
+ */
19
+ code: IssueTypeCode;
20
+
21
+ /**
22
+ * Additional diagnostic information, such as a stack trace or detailed error message.
23
+ */
24
+ diagnostics?: string;
25
+ }
26
+
27
+ /**
28
+ * A structured response detailing the result of an operation, based on a simplified FHIR structure.
29
+ */
30
+ export interface OperationOutcome {
31
+ resourceType: 'OperationOutcome';
32
+ issue: OperationOutcomeDetails[];
33
+ }
34
+
@@ -0,0 +1,142 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/models/params.ts
3
+
4
+ /**
5
+ * Represents a interoperable claim for all specifications.
6
+ */
7
+ export interface ClaimInteroperable {
8
+ /**
9
+ * Key name of the interoperable claim in reverse-DNS (e.g., 'org.hl7.fhir.immunization.vaccine-code').
10
+ */
11
+ name: string;
12
+ /**
13
+ * The value of the claim. Can be either a string or a number.
14
+ * Derived interfaces may specify more precise types.
15
+ */
16
+ value: any;
17
+ }
18
+
19
+ /**
20
+ * Represents a single, named piece of data within an entity's configuration,
21
+ * aligning with the structure of a Parameter in the FHIR Parameters resource.
22
+ *
23
+ * This structure is used to store secondary or multi-value attributes (like
24
+ * multiple emails or official identifiers) in their original, readable format.
25
+ * The entire collection of these attributes is considered private and is always
26
+ * stored within an encrypted parent configuration object.
27
+ *
28
+ * @see {@link https://hl7.org/fhir/parameters.html}
29
+ */
30
+ export interface ParamAttribute extends ClaimInteroperable {
31
+ /**
32
+ * The name of the parameter, which often corresponds to a key in the
33
+ * 'indexed' attributes dictionary of the parent configuration.
34
+ *
35
+ * @example 'NNES' (for a Spanish DNI, unique=true)
36
+ * @example 'email' (unique=falsez)
37
+ */
38
+ name: string;
39
+
40
+ /**
41
+ * The original value of the parameter. Can be either a string or a number.
42
+ * This corresponds to a simplified `value[x]` (e.g., `valueString`) in a FHIR Parameter.
43
+ */
44
+ value: string | number | undefined;
45
+
46
+ /**
47
+ * A custom flag to indicate whether this attribute's value is expected to
48
+ * be unique across all entities of the same type. This is used for
49
+ * server-side validation logic and is not part of the FHIR standard.
50
+ * @default false
51
+ */
52
+ unique?: boolean;
53
+ }
54
+
55
+ export type ParameterType = 'number' | 'date' | 'string' | 'token' | 'reference' | 'composite' | 'quantity' | 'uri' | 'period';
56
+
57
+ /**
58
+ * Represents a common interface for all types of parameters.
59
+ */
60
+ export interface ParameterData extends ParamAttribute {
61
+ /**
62
+ * Defines the type of parameter.
63
+ */
64
+ type: ParameterType | string;
65
+ /**
66
+ * (Optional) Coding system (e.g., SNOMED, LOINC...).
67
+ */
68
+ system?: string;
69
+ /**
70
+ * (Optional) Unit of measurement (e.g., ml, mg...).
71
+ */
72
+ unit?: string;
73
+ /**
74
+ * (Optional) Indicates if the date is a Period (e.g., FHIR effectivePeriod or FHIR onsetPeriod).
75
+ */
76
+ period?: boolean;
77
+ /**
78
+ * (Optional) The end date of a FHIR Period.
79
+ */
80
+ end?: string;
81
+ /**
82
+ * (Optional) Prefix for dates and quantities for comparisons (e.g., eq, gt, lt, ...).
83
+ */
84
+ prefix?: string;
85
+ /**
86
+ * (Optional) International display derived from a FHIR Coding within a CodeableConcept.
87
+ */
88
+ intDisplay?: string;
89
+ /**
90
+ * (Optional) Localized text derived from a FHIR CodeableConcept.
91
+ */
92
+ localizedText?: string;
93
+ /**
94
+ * (Optional) A hint or tooltip to guide users in a UI setting.
95
+ */
96
+ hint?: string;
97
+ /**
98
+ * (Optional) A list of select options for UI dropdowns or similar components.
99
+ */
100
+ optionsList?: any[];
101
+ /**
102
+ * (Optional) Resources to which this parameter is applicable.
103
+ */
104
+ appliesTo?: string[];
105
+ }
106
+
107
+ export interface StringSearchParameter extends ParameterData {
108
+ type: 'string';
109
+ value: string;
110
+ }
111
+ export interface NumberSearchParameter extends ParameterData {
112
+ value: number;
113
+ }
114
+ export interface DateSearchParameter extends ParameterData {
115
+ value: string;
116
+ end?: string;
117
+ period?: boolean;
118
+ }
119
+ export interface TokenSearchParameter extends ParameterData {
120
+ type: 'token';
121
+ value: string;
122
+ system: string;
123
+ }
124
+ export interface ReferenceSearchParameter extends ParameterData {
125
+ type: 'reference';
126
+ reference: string;
127
+ }
128
+ export interface CompositeSearchParameter extends ParameterData {
129
+ type: 'composite';
130
+ components: ParameterData[];
131
+ }
132
+ export interface QuantitySearchParameter extends ParameterData {
133
+ type: 'quantity';
134
+ value: number;
135
+ system: string;
136
+ unit: string;
137
+ }
138
+ export interface URISearchParameter extends ParameterData {
139
+ type: 'uri';
140
+ value: string;
141
+ }
142
+ export type FHIRSearchParameter = NumberSearchParameter | DateSearchParameter | StringSearchParameter | TokenSearchParameter | ReferenceSearchParameter | CompositeSearchParameter | QuantitySearchParameter | URISearchParameter;
@@ -0,0 +1,21 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/models/resource-document.ts
3
+
4
+ /**
5
+ * A flexible record type for claims objects.
6
+ */
7
+ export type ClaimsRecord = Record<string, any>;
8
+
9
+ // A generic type for records stored in the vault.
10
+ export interface RecordBase {
11
+ id: string;
12
+ }
13
+
14
+ /**
15
+ * Represents the configuration metadata for a vault.
16
+ * As defined in the original database abstract layer.
17
+ */
18
+ export interface VaultConfig extends RecordBase{
19
+ custodian?: string; // The tenant responsible for this vault
20
+ }
21
+
@@ -0,0 +1,5 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/models/response.ts
3
+
4
+ // Re-exported for backwards compatibility. The canonical definition lives in `confidential-message.ts`.
5
+ export type { IDecodedDidcommPayload } from './confidential-message';
@@ -0,0 +1,76 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/models/urlPath.ts
3
+
4
+ /**
5
+ * Defines the standardized business sectors supported by the gateway.
6
+ * Using an enum ensures type safety and prevents the use of arbitrary strings.
7
+ */
8
+ export enum Sector {
9
+ TEST = 'test', // For mock/demo endpoints and host registry in tests
10
+ SYSTEM = 'system', // Reserved for the host's bootstrap operation (TODO: deprecate)
11
+ HEALTH_CARE = 'health-care',
12
+ HEALTH_INSURANCE = 'health-insurance',
13
+ EMERGENCY = 'emergency',
14
+ RESEARCH = 'research',
15
+ }
16
+
17
+ export enum Section {
18
+ /** Managing registration of organizations */
19
+ registry = 'registry',
20
+ /** Managing data of the hosted organization */
21
+ entity = 'entity',
22
+ /** Managing data of the hosted individual */
23
+ individual = 'individual',
24
+ /** Managing data in the blockchain network */
25
+ network = 'network', // generic 'network' for the path, but customized network name can be used
26
+ }
27
+
28
+ /** Standards, specifications and formats for data supported in the url path */
29
+ export enum Format {
30
+ Schema = 'org.schema',
31
+ FhirApi = 'org.hl7.fhir.api',
32
+ //Pdf' = 'pdf',
33
+ }
34
+
35
+ /** Types of resources supported in the url path */
36
+ export enum Resource {
37
+ Person = 'Person',
38
+ RelatedPerson = 'RelatedPerson',
39
+ Employee = 'Emloyee',
40
+ EmployeeRole = 'EmloyeeRole',
41
+ Practitioner = 'Practitioner',
42
+ PractitionerRole = 'PractitionerRole',
43
+ Organization = 'Organization',
44
+ Location = 'Location',
45
+ Group = 'Group',
46
+ }
47
+
48
+ export enum JobAction {
49
+ "_batch" = "_batch",
50
+ "_create" = "_create",
51
+ "_discovery" = "_discovery"
52
+ }
53
+
54
+ export enum knownDomainsReversedEnum {
55
+ 'org.schema' = 'org.schema',
56
+ 'org.hl7.fhir.api' = 'org.hl7.fhir.api',
57
+ 'org.hl7.fhir.r4' = 'org.hl7.fhir.r4',
58
+ 'org.ilo.isco' = 'org.ilo.isco',
59
+ 'net.openid' = 'net.openid',
60
+ // Add other known standards here
61
+ };
62
+
63
+ /**
64
+ * A list of known, fully-qualified context prefixes in reverse DNS format.
65
+ * This is used by the claim normalization utility to identify claims that
66
+ * are already interoperable and should not be modified.
67
+ * All entries should be in lowercase.
68
+ */
69
+ export const knownDomainsReversed: string[] = [
70
+ knownDomainsReversedEnum["org.schema"],
71
+ knownDomainsReversedEnum["org.hl7.fhir.api"],
72
+ knownDomainsReversedEnum["org.hl7.fhir.r4"],
73
+ knownDomainsReversedEnum["org.ilo.isco"],
74
+ knownDomainsReversedEnum["net.openid"]
75
+ // Add other known standards here
76
+ ];
@@ -0,0 +1,52 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: crypto-ts/models/verifiable-credential.ts
3
+
4
+ import { EvidenceObjectDLT } from "./oidc4ida.evidence.model"
5
+
6
+ /**
7
+ * Defines the JSON-LD context URI for W3C Verifiable Credentials Data Model v2.0.
8
+ * This constant MUST be used for all V2 credential creations to ensure consistency.
9
+ * @see https://www.w3.org/TR/vc-data-model-2.0/#contexts
10
+ */
11
+ export const VC_CONTEXT_V2 = 'https://www.w3.org/ns/credentials/v2';
12
+
13
+ /** ProofEBSIv2 foresees the possibility to use different types of proofs for Verifiable Credentials,
14
+ * such as proofs derived from eIDAS keys (qualified) to DID keys (unqualified).
15
+ * In EBSI 2.0, every V-ID will only contain a single proof, which must be derived from eIDAS keys.
16
+ * Definition: https://www.w3.org/TR/vc-data-model/#proofs-signatures
17
+ * See https://ec.europa.eu/digital-building-blocks/wikis/display/EBSIDOC/Verifiable+Attestation
18
+ * - 'created' is REQURED, it is the ISO 8601 original timestamp of the signature, it is not the same as credential.issued (tx timestamp) (in Aries go framework use *util.TimeWithTrailingZeroMsec instead of time.Time)
19
+ * - 'jws' is REQUIRED, it defines the detached JWS signature string "<base64url(protectedheader)>..<base64url(signature)>"
20
+ * - 'proofPurpose' is REQUIRED, e.g.: assertionMethod, authentication, keyAgreement, contractAgreement, capabilityInvocation, capabilityDelegation
21
+ * - 'type' is REQUIRED, e.g.: "JsonWebSignature2020", "BbsBlsSignature2020", "BbsBlsSignatureProof2020".
22
+ * - 'verificationMethod' is REQUIRED, it is the 'urndid#keyId' to verify the signature by using the issuer's public signature key.
23
+ */
24
+ export interface ProofEBSIv2 {
25
+ created?: string // ISO 8601 original timestamp of the signature, it is not the same as credential.issued (tx timestamp) (in Aries go framework use *util.TimeWithTrailingZeroMsec instead of time.Time)
26
+ jws?: string // The detached JWS signature string "<base64url(protectedheader)>..<base64url(signature)>"
27
+ proofPurpose?: string // assertionMethod, authentication, keyAgreement, contractAgreement, capabilityInvocation, capabilityDelegation
28
+ type: string // "JsonWebSignature2020", "BbsBlsSignature2020", "BbsBlsSignatureProof2020"
29
+ verificationMethod?: string // The DID URL of the public key, e.g., "did:web:host.example.com#keyIdThumbprintBase64urlEncoded"
30
+ }
31
+
32
+ /**
33
+ * Defines the structure for a W3C Verifiable Credential.
34
+ * The credentialSubject can be any object containing the claims.
35
+ * @see https://www.w3.org/TR/vc-data-model-2.0/#verifiable-credentials
36
+ */
37
+ export interface VerifiableCredentialV2 {
38
+ '@context': string[];
39
+ id?: string; // A unique identifier for the credential, e.g. hash result of the credential version (unique URN).
40
+ type: string[];
41
+ /** Claims about the subject, such as the "identifier" or subject's URN */
42
+ credentialSubject: Record<string, any>;
43
+ /** Evidence for Identity Assurance: https://openid.net/specs/openid-ida-verified-claims-1_0-final.html#section-5.4.4 */
44
+ evidence?: EvidenceObjectDLT[];
45
+ /** The issuer is the creator (e.g., "did:web:gateway.example.com"), but could be distinct to the signer of a proof */
46
+ issuer: string; // The DID of the issuer
47
+ /** Proof is optional during creation, but required for a signed VC */
48
+ proof?: ProofEBSIv2 | ProofEBSIv2[];
49
+ validFrom: string; // ISO 8601 timestamp, e.g.: 2025-09-29T11:31:00Z
50
+ validUntil?: string; // ISO 8601 timestamp, e.g.: 2026-09-29T11:30:59Z
51
+ }
52
+
@@ -0,0 +1,4 @@
1
+ declare module '@noble/hashes/hmac.js';
2
+ declare module '@noble/hashes/sha3.js';
3
+ declare module '@noble/hashes/sha2.js';
4
+ declare module '@noble/hashes/utils.js';
@@ -0,0 +1,52 @@
1
+ // src/utils/actor.ts
2
+
3
+ export type ParsedActor = {
4
+ /**
5
+ * The token subject / authenticated actor identifier (as provided in the token request).
6
+ * Examples:
7
+ * - did:web:api.acme.org:employee:doctor1@acme.org:role:ISCO-08|2211
8
+ * - doctor1@acme.org
9
+ */
10
+ sub: string;
11
+ /** The employee email if present (either from did:web employee DID or raw email). */
12
+ email?: 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
+
19
+ export function parseActorFromSub(sub: string): ParsedActor {
20
+ const trimmed = (sub || '').trim();
21
+ const parsed: ParsedActor = { sub: trimmed };
22
+ if (!trimmed) return parsed;
23
+
24
+ if (trimmed.startsWith('did:web:')) {
25
+ // Base org DID is always the first component after did:web:
26
+ // did:web:<host>[:...]
27
+ const after = trimmed.replace(/^did:web:/, '');
28
+ const host = after.split(':')[0];
29
+ if (host) parsed.organization = `did:web:${host}`;
30
+
31
+ // Extract email and role from the canonical employee DID shape:
32
+ // did:web:<host>:employee:<email>:role:<roleCode>[:device:<uuid>]
33
+ const parts = after.split(':');
34
+ const employeeIdx = parts.indexOf('employee');
35
+ if (employeeIdx >= 0 && parts.length > employeeIdx + 1) {
36
+ const email = parts[employeeIdx + 1];
37
+ if (email && email.includes('@')) parsed.email = email.toLowerCase();
38
+ }
39
+ const roleIdx = parts.indexOf('role');
40
+ if (roleIdx >= 0 && parts.length > roleIdx + 1) {
41
+ parsed.role = parts[roleIdx + 1];
42
+ }
43
+ return parsed;
44
+ }
45
+
46
+ // Raw email actor identifier
47
+ if (trimmed.includes('@') && !/\s/.test(trimmed)) {
48
+ parsed.email = trimmed.toLowerCase();
49
+ }
50
+ return parsed;
51
+ }
52
+
@@ -0,0 +1,77 @@
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
+
12
+ /** Converts a Uint8Array to a hexadecimal string. */
13
+ export function bytesToHexString(bytes: Uint8Array): string {
14
+ return Array.from(bytes, (byte) => {
15
+ return ('0' + (byte & 0xff).toString(16)).slice(-2);
16
+ }).join('');
17
+ };
18
+
19
+ /** Encodes a Uint8Array into a Base58 string. */
20
+ export function bytesToBase58(bytes: Uint8Array): string {
21
+ return encodeN(bytes, alphabetBase58, undefined);
22
+ }
23
+
24
+ /** Decodes a Base58 string into a Uint8Array. */
25
+ export function base58ToBytes(base58str: string): Uint8Array {
26
+ return decodeN(base58str, alphabetBase58);
27
+ }
28
+
29
+ /** Encodes a string into a standard Base64 string (with padding). */
30
+ export function stringToStdBase64(str: string): string {
31
+ const dataBytes: Uint8Array = stringToBytesUTF8(str);
32
+ return encodeBase64(dataBytes);
33
+ }
34
+
35
+ /** Converts a standard Base64 string to a Base64URL string. */
36
+ export function base64ToBase64Url(encodedData: string): string {
37
+ if (encodedData && (encodedData.indexOf("+") !== -1 || encodedData.indexOf("/") !== -1)) {
38
+ return encodedData.split("+").join("-").split("/").join("_");
39
+ } else {
40
+ return encodedData;
41
+ }
42
+ }
43
+
44
+ /** Encodes a string into a Base64URL string. */
45
+ export function stringToBase64Url(stringifiedData: string): string {
46
+ const encodedData = stringToStdBase64(stringifiedData);
47
+ return base64ToBase64Url(encodedData);
48
+ }
49
+
50
+ /** Converts a Base64URL string to a standard Base64 string. */
51
+ export function base64UrlToBase64(encodedData: string): string {
52
+ if (encodedData && (encodedData.indexOf("-") !== -1 || encodedData.indexOf("_") !== -1)) {
53
+ return encodedData.split("-").join("+").split("_").join("/");
54
+ } else {
55
+ return encodedData;
56
+ }
57
+ }
58
+
59
+ /** Decodes a string that is either Base64 or Base64URL into a Uint8Array. */
60
+ export function base64OrUrlSafeToBytes(base64OrUrlSafe: string): Uint8Array {
61
+ if (String(base64OrUrlSafe).includes("+") || String(base64OrUrlSafe).includes("/")) {
62
+ return new Uint8Array(decodeBase64(base64OrUrlSafe));
63
+ } else {
64
+ return new Uint8Array(decodeURLSafe(base64OrUrlSafe));
65
+ }
66
+ }
67
+
68
+ /** Encodes a Uint8Array into a standard Base64 string (with padding). */
69
+ export function bytesToBase64(bytes: Uint8Array): string {
70
+ return encodeBase64(bytes);
71
+ }
72
+
73
+ /** Encodes a Uint8Array into a raw Base64URL string (no padding). */
74
+ export function bytesToRawBase64UrlSafe(bytes: Uint8Array): string {
75
+ return encodeURLSafe(bytes).replace(/=/g, "");
76
+ }
77
+