gdc-common-utils-ts 2.3.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/dist/CryptographyService.d.ts +3 -0
- package/dist/CryptographyService.js +64 -35
- package/dist/constants/identity-identifiers.d.ts +60 -7
- package/dist/constants/identity-identifiers.js +58 -7
- package/dist/constants/schemaorg.d.ts +4 -0
- package/dist/constants/schemaorg.js +4 -0
- package/dist/constants/urn.d.ts +1 -0
- package/dist/constants/urn.js +1 -0
- package/dist/convert/index.d.ts +1 -0
- package/dist/convert/index.js +1 -0
- package/dist/convert/schemaorg-to-gaia-x.d.ts +116 -0
- package/dist/convert/schemaorg-to-gaia-x.js +211 -0
- package/dist/examples/shared.d.ts +1 -1
- package/dist/examples/shared.js +1 -1
- package/dist/models/bundle-editor-types.d.ts +13 -3
- package/dist/models/bundle-editor-types.js +9 -1
- package/dist/models/gaia-x.d.ts +132 -0
- package/dist/models/gaia-x.js +26 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.js +2 -0
- package/dist/models/interoperable-claims/invoice-claims.d.ts +1 -1
- package/dist/models/interoperable-claims/invoice-claims.js +2 -2
- package/dist/models/interoperable-claims/observation-claims.d.ts +2 -2
- package/dist/models/interoperable-claims/observation-claims.js +2 -2
- package/dist/models/jwe.d.ts +25 -0
- package/dist/models/subject-identifier-ledger.d.ts +16 -0
- package/dist/models/subject-identifier-ledger.js +1 -0
- package/dist/utils/bundle-editor-core.d.ts +9 -0
- package/dist/utils/bundle-editor-core.js +46 -0
- package/dist/utils/bundle-editor.d.ts +2 -0
- package/dist/utils/bundle-editor.js +2 -0
- package/dist/utils/bundle-entry-editor.d.ts +6 -0
- package/dist/utils/bundle-entry-editor.js +20 -0
- package/dist/utils/communication-consent-access-editor.d.ts +14 -1
- package/dist/utils/communication-consent-access-editor.js +27 -0
- package/dist/utils/consent-entry-editor.d.ts +42 -0
- package/dist/utils/consent-entry-editor.js +80 -0
- package/dist/utils/did.d.ts +2 -2
- package/dist/utils/did.js +3 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/individual-identifier.d.ts +14 -0
- package/dist/utils/individual-identifier.js +39 -0
- package/dist/utils/multibasehash.d.ts +19 -5
- package/dist/utils/multibasehash.js +35 -10
- package/dist/utils/multiformat-profile.d.ts +4 -2
- package/dist/utils/multiformat-profile.js +5 -3
- package/dist/utils/related-person-entry-editor.d.ts +32 -0
- package/dist/utils/related-person-entry-editor.js +97 -0
- package/dist/utils/same-as.d.ts +10 -0
- package/dist/utils/same-as.js +28 -3
- package/package.json +2 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File discipline note:
|
|
3
|
+
* - Read `ARCHITECTURE.md` and `CONTRIBUTING.md` before changing this module.
|
|
4
|
+
* - This file owns only the typed editor for one staged RelatedPerson entry.
|
|
5
|
+
*/
|
|
6
|
+
import { RelatedPersonClaim } from '../models/interoperable-claims/related-person-claims.js';
|
|
7
|
+
import { BundleEditableResourceTypes } from '../models/bundle-editor-types.js';
|
|
8
|
+
import { BundleEntryEditor } from './bundle-entry-editor.js';
|
|
9
|
+
import { registerBundleEntryEditor } from './bundle-editor-registry.js';
|
|
10
|
+
function normalizeText(value) {
|
|
11
|
+
const normalized = String(value || '').trim();
|
|
12
|
+
return normalized || undefined;
|
|
13
|
+
}
|
|
14
|
+
function normalizeList(values) {
|
|
15
|
+
return [...new Set(values.map((value) => String(value || '').trim()).filter(Boolean))];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Typed editor for one RelatedPerson/contact staged inside a Bundle.
|
|
19
|
+
*
|
|
20
|
+
* Relationship authoring is separate from access authorization. This editor
|
|
21
|
+
* does not grant Consent, build a Communication, submit or poll.
|
|
22
|
+
*/
|
|
23
|
+
export class RelatedPersonEntryEditor extends BundleEntryEditor {
|
|
24
|
+
setIdentifier(value) {
|
|
25
|
+
const normalized = normalizeText(value);
|
|
26
|
+
if (!normalized) {
|
|
27
|
+
this.removeClaim(RelatedPersonClaim.IdentifierValue)
|
|
28
|
+
.removeClaim(RelatedPersonClaim.Identifier)
|
|
29
|
+
.setResourceId()
|
|
30
|
+
.setFullUrl();
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
return this.setClaim(RelatedPersonClaim.IdentifierValue, normalized)
|
|
34
|
+
.setClaim(RelatedPersonClaim.Identifier, normalized)
|
|
35
|
+
.setResourceId(normalized)
|
|
36
|
+
.setFullUrl(normalized);
|
|
37
|
+
}
|
|
38
|
+
getIdentifier() {
|
|
39
|
+
return normalizeText(String(this.getClaim(RelatedPersonClaim.IdentifierValue)
|
|
40
|
+
|| this.getClaim(RelatedPersonClaim.Identifier)
|
|
41
|
+
|| this.getResourceId()
|
|
42
|
+
|| this.getFullUrl()
|
|
43
|
+
|| ''));
|
|
44
|
+
}
|
|
45
|
+
ensureIdentifier() {
|
|
46
|
+
const identifier = this.getIdentifier();
|
|
47
|
+
if (!identifier)
|
|
48
|
+
throw new Error('RelatedPerson entry requires a generated resource id or explicit identifier.');
|
|
49
|
+
this.setIdentifier(identifier);
|
|
50
|
+
return identifier;
|
|
51
|
+
}
|
|
52
|
+
setActive(value) {
|
|
53
|
+
return value === undefined || value === null
|
|
54
|
+
? this.removeClaim(RelatedPersonClaim.Active)
|
|
55
|
+
: this.setClaim(RelatedPersonClaim.Active, value);
|
|
56
|
+
}
|
|
57
|
+
getActive() {
|
|
58
|
+
const value = this.getClaim(RelatedPersonClaim.Active);
|
|
59
|
+
if (typeof value === 'boolean')
|
|
60
|
+
return value;
|
|
61
|
+
if (String(value).toLowerCase() === 'true')
|
|
62
|
+
return true;
|
|
63
|
+
if (String(value).toLowerCase() === 'false')
|
|
64
|
+
return false;
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
setSubject(value) { return this.setOptionalText(RelatedPersonClaim.Patient, value); }
|
|
68
|
+
getSubject() { return this.getOptionalText(RelatedPersonClaim.Patient); }
|
|
69
|
+
setRelationship(value) { return this.setOptionalText(RelatedPersonClaim.Relationship, value); }
|
|
70
|
+
getRelationship() { return this.getOptionalText(RelatedPersonClaim.Relationship); }
|
|
71
|
+
setRoleList(values) { return this.setList(RelatedPersonClaim.Role, values); }
|
|
72
|
+
getRoleList() { return this.getList(RelatedPersonClaim.Role); }
|
|
73
|
+
setName(value) { return this.setOptionalText(RelatedPersonClaim.Name, value); }
|
|
74
|
+
getName() { return this.getOptionalText(RelatedPersonClaim.Name); }
|
|
75
|
+
setTelecom(value) { return this.setOptionalText(RelatedPersonClaim.Telecom, value); }
|
|
76
|
+
getTelecom() { return this.getOptionalText(RelatedPersonClaim.Telecom); }
|
|
77
|
+
setRelatedEntityType(value) { return this.setOptionalText(RelatedPersonClaim.RelatedEntityType, value); }
|
|
78
|
+
getRelatedEntityType() { return this.getOptionalText(RelatedPersonClaim.RelatedEntityType); }
|
|
79
|
+
setActorIdentifierList(values) { return this.setList(RelatedPersonClaim.ActorIdentifier, values); }
|
|
80
|
+
getActorIdentifierList() { return this.getList(RelatedPersonClaim.ActorIdentifier); }
|
|
81
|
+
setOptionalText(key, value) {
|
|
82
|
+
const normalized = normalizeText(value);
|
|
83
|
+
return normalized ? this.setClaim(key, normalized) : this.removeClaim(key);
|
|
84
|
+
}
|
|
85
|
+
getOptionalText(key) {
|
|
86
|
+
return normalizeText(String(this.getClaim(key) || ''));
|
|
87
|
+
}
|
|
88
|
+
setList(key, values) {
|
|
89
|
+
const normalized = normalizeList(values);
|
|
90
|
+
return normalized.length ? this.setClaim(key, normalized.join(',')) : this.removeClaim(key);
|
|
91
|
+
}
|
|
92
|
+
getList(key) {
|
|
93
|
+
const value = this.getClaim(key);
|
|
94
|
+
return normalizeList(Array.isArray(value) ? value.map(String) : String(value || '').split(','));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
registerBundleEntryEditor(BundleEditableResourceTypes.relatedPerson, RelatedPersonEntryEditor);
|
package/dist/utils/same-as.d.ts
CHANGED
|
@@ -49,6 +49,16 @@ export declare function normalizeSameAsHash(value: string): string;
|
|
|
49
49
|
* @param value Canonical sameAs source value(s).
|
|
50
50
|
*/
|
|
51
51
|
export declare function normalizeSameAsHashList(value: string | readonly string[] | undefined): string[];
|
|
52
|
+
/**
|
|
53
|
+
* Splits a public alias CSV without changing the aliases themselves.
|
|
54
|
+
*
|
|
55
|
+
* Use this for mixed DID/CID `sameAs` indexes. Unlike
|
|
56
|
+
* `normalizeSameAsHashList`, it deliberately does not interpret a CIDv1
|
|
57
|
+
* beginning with `z` as a bare `urn:multibase` value.
|
|
58
|
+
*/
|
|
59
|
+
export declare function normalizePublicAliasList(value: string | readonly string[] | undefined): string[];
|
|
60
|
+
/** Derives an opaque SHA3-384 multihash URN for a global-ledger alias key. */
|
|
61
|
+
export declare function buildPublicAliasLedgerAssetId(alias: string): string;
|
|
52
62
|
/**
|
|
53
63
|
* Joins one or more normalized `sameAs` aliases into the current flat CSV
|
|
54
64
|
* storage form used by some shared VC/profile helpers.
|
package/dist/utils/same-as.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sha3_256 } from '@noble/hashes/sha3.js';
|
|
2
|
+
import { utf8ToBytes } from '@noble/hashes/utils.js';
|
|
2
3
|
import { normalizePhone } from './consent.js';
|
|
3
4
|
import { encodeMultibase58btc } from './multibase58.js';
|
|
5
|
+
import { encodeMultibaseSha3 } from './multibasehash.js';
|
|
6
|
+
import { UrnPrefixes } from '../constants/urn.js';
|
|
4
7
|
/**
|
|
5
8
|
* Builds the ICA-compatible multibase58(multihash(sha3-256)) payload for a
|
|
6
9
|
* public controller alias.
|
|
@@ -18,8 +21,8 @@ export function multibase58MultihashSha3_256(value) {
|
|
|
18
21
|
if (!normalized) {
|
|
19
22
|
throw new Error('Cannot create multihash from empty value.');
|
|
20
23
|
}
|
|
21
|
-
const digest =
|
|
22
|
-
const multihash =
|
|
24
|
+
const digest = sha3_256(utf8ToBytes(normalized));
|
|
25
|
+
const multihash = Uint8Array.from([0x16, 0x20, ...digest]);
|
|
23
26
|
return encodeMultibase58btc(multihash);
|
|
24
27
|
}
|
|
25
28
|
function looksLikeBase58Multibase(value) {
|
|
@@ -96,6 +99,28 @@ export function normalizeSameAsHashList(value) {
|
|
|
96
99
|
.filter(Boolean);
|
|
97
100
|
return [...new Set(normalized)];
|
|
98
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Splits a public alias CSV without changing the aliases themselves.
|
|
104
|
+
*
|
|
105
|
+
* Use this for mixed DID/CID `sameAs` indexes. Unlike
|
|
106
|
+
* `normalizeSameAsHashList`, it deliberately does not interpret a CIDv1
|
|
107
|
+
* beginning with `z` as a bare `urn:multibase` value.
|
|
108
|
+
*/
|
|
109
|
+
export function normalizePublicAliasList(value) {
|
|
110
|
+
const candidates = Array.isArray(value)
|
|
111
|
+
? value.flatMap((entry) => splitCommaSeparatedValues(entry))
|
|
112
|
+
: splitCommaSeparatedValues(String(value || ''));
|
|
113
|
+
return [...new Set(candidates.map((candidate) => candidate.trim()).filter(Boolean))];
|
|
114
|
+
}
|
|
115
|
+
/** Derives an opaque SHA3-384 multihash URN for a global-ledger alias key. */
|
|
116
|
+
export function buildPublicAliasLedgerAssetId(alias) {
|
|
117
|
+
const normalized = String(alias || '').trim().normalize('NFKC');
|
|
118
|
+
if (!normalized)
|
|
119
|
+
throw new Error('Public alias is required');
|
|
120
|
+
if (normalized.startsWith(UrnPrefixes.Multibase))
|
|
121
|
+
return normalized;
|
|
122
|
+
return `${UrnPrefixes.Multibase}${encodeMultibaseSha3(normalized)}`;
|
|
123
|
+
}
|
|
99
124
|
/**
|
|
100
125
|
* Joins one or more normalized `sameAs` aliases into the current flat CSV
|
|
101
126
|
* storage form used by some shared VC/profile helpers.
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gdc-common-utils-ts",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"type": "module",
|
|
8
8
|
"dependencies": {
|
|
9
|
+
"@noble/hashes": "^2.0.1",
|
|
9
10
|
"@noble/post-quantum": "^0.5.4",
|
|
10
11
|
"@stablelib/base64": "^1.0.1",
|
|
11
12
|
"@stablelib/utf8": "^1.0.2",
|