@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 2.56 kB
JavaScript
import{PasskeySdkLoader as e}from"./PasskeySdkLoader.js";import{PasskeyErrorTypes as i}from"./types.js";import t,{SDK_ERROR as n}from"../../../core/Errors/AdyenCheckoutError.js";import s from"../../../utils/base64.js";function r(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class a{get deviceId(){return this.passkeyServiceConfig.deviceId}async getWebAuthnUnsupportedReason(){if(!window.PublicKeyCredential)return"Browser does not support webauthn";try{if(!await window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable())return"Device does not have platform authenticator"}catch(e){return"Unknown error"}return""}initialize(){return null==this.initialized&&(this.initialized=(new e).load(this.passkeyServiceConfig.environment).then((e=>{this.passkeySdk=e}))),this.initialized}async captureRiskSignalsEnrollment(){if(await this.initialized,this.riskSignals)return this.riskSignals;const e=await this.passkeySdk.captureRiskSignalsEnrollment(this.deviceId);if(e&&"type"in e&&e.type===i.RISK_SIGNALS_ERROR)throw new t(n,e.message);return this.riskSignals=e,this.riskSignals}async canUseStoredCredential(){try{return await this.captureRiskSignalsAuthentication(),!0}catch(e){return console.warn(`The device is not eligible for stored credential authentication: ${e instanceof Error?e?.message:"unknown error"}`),!1}}async captureRiskSignalsAuthentication(){await this.initialized;const e=await this.passkeySdk.captureRiskSignalsAuthentication(this.deviceId);if(e&&"type"in e&&e.type===i.RISK_SIGNALS_ERROR)throw new t(n,e.message);return e}async createCredentialForEnrollment(e){await this.initialized;const r=this.decodeJsonBase64(e,"Failed to decode registrationOptions"),a=await this.passkeySdk.createCredentialForEnrollment(r);if(a&&"type"in a&&a.type===i.CREDENTIAL_CREATION_ERROR)throw new t(n,a.message);return s.encode(JSON.stringify(a))}async authenticateWithCredential(e){await this.initialized;const r=this.decodeJsonBase64(e,"Failed to decode authenticationOptions"),a=await this.passkeySdk.authenticateWithCredential(r);if(a&&"type"in a&&a.type===i.CREDENTIAL_RETRIEVAL_ERROR)throw new t(n,a.message);return s.encode(JSON.stringify(a))}decodeJsonBase64(e,i){const r=s.decode(e);if(!r.success)throw new t(n,i);return JSON.parse(r.data)}constructor(e){r(this,"passkeySdk",void 0),r(this,"passkeyServiceConfig",void 0),r(this,"riskSignals",void 0),r(this,"initialized",void 0),this.passkeyServiceConfig=e}}export{a as PasskeyService};
//# sourceMappingURL=PasskeyService.js.map