!function(e,t){for(var r in t)e[r]=t[r]}(exports,function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=12)}([function(e,t){e.exports=require("crypto")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n={FormData:!0,UniCloudError:!0};Object.defineProperty(t,"FormData",{enumerable:!0,get:function(){return i.default}}),Object.defineProperty(t,"UniCloudError",{enumerable:!0,get:function(){return s.default}});var i=u(r(15)),s=u(r(16)),a=r(17);Object.keys(a).forEach((function(e){"default"!==e&&"__esModule"!==e&&(Object.prototype.hasOwnProperty.call(n,e)||Object.defineProperty(t,e,{enumerable:!0,get:function(){return a[e]}}))}));var o=r(2);function u(e){return e&&e.__esModule?e:{default:e}}Object.keys(o).forEach((function(e){"default"!==e&&"__esModule"!==e&&(Object.prototype.hasOwnProperty.call(n,e)||Object.defineProperty(t,e,{enumerable:!0,get:function(){return o[e]}}))}))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.hasOwn=s,t.isPlainObject=a,t.isFn=function(e){return"function"==typeof e},t.deepClone=function(e){return JSON.parse(JSON.stringify(e))},t.getExtension=function(e){return o[e]},t.snake2camel=l,t.camel2snake=f,t.snake2camelJson=function(e){return h(e,"snake2camel")},t.camel2snakeJson=function(e){return h(e,"camel2snake")},t.getOffsetDate=function(e){return new Date(Date.now()+6e4*((new Date).getTimezoneOffset()+60*(e||0)))},t.getDateStr=p,t.getTimeStr=d,t.getFullTimeStr=function(e){return p(e=e||new Date)+" "+d(e)},t.log=function(){0},t.accMul=function(e,t){if(isNaN(e)||isNaN(t))return NaN;const{value:r,power:n}=y(e),{value:i,power:s}=y(t);return r*i/Math.pow(10,n+s)},t.mime2ext=void 0;const n=Object.prototype.toString,i=Object.prototype.hasOwnProperty;function s(e,t){return i.call(e,t)}function a(e){return"[object Object]"===n.call(e)}const o={"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/svg+xml":"svg","image/bmp":"bmp","image/webp":"webp"};t.mime2ext=o;const u=/_(\w)/g,c=/[A-Z]/g;function l(e){return e.replace(u,(e,t)=>t?t.toUpperCase():"")}function f(e){return e.replace(c,e=>"_"+e.toLowerCase())}function h(e,t){let r,n;switch(t){case"snake2camel":n=l,r=u;break;case"camel2snake":n=f,r=c}for(const i in e)if(s(e,i)&&r.test(i)){const r=n(i);e[r]=e[i],delete e[i],a(e[r])?e[r]=h(e[r],t):Array.isArray(e[r])&&(e[r]=e[r].map(e=>h(e,t)))}return e}function p(e,t="-"){e=e||new Date;const r=[];return r.push(e.getFullYear()),r.push(("00"+(e.getMonth()+1)).substr(-2)),r.push(("00"+e.getDate()).substr(-2)),r.join(t)}function d(e,t=":"){e=e||new Date;const r=[];return r.push(("00"+e.getHours()).substr(-2)),r.push(("00"+e.getMinutes()).substr(-2)),r.push(("00"+e.getSeconds()).substr(-2)),r.join(t)}function y(e){const t=e.toString().split("."),r=t[1]?t[1].length:0;return{value:Number(t.join("")),power:r}}},function(e,t){e.exports=require("util")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(39);t.bytesFromIP=function(e){switch(n.isIP(e)){case 4:return Buffer.from(e.split(".").map(e=>parseInt(e,10)));case 6:const t=e.split(":"),r=Buffer.alloc(16);let n=0;""===t[t.length-1]&&(t[t.length-1]="0");for(let e=0;es&&(s=n,i=r)):(r=-1,n=0),t.push(o.toString(16))}if(s>0){let e="";const r=t.slice(i+s);t.length=i,0===t.length&&(e+=":"),0===r.length&&(e+=":"),t.push(e,...r)}return t.join(":");default:return""}};const i=Object.create(null),s=/^[0-9.]+$/;function a(e,t){i[e]=t,i[t]=e}t.getOID=function(e){return s.test(e)&&""!==i[e]?e:null==i[e]?"":i[e]},t.getOIDName=function(e){return s.test(e)||""===i[e]?null==i[e]?e:i[e]:e},a("1.2.840.113549.1.1.1","rsaEncryption"),a("1.2.840.113549.1.1.4","md5WithRsaEncryption"),a("1.2.840.113549.1.1.5","sha1WithRsaEncryption"),a("1.2.840.113549.1.1.8","mgf1"),a("1.2.840.113549.1.1.10","RSASSA-PSS"),a("1.2.840.113549.1.1.11","sha256WithRsaEncryption"),a("1.2.840.113549.1.1.12","sha384WithRsaEncryption"),a("1.2.840.113549.1.1.13","sha512WithRsaEncryption"),a("1.2.840.10045.2.1","ecEncryption"),a("1.2.840.10045.4.1","ecdsaWithSha1"),a("1.2.840.10045.4.3.2","ecdsaWithSha256"),a("1.2.840.10045.4.3.3","ecdsaWithSha384"),a("1.2.840.10045.4.3.4","ecdsaWithSha512"),a("1.2.840.10040.4.3","dsaWithSha1"),a("2.16.840.1.101.3.4.3.2","dsaWithSha256"),a("1.3.14.3.2.7","desCBC"),a("1.3.14.3.2.26","sha1"),a("2.16.840.1.101.3.4.2.1","sha256"),a("2.16.840.1.101.3.4.2.2","sha384"),a("2.16.840.1.101.3.4.2.3","sha512"),a("1.2.840.113549.2.5","md5"),a("1.3.101.110","X25519"),a("1.3.101.111","X448"),a("1.3.101.112","Ed25519"),a("1.3.101.113","Ed448"),a("1.2.840.113549.1.7.1","data"),a("1.2.840.113549.1.7.2","signedData"),a("1.2.840.113549.1.7.3","envelopedData"),a("1.2.840.113549.1.7.4","signedAndEnvelopedData"),a("1.2.840.113549.1.7.5","digestedData"),a("1.2.840.113549.1.7.6","encryptedData"),a("1.2.840.113549.1.9.1","emailAddress"),a("1.2.840.113549.1.9.2","unstructuredName"),a("1.2.840.113549.1.9.3","contentType"),a("1.2.840.113549.1.9.4","messageDigest"),a("1.2.840.113549.1.9.5","signingTime"),a("1.2.840.113549.1.9.6","counterSignature"),a("1.2.840.113549.1.9.7","challengePassword"),a("1.2.840.113549.1.9.8","unstructuredAddress"),a("1.2.840.113549.1.9.14","extensionRequest"),a("1.2.840.113549.1.9.20","friendlyName"),a("1.2.840.113549.1.9.21","localKeyId"),a("1.2.840.113549.1.9.22.1","x509Certificate"),a("1.2.840.113549.1.12.10.1.1","keyBag"),a("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag"),a("1.2.840.113549.1.12.10.1.3","certBag"),a("1.2.840.113549.1.12.10.1.4","crlBag"),a("1.2.840.113549.1.12.10.1.5","secretBag"),a("1.2.840.113549.1.12.10.1.6","safeContentsBag"),a("1.2.840.113549.1.5.13","pkcs5PBES2"),a("1.2.840.113549.1.5.12","pkcs5PBKDF2"),a("1.2.840.113549.2.7","hmacWithSha1"),a("1.2.840.113549.2.9","hmacWithSha256"),a("1.2.840.113549.2.10","hmacWithSha384"),a("1.2.840.113549.2.11","hmacWithSha512"),a("1.2.840.113549.3.7","3desCBC"),a("2.16.840.1.101.3.4.1.2","aesCBC128"),a("2.16.840.1.101.3.4.1.42","aesCBC256"),a("2.5.4.3","commonName"),a("2.5.4.5","serialName"),a("2.5.4.6","countryName"),a("2.5.4.7","localityName"),a("2.5.4.8","stateOrProvinceName"),a("2.5.4.10","organizationName"),a("2.5.4.11","organizationalUnitName"),a("2.5.4.15","businessCategory"),a("2.16.840.1.113730.1.1","nsCertType"),a("2.5.29.2","keyAttributes"),a("2.5.29.4","keyUsageRestriction"),a("2.5.29.6","subtreesConstraint"),a("2.5.29.9","subjectDirectoryAttributes"),a("2.5.29.14","subjectKeyIdentifier"),a("2.5.29.15","keyUsage"),a("2.5.29.16","privateKeyUsagePeriod"),a("2.5.29.17","subjectAltName"),a("2.5.29.18","issuerAltName"),a("2.5.29.19","basicConstraints"),a("2.5.29.20","cRLNumber"),a("2.5.29.21","cRLReason"),a("2.5.29.22","expirationDate"),a("2.5.29.23","instructionCode"),a("2.5.29.24","invalidityDate"),a("2.5.29.27","deltaCRLIndicator"),a("2.5.29.28","issuingDistributionPoint"),a("2.5.29.29","certificateIssuer"),a("2.5.29.30","nameConstraints"),a("2.5.29.31","cRLDistributionPoints"),a("2.5.29.32","certificatePolicies"),a("2.5.29.33","policyMappings"),a("2.5.29.35","authorityKeyIdentifier"),a("2.5.29.36","policyConstraints"),a("2.5.29.37","extKeyUsage"),a("2.5.29.46","freshestCRL"),a("2.5.29.54","inhibitAnyPolicy"),a("1.3.6.1.4.1.311.60.2.1.2","jurisdictionST"),a("1.3.6.1.4.1.311.60.2.1.3","jurisdictionC"),a("1.3.6.1.4.1.11129.2.4.2","timestampList"),a("1.3.6.1.5.5.7.1.1","authorityInfoAccess"),a("1.3.6.1.5.5.7.3.1","serverAuth"),a("1.3.6.1.5.5.7.3.2","clientAuth"),a("1.3.6.1.5.5.7.3.3","codeSigning"),a("1.3.6.1.5.5.7.3.4","emailProtection"),a("1.3.6.1.5.5.7.3.8","timeStamping"),a("1.3.6.1.5.5.7.48.1","authorityInfoAccessOcsp"),a("1.3.6.1.5.5.7.48.2","authorityInfoAccessIssuers")},function(e,t){e.exports=require("fs")},function(e,t,r){"use strict";const n=e=>!("object"!=typeof e||null===e||e instanceof RegExp||e instanceof Error||e instanceof Date);e.exports=function e(t,r,i,s){if(i=Object.assign({deep:!1,target:{}},i),(s=s||new WeakMap).has(t))return s.get(t);s.set(t,i.target);const a=i.target;delete i.target;for(const o of Object.keys(t)){const u=t[o],c=r(o,u,t);let l=c[1];i.deep&&n(l)&&(l=Array.isArray(l)?l.map(t=>n(t)?e(t,r,i,s):t):e(l,r,i,s)),a[c[0]]=l}return a}},function(e,t,r){"use strict";var n=r(6),i=r(31);e.exports=function(e,t){return t=Object.assign({deep:!0},t),n(e,(function(e,t){return[i(e),t]}),t)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(0),i=r(34),s=r(35),a=r(7),o={RSA:"RSA-SHA1",RSA2:"RSA-SHA256"};t.ALIPAY_ALGORITHM_MAPPING=o,t.sign=function(e,t={},r){const u=t.bizContent||null;delete t.bizContent;let c=Object.assign({method:e,appId:r.appId,charset:r.charset,version:r.version,signType:r.signType,timestamp:i().format("YYYY-MM-DD HH:mm:ss")},t);r.appCertSn&&r.alipayRootCertSn&&(c=Object.assign({appCertSn:r.appCertSn,alipayRootCertSn:r.alipayRootCertSn},c)),u&&(c.bizContent=JSON.stringify(a(u)));const l=a(c),f=Object.keys(l).sort().map(e=>{let t=l[e];return"[object String]"!==Array.prototype.toString.call(t)&&(t=JSON.stringify(t)),`${e}=${s.encode(t,r.charset)}`}).join("&"),h=n.createSign(o[r.signType]).update(f,"utf8").sign(r.privateKey,"base64");return Object.assign(l,{sign:h})}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(3),i=r(0),s=r(40),a=r(10),o=r(4);t.publicKeyValidator={name:"PublicKeyInfo",class:a.Class.UNIVERSAL,tag:a.Tag.SEQUENCE,capture:"publicKeyInfo",value:[{name:"PublicKeyInfo.AlgorithmIdentifier",class:a.Class.UNIVERSAL,tag:a.Tag.SEQUENCE,value:[{name:"PublicKeyAlgorithmIdentifier.algorithm",class:a.Class.UNIVERSAL,tag:a.Tag.OID,capture:"publicKeyOID"}]},{name:"PublicKeyInfo.PublicKey",class:a.Class.UNIVERSAL,tag:a.Tag.BITSTRING,capture:"publicKey"}]},t.privateKeyValidator={name:"PrivateKeyInfo",class:a.Class.UNIVERSAL,tag:a.Tag.SEQUENCE,capture:"privateKeyInfo",value:[{name:"PrivateKeyInfo.Version",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.AlgorithmIdentifier",class:a.Class.UNIVERSAL,tag:a.Tag.SEQUENCE,value:[{name:"PrivateKeyAlgorithmIdentifier.algorithm",class:a.Class.UNIVERSAL,tag:a.Tag.OID,capture:"privateKeyOID"}]},{name:"PrivateKeyInfo.PrivateKey",class:a.Class.UNIVERSAL,tag:a.Tag.OCTETSTRING,capture:"privateKey"}]};const u={name:"RSAPublicKey",class:a.Class.UNIVERSAL,tag:a.Tag.SEQUENCE,value:[{name:"RSAPublicKey.modulus",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"publicKeyModulus"},{name:"RSAPublicKey.exponent",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"publicKeyExponent"}]},c={name:"RSAPrivateKey",class:a.Class.UNIVERSAL,tag:a.Tag.SEQUENCE,value:[{name:"RSAPrivateKey.version",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"privateKeyVersion"},{name:"RSAPrivateKey.modulus",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"privateKeyModulus"},{name:"RSAPrivateKey.publicExponent",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"privateKeyPublicExponent"},{name:"RSAPrivateKey.privateExponent",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"privateKeyPrivateExponent"},{name:"RSAPrivateKey.prime1",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"privateKeyPrime1"},{name:"RSAPrivateKey.prime2",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"privateKeyPrime2"},{name:"RSAPrivateKey.exponent1",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"privateKeyExponent1"},{name:"RSAPrivateKey.exponent2",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"privateKeyExponent2"},{name:"RSAPrivateKey.coefficient",class:a.Class.UNIVERSAL,tag:a.Tag.INTEGER,capture:"privateKeyCoefficient"}]},l=[o.getOID("X25519"),o.getOID("X448"),o.getOID("Ed25519"),o.getOID("Ed448")];class f{constructor(e){const r={},n=e.validate(t.publicKeyValidator,r);if(null!=n)throw new Error("Cannot read X.509 public key: "+n.message);this.oid=a.ASN1.parseOID(r.publicKeyOID.bytes),this.algo=o.getOIDName(this.oid),this._pkcs8=e,this._keyRaw=a.ASN1.parseBitString(r.publicKey.bytes).buf,this._finalKey=this._keyRaw,this._finalPEM=""}static fromPEM(e){const t=a.PEM.parse(e)[0];if(t.procType.includes("ENCRYPTED"))throw new Error("Could not convert public key from PEM, PEM is encrypted.");const r=a.ASN1.fromDER(t.body,!0);switch(t.type){case"PUBLIC KEY":return new f(r);case"RSA PUBLIC KEY":const e=a.ASN1.Seq([a.ASN1.Seq([a.ASN1.OID(o.getOID("rsaEncryption")),a.ASN1.Null()]),a.ASN1.BitString(r.DER)]);return new f(e);default:throw new Error("Could not convert public key from PEM, recommend PKCS#8 PEM")}}static addVerifier(e,t){if(""===(e=o.getOID(e)))throw new Error("Invalid object identifier: "+e);if(null!=f._verifiers[e])throw new Error(`Verifier ${e} exists`);f._verifiers[e]=t}get keyRaw(){return this._finalKey}verify(e,t,r){const n=f._verifiers[this.oid];if(null!=n){const s=i.createHash(r).update(e).digest();return n.call(this,s,t)}const s=i.createVerify(r);return s.update(e),s.verify(this.toPEM(),t)}getFingerprint(e,t="PublicKey"){let r;switch(t){case"PublicKeyInfo":r=this._pkcs8.DER;break;case"PublicKey":r=this._keyRaw;break;default:throw new Error(`Unknown fingerprint type "${t}".`)}const n=i.createHash(e);return n.update(r),n.digest()}toASN1(){return this._pkcs8}toDER(){return this._pkcs8.DER}toPEM(){return""===this._finalPEM&&(this._finalPEM=new a.PEM("PUBLIC KEY",this._pkcs8.DER).toString()),this._finalPEM}toJSON(){return{oid:this.oid,algo:this.algo,publicKey:this._keyRaw}}[n.inspect.custom](e,t){return`<${this.constructor.name} ${n.inspect(this.toJSON(),t)}>`}}f._verifiers=Object.create(null),t.PublicKey=f;class h{constructor(e){const r=Object.create(null),n=e.validate(t.privateKeyValidator,r);if(null!=n)throw new Error("Cannot read X.509 private key: "+n.message);if(this.version=a.ASN1.parseIntegerNum(r.privateKeyVersion.bytes)+1,this.oid=a.ASN1.parseOID(r.privateKeyOID.bytes),this.algo=o.getOIDName(this.oid),this._pkcs8=e,this._keyRaw=r.privateKey.bytes,this._publicKeyRaw=null,this._finalKey=this._keyRaw,this._finalPEM="",l.includes(this.oid))if(this._finalKey=this._keyRaw=a.ASN1.parseDER(this._keyRaw,a.Class.UNIVERSAL,a.Tag.OCTETSTRING).bytes,"1.3.101.112"===this.oid){const e=s.sign.keyPair.fromSeed(this._keyRaw);this._publicKeyRaw=Buffer.from(e.publicKey),this._finalKey=Buffer.from(e.secretKey)}else if(2===this.version)for(const t of e.mustCompound())t.class===a.Class.CONTEXT_SPECIFIC&&1===t.tag&&(this._publicKeyRaw=a.ASN1.parseBitString(t.bytes).buf,this._finalKey=Buffer.concat([this._keyRaw,this._publicKeyRaw]))}static fromPEM(e){const t=a.PEM.parse(e)[0];if(t.procType.includes("ENCRYPTED"))throw new Error("Could not convert private key from PEM, PEM is encrypted.");let r=a.ASN1.fromDER(t.body,!0);switch(t.type){case"PRIVATE KEY":return new h(r);case"RSA PRIVATE KEY":return r=a.ASN1.Seq([r.value[0],a.ASN1.Seq([a.ASN1.OID(o.getOID("rsaEncryption")),a.ASN1.Null()]),new a.ASN1(a.Class.UNIVERSAL,a.Tag.OCTETSTRING,r.DER)]),new h(r);default:throw new Error("Could not convert private key from PEM, recommend PKCS#8 PEM")}}static addSigner(e,t){if(""===(e=o.getOID(e)))throw new Error("Invalid object identifier: "+e);if(null!=h._signers[e])throw new Error(`Signer ${e} exists`);h._signers[e]=t}get keyRaw(){return this._finalKey}get publicKeyRaw(){return this._publicKeyRaw}sign(e,t){const r=h._signers[this.oid];if(null!=r){const n=i.createHash(t).update(e).digest();return r.call(this,n)}const n=i.createSign(t);return n.update(e),n.sign(this.toPEM())}toASN1(){return this._pkcs8}toDER(){return this._pkcs8.DER}toPEM(){return""===this._finalPEM&&(this._finalPEM=new a.PEM("PRIVATE KEY",this._pkcs8.DER).toString()),this._finalPEM}toJSON(){return{version:this.version,oid:this.oid,algo:this.algo,privateKey:this._keyRaw,publicKey:this._publicKeyRaw}}[n.inspect.custom](e,t){return`<${this.constructor.name} ${n.inspect(this.toJSON(),t)}>`}}h._signers=Object.create(null),t.PrivateKey=h;class p extends f{static fromPublicKey(e){return new p(e.toASN1())}constructor(e){if(super(e),o.getOID(this.oid)!==o.getOID("rsaEncryption"))throw new Error("Invalid RSA public key, unknown OID: "+this.oid);const t=Object.create(null);this._pkcs1=a.ASN1.fromDER(this._keyRaw,!0);const r=this._pkcs1.validate(u,t);if(null!=r)throw new Error("Cannot read RSA public key: "+r.message);this.modulus=a.ASN1.parseIntegerStr(t.publicKeyModulus.bytes),this.exponent=a.ASN1.parseIntegerNum(t.publicKeyExponent.bytes)}toASN1(){return this._pkcs1}toDER(){return this._keyRaw}toPEM(){return""===this._finalPEM&&(this._finalPEM=new a.PEM("RSA PUBLIC KEY",this._keyRaw).toString()),this._finalPEM}toPublicKeyPEM(){return new a.PEM("PUBLIC KEY",this._pkcs8.DER).toString()}toJSON(){return{oid:this.oid,algo:this.algo,modulus:y(this.modulus),exponent:this.exponent}}[n.inspect.custom](e,t){return`<${this.constructor.name} ${n.inspect(this.toJSON(),t)}>`}}t.RSAPublicKey=p;class d extends h{static fromPrivateKey(e){return new d(e.toASN1())}constructor(e){if(super(e),o.getOID(this.oid)!==o.getOID("rsaEncryption"))throw new Error("Invalid RSA private key, unknown OID: "+this.oid);const t=Object.create(null);this._pkcs1=a.ASN1.fromDER(this._keyRaw,!0);const r=this._pkcs1.validate(c,t);if(null!=r)throw new Error("Cannot read RSA private key: "+r.message);this.publicExponent=a.ASN1.parseIntegerNum(t.privateKeyPublicExponent.bytes),this.privateExponent=a.ASN1.parseIntegerStr(t.privateKeyPrivateExponent.bytes),this.modulus=a.ASN1.parseIntegerStr(t.privateKeyModulus.bytes),this.prime1=a.ASN1.parseIntegerStr(t.privateKeyPrime1.bytes),this.prime2=a.ASN1.parseIntegerStr(t.privateKeyPrime2.bytes),this.exponent1=a.ASN1.parseIntegerStr(t.privateKeyExponent1.bytes),this.exponent2=a.ASN1.parseIntegerStr(t.privateKeyExponent2.bytes),this.coefficient=a.ASN1.parseIntegerStr(t.privateKeyCoefficient.bytes)}toASN1(){return this._pkcs1}toDER(){return this._keyRaw}toPEM(){return""===this._finalPEM&&(this._finalPEM=new a.PEM("RSA PRIVATE KEY",this._keyRaw).toString()),this._finalPEM}toPrivateKeyPEM(){return new a.PEM("PRIVATE KEY",this._pkcs8.DER).toString()}toJSON(){return{version:this.version,oid:this.oid,algo:this.algo,publicExponent:this.publicExponent,privateExponent:y(this.privateExponent),modulus:y(this.modulus),prime1:y(this.prime1),prime2:y(this.prime2),exponent1:y(this.exponent1),exponent2:y(this.exponent2),coefficient:y(this.coefficient)}}[n.inspect.custom](e,t){return`<${this.constructor.name} ${n.inspect(this.toJSON(),t)}>`}}function y(e){return e.length%8!=0&&e.startsWith("00")?e.slice(2):e}t.RSAPrivateKey=d,f.addVerifier(o.getOID("Ed25519"),(function(e,t){return s.sign.detached.verify(e,t,this.keyRaw)})),h.addSigner(o.getOID("Ed25519"),(function(e){const t=this.keyRaw;if(64!==t.length)throw new Error("Invalid signing key.");return Buffer.from(s.sign.detached(e,t))}))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(11);t.BufferVisitor=n.BufferVisitor;var i=r(41);t.PEM=i.PEM;var s=r(42);t.ASN1=s.ASN1,t.Class=s.Class,t.Tag=s.Tag,t.BitString=s.BitString},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.BufferVisitor=class{constructor(e,t=0,r=0){this.start=t,this.end=r>t?r:t,this.buf=e}get length(){return this.buf.length}reset(e=0,t=0){return this.start=e,t>=this.start?this.end=t:this.endthis.buf.length){const e=new Error(t);throw e.available=this.buf.length,e.requested=r,e}return this.walk(0),this}mustWalk(e,t){return this.mustHas(e,t),this.walk(e),this}}},function(e,t,r){"use strict";var n=o(r(13)),i=o(r(19)),s=o(r(46)),a=r(1);function o(e){return e&&e.__esModule?e:{default:e}}e.exports={initWeixin:(e={})=>(e.clientType=e.clientType||__ctx__.PLATFORM,(0,a.createApi)(n.default,e)),initAlipay:(e={})=>(e.clientType=e.clientType||__ctx__.PLATFORM,(0,a.createApi)(i.default,e)),initAppleIapPayment:(e={})=>(e.clientType=e.clientType||__ctx__.PLATFORM,(0,a.createApi)(s.default,e))}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=a(r(14)),i=a(r(18)),s=r(1);function a(e){return e&&e.__esModule?e:{default:e}}t.default=class{constructor(e={}){if(!e.appId)throw new Error("appId required");if(!e.mchId)throw new Error("mchId required");if(!e.key)throw new Error("key required");e.signType=e.signType||"MD5",this.options=Object.assign({},e),this._protocols=i.default,this.baseUrl="https://api.mch.weixin.qq.com",this.paths={unifiedOrder:"/pay/unifiedorder",orderQuery:"/pay/orderquery",closeOrder:"/pay/closeorder",refund:"/secapi/pay/refund",refundQuery:"/pay/refundquery",downloadBill:"/pay/downloadbill",downloadFundflow:"/pay/downloadfundflow",getsignkey:"/pay/getsignkey"}}_getSign(e,t){const r=n.default.getSignStr(e)+"&key="+this.options.key;switch(t){case"MD5":return n.default.md5(r).toUpperCase();case"HMAC-SHA256":return n.default.sha256(r,this.options.key).toUpperCase();default:throw new Error("signType Error")}}_normalizeResult(e,t){return e.returnMsg=e.returnMsg||("SUCCESS"===e.returnCode?"ok":"fail"),e.errMsg=`payment.${t} ${e.returnMsg.toLowerCase()}`,e}_parse(e,t,r){const i=n.default.parseXML(e);if("FAIL"===i.return_code)throw new Error(""+i.return_msg);if("getSandboxKey"!==t){if(i.appid!==this.options.appId)throw new Error("appId不匹配");if(i.mch_id!==this.options.mchId)throw new Error("mchId不匹配");if(i.sign!==this._getSign(i,r))throw new Error("返回结果签名错误");i.app_id=i.appid,delete i.appid}if("FAIL"===i.result_code)throw new Error(`${i.err_code} ${i.err_code_des}`);return this._normalizeResult((0,s.snake2camelJson)(i),t)}_parseBill(e,t){const r={};if(n.default.isXML(e)){const t=n.default.parseXML(e);if("FAIL"===t.return_code)throw new Error(""+t.return_msg);if("FAIL"===t.result_code)throw new Error(`${t.err_code} ${t.err_code_des}`)}else r.returnCode="SUCCESS",r.content=e;return this._normalizeResult(r,t)}_getPublicParams(){const{appId:e,mchId:t,subAppId:r,subMchId:i}=this.options;return r?{appid:e,mchId:t,nonceStr:n.default.getNonceStr(),subAppid:r,subMchId:i}:{appid:e,mchId:t,nonceStr:n.default.getNonceStr()}}async _requestWxpay(e,t,r=!1){if(r&&!this.options.pfx)throw new Error("此接口需要微信支付证书(请传入pfx字段)");"getSandboxKey"!==t&&await this._initSandbox();const i=e.signType||this.options.signType;(e=(0,s.camel2snakeJson)(e)).sign=this._getSign(e,i);const a={method:"POST",dataType:"text",data:n.default.buildXML(e),timeout:this.options.timeout};r&&(a.pfx=this.options.pfx,a.passphrase=this.options.mchId);const{status:o,data:u}=await uniCloud.httpclient.request(this.options.sandbox?`${this.baseUrl}/sandboxnew${this.paths[t]}`:`${this.baseUrl}${this.paths[t]}`,a);if(200!==o)throw new Error("request fail");return-1!==["downloadBill","downloadFundflow"].indexOf(t)?this._parseBill(u,t):this._parse(u,t,i)}async getSandboxKey(){const e={mchId:this.options.mchId,nonceStr:n.default.getNonceStr()};return await this._requestWxpay(e,"getSandboxKey")}async _initSandbox(){this.options.sandbox&&!this.options.sandboxKey&&(this.options.key=this.options.sandboxKey=await this.getSandboxKey().sandbox_signkey)}async unifiedOrder(e){let t;if(e.tradeType)t=e.tradeType;else switch(this.options.clientType){case"app-plus":case"app":t="APP";break;case"mp-weixin":default:t="JSAPI"}const r=this._getPublicParams();r.subAppid&&(e.sub_openid=e.openid),("JSAPI"!==t||r.subAppid)&&delete e.openid;const n={...e,...r,spbillCreateIp:e.spbillCreateIp||"127.0.0.1",tradeType:t};return await this._requestWxpay(n,"unifiedOrder")}_getPayParamsByPrepayId(e,t){let r;switch(this.options.clientType){case"app-plus":case"app":r={appid:this.options.subAppId?this.options.subAppId:this.options.appId,noncestr:n.default.getNonceStr(),package:"Sign=WXPay",partnerid:this.options.mchId,prepayid:e,timestamp:""+(Date.now()/1e3|0)},r.sign=this._getSign(r,t);break;case"mp-weixin":default:{const i=""+(Date.now()/1e3|0);r={appId:this.options.subAppId?this.options.subAppId:this.options.appId,nonceStr:n.default.getNonceStr(),package:"prepay_id="+e,timeStamp:i},r.signType=t,r.paySign=this._getSign(r,t),r.timestamp=i;break}}return r}async getOrderInfo(e){let t;if(e.tradeType)t=e.tradeType;else switch(this.options.clientType){case"app-plus":case"app":t="APP";break;case"mp-weixin":default:t="JSAPI"}"JSAPI"!==t&&delete e.openid,e.tradeType=t;const r=await this.unifiedOrder(e);if("NATIVE"===t||"MWEB"===t)return r;if(!r.prepayId)throw new Error(r.errMsg||"获取prepayId失败");return this._getPayParamsByPrepayId(r.prepayId,e.signType||this.options.signType)}async orderQuery(e){const t={...e,...this._getPublicParams()};return await this._requestWxpay(t,"orderQuery")}async closeOrder(e){const t={...e,...this._getPublicParams()};return await this._requestWxpay(t,"closeOrder")}async refund(e){const t={...e,...this._getPublicParams()};return await this._requestWxpay(t,"refund",!0)}async refundQuery(e){const t={...e,...this._getPublicParams()};return await this._requestWxpay(t,"refundQuery")}async downloadBill(e){const t={...e,...this._getPublicParams(),billType:e.billType||"ALL"};return await this._requestWxpay(t,"downloadBill")}async downloadFundflow(e){const t={...e,...this._getPublicParams(),signType:e.signType||"HMAC-SHA256",accountType:e.accountType||"Basic"};return await this._requestWxpay(t,"downloadFundflow",!0)}_getNotifyData(e){let t=e.body;return e.isBase64Encoded&&(t=Buffer.from(t,"base64").toString("utf-8")),n.default.parseXML(t)}_verifyNotify(e,t){const r=this._getNotifyData(e);if("FAIL"===r.return_code)throw new Error(`${r.return_code} ${r.return_msg}`);if(r.appid!==this.options.appId)throw new Error("appId不匹配");if(r.mch_id!==this.options.mchId)throw new Error("mchId不匹配");if(t&&r.sign!==this._getSign(r,this.options.signType))throw new Error("通知验签未通过");const n=(0,s.snake2camelJson)(r);return n.appId=n.appid,delete n.appid,n}verifyPaymentNotify(e){return"payment"===this.checkNotifyType(e)&&this._verifyNotify(e,!0)}verifyRefundNotify(e){if("refund"!==this.checkNotifyType(e))return!1;const t=this._verifyNotify(e,!1),r=(0,s.snake2camelJson)(n.default.parseXML(n.default.decryptData(t.reqInfo,n.default.md5(this.options.key))));return Object.assign(t,r),delete t.reqInfo,t}checkNotifyType(e){const t=this._getNotifyData(e);return"total_fee"in t?"payment":"req_info"in t?"refund":"payment"}},e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,i=(n=r(0))&&n.__esModule?n:{default:n},s=r(1);var a={decryptData:function(e,t,r=""){const n=i.default.createDecipheriv("aes-256-ecb",t,r);n.setAutoPadding(!0);let s=n.update(e,"base64","utf8");return s+=n.final("utf8"),s},md5:function(e,t="utf8"){return i.default.createHash("md5").update(e,t).digest("hex")},sha256:function(e,t,r="utf8"){return i.default.createHmac("sha256",t).update(e,r).digest("hex")},getSignStr:function(e){return Object.keys(e).filter(t=>"sign"!==t&&void 0!==e[t]&&""!==e[t]).sort().map(t=>t+"="+((0,s.isPlainObject)(e[t])?JSON.stringify(e[t]):e[t])).join("&")},getNonceStr:function(e=16){let t="";for(;t.length${Object.keys(e).map(t=>(0,s.isPlainObject)(e[t])?`<${t}>`:`<${t}>`).join("")}`},parseXML:function(e){const t=/<(?:xml|root).*?>([\s|\S]*)<\/(?:xml|root)>/.exec(e)[1],r={},n=/<(.*?)>(?:){0,1}<\/.*?>/g;let i=null;for(;i=n.exec(t);)r[i[1]]=i[2];return r},isXML:function(e){return/^(<\?xml.*\?>)?(\r?\n)*(.|\r?\n)*<\/xml>$/i.test(e.trim())}};t.default=a,e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default=class{constructor(){this._boundary="------FormDataBaseBoundary"+Math.random().toString(36).substring(2),this.dataList=[]}_addData(e){const t=this.dataList[this.dataList.length-1];"string"==typeof e&&"string"==typeof t?this.dataList[this.dataList.length-1]=t+"\r\n"+e:this.dataList.push(e)}append(e,t,r){this._addData("--"+this._boundary);let n=`Content-Disposition: form-data; name="${e}"`;switch(Buffer.isBuffer(t)){case!0:if(!r.filename||!r.contentType)throw new Error("filename and contentType required");n+=`; filename="${r.filename}"`,this._addData(n),this._addData("Content-Type: "+r.contentType),this._addData(""),this._addData(t);break;default:this._addData(""),this._addData(t)}}getHeaders(e){const t={"Content-Type":"multipart/form-data; boundary="+this._boundary};return Object.assign(t,e)}getBuffer(){let e=Buffer.alloc(0);return this.dataList.forEach(t=>{e=Buffer.isBuffer(t)?Buffer.concat([e,t]):Buffer.concat([e,Buffer.from(""+t)]),e=Buffer.concat([e,Buffer.from("\r\n")])}),e=Buffer.concat([e,Buffer.from("--"+this._boundary+"--")]),e}},e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;class n extends Error{constructor(e){super(e.message),this.errMsg=e.message||"",Object.defineProperties(this,{message:{get(){return`errCode: ${e.code||""} | errMsg: `+this.errMsg},set(e){this.errMsg=e}}})}}t.default=n,e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createApi=function(e,t){const r=new e(t);return new Proxy(r,{get:function(e,t){if("function"==typeof e[t]&&0!==t.indexOf("_")&&e._protocols&&e._protocols[t]){const r=e._protocols[t];return async function(n){n=i(n,r.args);let s=await e[t](n);return s=i(s,r.returnValue),s}}return e[t]}})};var n=r(2);function i(e={},t){if(!t||!e)return e;const r=["_pre","_purify","_post"];t._pre&&(e=t._pre(e));let i={shouldDelete:new Set([])};if(t._purify){const e=t._purify;for(const t in e)e[t]=new Set(e[t]);i=Object.assign(i,e)}if((0,n.isPlainObject)(t))for(const s in t){const a=t[s];(0,n.isFn)(a)&&-1===r.indexOf(s)?e[s]=a(e):"string"==typeof a&&-1===r.indexOf(s)&&(e[s]=e[a],i.shouldDelete.add(a))}else(0,n.isFn)(t)&&(e=t(e));if(i.shouldDelete)for(const t of i.shouldDelete)delete e[t];return t._post&&(e=t._post(e)),e}},function(e,t,r){"use strict";function n(e,t){t.forEach(t=>{void 0!==e[t]&&(e[t]=Number(e[t]))})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i={unifiedOrder:{args:{_purify:{shouldDelete:["subject"]}}},getOrderInfo:{args:{_purify:{shouldDelete:["subject"]}}},orderQuery:{returnValue:function(e){n(e,["cashFee","totalFee","couponCount"]),e.couponList=[];const t=e.couponCount||0;for(let r=0;r-1){const n=encodeURIComponent(t[e]);r=`${r}${r.includes("?")?"&":"?"}${e}=${n}`,delete t[e]}return{execParams:t,url:r}}async getOrderInfo(e){let t;if(e.tradeType)t=e.tradeType,delete e.tradeType;else switch(this.options.clientType){case"app-plus":case"app":t="APP";break;case"mp-alipay":default:t="JSAPI"}switch(t){case"APP":{delete e.buyerId;const t={};e.notifyUrl&&(t.notifyUrl=e.notifyUrl,delete e.notifyUrl),t.bizContent=e;const r=this._getSign("alipay.trade.app.pay",t),{url:n,execParams:i}=this.formatUrl("",r);return(n+"&biz_content="+encodeURIComponent(i.biz_content)).substr(1)}case"JSAPI":{const t=await this.unifiedOrder(e);if(!t.tradeNo)throw new Error("获取支付宝交易号失败,详细信息为:"+JSON.stringify(t));return t.tradeNo}case"NATIVE":return await this._request("alipay.trade.precreate",Object.assign({sellerId:this.options.mchId},e));default:throw new Error("不支持的支付类型,支付宝支付下单仅支持App、支付宝小程序、网站二维码支付")}}async orderQuery(e){return await this._request("alipay.trade.query",e)}async cancelOrder(e){return await this._request("alipay.trade.cancel",e)}async closeOrder(e){return await this._request("alipay.trade.close",e)}async refund(e){return await this._request("alipay.trade.refund",e)}async refundQuery(e){return await this._request("alipay.trade.fastpay.refund.query",e)}notifyRSACheck(e,t,r){const n=Object.keys(e).sort().filter(e=>e).map(t=>{let r=e[t];return"[object String]"!==Array.prototype.toString.call(r)&&(r=JSON.stringify(r)),`${t}=${r}`}).join("&");return i.default.createVerify(l[r]).update(n,"utf8").verify(this.config.alipayPublicKey,t,"base64")}_getNotifyData(e){if(!e.headers)throw new Error("通知格式不正确");let t;for(const r in e.headers)"content-type"===r.toLowerCase()&&(t=e.headers[r]);if(!1!==e.isBase64Encoded&&-1===t.indexOf("application/x-www-form-urlencoded"))throw new Error("通知格式不正确");return s.default.parse(e.body)}_verifyNotify(e){const t=this._getNotifyData(e);return!!this.checkNotifySign(t)&&(0,n.snake2camelJson)(t)}verifyPaymentNotify(e){return"payment"===this.checkNotifyType(e)&&this._verifyNotify(e)}verifyRefundNotify(e){return"refund"===this.checkNotifyType(e)&&this._verifyNotify(e)}checkNotifyType(e){return"refund_fee"in this._getNotifyData(e)?"refund":"payment"}}t.default=f,e.exports=t.default},function(e,t){e.exports=require("querystring")},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(5),i=r(22),s=r(0),a=r(23),o=r(24),u=r(25),c=r(27),l=r(28),f=r(7),h=r(8),p=r(36),d=r(44);t.default=class{constructor(e){if(!e.appId)throw Error("config.appId is required");if(!e.privateKey)throw Error("config.privateKey is required");const t="PKCS8"===e.keyType?"PRIVATE KEY":"RSA PRIVATE KEY";e.privateKey=this.formatKey(e.privateKey,t),e.appCertPath||e.appCertContent?(e.appCertSn=i.empty(e.appCertContent)?p.getSNFromPath(e.appCertPath,!1):p.getSN(e.appCertContent,!1),e.alipayCertSn=i.empty(e.alipayPublicCertContent)?p.getSNFromPath(e.alipayPublicCertPath,!1):p.getSN(e.alipayPublicCertContent,!1),e.alipayRootCertSn=i.empty(e.alipayRootCertContent)?p.getSNFromPath(e.alipayRootCertPath,!0):p.getSN(e.alipayRootCertContent,!0),e.alipayPublicKey=i.empty(e.alipayPublicCertContent)?p.loadPublicKeyFromPath(e.alipayPublicCertPath):p.loadPublicKey(e.alipayPublicCertContent),e.alipayPublicKey=this.formatKey(e.alipayPublicKey,"PUBLIC KEY")):e.alipayPublicKey&&(e.alipayPublicKey=this.formatKey(e.alipayPublicKey,"PUBLIC KEY")),this.config=Object.assign({urllib:a,gateway:"https://openapi.alipay.com/gateway.do",timeout:5e3,camelcase:!0,signType:"RSA2",charset:"utf-8",version:"1.0"},l(e,{deep:!0})),this.sdkVersion="alipay-sdk-nodejs-"+d.version}formatKey(e,t){const r=e.split("\n").map(e=>e.trim());return r[0].includes(t)&&r.shift(),r[r.length-1].includes(t)&&r.pop(),`-----BEGIN ${t}-----\n${r.join("")}\n-----END ${t}-----`}formatUrl(e,t){let r=e;const n=["app_id","method","format","charset","sign_type","sign","timestamp","version","notify_url","return_url","auth_token","app_auth_token","appCertSn","alipayRootCertSn"];for(const e in t)if(n.indexOf(e)>-1){const n=encodeURIComponent(t[e]);r=`${r}${r.includes("?")?"&":"?"}${e}=${n}`,delete t[e]}return{execParams:t,url:r}}multipartExec(e,t={}){const r=this.config;let s={},a={};const p=t.log&&i.fn(t.log.info)?t.log.info:null,d=t.log&&i.fn(t.log.error)?t.log.error:null;t.formData.getFields().forEach(e=>{s[e.name]=e.value,a[e.name]=e.value}),s=l(s,{deep:!0}),a=f(a),t.formData.getFiles().forEach(e=>{const t=c(e.fieldName);a[t]=u.isValid(e.path)?o(e.path):n.createReadStream(e.path)});const y=h.sign(e,s,r),{url:g}=this.formatUrl(r.gateway,y);return p&&p("[AlipaySdk]start exec url: %s, method: %s, params: %s",g,e,JSON.stringify(s)),new Promise((n,i)=>{o.post({url:g,formData:a,json:!1,timeout:r.timeout,headers:{"user-agent":this.sdkVersion}},(s,{},a)=>{s&&(s.message="[AlipaySdk]exec error",d&&d(s),i(s)),p&&p("[AlipaySdk]exec response: %s",a);const o=JSON.parse(a),u=e.replace(/\./g,"_")+"_response",c=o[u];if(c){!t.validateSign||this.checkResponseSign(a,u)?n(r.camelcase?l(c,{deep:!0}):c):i({serverResult:a,errorMessage:"[AlipaySdk]验签失败"})}i({serverResult:a,errorMessage:"[AlipaySdk]HTTP 请求错误"})})})}pageExec(e,t={}){let r={alipaySdk:this.sdkVersion};const n=this.config,s=t.log&&i.fn(t.log.info)?t.log.info:null;t.formData.getFields().forEach(e=>{r[e.name]=e.value}),r=l(r,{deep:!0});const a=h.sign(e,r,n),{url:o,execParams:u}=this.formatUrl(n.gateway,a);return s&&s("[AlipaySdk]start exec url: %s, method: %s, params: %s",o,e,JSON.stringify(r)),"get"===t.formData.getMethod()?new Promise(e=>{const t=Object.keys(u).map(e=>`${e}=${encodeURIComponent(u[e])}`);e(`${o}&${t.join("&")}`)}):new Promise(e=>{const t="alipaySDKSubmit"+Date.now();e(`\n
\n ${Object.keys(u).map(e=>``).join("")}\n
\n