From b674f113c794ca8dfed27f177bcac5a54a765400 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Sun, 9 Jul 2023 11:28:50 +0200 Subject: [PATCH] feat: add ServiceProvider class --- src/index.js | 2 +- src/serviceProvider.js | 134 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/serviceProvider.js diff --git a/src/index.js b/src/index.js index 7a77877..85bd7d8 100644 --- a/src/index.js +++ b/src/index.js @@ -16,7 +16,7 @@ limitations under the License. export { Profile } from './profile.js' export { Persona } from './persona.js' export { Claim } from './claim.js' -export * as claimDefinitions from './claimDefinitions/index.js' +export { ServiceProvider } from './serviceProvider.js' export * as proofs from './proofs.js' export * as keys from './keys.js' export * as asp from './asp.js' diff --git a/src/serviceProvider.js b/src/serviceProvider.js new file mode 100644 index 0000000..0d8ba49 --- /dev/null +++ b/src/serviceProvider.js @@ -0,0 +1,134 @@ +/* +Copyright 2023 Yarmo Mackenbach + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +/** + * A service provider matched to an identity claim + * @class + * @constructor + * @public + */ +export class ServiceProvider { + /** + * @param {object} spObj + */ + constructor (spObj) { + /** + * Details about the service provider + * @property {object} + */ + this.about = { + /** + * Identifier of the service provider (no whitespace or symbols, lowercase) + * @type {string} + */ + id: spObj.about.id, + /** + * Full name of the service provider + * @type {string} + */ + name: spObj.about.name, + /** + * URL to the homepage of the service provider + * @type {string | null} + */ + homepage: spObj.about.homepage || null + } + /** + * What the profile would look like if the match is correct + * @property {object} + */ + this.profile = { + /** + * Profile name to be displayed + * @type {string} + */ + display: spObj.profile.display, + /** + * URI or URL for public access to the profile + * @type {string} + */ + uri: spObj.profile.uri, + /** + * URI or URL associated with the profile usually served as a QR code + * @type {string | null} + */ + qr: spObj.profile.qr || null + } + /** + * Details from the claim matching process + * @property {object} + */ + this.claim = { + /** + * Regular expression used to parse the URI + * @type {string} + */ + uriRegularExpression: spObj.claim.uriRegularExpression, + /** + * Whether this match automatically excludes other matches + * @type {boolean} + */ + uriIsAmbiguous: spObj.claim.uriIsAmbiguous + } + /** + * Information for the proof verification process + * @property {object} + */ + this.proof = { + /** + * Details to request the potential proof + * @property {object} + */ + request: { + /** + * Location of the proof + * @type {string} + */ + uri: spObj.proof.request.uri, + /** + * Protocol to be used to request the proof + * @type {string} + */ + protocol: spObj.proof.request.protocol, + /** + * Type of access restriction + * @type {import('./enums.js').ProofAccessRestriction} + */ + accessRestriction: spObj.proof.request.accessRestriction, + /** + * Data needed by the fetcher or proxy to request the proof + * @type {object} + */ + data: spObj.proof.request.data + }, + /** + * Details about the expected response + * @property {object} + */ + response: { + /** + * Expected format of the proof + * @type {import('./enums.js').ProofFormat} + */ + format: spObj.proof.response.format + }, + /** + * Details about the target located in the response + * @type {{format: import('./enums.js').ClaimFormat, encoding: import('./enums.js').EntityEncodingFormat, relation: import('./enums.js').ClaimRelation, path: string[]}[]} + */ + target: spObj.proof.target + } + } +}