gws-client 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(D,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(D=typeof globalThis<"u"?globalThis:D||self,b(D.GZCA={}))})(this,function(D){"use strict";var ne=Object.defineProperty;var se=(D,b,_)=>b in D?ne(D,b,{enumerable:!0,configurable:!0,writable:!0,value:_}):D[b]=_;var o=(D,b,_)=>se(D,typeof b!="symbol"?b+"":b,_);const b=window.location.href.includes("https")?"wss://localhost:19528":"ws://localhost:9527",_="1",Ct="2";var Y=(n=>(n[n.MIN=0]="MIN",n[n.LOW=1]="LOW",n[n.MIDDLE=2]="MIDDLE",n[n.HIGH=3]="HIGH",n))(Y||{});const vt="00000001";function kt(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var G={},tt;function xt(){if(tt)return G;tt=1,G.byteLength=u,G.toByteArray=h,G.fromByteArray=x;for(var n=[],t=[],e=typeof Uint8Array<"u"?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,r=s.length;a<r;++a)n[a]=s[a],t[s.charCodeAt(a)]=a;t[45]=62,t[95]=63;function c(i){var d=i.length;if(d%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var p=i.indexOf("=");p===-1&&(p=d);var C=p===d?0:4-p%4;return[p,C]}function u(i){var d=c(i),p=d[0],C=d[1];return(p+C)*3/4-C}function f(i,d,p){return(d+p)*3/4-p}function h(i){var d,p=c(i),C=p[0],y=p[1],g=new e(f(i,C,y)),v=0,A=y>0?C-4:C,m;for(m=0;m<A;m+=4)d=t[i.charCodeAt(m)]<<18|t[i.charCodeAt(m+1)]<<12|t[i.charCodeAt(m+2)]<<6|t[i.charCodeAt(m+3)],g[v++]=d>>16&255,g[v++]=d>>8&255,g[v++]=d&255;return y===2&&(d=t[i.charCodeAt(m)]<<2|t[i.charCodeAt(m+1)]>>4,g[v++]=d&255),y===1&&(d=t[i.charCodeAt(m)]<<10|t[i.charCodeAt(m+1)]<<4|t[i.charCodeAt(m+2)]>>2,g[v++]=d>>8&255,g[v++]=d&255),g}function w(i){return n[i>>18&63]+n[i>>12&63]+n[i>>6&63]+n[i&63]}function l(i,d,p){for(var C,y=[],g=d;g<p;g+=3)C=(i[g]<<16&16711680)+(i[g+1]<<8&65280)+(i[g+2]&255),y.push(w(C));return y.join("")}function x(i){for(var d,p=i.length,C=p%3,y=[],g=16383,v=0,A=p-C;v<A;v+=g)y.push(l(i,v,v+g>A?A:v+g));return C===1?(d=i[p-1],y.push(n[d>>2]+n[d<<4&63]+"==")):C===2&&(d=(i[p-2]<<8)+i[p-1],y.push(n[d>>10]+n[d>>4&63]+n[d<<2&63]+"=")),y.join("")}return G}var Dt=xt();const et=kt(Dt);class bt{constructor(){o(this,"deps",new Map)}on(t,e){this.deps.set(t,e)}emit(t,e){const s=this.deps.get(t);s&&s(e)}}(function(){try{var n=document.createElement("style");n.appendChild(document.createTextNode("button.svelte-n1zwga{background-color:transparent;border:none;padding:0;margin:0;font-family:inherit;font-size:inherit;color:inherit;cursor:pointer;outline:none}.modal-background.svelte-n1zwga{display:none;position:fixed;z-index:10000;left:0;top:0;width:100%;height:100%;background-color:#00000080;align-items:center;justify-content:center}.modal-content.svelte-n1zwga{background-color:#fff;padding:20px;border-radius:5px;width:40%}.model-title.svelte-n1zwga{color:#303133;font-size:18px;margin-bottom:16px}.modal-visible.svelte-n1zwga{display:flex}.modal-footer.svelte-n1zwga{display:flex;align-items:center;justify-content:flex-end;margin-top:16px}.modal-btn.svelte-n1zwga{padding:8px 15px;border-radius:4px;font-size:14px;border:1px solid #dcdfe6}.success.svelte-n1zwga{background-color:#409eff;margin-left:12px;color:#fff}.slot.svelte-n1zwga{max-height:200px;overflow-y:scroll}.slot.svelte-n1zwga::-webkit-scrollbar{display:none}.cert-item.svelte-jtc2v4.svelte-jtc2v4{padding:16px;display:flex;align-items:center;cursor:pointer;border-bottom:1px solid #ebeef5;font-size:14px}.cert-item-selected.svelte-jtc2v4.svelte-jtc2v4{background-color:#f1f1f1}.cert-item-first.svelte-jtc2v4.svelte-jtc2v4{border-top:1px solid #ebeef5}.cert-item.svelte-jtc2v4 span.svelte-jtc2v4{display:inline-block;color:#606266}.cert-item.svelte-jtc2v4 span.svelte-jtc2v4:first-child{width:30%}.seal-wrapper.svelte-1w19fs3.svelte-1w19fs3{display:flex;flex-direction:row;align-items:center;flex-wrap:wrap}.seal-item.svelte-1w19fs3.svelte-1w19fs3{width:180px;height:180px;display:flex;flex-direction:column;align-items:center;justify-content:center;border:1px solid #ccc;margin-top:10px;margin-right:10px;border-radius:4px}.seal-item.svelte-1w19fs3 img.svelte-1w19fs3{width:100px;height:100px}.seal-item-selected.svelte-1w19fs3.svelte-1w19fs3{background-color:#f1f1f1}.seal-name.svelte-1w19fs3.svelte-1w19fs3{margin-top:10px;color:#333}")),document.head.appendChild(n)}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();var Bt=Object.defineProperty,St=(n,t,e)=>t in n?Bt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,nt=(n,t,e)=>St(n,typeof t!="symbol"?t+"":t,e);function U(){}function $t(n,t){for(const e in t)n[e]=t[e];return n}function st(n){return n()}function at(){return Object.create(null)}function j(n){n.forEach(st)}function F(n){return typeof n=="function"}function rt(n,t){return n!=n?t==t:n!==t||n&&typeof n=="object"||typeof n=="function"}function It(n){return Object.keys(n).length===0}function At(n,t,e,s){if(n){const a=ot(n,t,e,s);return n[0](a)}}function ot(n,t,e,s){return n[1]&&s?$t(e.ctx.slice(),n[1](s(t))):e.ctx}function Et(n,t,e,s){if(n[2]&&s){const a=n[2](s(e));if(t.dirty===void 0)return a;if(typeof a=="object"){const r=[],c=Math.max(t.dirty.length,a.length);for(let u=0;u<c;u+=1)r[u]=t.dirty[u]|a[u];return r}return t.dirty|a}return t.dirty}function _t(n,t,e,s,a,r){if(a){const c=ot(t,e,s,r);n.p(c,a)}}function Lt(n){if(n.ctx.length>32){const t=[],e=n.ctx.length/32;for(let s=0;s<e;s++)t[s]=-1;return t}return-1}function ct(n){return n??""}function k(n,t){n.appendChild(t)}function J(n,t,e){n.insertBefore(t,e||null)}function z(n){n.parentNode&&n.parentNode.removeChild(n)}function Pt(n,t){for(let e=0;e<n.length;e+=1)n[e]&&n[e].d(t)}function S(n){return document.createElement(n)}function $(n){return document.createTextNode(n)}function O(){return $(" ")}function Tt(){return $("")}function Z(n,t,e,s){return n.addEventListener(t,e,s),()=>n.removeEventListener(t,e,s)}function B(n,t,e){e==null?n.removeAttribute(t):n.getAttribute(t)!==e&&n.setAttribute(t,e)}function Mt(n){return Array.from(n.childNodes)}function L(n,t){t=""+t,n.data!==t&&(n.data=t)}let q;function N(n){q=n}const P=[],it=[];let T=[];const lt=[],Ht=Promise.resolve();let K=!1;function Gt(){K||(K=!0,Ht.then(dt))}function W(n){T.push(n)}const Q=new Set;let M=0;function dt(){if(M!==0)return;const n=q;do{try{for(;M<P.length;){const t=P[M];M++,N(t),jt(t.$$)}}catch(t){throw P.length=0,M=0,t}for(N(null),P.length=0,M=0;it.length;)it.pop()();for(let t=0;t<T.length;t+=1){const e=T[t];Q.has(e)||(Q.add(e),e())}T.length=0}while(P.length);for(;lt.length;)lt.pop()();K=!1,Q.clear(),N(n)}function jt(n){if(n.fragment!==null){n.update(),j(n.before_update);const t=n.dirty;n.dirty=[-1],n.fragment&&n.fragment.p(n.ctx,t),n.after_update.forEach(W)}}function Ft(n){const t=[],e=[];T.forEach(s=>n.indexOf(s)===-1?t.push(s):e.push(s)),e.forEach(s=>s()),T=t}const V=new Set;let Ot;function X(n,t){n&&n.i&&(V.delete(n),n.i(t))}function ut(n,t,e,s){if(n&&n.o){if(V.has(n))return;V.add(n),Ot.c.push(()=>{V.delete(n)}),n.o(t)}}function ht(n){return(n==null?void 0:n.length)!==void 0?n:Array.from(n)}function Zt(n){n&&n.c()}function pt(n,t,e){const{fragment:s,after_update:a}=n.$$;s&&s.m(t,e),W(()=>{const r=n.$$.on_mount.map(st).filter(F);n.$$.on_destroy?n.$$.on_destroy.push(...r):j(r),n.$$.on_mount=[]}),a.forEach(W)}function gt(n,t){const e=n.$$;e.fragment!==null&&(Ft(e.after_update),j(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Nt(n,t){n.$$.dirty[0]===-1&&(P.push(n),Gt(),n.$$.dirty.fill(0)),n.$$.dirty[t/31|0]|=1<<t%31}function ft(n,t,e,s,a,r,c=null,u=[-1]){const f=q;N(n);const h=n.$$={fragment:null,ctx:[],props:r,update:U,not_equal:a,bound:at(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(f?f.$$.context:[])),callbacks:at(),dirty:u,skip_bound:!1,root:t.target||f.$$.root};c&&c(h.root);let w=!1;if(h.ctx=e?e(n,t.props||{},(l,x,...i)=>{const d=i.length?i[0]:x;return h.ctx&&a(h.ctx[l],h.ctx[l]=d)&&(!h.skip_bound&&h.bound[l]&&h.bound[l](d),w&&Nt(n,l)),x}):[],h.update(),w=!0,j(h.before_update),h.fragment=s?s(h.ctx):!1,t.target){if(t.hydrate){const l=Mt(t.target);h.fragment&&h.fragment.l(l),l.forEach(z)}else h.fragment&&h.fragment.c();t.intro&&X(n.$$.fragment),pt(n,t.target,t.anchor),dt()}N(f)}class yt{constructor(){nt(this,"$$"),nt(this,"$$set")}$destroy(){gt(this,1),this.$destroy=U}$on(t,e){if(!F(e))return U;const s=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return s.push(e),()=>{const a=s.indexOf(e);a!==-1&&s.splice(a,1)}}$set(t){this.$$set&&!It(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const zt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(zt);function Vt(n){let t,e,s,a=(n[1]||"标题")+"",r,c,u,f,h,w,l=(n[4]||"取消")+"",x,i,d,p=(n[5]||"确认")+"",C,y,g,v;const A=n[7].default,m=At(A,n,n[6],null);return{c(){t=S("div"),e=S("div"),s=S("div"),r=$(a),c=O(),u=S("div"),m&&m.c(),f=O(),h=S("div"),w=S("button"),x=$(l),i=O(),d=S("button"),C=$(p),B(s,"class","model-title svelte-n1zwga"),B(u,"class","slot svelte-n1zwga"),B(w,"class","modal-btn svelte-n1zwga"),B(d,"class","modal-btn success svelte-n1zwga"),B(h,"class","modal-footer svelte-n1zwga"),B(e,"class","modal-content svelte-n1zwga"),B(t,"class","modal-background modal-visible svelte-n1zwga")},m(I,E){J(I,t,E),k(t,e),k(e,s),k(s,r),k(e,c),k(e,u),m&&m.m(u,null),k(e,f),k(e,h),k(h,w),k(w,x),k(h,i),k(h,d),k(d,C),y=!0,g||(v=[Z(w,"click",function(){F(n[0])&&n[0].apply(this,arguments)}),Z(d,"click",function(){F(n[2])&&n[2].apply(this,arguments)}),Z(e,"click",Rt),Z(t,"click",function(){F(n[3])&&n[3].apply(this,arguments)})],g=!0)},p(I,[E]){n=I,(!y||E&2)&&a!==(a=(n[1]||"标题")+"")&&L(r,a),m&&m.p&&(!y||E&64)&&_t(m,A,n,n[6],y?Et(A,n[6],E,null):Lt(n[6]),null),(!y||E&16)&&l!==(l=(n[4]||"取消")+"")&&L(x,l),(!y||E&32)&&p!==(p=(n[5]||"确认")+"")&&L(C,p)},i(I){y||(X(m,I),y=!0)},o(I){ut(m,I),y=!1},d(I){I&&z(t),m&&m.d(I),g=!1,j(v)}}}const Rt=n=>n.stopPropagation();function Ut(n,t,e){let{$$slots:s={},$$scope:a}=t,{onCancel:r}=t,{title:c}=t,{onOk:u}=t,{onClose:f}=t,{cancelText:h}=t,{okText:w}=t;return n.$$set=l=>{"onCancel"in l&&e(0,r=l.onCancel),"title"in l&&e(1,c=l.title),"onOk"in l&&e(2,u=l.onOk),"onClose"in l&&e(3,f=l.onClose),"cancelText"in l&&e(4,h=l.cancelText),"okText"in l&&e(5,w=l.okText),"$$scope"in l&&e(6,a=l.$$scope)},[r,c,u,f,h,w,a,s]}class Jt extends yt{constructor(t){super(),ft(this,t,Ut,Vt,rt,{onCancel:0,title:1,onOk:2,onClose:3,cancelText:4,okText:5})}}function mt(n,t,e){const s=n.slice();return s[10]=t[e],s[12]=e,s}function wt(n){let t,e,s=n[10].CN+"",a,r,c,u=n[10].DevClass+"",f,h,w=n[10].sn+"",l,x,i,d,p,C;function y(){return n[9](n[12])}return{c(){t=S("div"),e=S("span"),a=$(s),r=O(),c=S("span"),f=$(u),h=$("("),l=$(w),x=$(")"),i=O(),B(e,"class","svelte-jtc2v4"),B(c,"class","svelte-jtc2v4"),B(t,"class",d=ct(`cert-item ${n[12]===0?"cert-item-first":""} ${n[12]===n[4]?"cert-item-selected":""}`)+" svelte-jtc2v4")},m(g,v){J(g,t,v),k(t,e),k(e,a),k(t,r),k(t,c),k(c,f),k(c,h),k(c,l),k(c,x),k(t,i),p||(C=Z(t,"click",y),p=!0)},p(g,v){n=g,v&1&&s!==(s=n[10].CN+"")&&L(a,s),v&1&&u!==(u=n[10].DevClass+"")&&L(f,u),v&1&&w!==(w=n[10].sn+"")&&L(l,w),v&16&&d!==(d=ct(`cert-item ${n[12]===0?"cert-item-first":""} ${n[12]===n[4]?"cert-item-selected":""}`)+" svelte-jtc2v4")&&B(t,"class",d)},d(g){g&&z(t),p=!1,C()}}}function qt(n){let t,e=ht(n[0]),s=[];for(let a=0;a<e.length;a+=1)s[a]=wt(mt(n,e,a));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=Tt()},m(a,r){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(a,r);J(a,t,r)},p(a,r){if(r&17){e=ht(a[0]);let c;for(c=0;c<e.length;c+=1){const u=mt(a,e,c);s[c]?s[c].p(u,r):(s[c]=wt(u),s[c].c(),s[c].m(t.parentNode,t))}for(;c<s.length;c+=1)s[c].d(1);s.length=e.length}},d(a){a&&z(t),Pt(s,a)}}}function Kt(n){let t,e;return t=new Jt({props:{onOk:n[6],onClose:n[1],onCancel:n[5],cancelText:n[2],okText:n[3],title:"选择证书",$$slots:{default:[qt]},$$scope:{ctx:n}}}),{c(){Zt(t.$$.fragment)},m(s,a){pt(t,s,a),e=!0},p(s,[a]){const r={};a&2&&(r.onClose=s[1]),a&4&&(r.cancelText=s[2]),a&8&&(r.okText=s[3]),a&8209&&(r.$$scope={dirty:a,ctx:s}),t.$set(r)},i(s){e||(X(t.$$.fragment,s),e=!0)},o(s){ut(t.$$.fragment,s),e=!1},d(s){gt(t,s)}}}function Wt(n,t,e){let{certList:s=[]}=t,{onCancel:a}=t,{onOk:r}=t,{onClose:c}=t,{cancelText:u=""}=t,{okText:f=""}=t,h=0;const w=()=>{c==null||c()},l=()=>{r==null||r(s[h]),c==null||c()},x=i=>e(4,h=i);return n.$$set=i=>{"certList"in i&&e(0,s=i.certList),"onCancel"in i&&e(7,a=i.onCancel),"onOk"in i&&e(8,r=i.onOk),"onClose"in i&&e(1,c=i.onClose),"cancelText"in i&&e(2,u=i.cancelText),"okText"in i&&e(3,f=i.okText)},[s,c,u,f,h,w,l,a,r,x]}class Qt extends yt{constructor(t){super(),ft(this,t,Wt,Kt,rt,{certList:0,onCancel:7,onOk:8,onClose:1,cancelText:2,okText:3})}}class Xt{constructor(){o(this,"modalInstance",{current:null});o(this,"open",t=>new Promise((e,s)=>{this.modalInstance.current=new Qt({target:document.body,props:{...t,onCancel:a=>{s()},onOk:a=>{e(a)},onClose:()=>{this.close()}}})}));o(this,"close",()=>{setTimeout(()=>{var t;(t=this.modalInstance.current)==null||t.$destroy()})})}}const Yt=new Xt;class te{constructor(t){o(this,"socketInstance",null);o(this,"eventBus",new bt);o(this,"isRememberPin",!1);o(this,"socketEvent");o(this,"pinPolicy");o(this,"socketConfig",null);o(this,"getSocketReadyState",()=>{var t;return(t=this.socketInstance)==null?void 0:t.readyState});o(this,"destroy",()=>{var t;(t=this.socketInstance)==null||t.close()});o(this,"sendMessage",(t,e)=>new Promise((s,a)=>{var c,u;if(((c=this.socketInstance)==null?void 0:c.readyState)!==WebSocket.OPEN){console.log(t),a({errCode:-1,msg:"socket未连接"});return}const r={function:t,args:[e??{}]};(u=this.socketInstance)==null||u.send(JSON.stringify(r)),this.eventBus.on(t,f=>{f.success?s(f.data):a(f)})}));o(this,"handleEventData",async t=>{var e,s,a,r,c,u;if(t.data instanceof Blob){const f=await t.data.arrayBuffer(),w=new TextDecoder("gbk").decode(f),l=JSON.parse(w),x={data:l.data,success:(e=l.result)==null?void 0:e.success,msg:(s=l.result)==null?void 0:s.msg,errCode:(a=l.result)==null?void 0:a.errCode};this.eventBus.emit((r=l.result)==null?void 0:r.function,x),(u=(c=this.socketConfig)==null?void 0:c.onMessage)==null||u.call(c,x)}});o(this,"base64Encode",t=>{const e=new TextEncoder().encode(t);return et.fromByteArray(e)});o(this,"base64Decode",t=>{const e=et.toByteArray(t);return new TextDecoder().decode(e)});o(this,"changeIsRememberPin",async t=>{this.isRememberPin=t});o(this,"changePinPolicy",async t=>{this.pinPolicy=t});o(this,"checkCertIsLogin",async t=>await this.sendMessage("GZCA_IsLogin",t));o(this,"addUkeyEvents",async()=>{this.sendMessage("GZCA_StartListen",{Type:vt}).then(t=>{var e,s;(s=(e=this.socketConfig)==null?void 0:e.onUkeyEvent)==null||s.call(e,t)})});o(this,"certLogin",async t=>{const e=await this.checkCertIsLogin({ContainerName:t});e!=null&&e[0].isLogin||await this.sendMessage("GZCA_Login",{ContainerName:t,IsLogin:"N",UserPin:"123456",PinPolicy:this.pinPolicy})});o(this,"getCert",async(t,e)=>{const s=e??await this.chooseCert(t);return await this.certLogin(s.ContainerName),s});o(this,"getCertList",async t=>await this.sendMessage("GZCA_GetCertList",t));o(this,"chooseCert",async t=>{const e=await this.getCertList(t);return(e==null?void 0:e.length)===1?e[0]:await Yt.open({certList:e})});o(this,"pkcs1Sign",async t=>await this.sendMessage("GZCA_Pkcs1SignData",{...t,IsLogin:this.getIsLogin(),PinPolicy:this.pinPolicy}));o(this,"pkcs1Base64Sign",async t=>await this.sendMessage("GZCA_Pkcs1SignDataEx",{...t,IsLogin:this.getIsLogin(),PinPolicy:this.pinPolicy}));o(this,"pkcs1VerifySignature",async t=>await this.sendMessage("GZCA_Pkcs1VerifySign",t));o(this,"pkcs1Base64VerifySignature",async t=>await this.sendMessage("GZCA_Pkcs1VerifySignEx",t));o(this,"getSealList",async t=>await this.sendMessage("GZCA_EnumSeals",{...t,IsLogin:this.getIsLogin()}));o(this,"sm2SignPreprocess1",async t=>await this.sendMessage("GZCA_PrepareSm2SignStep1",t));o(this,"sm2SignPreprocess2",async t=>await this.sendMessage("GZCA_PrepareSm2SignStep2",t));o(this,"pkcs1HashSign",async t=>await this.sendMessage("GZCA_Pkcs1SignDataForHash",{...t??{},IsLogin:this.getIsLogin(),PinPolicy:this.pinPolicy}));o(this,"pkcs1HashVerifySignature",async t=>await this.sendMessage("GZCA_Pkcs1VerifySignForHash",t));o(this,"pkcs7Sign",async t=>await this.sendMessage("GZCA_Pkcs7SignData",{...t,IsLogin:this.getIsLogin(),IsAuthAttr:"Y",PinPolicy:this.pinPolicy}));o(this,"pkcs7VerifySignature",async t=>await this.sendMessage("GZCA_Pkcs7VerifySign",t));o(this,"sm3Hash",async t=>await this.sendMessage("GZCA_HashData",t));o(this,"sm3HexHash",async t=>await this.sendMessage("GZCA_HashDataEx",t));o(this,"sm3FileHash",async t=>await this.sendMessage("GZCA_HashFile",t));o(this,"sm3HashEncryption",async t=>await this.sendMessage("GZCA_HMac",t));o(this,"pkcs7Encryption",async t=>await this.sendMessage("GZCA_Pkcs7EncryptData",t));o(this,"pkcs7Decryption",async t=>await this.sendMessage("GZCA_Pkcs7DecryptData",{...t,IsLogin:this.getIsLogin()}));o(this,"asymmetricEncryption",async t=>await this.sendMessage("GZCA_AsymEncryptData",t));o(this,"asymmetricDecryption",async t=>await this.sendMessage("GZCA_AsymDecryptData",{...t,IsLogin:this.getIsLogin()}));o(this,"sm4Encryption",async t=>await this.sendMessage("GZCA_EncryptDataEx",t));o(this,"sm4Decryption",async t=>await this.sendMessage("GZCA_DecryptDataEx",t));o(this,"getCertInfo",async t=>await this.sendMessage("GZCA_GetCertInfo",t));o(this,"getCertInfoByOid",async t=>await this.sendMessage("GZCA_GetCertInfoByOid",t));this.socketConfig=t,this.socketInstance=this.createSocket(t),this.isRememberPin=t.isRememberPin??!1,this.pinPolicy=t.pinPolicy??Y.MIN}createSocket(t){const e=new WebSocket(t.url);return e.onerror=s=>{var a;(a=t.onError)==null||a.call(t,s)},e.onopen=s=>{var a;(a=t.onOpen)==null||a.call(t,s),this.addUkeyEvents()},e.onmessage=s=>{this.handleEventData(s)},e.onclose=s=>{var a;(a=t.onClose)==null||a.call(t,s)},e}getIsLogin(){return this.isRememberPin?"Y":"N"}}const H=class H{constructor(t){o(this,"coreInstance",null);o(this,"gwsConfig",{});o(this,"createGwsCore",t=>{this.gwsConfig=t??{},this.coreInstance=new te({...t??{},url:b})});o(this,"appendCertBase64",async(t,e=!0)=>{if(t.CertB64)return t;const s=e?await this.getSignatureCert():await this.getEncryptionCert();return{...t??{},CertB64:s==null?void 0:s.CertB64}});o(this,"destroy",()=>{var t;(t=this.coreInstance)==null||t.destroy(),this.coreInstance=null});o(this,"restart",t=>{this.coreInstance&&this.destroy(),this.gwsConfig=t??this.gwsConfig,this.createGwsCore(t)});o(this,"getSocketReadyState",()=>{var t;return(t=this.coreInstance)==null?void 0:t.getSocketReadyState()});o(this,"getSignatureCert",async t=>{var s;return await((s=this.coreInstance)==null?void 0:s.getCert({CertType:_},t))});o(this,"getEncryptionCert",async t=>{var s;return await((s=this.coreInstance)==null?void 0:s.getCert({CertType:Ct},t))});o(this,"base64Encode",t=>{var e;return(e=this.coreInstance)==null?void 0:e.base64Encode(t.Data)});o(this,"base64Decode",t=>{var e;return(e=this.coreInstance)==null?void 0:e.base64Decode(t.DataB64)});o(this,"changeIsRememberPin",t=>{var e;(e=this.coreInstance)==null||e.changeIsRememberPin(t)});o(this,"changePinPolicy",t=>{var e;(e=this.coreInstance)==null||e.changePinPolicy(t)});o(this,"pkcs1Sign",async(t,e)=>{var r,c;const s=await this.getSignatureCert(e),a=await((r=this.coreInstance)==null?void 0:r.pkcs1Sign({...t??{},ContainerName:(s==null?void 0:s.ContainerName)??""}));return(c=a==null?void 0:a[0])==null?void 0:c.SignData});o(this,"pkcs1VerifySignature",async t=>{var a;const e=await this.appendCertBase64(t),s=await((a=this.coreInstance)==null?void 0:a.pkcs1VerifySignature(e));return Array.isArray(s)});o(this,"pkcs1Base64Sign",async(t,e)=>{var c,u;const s=await this.getSignatureCert(e),a=t.DataB64??this.base64Encode({Data:t.Data??""}),r=await((c=this.coreInstance)==null?void 0:c.pkcs1Base64Sign({ContainerName:(s==null?void 0:s.ContainerName)??"",DataB64:a}));return(u=r==null?void 0:r[0])==null?void 0:u.SignData});o(this,"pkcs1Base64VerifySignature",async t=>{var r;const e=t.DataB64??this.base64Encode({Data:t.Data??""}),s=await this.appendCertBase64(t);return!!await((r=this.coreInstance)==null?void 0:r.pkcs1Base64VerifySignature({CertB64:s.CertB64,DataB64:e,SignData:s.SignData}))});o(this,"getSealList",async()=>{var s;const t=await this.getSignatureCert(),e=await((s=this.coreInstance)==null?void 0:s.getSealList({ContainerName:(t==null?void 0:t.ContainerName)??""}));return{cert:t,sealList:e}});o(this,"sm2SignPreprocess1",async t=>{var a,r;const e=await this.appendCertBase64(t),s=await((a=this.coreInstance)==null?void 0:a.sm2SignPreprocess1(e));return(r=s==null?void 0:s[0])==null?void 0:r.Z});o(this,"sm2SignPreprocess2",async t=>{var r;const e=this.base64Encode({Data:t.Data??""}),s=await this.appendCertBase64(t),a=await((r=this.coreInstance)==null?void 0:r.sm2SignPreprocess2({CertB64:s.CertB64,DataB64:e}));return a==null?void 0:a[0].H});o(this,"pkcs1HashSign",async(t,e)=>{var r,c;const s=await this.getSignatureCert(e),a=await((r=this.coreInstance)==null?void 0:r.pkcs1HashSign({ContainerName:(s==null?void 0:s.ContainerName)??"",DataB64:t.DataB64,HashAlg:t.HashAlg??"sm3"}));return(c=a==null?void 0:a[0])==null?void 0:c.SignData});o(this,"pkcs1HashVerifySignature",async t=>{var a;const e=await this.appendCertBase64(t);return!!await((a=this.coreInstance)==null?void 0:a.pkcs1HashVerifySignature({...e,HashAlg:e.HashAlg??"sm3"}))});o(this,"pkcs7Sign",async(t,e)=>{var c,u;const s=t.DataB64??this.base64Encode({Data:t.Data??""}),a=await this.getSignatureCert(e),r=await((c=this.coreInstance)==null?void 0:c.pkcs7Sign({IsDetached:t.IsDetached,ContainerName:(a==null?void 0:a.ContainerName)??"",DataB64:s}));return(u=r==null?void 0:r[0])==null?void 0:u.SignData});o(this,"pkcs7VerifySignature",async t=>{var a;const e=t.DataB64??this.base64Encode({Data:t.Data??""});return!!await((a=this.coreInstance)==null?void 0:a.pkcs7VerifySignature({DataB64:e,SignData:t.SignData}))});o(this,"sm3Hash",async t=>{var s,a;const e=await((s=this.coreInstance)==null?void 0:s.sm3Hash(t));return(a=e==null?void 0:e[0])==null?void 0:a.HashB64});o(this,"sm3HexHash",async t=>{var s,a;const e=await((s=this.coreInstance)==null?void 0:s.sm3HexHash(t));return(a=e==null?void 0:e[0])==null?void 0:a.HashB64});o(this,"sm3FileHash",async t=>{var s,a;const e=await((s=this.coreInstance)==null?void 0:s.sm3FileHash(t));return(a=e==null?void 0:e[0])==null?void 0:a.HashB64});o(this,"sm3HashEncryption",async t=>{var r,c;const e=t.DataB64??this.base64Encode({Data:t.Data??""}),s=t.KeyB64??this.base64Encode({Data:t.Key??""}),a=await((r=this.coreInstance)==null?void 0:r.sm3HashEncryption({dataB64:e,keyB64:s,alg:"sm3"}));return(c=a==null?void 0:a[0])==null?void 0:c.DataB64});o(this,"pkcs7Encryption",async t=>{var a,r;if(!t.CertB64List){const c=await this.getEncryptionCert();t.CertB64List=c==null?void 0:c.CertB64}const e=t.DataB64??this.base64Encode({Data:t.Data??""}),s=await((a=this.coreInstance)==null?void 0:a.pkcs7Encryption({DataB64:e,CertB64List:t.CertB64List}));return(r=s==null?void 0:s[0])==null?void 0:r.DataB64});o(this,"pkcs7Decryption",async t=>{var r,c;const e=await this.getEncryptionCert(),s=await((r=this.coreInstance)==null?void 0:r.pkcs7Decryption({DataB64:t.DataB64,ContainerName:e==null?void 0:e.ContainerName})),a=(c=s==null?void 0:s[0])==null?void 0:c.DataB64;return t.shouldDecodeBase64?this.base64Decode({DataB64:a}):a});o(this,"asymmetricEncryption",async t=>{var a,r;const e=await this.appendCertBase64(t,!1),s=await((a=this.coreInstance)==null?void 0:a.asymmetricEncryption(e));return(r=s==null?void 0:s[0])==null?void 0:r.Data});o(this,"asymmetricDecryption",async t=>{var a,r;const e=await this.getEncryptionCert(),s=await((a=this.coreInstance)==null?void 0:a.asymmetricDecryption({Data:t.Data,ContainerName:e==null?void 0:e.ContainerName}));return(r=s==null?void 0:s[0])==null?void 0:r.Data});o(this,"sm4Encryption",async t=>{var s;const e=await((s=this.coreInstance)==null?void 0:s.sm4Encryption(t));return e==null?void 0:e[0]});o(this,"sm4Decryption",async t=>{var s,a;const e=await((s=this.coreInstance)==null?void 0:s.sm4Decryption(t));return(a=e==null?void 0:e[0])==null?void 0:a.Data});o(this,"getCertInfo",async t=>{var s;const e=await((s=this.coreInstance)==null?void 0:s.getCertInfo(t));return{...(e==null?void 0:e[0])??{}}});o(this,"getCertInfoByOid",async t=>{var s,a;const e=await((s=this.coreInstance)==null?void 0:s.getCertInfoByOid({...t??{}}));return(a=e==null?void 0:e[0])==null?void 0:a.OidValue});return H.instance&&!(t!=null&&t.isCreateNew)?H.instance:(this.createGwsCore(t),H.instance=this,this)}};o(H,"instance",null);let R=H;function ee(n){return new Promise((t,e)=>{const s=new R({...n??{},onOpen(a){var r;t(s),(r=n==null?void 0:n.onOpen)==null||r.call(n,a)},onClose(a){var r;e(a),(r=n==null?void 0:n.onClose)==null||r.call(n,a)}})})}D.GwsService=R,D.createService=ee,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
1
+ (function(D,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(D=typeof globalThis<"u"?globalThis:D||self,b(D.GWS_CLIENT={}))})(this,function(D){"use strict";var ne=Object.defineProperty;var se=(D,b,_)=>b in D?ne(D,b,{enumerable:!0,configurable:!0,writable:!0,value:_}):D[b]=_;var o=(D,b,_)=>se(D,typeof b!="symbol"?b+"":b,_);const b=window.location.href.includes("https")?"wss://localhost:19528":"ws://localhost:9527",_="1",Ct="2";var Y=(n=>(n[n.MIN=0]="MIN",n[n.LOW=1]="LOW",n[n.MIDDLE=2]="MIDDLE",n[n.HIGH=3]="HIGH",n))(Y||{});const vt="00000001";function kt(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var G={},tt;function xt(){if(tt)return G;tt=1,G.byteLength=u,G.toByteArray=h,G.fromByteArray=x;for(var n=[],t=[],e=typeof Uint8Array<"u"?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,r=s.length;a<r;++a)n[a]=s[a],t[s.charCodeAt(a)]=a;t[45]=62,t[95]=63;function c(i){var d=i.length;if(d%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var p=i.indexOf("=");p===-1&&(p=d);var C=p===d?0:4-p%4;return[p,C]}function u(i){var d=c(i),p=d[0],C=d[1];return(p+C)*3/4-C}function f(i,d,p){return(d+p)*3/4-p}function h(i){var d,p=c(i),C=p[0],y=p[1],g=new e(f(i,C,y)),v=0,E=y>0?C-4:C,m;for(m=0;m<E;m+=4)d=t[i.charCodeAt(m)]<<18|t[i.charCodeAt(m+1)]<<12|t[i.charCodeAt(m+2)]<<6|t[i.charCodeAt(m+3)],g[v++]=d>>16&255,g[v++]=d>>8&255,g[v++]=d&255;return y===2&&(d=t[i.charCodeAt(m)]<<2|t[i.charCodeAt(m+1)]>>4,g[v++]=d&255),y===1&&(d=t[i.charCodeAt(m)]<<10|t[i.charCodeAt(m+1)]<<4|t[i.charCodeAt(m+2)]>>2,g[v++]=d>>8&255,g[v++]=d&255),g}function w(i){return n[i>>18&63]+n[i>>12&63]+n[i>>6&63]+n[i&63]}function l(i,d,p){for(var C,y=[],g=d;g<p;g+=3)C=(i[g]<<16&16711680)+(i[g+1]<<8&65280)+(i[g+2]&255),y.push(w(C));return y.join("")}function x(i){for(var d,p=i.length,C=p%3,y=[],g=16383,v=0,E=p-C;v<E;v+=g)y.push(l(i,v,v+g>E?E:v+g));return C===1?(d=i[p-1],y.push(n[d>>2]+n[d<<4&63]+"==")):C===2&&(d=(i[p-2]<<8)+i[p-1],y.push(n[d>>10]+n[d>>4&63]+n[d<<2&63]+"=")),y.join("")}return G}var Dt=xt();const et=kt(Dt);class bt{constructor(){o(this,"deps",new Map)}on(t,e){this.deps.set(t,e)}emit(t,e){const s=this.deps.get(t);s&&s(e)}}(function(){try{var n=document.createElement("style");n.appendChild(document.createTextNode("button.svelte-n1zwga{background-color:transparent;border:none;padding:0;margin:0;font-family:inherit;font-size:inherit;color:inherit;cursor:pointer;outline:none}.modal-background.svelte-n1zwga{display:none;position:fixed;z-index:10000;left:0;top:0;width:100%;height:100%;background-color:#00000080;align-items:center;justify-content:center}.modal-content.svelte-n1zwga{background-color:#fff;padding:20px;border-radius:5px;width:40%}.model-title.svelte-n1zwga{color:#303133;font-size:18px;margin-bottom:16px}.modal-visible.svelte-n1zwga{display:flex}.modal-footer.svelte-n1zwga{display:flex;align-items:center;justify-content:flex-end;margin-top:16px}.modal-btn.svelte-n1zwga{padding:8px 15px;border-radius:4px;font-size:14px;border:1px solid #dcdfe6}.success.svelte-n1zwga{background-color:#409eff;margin-left:12px;color:#fff}.slot.svelte-n1zwga{max-height:200px;overflow-y:scroll}.slot.svelte-n1zwga::-webkit-scrollbar{display:none}.cert-item.svelte-jtc2v4.svelte-jtc2v4{padding:16px;display:flex;align-items:center;cursor:pointer;border-bottom:1px solid #ebeef5;font-size:14px}.cert-item-selected.svelte-jtc2v4.svelte-jtc2v4{background-color:#f1f1f1}.cert-item-first.svelte-jtc2v4.svelte-jtc2v4{border-top:1px solid #ebeef5}.cert-item.svelte-jtc2v4 span.svelte-jtc2v4{display:inline-block;color:#606266}.cert-item.svelte-jtc2v4 span.svelte-jtc2v4:first-child{width:30%}.seal-wrapper.svelte-1w19fs3.svelte-1w19fs3{display:flex;flex-direction:row;align-items:center;flex-wrap:wrap}.seal-item.svelte-1w19fs3.svelte-1w19fs3{width:180px;height:180px;display:flex;flex-direction:column;align-items:center;justify-content:center;border:1px solid #ccc;margin-top:10px;margin-right:10px;border-radius:4px}.seal-item.svelte-1w19fs3 img.svelte-1w19fs3{width:100px;height:100px}.seal-item-selected.svelte-1w19fs3.svelte-1w19fs3{background-color:#f1f1f1}.seal-name.svelte-1w19fs3.svelte-1w19fs3{margin-top:10px;color:#333}")),document.head.appendChild(n)}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();var Bt=Object.defineProperty,St=(n,t,e)=>t in n?Bt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,nt=(n,t,e)=>St(n,typeof t!="symbol"?t+"":t,e);function U(){}function $t(n,t){for(const e in t)n[e]=t[e];return n}function st(n){return n()}function at(){return Object.create(null)}function j(n){n.forEach(st)}function F(n){return typeof n=="function"}function rt(n,t){return n!=n?t==t:n!==t||n&&typeof n=="object"||typeof n=="function"}function It(n){return Object.keys(n).length===0}function Et(n,t,e,s){if(n){const a=ot(n,t,e,s);return n[0](a)}}function ot(n,t,e,s){return n[1]&&s?$t(e.ctx.slice(),n[1](s(t))):e.ctx}function At(n,t,e,s){if(n[2]&&s){const a=n[2](s(e));if(t.dirty===void 0)return a;if(typeof a=="object"){const r=[],c=Math.max(t.dirty.length,a.length);for(let u=0;u<c;u+=1)r[u]=t.dirty[u]|a[u];return r}return t.dirty|a}return t.dirty}function _t(n,t,e,s,a,r){if(a){const c=ot(t,e,s,r);n.p(c,a)}}function Lt(n){if(n.ctx.length>32){const t=[],e=n.ctx.length/32;for(let s=0;s<e;s++)t[s]=-1;return t}return-1}function ct(n){return n??""}function k(n,t){n.appendChild(t)}function J(n,t,e){n.insertBefore(t,e||null)}function z(n){n.parentNode&&n.parentNode.removeChild(n)}function Pt(n,t){for(let e=0;e<n.length;e+=1)n[e]&&n[e].d(t)}function S(n){return document.createElement(n)}function $(n){return document.createTextNode(n)}function O(){return $(" ")}function Tt(){return $("")}function N(n,t,e,s){return n.addEventListener(t,e,s),()=>n.removeEventListener(t,e,s)}function B(n,t,e){e==null?n.removeAttribute(t):n.getAttribute(t)!==e&&n.setAttribute(t,e)}function Mt(n){return Array.from(n.childNodes)}function L(n,t){t=""+t,n.data!==t&&(n.data=t)}let W;function Z(n){W=n}const P=[],it=[];let T=[];const lt=[],Ht=Promise.resolve();let q=!1;function Gt(){q||(q=!0,Ht.then(dt))}function K(n){T.push(n)}const Q=new Set;let M=0;function dt(){if(M!==0)return;const n=W;do{try{for(;M<P.length;){const t=P[M];M++,Z(t),jt(t.$$)}}catch(t){throw P.length=0,M=0,t}for(Z(null),P.length=0,M=0;it.length;)it.pop()();for(let t=0;t<T.length;t+=1){const e=T[t];Q.has(e)||(Q.add(e),e())}T.length=0}while(P.length);for(;lt.length;)lt.pop()();q=!1,Q.clear(),Z(n)}function jt(n){if(n.fragment!==null){n.update(),j(n.before_update);const t=n.dirty;n.dirty=[-1],n.fragment&&n.fragment.p(n.ctx,t),n.after_update.forEach(K)}}function Ft(n){const t=[],e=[];T.forEach(s=>n.indexOf(s)===-1?t.push(s):e.push(s)),e.forEach(s=>s()),T=t}const V=new Set;let Ot;function X(n,t){n&&n.i&&(V.delete(n),n.i(t))}function ut(n,t,e,s){if(n&&n.o){if(V.has(n))return;V.add(n),Ot.c.push(()=>{V.delete(n)}),n.o(t)}}function ht(n){return(n==null?void 0:n.length)!==void 0?n:Array.from(n)}function Nt(n){n&&n.c()}function pt(n,t,e){const{fragment:s,after_update:a}=n.$$;s&&s.m(t,e),K(()=>{const r=n.$$.on_mount.map(st).filter(F);n.$$.on_destroy?n.$$.on_destroy.push(...r):j(r),n.$$.on_mount=[]}),a.forEach(K)}function gt(n,t){const e=n.$$;e.fragment!==null&&(Ft(e.after_update),j(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Zt(n,t){n.$$.dirty[0]===-1&&(P.push(n),Gt(),n.$$.dirty.fill(0)),n.$$.dirty[t/31|0]|=1<<t%31}function ft(n,t,e,s,a,r,c=null,u=[-1]){const f=W;Z(n);const h=n.$$={fragment:null,ctx:[],props:r,update:U,not_equal:a,bound:at(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(f?f.$$.context:[])),callbacks:at(),dirty:u,skip_bound:!1,root:t.target||f.$$.root};c&&c(h.root);let w=!1;if(h.ctx=e?e(n,t.props||{},(l,x,...i)=>{const d=i.length?i[0]:x;return h.ctx&&a(h.ctx[l],h.ctx[l]=d)&&(!h.skip_bound&&h.bound[l]&&h.bound[l](d),w&&Zt(n,l)),x}):[],h.update(),w=!0,j(h.before_update),h.fragment=s?s(h.ctx):!1,t.target){if(t.hydrate){const l=Mt(t.target);h.fragment&&h.fragment.l(l),l.forEach(z)}else h.fragment&&h.fragment.c();t.intro&&X(n.$$.fragment),pt(n,t.target,t.anchor),dt()}Z(f)}class yt{constructor(){nt(this,"$$"),nt(this,"$$set")}$destroy(){gt(this,1),this.$destroy=U}$on(t,e){if(!F(e))return U;const s=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return s.push(e),()=>{const a=s.indexOf(e);a!==-1&&s.splice(a,1)}}$set(t){this.$$set&&!It(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const zt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(zt);function Vt(n){let t,e,s,a=(n[1]||"标题")+"",r,c,u,f,h,w,l=(n[4]||"取消")+"",x,i,d,p=(n[5]||"确认")+"",C,y,g,v;const E=n[7].default,m=Et(E,n,n[6],null);return{c(){t=S("div"),e=S("div"),s=S("div"),r=$(a),c=O(),u=S("div"),m&&m.c(),f=O(),h=S("div"),w=S("button"),x=$(l),i=O(),d=S("button"),C=$(p),B(s,"class","model-title svelte-n1zwga"),B(u,"class","slot svelte-n1zwga"),B(w,"class","modal-btn svelte-n1zwga"),B(d,"class","modal-btn success svelte-n1zwga"),B(h,"class","modal-footer svelte-n1zwga"),B(e,"class","modal-content svelte-n1zwga"),B(t,"class","modal-background modal-visible svelte-n1zwga")},m(I,A){J(I,t,A),k(t,e),k(e,s),k(s,r),k(e,c),k(e,u),m&&m.m(u,null),k(e,f),k(e,h),k(h,w),k(w,x),k(h,i),k(h,d),k(d,C),y=!0,g||(v=[N(w,"click",function(){F(n[0])&&n[0].apply(this,arguments)}),N(d,"click",function(){F(n[2])&&n[2].apply(this,arguments)}),N(e,"click",Rt),N(t,"click",function(){F(n[3])&&n[3].apply(this,arguments)})],g=!0)},p(I,[A]){n=I,(!y||A&2)&&a!==(a=(n[1]||"标题")+"")&&L(r,a),m&&m.p&&(!y||A&64)&&_t(m,E,n,n[6],y?At(E,n[6],A,null):Lt(n[6]),null),(!y||A&16)&&l!==(l=(n[4]||"取消")+"")&&L(x,l),(!y||A&32)&&p!==(p=(n[5]||"确认")+"")&&L(C,p)},i(I){y||(X(m,I),y=!0)},o(I){ut(m,I),y=!1},d(I){I&&z(t),m&&m.d(I),g=!1,j(v)}}}const Rt=n=>n.stopPropagation();function Ut(n,t,e){let{$$slots:s={},$$scope:a}=t,{onCancel:r}=t,{title:c}=t,{onOk:u}=t,{onClose:f}=t,{cancelText:h}=t,{okText:w}=t;return n.$$set=l=>{"onCancel"in l&&e(0,r=l.onCancel),"title"in l&&e(1,c=l.title),"onOk"in l&&e(2,u=l.onOk),"onClose"in l&&e(3,f=l.onClose),"cancelText"in l&&e(4,h=l.cancelText),"okText"in l&&e(5,w=l.okText),"$$scope"in l&&e(6,a=l.$$scope)},[r,c,u,f,h,w,a,s]}class Jt extends yt{constructor(t){super(),ft(this,t,Ut,Vt,rt,{onCancel:0,title:1,onOk:2,onClose:3,cancelText:4,okText:5})}}function mt(n,t,e){const s=n.slice();return s[10]=t[e],s[12]=e,s}function wt(n){let t,e,s=n[10].CN+"",a,r,c,u=n[10].DevClass+"",f,h,w=n[10].sn+"",l,x,i,d,p,C;function y(){return n[9](n[12])}return{c(){t=S("div"),e=S("span"),a=$(s),r=O(),c=S("span"),f=$(u),h=$("("),l=$(w),x=$(")"),i=O(),B(e,"class","svelte-jtc2v4"),B(c,"class","svelte-jtc2v4"),B(t,"class",d=ct(`cert-item ${n[12]===0?"cert-item-first":""} ${n[12]===n[4]?"cert-item-selected":""}`)+" svelte-jtc2v4")},m(g,v){J(g,t,v),k(t,e),k(e,a),k(t,r),k(t,c),k(c,f),k(c,h),k(c,l),k(c,x),k(t,i),p||(C=N(t,"click",y),p=!0)},p(g,v){n=g,v&1&&s!==(s=n[10].CN+"")&&L(a,s),v&1&&u!==(u=n[10].DevClass+"")&&L(f,u),v&1&&w!==(w=n[10].sn+"")&&L(l,w),v&16&&d!==(d=ct(`cert-item ${n[12]===0?"cert-item-first":""} ${n[12]===n[4]?"cert-item-selected":""}`)+" svelte-jtc2v4")&&B(t,"class",d)},d(g){g&&z(t),p=!1,C()}}}function Wt(n){let t,e=ht(n[0]),s=[];for(let a=0;a<e.length;a+=1)s[a]=wt(mt(n,e,a));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=Tt()},m(a,r){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(a,r);J(a,t,r)},p(a,r){if(r&17){e=ht(a[0]);let c;for(c=0;c<e.length;c+=1){const u=mt(a,e,c);s[c]?s[c].p(u,r):(s[c]=wt(u),s[c].c(),s[c].m(t.parentNode,t))}for(;c<s.length;c+=1)s[c].d(1);s.length=e.length}},d(a){a&&z(t),Pt(s,a)}}}function qt(n){let t,e;return t=new Jt({props:{onOk:n[6],onClose:n[1],onCancel:n[5],cancelText:n[2],okText:n[3],title:"选择证书",$$slots:{default:[Wt]},$$scope:{ctx:n}}}),{c(){Nt(t.$$.fragment)},m(s,a){pt(t,s,a),e=!0},p(s,[a]){const r={};a&2&&(r.onClose=s[1]),a&4&&(r.cancelText=s[2]),a&8&&(r.okText=s[3]),a&8209&&(r.$$scope={dirty:a,ctx:s}),t.$set(r)},i(s){e||(X(t.$$.fragment,s),e=!0)},o(s){ut(t.$$.fragment,s),e=!1},d(s){gt(t,s)}}}function Kt(n,t,e){let{certList:s=[]}=t,{onCancel:a}=t,{onOk:r}=t,{onClose:c}=t,{cancelText:u=""}=t,{okText:f=""}=t,h=0;const w=()=>{c==null||c()},l=()=>{r==null||r(s[h]),c==null||c()},x=i=>e(4,h=i);return n.$$set=i=>{"certList"in i&&e(0,s=i.certList),"onCancel"in i&&e(7,a=i.onCancel),"onOk"in i&&e(8,r=i.onOk),"onClose"in i&&e(1,c=i.onClose),"cancelText"in i&&e(2,u=i.cancelText),"okText"in i&&e(3,f=i.okText)},[s,c,u,f,h,w,l,a,r,x]}class Qt extends yt{constructor(t){super(),ft(this,t,Kt,qt,rt,{certList:0,onCancel:7,onOk:8,onClose:1,cancelText:2,okText:3})}}class Xt{constructor(){o(this,"modalInstance",{current:null});o(this,"open",t=>new Promise((e,s)=>{this.modalInstance.current=new Qt({target:document.body,props:{...t,onCancel:a=>{s()},onOk:a=>{e(a)},onClose:()=>{this.close()}}})}));o(this,"close",()=>{setTimeout(()=>{var t;(t=this.modalInstance.current)==null||t.$destroy()})})}}const Yt=new Xt;class te{constructor(t){o(this,"socketInstance",null);o(this,"eventBus",new bt);o(this,"isRememberPin",!1);o(this,"socketEvent");o(this,"pinPolicy");o(this,"socketConfig",null);o(this,"getSocketReadyState",()=>{var t;return(t=this.socketInstance)==null?void 0:t.readyState});o(this,"destroy",()=>{var t;(t=this.socketInstance)==null||t.close()});o(this,"sendMessage",(t,e)=>new Promise((s,a)=>{var c,u;if(((c=this.socketInstance)==null?void 0:c.readyState)!==WebSocket.OPEN){console.log(t),a({errCode:-1,msg:"socket未连接"});return}const r={function:t,args:[e??{}]};(u=this.socketInstance)==null||u.send(JSON.stringify(r)),this.eventBus.on(t,f=>{f.success?s(f.data):a(f)})}));o(this,"handleEventData",async t=>{var e,s,a,r,c,u;if(t.data instanceof Blob){const f=await t.data.arrayBuffer(),w=new TextDecoder("gbk").decode(f),l=JSON.parse(w),x={data:l.data,success:(e=l.result)==null?void 0:e.success,msg:(s=l.result)==null?void 0:s.msg,errCode:(a=l.result)==null?void 0:a.errCode};this.eventBus.emit((r=l.result)==null?void 0:r.function,x),(u=(c=this.socketConfig)==null?void 0:c.onMessage)==null||u.call(c,x)}});o(this,"base64Encode",t=>{const e=new TextEncoder().encode(t);return et.fromByteArray(e)});o(this,"base64Decode",t=>{const e=et.toByteArray(t);return new TextDecoder().decode(e)});o(this,"changeIsRememberPin",async t=>{this.isRememberPin=t});o(this,"changePinPolicy",async t=>{this.pinPolicy=t});o(this,"checkCertIsLogin",async t=>await this.sendMessage("GZCA_IsLogin",t));o(this,"addUkeyEvents",async()=>{this.sendMessage("GZCA_StartListen",{Type:vt}).then(t=>{var e,s;(s=(e=this.socketConfig)==null?void 0:e.onUkeyEvent)==null||s.call(e,t)})});o(this,"certLogin",async t=>{const e=await this.checkCertIsLogin({ContainerName:t});e!=null&&e[0].isLogin||await this.sendMessage("GZCA_Login",{ContainerName:t,IsLogin:"N",UserPin:"123456",PinPolicy:this.pinPolicy})});o(this,"getCert",async(t,e)=>{const s=e??await this.chooseCert(t);return await this.certLogin(s.ContainerName),s});o(this,"getCertList",async t=>await this.sendMessage("GZCA_GetCertList",t));o(this,"chooseCert",async t=>{const e=await this.getCertList(t);return(e==null?void 0:e.length)===1?e[0]:await Yt.open({certList:e})});o(this,"pkcs1Sign",async t=>await this.sendMessage("GZCA_Pkcs1SignData",{...t,IsLogin:this.getIsLogin(),PinPolicy:this.pinPolicy}));o(this,"pkcs1Base64Sign",async t=>await this.sendMessage("GZCA_Pkcs1SignDataEx",{...t,IsLogin:this.getIsLogin(),PinPolicy:this.pinPolicy}));o(this,"pkcs1VerifySignature",async t=>await this.sendMessage("GZCA_Pkcs1VerifySign",t));o(this,"pkcs1Base64VerifySignature",async t=>await this.sendMessage("GZCA_Pkcs1VerifySignEx",t));o(this,"getSealList",async t=>await this.sendMessage("GZCA_EnumSeals",{...t,IsLogin:this.getIsLogin()}));o(this,"sm2SignPreprocess1",async t=>await this.sendMessage("GZCA_PrepareSm2SignStep1",t));o(this,"sm2SignPreprocess2",async t=>await this.sendMessage("GZCA_PrepareSm2SignStep2",t));o(this,"pkcs1HashSign",async t=>await this.sendMessage("GZCA_Pkcs1SignDataForHash",{...t??{},IsLogin:this.getIsLogin(),PinPolicy:this.pinPolicy}));o(this,"pkcs1HashVerifySignature",async t=>await this.sendMessage("GZCA_Pkcs1VerifySignForHash",t));o(this,"pkcs7Sign",async t=>await this.sendMessage("GZCA_Pkcs7SignData",{...t,IsLogin:this.getIsLogin(),IsAuthAttr:"Y",PinPolicy:this.pinPolicy}));o(this,"pkcs7VerifySignature",async t=>await this.sendMessage("GZCA_Pkcs7VerifySign",t));o(this,"sm3Hash",async t=>await this.sendMessage("GZCA_HashData",t));o(this,"sm3HexHash",async t=>await this.sendMessage("GZCA_HashDataEx",t));o(this,"sm3FileHash",async t=>await this.sendMessage("GZCA_HashFile",t));o(this,"sm3HashEncryption",async t=>await this.sendMessage("GZCA_HMac",t));o(this,"pkcs7Encryption",async t=>await this.sendMessage("GZCA_Pkcs7EncryptData",t));o(this,"pkcs7Decryption",async t=>await this.sendMessage("GZCA_Pkcs7DecryptData",{...t,IsLogin:this.getIsLogin()}));o(this,"asymmetricEncryption",async t=>await this.sendMessage("GZCA_AsymEncryptData",t));o(this,"asymmetricDecryption",async t=>await this.sendMessage("GZCA_AsymDecryptData",{...t,IsLogin:this.getIsLogin()}));o(this,"sm4Encryption",async t=>await this.sendMessage("GZCA_EncryptDataEx",t));o(this,"sm4Decryption",async t=>await this.sendMessage("GZCA_DecryptDataEx",t));o(this,"getCertInfo",async t=>await this.sendMessage("GZCA_GetCertInfo",t));o(this,"getCertInfoByOid",async t=>await this.sendMessage("GZCA_GetCertInfoByOid",t));this.socketConfig=t,this.socketInstance=this.createSocket(t),this.isRememberPin=t.isRememberPin??!1,this.pinPolicy=t.pinPolicy??Y.MIN}createSocket(t){const e=new WebSocket(t.url);return e.onerror=s=>{var a;(a=t.onError)==null||a.call(t,s)},e.onopen=s=>{var a;(a=t.onOpen)==null||a.call(t,s),this.addUkeyEvents()},e.onmessage=s=>{this.handleEventData(s)},e.onclose=s=>{var a;(a=t.onClose)==null||a.call(t,s)},e}getIsLogin(){return this.isRememberPin?"Y":"N"}}const H=class H{constructor(t){o(this,"coreInstance",null);o(this,"gwsConfig",{});o(this,"createGwsCore",t=>{this.gwsConfig=t??{},this.coreInstance=new te({...t??{},url:b})});o(this,"appendCertBase64",async(t,e=!0)=>{if(t.CertB64)return t;const s=e?await this.getSignatureCert():await this.getEncryptionCert();return{...t??{},CertB64:s==null?void 0:s.CertB64}});o(this,"destroy",()=>{var t;(t=this.coreInstance)==null||t.destroy(),this.coreInstance=null});o(this,"restart",t=>{this.coreInstance&&this.destroy(),this.gwsConfig=t??this.gwsConfig,this.createGwsCore(t)});o(this,"getSocketReadyState",()=>{var t;return(t=this.coreInstance)==null?void 0:t.getSocketReadyState()});o(this,"getSignatureCert",async t=>{var s;return await((s=this.coreInstance)==null?void 0:s.getCert({CertType:_},t))});o(this,"getEncryptionCert",async t=>{var s;return await((s=this.coreInstance)==null?void 0:s.getCert({CertType:Ct},t))});o(this,"base64Encode",t=>{var e;return(e=this.coreInstance)==null?void 0:e.base64Encode(t.Data)});o(this,"base64Decode",t=>{var e;return(e=this.coreInstance)==null?void 0:e.base64Decode(t.DataB64)});o(this,"changeIsRememberPin",t=>{var e;(e=this.coreInstance)==null||e.changeIsRememberPin(t)});o(this,"changePinPolicy",t=>{var e;(e=this.coreInstance)==null||e.changePinPolicy(t)});o(this,"pkcs1Sign",async(t,e)=>{var r,c;const s=await this.getSignatureCert(e),a=await((r=this.coreInstance)==null?void 0:r.pkcs1Sign({...t??{},ContainerName:(s==null?void 0:s.ContainerName)??""}));return(c=a==null?void 0:a[0])==null?void 0:c.SignData});o(this,"pkcs1VerifySignature",async t=>{var a;const e=await this.appendCertBase64(t),s=await((a=this.coreInstance)==null?void 0:a.pkcs1VerifySignature(e));return Array.isArray(s)});o(this,"pkcs1Base64Sign",async(t,e)=>{var c,u;const s=await this.getSignatureCert(e),a=t.DataB64??this.base64Encode({Data:t.Data??""}),r=await((c=this.coreInstance)==null?void 0:c.pkcs1Base64Sign({ContainerName:(s==null?void 0:s.ContainerName)??"",DataB64:a}));return(u=r==null?void 0:r[0])==null?void 0:u.SignData});o(this,"pkcs1Base64VerifySignature",async t=>{var r;const e=t.DataB64??this.base64Encode({Data:t.Data??""}),s=await this.appendCertBase64(t);return!!await((r=this.coreInstance)==null?void 0:r.pkcs1Base64VerifySignature({CertB64:s.CertB64,DataB64:e,SignData:s.SignData}))});o(this,"getSealList",async()=>{var s;const t=await this.getSignatureCert(),e=await((s=this.coreInstance)==null?void 0:s.getSealList({ContainerName:(t==null?void 0:t.ContainerName)??""}));return{cert:t,sealList:e}});o(this,"sm2SignPreprocess1",async t=>{var a,r;const e=await this.appendCertBase64(t),s=await((a=this.coreInstance)==null?void 0:a.sm2SignPreprocess1(e));return(r=s==null?void 0:s[0])==null?void 0:r.Z});o(this,"sm2SignPreprocess2",async t=>{var r;const e=this.base64Encode({Data:t.Data??""}),s=await this.appendCertBase64(t),a=await((r=this.coreInstance)==null?void 0:r.sm2SignPreprocess2({CertB64:s.CertB64,DataB64:e}));return a==null?void 0:a[0].H});o(this,"pkcs1HashSign",async(t,e)=>{var r,c;const s=await this.getSignatureCert(e),a=await((r=this.coreInstance)==null?void 0:r.pkcs1HashSign({ContainerName:(s==null?void 0:s.ContainerName)??"",DataB64:t.DataB64,HashAlg:t.HashAlg??"sm3"}));return(c=a==null?void 0:a[0])==null?void 0:c.SignData});o(this,"pkcs1HashVerifySignature",async t=>{var a;const e=await this.appendCertBase64(t);return!!await((a=this.coreInstance)==null?void 0:a.pkcs1HashVerifySignature({...e,HashAlg:e.HashAlg??"sm3"}))});o(this,"pkcs7Sign",async(t,e)=>{var c,u;const s=t.DataB64??this.base64Encode({Data:t.Data??""}),a=await this.getSignatureCert(e),r=await((c=this.coreInstance)==null?void 0:c.pkcs7Sign({IsDetached:t.IsDetached,ContainerName:(a==null?void 0:a.ContainerName)??"",DataB64:s}));return(u=r==null?void 0:r[0])==null?void 0:u.SignData});o(this,"pkcs7VerifySignature",async t=>{var a;const e=t.DataB64??this.base64Encode({Data:t.Data??""});return!!await((a=this.coreInstance)==null?void 0:a.pkcs7VerifySignature({DataB64:e,SignData:t.SignData}))});o(this,"sm3Hash",async t=>{var s,a;const e=await((s=this.coreInstance)==null?void 0:s.sm3Hash(t));return(a=e==null?void 0:e[0])==null?void 0:a.HashB64});o(this,"sm3HexHash",async t=>{var s,a;const e=await((s=this.coreInstance)==null?void 0:s.sm3HexHash(t));return(a=e==null?void 0:e[0])==null?void 0:a.HashB64});o(this,"sm3FileHash",async t=>{var s,a;const e=await((s=this.coreInstance)==null?void 0:s.sm3FileHash(t));return(a=e==null?void 0:e[0])==null?void 0:a.HashB64});o(this,"sm3HashEncryption",async t=>{var r,c;const e=t.DataB64??this.base64Encode({Data:t.Data??""}),s=t.KeyB64??this.base64Encode({Data:t.Key??""}),a=await((r=this.coreInstance)==null?void 0:r.sm3HashEncryption({dataB64:e,keyB64:s,alg:"sm3"}));return(c=a==null?void 0:a[0])==null?void 0:c.DataB64});o(this,"pkcs7Encryption",async t=>{var a,r;if(!t.CertB64List){const c=await this.getEncryptionCert();t.CertB64List=c==null?void 0:c.CertB64}const e=t.DataB64??this.base64Encode({Data:t.Data??""}),s=await((a=this.coreInstance)==null?void 0:a.pkcs7Encryption({DataB64:e,CertB64List:t.CertB64List}));return(r=s==null?void 0:s[0])==null?void 0:r.DataB64});o(this,"pkcs7Decryption",async t=>{var r,c;const e=await this.getEncryptionCert(),s=await((r=this.coreInstance)==null?void 0:r.pkcs7Decryption({DataB64:t.DataB64,ContainerName:e==null?void 0:e.ContainerName})),a=(c=s==null?void 0:s[0])==null?void 0:c.DataB64;return t.shouldDecodeBase64?this.base64Decode({DataB64:a}):a});o(this,"asymmetricEncryption",async t=>{var a,r;const e=await this.appendCertBase64(t,!1),s=await((a=this.coreInstance)==null?void 0:a.asymmetricEncryption(e));return(r=s==null?void 0:s[0])==null?void 0:r.Data});o(this,"asymmetricDecryption",async t=>{var a,r;const e=await this.getEncryptionCert(),s=await((a=this.coreInstance)==null?void 0:a.asymmetricDecryption({Data:t.Data,ContainerName:e==null?void 0:e.ContainerName}));return(r=s==null?void 0:s[0])==null?void 0:r.Data});o(this,"sm4Encryption",async t=>{var s;const e=await((s=this.coreInstance)==null?void 0:s.sm4Encryption(t));return e==null?void 0:e[0]});o(this,"sm4Decryption",async t=>{var s,a;const e=await((s=this.coreInstance)==null?void 0:s.sm4Decryption(t));return(a=e==null?void 0:e[0])==null?void 0:a.Data});o(this,"getCertInfo",async t=>{var s;const e=await((s=this.coreInstance)==null?void 0:s.getCertInfo(t));return{...(e==null?void 0:e[0])??{}}});o(this,"getCertInfoByOid",async t=>{var s,a;const e=await((s=this.coreInstance)==null?void 0:s.getCertInfoByOid({...t??{}}));return(a=e==null?void 0:e[0])==null?void 0:a.OidValue});return H.instance&&!(t!=null&&t.isCreateNew)?H.instance:(this.createGwsCore(t),H.instance=this,this)}};o(H,"instance",null);let R=H;function ee(n){return new Promise((t,e)=>{const s=new R({...n??{},onOpen(a){var r;t(s),(r=n==null?void 0:n.onOpen)==null||r.call(n,a)},onClose(a){var r;e(a),(r=n==null?void 0:n.onClose)==null||r.call(n,a)}})})}D.GwsService=R,D.createService=ee,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gws-client",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "module": "dist/index.es.js",
6
6
  "browser": "dist/index.umd.js",