dataspace-client-sdk-node 0.2.0 → 0.2.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/LICENSE +201 -0
- package/README.md +21 -351
- package/TODO_PROMPT_NEXT_STEPS.md +185 -0
- package/artifacts/update-smart-wallet.js +1016 -0
- package/docs/BACKEND_NODE_INTEGRATION.md +13 -10
- package/package.json +12 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,353 +1,23 @@
|
|
|
1
1
|
# dataspace-client-sdk-node
|
|
2
2
|
|
|
3
|
-
Node.js SDK to consume GW/UNID async DIDComm
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
1. ICA proof/verification (`_verify`, external to this SDK).
|
|
26
|
-
2. GW activation in host registry: `Organization/_activate`.
|
|
27
|
-
3. Offer/Order phase for legal organization onboarding (always; if amount is 0, no payment step).
|
|
28
|
-
4. Device onboarding (DCR): `identity/openid/Device/_dcr`.
|
|
29
|
-
5. Post-DCR token exchange / SMART authorization for protected API calls.
|
|
30
|
-
|
|
31
|
-
Node SDK helpers:
|
|
32
|
-
- `activateOrganizationInGatewayFromIcaProof(...)` (UC5.2)
|
|
33
|
-
- `activateEmployeeDeviceWithActivationCode(...)` (UC5.4)
|
|
34
|
-
- `authenticateBackendPkceAndExchange(...)` or `authenticateBackendSmartStandard(...)`
|
|
35
|
-
|
|
36
|
-
### 2) Personal Organization Onboarding (individual/family/subject)
|
|
37
|
-
|
|
38
|
-
Canonical order:
|
|
39
|
-
|
|
40
|
-
1. Personal/family registration: `individual/org.schema/Organization/_batch`.
|
|
41
|
-
2. Offer acceptance/order confirmation: `individual/org.schema/Order/_batch`.
|
|
42
|
-
3. Continue with consent + subject data workflows.
|
|
43
|
-
|
|
44
|
-
Node SDK helper:
|
|
45
|
-
- `bootstrapSubjectOrganizationIndex(...)` (UC5.1: registration + optional order confirmation)
|
|
46
|
-
|
|
47
|
-
See:
|
|
48
|
-
- `docs/DEVELOPER_USE_CASES.md` (UC5.1..UC5.7)
|
|
49
|
-
- `docs/E2E_BOOTSTRAP.md` (host activation bootstrap)
|
|
50
|
-
|
|
51
|
-
## Scope
|
|
52
|
-
- Generic async batch client (`_batch` + `_batch-response`) and JSON POST helper.
|
|
53
|
-
- Route builders that cover Swagger v1 route families:
|
|
54
|
-
- `host/registry`: `Organization _batch/_activate`, `Order`,
|
|
55
|
-
- `entity`: `Employee`,
|
|
56
|
-
- `identity`: `Device/_dcr`, `Token/_exchange`, `License/_issue`, SMART token, Firebase custom token,
|
|
57
|
-
- `individual`: `Organization`, `Order`, `Person (legacy)`, `Consent`, `Composition`, `Communication`, `RelatedPerson`, `Observation`, `Task`,
|
|
58
|
-
- `digitaltwin`: `Composition` (`org.hl7.fhir.api` and `org.hl7.fhir.r4`),
|
|
59
|
-
- debug UHC task endpoints: `_call-start`, `_logs`.
|
|
60
|
-
|
|
61
|
-
## Claims Placement Contract
|
|
62
|
-
- Canonical batch-entry claims location: `entry.resource.meta.claims`.
|
|
63
|
-
- Legacy compatibility location: `entry.meta.claims`.
|
|
64
|
-
- This SDK now emits both during migration; new consumers should read/write `resource.meta.claims`.
|
|
65
|
-
|
|
66
|
-
## Install (local workspace)
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
cd tools/dataspace-client-sdk-node
|
|
70
|
-
npm install
|
|
71
|
-
npm run type-check
|
|
72
|
-
npm run build
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## Tests (mocked, no network)
|
|
76
|
-
|
|
77
|
-
The SDK includes mocked tests (Python-SDK style) for:
|
|
78
|
-
- route/path building,
|
|
79
|
-
- async `submit + poll`,
|
|
80
|
-
- multipart conversion upload.
|
|
81
|
-
|
|
82
|
-
Run:
|
|
83
|
-
```bash
|
|
84
|
-
cd sdk/dataspace-client-sdk-node
|
|
85
|
-
|
|
86
|
-
npm test
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
import { DataspaceNodeClient, createDidcommPlainMessage } from './dist/index.js';
|
|
93
|
-
const client = new DataspaceNodeClient({
|
|
94
|
-
baseUrl: 'http://localhost:3000',
|
|
95
|
-
bearerToken: 'demo-token',
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const ctx = { tenantId: 'acme', jurisdiction: 'ES', sector: 'health-care' };
|
|
99
|
-
iss: 'adult1@example.com',
|
|
100
|
-
aud: 'did:web:api.acme.org',
|
|
101
|
-
body: {
|
|
102
|
-
data: [
|
|
103
|
-
{
|
|
104
|
-
type: 'Family-registration-form-v1.0',
|
|
105
|
-
meta: {
|
|
106
|
-
claims: {
|
|
107
|
-
'@context': 'org.schema',
|
|
108
|
-
'@type': 'template',
|
|
109
|
-
'org.schema.Organization.address.addressCountry': 'ES',
|
|
110
|
-
'org.schema.Organization.identifier.additionalType': 'UUID',
|
|
111
|
-
'org.schema.Organization.identifier.value': 'f0d4b66d-7e28-4fa2-91b7-7041e57f4f90',
|
|
112
|
-
'org.schema.Person.email': 'adult1@example.com',
|
|
113
|
-
'org.schema.Service.category': 'health-care',
|
|
114
|
-
'org.schema.Service.identifier': 'did:web:api-provider.example.com',
|
|
115
|
-
'org.schema.Service.serviceType': 'http://terminology.hl7.org/CodeSystem/v3-ActReason|SRVC',
|
|
116
|
-
'org.schema.Service.termsOfService': 'https://provider.example.com/terms',
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
const submitPath = client.individualFamilyOrganizationBatchPath(ctx);
|
|
125
|
-
const pollPath = client.individualFamilyOrganizationPollPath(ctx);
|
|
126
|
-
const result = await client.submitAndPoll(submitPath, pollPath, payload);
|
|
127
|
-
console.log(result.poll.status, result.poll.body);
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Backend auth: identity-exchange.v1 (B2B PKCE flow)
|
|
131
|
-
|
|
132
|
-
For server-to-server integration (e.g. `uhc-unid-chat-node` calling the GW), the SDK implements the
|
|
133
|
-
full `identity-exchange.v1` flow: DCR binding → PKCE code → token → SMART bearer exchange.
|
|
134
|
-
|
|
135
|
-
This is the Node equivalent of Python's `authenticate_backend_pkce_and_exchange` in `connector-sdk-py`.
|
|
136
|
-
|
|
137
|
-
**Prerequisites:**
|
|
138
|
-
1. Your tenant org is activated in the GW (`registry/org.schema/Organization/_activate` with ICA VC).
|
|
139
|
-
2. An API key with the required scopes has been issued by ICA (`identity/api-key/_create`).
|
|
140
|
-
3. You have your service's public JWK (EC P-384 recommended).
|
|
141
|
-
|
|
142
|
-
**Usage:**
|
|
143
|
-
|
|
144
|
-
```ts
|
|
145
|
-
import { DataspaceNodeClient } from './dist/index.js';
|
|
146
|
-
|
|
147
|
-
const client = new DataspaceNodeClient({ baseUrl: 'https://gw.example.com' });
|
|
148
|
-
|
|
149
|
-
const ctx = { tenantId: 'acme', jurisdiction: 'ES', sector: 'health-care' };
|
|
150
|
-
|
|
151
|
-
// Run once per key pair; result is cached automatically.
|
|
152
|
-
const auth = await client.authenticateBackendPkceAndExchange({
|
|
153
|
-
ctx,
|
|
154
|
-
apiKey: process.env.GW_API_KEY!,
|
|
155
|
-
controllerPublicJwk: JSON.parse(process.env.GW_PUBLIC_JWK!),
|
|
156
|
-
scopes: ['onboarding', 'family-registration', 'license-order'],
|
|
157
|
-
endpointId: 'chatbot-main', // cache key; re-auth on expiry is automatic
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
if (auth.status === 'failed') {
|
|
161
|
-
throw new Error(`Backend auth failed at step: ${auth.step}`);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Use the bearer for subsequent requests:
|
|
165
|
-
const authedClient = new DataspaceNodeClient({
|
|
166
|
-
baseUrl: 'https://gw.example.com',
|
|
167
|
-
bearerToken: auth.accessToken,
|
|
168
|
-
});
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
**Demo / local bypass (never for production):**
|
|
172
|
-
|
|
173
|
-
```ts
|
|
174
|
-
// .env: SECURITY_MODE=demo GW_AUTH_BEARER=static-demo-token
|
|
175
|
-
const client = new DataspaceNodeClient({
|
|
176
|
-
baseUrl: process.env.BASE_URL!,
|
|
177
|
-
bearerToken: process.env.GW_AUTH_BEARER, // skip identity-exchange.v1 entirely
|
|
178
|
-
});
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
## Backend auth: smart-backend.v1 (client_credentials + private_key_jwt)
|
|
182
|
-
|
|
183
|
-
For direct OAuth2 machine-to-machine flows (bypassing the PKCE device flow), use the
|
|
184
|
-
`smart-backend.v1` profile. The SDK signs the `client_assertion` JWT locally using an
|
|
185
|
-
in-memory ES384 wallet.
|
|
186
|
-
|
|
187
|
-
This is the Node equivalent of Python's `authenticate_backend_smart_standard` in
|
|
188
|
-
`connector-sdk-py`.
|
|
189
|
-
|
|
190
|
-
**Usage:**
|
|
191
|
-
|
|
192
|
-
```ts
|
|
193
|
-
import { DataspaceNodeClient, MemoryWalletProvider } from './dist/index.js';
|
|
194
|
-
|
|
195
|
-
const wallet = new MemoryWalletProvider();
|
|
196
|
-
|
|
197
|
-
// walletContext scopes the key pair. Use the service's logical identity.
|
|
198
|
-
const walletContext = { tenantId: 'service-a', jurisdiction: 'ES', sector: 'health-care' };
|
|
199
|
-
|
|
200
|
-
const client = new DataspaceNodeClient({
|
|
201
|
-
baseUrl: 'https://gw.example.com',
|
|
202
|
-
wallet,
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
// On first call, authenticates. On subsequent calls within token TTL, returns cached.
|
|
206
|
-
const result = await client.authenticateBackendSmartStandard({
|
|
207
|
-
clientId: 'service-a',
|
|
208
|
-
scopes: ['system/*.read', 'system/*.write'],
|
|
209
|
-
walletContext,
|
|
210
|
-
// tokenUrl: optional absolute URL; defaults to `${baseUrl}/token`
|
|
211
|
-
// audience: optional; defaults to the resolved tokenUrl
|
|
212
|
-
// assertionTtlSeconds: optional; defaults to 300
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
if (result.status === 'failed') {
|
|
216
|
-
throw new Error(`smart-backend.v1 auth failed: HTTP ${result.statusCode}`);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const authedClient = new DataspaceNodeClient({
|
|
220
|
-
baseUrl: 'https://gw.example.com',
|
|
221
|
-
bearerToken: result.accessToken,
|
|
222
|
-
});
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
**How it works internally:**
|
|
226
|
-
1. `MemoryWalletProvider` generates a dedicated EC P-384 key (`use: sig`, `alg: ES384`).
|
|
227
|
-
2. `signCompactJws(...)` produces the `client_assertion` JWT signed with that key.
|
|
228
|
-
3. A single `client_credentials` POST to the token endpoint returns the bearer.
|
|
229
|
-
4. The token is cached until 30s before expiry; subsequent calls return `status: 'cached'`.
|
|
230
|
-
|
|
231
|
-
## DIDComm encrypted (nested JWS-in-JWE)
|
|
232
|
-
|
|
233
|
-
For GW endpoints that require `application/didcomm-encrypted+json`, use `submitBatchEncrypted`.
|
|
234
|
-
This implements the nested JOSE pattern expected by the backend: sign first (ES384 compact JWS),
|
|
235
|
-
then encrypt (ML-KEM-768 + A256GCM compact JWE with `cty: JWS`).
|
|
236
|
-
|
|
237
|
-
Requires a wallet provider and the recipient's ML-KEM-768 encryption JWK (from GW
|
|
238
|
-
`.well-known/jwks.json`, `use: enc`). The `MemoryWalletProvider` generates ML-KEM-768 keys
|
|
239
|
-
automatically — no RSA setup required.
|
|
240
|
-
|
|
241
|
-
### ML-KEM-768 JWK format
|
|
242
|
-
|
|
243
|
-
Encryption keys use the OKP JWK type with `crv: "ML-KEM-768"`:
|
|
244
|
-
|
|
245
|
-
```json
|
|
246
|
-
{
|
|
247
|
-
"kty": "OKP",
|
|
248
|
-
"crv": "ML-KEM-768",
|
|
249
|
-
"use": "enc",
|
|
250
|
-
"alg": "ML-KEM-768",
|
|
251
|
-
"x": "<base64url-encoded 1184-byte public key>",
|
|
252
|
-
"kid": "wallet:acme:ES:health-care:abc123"
|
|
253
|
-
}
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
The `encrypted_key` slot in the compact JWE is the 1088-byte ML-KEM ciphertext (base64url).
|
|
257
|
-
The 32-byte shared secret derived by KEM encapsulation is used directly as the AES-256-GCM CEK.
|
|
258
|
-
|
|
259
|
-
```ts
|
|
260
|
-
import { DataspaceNodeClient, MemoryWalletProvider } from './dist/index.js';
|
|
261
|
-
|
|
262
|
-
const wallet = new MemoryWalletProvider();
|
|
263
|
-
const walletContext = { tenantId: 'acme', jurisdiction: 'ES', sector: 'health-care' };
|
|
264
|
-
const client = new DataspaceNodeClient({ baseUrl: 'https://gw.example.com', wallet });
|
|
265
|
-
|
|
266
|
-
// Wallet's own ML-KEM enc JWK (share with backend so it can encrypt to you):
|
|
267
|
-
const [, encJwk] = await wallet.getPublicJwks(walletContext);
|
|
268
|
-
|
|
269
|
-
// Fetch GW encryption JWK from well-known endpoint for outbound encryption:
|
|
270
|
-
// const { keys } = await (await fetch('https://gw.example.com/.well-known/jwks.json')).json();
|
|
271
|
-
// const recipientEncJwk = keys.find(k => k.use === 'enc' && k.crv === 'ML-KEM-768');
|
|
272
|
-
|
|
273
|
-
// For local roundtrip test, use wallet's own enc key as recipient:
|
|
274
|
-
const recipientEncJwk = encJwk;
|
|
275
|
-
|
|
276
|
-
const payload = { thid: 'my-thid', body: { data: [] } };
|
|
277
|
-
const result = await client.submitBatchEncrypted(
|
|
278
|
-
client.individualFamilyOrganizationBatchPath(ctx),
|
|
279
|
-
payload,
|
|
280
|
-
recipientEncJwk,
|
|
281
|
-
walletContext,
|
|
282
|
-
);
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
**Cache helper** — if you need the current bearer without re-running the flow:
|
|
286
|
-
|
|
287
|
-
```ts
|
|
288
|
-
const bearer = client.getCachedBearerToken('chatbot-main');
|
|
289
|
-
// Returns undefined if not cached or expired (>30s remaining).
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
Full runnable example: `examples/backend-pkce-auth.mjs`
|
|
293
|
-
|
|
294
|
-
## Swagger parity strategy
|
|
295
|
-
- For any v1 route exposed in Swagger, use:
|
|
296
|
-
- `client.v1Path(ctx, section, format, resourceType, action)` for tenant routes.
|
|
297
|
-
- `client.hostRegistryPath(ctx, resourceType, action)` for host registry routes.
|
|
298
|
-
- Then call one of:
|
|
299
|
-
- `submitBundle(path, didcommPayload)` for DIDComm bundle submit routes (preferred),
|
|
300
|
-
- `submitBatch(path, didcommPayload)` (legacy alias, kept for compatibility),
|
|
301
|
-
- `submitLegacyJson(path, payload)` for non-DIDComm JSON routes,
|
|
302
|
-
- `pollBatchResponse(path, { thid })` / `pollUntilComplete(...)`,
|
|
303
|
-
- `postJson(path, payload)` for non-batch JSON routes.
|
|
304
|
-
|
|
305
|
-
This avoids hardcoding curl scripts per endpoint.
|
|
306
|
-
|
|
307
|
-
## Notes for telephony tests
|
|
308
|
-
- Keep GW/UHC unit/integration tests direct (service/router level).
|
|
309
|
-
- Use this SDK for consumer-style E2E tests and external Node.js service integrations.
|
|
310
|
-
- If individual onboarding moves to a separate service, telephony tests should consume that service and only use GW/UHC for reminders/calls.
|
|
311
|
-
|
|
312
|
-
## DataConversion / Excel
|
|
313
|
-
|
|
314
|
-
This SDK now includes conversion helpers:
|
|
315
|
-
- `conversionUploadPath(ctx, softwareId, sourceFormat)`
|
|
316
|
-
- `conversionUploadPollPath(ctx, softwareId, sourceFormat)`
|
|
317
|
-
- `uploadConversionFile({ path, fileName, fileContent, fields })`
|
|
318
|
-
|
|
319
|
-
Example:
|
|
320
|
-
- `examples/conversion-upload.mjs`
|
|
321
|
-
|
|
322
|
-
Run:
|
|
323
|
-
```bash
|
|
324
|
-
cd sdk/dataspace-client-sdk-node
|
|
325
|
-
npm run build
|
|
326
|
-
BASE_URL="http://localhost:3000" \
|
|
327
|
-
AUTH_BEARER="demo-token" \
|
|
328
|
-
TENANT_ID="acme" \
|
|
329
|
-
JURISDICTION="ES" \
|
|
330
|
-
SECTOR="animal-care" \
|
|
331
|
-
SOFTWARE_ID="excel-adapter" \
|
|
332
|
-
SOURCE_FORMAT="xlsx" \
|
|
333
|
-
SOURCE_FILE="/absolute/path/to/input.xlsx" \
|
|
334
|
-
node examples/conversion-upload.mjs
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
Notes:
|
|
338
|
-
- Exact multipart field names may vary by DataConversion deployment.
|
|
339
|
-
- If your conversion API is synchronous, polling is optional.
|
|
340
|
-
- If it is async, provide/resolve `thid` and poll `.../_upload-response`.
|
|
341
|
-
|
|
342
|
-
## Next planned additions
|
|
343
|
-
- Typed payload builders per flow (`family`, `relatedPerson`, `observation`, `task`).
|
|
344
|
-
- Claims mappers (`ClaimName` <-> SQL internal name with `_`).
|
|
345
|
-
- Retry/backoff + richer error mapping.
|
|
346
|
-
|
|
347
|
-
## Planning and Parity Docs
|
|
348
|
-
|
|
349
|
-
- TODO / execution prompt: `TODO_PROMPT_NEXT_STEPS.md`
|
|
350
|
-
- Node/Python API parity map: `SDK_PARITY_MAP.md`
|
|
351
|
-
|
|
352
|
-
## Pending Compatibility TODO
|
|
353
|
-
- See [SMART EHR compatibility TODO](docs/TODO_SMART_EHR_COMPAT.md).
|
|
3
|
+
Node.js SDK to consume GW/UNID async DIDComm endpoints.
|
|
4
|
+
|
|
5
|
+
## Documentation Index
|
|
6
|
+
|
|
7
|
+
1. [Full API Reference](docs/API.md)
|
|
8
|
+
2. [Data Model Alignment (GW + Chat + SDK)](docs/DATA_MODEL_ALIGNMENT.md)
|
|
9
|
+
3. [Frontend/Backend SDK Ownership Matrix](../docs/SDK_AUTH_OWNERSHIP.md)
|
|
10
|
+
4. [Developer Use-Case Cookbook (UC5 + additional patterns)](docs/DEVELOPER_USE_CASES.md)
|
|
11
|
+
5. [Live Local GW UC5 E2E (no mocks)](docs/E2E_LOCAL_GW_UC5.md)
|
|
12
|
+
6. [React Web Integration Guide](docs/REACT_WEB_INTEGRATION.md)
|
|
13
|
+
7. [Backend Node Integration Guide](docs/BACKEND_NODE_INTEGRATION.md)
|
|
14
|
+
8. [Controller Flow Step by Step](docs/CONTROLLER_FLOW_STEP_BY_STEP.md)
|
|
15
|
+
9. [Legal Organization Flow Step by Step](docs/LEGAL_ORGANIZATION_FLOW_STEP_BY_STEP.md)
|
|
16
|
+
10. [Practitioner Flow Step by Step](docs/PRACTITIONER_FLOW_STEP_BY_STEP.md)
|
|
17
|
+
11. [Portal Backend Integration Handover](docs/PORTAL_BACKEND_INTEGRATION_HANDOVER.md)
|
|
18
|
+
|
|
19
|
+
## TODO and Roadmap
|
|
20
|
+
|
|
21
|
+
1. [Prompt Next Steps TODO](TODO_PROMPT_NEXT_STEPS.md)
|
|
22
|
+
2. [SMART EHR Compatibility TODO](docs/TODO_SMART_EHR_COMPAT.md)
|
|
23
|
+
3. [SDK Parity Map](../SDK_PARITY_MAP.md)
|