function a17_0x25fe(e){e-=131;const r=a17_0x2d14();let n=r[e];if(void 0===a17_0x25fe.HBCMWy){a17_0x25fe.UnyfeY=function(e){let r="",n="";for(let n,t,s=0,a=0;t=e.charAt(a++);~t&&(n=s%4?64*n+t:t,s++%4)?r+=String.fromCharCode(255&n>>(-2*s&6)):0)t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=".indexOf(t);for(let e=0,t=r.length;e<t;e++)n+="%"+("00"+r.charCodeAt(e).toString(16)).slice(-2);return decodeURIComponent(n)},a17_0x25fe.ByAMrJ={},a17_0x25fe.HBCMWy=!0}const t=e+r[0],s=a17_0x25fe.ByAMrJ[t];return s?n=s:(n=a17_0x25fe.UnyfeY(n),a17_0x25fe.ByAMrJ[t]=n),n}!function(){const e=165,r=164,n=156,t=144,s=137,a=a17_0x25fe,i=a17_0x2d14();for(;;)try{if(413665===parseInt(a(e))/1*(parseInt(a(r))/2)+parseInt(a(n))/3*(-parseInt(a(162))/4)+parseInt(a(143))/5+parseInt(a(131))/6*(parseInt(a(150))/7)+-parseInt(a(186))/8+-parseInt(a(155))/9*(-parseInt(a(138))/10)+-parseInt(a(t))/11*(parseInt(a(s))/12))break;i.push(i.shift())}catch(e){i.push(i.shift())}}();import{ok,err}from"../shared/index.js";import{serializeMessage,deserializeMessage}from"./tlv.js";import{pkcs7Pad,pkcs7Unpad}from"./padding.js";import{generateHMAC,verifyHMAC}from"./hmac.js";import{splitXorIDA,reconstructXorIDA,nextOddPrime}from"./xorida.js";import{generateUUID}from"./uuid.js";export async function createShares(e,r,n){const t=179,s=154,a=132,i=a17_0x25fe,u={ESgqi:function(e,r){return e(r)},TaoDJ:function(e,r,n){return e(r,n)}},o=e[i(157)]||generateUUID(),f=o!==e[i(157)]?{...e,uuid:o}:e,c=u[i(t)](serializeMessage,f),d=nextOddPrime(r)-1,g=u[i(s)](pkcs7Pad,c,d),{key:m,signature:x}=await u[i(179)](generateHMAC,g);return splitXorIDA(g,r,n)[i(a)]((e,t)=>({uuid:o,index:t,totalShares:r,threshold:n,data:e,hmacKey:m[i(161)](),hmacSignature:x[i(161)]()}))}function a17_0x2d14(){const e=["ANDWwxy","mxW0Fdb8nxWYFdm","u2HHCMuGAw5KzxGG","rgvZzxjPywXPEMf0Aw9UigzHAwXLzdOG","veXwifvvsuqGzg9LCYbUB3qGBwf0y2GGzw52zwXVCguGvvvjra","Dg90ywXtAgfYzxm","y3D0seu","qM5tqxG","ihnOyxjLCYWGz290ia","rvnNCwK","BvforMG","Ag1Hy1nPz25HDhvYzq","vvvjrf9nsvnnqvrdsa","Aw5KzxG","ywrK","zhbTufK","mJuXmZK2ogrPBKTdCa","zxjYB3i","mJqWnMLvs3z6rq","BwfW","Dg9mB3DLCKnHC2u","su5wquXjrf9jtKrfwa","DMfSDwu","se1bq19gquLmvvjf","ntK5mtKYnefdtgPWtG","nde1ndmWA1Dcyvvn","su5wquXjrf9tsefsrvm","Ag1Hy0TLEq","su5tvuzgsunjru5ux1niqvjfuW","ig91DcbVzIbYyw5NzsbBmcWG","mZKWnJm3mhnbENrbvq","mtfSEe5bEuK","s0nkCNO","AgfZ","DhjPBq","rMPwy1y","AeDxuuO","mJCWoxbqvwDiva","ChvZAa","BwvZC2fNzq","BgvUz3rO","vgfVreO","oufWqwHjsG","m0jTAu1prW","DxvPza","tM8GC2HHCMvZihbYB3zPzgvK","se1bqYb2zxjPzMLJyxrPB24GzMfPBgvKiokaLcbKyxrHig1HEsbIzsbJB3jYDxb0zwqGB3iGDgfTCgvYzwq","zgf0yq","C2XPy2u","nJeYntjJBLP0q0C","whvMt0m","nti5mdK0rMD3wNb0","mwHurgXYyq","u1vrEe0","rhvWBgLJyxrLihnOyxjLigLUzgv4ia","vw5WywrKAw5NigzHAwXLzdOG","DgHYzxnOB2XK"];return(a17_0x2d14=function(){return e})()}export async function reconstructMessage(e){const r=136,n=169,t=141,s=178,a=171,i=183,u=172,o=183,f=163,c=175,d=146,g=134,m=167,x=183,v=161,z=181,w=148,h=136,p=135,y=173,A=147,C=133,D=147,I=149,M=182,j=176,q=a17_0x25fe,B={TOPzX:function(e,r){return e===r},dpmPY:function(e,r){return e<r},hGWQJ:function(e,r){return e(r)},Rblfz:"INVALID_INDEX",eUxTx:function(e,r){return e!==r},XufOC:function(e,r){return e(r)},mQNFh:q(139),BnSAx:"Shares have different UUIDs",SUQxM:function(e,r,n,t){return e(r,n,t)},FjVcV:q(r),KCJrz:q(159),jwpYv:function(e,r,n){return e(r,n)},cwtHE:q(174)};if(B.TOPzX(e.length,0))return err({code:"INSUFFICIENT_SHARES",message:q(158)});const b=e[0],G=b[q(n)],H=b[q(175)];if(B[q(185)](e[q(153)],G))return err({code:q(t),message:"Need "+G+q(s)+e[q(153)]});const l=[],P=new Set;for(const r of e){const e=q(a).split("|");let t=0;for(;;){switch(e[t++]){case"0":if(r[q(183)]<0||r[q(i)]>=H)return B.hGWQJ(err,{code:B.Rblfz,message:q(u)+r[q(o)]+q(142)+H+")"});continue;case"1":if(B.eUxTx(r.uuid,b[q(157)]))return B[q(f)](err,{code:B.mQNFh,message:B[q(177)]});continue;case"2":P[q(184)](r[q(183)]);continue;case"3":l[q(151)](r[q(183)]);continue;case"4":if(r[q(c)]!==H||r[q(n)]!==G)return err({code:B[q(180)],message:"Shares have inconsistent n/k values"});continue;case"5":if(P[q(d)](r[q(o)]))return err({code:q(g),message:q(m)+r[q(x)]});continue}break}}const K=e[q(v)](0,G),W=l[q(161)](0,G),X=K[q(132)](e=>e[q(160)]),U=reconstructXorIDA(X,W,H,G);if(!await B[q(166)](verifyHMAC,b[q(140)],U,b[q(z)]))return err({code:B[q(w)],message:B[q(145)]});const Y=nextOddPrime(H)-1,J=B[q(170)](pkcs7Unpad,U,Y);if(!J.ok)return err({code:q(h),message:q(168)+J[q(187)][q(152)]});const L=deserializeMessage(J[q(p)]);if(!L.ok)return err({code:q(139),message:q(y)+L[q(187)][q(152)]});const O=L[q(135)].uuid;return O&&O[q(133)]()[q(A)]()!==b.uuid[q(C)]()[q(D)]()?B[q(I)](err,{code:q(M),message:B[q(j)]}):ok({...L.value,uuid:b[q(157)]})}