@connectid-tools/rp-nodejs-sdk 4.0.5 → 4.1.0
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 +3 -0
- package/package.json +2 -1
- package/relying-party-client-sdk.js +17 -8
- package/utils/system-information.d.ts +1 -0
- package/utils/system-information.js +27 -0
- package/utils/user-agent.d.ts +2 -0
- package/utils/user-agent.js +6 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@connectid-tools/rp-nodejs-sdk",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Digital Identity Relying Party Node SDK",
|
|
5
5
|
"main": "relying-party-client-sdk.js",
|
|
6
6
|
"types": "relying-party-client-sdk.d.ts",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"test": "node --import tsx --test src/tests/*.test.ts",
|
|
12
12
|
"test:watch": "node --watch --test --import tsx src/tests/*.test.ts",
|
|
13
13
|
"test:conformance": "node --import tsx --test src/conformance/conformance.test.ts",
|
|
14
|
+
"test:integration": "npm run build && node --import tsx --test src/integration/*.test.ts",
|
|
14
15
|
"prebuild": "rm -rf lib",
|
|
15
16
|
"build": "tsc",
|
|
16
17
|
"postbuild": "cp package.json README.md license lib && cd lib && node ../node_modules/add-js-extension/dist/bin.js . --once && replace-in-files --string='${process.env.SDK_VERSION}' --replacement=$npm_package_version relying-party-client-sdk.js && cd .."
|
|
@@ -15,6 +15,7 @@ import { getLogger } from './logger.js';
|
|
|
15
15
|
import ParticipantFilters from './filter/participant-filters.js';
|
|
16
16
|
import { illegalPurposeChars, isValidCertificate, validatePurpose } from './validator.js';
|
|
17
17
|
import { generatePushAuthorisationRequestParams } from './utils/request-utils.js';
|
|
18
|
+
import { buildUserAgent } from './utils/user-agent.js';
|
|
18
19
|
// The extended list of claims which can be requested for a user
|
|
19
20
|
const extendedClaimList = ['over16', 'over18', 'over21', 'over25', 'over65', 'beneficiary_account_au', 'beneficiary_account_au_payid', 'beneficiary_account_international'];
|
|
20
21
|
export default class RelyingPartyClientSdk {
|
|
@@ -42,7 +43,7 @@ export default class RelyingPartyClientSdk {
|
|
|
42
43
|
this.signingKey = getCertificate(this.config.data.signing_key, this.config.data.signing_key_content);
|
|
43
44
|
this.caPem = getCertificate(this.config.data.ca_pem, this.config.data.ca_pem_content);
|
|
44
45
|
this.logger = getLogger(this.config.data.log_level);
|
|
45
|
-
this.logger.info(`Creating RelyingPartyClientSdk - version 4.0
|
|
46
|
+
this.logger.info(`Creating RelyingPartyClientSdk - version 4.1.0`);
|
|
46
47
|
if (this.config.data.purpose) {
|
|
47
48
|
const purposeValidation = validatePurpose(this.config.data.purpose);
|
|
48
49
|
if (purposeValidation === 'INVALID_LENGTH') {
|
|
@@ -74,7 +75,7 @@ export default class RelyingPartyClientSdk {
|
|
|
74
75
|
globalAgent.options.key = this.transportKey;
|
|
75
76
|
globalAgent.options.ca = [this.caPem, ...rootCertificates];
|
|
76
77
|
custom.setHttpOptionsDefaults({ timeout: 10000 });
|
|
77
|
-
// 4.0
|
|
78
|
+
// 4.1.0 is replaced with `postbuild` script in package.json (see replace-in-files)
|
|
78
79
|
this.logger.info(`Using ${this.config.data.transport_key_content ? 'transport_key_content' : 'transport_key'} config prop`);
|
|
79
80
|
this.logger.info(`Using ${this.config.data.transport_pem_content ? 'transport_pem_content' : 'transport_pem'} config prop`);
|
|
80
81
|
this.logger.info(`Using ${this.config.data.ca_pem_content ? 'ca_pem_content' : 'ca_pem'} config prop`);
|
|
@@ -130,7 +131,11 @@ export default class RelyingPartyClientSdk {
|
|
|
130
131
|
return new Date();
|
|
131
132
|
}
|
|
132
133
|
async fetchParticipants(participantsUri) {
|
|
133
|
-
const response = await fetch(participantsUri
|
|
134
|
+
const response = await fetch(participantsUri, {
|
|
135
|
+
headers: {
|
|
136
|
+
'User-Agent': buildUserAgent(this.config.data.client.client_id),
|
|
137
|
+
},
|
|
138
|
+
});
|
|
134
139
|
if (!response.ok) {
|
|
135
140
|
throw new Error(`Failed to retrieve participants from ${participantsUri}: status (${response.status})`);
|
|
136
141
|
}
|
|
@@ -142,8 +147,8 @@ export default class RelyingPartyClientSdk {
|
|
|
142
147
|
this.cachedParticipants = await this.fetchParticipants(participantsUri);
|
|
143
148
|
this.cachedParticipantsExpiry = currentTime + (this.config.data.cache_ttl ?? this.default_cache_ttl) * 1000;
|
|
144
149
|
}
|
|
145
|
-
// ensure the cached value remain untouched down the call stack by returning a deep copy
|
|
146
|
-
return this.cachedParticipants.map(participant => Object.assign({}, participant));
|
|
150
|
+
// ensure the cached value remain untouched down the call stack by returning a deep copy
|
|
151
|
+
return this.cachedParticipants.map((participant) => Object.assign({}, participant));
|
|
147
152
|
}
|
|
148
153
|
// Create and send a pushed authorisation request to the specified authorisation
|
|
149
154
|
// server to allow the initiation of an OIDC flow.
|
|
@@ -320,7 +325,11 @@ export default class RelyingPartyClientSdk {
|
|
|
320
325
|
const keyset = await this.getKeyset();
|
|
321
326
|
const fapiClient = new localIssuer.FAPI1Client(this.config.data.client, keyset);
|
|
322
327
|
this.logger.debug(`Discovered client ${JSON.stringify(fapiClient)}`);
|
|
323
|
-
fapiClient[custom.http_options] = () => ({
|
|
328
|
+
fapiClient[custom.http_options] = () => ({
|
|
329
|
+
key: this.transportKey,
|
|
330
|
+
cert: this.transportPem,
|
|
331
|
+
headers: { 'x-fapi-interaction-id': xFapiInteractionId },
|
|
332
|
+
});
|
|
324
333
|
return { fapiClient, localIssuer };
|
|
325
334
|
}
|
|
326
335
|
async generateRequest(fapiClient, claims, purpose) {
|
|
@@ -341,8 +350,8 @@ export default class RelyingPartyClientSdk {
|
|
|
341
350
|
});
|
|
342
351
|
const clientAssertionPayload = {
|
|
343
352
|
clientAssertionPayload: {
|
|
344
|
-
aud: fapiClient.issuer.issuer
|
|
345
|
-
}
|
|
353
|
+
aud: fapiClient.issuer.issuer,
|
|
354
|
+
},
|
|
346
355
|
};
|
|
347
356
|
this.logger.debug('Generated request object: ' + JSON.stringify(request));
|
|
348
357
|
const { request_uri } = await fapiClient.pushedAuthorizationRequest({ request }, clientAssertionPayload);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getSystemInformation: () => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
export const getSystemInformation = () => {
|
|
3
|
+
const platform = os.platform(); // 'darwin', 'win32', 'linux', etc.
|
|
4
|
+
const arch = os.arch(); // 'x64', 'arm64', etc.
|
|
5
|
+
const release = os.release(); // OS version like '10.15.7' or '10.0.18363'
|
|
6
|
+
// Get Node.js version
|
|
7
|
+
const nodeVersion = process.version; // e.g., 'v16.13.0'
|
|
8
|
+
let userAgent;
|
|
9
|
+
if (platform === 'darwin') {
|
|
10
|
+
// macOS
|
|
11
|
+
const chip = arch === 'arm64' ? 'Apple Silicon' : 'Intel'; // Check if M1 chip (arm64)
|
|
12
|
+
userAgent = `(${platform}; ${chip} Mac OS X ${release}; node${nodeVersion.replace('v', ' ')})`;
|
|
13
|
+
}
|
|
14
|
+
else if (platform === 'win32') {
|
|
15
|
+
// Windows
|
|
16
|
+
userAgent = `(${platform}; ${arch} Windows NT ${release}; node${nodeVersion.replace('v', ' ')})`;
|
|
17
|
+
}
|
|
18
|
+
else if (platform === 'linux') {
|
|
19
|
+
// Linux
|
|
20
|
+
userAgent = `(${platform}; ${arch} ${release}; node${nodeVersion.replace('v', ' ')})`;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// For any other platform (e.g., unknown)
|
|
24
|
+
userAgent = `(${platform}; ${arch} ${release}; node${nodeVersion.replace('v', ' ')})`;
|
|
25
|
+
}
|
|
26
|
+
return userAgent;
|
|
27
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getSystemInformation } from './system-information.js';
|
|
2
|
+
// important: Update this every time the package version changes
|
|
3
|
+
export const packageJsonVersion = '4.1.0';
|
|
4
|
+
export const buildUserAgent = (clientId) => {
|
|
5
|
+
return `cid-rp-nodejs-sdk/${packageJsonVersion} ${getSystemInformation()} +${clientId}`;
|
|
6
|
+
};
|