@ideem/zsm-client-sdk 2.8.1 → 2.9.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.
@@ -1,371 +1,3 @@
1
- import eventCoordinator from './EventCoordinator.js';
2
- import GLOBAL from './GlobalScoping.js';
3
- import {uid2iid} from './IdentityIndexing.js';
4
- import { b64urlToBuf, toObject } from './Utils.js';
5
-
6
-
7
- eventCoordinator.update('RelyingPartyBase');
8
-
9
- function tracePrimer (obj=false) {
10
- const traceBase = [[new Date().toISOString(), "TRACEPRIMER"]]
11
- return (obj) ? {"trace": traceBase} : traceBase;
12
- }
13
-
14
- //## BEGIN RelyingPartyBase ===================================================================================================================================
15
- class RelyingPartyBase {
16
- /**
17
- * Constructs a RelyingParty object.
18
- * @param {string} host - The URL of the relying party server.
19
- * @param {string} apiKey - The API key for authentication.
20
- * @param {string} applicationID - The ID of the application.
21
- */
22
- constructor(host, apiKey, applicationID, appEnvironment, useOrigin) {
23
- this.host = host;
24
- this.apiKey = apiKey;
25
- this.applicationId = applicationID;
26
- this.appEnvironment = appEnvironment || null;
27
- this.customerDefinedIdentifier = undefined;
28
- this.publicKey = undefined;
29
- this.identityID = undefined;
30
- this.credentialID = undefined;
31
- this.traceId = undefined;
32
- this.xhrHeaders = { 'Content-Type' : 'application/json' };
33
- this.addlRelyingPartyBodyProps = useOrigin ? {use_origin: "true"} : {};
34
- eventCoordinator.update('RelyingPartyBase', 'READY');
35
- }
36
-
37
- get userIdentifier() { return this.customerDefinedIdentifier; }
38
- set userIdentifier(v) { return userIdentifier = this.customerDefinedIdentifier = v; }
39
-
40
- /**
41
- * @name makePostRequest
42
- * @description Performs an HTTP POST request
43
- * @param {string} url The URL to send the request to.
44
- * @param {Object} body The request body data.
45
- * @param {Object} headers Additional headers for the request.
46
- * @param {string} method The HTTP method to use (default is 'POST').
47
- * @returns {Promise<Object>} Resolves with the response data.
48
- */
49
- makePostRequest (url, body={}, headers={}, method='POST') {
50
- url = `${this.host.endsWith('/') ? this.host.slice(0,-1) : this.host}/${url.startsWith('/') ? url.slice(1) : url}`;
51
- body = ((typeof body === 'object') ? body : {});
52
- if(this.appEnvironment) body = Object.assign(body, {environment: this.appEnvironment});
53
- body = Object.assign({ customer_defined_identifier : this.customerDefinedIdentifier, application_id : this.applicationId}, body, this.addlRelyingPartyBodyProps, tracePrimer(true));
54
- let fetchObj = {
55
- method,
56
- // headers : Object.assign(this.xhrHeaders, ((!headers?.Authorization) ? {'Authorization': `Bearer ${this.apiKey}`} : {}), headers, {"X-SDK-Version": JSON.stringify(GLOBAL.ZSMVersions)}),
57
- headers : Object.assign(this.xhrHeaders, ((!headers?.Authorization) ? {'Authorization': `Bearer ${this.apiKey}`} : {}), headers),
58
- body : JSON.stringify(body)
59
- };
60
- return fetch(url, fetchObj)
61
- .then(response => response.ok
62
- ? response.json()
63
- : response.json().then(errData => { throw new Error(`[RelyingParty] :: makePostRequest :: Request failed: ${response.statusText}, ${JSON.stringify(errData)}`) })
64
- )
65
-
66
- .then(response => {
67
- GLOBAL.dispatchEvent(new CustomEvent("AuthResponse", {bubbles: true, cancelable: false, detail: response }));
68
- return response;
69
- });
70
- }
71
-
72
- /**
73
- * @name clearEnrollmentCredentials
74
- * @description Clears the enrollment credentials.
75
- * @returns {Promise<ZSMAPI>}
76
- */
77
- clearEnrollmentCredentials () { return (this.publicKey = this.credentialID = null) };
78
- /**
79
- * @name clearLoginCredentials
80
- * @description Clears the login credentials.
81
- * @returns {Promise<Void>}
82
- * @todo Verify nothing is calling this and remove it outright.
83
- */
84
- clearLoginCredentials () {};
85
- /**
86
- * @name resetAll
87
- * @description Resets all credentials.
88
- * @returns {Promise<Void>}
89
- */
90
- resetAll () { return (this.clearLoginCredentials(), this.clearEnrollmentCredentials()); }
91
-
92
- /**
93
- * @name registrationStart
94
- * @description Sends a login request to the server.
95
- * @returns {Promise<Object>} Resolves with publicKey object used in the subsequent Crypto Server API call.
96
- */
97
- registrationStart () {
98
-
99
- return this.makePostRequest(`api/webauthn/registration/start`)
100
- .then(data => {
101
-
102
- if(data.identity_id){
103
- GLOBAL.mpcConfig.consumer_id = data.identity_id;
104
- uid2iid(this.userIdentifier, data.identity_id);
105
- }
106
- return (this.publicKey = data.ccr.publicKey)
107
- })
108
- .then(result => result)
109
- .catch(error => Promise.reject(new Error(error)));
110
- }
111
- /**
112
- * @name registrationFinish
113
- * @description Completes WebAuthn registration by sending the credential to the server.
114
- * @param {Object} credential The credential information to finalize registration.
115
- * @returns {Promise<Object>} Resolves with the registered credential.
116
- * @throws {Error} Throws an error if the request fails.
117
- */
118
- registrationFinish (credential) {
119
- return credential;
120
- return this.makePostRequest(`api/webauthn/registration/finish`, { credential })
121
- .then(body => {
122
- this.credentialID = credential.rawId;
123
- return {credential, response: body, ...body};
124
- })
125
- .catch(error => (this.clearEnrollmentCredentials(), Promise.reject(new Error(error))));
126
-
127
- }
128
-
129
- /**
130
- * @name authenticationStart
131
- * @description Starts the authentication process by sending a request to the server.
132
- * @param {String} credential_id The ID of the credential to use for authentication.
133
- * @returns {Promise<Object>} Resolves with the authentication challenge.
134
- * @throws {Error} Throws an error if the request fails.
135
- */
136
- authenticationStart (credential_id=this.credentialID, credential_type = 'passkey', chain_handoff, chain_credential_id, chain_challenge) {
137
- const body = {
138
- credential_type,
139
- credential_id,
140
- chain_handoff,
141
- chain_credential_id,
142
- chain_challenge,
143
- }
144
- return (credential_id != null)
145
- ? this.makePostRequest( `api/webauthn/authentication/start`, { credential_id })
146
- .then(result => result)
147
- : (Promise.reject(new Error("[RelyingParty] :: authenticationStart :: No user ID or credential ID provided")));
148
- }
149
-
150
-
151
- /**
152
- * @name authenticationFinish
153
- * @description Completes the authentication process by sending the credential to the server.
154
- * @param {Object} credential The credential information to finalize authentication.
155
- * @returns {Promise<Object>} Resolves with the authentication result.
156
- * @throws {Error} Throws an error if the request fails.
157
- */
158
- authenticationFinish (credential) {
159
- return credential;
160
- return this.makePostRequest("api/webauthn/authentication/finish", { credential })
161
- .then(result => result)
162
- .catch(error => Promise.reject(new Error(error)));
163
- }
164
-
165
-
166
- /**
167
- * @name createIdentityThenRegistrationStart
168
- * @description UMFA-OPTIMIZED FLOW: Creates a server-side Identity and then starts the WebAuthn Registration challenge automatically.
169
- * @returns {Promise<Object>} Resolves with an object containing the publicKey and identity_id.
170
- * @throws {Error} Throws an error if the request fails.
171
- */
172
- createIdentityThenRegistrationStart(credential_type = 'zsm', chain_handoff, chain_credential_id, chain_challenge) {
173
- const body = {
174
- credential_type,
175
- chain_handoff,
176
- chain_credential_id,
177
- chain_challenge,
178
- };
179
- return this.makePostRequest("api/webauthn/registration/create-identity-then-start", body)
180
- .then(data => {
181
- if(data.identity_id){
182
- GLOBAL.mpcConfig.consumer_id = data.identity_id;
183
- uid2iid(this.userIdentifier, data.identity_id);
184
- }
185
- return {publicKey:(this.publicKey = data.ccr.publicKey), identity_id:data.identity_id}
186
- })
187
- .then(result => result)
188
- .catch(error => Promise.reject(new Error(error)));
189
- }
190
-
191
- /**
192
- * @name registrationFinishAuthenticationStart
193
- * @description UMFA-OPTIMIZED FLOW: Completes WebAuthn registration by sending the credential to the server.
194
- * @param {Object} credential The credential information to finalize registration.
195
- * @returns {Promise<Object>} Resolves with the registered credential.
196
- * @throws {Error} Throws an error if the request fails.
197
- */
198
- registrationFinishAuthenticationStart (credential) {
199
- return credential;
200
- return this.makePostRequest(`api/webauthn/registration/finish-then-authentication-start`, { credential })
201
- .then(result => (this.credentialID = credential.rawId, result))
202
- .then(credential => credential)
203
- .catch(error => (this.clearEnrollmentCredentials(), Promise.reject(new Error(error))));
204
- }
205
-
206
- /**
207
- * @name checkServerSideIdentity
208
- * @description Checks if an identity exists on the server and creates one if it doesn't.
209
- * @param {boolean} createNewIdentity Whether to create a new identity if one doesn't exist.
210
- * @returns {Promise<Object>} Resolves with the server response.
211
- * @throws {Error} Throws an error if the request fails.
212
- */
213
- checkServerSideIdentity (createNewIdentity) {
214
- createNewIdentity = createNewIdentity ? { create_new_identity: "true" } : {};
215
- return this.makePostRequest("api/umfa/check-identity", createNewIdentity)
216
- .then(result => result)
217
- .catch(error => Promise.reject(new Error(error)));
218
- }
219
-
220
- //! PASSKEYS PLUS RELYING PARTY METHODS =========================================================================================================================
221
- /**
222
- * @name pkpRegistrationStart
223
- * @description Starts the registration process for a passkey using the Relying Party.
224
- * @param {string} userIdentifier The identifier for the user.
225
- * @param {string} userVerified Indicates if the user has been verified.
226
- * @param {string|null} zsmCredChainID (Optional) The ZSM Credential Chain ID for linking credentials.
227
- * @returns {Promise<Object>} Resolves with the Relying Party Challenge object.
228
- * @throws {Error} If the Relying Party Challenge is not retrieved successfully.
229
- * @throws {Error} If the public key is not found in the Relying Party Challenge.
230
- * @throws {Error} If the user ID is not found in the Relying Party Challenge.
231
- * @memberOf RelyingPartyBase
232
- */
233
- async pkpRegistrationStart (userIdentifier, userVerified, zsmCredChainID = null) {
234
- const requestBody = zsmCredChainID ? {chain_handoff: 'internal', chain_credential_id: zsmCredChainID} : {chain_handoff: 'internal'};
235
- const paChallenge = await this.makePostRequest(`api/passkey/registration/create-identity-then-start`, requestBody)
236
- .then(data => {
237
- if(data.identity_id){
238
- GLOBAL.mpcConfig.consumer_id = data.identity_id;
239
- uid2iid(this.userIdentifier, data.identity_id);
240
- }
241
- return {publicKey:(this.publicKey = data.ccr.publicKey), identity_id:data.identity_id}
242
- })
243
- .then(result => result)
244
- .catch(error => Promise.reject(new Error(error)));
245
- if(!paChallenge) throw new Error(`[PK+ RelyingParty] :: pkpRegistrationStart :: Unable to retrieve Platform Authority Challenge from Relying Party Server!`);
246
- if(!paChallenge?.publicKey) throw new Error(`[PK+ RelyingParty] :: pkpRegistrationStart :: Platform Authority Challenge's Public Key was not found!`);
247
-
248
- paChallenge.publicKey.challenge = b64urlToBuf(paChallenge.publicKey.challenge);
249
- if(!paChallenge?.publicKey?.user) throw new Error(`[PK+ RelyingParty] :: pkpRegistrationStart :: User for the Platform Authority Challenge Public Key's user node was not found!`);
250
-
251
- paChallenge.publicKey.user.id = b64urlToBuf(paChallenge.publicKey.user.id);
252
- return paChallenge;
253
- }
254
-
255
- /**
256
- * @name pkpRegistrationFinish
257
- * @description Completes the registration process for a passkey using the Relying Party.
258
- * @param {Object} credential The Platform Authenticator Credential object.
259
- * @returns {Promise<Object>} Resolves with the registration result.
260
- * @throws {TypeError} If the Platform Authenticator Credential is not provided.
261
- * @throws {Error} If the Platform Authenticator response is invalid.
262
- * @memberOf RelyingPartyBase
263
- * @async
264
- */
265
- async pkpRegistrationFinish (credential) {
266
- if (!credential) throw new TypeError('[PK+ RelyingParty] :: pkpRegistrationFinish :: No Platform Authenticator Credential provided!');
267
-
268
- return this.makePostRequest(`api/passkey/registration/finish`, { credential })
269
- .then(body => {
270
- this.credentialID = credential.rawId;
271
- return {credential, credentialID: this.credentialID, response: {credentialID: this.credentialID, ...body}};
272
- })
273
- .catch(err => {
274
- this.clearEnrollmentCredentials();
275
- throw new Error('[PK+ RelyingParty] :: pkpRegistrationFinish :: Unable to complete registration!', {cause: err});
276
- });
277
- }
278
-
279
- /**
280
- * @name pkpAuthenticationStart
281
- * @description Starts the authentication process for a passkey using the Relying Party.
282
- * @param {object} credentialData The credential data object (cleanFinalData shape, possibly with userIdentifier attached).
283
- * @returns {Promise<Object>} Resolves with the Relying Party Challenge object.
284
- * @throws {TypeError} If the Credential Data object is not provided.
285
- * @throws {Error} If the Credential Data object does not contain valid IDs.
286
- * @throws {Error} If the Relying Party Challenge is not retrieved successfully.
287
- * @throws {Error} If the RCR challenge and/or publicKey is not found in the Relying Party Challenge.
288
- * @throws {Error} If the allowCredentials and/or id is not found in the Relying Party Challenge.
289
- * @memberOf RelyingPartyBase
290
- * @async
291
- */
292
- async pkpAuthenticationStart (credentialData) {
293
-
294
- if(credentialData == null || typeof credentialData !== 'object')
295
- throw new TypeError('[PK+ RelyingParty] :: pkpAuthenticationStart :: No Credential Data object provided!');
296
- if(!credentialData.hasRemotePasskey && !credentialData.zsmCredentialID) // [J] Field names updated to match cleanFinalData
297
- throw new Error('[PK+ RelyingParty] :: pkpAuthenticationStart :: Credential Data object does not contain a valid Passkeys+ Credential ID or ZSM Credential ID!');
298
-
299
- const body = {
300
- credential_id : credentialData?.pkpCredentialID, // [J] PKP credential ID not present in cleanFinalData; to be addressed when cleanFinalData is moved to post-RP boundary
301
- chain_credential_id : credentialData.zsmCredentialID, // [J] Was .zsmCredID
302
- chain_handoff : credentialData?.chainHandoff || 'internal',
303
- chain_challenge : credentialData?.pkpCredential ? JSON.stringify(credentialData.pkpCredential) : null,
304
- };
305
-
306
- let paChallenge = await this.makePostRequest( `api/passkey/authentication/start`, body)
307
- if(paChallenge instanceof Error || !paChallenge)
308
- throw new Error('[PK+ RelyingParty] :: pkpAuthenticationStart :: Unable to retrieve Platform Authority Challenge from Relying Party Server!', {cause: paChallenge});
309
-
310
- paChallenge = toObject(paChallenge);
311
-
312
- if(!paChallenge?.rcr ||
313
- !paChallenge?.rcr?.publicKey) throw new Error(`[PK+ RelyingParty] :: pkpAuthenticationStart :: Platform Authority's RCR challenge and/or publicKey was not found!`);
314
-
315
- const paRCRPublicKey = paChallenge.rcr.publicKey;
316
- paRCRPublicKey.challenge = b64urlToBuf(paRCRPublicKey.challenge);
317
- const paAllowCredentials = paRCRPublicKey.allowCredentials;
318
-
319
- if(!paAllowCredentials ||
320
- !paAllowCredentials[0]?.id) throw new Error(`[PK+ RelyingParty] :: pkpAuthenticationStart :: Platform Authority Challenge's allowCredentials and/or id was not found!`);
321
-
322
- paAllowCredentials[0].id = b64urlToBuf(paAllowCredentials[0].id);
323
-
324
- return paRCRPublicKey;
325
- }
326
-
327
- /**
328
- * @name pkpAuthenticationFinish
329
- * @description Completes the authentication process for a passkey using the Relying Party.
330
- * @param {Object} paCredential The Platform Authenticator Credential object.
331
- * @returns {Promise<Object>} Resolves with the authentication result.
332
- * @throws {Error} If the Platform Authenticator Credential is not provided.
333
- * @throws {Error} If the Platform Authenticator response is invalid.
334
- * @memberOf RelyingPartyBase
335
- * @async
336
- */
337
- async pkpAuthenticationFinish (credential) {
338
- if (!credential || typeof credential !== 'object') throw new Error('[PK+ RelyingParty] :: pkpAuthenticationFinish :: No Platform Authenticator Credential provided or is not an object!');
339
- return this.makePostRequest(`api/passkey/authentication/finish`, { credential })
340
- .then(body => ({credential, response: body}))
341
- .catch(err => Promise.reject(new Error('[PK+ RelyingParty] :: pkpAuthenticationFinish :: Unable to complete authentication!', {cause: err})));
342
- }
343
-
344
-
345
- /**
346
- * @name getRemoteEnrollmentDetails
347
- * @description Retrieves remote enrollment details for a given user identifier.
348
- * @param {string} userIdentifier The user identifier.
349
- * @param {Object} localDataPayload The local data payload.
350
- * @returns {Promise<Object>} Resolves with the enrollment details.
351
- * @throws {Error} Throws an error if the request fails.
352
- */
353
-
354
- async getRemoteEnrollmentDetails (userIdentifier, localDataPayload, bootstrap=false) {
355
- // console.log('[CORE] :: [RelyingPartyBase] :: getRemoteEnrollmentDetails :: userIdentifier, localDataPayload', userIdentifier, localDataPayload);
356
- const body = {
357
- customer_defined_identifier: userIdentifier,
358
- };
359
- if(!bootstrap) { // [J] During the initial bootstrap, we want to minimize the data sent in this request to reduce the payload size and speed up the response; on subsequent calls, we can include the full localDataPayload for more informed server responses
360
- // if(localDataPayload['zsm_credential_id']) body.zsmCredentialID = localDataPayload['zsm_credential_id']; // [J] Field names updated to match cleanFinalData
361
- // if(localDataPayload['passkey_credential_id']) body.pkpCredentialID = localDataPayload['passkey_credential_id']; // [J] Field names updated to match cleanFinalData
362
- }
363
-
364
- const response = await this.makePostRequest('/api/v1/enrollment-details', body);
365
- // console.log('[CORE] :: [RelyingPartyBase] :: getRemoteEnrollmentDetails :: response', response);
366
- return response;
367
- }
368
- }
369
- //## END RelyingPartyBase =====================================================================================================================================
370
-
371
- export default RelyingPartyBase;
1
+ import t from"./EventCoordinator.js";import e from"./GlobalScoping.js";import{uid2iid as i}from"./IdentityIndexing.js";import{b64urlToBuf as r,toObject as n}from"./Utils.js";t.update("RelyingPartyBase");export default class{constructor(e,i,r,n,a){this.host=e,this.apiKey=i,this.applicationId=r,this.appEnvironment=n||null,this.customerDefinedIdentifier=void 0,this.publicKey=void 0,this.identityID=void 0,this.credentialID=void 0,this.traceId=void 0,this.xhrHeaders={"Content-Type":"application/json"},this.addlRelyingPartyBodyProps=a?{use_origin:"true"}:{},t.update("RelyingPartyBase","READY")}get userIdentifier(){return this.customerDefinedIdentifier}set userIdentifier(t){return userIdentifier=this.customerDefinedIdentifier=t}makePostRequest(t,i={},r={},n="POST"){t=`${this.host.endsWith("/")?this.host.slice(0,-1):this.host}/${t.startsWith("/")?t.slice(1):t}`,i="object"==typeof i?i:{},this.appEnvironment&&(i=Object.assign(i,{environment:this.appEnvironment})),i=Object.assign({customer_defined_identifier:this.customerDefinedIdentifier,application_id:this.applicationId},i,this.addlRelyingPartyBodyProps,function(t=!1){const e=[[(new Date).toISOString(),"TRACEPRIMER"]];return t?{trace:e}:e}(!0));let a={method:n,headers:Object.assign(this.xhrHeaders,r?.Authorization?{}:{Authorization:`Bearer ${this.apiKey}`},r),body:JSON.stringify(i)};return fetch(t,a).then(t=>t.ok?t.json():t.json().then(e=>{throw new Error(`[RelyingParty] :: makePostRequest :: Request failed: ${t.statusText}, ${JSON.stringify(e)}`)})).then(t=>(e.dispatchEvent(new CustomEvent("AuthResponse",{bubbles:!0,cancelable:!1,detail:t})),t))}clearEnrollmentCredentials(){return this.publicKey=this.credentialID=null}clearLoginCredentials(){}resetAll(){return this.clearLoginCredentials(),this.clearEnrollmentCredentials()}registrationStart(){return this.makePostRequest("api/webauthn/registration/start").then(t=>(t.identity_id&&(e.mpcConfig.consumer_id=t.identity_id,i(this.userIdentifier,t.identity_id)),this.publicKey=t.ccr.publicKey)).then(t=>t).catch(t=>Promise.reject(new Error(t)))}registrationFinish(t){return t}authenticationStart(t=this.credentialID,e="passkey",i,r,n){return null!=t?this.makePostRequest("api/webauthn/authentication/start",{credential_id:t}).then(t=>t):Promise.reject(new Error("[RelyingParty] :: authenticationStart :: No user ID or credential ID provided"))}authenticationFinish(t){return t}createIdentityThenRegistrationStart(t="zsm",r,n,a){const s={credential_type:t,chain_handoff:r,chain_credential_id:n,chain_challenge:a};return this.makePostRequest("api/webauthn/registration/create-identity-then-start",s).then(t=>(t.identity_id&&(e.mpcConfig.consumer_id=t.identity_id,i(this.userIdentifier,t.identity_id)),{publicKey:this.publicKey=t.ccr.publicKey,identity_id:t.identity_id})).then(t=>t).catch(t=>Promise.reject(new Error(t)))}registrationFinishAuthenticationStart(t){return t}checkServerSideIdentity(t){return t=t?{create_new_identity:"true"}:{},this.makePostRequest("api/umfa/check-identity",t).then(t=>t).catch(t=>Promise.reject(new Error(t)))}
2
+ //! PASSKEYS PLUS RELYING PARTY METHODS =========================================================================================================================
3
+ async pkpRegistrationStart(t,n,a=null){const s=a?{chain_handoff:"internal",chain_credential_id:a}:{chain_handoff:"internal"},o=await this.makePostRequest("api/passkey/registration/create-identity-then-start",s).then(t=>(t.identity_id&&(e.mpcConfig.consumer_id=t.identity_id,i(this.userIdentifier,t.identity_id)),{publicKey:this.publicKey=t.ccr.publicKey,identity_id:t.identity_id})).then(t=>t).catch(t=>Promise.reject(new Error(t)));if(!o)throw new Error("[PK+ RelyingParty] :: pkpRegistrationStart :: Unable to retrieve Platform Authority Challenge from Relying Party Server!");if(!o?.publicKey)throw new Error("[PK+ RelyingParty] :: pkpRegistrationStart :: Platform Authority Challenge's Public Key was not found!");if(o.publicKey.challenge=r(o.publicKey.challenge),!o?.publicKey?.user)throw new Error("[PK+ RelyingParty] :: pkpRegistrationStart :: User for the Platform Authority Challenge Public Key's user node was not found!");return o.publicKey.user.id=r(o.publicKey.user.id),o}async pkpRegistrationFinish(t){if(!t)throw new TypeError("[PK+ RelyingParty] :: pkpRegistrationFinish :: No Platform Authenticator Credential provided!");return this.makePostRequest("api/passkey/registration/finish",{credential:t}).then(e=>(this.credentialID=t.rawId,{credential:t,credentialID:this.credentialID,response:{credentialID:this.credentialID,...e}})).catch(t=>{throw this.clearEnrollmentCredentials(),new Error("[PK+ RelyingParty] :: pkpRegistrationFinish :: Unable to complete registration!",{cause:t})})}async pkpAuthenticationStart(t){if(null==t||"object"!=typeof t)throw new TypeError("[PK+ RelyingParty] :: pkpAuthenticationStart :: No Credential Data object provided!");if(!t.hasRemotePasskey&&!t.zsmCredentialID)throw new Error("[PK+ RelyingParty] :: pkpAuthenticationStart :: Credential Data object does not contain a valid Passkeys+ Credential ID or ZSM Credential ID!");const e={credential_id:t?.pkpCredentialID,chain_credential_id:t.zsmCredentialID,chain_handoff:t?.chainHandoff||"internal",chain_challenge:t?.pkpCredential?JSON.stringify(t.pkpCredential):null};let i=await this.makePostRequest("api/passkey/authentication/start",e);if(i instanceof Error||!i)throw new Error("[PK+ RelyingParty] :: pkpAuthenticationStart :: Unable to retrieve Platform Authority Challenge from Relying Party Server!",{cause:i});if(i=n(i),!i?.rcr||!i?.rcr?.publicKey)throw new Error("[PK+ RelyingParty] :: pkpAuthenticationStart :: Platform Authority's RCR challenge and/or publicKey was not found!");const a=i.rcr.publicKey;a.challenge=r(a.challenge);const s=a.allowCredentials;if(!s||!s[0]?.id)throw new Error("[PK+ RelyingParty] :: pkpAuthenticationStart :: Platform Authority Challenge's allowCredentials and/or id was not found!");return s[0].id=r(s[0].id),a}async pkpAuthenticationFinish(t){if(!t||"object"!=typeof t)throw new Error("[PK+ RelyingParty] :: pkpAuthenticationFinish :: No Platform Authenticator Credential provided or is not an object!");return this.makePostRequest("api/passkey/authentication/finish",{credential:t}).then(e=>({credential:t,response:e})).catch(t=>Promise.reject(new Error("[PK+ RelyingParty] :: pkpAuthenticationFinish :: Unable to complete authentication!",{cause:t})))}async getRemoteEnrollmentDetails(t,e,i=!1){const r={customer_defined_identifier:t};return await this.makePostRequest("/api/v1/enrollment-details",r)}}
package/UMFAClient.js CHANGED
@@ -1,15 +1 @@
1
- import eventCoordinator from './EventCoordinator.js';
2
- import UMFAClientBase from './UMFAClientBase.js';
3
-
4
- class UMFAClient extends UMFAClientBase {
5
- /**
6
- * Constructs a UMFAClient object by extending the UMFAClientBase class.
7
- * @param {Object} config - The configuration for ZSM initialization (ref: ./zsm_app_config.json)
8
- */
9
- constructor(config) {
10
- super(config);
11
- eventCoordinator.update('UMFAClient', 'READY');
12
- }
13
- }
14
-
15
- export {UMFAClient};
1
+ import t from"./EventCoordinator.js";import o from"./UMFAClientBase.js";class r extends o{constructor(o){super(o),t.update("UMFAClient","READY")}}export{r as UMFAClient};