vet-sdk-core-ts 0.4.28 → 0.4.31
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/dist/secure-clinic-channel.js +44 -31
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ml_dsa44 } from '@noble/post-quantum/ml-dsa.js';
|
|
2
2
|
import { ml_kem768 } from '@noble/post-quantum/ml-kem.js';
|
|
3
|
+
import { prepareVeterinaryIndexTaggedBundle } from 'vet-data-utils-ts/index-projection-tags';
|
|
3
4
|
const encoder = new TextEncoder();
|
|
4
5
|
const decoder = new TextDecoder();
|
|
5
6
|
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
@@ -80,33 +81,6 @@ function extractIndexProjection(bundle, policy) {
|
|
|
80
81
|
const resource = entry.resource;
|
|
81
82
|
if (!resource || typeof resource.resourceType !== 'string' || typeof resource.id !== 'string')
|
|
82
83
|
continue;
|
|
83
|
-
if (typeof entry.fullUrl !== 'string')
|
|
84
|
-
throw new Error('Each indexed resource requires an absolute HTTPS fullUrl');
|
|
85
|
-
const relative = /^([A-Z][A-Za-z0-9]+)\/([0-9a-f-]+)$/i.exec(entry.fullUrl);
|
|
86
|
-
let urlResourceType;
|
|
87
|
-
let urlId;
|
|
88
|
-
if (relative) {
|
|
89
|
-
;
|
|
90
|
-
[, urlResourceType, urlId] = relative;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
let parsed;
|
|
94
|
-
try {
|
|
95
|
-
parsed = new URL(entry.fullUrl);
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
throw new Error('The index fullUrl must contain /<ResourceType>/<UUID>');
|
|
99
|
-
}
|
|
100
|
-
if (parsed.protocol !== 'https:')
|
|
101
|
-
throw new Error('The index fullUrl must contain /<ResourceType>/<UUID>');
|
|
102
|
-
const segments = parsed.pathname.split('/').filter(Boolean);
|
|
103
|
-
urlResourceType = segments.at(-2);
|
|
104
|
-
urlId = segments.at(-1);
|
|
105
|
-
}
|
|
106
|
-
if (urlResourceType !== resource.resourceType
|
|
107
|
-
|| urlId !== resource.id || !UUID_PATTERN.test(resource.id)) {
|
|
108
|
-
throw new Error('The fullUrl must end in /<ResourceType>/<UUID> matching the resource');
|
|
109
|
-
}
|
|
110
84
|
if (resource.resourceType === 'Binary' && resource.contentType === 'application/pdf') {
|
|
111
85
|
throw new Error('PDF content must be an Attachment inside DocumentReference');
|
|
112
86
|
}
|
|
@@ -127,8 +101,44 @@ function extractIndexProjection(bundle, policy) {
|
|
|
127
101
|
(grouped[_a = tag.system] ?? (grouped[_a] = [])).push(tag.code);
|
|
128
102
|
}
|
|
129
103
|
const claims = Object.fromEntries(Object.entries(grouped).map(([key, values]) => [key, values.join(',')]));
|
|
130
|
-
if (Object.keys(claims).length)
|
|
131
|
-
|
|
104
|
+
if (!Object.keys(claims).length)
|
|
105
|
+
continue;
|
|
106
|
+
// A private FHIR document can legitimately contain contained-only or
|
|
107
|
+
// human-readable entry identities. They remain in the encrypted payload,
|
|
108
|
+
// but only independently retrievable UUID resources enter the index.
|
|
109
|
+
if (typeof entry.fullUrl !== 'string' || !UUID_PATTERN.test(resource.id))
|
|
110
|
+
continue;
|
|
111
|
+
const relative = /^([A-Z][A-Za-z0-9]+)\/([0-9a-f-]+)$/i.exec(entry.fullUrl);
|
|
112
|
+
const documentUrn = /^urn:uuid:([0-9a-f-]+)$/i.exec(entry.fullUrl);
|
|
113
|
+
let urlResourceType;
|
|
114
|
+
let urlId;
|
|
115
|
+
let indexFullUrl = entry.fullUrl;
|
|
116
|
+
if (relative) {
|
|
117
|
+
;
|
|
118
|
+
[, urlResourceType, urlId] = relative;
|
|
119
|
+
}
|
|
120
|
+
else if (documentUrn) {
|
|
121
|
+
urlResourceType = resource.resourceType;
|
|
122
|
+
[, urlId] = documentUrn;
|
|
123
|
+
indexFullUrl = `${resource.resourceType}/${resource.id}`;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
let parsed;
|
|
127
|
+
try {
|
|
128
|
+
parsed = new URL(entry.fullUrl);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (parsed.protocol !== 'https:')
|
|
134
|
+
continue;
|
|
135
|
+
const segments = parsed.pathname.split('/').filter(Boolean);
|
|
136
|
+
urlResourceType = segments.at(-2);
|
|
137
|
+
urlId = segments.at(-1);
|
|
138
|
+
}
|
|
139
|
+
if (urlResourceType !== resource.resourceType || urlId !== resource.id)
|
|
140
|
+
continue;
|
|
141
|
+
entries.push({ fullUrl: indexFullUrl, claims });
|
|
132
142
|
}
|
|
133
143
|
return { entries };
|
|
134
144
|
}
|
|
@@ -138,12 +148,15 @@ function sign(sender, plaintext) {
|
|
|
138
148
|
return `${header}.${payload}.${base64Url(ml_dsa44.sign(encoder.encode(`${header}.${payload}`), sender.signingSecretKey))}`;
|
|
139
149
|
}
|
|
140
150
|
export async function sealVeterinarySecureClinicMessage(input) {
|
|
141
|
-
const
|
|
151
|
+
const taggedBundle = prepareVeterinaryIndexTaggedBundle(input.bundle, {
|
|
152
|
+
allowedTagSystems: input.indexPolicy.allowedTagSystems,
|
|
153
|
+
});
|
|
154
|
+
const indexProjection = extractIndexProjection(taggedBundle, input.indexPolicy);
|
|
142
155
|
const signed = sign(input.sender, {
|
|
143
156
|
id: input.messageId, thid: input.threadId,
|
|
144
157
|
type: 'https://vetchain.app/protocols/private-fhir-document/1.0/ips',
|
|
145
158
|
from: input.from, to: [input.to], created_time: Math.floor(Date.now() / 1000),
|
|
146
|
-
body: { mediaType: 'application/fhir+json', bundle:
|
|
159
|
+
body: { mediaType: 'application/fhir+json', bundle: taggedBundle },
|
|
147
160
|
});
|
|
148
161
|
const cek = crypto.getRandomValues(new Uint8Array(32));
|
|
149
162
|
const header = base64Url(canonicalize({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vet-sdk-core-ts",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.31",
|
|
4
4
|
"description": "Browser-safe VetChain core contracts and governed animal species identifiers",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Connecting Solution & Applications Ltd",
|
|
@@ -81,6 +81,6 @@
|
|
|
81
81
|
"@noble/hashes": "^2.2.0",
|
|
82
82
|
"@noble/post-quantum": "0.5.4",
|
|
83
83
|
"gdc-common-utils-ts": "2.9.10",
|
|
84
|
-
"vet-data-utils-ts": "0.5.
|
|
84
|
+
"vet-data-utils-ts": "0.5.20"
|
|
85
85
|
}
|
|
86
86
|
}
|