@catena/cli 0.0.0-bootstrap.0 → 0.0.2

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
+ import{t as e}from"./utils-CGVgWgFq.mjs";import*as t from"crypto";const n=async n=>{let{content:r,publicKey:i,privateKey:a}=n,o=t.createPrivateKey({key:e({uncompressedPrivateKeyHex:a,compressedPublicKeyHex:i}),format:`jwk`}),s=t.createSign(`SHA256`);return s.write(Buffer.from(r)),s.end(),s.sign(o,`hex`)};export{n as signWithApiKey};
@@ -0,0 +1,15 @@
1
+ import{a as e,c as t,d as n,f as r,g as i,h as a,i as o,l as s,m as c,n as l,o as u,p as d,r as f,s as p,u as m,y as h}from"./index.mjs";var g=class extends e{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,t(e);let a=i(r);if(this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(a.length>o?e.create().update(a).digest():a);for(let e=0;e<s.length;e++)s[e]^=54;this.iHash.update(s),this.oHash=e.create();for(let e=0;e<s.length;e++)s[e]^=106;this.oHash.update(s),n(s)}update(e){return p(this),this.iHash.update(e),this}digestInto(e){p(this),u(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const _=(e,t,n)=>new g(e,t).update(n).digest();_.create=(e,t)=>new g(e,t);
2
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
3
+ const v=BigInt(0),y=BigInt(1);function b(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}"`;throw Error(n+`expected boolean, got type=`+typeof e)}return e}function x(e,t,n=``){let r=c(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`;throw Error(o+`expected Uint8Array`+s+`, got `+c)}return e}function S(e){let t=e.toString(16);return t.length&1?`0`+t:t}function C(e){if(typeof e!=`string`)throw Error(`hex string expected, got `+typeof e);return e===``?v:BigInt(`0x`+e)}function w(e){return C(m(e))}function T(e){return u(e),C(m(Uint8Array.from(e).reverse()))}function E(e,t){return d(e.toString(16).padStart(t*2,`0`))}function D(e,t){return E(e,t).reverse()}function O(e,t,n){let r;if(typeof t==`string`)try{r=d(t)}catch(t){throw Error(e+` must be hex string or Uint8Array, cause: `+t)}else if(c(t))r=Uint8Array.from(t);else throw Error(e+` must be hex string or Uint8Array`);let i=r.length;if(typeof n==`number`&&i!==n)throw Error(e+` of length `+n+` expected, got `+i);return r}const k=e=>typeof e==`bigint`&&v<=e;function A(e,t,n){return k(e)&&k(t)&&k(n)&&t<=e&&e<n}function j(e,t,n,r){if(!A(t,n,r))throw Error(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function M(e){let t;for(t=0;e>v;e>>=y,t+=1);return t}const N=e=>(y<<BigInt(e))-y;function ee(e,t,n){if(typeof e!=`number`||e<2)throw Error(`hashLen must be a number`);if(typeof t!=`number`||t<2)throw Error(`qByteLen must be a number`);if(typeof n!=`function`)throw Error(`hmacFn must be a function`);let i=e=>new Uint8Array(e),a=e=>Uint8Array.of(e),o=i(e),s=i(e),c=0,l=()=>{o.fill(1),s.fill(0),c=0},u=(...e)=>n(s,o,...e),d=(e=i(0))=>{s=u(a(0),e),o=u(),e.length!==0&&(s=u(a(1),e),o=u())},f=()=>{if(c++>=1e3)throw Error(`drbg: tried 1000 values`);let e=0,n=[];for(;e<t;){o=u();let t=o.slice();n.push(t),e+=o.length}return r(...n)};return(e,t)=>{l(),d(e);let n;for(;!(n=t(f()));)d();return l(),n}}function te(e,t,n={}){if(!e||typeof e!=`object`)throw Error(`expected valid options object`);function r(t,n,r){let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw Error(`param "${t}" is invalid: expected ${n}, got ${a}`)}Object.entries(t).forEach(([e,t])=>r(e,t,!1)),Object.entries(n).forEach(([e,t])=>r(e,t,!0))}function ne(e){let t=new WeakMap;return(n,...r)=>{let i=t.get(n);if(i!==void 0)return i;let a=e(n,...r);return t.set(n,a),a}}
4
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
5
+ const P=BigInt(0),F=BigInt(1),I=BigInt(2),re=BigInt(3),ie=BigInt(4),ae=BigInt(5),oe=BigInt(7),se=BigInt(8),ce=BigInt(9),le=BigInt(16);function L(e,t){let n=e%t;return n>=P?n:t+n}function ue(e,t){if(e===P)throw Error(`invert: expected non-zero number`);if(t<=P)throw Error(`invert: expected positive modulus, got `+t);let n=L(e,t),r=t,i=P,a=F,o=F,s=P;for(;n!==P;){let e=r/n,t=r%n,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==F)throw Error(`invert: does not exist`);return L(i,t)}function R(e,t,n){if(!e.eql(e.sqr(t),n))throw Error(`Cannot find square root`)}function de(e,t){let n=(e.ORDER+F)/ie,r=e.pow(t,n);return R(e,r,t),r}function fe(e,t){let n=(e.ORDER-ae)/se,r=e.mul(t,I),i=e.pow(r,n),a=e.mul(t,i),o=e.mul(e.mul(a,I),i),s=e.mul(a,e.sub(o,e.ONE));return R(e,s,t),s}function pe(e){let t=z(e),n=me(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+oe)/le;return(e,t)=>{let n=e.pow(t,o),s=e.mul(n,r),c=e.mul(n,i),l=e.mul(n,a),u=e.eql(e.sqr(s),t),d=e.eql(e.sqr(c),t);n=e.cmov(n,s,u),s=e.cmov(l,c,d);let f=e.eql(e.sqr(s),t),p=e.cmov(n,s,f);return R(e,p,t),p}}function me(e){if(e<re)throw Error(`sqrt is not defined for small field`);let t=e-F,n=0;for(;t%I===P;)t/=I,n++;let r=I,i=z(e);for(;be(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return de;let a=i.pow(r,t),o=(t+F)/I;return function(e,r){if(e.is0(r))return r;if(be(e,r)!==1)throw Error(`Cannot find square root`);let i=n,s=e.mul(e.ONE,a),c=e.pow(r,t),l=e.pow(r,o);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,n=e.sqr(c);for(;!e.eql(n,e.ONE);)if(t++,n=e.sqr(n),t===i)throw Error(`Cannot find square root`);let r=F<<BigInt(i-t-1),a=e.pow(s,r);i=t,s=e.sqr(a),c=e.mul(c,s),l=e.mul(l,a)}return l}}function he(e){return e%ie===re?de:e%se===ae?fe:e%le===ce?pe(e):me(e)}const ge=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function _e(e){return te(e,ge.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,MASK:`bigint`,BYTES:`number`,BITS:`number`})),e}function ve(e,t,n){if(n<P)throw Error(`invalid exponent, negatives unsupported`);if(n===P)return e.ONE;if(n===F)return t;let r=e.ONE,i=t;for(;n>P;)n&F&&(r=e.mul(r,i)),i=e.sqr(i),n>>=F;return r}function ye(e,t,n=!1){let r=Array(t.length).fill(n?e.ZERO:void 0),i=t.reduce((t,n,i)=>e.is0(n)?t:(r[i]=t,e.mul(t,n)),e.ONE),a=e.inv(i);return t.reduceRight((t,n,i)=>e.is0(n)?t:(r[i]=e.mul(t,r[i]),e.mul(t,n)),a),r}function be(e,t){let n=(e.ORDER-F)/I,r=e.pow(t,n),i=e.eql(r,e.ONE),a=e.eql(r,e.ZERO),o=e.eql(r,e.neg(e.ONE));if(!i&&!a&&!o)throw Error(`invalid Legendre symbol result`);return i?1:a?0:-1}function xe(e,t){t!==void 0&&s(t);let n=t===void 0?e.toString(2).length:t;return{nBitLength:n,nByteLength:Math.ceil(n/8)}}function z(e,t,n=!1,r={}){if(e<=P)throw Error(`invalid field: expected ORDER > 0, got `+e);let i,a,o=!1,s;if(typeof t==`object`&&t){if(r.sqrt||n)throw Error(`cannot specify opts in two arguments`);let e=t;e.BITS&&(i=e.BITS),e.sqrt&&(a=e.sqrt),typeof e.isLE==`boolean`&&(n=e.isLE),typeof e.modFromBytes==`boolean`&&(o=e.modFromBytes),s=e.allowedLengths}else typeof t==`number`&&(i=t),r.sqrt&&(a=r.sqrt);let{nBitLength:c,nByteLength:l}=xe(e,i);if(l>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);let u,d=Object.freeze({ORDER:e,isLE:n,BITS:c,BYTES:l,MASK:N(c),ZERO:P,ONE:F,allowedLengths:s,create:t=>L(t,e),isValid:t=>{if(typeof t!=`bigint`)throw Error(`invalid field element: expected bigint, got `+typeof t);return P<=t&&t<e},is0:e=>e===P,isValidNot0:e=>!d.is0(e)&&d.isValid(e),isOdd:e=>(e&F)===F,neg:t=>L(-t,e),eql:(e,t)=>e===t,sqr:t=>L(t*t,e),add:(t,n)=>L(t+n,e),sub:(t,n)=>L(t-n,e),mul:(t,n)=>L(t*n,e),pow:(e,t)=>ve(d,e,t),div:(t,n)=>L(t*ue(n,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>ue(t,e),sqrt:a||(t=>(u||=he(e),u(d,t))),toBytes:e=>n?D(e,l):E(e,l),fromBytes:(t,r=!0)=>{if(s){if(!s.includes(t.length)||t.length>l)throw Error(`Field.fromBytes: expected `+s+` bytes, got `+t.length);let e=new Uint8Array(l);e.set(t,n?0:e.length-t.length),t=e}if(t.length!==l)throw Error(`Field.fromBytes: expected `+l+` bytes, got `+t.length);let i=n?T(t):w(t);if(o&&(i=L(i,e)),!r&&!d.isValid(i))throw Error(`invalid field element: outside of range 0..ORDER`);return i},invertBatch:e=>ye(d,e),cmov:(e,t,n)=>n?t:e});return Object.freeze(d)}function Se(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);let t=e.toString(2).length;return Math.ceil(t/8)}function Ce(e){let t=Se(e);return t+Math.ceil(t/2)}function we(e,t,n=!1){let r=e.length,i=Se(t),a=Ce(t);if(r<16||r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=L(n?T(e):w(e),t-F)+F;return n?D(o,i):E(o,i)}
6
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
7
+ const B=BigInt(0),V=BigInt(1);function H(e,t){let n=t.negate();return e?n:t}function U(e,t){let n=ye(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Te(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function Ee(e,t){Te(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:N(e),maxNumber:i,shiftBy:BigInt(e)}}function De(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=V);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}function Oe(e,t){if(!Array.isArray(e))throw Error(`array expected`);e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function ke(e,t){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,n)=>{if(!t.isValid(e))throw Error(`invalid scalar at index `+n)})}const Ae=new WeakMap,je=new WeakMap;function Me(e){return je.get(e)||1}function Ne(e){if(e!==B)throw Error(`invalid wNAF`)}var Pe=class{constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>B;)t&V&&(n=n.add(r)),r=r.double(),t>>=V;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=Ee(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=Ee(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=De(n,e,a);n=o,c?i=i.add(H(u,t[d])):r=r.add(H(l,t[s]))}return Ne(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=Ee(e,this.bits);for(let e=0;e<i.windows&&n!==B;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=De(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return Ne(n),r}getPrecomputes(e,t,n){let r=Ae.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),Ae.set(t,r))),r}cached(e,t,n){let r=Me(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=Me(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){Te(t,this.bits),je.set(e,t),Ae.delete(e)}hasCache(e){return Me(e)!==1}};function Fe(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>B||r>B;)n&V&&(a=a.add(i)),r&V&&(o=o.add(i)),i=i.double(),n>>=V,r>>=V;return{p1:a,p2:o}}function Ie(e,t,n,r){Oe(n,e),ke(r,t);let i=n.length,a=r.length;if(i!==a)throw Error(`arrays of points and scalars must have equal length`);let o=e.ZERO,s=M(BigInt(i)),c=1;s>12?c=s-3:s>4?c=s-2:s>0&&(c=2);let l=N(c),u=Array(Number(l)+1).fill(o),d=Math.floor((t.BITS-1)/c)*c,f=o;for(let e=d;e>=0;e-=c){u.fill(o);for(let t=0;t<a;t++){let i=r[t],a=Number(i>>BigInt(e)&l);u[a]=u[a].add(n[t])}let t=o;for(let e=u.length-1,n=o;e>0;e--)n=n.add(u[e]),t=t.add(n);if(f=f.add(t),e!==0)for(let e=0;e<c;e++)f=f.double()}return f}function Le(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return _e(t),t}else return z(e,{isLE:n})}function Re(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>B))throw Error(`CURVE.${e} must be positive bigint`)}let i=Le(t.p,n.Fp,r),a=Le(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}
8
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
9
+ const ze=(e,t)=>(e+(e>=0?t:-t)/Ue)/t;function Be(e,t,n){let[[r,i],[a,o]]=t,s=ze(o*e,n),c=ze(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<G,f=u<G;d&&(l=-l),f&&(u=-u);let p=N(Math.ceil(M(n)/2))+K;if(l<G||l>=p||u<G||u>=p)throw Error(`splitScalar (endomorphism): failed, k=`+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}function Ve(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function He(e,t){let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return b(n.lowS,`lowS`),b(n.prehash,`prehash`),n.format!==void 0&&Ve(n.format),n}const W={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=W;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=S(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?S(i.length/2|128):``;return S(e)+a+i+t},decode(e,t){let{Err:n}=W,r=0;if(e<0||e>256)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=W;if(e<G)throw new t(`integer: negative integers are not allowed`);let n=S(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=W;if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return w(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=W,i=O(`signature`,e),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=W,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},G=BigInt(0),K=BigInt(1),Ue=BigInt(2),q=BigInt(3),We=BigInt(4);function J(e,t){let{BYTES:n}=e,r;if(typeof t==`bigint`)r=t;else{let i=O(`private key`,t);try{r=e.fromBytes(i)}catch{throw Error(`invalid private key: expected ui8a of size ${n}, got ${typeof t}`)}}if(!e.isValidNot0(r))throw Error(`invalid private key: out of range [1..N-1]`);return r}function Ge(e,t={}){let n=Re(`weierstrass`,e,t),{Fp:i,Fn:a}=n,o=n.CURVE,{h:s,n:c}=o;te(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`,wrapPrivateKey:`boolean`});let{endo:l}=t;if(l&&(!i.is0(o.a)||typeof l.beta!=`bigint`||!Array.isArray(l.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let u=qe(i,a);function d(){if(!i.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function f(e,t,n){let{x:a,y:o}=t.toAffine(),s=i.toBytes(a);return b(n,`isCompressed`),n?(d(),r(Ke(!i.isOdd(o)),s)):r(Uint8Array.of(4),s,i.toBytes(o))}function p(e){x(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=u,r=e.length,a=e[0],o=e.subarray(1);if(r===t&&(a===2||a===3)){let e=i.fromBytes(o);if(!i.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=_(e),n;try{n=i.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}d();let r=i.isOdd(n);return(a&1)==1!==r&&(n=i.neg(n)),{x:e,y:n}}else if(r===n&&a===4){let e=i.BYTES,t=i.fromBytes(o.subarray(0,e)),n=i.fromBytes(o.subarray(e,e*2));if(!v(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}else throw Error(`bad point: got length ${r}, expected compressed=${t} or uncompressed=${n}`)}let h=t.toBytes||f,g=t.fromBytes||p;function _(e){let t=i.sqr(e),n=i.mul(t,e);return i.add(i.add(n,i.mul(e,o.a)),o.b)}function v(e,t){let n=i.sqr(t),r=_(e);return i.eql(n,r)}if(!v(o.Gx,o.Gy))throw Error(`bad curve params: generator point`);let y=i.mul(i.pow(o.a,q),We),S=i.mul(i.sqr(o.b),BigInt(27));if(i.is0(i.add(y,S)))throw Error(`bad curve params: a or b`);function C(e,t,n=!1){if(!i.isValid(t)||n&&i.is0(t))throw Error(`bad point coordinate ${e}`);return t}function w(e){if(!(e instanceof A))throw Error(`ProjectivePoint expected`)}function T(e){if(!l||!l.basises)throw Error(`no endo`);return Be(e,l.basises,a.ORDER)}let E=ne((e,t)=>{let{X:n,Y:r,Z:a}=e;if(i.eql(a,i.ONE))return{x:n,y:r};let o=e.is0();t??=o?i.ONE:i.inv(a);let s=i.mul(n,t),c=i.mul(r,t),l=i.mul(a,t);if(o)return{x:i.ZERO,y:i.ZERO};if(!i.eql(l,i.ONE))throw Error(`invZ was invalid`);return{x:s,y:c}}),D=ne(e=>{if(e.is0()){if(t.allowInfinityPoint&&!i.is0(e.Y))return;throw Error(`bad point: ZERO`)}let{x:n,y:r}=e.toAffine();if(!i.isValid(n)||!i.isValid(r))throw Error(`bad point: x or y not field elements`);if(!v(n,r))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);return!0});function k(e,t,n,r,a){return n=new A(i.mul(n.X,e),n.Y,n.Z),t=H(r,t),n=H(a,n),t.add(n)}class A{constructor(e,t,n){this.X=C(`x`,e),this.Y=C(`y`,t,!0),this.Z=C(`z`,n),Object.freeze(this)}static CURVE(){return o}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!i.isValid(t)||!i.isValid(n))throw Error(`invalid affine point`);if(e instanceof A)throw Error(`projective point not allowed`);return i.is0(t)&&i.is0(n)?A.ZERO:new A(t,n,i.ONE)}static fromBytes(e){let t=A.fromAffine(g(x(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return A.fromBytes(O(`pointHex`,e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return M.createCache(this,e),t||this.multiply(q),this}assertValidity(){D(this)}hasEvenY(){let{y:e}=this.toAffine();if(!i.isOdd)throw Error(`Field doesn't support isOdd`);return!i.isOdd(e)}equals(e){w(e);let{X:t,Y:n,Z:r}=this,{X:a,Y:o,Z:s}=e,c=i.eql(i.mul(t,s),i.mul(a,r)),l=i.eql(i.mul(n,s),i.mul(o,r));return c&&l}negate(){return new A(this.X,i.neg(this.Y),this.Z)}double(){let{a:e,b:t}=o,n=i.mul(t,q),{X:r,Y:a,Z:s}=this,c=i.ZERO,l=i.ZERO,u=i.ZERO,d=i.mul(r,r),f=i.mul(a,a),p=i.mul(s,s),m=i.mul(r,a);return m=i.add(m,m),u=i.mul(r,s),u=i.add(u,u),c=i.mul(e,u),l=i.mul(n,p),l=i.add(c,l),c=i.sub(f,l),l=i.add(f,l),l=i.mul(c,l),c=i.mul(m,c),u=i.mul(n,u),p=i.mul(e,p),m=i.sub(d,p),m=i.mul(e,m),m=i.add(m,u),u=i.add(d,d),d=i.add(u,d),d=i.add(d,p),d=i.mul(d,m),l=i.add(l,d),p=i.mul(a,s),p=i.add(p,p),d=i.mul(p,m),c=i.sub(c,d),u=i.mul(p,f),u=i.add(u,u),u=i.add(u,u),new A(c,l,u)}add(e){w(e);let{X:t,Y:n,Z:r}=this,{X:a,Y:s,Z:c}=e,l=i.ZERO,u=i.ZERO,d=i.ZERO,f=o.a,p=i.mul(o.b,q),m=i.mul(t,a),h=i.mul(n,s),g=i.mul(r,c),_=i.add(t,n),v=i.add(a,s);_=i.mul(_,v),v=i.add(m,h),_=i.sub(_,v),v=i.add(t,r);let y=i.add(a,c);return v=i.mul(v,y),y=i.add(m,g),v=i.sub(v,y),y=i.add(n,r),l=i.add(s,c),y=i.mul(y,l),l=i.add(h,g),y=i.sub(y,l),d=i.mul(f,v),l=i.mul(p,g),d=i.add(l,d),l=i.sub(h,d),d=i.add(h,d),u=i.mul(l,d),h=i.add(m,m),h=i.add(h,m),g=i.mul(f,g),v=i.mul(p,v),h=i.add(h,g),g=i.sub(m,g),g=i.mul(f,g),v=i.add(v,g),m=i.mul(h,v),u=i.add(u,m),m=i.mul(y,v),l=i.mul(_,l),l=i.sub(l,m),m=i.mul(_,h),d=i.mul(y,d),d=i.add(d,m),new A(l,u,d)}subtract(e){return this.add(e.negate())}is0(){return this.equals(A.ZERO)}multiply(e){let{endo:n}=t;if(!a.isValidNot0(e))throw Error(`invalid scalar: out of range`);let r,i,o=e=>M.cached(this,e,e=>U(A,e));if(n){let{k1neg:t,k1:a,k2neg:s,k2:c}=T(e),{p:l,f:u}=o(a),{p:d,f}=o(c);i=u.add(f),r=k(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,i=n}return U(A,[r,i])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this;if(!a.isValid(e))throw Error(`invalid scalar: out of range`);if(e===G||r.is0())return A.ZERO;if(e===K)return r;if(M.hasCache(this))return this.multiply(e);if(n){let{k1neg:t,k1:i,k2neg:a,k2:o}=T(e),{p1:s,p2:c}=Fe(A,r,i,o);return k(n.beta,s,c,t,a)}else return M.unsafe(r,e)}multiplyAndAddUnsafe(e,t,n){let r=this.multiplyUnsafe(t).add(e.multiplyUnsafe(n));return r.is0()?void 0:r}toAffine(e){return E(this,e)}isTorsionFree(){let{isTorsionFree:e}=t;return s===K?!0:e?e(A,this):M.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:e}=t;return s===K?this:e?e(A,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(e=!0){return b(e,`isCompressed`),this.assertValidity(),h(A,this,e)}toHex(e=!0){return m(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(e=!0){return this.toBytes(e)}_setWindowSize(e){this.precompute(e)}static normalizeZ(e){return U(A,e)}static msm(e,t){return Ie(A,a,e,t)}static fromPrivateKey(e){return A.BASE.multiply(J(a,e))}}A.BASE=new A(o.Gx,o.Gy,i.ONE),A.ZERO=new A(i.ZERO,i.ONE,i.ZERO),A.Fp=i,A.Fn=a;let j=a.BITS,M=new Pe(A,t.endo?Math.ceil(j/2):j);return A.BASE.precompute(8),A}function Ke(e){return Uint8Array.of(e?2:3)}function qe(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Je(e,t={}){let{Fn:n}=e,r=t.randomBytes||a,i=Object.assign(qe(e.Fp,n),{seed:Ce(n.ORDER)});function o(e){try{return!!J(n,e)}catch{return!1}}function s(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!!e.fromBytes(t)}catch{return!1}}function c(e=r(i.seed)){return we(x(e,i.seed,`seed`),n.ORDER)}function l(t,r=!0){return e.BASE.multiply(J(n,t)).toBytes(r)}function u(e){let t=c(e);return{secretKey:t,publicKey:l(t)}}function d(t){if(typeof t==`bigint`)return!1;if(t instanceof e)return!0;let{secretKey:r,publicKey:a,publicKeyUncompressed:o}=i;if(n.allowedLengths||r===a)return;let s=O(`key`,t).length;return s===a||s===o}function f(t,r,i=!0){if(d(t)===!0)throw Error(`first arg must be private key`);if(d(r)===!1)throw Error(`second arg must be public key`);let a=J(n,t);return e.fromHex(r).multiply(a).toBytes(i)}return Object.freeze({getPublicKey:l,getSharedSecret:f,keygen:u,Point:e,utils:{isValidSecretKey:o,isValidPublicKey:s,randomSecretKey:c,isValidPrivateKey:o,randomPrivateKey:c,normPrivateKeyToScalar:e=>J(n,e),precompute(t=8,n=e.BASE){return n.precompute(t,!1)}},lengths:i})}function Ye(e,n,i={}){t(n),te(i,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`});let o=i.randomBytes||a,s=i.hmac||((e,...t)=>_(n,e,r(...t))),{Fp:l,Fn:u}=e,{ORDER:f,BITS:p}=u,{keygen:h,getPublicKey:g,getSharedSecret:v,utils:y,lengths:b}=Je(e,i),S={prehash:!1,lowS:typeof i.lowS==`boolean`?i.lowS:!1,format:void 0,extraEntropy:!1},C=`compact`;function T(e){return e>f>>K}function E(e,t){if(!u.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function D(e,t){Ve(t);let n=b.signature;return x(e,t===`compact`?n:t===`recovered`?n+1:void 0,`${t} signature`)}class k{constructor(e,t,n){this.r=E(`r`,e),this.s=E(`s`,t),n!=null&&(this.recovery=n),Object.freeze(this)}static fromBytes(e,t=C){D(e,t);let n;if(t===`der`){let{r:t,s:n}=W.toSig(x(e));return new k(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=u.BYTES,i=e.subarray(0,r),a=e.subarray(r,r*2);return new k(u.fromBytes(i),u.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(d(e),t)}addRecoveryBit(e){return new k(this.r,this.s,e)}recoverPublicKey(t){let n=l.ORDER,{r:i,s:a,recovery:o}=this;if(o==null||![0,1,2,3].includes(o))throw Error(`recovery id invalid`);if(f*Ue<n&&o>1)throw Error(`recovery id is ambiguous for h>1 curve`);let s=o===2||o===3?i+f:i;if(!l.isValid(s))throw Error(`recovery id 2 or 3 invalid`);let c=l.toBytes(s),d=e.fromBytes(r(Ke((o&1)==0),c)),p=u.inv(s),m=M(O(`msgHash`,t)),h=u.create(-m*p),g=u.create(a*p),_=e.BASE.multiplyUnsafe(h).add(d.multiplyUnsafe(g));if(_.is0())throw Error(`point at infinify`);return _.assertValidity(),_}hasHighS(){return T(this.s)}toBytes(e=C){if(Ve(e),e===`der`)return d(W.hexFromSig(this));let t=u.toBytes(this.r),n=u.toBytes(this.s);if(e===`recovered`){if(this.recovery==null)throw Error(`recovery bit must be present`);return r(Uint8Array.of(this.recovery),t,n)}return r(t,n)}toHex(e){return m(this.toBytes(e))}assertValidity(){}static fromCompact(e){return k.fromBytes(O(`sig`,e),`compact`)}static fromDER(e){return k.fromBytes(O(`sig`,e),`der`)}normalizeS(){return this.hasHighS()?new k(this.r,u.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes(`der`)}toDERHex(){return m(this.toBytes(`der`))}toCompactRawBytes(){return this.toBytes(`compact`)}toCompactHex(){return m(this.toBytes(`compact`))}}let A=i.bits2int||function(e){if(e.length>8192)throw Error(`input is too large`);let t=w(e),n=e.length*8-p;return n>0?t>>BigInt(n):t},M=i.bits2int_modN||function(e){return u.create(A(e))},ne=N(p);function P(e){return j(`num < 2^`+p,e,G,ne),u.toBytes(e)}function F(e,t){return x(e,void 0,`message`),t?x(n(e),void 0,`prehashed message`):e}function I(t,n,i){if([`recovered`,`canonical`].some(e=>e in i))throw Error(`sign() legacy options not supported`);let{lowS:a,prehash:s,extraEntropy:c}=He(i,S);t=F(t,s);let l=M(t),d=J(u,n),f=[P(d),P(l)];if(c!=null&&c!==!1){let e=c===!0?o(b.secretKey):c;f.push(O(`extraEntropy`,e))}let p=r(...f),m=l;function h(t){let n=A(t);if(!u.isValidNot0(n))return;let r=u.inv(n),i=e.BASE.multiply(n).toAffine(),o=u.create(i.x);if(o===G)return;let s=u.create(r*u.create(m+o*d));if(s===G)return;let c=(i.x===o?0:2)|Number(i.y&K),l=s;return a&&T(s)&&(l=u.neg(s),c^=1),new k(o,l,c)}return{seed:p,k2sig:h}}function re(e,t,r={}){e=O(`message`,e);let{seed:i,k2sig:a}=I(e,t,r);return ee(n.outputLen,u.BYTES,s)(i,a)}function ie(e){let t,n=typeof e==`string`||c(e),r=!n&&typeof e==`object`&&!!e&&typeof e.r==`bigint`&&typeof e.s==`bigint`;if(!n&&!r)throw Error(`invalid signature, expected Uint8Array, hex string or Signature instance`);if(r)t=new k(e.r,e.s);else if(n){try{t=k.fromBytes(O(`sig`,e),`der`)}catch(e){if(!(e instanceof W.Err))throw e}if(!t)try{t=k.fromBytes(O(`sig`,e),`compact`)}catch{return!1}}return t||!1}function ae(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=He(i,S);if(r=O(`publicKey`,r),n=F(O(`message`,n),o),`strict`in i)throw Error(`options.strict was renamed to lowS`);let c=s===void 0?ie(t):k.fromBytes(O(`sig`,t),s);if(c===!1)return!1;try{let t=e.fromBytes(r);if(a&&c.hasHighS())return!1;let{r:i,s:o}=c,s=M(n),l=u.inv(o),d=u.create(s*l),f=u.create(i*l),p=e.BASE.multiplyUnsafe(d).add(t.multiplyUnsafe(f));return p.is0()?!1:u.create(p.x)===i}catch{return!1}}function oe(e,t,n={}){let{prehash:r}=He(n,S);return t=F(t,r),k.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:h,getPublicKey:g,getSharedSecret:v,utils:y,lengths:b,Point:e,sign:re,verify:ae,recoverPublicKey:oe,Signature:k,hash:n})}function Xe(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},n=e.Fp,r=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(e=>Math.ceil(e/2)))):void 0;return{CURVE:t,curveOpts:{Fp:n,Fn:z(t.n,{BITS:e.nBitLength,allowedLengths:r,modFromBytes:e.wrapPrivateKey}),allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes}}}function Ze(e){let{CURVE:t,curveOpts:n}=Xe(e),r={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:n,hash:e.hash,ecdsaOpts:r}}function Qe(e,t){let n=t.Point;return Object.assign({},t,{ProjectivePoint:n,CURVE:Object.assign({},e,xe(n.Fn.ORDER,n.Fn.BITS))})}function $e(e){let{CURVE:t,curveOpts:n,hash:r,ecdsaOpts:i}=Ze(e);return Qe(e,Ye(Ge(t,n),r,i))}
10
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
11
+ function et(e,t){let n=t=>$e({...e,hash:t});return{...n(t),create:n}}
12
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
13
+ const tt={p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)},nt={p:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff`),n:BigInt(`0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973`),h:BigInt(1),a:BigInt(`0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc`),b:BigInt(`0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef`),Gx:BigInt(`0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7`),Gy:BigInt(`0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f`)},rt={p:BigInt(`0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`),n:BigInt(`0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409`),h:BigInt(1),a:BigInt(`0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc`),b:BigInt(`0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00`),Gx:BigInt(`0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66`),Gy:BigInt(`0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650`)},it=z(tt.p),at=z(nt.p),ot=z(rt.p),st=et({...tt,Fp:it,lowS:!1},l);et({...nt,Fp:at,lowS:!1},f),et({...rt,Fp:ot,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},o);
14
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
15
+ const ct=st,lt=[1116352408,1899447441,-1245643825,-373957723,961987163,1508970993,-1841331548,-1424204075,-670586216,310598401,607225278,1426881987,1925078388,-2132889090,-1680079193,-1046744716,-459576895,-272742522,264347078,604807628,770255983,1249150122,1555081692,1996064986,-1740746414,-1473132947,-1341970488,-1084653625,-958395405,-710438585,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,-2117940946,-1838011259,-1564481375,-1474664885,-1035236496,-949202525,-778901479,-694614492,-200395387,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,-2067236844,-1933114872,-1866530822,-1538233109,-1090935817,-965641998],ut={sha256:1};function dt(e){if(e&&!ut[e]&&!ut[e.toLowerCase()])throw Error(`Digest method not supported`);return new ft}var ft=class{constructor(){this.A=1779033703,this.B=-1150833019,this.C=1013904242,this.D=-1521486534,this.E=1359893119,this.F=-1694144372,this.G=528734635,this.H=1541459225,this._size=0,this._sp=0,(!X||Z>=8e3)&&(X=new ArrayBuffer(8e3),Z=0),this._byte=new Uint8Array(X,Z,80),this._word=new Int32Array(X,Z,20),Z+=80}update(e){if(typeof e==`string`)return this._utf8(e);if(e==null)throw TypeError(`Invalid type: `+typeof e);let t=e.byteOffset,n=e.byteLength,r=n/64|0,i=0;if(r&&!(t&3)&&!(this._size%64)){let n=new Int32Array(e.buffer,t,r*16);for(;r--;)this._int32(n,i>>2),i+=64;this._size+=i}if(e.BYTES_PER_ELEMENT!==1&&e.buffer){let r=new Uint8Array(e.buffer,t+i,n-i);return this._uint8(r)}return i===n?this:this._uint8(e,i)}_uint8(e,t){let{_byte:n,_word:r}=this,i=e.length;for(t|=0;t<i;){let a=this._size%64,o=a;for(;t<i&&o<64;)n[o++]=e[t++];o>=64&&this._int32(r),this._size+=o-a}return this}_utf8(e){let{_byte:t,_word:n}=this,r=e.length,i=this._sp;for(let a=0;a<r;){let o=this._size%64,s=o;for(;a<r&&s<64;){let n=e.charCodeAt(a++)|0;n<128?t[s++]=n:n<2048?(t[s++]=192|n>>>6,t[s++]=128|n&63):n<55296||n>57343?(t[s++]=224|n>>>12,t[s++]=128|n>>>6&63,t[s++]=128|n&63):i?(n=((i&1023)<<10)+(n&1023)+65536,t[s++]=240|n>>>18,t[s++]=128|n>>>12&63,t[s++]=128|n>>>6&63,t[s++]=128|n&63,i=0):i=n}s>=64&&(this._int32(n),n[0]=n[16]),this._size+=s-o}return this._sp=i,this}_int32(e,t){let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this,u=0;for(t|=0;u<16;)Y[u++]=$(e[t++]);for(u=16;u<64;u++)Y[u]=vt(Y[u-2])+Y[u-7]+_t(Y[u-15])+Y[u-16]|0;for(u=0;u<64;u++){let e=l+gt(o)+pt(o,s,c)+lt[u]+Y[u]|0,t=ht(n)+mt(n,r,i)|0;l=c,c=s,s=o,o=a+e|0,a=i,i=r,r=n,n=e+t|0}this.A=n+this.A|0,this.B=r+this.B|0,this.C=i+this.C|0,this.D=a+this.D|0,this.E=o+this.E|0,this.F=s+this.F|0,this.G=c+this.G|0,this.H=l+this.H|0}digest(e){let{_byte:t,_word:n}=this,r=this._size%64|0;for(t[r++]=128;r&3;)t[r++]=0;if(r>>=2,r>14){for(;r<16;)n[r++]=0;r=0,this._int32(n)}for(;r<16;)n[r++]=0;let i=this._size*8,a=(i&4294967295)>>>0,o=(i-a)/4294967296;return o&&(n[14]=$(o)),a&&(n[15]=$(a)),this._int32(n),e===`hex`?this._hex():this._bin()}_hex(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return Q(e)+Q(t)+Q(n)+Q(r)+Q(i)+Q(a)+Q(o)+Q(s)}_bin(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s,_byte:c,_word:l}=this;return l[0]=$(e),l[1]=$(t),l[2]=$(n),l[3]=$(r),l[4]=$(i),l[5]=$(a),l[6]=$(o),l[7]=$(s),c.slice(0,32)}};const Y=new Int32Array(64);let X,Z=0;const Q=e=>(e+4294967296).toString(16).substr(-8),$=yt()?(e=>e):(e=>e<<24&4278190080|e<<8&16711680|e>>8&65280|e>>24&255),pt=(e,t,n)=>n^e&(t^n),mt=(e,t,n)=>e&t|n&(e|t),ht=e=>(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),gt=e=>(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7),_t=e=>(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3,vt=e=>(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10;function yt(){return new Uint8Array(new Uint16Array([65279]).buffer)[0]===254}const bt=async e=>{let t=h(ct.getPublicKey(e.privateKey,!0));if(t!=e.publicKey)throw Error(`Bad API key. Expected to get public key ${e.publicKey}, got ${t}`);let n=dt().update(e.content).digest();return ct.sign(n,e.privateKey).toDERHex()};export{bt as signWithApiKey};
@@ -0,0 +1 @@
1
+ import{_ as e,t,v as n}from"./index.mjs";function r(r){let{uncompressedPrivateKeyHex:i,compressedPublicKeyHex:a}=r,o;try{o=t(n(a))}catch{throw Error(`unable to load API key: invalid public key. Did you switch your public and private key by accident? Is your public key a valid, compressed P-256 public key?`)}return o.d=e(i,32),o}export{r as t};
@@ -0,0 +1 @@
1
+ import{y as e}from"./index.mjs";import{t}from"./utils-CGVgWgFq.mjs";const n=async e=>{let{content:t,publicKey:n,privateKey:a}=e;return await i({key:await r({uncompressedPrivateKeyHex:a,compressedPublicKeyHex:n}),content:t})};async function r(e){let{uncompressedPrivateKeyHex:n,compressedPublicKeyHex:r}=e,i=t({uncompressedPrivateKeyHex:n,compressedPublicKeyHex:r});return await crypto.subtle.importKey(`jwk`,i,{name:`ECDSA`,namedCurve:`P-256`},!1,[`sign`])}async function i(t){let{key:n,content:r}=t,i=await crypto.subtle.sign({name:`ECDSA`,hash:`SHA-256`},n,new TextEncoder().encode(r));return e(a(new Uint8Array(i)))}function a(e){if(e.length%2!=0||e.length==0||e.length>132)throw Error(`Invalid IEEE P1363 signature encoding. Length: `+e.length);let t=o(e.subarray(0,e.length/2)),n=o(e.subarray(e.length/2,e.length)),r=0,i=2+t.length+1+1+n.length,a;return i>=128?(a=new Uint8Array(i+3),a[r++]=48,a[r++]=129,a[r++]=i):(a=new Uint8Array(i+2),a[r++]=48,a[r++]=i),a[r++]=2,a[r++]=t.length,a.set(t,r),r+=t.length,a[r++]=2,a[r++]=n.length,a.set(n,r),a}function o(e){let t=0;for(;t<e.length&&e[t]==0;)t++;t==e.length&&(t=e.length-1);let n=0;(e[t]&128)==128&&(n=1);let r=new Uint8Array(e.length-t+n);return r.set(e.subarray(t),n),r}export{n as signWithApiKey};
package/package.json CHANGED
@@ -1,9 +1,43 @@
1
1
  {
2
2
  "name": "@catena/cli",
3
- "version": "0.0.0-bootstrap.0",
4
- "description": "Bootstrap placeholder for Catena CLI trusted publishing setup.",
3
+ "version": "0.0.2",
4
+ "description": "Catena CLI for agent runtimes",
5
+ "homepage": "https://catena.com/",
5
6
  "license": "Apache-2.0",
7
+ "bin": {
8
+ "catena": "./dist/index.mjs"
9
+ },
6
10
  "files": [
11
+ "dist",
12
+ "LICENSE",
7
13
  "README.md"
8
- ]
9
- }
14
+ ],
15
+ "type": "module",
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "dependencies": {
20
+ "citty": "0.2.2",
21
+ "semver": "7.8.4",
22
+ "valibot": "1.4.1"
23
+ },
24
+ "devDependencies": {
25
+ "@types/semver": "7.7.1",
26
+ "publint": "0.3.21",
27
+ "tsdown": "0.22.2",
28
+ "tsx": "4.22.4",
29
+ "@bank/agent-client": "0.1.0",
30
+ "@bank/money": "0.1.0",
31
+ "@bank/shared": "0.1.0"
32
+ },
33
+ "engines": {
34
+ "node": ">=20"
35
+ },
36
+ "scripts": {
37
+ "build": "tsdown",
38
+ "clean": "git clean -xdf dist node_modules/.cache",
39
+ "dev": "CATENA_API_URL=http://localhost:3456 tsx src/index.ts",
40
+ "publint": "pnpm run build && publint --pack pnpm --strict",
41
+ "verify:pack": "pnpm run publint && tsx bin/verify-pack.ts"
42
+ }
43
+ }