@alessiofrittoli/credentials-manager
Version:
Handle OTP and Passkeys with ease
2 lines (1 loc) • 1.68 kB
JavaScript
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _mathutils = require('@alessiofrittoli/math-utils');var r=class{constructor(t){this.id=t.id||_mathutils.randomUUID.call(void 0, ),this.credentialId=t.credentialId||_mathutils.randomUUID.call(void 0, ),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}};var _cryptootp = require('@alessiofrittoli/crypto-otp');var _exception = require('@alessiofrittoli/exception');var _error = require('@alessiofrittoli/crypto-signature/error');var u=(e=>(e.Sms="sms",e.Mail="mail",e.Usb="usb",e.App="app",e))(u||{}),i= exports.OtpCredential =class extends r{constructor(t){super(t);let{hash:o=_cryptootp.Otp.Algorithm,encoding:c=_cryptootp.Otp.Encoding,digits:e=_cryptootp.Otp.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 (0, _exception.Exception)("Missing Private Key",{code:_error.ErrorCode.Signature.NO_PRIVATEKEY});return{key:this.key,encoding:this.encoding,algorithm:this.hash}}getSecrets(){return _cryptootp.Otp.GetSecrets({secret:this.getSecret()})}};exports.Credential = r; exports.OtpCredential = i; exports.OtpTransport = u;