gws-client 0.2.4 → 0.4.0

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.
@@ -0,0 +1 @@
1
+ "use strict";var ft=Object.defineProperty;var mt=(n,t,e)=>t in n?ft(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var o=(n,t,e)=>mt(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const wt=window.location.href.includes("https")?"wss://localhost:19528":"ws://localhost:9527",Ct="1",vt="2";var ot=(n=>(n[n.MIN=0]="MIN",n[n.LOW=1]="LOW",n[n.MIDDLE=2]="MIDDLE",n[n.HIGH=3]="HIGH",n))(ot||{});const kt="00000001";function xt(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var M={},W;function Dt(){if(W)return M;W=1,M.byteLength=u,M.toByteArray=h,M.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 g=i.indexOf("=");g===-1&&(g=d);var C=g===d?0:4-g%4;return[g,C]}function u(i){var d=c(i),g=d[0],C=d[1];return(g+C)*3/4-C}function y(i,d,g){return(d+g)*3/4-g}function h(i){var d,g=c(i),C=g[0],f=g[1],p=new e(y(i,C,f)),v=0,$=f>0?C-4:C,m;for(m=0;m<$;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)],p[v++]=d>>16&255,p[v++]=d>>8&255,p[v++]=d&255;return f===2&&(d=t[i.charCodeAt(m)]<<2|t[i.charCodeAt(m+1)]>>4,p[v++]=d&255),f===1&&(d=t[i.charCodeAt(m)]<<10|t[i.charCodeAt(m+1)]<<4|t[i.charCodeAt(m+2)]>>2,p[v++]=d>>8&255,p[v++]=d&255),p}function w(i){return n[i>>18&63]+n[i>>12&63]+n[i>>6&63]+n[i&63]}function l(i,d,g){for(var C,f=[],p=d;p<g;p+=3)C=(i[p]<<16&16711680)+(i[p+1]<<8&65280)+(i[p+2]&255),f.push(w(C));return f.join("")}function x(i){for(var d,g=i.length,C=g%3,f=[],p=16383,v=0,$=g-C;v<$;v+=p)f.push(l(i,v,v+p>$?$:v+p));return C===1?(d=i[g-1],f.push(n[d>>2]+n[d<<4&63]+"==")):C===2&&(d=(i[g-2]<<8)+i[g-1],f.push(n[d>>10]+n[d>>4&63]+n[d<<2&63]+"=")),f.join("")}return M}var bt=Dt();const Q=xt(bt);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 St=Object.defineProperty,$t=(n,t,e)=>t in n?St(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,X=(n,t,e)=>$t(n,typeof t!="symbol"?t+"":t,e);function V(){}function It(n,t){for(const e in t)n[e]=t[e];return n}function ct(n){return n()}function Y(){return Object.create(null)}function j(n){n.forEach(ct)}function H(n){return typeof n=="function"}function it(n,t){return n!=n?t==t:n!==t||n&&typeof n=="object"||typeof n=="function"}function Et(n){return Object.keys(n).length===0}function At(n,t,e,s){if(n){const a=lt(n,t,e,s);return n[0](a)}}function lt(n,t,e,s){return n[1]&&s?It(e.ctx.slice(),n[1](s(t))):e.ctx}function _t(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 Lt(n,t,e,s,a,r){if(a){const c=lt(t,e,s,r);n.p(c,a)}}function Pt(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 tt(n){return n??""}function k(n,t){n.appendChild(t)}function J(n,t,e){n.insertBefore(t,e||null)}function N(n){n.parentNode&&n.parentNode.removeChild(n)}function Mt(n,t){for(let e=0;e<n.length;e+=1)n[e]&&n[e].d(t)}function B(n){return document.createElement(n)}function S(n){return document.createTextNode(n)}function G(){return S(" ")}function Tt(){return S("")}function T(n,t,e,s){return n.addEventListener(t,e,s),()=>n.removeEventListener(t,e,s)}function D(n,t,e){e==null?n.removeAttribute(t):n.getAttribute(t)!==e&&n.setAttribute(t,e)}function Ht(n){return Array.from(n.childNodes)}function L(n,t){t=""+t,n.data!==t&&(n.data=t)}let q;function F(n){q=n}const A=[],et=[];let P=[];const nt=[],Gt=Promise.resolve();let R=!1;function Ft(){R||(R=!0,Gt.then(dt))}function U(n){P.push(n)}const z=new Set;let E=0;function dt(){if(E!==0)return;const n=q;do{try{for(;E<A.length;){const t=A[E];E++,F(t),jt(t.$$)}}catch(t){throw A.length=0,E=0,t}for(F(null),A.length=0,E=0;et.length;)et.pop()();for(let t=0;t<P.length;t+=1){const e=P[t];z.has(e)||(z.add(e),e())}P.length=0}while(A.length);for(;nt.length;)nt.pop()();R=!1,z.clear(),F(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(U)}}function Ot(n){const t=[],e=[];P.forEach(s=>n.indexOf(s)===-1?t.push(s):e.push(s)),e.forEach(s=>s()),P=t}const O=new Set;let Zt;function K(n,t){n&&n.i&&(O.delete(n),n.i(t))}function ut(n,t,e,s){if(n&&n.o){if(O.has(n))return;O.add(n),Zt.c.push(()=>{O.delete(n)}),n.o(t)}}function st(n){return(n==null?void 0:n.length)!==void 0?n:Array.from(n)}function Nt(n){n&&n.c()}function ht(n,t,e){const{fragment:s,after_update:a}=n.$$;s&&s.m(t,e),U(()=>{const r=n.$$.on_mount.map(ct).filter(H);n.$$.on_destroy?n.$$.on_destroy.push(...r):j(r),n.$$.on_mount=[]}),a.forEach(U)}function gt(n,t){const e=n.$$;e.fragment!==null&&(Ot(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&&(A.push(n),Ft(),n.$$.dirty.fill(0)),n.$$.dirty[t/31|0]|=1<<t%31}function pt(n,t,e,s,a,r,c=null,u=[-1]){const y=q;F(n);const h=n.$$={fragment:null,ctx:[],props:r,update:V,not_equal:a,bound:Y(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(y?y.$$.context:[])),callbacks:Y(),dirty:u,skip_bound:!1,root:t.target||y.$$.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=Ht(t.target);h.fragment&&h.fragment.l(l),l.forEach(N)}else h.fragment&&h.fragment.c();t.intro&&K(n.$$.fragment),ht(n,t.target,t.anchor),dt()}F(y)}class yt{constructor(){X(this,"$$"),X(this,"$$set")}$destroy(){gt(this,1),this.$destroy=V}$on(t,e){if(!H(e))return V;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&&!Et(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Vt="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Vt);function Rt(n){let t,e,s,a=(n[1]||"标题")+"",r,c,u,y,h,w,l=(n[4]||"取消")+"",x,i,d,g=(n[5]||"确认")+"",C,f,p,v;const $=n[7].default,m=At($,n,n[6],null);return{c(){t=B("div"),e=B("div"),s=B("div"),r=S(a),c=G(),u=B("div"),m&&m.c(),y=G(),h=B("div"),w=B("button"),x=S(l),i=G(),d=B("button"),C=S(g),D(s,"class","model-title svelte-n1zwga"),D(u,"class","slot svelte-n1zwga"),D(w,"class","modal-btn svelte-n1zwga"),D(d,"class","modal-btn success svelte-n1zwga"),D(h,"class","modal-footer svelte-n1zwga"),D(e,"class","modal-content svelte-n1zwga"),D(t,"class","modal-background modal-visible svelte-n1zwga")},m(b,I){J(b,t,I),k(t,e),k(e,s),k(s,r),k(e,c),k(e,u),m&&m.m(u,null),k(e,y),k(e,h),k(h,w),k(w,x),k(h,i),k(h,d),k(d,C),f=!0,p||(v=[T(w,"click",function(){H(n[0])&&n[0].apply(this,arguments)}),T(d,"click",function(){H(n[2])&&n[2].apply(this,arguments)}),T(e,"click",Ut),T(t,"click",function(){H(n[3])&&n[3].apply(this,arguments)})],p=!0)},p(b,[I]){n=b,(!f||I&2)&&a!==(a=(n[1]||"标题")+"")&&L(r,a),m&&m.p&&(!f||I&64)&&Lt(m,$,n,n[6],f?_t($,n[6],I,null):Pt(n[6]),null),(!f||I&16)&&l!==(l=(n[4]||"取消")+"")&&L(x,l),(!f||I&32)&&g!==(g=(n[5]||"确认")+"")&&L(C,g)},i(b){f||(K(m,b),f=!0)},o(b){ut(m,b),f=!1},d(b){b&&N(t),m&&m.d(b),p=!1,j(v)}}}const Ut=n=>n.stopPropagation();function Jt(n,t,e){let{$$slots:s={},$$scope:a}=t,{onCancel:r}=t,{title:c}=t,{onOk:u}=t,{onClose:y}=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,y=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,y,h,w,a,s]}class qt extends yt{constructor(t){super(),pt(this,t,Jt,Rt,it,{onCancel:0,title:1,onOk:2,onClose:3,cancelText:4,okText:5})}}function at(n,t,e){const s=n.slice();return s[10]=t[e],s[12]=e,s}function rt(n){let t,e,s=n[10].CN+"",a,r,c,u=n[10].DevClass+"",y,h,w=n[10].sn+"",l,x,i,d,g,C;function f(){return n[9](n[12])}return{c(){t=B("div"),e=B("span"),a=S(s),r=G(),c=B("span"),y=S(u),h=S("("),l=S(w),x=S(")"),i=G(),D(e,"class","svelte-jtc2v4"),D(c,"class","svelte-jtc2v4"),D(t,"class",d=tt(`cert-item ${n[12]===0?"cert-item-first":""} ${n[12]===n[4]?"cert-item-selected":""}`)+" svelte-jtc2v4")},m(p,v){J(p,t,v),k(t,e),k(e,a),k(t,r),k(t,c),k(c,y),k(c,h),k(c,l),k(c,x),k(t,i),g||(C=T(t,"click",f),g=!0)},p(p,v){n=p,v&1&&s!==(s=n[10].CN+"")&&L(a,s),v&1&&u!==(u=n[10].DevClass+"")&&L(y,u),v&1&&w!==(w=n[10].sn+"")&&L(l,w),v&16&&d!==(d=tt(`cert-item ${n[12]===0?"cert-item-first":""} ${n[12]===n[4]?"cert-item-selected":""}`)+" svelte-jtc2v4")&&D(t,"class",d)},d(p){p&&N(t),g=!1,C()}}}function Kt(n){let t,e=st(n[0]),s=[];for(let a=0;a<e.length;a+=1)s[a]=rt(at(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=st(a[0]);let c;for(c=0;c<e.length;c+=1){const u=at(a,e,c);s[c]?s[c].p(u,r):(s[c]=rt(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&&N(t),Mt(s,a)}}}function Wt(n){let t,e;return t=new qt({props:{onOk:n[6],onClose:n[1],onCancel:n[5],cancelText:n[2],okText:n[3],title:"选择证书",$$slots:{default:[Kt]},$$scope:{ctx:n}}}),{c(){Nt(t.$$.fragment)},m(s,a){ht(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||(K(t.$$.fragment,s),e=!0)},o(s){ut(t.$$.fragment,s),e=!1},d(s){gt(t,s)}}}function Qt(n,t,e){let{certList:s=[]}=t,{onCancel:a}=t,{onOk:r}=t,{onClose:c}=t,{cancelText:u=""}=t,{okText:y=""}=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,y=i.okText)},[s,c,u,y,h,w,l,a,r,x]}class Xt extends yt{constructor(t){super(),pt(this,t,Qt,Wt,it,{certList:0,onCancel:7,onOk:8,onClose:1,cancelText:2,okText:3})}}class Yt{constructor(){o(this,"modalInstance",{current:null});o(this,"open",t=>new Promise((e,s)=>{this.modalInstance.current=new Xt({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 te=new Yt;class ee{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,y=>{y.success?s(y.data):a(y)})}));o(this,"handleEventData",async t=>{var e,s,a,r,c,u;if(t.data instanceof Blob){const y=await t.data.arrayBuffer(),w=new TextDecoder("gbk").decode(y),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 Q.fromByteArray(e)});o(this,"base64Decode",t=>{const e=Q.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:kt}).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 te.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??ot.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 _=class _{constructor(t){o(this,"coreInstance",null);o(this,"gwsConfig",{});o(this,"createGwsCore",t=>{this.gwsConfig=t??{},this.coreInstance=new ee({...t??{},url:wt})});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:Ct},t))});o(this,"getEncryptionCert",async t=>{var s;return await((s=this.coreInstance)==null?void 0:s.getCert({CertType:vt},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 _.instance&&!(t!=null&&t.isCreateNew)?_.instance:(this.createGwsCore(t),_.instance=this,this)}};o(_,"instance",null);let Z=_;function ne(n){return new Promise((t,e)=>{const s=new Z({...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)}})})}exports.GwsService=Z;exports.createService=ne;
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "gws-client",
3
- "version": "0.2.4",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "module": "dist/index.es.js",
6
6
  "browser": "dist/index.umd.js",
7
+ "main": "dist/index.cjs.js",
7
8
  "types": "dist/index.d.ts",
8
9
  "description": "gws client",
9
10
  "keywords": [