import{k as ye,j as D,t as ve,h as Y,m as $,n as a,p as t,f as p,i as N,v as Z,A as g,x as B,s as we,e as Ce,S as d,q as ke}from"./web.Os7kOAdY.js";import{c as He}from"./clipboard.BNxbz_oK.js";import{s as ee,d as Me,a as te,e as Ie,c as Je}from"./utils.BiOoVwDh.js";import{g as le,t as Ae}from"./i18n-runtime._BAkvU05.js";var Te=g("<pre>"),De=g("<div class=tool-grid-2><div class=tool-field><span class=tool-label>Header</span><pre class=tool-pre></pre></div><div class=tool-field><span class=tool-label>Payload</span><pre class=tool-pre>"),Ne=g('<div class=tool-field><span class=tool-label>Signature (HEX)</span><pre class=tool-pre></pre><button class="tool-btn is-ghost"style=align-self:flex-start>'),Ee=g('<div class=panel style=display:flex;flex-direction:column;gap:14px><div class=tool-field><span class=tool-label>JWT Token</span><textarea class=tool-textarea rows=4 placeholder=eyJhbGc...></textarea></div><div class=tool-grid-2><div class=tool-field><span class=tool-label>Secret（HS256/384/512）</span><input class=tool-input placeholder=your-secret></div><div class=tool-actions style=align-items:end><button class="tool-btn is-primary"></button><button class="tool-btn is-ghost"></button><button class="tool-btn is-ghost"></button></div></div><!$><!/><!$><!/><p class=tool-hint>'),Oe=g('<span class=tool-error style="padding:6px 10px">× <!$><!/>'),We=g("<li><span>iat</span><strong><!$><!/><!$><!/>"),je=g("<li><span>exp</span><strong><!$><!/><!$><!/>"),Le=g("<li><span>nbf</span><strong><!$><!/><!$><!/>"),Be=g("<li><span>iss</span><strong>"),Ue=g("<li><span>sub</span><strong>"),ze=g("<li><span>aud</span><strong>"),Pe=g("<ul class=tool-kv><!$><!/><!$><!/><!$><!/><!$><!/><!$><!/><!$><!/>");const Re={HS256:"SHA-256",HS384:"SHA-384",HS512:"SHA-512"};async function qe(y,x,f){const J=await crypto.subtle.importKey("raw",x,{name:"HMAC",hash:Re[y]},!1,["sign"]),v=await crypto.subtle.sign("HMAC",J,f);return new Uint8Array(v)}function U(y){if(typeof y!="number")return"";const x=new Date(y*1e3);return isNaN(x.getTime())?"":` → ${x.toLocaleString()}`}function Xe(){const[y,x]=D(le(),{equals:!1}),f=l=>Ae(l,y());ve(()=>{const l=r=>{const c=r.detail?.locale;c&&x(c)};window.addEventListener("taitan:locale-change",l),x(le()),we(()=>window.removeEventListener("taitan:locale-change",l))});const[J,v]=D(""),[E,O]=D(""),[W,h]=D(""),o=Y(()=>{const l=J().trim();if(!l)return null;const r=l.split(".");if(r.length!==3)return{ok:!1,err:"JWT 必须是 3 段（header.payload.signature）"};try{const c=JSON.parse(te(r[0])),m=JSON.parse(te(r[1]));return{ok:!0,header:c,payload:m,sig:r[2],signing:`${r[0]}.${r[1]}`}}catch(c){return{ok:!1,err:c.message}}}),ne=async()=>{const l=o();if(!l||!l.ok){h("× 无法解码 JWT");return}const r=l.header.alg;if(!r||!["HS256","HS384","HS512"].includes(r)){h(`× 不支持算法：${r??"(空)"}（仅支持 HS256/384/512）`);return}if(!E()){h("× 请输入 secret");return}try{const c=await qe(r,ee(E()),ee(l.signing)),m=Me(c);m===l.sig?h("✓ 签名校验通过"):h(`× 签名不匹配
  实际: ${l.sig}
  期望: ${m}`)}catch(c){h(`× ${c.message}`)}},ie=()=>{v("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkxpIExlaSIsImlhdCI6MTcwMDAwMDAwMCwiZXhwIjoyMDAwMDAwMDAwfQ.Q3FRQwzNzPC8jvJ_FjU7UwiDhvJU-9C8DBkKqkDtYy0"),O("your-256-bit-secret")},z=Y(()=>{const l=o();if(!l||!l.ok)return"";try{return Ie(Je(l.sig))}catch{return""}});return(()=>{var l=$(Ee),r=l.firstChild,c=r.firstChild,m=c.nextSibling,P=r.nextSibling,R=P.firstChild,re=R.firstChild,q=re.nextSibling,se=R.nextSibling,A=se.firstChild,j=A.nextSibling,F=j.nextSibling,ae=P.nextSibling,[G,oe]=a(ae.nextSibling),ce=G.nextSibling,[K,$e]=a(ce.nextSibling),ge=K.nextSibling;return m.$$input=e=>v(e.currentTarget.value),q.$$input=e=>O(e.currentTarget.value),A.$$click=ne,t(A,()=>f("校验签名")),j.$$click=ie,t(j,()=>f("示例")),F.$$click=()=>{v(""),O(""),h("")},t(F,()=>f("清空")),t(l,p(d,{get when(){return W()},get children(){var e=$(Te);return t(e,W),N(()=>Ce(e,`tool-pre ${W().startsWith("×")?"tool-error":""}`)),e}}),G,oe),t(l,p(d,{get when(){return o()},get children(){return p(d,{get when(){return o().ok},get fallback(){return(()=>{var e=$(Oe),s=e.firstChild,b=s.nextSibling,[u,w]=a(b.nextSibling);return t(e,()=>o().err,u,w),e})()},get children(){return[(()=>{var e=$(De),s=e.firstChild,b=s.firstChild,u=b.nextSibling,w=s.nextSibling,L=w.firstChild,T=L.nextSibling;return t(u,()=>JSON.stringify(o().header,null,2)),t(T,()=>JSON.stringify(o().payload,null,2)),e})(),(()=>{var e=$(Ne),s=e.firstChild,b=s.nextSibling,u=b.nextSibling;return t(b,z),u.$$click=()=>He(z()),t(u,()=>f("复制")),Z(),e})(),p(d,{get when(){return ke(()=>!!o().payload)()&&typeof o().payload=="object"},get children(){return(()=>{const e=o().payload;return(()=>{var s=$(Pe),b=s.firstChild,[u,w]=a(b.nextSibling),L=u.nextSibling,[T,_e]=a(L.nextSibling),pe=T.nextSibling,[Q,de]=a(pe.nextSibling),ue=Q.nextSibling,[X,be]=a(ue.nextSibling),Se=X.nextSibling,[V,xe]=a(Se.nextSibling),fe=V.nextSibling,[he,me]=a(fe.nextSibling);return t(s,p(d,{get when(){return"iat"in e},get children(){var n=$(We),_=n.firstChild,i=_.nextSibling,C=i.firstChild,[S,k]=a(C.nextSibling),H=S.nextSibling,[M,I]=a(H.nextSibling);return t(i,()=>String(e.iat),S,k),t(i,()=>U(e.iat),M,I),n}}),u,w),t(s,p(d,{get when(){return"exp"in e},get children(){var n=$(je),_=n.firstChild,i=_.nextSibling,C=i.firstChild,[S,k]=a(C.nextSibling),H=S.nextSibling,[M,I]=a(H.nextSibling);return t(i,()=>String(e.exp),S,k),t(i,()=>U(e.exp),M,I),n}}),T,_e),t(s,p(d,{get when(){return"nbf"in e},get children(){var n=$(Le),_=n.firstChild,i=_.nextSibling,C=i.firstChild,[S,k]=a(C.nextSibling),H=S.nextSibling,[M,I]=a(H.nextSibling);return t(i,()=>String(e.nbf),S,k),t(i,()=>U(e.nbf),M,I),n}}),Q,de),t(s,p(d,{get when(){return"iss"in e},get children(){var n=$(Be),_=n.firstChild,i=_.nextSibling;return t(i,()=>String(e.iss)),n}}),X,be),t(s,p(d,{get when(){return"sub"in e},get children(){var n=$(Ue),_=n.firstChild,i=_.nextSibling;return t(i,()=>String(e.sub)),n}}),V,xe),t(s,p(d,{get when(){return"aud"in e},get children(){var n=$(ze),_=n.firstChild,i=_.nextSibling;return t(i,()=>String(e.aud)),n}}),he,me),s})()})()}})]}})}}),K,$e),t(ge,()=>f("仅本地解码与校验，不会上传 token。RSA / ES 类算法因需要 PEM/JWK 公钥解析未内置，可手动复用 WebCrypto。")),N(()=>B(A,"disabled",!o()||!o()?.ok)),N(()=>B(m,"value",J())),N(()=>B(q,"value",E())),Z(),l})()}ye(["input","click"]);export{Xe as default};
