>3,r-=c,a-=c<<3,n&=(1<=1&&0===P[g];g--);if(m>g&&(m=g),0===g)return n[a++]=20971520,n[a++]=20971520,o.bits=1,0;for(b=1;b =0;i--){for(var u=t.words[i],h=c-1;h>=0;h--){var d=u>>h&1;a!==r[0]&&(a=this.sqr(a)),0!==d||0!==s?(s<<=1,s|=d,(4===++o||0===i&&0===h)&&(a=this.mul(a,r[s]),o=0,s=0)):o=0}c=26}return a},k.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},k.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},n.mont=function(e){return new A(e)},i(A,k),A.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},A.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},A.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),a=n;return n.cmp(this.m)>=0?a=n.isub(this.m):n.cmpn(0)<0&&(a=n.iadd(this.m)),a._forceRed(this)},A.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new n(0)._forceRed(this);var r=e.mul(t),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),a=r.isub(i).iushrn(this.shift),s=a;return a.cmp(this.m)>=0?s=a.isub(this.m):a.cmpn(0)<0&&(s=a.iadd(this.m)),s._forceRed(this)},A.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(e,gt)})),Jp=/*#__PURE__*/Object.freeze({__proto__:null,default:Qp,__moduleExports:Qp});class ey{constructor(e){if(void 0===e)throw Error(\"Invalid BigInteger input\");this.value=new Qp(e)}clone(){const e=new ey(null);return this.value.copy(e.value),e}iinc(){return this.value.iadd(new Qp(1)),this}inc(){return this.clone().iinc()}idec(){return this.value.isub(new Qp(1)),this}dec(){return this.clone().idec()}iadd(e){return this.value.iadd(e.value),this}add(e){return this.clone().iadd(e)}isub(e){return this.value.isub(e.value),this}sub(e){return this.clone().isub(e)}imul(e){return this.value.imul(e.value),this}mul(e){return this.clone().imul(e)}imod(e){return this.value=this.value.umod(e.value),this}mod(e){return this.clone().imod(e)}modExp(e,t){const r=t.isEven()?Qp.red(t.value):Qp.mont(t.value),i=this.clone();return i.value=i.value.toRed(r).redPow(e.value).fromRed(),i}modInv(e){if(!this.gcd(e).isOne())throw Error(\"Inverse does not exist\");return new ey(this.value.invm(e.value))}gcd(e){return new ey(this.value.gcd(e.value))}ileftShift(e){return this.value.ishln(e.value.toNumber()),this}leftShift(e){return this.clone().ileftShift(e)}irightShift(e){return this.value.ishrn(e.value.toNumber()),this}rightShift(e){return this.clone().irightShift(e)}equal(e){return this.value.eq(e.value)}lt(e){return this.value.lt(e.value)}lte(e){return this.value.lte(e.value)}gt(e){return this.value.gt(e.value)}gte(e){return this.value.gte(e.value)}isZero(){return this.value.isZero()}isOne(){return this.value.eq(new Qp(1))}isNegative(){return this.value.isNeg()}isEven(){return this.value.isEven()}abs(){const e=this.clone();return e.value=e.value.abs(),e}toString(){return this.value.toString()}toNumber(){return this.value.toNumber()}getBit(e){return this.value.testn(e)?1:0}bitLength(){return this.value.bitLength()}byteLength(){return this.value.byteLength()}toUint8Array(e=\"be\",t){return this.value.toArrayLike(Uint8Array,e,t)}}var ty,ry=/*#__PURE__*/Object.freeze({__proto__:null,default:ey}),iy=mt((function(e,t){var r=t;function i(e){return 1===e.length?\"0\"+e:e}function n(e){for(var t=\"\",r=0;rn.bindingSignatures[t].created&&(n.bindingSignatures[t]=e),!1;try{return await e.verify(i,ue.signature.subkeyBinding,a,t,void 0,r),!0}catch(e){return!1}})),await lh(e,this,\"revocationSignatures\",t,(function(e){return ph(i,ue.signature.subkeyRevocation,a,[e],void 0,void 0,t,r)}))}async revoke(e,{flag:t=ue.reasonForRevocation.noReason,string:r=\"\"}={},i=new Date,n=we){const a={key:e,bind:this.keyPacket},s=new kh(this.keyPacket,this.mainKey);return s.revocationSignatures.push(await fh(a,null,e,{signatureType:ue.signature.subkeyRevocation,reasonForRevocationFlag:ue.write(ue.reasonForRevocation,t),reasonForRevocationString:r},i,void 0,void 0,!1,n)),await s.update(this),s}hasSameFingerprintAs(e){return this.keyPacket.hasSameFingerprintAs(e.keyPacket||e)}}[\"getKeyID\",\"getFingerprint\",\"getAlgorithmInfo\",\"getCreationTime\",\"isDecrypted\"].forEach((e=>{kh.prototype[e]=function(){return this.keyPacket[e]()}}));const Ah=/*#__PURE__*/de.constructAllowedPackets([Eu]),Sh=new Set([ue.packet.publicKey,ue.packet.privateKey]),Eh=new Set([ue.packet.publicKey,ue.packet.privateKey,ue.packet.publicSubkey,ue.packet.privateSubkey]);class Ph{packetListToStructure(e,t=new Set){let r,i,n,a;for(const s of e){if(s instanceof Rn){Eh.has(s.tag)&&!a&&(a=Sh.has(s.tag)?Sh:Eh);continue}const e=s.constructor.tag;if(a){if(!a.has(e))continue;a=null}if(t.has(e))throw Error(\"Unexpected packet type: \"+e);switch(e){case ue.packet.publicKey:case ue.packet.secretKey:if(this.keyPacket)throw Error(\"Key block contains multiple keys\");if(this.keyPacket=s,i=this.getKeyID(),!i)throw Error(\"Missing Key ID\");break;case ue.packet.userID:case ue.packet.userAttribute:r=new _h(s,this),this.users.push(r);break;case ue.packet.publicSubkey:case ue.packet.secretSubkey:r=null,n=new kh(s,this),this.subkeys.push(n);break;case ue.packet.signature:switch(s.signatureType){case ue.signature.certGeneric:case ue.signature.certPersona:case ue.signature.certCasual:case ue.signature.certPositive:if(!r){de.printDebug(\"Dropping certification signatures without preceding user packet\");continue}s.issuerKeyID.equals(i)?r.selfCertifications.push(s):r.otherCertifications.push(s);break;case ue.signature.certRevocation:r?r.revocationSignatures.push(s):this.directSignatures.push(s);break;case ue.signature.key:this.directSignatures.push(s);break;case ue.signature.subkeyBinding:if(!n){de.printDebug(\"Dropping subkey binding signature without preceding subkey packet\");continue}n.bindingSignatures.push(s);break;case ue.signature.keyRevocation:this.revocationSignatures.push(s);break;case ue.signature.subkeyRevocation:if(!n){de.printDebug(\"Dropping subkey revocation signature without preceding subkey packet\");continue}n.revocationSignatures.push(s)}}}}toPacketList(){const e=new Ku;return e.push(this.keyPacket),e.push(...this.revocationSignatures),e.push(...this.directSignatures),this.users.map((t=>e.push(...t.toPacketList()))),this.subkeys.map((t=>e.push(...t.toPacketList()))),e}clone(e=!1){const t=new this.constructor(this.toPacketList());return e&&t.getKeys().forEach((e=>{if(e.keyPacket=Object.create(Object.getPrototypeOf(e.keyPacket),Object.getOwnPropertyDescriptors(e.keyPacket)),!e.keyPacket.isDecrypted())return;const t={};Object.keys(e.keyPacket.privateParams).forEach((r=>{t[r]=new Uint8Array(e.keyPacket.privateParams[r])})),e.keyPacket.privateParams=t})),t}getSubkeys(e=null){return this.subkeys.filter((t=>!e||t.getKeyID().equals(e,!0)))}getKeys(e=null){const t=[];return e&&!this.getKeyID().equals(e,!0)||t.push(this),t.concat(this.getSubkeys(e))}getKeyIDs(){return this.getKeys().map((e=>e.getKeyID()))}getUserIDs(){return this.users.map((e=>e.userID?e.userID.userID:null)).filter((e=>null!==e))}write(){return this.toPacketList().write()}async getSigningKey(e=null,t=new Date,r={},i=we){await this.verifyPrimaryKey(t,r,i);const n=this.keyPacket,a=this.subkeys.slice().sort(((e,t)=>t.keyPacket.created-e.keyPacket.created));let s;for(const r of a)if(!e||r.getKeyID().equals(e))try{await r.verify(t,i);const e={key:n,bind:r.keyPacket},a=await oh(r.bindingSignatures,n,ue.signature.subkeyBinding,e,t,i);if(!gh(r.keyPacket,a))continue;if(!a.embeddedSignature)throw Error(\"Missing embedded signature\");return await oh([a.embeddedSignature],r.keyPacket,ue.signature.keyBinding,e,t,i),vh(r.keyPacket,i),r}catch(e){s=e}try{const a=await this.getPrimaryUser(t,r,i);if((!e||n.getKeyID().equals(e))&&gh(n,a.selfCertification))return vh(n,i),this}catch(e){s=e}throw de.wrapError(\"Could not find valid signing key packet in key \"+this.getKeyID().toHex(),s)}async getEncryptionKey(e,t=new Date,r={},i=we){await this.verifyPrimaryKey(t,r,i);const n=this.keyPacket,a=this.subkeys.slice().sort(((e,t)=>t.keyPacket.created-e.keyPacket.created));let s;for(const r of a)if(!e||r.getKeyID().equals(e))try{await r.verify(t,i);const e={key:n,bind:r.keyPacket},a=await oh(r.bindingSignatures,n,ue.signature.subkeyBinding,e,t,i);if(mh(r.keyPacket,a))return vh(r.keyPacket,i),r}catch(e){s=e}try{const a=await this.getPrimaryUser(t,r,i);if((!e||n.getKeyID().equals(e))&&mh(n,a.selfCertification))return vh(n,i),this}catch(e){s=e}throw de.wrapError(\"Could not find valid encryption key packet in key \"+this.getKeyID().toHex(),s)}async isRevoked(e,t,r=new Date,i=we){return ph(this.keyPacket,ue.signature.keyRevocation,{key:this.keyPacket},this.revocationSignatures,e,t,r,i)}async verifyPrimaryKey(e=new Date,t={},r=we){const i=this.keyPacket;if(await this.isRevoked(null,null,e,r))throw Error(\"Primary key is revoked\");const{selfCertification:n}=await this.getPrimaryUser(e,t,r);if(ch(i,n,e))throw Error(\"Primary key is expired\");const a=await oh(this.directSignatures,i,ue.signature.key,{key:i},e,r).catch((()=>{}));if(a&&ch(i,a,e))throw Error(\"Primary key is expired\")}async getExpirationTime(e,t=we){let r;try{const{selfCertification:i}=await this.getPrimaryUser(null,e,t),n=yh(this.keyPacket,i),a=i.getExpirationTime(),s=await oh(this.directSignatures,this.keyPacket,ue.signature.key,{key:this.keyPacket},null,t).catch((()=>{}));if(s){const e=yh(this.keyPacket,s);r=Math.min(n,a,e)}else r=ne.subkeys.some((e=>t.hasSameFingerprintAs(e)))))))throw Error(\"Cannot update public key with private key if subkeys mismatch\");return e.update(this,r)}const i=this.clone();return await lh(e,i,\"revocationSignatures\",t,(n=>ph(i.keyPacket,ue.signature.keyRevocation,i,[n],null,e.keyPacket,t,r))),await lh(e,i,\"directSignatures\",t),await Promise.all(e.users.map((async e=>{const n=i.users.filter((t=>e.userID&&e.userID.equals(t.userID)||e.userAttribute&&e.userAttribute.equals(t.userAttribute)));if(n.length>0)await Promise.all(n.map((i=>i.update(e,t,r))));else{const t=e.clone();t.mainKey=i,i.users.push(t)}}))),await Promise.all(e.subkeys.map((async e=>{const n=i.subkeys.filter((t=>t.hasSameFingerprintAs(e)));if(n.length>0)await Promise.all(n.map((i=>i.update(e,t,r))));else{const t=e.clone();t.mainKey=i,i.subkeys.push(t)}}))),i}async getRevocationCertificate(e=new Date,t=we){const r={key:this.keyPacket},i=await oh(this.revocationSignatures,this.keyPacket,ue.signature.keyRevocation,r,e,t),n=new Ku;return n.push(i),Me(ue.armor.publicKey,n.write(),null,null,\"This is a revocation certificate\")}async applyRevocationCertificate(e,t=new Date,r=we){const i=await xe(e,r),n=(await Ku.fromBinary(i.data,Ah,r)).findPacket(ue.packet.signature);if(!n||n.signatureType!==ue.signature.keyRevocation)throw Error(\"Could not find revocation signature packet\");if(!n.issuerKeyID.equals(this.getKeyID()))throw Error(\"Revocation signature does not match key\");try{await n.verify(this.keyPacket,ue.signature.keyRevocation,{key:this.keyPacket},t,void 0,r)}catch(e){throw de.wrapError(\"Could not verify revocation signature\",e)}const a=this.clone();return a.revocationSignatures.push(n),a}async signPrimaryUser(e,t,r,i=we){const{index:n,user:a}=await this.getPrimaryUser(t,r,i),s=await a.certify(e,t,i),o=this.clone();return o.users[n]=s,o}async signAllUsers(e,t=new Date,r=we){const i=this.clone();return i.users=await Promise.all(this.users.map((function(i){return i.certify(e,t,r)}))),i}async verifyPrimaryUser(e,t=new Date,r,i=we){const n=this.keyPacket,{user:a}=await this.getPrimaryUser(t,r,i);return e?await a.verifyAllCertifications(e,t,i):[{keyID:n.getKeyID(),valid:await a.verify(t,i).catch((()=>!1))}]}async verifyAllUsers(e,t=new Date,r=we){const i=this.keyPacket,n=[];return await Promise.all(this.users.map((async a=>{const s=e?await a.verifyAllCertifications(e,t,r):[{keyID:i.getKeyID(),valid:await a.verify(t,r).catch((()=>!1))}];n.push(...s.map((e=>({userID:a.userID?a.userID.userID:null,userAttribute:a.userAttribute,keyID:e.keyID,valid:e.valid}))))}))),n}}[\"getKeyID\",\"getFingerprint\",\"getAlgorithmInfo\",\"getCreationTime\",\"hasSameFingerprintAs\"].forEach((e=>{Ph.prototype[e]=kh.prototype[e]}));class xh extends Ph{constructor(e){if(super(),this.keyPacket=null,this.revocationSignatures=[],this.directSignatures=[],this.users=[],this.subkeys=[],e&&(this.packetListToStructure(e,new Set([ue.packet.secretKey,ue.packet.secretSubkey])),!this.keyPacket))throw Error(\"Invalid key: missing public-key packet\")}isPrivate(){return!1}toPublic(){return this}armor(e=we){return Me(ue.armor.publicKey,this.toPacketList().write(),void 0,void 0,void 0,e)}}class Mh extends xh{constructor(e){if(super(),this.packetListToStructure(e,new Set([ue.packet.publicKey,ue.packet.publicSubkey])),!this.keyPacket)throw Error(\"Invalid key: missing private-key packet\")}isPrivate(){return!0}toPublic(){const e=new Ku,t=this.toPacketList();for(const r of t)switch(r.constructor.tag){case ue.packet.secretKey:{const t=Vu.fromSecretKeyPacket(r);e.push(t);break}case ue.packet.secretSubkey:{const t=Xu.fromSecretSubkeyPacket(r);e.push(t);break}default:e.push(r)}return new xh(e)}armor(e=we){return Me(ue.armor.privateKey,this.toPacketList().write(),void 0,void 0,void 0,e)}async getDecryptionKeys(e,t=new Date,r={},i=we){const n=this.keyPacket,a=[];for(let r=0;r