@alessiofrittoli/credentials-manager
Version:
Handle OTP and Passkeys with ease
2 lines (1 loc) • 1.41 kB
JavaScript
import{randomUUID as n}from"@alessiofrittoli/math-utils";var r=class{constructor(t){this.id=t.id||n(),this.credentialId=t.credentialId||n(),this.createdAt=t.createdAt?new Date(t.createdAt):void 0,this.lastUse=t.lastUse?new Date(t.lastUse):void 0,this.title=t.title,this.key=t.key,this.encoding=t.encoding,this.counter=t.counter||0,this.userAgent=t.userAgent,this.user=t.user,this.authenticatorAttachment=t.authenticatorAttachment}};import{Otp as s}from"@alessiofrittoli/crypto-otp";import{Exception as d}from"@alessiofrittoli/exception";import{ErrorCode as p}from"@alessiofrittoli/crypto-signature/error";var u=(e=>(e.Sms="sms",e.Mail="mail",e.Usb="usb",e.App="app",e))(u||{}),i=class extends r{constructor(t){super(t);let{hash:o=s.Algorithm,encoding:c=s.Encoding,digits:e=s.Digits,transports:h=["mail"]}=t;this.encoding=c,this.hash=o,this.digits=e,this.label=t.label,this.issuer=t.issuer,this.secrets=this.getSecrets(),this.transports=h,this.authenticatorAttachment="platform",(this.hasTransport("usb")||this.hasTransport("app"))&&(this.authenticatorAttachment="cross-platform")}hasTransport(t){return this.transports.includes(t)}getSecret(){if(!this.key)throw new d("Missing Private Key",{code:p.Signature.NO_PRIVATEKEY});return{key:this.key,encoding:this.encoding,algorithm:this.hash}}getSecrets(){return s.GetSecrets({secret:this.getSecret()})}};export{r as Credential,i as OtpCredential,u as OtpTransport};