import{aF as _,j as u,h0 as b,g1 as j,eC as x,cJ as p,V as P,r as k,C as V,O as h,o as w}from"./index-CCv_8omK.js";import{u as R}from"./index-BiAAgnpw.js";import{E}from"./ErrorOutline-CUOja7My.js";import{r as C}from"./omit-BwCXmJ0x.js";const T=_(u.jsx("path",{d:"M12 2 4 5v6.09c0 5.05 3.41 9.76 8 10.91 4.59-1.15 8-5.86 8-10.91V5zm-1.06 13.54L7.4 12l1.41-1.41 2.12 2.12 4.24-4.24 1.41 1.41z"})),A={width:24,height:24,body:'<path fill="currentColor" d="M12 14.975q-.2 0-.375-.062T11.3 14.7l-4.6-4.6q-.275-.275-.275-.7t.275-.7q.275-.275.7-.275t.7.275l3.9 3.9l3.9-3.9q.275-.275.7-.275t.7.275q.275.275.275.7t-.275.7l-4.6 4.6q-.15.15-.325.213t-.375.062Z"/>'};var s={},$;function D(){if($)return s;$=1;var l=s&&s.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(s,"__esModule",{value:!0}),s.signResponse=c,s.verifyResponse=q,s.verifyVault=S;const g=l(C),v=l(b()),n=j(),a=x();async function c(e,d){const o=(0,v.default)(e),y=await d.sign(o);return{...e,$signature:y}}function q(e,d){return e.$signature?d.verify((0,v.default)((0,g.default)(e,"$signature")),e.$signature):Promise.resolve(!1)}async function S(e,d,o=!1){if(!Array.isArray(e)||e.length===0){if(o)throw new Error("vaults list is empty");return""}for(let t=1;t<e.length;t++)if(e[t].at<=e[t-1].at){if(o)throw new Error("vaults are not in ascending order");return""}if(new Set(e.map(t=>t.did)).size!==e.length){if(o)throw new Error("vaults list has duplicate vaults");return""}for(let t=0;t<e.length;t++){const r=e[t];if(!(0,a.isFromPublicKey)(r.did,r.pk)){if(o)throw new Error(`vault did and pk mismatch: ${r.did}(${r.pk})`);return""}let f=p.from(`vault:${d}`);for(let i=0;i<=t;i++)f=p.concat([f,p.from(`:${e[i].did}`)]);if(!r.approverSig){if(o)throw new Error(`vault approve signature missing for ${r.did}`);return""}try{let i;if(t>0){const m=e[t-1];i=(0,n.fromPublicKey)(m.pk,(0,a.toTypeInfo)(m.did))}else{if(!r.approverPk||!r.approverDid||!(0,a.isFromPublicKey)(r.approverDid,r.approverPk)){if(o)throw new Error(`approver config missing for ${r.did}`);return""}i=(0,n.fromPublicKey)(r.approverPk,(0,a.toTypeInfo)(r.approverDid))}if(await i.verify(f,r.approverSig)===!1){if(o)throw new Error(`signature verify failed for ${r.did}`);return""}}catch(i){if(console.error(i),o)throw new Error(`vault approve verify failed: ${i.message}`);return""}if(!r.sig){if(o)throw new Error(`vault commit signature missing for ${r.did}`);return""}try{const i=(0,n.fromPublicKey)(r.pk,(0,a.toTypeInfo)(r.did));if(r.approverSig&&(f=p.concat([f,p.from(`:${r.approverSig}`)])),await i.verify(f,r.sig)===!1){if(o)throw new Error(`commit signature verify failed for ${r.did}`);return""}}catch(i){if(console.error(i),o)throw new Error(`vault commit verify failed: ${i.message}`);return""}}return e[e.length-1].did}return s}var I=D();function K({vaults:l,appPid:g}){const{t:v}=P(),[n,a]=R({verified:!1,verifying:!0,error:""});return k.useEffect(()=>{I.verifyVault(l,g,!0).then(c=>{a({verified:!!c,verifying:!1})}).catch(c=>{a({verified:!1,verifying:!1,error:c.message})})},[l,g,a]),n.verifying?u.jsx(V,{}):n.verified?u.jsx(h,{title:v("blocklet.config.vault.verified"),children:u.jsx(T,{fontSize:"small",color:"success"})}):u.jsx(h,{title:n.error,children:u.jsx(E,{color:"error"})})}K.propTypes={vaults:w.array.isRequired,appPid:w.string.isRequired};export{K as V,A as d};
