dataspace-client-sdk-node 0.1.2 → 0.2.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.
- package/CHANGELOG.md +4 -1
- package/README.md +21 -348
- package/dist/client.d.ts +40 -2
- package/dist/client.js +156 -82
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types.d.ts +20 -1
- package/dist/vp-token.d.ts +37 -0
- package/dist/vp-token.js +56 -0
- package/docs/API.md +19 -4
- package/docs/BACKEND_NODE_INTEGRATION.md +138 -8
- package/docs/CONTROLLER_FLOW_STEP_BY_STEP.md +283 -0
- package/docs/DEVELOPER_USE_CASES.md +10 -2
- package/docs/E2E_LOCAL_GW_UC5.md +49 -0
- package/docs/ENDPOINT_ID_CATALOG.md +90 -0
- package/docs/LEGAL_ORGANIZATION_FLOW_STEP_BY_STEP.md +84 -0
- package/docs/PERSONAL_FLOW_STEP_BY_STEP.md +70 -0
- package/docs/PORTAL_BACKEND_INTEGRATION_HANDOVER.md +11 -3
- package/docs/PRACTITIONER_FLOW_STEP_BY_STEP.md +182 -0
- package/examples/e2e-bootstrap-tenant.mjs +3 -2
- package/examples/e2e-individual-flow.mjs +13 -8
- package/examples/host-activate-and-employee.mjs +3 -2
- package/package.json +4 -3
- package/src/client.ts +175 -85
- package/src/index.ts +1 -0
- package/src/types.ts +22 -1
- package/src/vp-token.ts +91 -0
- package/tests/fixtures/ica-vp-minimal.json +67 -0
- package/tests/helpers/vp-token-fixture.mjs +23 -0
- package/tests/live-gw-uc5.e2e.test.mjs +108 -0
|
@@ -2,12 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
This guide is backend-only and uses `dataspace-client-sdk-node`.
|
|
4
4
|
|
|
5
|
+
## Secure communications intent
|
|
6
|
+
|
|
7
|
+
- `backendWallet` is used for secure API communications in the dataspace.
|
|
8
|
+
- User authentication and authorization still apply (for example `client_assertion` for SMART token issuance, scopes, consent).
|
|
9
|
+
- Message protection can run in addition to HTTPS:
|
|
10
|
+
- signature (embedded JWS)
|
|
11
|
+
- encryption (JWE with nested JWS)
|
|
12
|
+
- Apply by environment policy (`plain` / `strict` / `auto-detect`).
|
|
13
|
+
- This is layered security (transport + message), not a literal VPN.
|
|
14
|
+
|
|
15
|
+
## Credential map (do not mix)
|
|
16
|
+
|
|
17
|
+
| Credential | Plane | Purpose | Not used for |
|
|
18
|
+
|---|---|---|---|
|
|
19
|
+
| transport bearer / mTLS / API-gateway credential | Transport | Allow backend HTTP access to GW deployment | User identity, `_exchange`, SMART scopes |
|
|
20
|
+
| `vp_token` | Identity/business | Onboarding proof for activation | Catalog discovery auth |
|
|
21
|
+
| `idToken` (user session) | Identity/business | User session proof | Transport gateway access policy |
|
|
22
|
+
| `_exchange` token flow | Identity/business | Activation code exchange for initial access | Multi-ICA/operator catalog traversal |
|
|
23
|
+
| SMART access token | Identity/business | Authorized protected operations via scopes | Infrastructure/operator-plane control |
|
|
24
|
+
|
|
5
25
|
Recommended initialization:
|
|
6
26
|
|
|
7
27
|
```ts
|
|
28
|
+
import { randomBytes } from 'node:crypto';
|
|
29
|
+
import { DataspaceNodeClient, SeedWalletProvider } from 'dataspace-client-sdk-node';
|
|
30
|
+
|
|
31
|
+
const backendWalletSeedBytes = process.env.WALLET_SEED_BASE64URL
|
|
32
|
+
? Buffer.from(process.env.WALLET_SEED_BASE64URL, 'base64url')
|
|
33
|
+
: randomBytes(32); // if not provided, generate random 32 bytes for this runtime
|
|
34
|
+
|
|
35
|
+
const backendWallet = new SeedWalletProvider(
|
|
36
|
+
Buffer.from(backendWalletSeedBytes).toString('base64url'),
|
|
37
|
+
);
|
|
38
|
+
|
|
8
39
|
const client = new DataspaceNodeClient({
|
|
9
40
|
baseUrl,
|
|
10
|
-
|
|
41
|
+
wallet: backendWallet,
|
|
11
42
|
ctx: { tenantId, jurisdiction, sector },
|
|
12
43
|
});
|
|
13
44
|
```
|
|
@@ -15,23 +46,71 @@ const client = new DataspaceNodeClient({
|
|
|
15
46
|
Alternative (mutable context):
|
|
16
47
|
|
|
17
48
|
```ts
|
|
18
|
-
const client = new DataspaceNodeClient({ baseUrl,
|
|
49
|
+
const client = new DataspaceNodeClient({ baseUrl, wallet: backendWallet });
|
|
19
50
|
client.setContextOrg({ tenantId, jurisdiction, sector });
|
|
20
51
|
client.setDefaultTimeoutSeconds(12);
|
|
21
52
|
client.setDefaultIntervalSeconds(2);
|
|
22
53
|
```
|
|
23
54
|
|
|
55
|
+
### Communication mode (integration-level policy)
|
|
56
|
+
|
|
57
|
+
SDK does not currently expose a single constructor flag for communication mode.
|
|
58
|
+
Use an integration policy variable and choose the submit method explicitly:
|
|
59
|
+
|
|
60
|
+
- `plain`: always `submitBundle(..., { mode: 'plain' })` (or `submitBatch(...)` for legacy compatibility)
|
|
61
|
+
- `strict`: always `submitBatchEncrypted(...)`
|
|
62
|
+
- `auto-detect` (default): use encrypted when backend wallet + recipient encryption JWK are available, otherwise plaintext
|
|
63
|
+
|
|
64
|
+
GW compatibility (current):
|
|
65
|
+
- supported request envelopes:
|
|
66
|
+
- `application/didcomm-plaintext+json` (demo/compat only)
|
|
67
|
+
- `application/json` (legacy/demo paths only)
|
|
68
|
+
- `application/x-www-form-urlencoded` with `request=<jwe>` (secure/FAPI style)
|
|
69
|
+
- no standalone `didcomm-signed+json` HTTP submit mode is currently exposed as a first-class request content type.
|
|
70
|
+
- signed-only JWS exists as an internal layer pattern, but secure mode entrypoint is form-encoded JWE.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
type CommunicationMode = 'plain' | 'strict' | 'auto-detect';
|
|
74
|
+
const communicationMode: CommunicationMode = (process.env.GW_COMMUNICATION_MODE as CommunicationMode) || 'auto-detect';
|
|
75
|
+
|
|
76
|
+
async function submitDidcomm(
|
|
77
|
+
client: DataspaceNodeClient,
|
|
78
|
+
path: string,
|
|
79
|
+
payload: Record<string, unknown>,
|
|
80
|
+
opts: {
|
|
81
|
+
mode: CommunicationMode;
|
|
82
|
+
walletContext: { tenantId: string; jurisdiction: string; sector: string; walletId?: string };
|
|
83
|
+
recipientEncryptionJwk?: any;
|
|
84
|
+
},
|
|
85
|
+
) {
|
|
86
|
+
const canEncrypt = !!opts.recipientEncryptionJwk;
|
|
87
|
+
if (opts.mode === 'strict' && !canEncrypt) {
|
|
88
|
+
throw new Error('strict mode requires recipientEncryptionJwk');
|
|
89
|
+
}
|
|
90
|
+
if (opts.mode === 'strict' || (opts.mode === 'auto-detect' && canEncrypt)) {
|
|
91
|
+
return client.submitBatchEncrypted(path, payload as any, opts.recipientEncryptionJwk, opts.walletContext as any);
|
|
92
|
+
}
|
|
93
|
+
return client.submitBundle(path, payload, { mode: 'plain' });
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
24
97
|
## Flow A. Legal Organization Onboarding (B2B)
|
|
25
98
|
|
|
26
|
-
1.
|
|
27
|
-
|
|
99
|
+
1. Verify legal-organization PDF in ICA and obtain:
|
|
100
|
+
- `OrganizationCredential` VC
|
|
101
|
+
- `LegalRepresentativeCredential` VC
|
|
102
|
+
2. Build VP payload with both VCs and prepare `header.payload` for signature.
|
|
103
|
+
- integrator signs with controller key (ES256K / ES384 / ML-DSA depending on environment policy)
|
|
104
|
+
3. Receive from frontend/backend session context: `jurisdiction`, `sector`, `tenantId`, signed `vpToken`.
|
|
105
|
+
4. Activate in GW:
|
|
28
106
|
- SDK method: `activateOrganizationInGatewaySimple(...)` (recommended)
|
|
29
107
|
- SDK method: `activateOrganizationInGatewayFromIcaProof(...)` (advanced)
|
|
30
|
-
|
|
108
|
+
5. Complete legal organization order (always; amount may be `0`) using `offerId` returned by activation response.
|
|
31
109
|
- `hostRegistryOrderBatchPath(...)`
|
|
32
110
|
- `hostRegistryOrderPollPath(...)`
|
|
33
111
|
- `submitAndPoll(...)`
|
|
34
|
-
|
|
112
|
+
6. Run controller DCR/token bootstrap first (`_exchange` then `_dcr`), then employee flows.
|
|
113
|
+
7. Run employee DCR/token bootstrap when employee is invited/activated:
|
|
35
114
|
- `activateEmployeeDeviceWithActivationCodeSimple(...)` (recommended)
|
|
36
115
|
- `activateEmployeeDeviceWithActivationCode(...)` (advanced)
|
|
37
116
|
- `requestSmartTokenSimple(...)` (recommended)
|
|
@@ -42,7 +121,7 @@ client.setDefaultIntervalSeconds(2);
|
|
|
42
121
|
|
|
43
122
|
```ts
|
|
44
123
|
app.post('/api/onboarding/legal/activate', async (req, res) => {
|
|
45
|
-
const client = new DataspaceNodeClient({ baseUrl
|
|
124
|
+
const client = new DataspaceNodeClient({ baseUrl });
|
|
46
125
|
client.setContextOrg({
|
|
47
126
|
tenantId: req.body.tenantId,
|
|
48
127
|
jurisdiction: req.body.jurisdiction,
|
|
@@ -94,7 +173,7 @@ Async UX note:
|
|
|
94
173
|
|
|
95
174
|
```ts
|
|
96
175
|
app.post('/api/onboarding/personal/register', async (req, res) => {
|
|
97
|
-
const client = new DataspaceNodeClient({ baseUrl
|
|
176
|
+
const client = new DataspaceNodeClient({ baseUrl });
|
|
98
177
|
const ctx = {
|
|
99
178
|
tenantId: req.body.tenantId,
|
|
100
179
|
jurisdiction: req.body.jurisdiction,
|
|
@@ -120,3 +199,54 @@ app.post('/api/onboarding/personal/register', async (req, res) => {
|
|
|
120
199
|
- `examples/e2e-individual-flow.mjs`
|
|
121
200
|
- `tests/uc5-org-onboarding.flow.test.mjs`
|
|
122
201
|
- `tests/uc5-subject-data.flow.test.mjs`
|
|
202
|
+
|
|
203
|
+
## Deterministic Wallet Profile (seed-based, integrator-managed)
|
|
204
|
+
|
|
205
|
+
Use this section for all flows (controller/professional/personal) when the backend signs/encrypts DIDComm messages without external per-operation KMS signing.
|
|
206
|
+
|
|
207
|
+
Core rule:
|
|
208
|
+
- key custody and seed storage are integrator responsibility
|
|
209
|
+
- SDK requires signing/encryption capability, not local private-key assumptions
|
|
210
|
+
|
|
211
|
+
Recommended derivation contract:
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
type DeriveKeyMaterialInput = {
|
|
215
|
+
seed: Uint8Array; // decrypted by integrator runtime
|
|
216
|
+
tenantId: string;
|
|
217
|
+
jurisdiction: string;
|
|
218
|
+
sector: string;
|
|
219
|
+
walletId?: string;
|
|
220
|
+
purpose: 'signing' | 'encryption';
|
|
221
|
+
algorithm: 'ES384' | 'ES256K' | 'ML-DSA-65' | 'ML-KEM-768';
|
|
222
|
+
kdfVersion: 'v1';
|
|
223
|
+
};
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Domain separation (mandatory):
|
|
227
|
+
- derive per `purpose` and `algorithm`
|
|
228
|
+
- never reuse derived bytes across different purposes or algorithms
|
|
229
|
+
|
|
230
|
+
Canonical context string:
|
|
231
|
+
- `tenantId|jurisdiction|sector|walletId|purpose|algorithm|kdfVersion`
|
|
232
|
+
|
|
233
|
+
KDF profile (example):
|
|
234
|
+
- `scrypt(seed, salt=context, N=2^15, r=8, p=1, dkLen=64)`
|
|
235
|
+
- split derived bytes by algorithm requirements
|
|
236
|
+
- keep parameters versioned and immutable per `kdfVersion`
|
|
237
|
+
|
|
238
|
+
Why:
|
|
239
|
+
- deterministic reproducibility across runs/devices
|
|
240
|
+
- safe algorithm migration (ES384 now, ML-DSA later) without collisions
|
|
241
|
+
- portable across Node backend and mobile/web SDK profiles
|
|
242
|
+
|
|
243
|
+
Strict DIDComm mode:
|
|
244
|
+
- sign payload as embedded JWS
|
|
245
|
+
- encrypt as JWE for recipient
|
|
246
|
+
- use the derived keypair for the active `purpose+algorithm`
|
|
247
|
+
|
|
248
|
+
Flow links:
|
|
249
|
+
- `CONTROLLER_FLOW_STEP_BY_STEP.md`
|
|
250
|
+
- `LEGAL_ORGANIZATION_FLOW_STEP_BY_STEP.md`
|
|
251
|
+
- `PRACTITIONER_FLOW_STEP_BY_STEP.md`
|
|
252
|
+
- `PERSONAL_FLOW_STEP_BY_STEP.md`
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# CONTROLLER_FLOW_STEP_BY_STEP
|
|
2
|
+
|
|
3
|
+
Strict step-by-step flow for organization onboarding by controller, then controller runtime activation, then employee provisioning.
|
|
4
|
+
|
|
5
|
+
## Security model (read first)
|
|
6
|
+
|
|
7
|
+
Security planes:
|
|
8
|
+
- Transport plane (deployment-specific): backend ↔ gateway channel protection (optional bearer, mTLS, API gateway policy).
|
|
9
|
+
- Identity/business plane (functional flow): controller/member credentials and tokens (`vp_token`, `idToken`, DCR, SMART).
|
|
10
|
+
- Operator/hosting plane: infrastructure tenancy and node-operator lifecycle.
|
|
11
|
+
|
|
12
|
+
Do not mix these planes in implementation or documentation.
|
|
13
|
+
|
|
14
|
+
Secure communication intent:
|
|
15
|
+
- controller/member auth tokens are identity-plane credentials
|
|
16
|
+
- in addition, backend P2P messages can be protected with embedded JWS/JWE via backend wallet
|
|
17
|
+
- use `plain` / `strict` / `auto-detect` communication policy per deployment
|
|
18
|
+
|
|
19
|
+
- `initialOrder` = first order linked to onboarding `offerId` from `_activate`.
|
|
20
|
+
- `licenseOrder` = later order(s) for additional employee licenses.
|
|
21
|
+
- `initialOrder` is authorized by onboarding proof (`vp_token`) + gateway onboarding policy.
|
|
22
|
+
- `licenseOrder` is a runtime business operation and must use controller runtime auth (DCR + SMART token).
|
|
23
|
+
- DCR for controller and DCR for employee are different operations and different identities.
|
|
24
|
+
|
|
25
|
+
Current GW behavior for `Employee/_batch` (important):
|
|
26
|
+
- if employee license pool exists and has `available` seats: employee is created (`201`) and one seat is consumed
|
|
27
|
+
- if employee license pool exists but has no `available` seats: response is `Employee-license-offer-v1.0` (no employee created)
|
|
28
|
+
- if employee license pool does not exist: employee is created without license gating (legacy/non-strict mode)
|
|
29
|
+
|
|
30
|
+
## 0) Runtime context (not all from `.env`)
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
// optional transport security context (deployment-specific, not user identity)
|
|
34
|
+
const transportSecurity = {
|
|
35
|
+
gwBearerToken: process.env.GW_BEARER_TOKEN, // optional
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// profile-level runtime context for this authenticated role in this organization
|
|
41
|
+
const profileContext = {
|
|
42
|
+
baseUrl: process.env.BASE_URL!,
|
|
43
|
+
jurisdiction: process.env.JURISDICTION!, // REQUIRED
|
|
44
|
+
sector: process.env.SECTOR || 'health-care',
|
|
45
|
+
hostRegistrySector: process.env.HOST_REGISTRY_SECTOR || 'test-network',
|
|
46
|
+
gwDidWeb: process.env.GW_DID_WEB!,
|
|
47
|
+
credentialExpSeconds: Number(process.env.CREDENTIAL_EXP_SECONDS || 300),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// user/session context (from authenticated portal user + selected tenant/org)
|
|
51
|
+
const sessionContext = {
|
|
52
|
+
tenantId: currentSession.tenantId,
|
|
53
|
+
controllerDidWeb: currentSession.controller.didWeb,
|
|
54
|
+
controllerSignKid: currentSession.controller.signKid, // RFC7638 thumbprint / key id
|
|
55
|
+
controllerIdToken: currentSession.idToken,
|
|
56
|
+
controllerPublicJwk: currentSession.controller.publicJwk,
|
|
57
|
+
controllerEmail: currentSession.controller.email,
|
|
58
|
+
newMemberEmailToInvite: uiFormNewMember.email,
|
|
59
|
+
newMemberRoleCode: uiFormNewMember.hasOccupation || 'ISCO-08|2211',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// credentials issued previously by ICA
|
|
63
|
+
const onboardingProof = {
|
|
64
|
+
organizationVcJwt: currentSession.ica.organizationVcJwt,
|
|
65
|
+
legalRepresentativeVcJwt: currentSession.ica.legalRepresentativeVcJwt, // optional by policy
|
|
66
|
+
};
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 1) Build and externally sign `vp_token` (controller identity proof)
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import {
|
|
73
|
+
DataspaceNodeClient,
|
|
74
|
+
createVP, addVC, prepareForSignature, prepareBytesForSignature, buildVpTokenCompact,
|
|
75
|
+
buildEpochWindow, generateUuidLike,
|
|
76
|
+
} from 'dataspace-client-sdk-node';
|
|
77
|
+
import { ClaimsPersonSchemaorg } from 'gdc-common-utils-ts/constants/schemaorg';
|
|
78
|
+
|
|
79
|
+
const { iat, exp } = buildEpochWindow(profileContext.credentialExpSeconds);
|
|
80
|
+
const header = {
|
|
81
|
+
alg: 'ES256',
|
|
82
|
+
typ: 'JWT',
|
|
83
|
+
kid: `${sessionContext.controllerDidWeb}#${sessionContext.controllerSignKid}`,
|
|
84
|
+
};
|
|
85
|
+
const uniquePresentationNonce = generateUuidLike();
|
|
86
|
+
const vp = createVP({
|
|
87
|
+
iss: sessionContext.controllerDidWeb,
|
|
88
|
+
sub: sessionContext.controllerDidWeb,
|
|
89
|
+
aud: profileContext.gwDidWeb,
|
|
90
|
+
iat,
|
|
91
|
+
exp,
|
|
92
|
+
nonce: uniquePresentationNonce,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
addVC(vp, onboardingProof.organizationVcJwt);
|
|
96
|
+
if (onboardingProof.legalRepresentativeVcJwt) addVC(vp, onboardingProof.legalRepresentativeVcJwt);
|
|
97
|
+
|
|
98
|
+
const { encodedHeader, encodedPayload } = prepareForSignature(header, vp);
|
|
99
|
+
const bytesToSign = prepareBytesForSignature(header, vp);
|
|
100
|
+
const signatureBase64Url = await externalSigner(bytesToSign); // wallet/HSM
|
|
101
|
+
const vpToken = buildVpTokenCompact(encodedHeader, encodedPayload, signatureBase64Url);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Signing responsibility (integrator):
|
|
105
|
+
- SDK provides `prepareForSignature(...)` and `prepareBytesForSignature(...)` to produce the JWT signing input.
|
|
106
|
+
- Signing input is exactly: `base64url(header) + "." + base64url(payload)`.
|
|
107
|
+
- The integrator signs that input with the current user's key material (wallet, secure storage, KMS, HSM, etc.).
|
|
108
|
+
- SDK does not require local custody of private keys.
|
|
109
|
+
|
|
110
|
+
## 2) Activate organization in GW (`_activate`)
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const client = new DataspaceNodeClient({
|
|
114
|
+
baseUrl: profileContext.baseUrl,
|
|
115
|
+
...(transportSecurity.gwBearerToken ? { bearerToken: transportSecurity.gwBearerToken } : {}),
|
|
116
|
+
ctx: { tenantId: sessionContext.tenantId, jurisdiction: profileContext.jurisdiction, sector: profileContext.sector },
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const activation = await client.activateOrganizationInGatewayFromIcaProof(
|
|
120
|
+
{ jurisdiction: profileContext.jurisdiction, sector: profileContext.hostRegistrySector },
|
|
121
|
+
{
|
|
122
|
+
vpToken,
|
|
123
|
+
organizationVc: onboardingProof.organizationVcJwt,
|
|
124
|
+
legalRepresentativeVc: onboardingProof.legalRepresentativeVcJwt,
|
|
125
|
+
numberOfMembers: 2,
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Jurisdiction is mandatory in all flows:
|
|
131
|
+
- Professional: the organization/tenant is registered in one jurisdiction (country) and routes/scopes resolve against it.
|
|
132
|
+
- Personal: user selects jurisdiction first, then service providers are filtered for that jurisdiction.
|
|
133
|
+
- Integrator rule: reject onboarding/session setup when `jurisdiction` is missing.
|
|
134
|
+
|
|
135
|
+
Auth model note:
|
|
136
|
+
- user auth tokens (`idToken`, SMART access token) belong to the identity/business plane (authenticated user session).
|
|
137
|
+
- `transportSecurity.gwBearerToken` belongs to the transport plane only and is optional by deployment.
|
|
138
|
+
- `transportSecurity.gwBearerToken` is not an ICA exchange token and not a controller API key.
|
|
139
|
+
|
|
140
|
+
## 3) Read Offer and show explicit acceptance UI
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
const offerId = client.getOfferIdFromResponse(activation);
|
|
144
|
+
const offer = client.getOfferInfoFromResponse(activation);
|
|
145
|
+
if (!offerId) throw new Error('Offer id missing in activation response');
|
|
146
|
+
// show offer in UI and wait for user acceptance
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## 4) Send Order (always, even if amount is 0)
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
// This is the INITIAL ORDER (onboarding order).
|
|
153
|
+
const initialOrder = await client.confirmLegalOrganizationOrderSimple({ offerId });
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## 5) Controller runtime activation (DCR) to operate organization's APIs
|
|
157
|
+
|
|
158
|
+
This is separate from onboarding proof. It creates controller device runtime identity.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
const controllerActivationCode =
|
|
162
|
+
client.getActivationCodeFromResponse(initialOrder) ||
|
|
163
|
+
client.getActivationCodeFromResponse(activation);
|
|
164
|
+
if (!controllerActivationCode) throw new Error('Controller activation code not found');
|
|
165
|
+
|
|
166
|
+
const controllerDevice = await client.activateEmployeeDeviceWithActivationCodeSimple({
|
|
167
|
+
tenantId: sessionContext.tenantId,
|
|
168
|
+
jurisdiction: profileContext.jurisdiction,
|
|
169
|
+
sector: profileContext.sector,
|
|
170
|
+
activationCode: controllerActivationCode,
|
|
171
|
+
idToken: sessionContext.controllerIdToken,
|
|
172
|
+
dcrPayload: {
|
|
173
|
+
application_type: 'web',
|
|
174
|
+
token_endpoint_auth_method: 'private_key_jwt',
|
|
175
|
+
jwks: { keys: [sessionContext.controllerPublicJwk] },
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## 6) Controller identity token vs entity token (separate concerns)
|
|
181
|
+
|
|
182
|
+
- Identity token request endpoint is tenant-scoped auth route:
|
|
183
|
+
`/host/cds-{jurisdiction}/v1/{sector}/{tenantId}/identity/auth/_token`
|
|
184
|
+
- The returned access token is then used to call entity/business endpoints like:
|
|
185
|
+
`/{tenantId}/cds-{jurisdiction}/v1/{sector}/entity/org.schema/Employee/_batch`
|
|
186
|
+
|
|
187
|
+
Use explicit cache keys by intent to avoid confusion:
|
|
188
|
+
- `controller_identity_token:*` for auth/token operations
|
|
189
|
+
- `controller_entity_token:*` for entity/business operations
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
const controllerSmart = await client.requestSmartTokenSimple({
|
|
193
|
+
tenantId: sessionContext.tenantId,
|
|
194
|
+
jurisdiction: profileContext.jurisdiction,
|
|
195
|
+
sector: profileContext.sector,
|
|
196
|
+
idToken: sessionContext.controllerIdToken,
|
|
197
|
+
targetEndpoint: client.getEndpointId(
|
|
198
|
+
{ section: 'organization', format: 'org.hl7.fhir.r4', resourceType: 'Person', action: '_batch' },
|
|
199
|
+
sessionContext.controllerDidWeb,
|
|
200
|
+
),
|
|
201
|
+
scopes: [
|
|
202
|
+
'organization/Person.cruds',
|
|
203
|
+
'organization/Organization.cruds',
|
|
204
|
+
'organization/Consent.cruds',
|
|
205
|
+
],
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## 7) Create newMember/practitioner employee (runtime, uses controller token)
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
const employee = await client.createOrganizationEmployee(
|
|
213
|
+
{ tenantId: sessionContext.tenantId, jurisdiction: profileContext.jurisdiction, sector: profileContext.sector },
|
|
214
|
+
{
|
|
215
|
+
employeeClaims: {
|
|
216
|
+
'@context': 'org.schema',
|
|
217
|
+
[ClaimsPersonSchemaorg.email]: sessionContext.newMemberEmailToInvite,
|
|
218
|
+
[ClaimsPersonSchemaorg.hasOccupation]: sessionContext.newMemberRoleCode,
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## 8) Extract newMember activation code and hand off to practitioner flow
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
const newMemberActivationCode = client.getActivationCodeFromResponse(employee);
|
|
228
|
+
if (!newMemberActivationCode) throw new Error('newMember activation code not found');
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## 9) If no license is available: create `licenseOrder` (separate from `initialOrder`)
|
|
232
|
+
|
|
233
|
+
When employee creation returns license-offer/gating instead of activation code:
|
|
234
|
+
|
|
235
|
+
1. Extract `licenseOfferId` from employee response (same `getOfferIdFromResponse(...)` helper).
|
|
236
|
+
2. Show offer in UI and request explicit user acceptance.
|
|
237
|
+
3. Submit a new order as `licenseOrder`.
|
|
238
|
+
4. Retry employee creation after successful `licenseOrder`.
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
const licenseOfferId = client.getOfferIdFromResponse(employee);
|
|
242
|
+
if (!licenseOfferId) throw new Error('License offer id missing');
|
|
243
|
+
|
|
244
|
+
// This is a LICENSE ORDER (runtime order), not the onboarding order.
|
|
245
|
+
const licenseOrder = await client.confirmLegalOrganizationOrderSimple({
|
|
246
|
+
offerId: licenseOfferId,
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Authentication rules for this step:
|
|
251
|
+
- never reuse onboarding `vp_token` for runtime ordering
|
|
252
|
+
- use controller runtime identity (DCR already completed)
|
|
253
|
+
- use controller SMART token for protected runtime routes
|
|
254
|
+
|
|
255
|
+
Route intent:
|
|
256
|
+
- controller's onboarding activation and onboarding order for the legal organization: `/host/.../registry/...`
|
|
257
|
+
- controller's identity DCR/token flows are tenant-scoped for the legal organization but exposed as `/host/.../{tenantId}/identity/auth/...`
|
|
258
|
+
- employee business operations use tenant-scoped data routes: `/{tenantId}/.../entity/...` (or corresponding section)
|
|
259
|
+
|
|
260
|
+
Complete path examples:
|
|
261
|
+
(using `test-network` but `test` can be used for local development)
|
|
262
|
+
- activate organization:
|
|
263
|
+
`/host/cds-ES/v1/test-network/registry/org.schema/Organization/_activate`
|
|
264
|
+
- poll activate:
|
|
265
|
+
`/host/cds-ES/v1/test-network/registry/org.schema/Organization/_activate-response`
|
|
266
|
+
- initial onboarding order:
|
|
267
|
+
`/host/cds-ES/v1/test-network/registry/org.schema/Order/_batch`
|
|
268
|
+
- poll onboarding order:
|
|
269
|
+
`/host/cds-ES/v1/test-network/registry/org.schema/Order/_batch-response`
|
|
270
|
+
- controller/employee identity exchange (activation code -> initial token):
|
|
271
|
+
`/host/cds-ES/v1/health-care/{tenantId}/identity/auth/_exchange`
|
|
272
|
+
- controller's DCR (consumes the initial access token with scope 'dcr' as per OpenID DCR):
|
|
273
|
+
`/host/cds-ES/v1/health-care/{tenantId}/identity/auth/_dcr`
|
|
274
|
+
- controller's smart token for entity management:
|
|
275
|
+
`/host/cds-ES/v1/health-care/{tenantId}/identity/auth/_token`
|
|
276
|
+
- employee creation:
|
|
277
|
+
`/{tenantId}/cds-ES/v1/health-care/entity/org.schema/Employee/_batch`
|
|
278
|
+
|
|
279
|
+
Continue with:
|
|
280
|
+
- `PRACTITIONER_FLOW_STEP_BY_STEP.md`
|
|
281
|
+
|
|
282
|
+
Shared wallet derivation profile:
|
|
283
|
+
- `BACKEND_NODE_INTEGRATION.md` ("Deterministic Wallet Profile")
|
|
@@ -11,6 +11,7 @@ SDK: `dataspace-client-sdk-node` (`DataspaceNodeClient`)
|
|
|
11
11
|
|
|
12
12
|
```ts
|
|
13
13
|
import { DataspaceNodeClient } from 'dataspace-client-sdk-node';
|
|
14
|
+
import { ClaimsPersonSchemaorg } from 'gdc-common-utils-ts/constants/schemaorg';
|
|
14
15
|
|
|
15
16
|
const client = new DataspaceNodeClient({
|
|
16
17
|
baseUrl: process.env.GW_BASE_URL!,
|
|
@@ -29,6 +30,7 @@ const ctx = {
|
|
|
29
30
|
Terminology note: `subject` names in methods/claims refer to the member (person/patient) orchestrated by a personal organization with controller/manager and associated members.
|
|
30
31
|
|
|
31
32
|
Method: `bootstrapSubjectOrganizationIndex(ctx, input)`
|
|
33
|
+
Test: [tests/client.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/client.test.mjs), [tests/uc5-subject-data.flow.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/uc5-subject-data.flow.test.mjs)
|
|
32
34
|
|
|
33
35
|
```ts
|
|
34
36
|
const result = await client.bootstrapSubjectOrganizationIndex(ctx, {
|
|
@@ -48,6 +50,7 @@ const result = await client.bootstrapSubjectOrganizationIndex(ctx, {
|
|
|
48
50
|
## UC5.2 Legal organization activation in GW (from ICA proof)
|
|
49
51
|
|
|
50
52
|
Method: `activateOrganizationInGatewayFromIcaProof(hostCtx, input)`
|
|
53
|
+
Test: [tests/client.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/client.test.mjs), [tests/uc5-org-onboarding.flow.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/uc5-org-onboarding.flow.test.mjs)
|
|
51
54
|
|
|
52
55
|
```ts
|
|
53
56
|
const activation = await client.activateOrganizationInGatewayFromIcaProof(
|
|
@@ -64,13 +67,14 @@ const activation = await client.activateOrganizationInGatewayFromIcaProof(
|
|
|
64
67
|
## UC5.3 Create employee / professional license
|
|
65
68
|
|
|
66
69
|
Method: `createOrganizationEmployee(ctx, input)`
|
|
70
|
+
Test: [tests/client.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/client.test.mjs), [tests/uc5-org-onboarding.flow.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/uc5-org-onboarding.flow.test.mjs)
|
|
67
71
|
|
|
68
72
|
```ts
|
|
69
73
|
await client.createOrganizationEmployee(ctx, {
|
|
70
74
|
employeeClaims: {
|
|
71
75
|
'@context': 'org.schema',
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
[ClaimsPersonSchemaorg.email]: 'doctor@example.com',
|
|
77
|
+
[ClaimsPersonSchemaorg.hasOccupation]: 'ISCO-08|2211',
|
|
74
78
|
},
|
|
75
79
|
});
|
|
76
80
|
```
|
|
@@ -78,6 +82,7 @@ await client.createOrganizationEmployee(ctx, {
|
|
|
78
82
|
## UC5.4 Activate employee device
|
|
79
83
|
|
|
80
84
|
Method: `activateEmployeeDeviceWithActivationCode(ctx, input)`
|
|
85
|
+
Test: [tests/client.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/client.test.mjs), [tests/uc5-org-onboarding.flow.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/uc5-org-onboarding.flow.test.mjs)
|
|
81
86
|
|
|
82
87
|
```ts
|
|
83
88
|
const device = await client.activateEmployeeDeviceWithActivationCode(ctx, {
|
|
@@ -94,6 +99,7 @@ const device = await client.activateEmployeeDeviceWithActivationCode(ctx, {
|
|
|
94
99
|
## UC5.5 Import IPS/FHIR and update index
|
|
95
100
|
|
|
96
101
|
Method: `importIpsOrFhirAndUpdateIndex(ctx, input)`
|
|
102
|
+
Test: [tests/client.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/client.test.mjs), [tests/uc5-subject-data.flow.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/uc5-subject-data.flow.test.mjs)
|
|
97
103
|
|
|
98
104
|
```ts
|
|
99
105
|
await client.importIpsOrFhirAndUpdateIndex(ctx, {
|
|
@@ -110,6 +116,7 @@ await client.importIpsOrFhirAndUpdateIndex(ctx, {
|
|
|
110
116
|
|
|
111
117
|
Step 1 method: `grantProfessionalAccessSimple(ctx, input)`
|
|
112
118
|
Step 2 method: `requestSmartToken(input)`
|
|
119
|
+
Test: [tests/client.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/client.test.mjs), [tests/uc5-subject-data.flow.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/uc5-subject-data.flow.test.mjs)
|
|
113
120
|
|
|
114
121
|
Domain note: the protected context is modeled as organization (including personal organizations with controller + subject/person/patient members).
|
|
115
122
|
|
|
@@ -138,6 +145,7 @@ const token = await client.requestSmartToken({
|
|
|
138
145
|
## UC5.7 Generate digital twin
|
|
139
146
|
|
|
140
147
|
Method: `generateDigitalTwinFromSubjectData(ctx, input)`
|
|
148
|
+
Test: [tests/client.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/client.test.mjs), [tests/uc5-subject-data.flow.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/uc5-subject-data.flow.test.mjs)
|
|
141
149
|
|
|
142
150
|
```ts
|
|
143
151
|
await client.generateDigitalTwinFromSubjectData(ctx, {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# E2E Local GW UC5 (Reproducible, No Mocks)
|
|
2
|
+
|
|
3
|
+
This test runs a real UC5 chain against a locally running GW in demo mode:
|
|
4
|
+
|
|
5
|
+
1. Legal entity controller activates tenant (`Organization/_activate`).
|
|
6
|
+
2. Individual controller bootstraps personal/individual organization (`Organization/_batch` + `Order/_batch`).
|
|
7
|
+
3. Consent is created (`Consent/_batch`) with `organization/Composition.rs`.
|
|
8
|
+
4. Professional requests SMART token and receives scoped token.
|
|
9
|
+
|
|
10
|
+
Test file:
|
|
11
|
+
- [live-gw-uc5.e2e.test.mjs](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/live-gw-uc5.e2e.test.mjs)
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
1. Start GW local in demo mode:
|
|
16
|
+
```bash
|
|
17
|
+
npm -C /Users/fernando/GITS/gdc-workspace/gwtemplate-node-ts run api:local-demo
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. Provide ICA proof as either:
|
|
21
|
+
- `VP_TOKEN` (preferred, real signed VP), or
|
|
22
|
+
- `VP_TOKEN_FILE` pointing to a minimal fixture payload.
|
|
23
|
+
|
|
24
|
+
Default fixture included:
|
|
25
|
+
- [ica-vp-minimal.json](/Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node/tests/fixtures/ica-vp-minimal.json)
|
|
26
|
+
- Built at runtime into unsigned compact JWT only for local demo reproducibility.
|
|
27
|
+
|
|
28
|
+
3. Use a tenant id aligned with your activation proof (`TENANT_ID`).
|
|
29
|
+
|
|
30
|
+
## Run
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
cd /Users/fernando/GITS/gdc-workspace/dataspace-client-sdk-node
|
|
34
|
+
BASE_URL=http://127.0.0.1:3000 \
|
|
35
|
+
VP_TOKEN_FILE=./tests/fixtures/ica-vp-minimal.json \
|
|
36
|
+
TENANT_ID=VATES-B00000000 \
|
|
37
|
+
JURISDICTION=ES \
|
|
38
|
+
SECTOR=health-care \
|
|
39
|
+
HOST_REGISTRY_SECTOR=test \
|
|
40
|
+
PROFESSIONAL_ID_TOKEN='eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJzdWIiOiJwcm9mZXNzaW9uYWwifQ.demo' \
|
|
41
|
+
npm run test:e2e:live-gw-uc5
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Notes
|
|
45
|
+
|
|
46
|
+
- This is a real integration test (no `fetch` mocks).
|
|
47
|
+
- `_activate` in this E2E uses `vp_token` in payload (no Bearer header required by the test).
|
|
48
|
+
- If `TENANT_ID` does not match activation proof context, downstream tenant-scoped steps can return `404`.
|
|
49
|
+
- The scripted scope assertion verifies `organization/Composition.rs` is granted in SMART token response.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# ENDPOINT_ID_CATALOG
|
|
2
|
+
|
|
3
|
+
Canonical endpoint-id construction for token cache/session reuse.
|
|
4
|
+
|
|
5
|
+
Use `client.getEndpointId(selector, providerDid?)` and avoid ad-hoc strings.
|
|
6
|
+
|
|
7
|
+
Selector shape:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
type EndpointSelector = {
|
|
11
|
+
section: string;
|
|
12
|
+
format: string;
|
|
13
|
+
resourceType: string;
|
|
14
|
+
action: string;
|
|
15
|
+
};
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Generation rule:
|
|
19
|
+
- With `providerDid`: `did:web:...#section:format:resourceType:action`
|
|
20
|
+
- Without `providerDid`: `section:format:resourceType:action`
|
|
21
|
+
|
|
22
|
+
## Recommended selectors
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
export const ENDPOINT_SELECTORS = {
|
|
26
|
+
ORG_COMPOSITION_SEARCH: {
|
|
27
|
+
section: 'organization',
|
|
28
|
+
format: 'org.hl7.fhir.r4',
|
|
29
|
+
resourceType: 'Composition',
|
|
30
|
+
action: '_search',
|
|
31
|
+
},
|
|
32
|
+
INDIVIDUAL_CONSENT_BATCH: {
|
|
33
|
+
section: 'individual',
|
|
34
|
+
format: 'org.hl7.fhir.r4',
|
|
35
|
+
resourceType: 'Consent',
|
|
36
|
+
action: '_batch',
|
|
37
|
+
},
|
|
38
|
+
INDIVIDUAL_COMMUNICATION_BATCH: {
|
|
39
|
+
section: 'individual',
|
|
40
|
+
format: 'org.hl7.fhir.r4',
|
|
41
|
+
resourceType: 'Communication',
|
|
42
|
+
action: '_batch',
|
|
43
|
+
},
|
|
44
|
+
INDIVIDUAL_DOCUMENTREFERENCE_BATCH: {
|
|
45
|
+
section: 'individual',
|
|
46
|
+
format: 'org.hl7.fhir.r4',
|
|
47
|
+
resourceType: 'DocumentReference',
|
|
48
|
+
action: '_batch',
|
|
49
|
+
},
|
|
50
|
+
IDENTITY_AUTH_TOKEN: {
|
|
51
|
+
section: 'identity',
|
|
52
|
+
format: 'auth',
|
|
53
|
+
resourceType: 'token',
|
|
54
|
+
action: '_token',
|
|
55
|
+
},
|
|
56
|
+
IDENTITY_AUTH_DCR: {
|
|
57
|
+
section: 'identity',
|
|
58
|
+
format: 'auth',
|
|
59
|
+
resourceType: 'device',
|
|
60
|
+
action: '_dcr',
|
|
61
|
+
},
|
|
62
|
+
IDENTITY_AUTH_EXCHANGE: {
|
|
63
|
+
section: 'identity',
|
|
64
|
+
format: 'auth',
|
|
65
|
+
resourceType: 'token',
|
|
66
|
+
action: '_exchange',
|
|
67
|
+
},
|
|
68
|
+
} as const;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Example
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const targetEndpoint = client.getEndpointId(
|
|
75
|
+
ENDPOINT_SELECTORS.ORG_COMPOSITION_SEARCH,
|
|
76
|
+
ORG_CONTROLLER_DID_WEB,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const smart = await client.requestSmartTokenSimple({
|
|
80
|
+
idToken,
|
|
81
|
+
targetEndpoint,
|
|
82
|
+
scopes: ['organization/Composition.rs'],
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Alignment policy
|
|
87
|
+
|
|
88
|
+
- Prefer current namespaces and flows: `/host`, `/ica`, `/publisher`, and GW runtime `identity/auth`.
|
|
89
|
+
- Do not introduce new integrations based on legacy aliases.
|
|
90
|
+
- Keep endpoint-id selectors stable and explicit across Node + frontend SDKs.
|