@wovin/connect-ucan-store-proxy 0.0.13 → 0.0.15

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.
@@ -1,2 +1,2 @@
1
- import{a,d as p,e as m}from"./chunk-R5T56SIO.min.js";import{c as d}from"./chunk-U6LK5UQW.min.js";function y({name:e,code:t,encode:r}){return new c(e,t,r)}var c=class{name;code;encode;constructor(t,r,i){this.name=t,this.code=r,this.encode=i}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?a(this.code,r):r.then(i=>a(this.code,i))}else throw Error("Unknown type, must be binary type")}};var{WARN:x,LOG:b,DEBUG:g,VERBOSE:j,ERROR:u}=m.setup(m.INFO);async function L(e,t,r,{ucans:i}){e=d(e);let s;try{s=await fetch(`${e}/upload`,{method:"PUT",headers:{Authorization:`Bearer ${r.toString()}`,Accept:"application/json","Content-Type":"application/car","x-agent-did":r.issuer.did,ucans:i?.join(", ")},body:t,mode:"cors"})}catch(n){throw u("Failed to upload to ucan proxy:",n),n.message?.includes("net::ERR_CERT_AUTHORITY_INVALID"),n}let o=await s.json();if(!s.ok)throw u("[storeCar] failed:",o?.error||o||s,{result:o,response:s});g("[storeCar] result",{response:s,result:o});let f=o.Type==="error"?o.Message:o.Root.PinErrorMsg;return f&&x("Pin error:",f,{result:o}),p.parse(o.Root.Cid["/"])}export{y as a,L as b};
2
- //# sourceMappingURL=chunk-ULU4ARX5.min.js.map
1
+ import{a,d as p,e as m}from"./chunk-OWXA5F6K.min.js";import{c as d}from"./chunk-EHSVSU5O.min.js";function y({name:e,code:t,encode:r}){return new c(e,t,r)}var c=class{name;code;encode;constructor(t,r,i){this.name=t,this.code=r,this.encode=i}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?a(this.code,r):r.then(i=>a(this.code,i))}else throw Error("Unknown type, must be binary type")}};var{WARN:x,LOG:b,DEBUG:g,VERBOSE:j,ERROR:u}=m.setup(m.INFO);async function L(e,t,r,{ucans:i}){e=d(e);let s;try{s=await fetch(`${e}/upload`,{method:"PUT",headers:{Authorization:`Bearer ${r.toString()}`,Accept:"application/json","Content-Type":"application/car","x-agent-did":r.issuer.did,ucans:i?.join(", ")},body:t,mode:"cors"})}catch(n){throw u("Failed to upload to ucan proxy:",n),n.message?.includes("net::ERR_CERT_AUTHORITY_INVALID"),n}let o=await s.json();if(!s.ok)throw u("[storeCar] failed:",o?.error||o||s,{result:o,response:s});g("[storeCar] result",{response:s,result:o});let f=o.Type==="error"?o.Message:o.Root.PinErrorMsg;return f&&x("Pin error:",f,{result:o}),p.parse(o.Root.Cid["/"])}export{y as a,L as b};
2
+ //# sourceMappingURL=chunk-T4F3ZRAG.min.js.map
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { type StorageConnector } from '@wovin/core/pubsub';
3
3
  import { ISigner } from 'iso-signatures/types';
4
4
  import { CID } from 'multiformats';
5
5
  import { resolveIPNS, retrieveThread } from './retrieve';
6
- import { ParametersExceptFirst } from './utils';
6
+ import { ClassFields, ParametersExceptFirst } from './utils';
7
7
  export * from './retrieve';
8
8
  export * from './store';
9
9
  export declare class UcanStoreProxyConnector implements StorageConnector {
@@ -12,12 +12,20 @@ export declare class UcanStoreProxyConnector implements StorageConnector {
12
12
  private tmpKey;
13
13
  private ucanList;
14
14
  gatewayBaseUrl: string;
15
- static init({ url, issuerKey, ucanList }: {
15
+ nameBaseUrl?: string;
16
+ static init({ url, issuerKey, ucanList, ...restConfig }: Partial<Pick<UcanStoreProxyConnector, ClassFields<UcanStoreProxyConnector>>> & {
16
17
  url: string;
17
18
  issuerKey: ISigner<any>;
18
19
  ucanList?: UCAN[];
19
- }): Promise<UcanStoreProxyConnector>;
20
- constructor(baseUrl: string, issuerKey: ISigner<any>, tmpKey: ISigner<any>, ucanList?: UCAN[], gatewayBaseUrl?: string);
20
+ }): Promise<UcanStoreProxyConnector & {
21
+ nameBaseUrl?: string;
22
+ baseUrl?: string;
23
+ gatewayBaseUrl?: string;
24
+ isSetup?: boolean;
25
+ isValid?: boolean;
26
+ }>;
27
+ constructor(baseUrl: string, issuerKey: ISigner<any>, tmpKey: ISigner<any>, ucanList?: UCAN[], gatewayBaseUrl?: string, // TODO: query baseURL from ucan proxy?
28
+ nameBaseUrl?: string);
21
29
  get isSetup(): boolean;
22
30
  get isValid(): boolean;
23
31
  storeCar(car: Blob): Promise<CID<unknown, number, number, import("multiformats").Version>>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAE1C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAI1D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,WAAW,EAAe,cAAc,EAAE,MAAM,YAAY,CAAA;AAErE,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAI/C,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AAEvB,qBAAa,uBAAwB,YAAW,gBAAgB;IA2BvD,OAAO,EAAE,MAAM;IACtB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ;IACT,cAAc,EAAE,MAAM;WA9BjB,IAAI,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;QAC/C,GAAG,EAAE,MAAM,CAAA;QACX,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;QACvB,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAA;KACjB;gBAsBO,OAAO,EAAE,MAAM,EACd,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,EACvB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,EACpB,QAAQ,GAAE,IAAI,EAAO,EACtB,cAAc,GAAE,MAAgB;IAIxC,IAAI,OAAO,YAEV;IACD,IAAI,OAAO,YAEV;IAEK,QAAQ,CAAC,GAAG,EAAE,IAAI;IAsBlB,WAAW,CAAC,GAAG,EAAE,GAAG;IAKpB,cAAc,CACnB,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,cAAc,CAAC;;;;;IAKhD,WAAW,CAChB,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,WAAW,CAAC;CAKnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAE1C,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAI1D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,WAAW,EAAe,cAAc,EAAE,MAAM,YAAY,CAAA;AAErE,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAI5D,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AAEvB,qBAAa,uBAAwB,YAAW,gBAAgB;IA6BvD,OAAO,EAAE,MAAM;IACtB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ;IACT,cAAc,EAAE,MAAM;IACtB,WAAW,CAAC,EAAE,MAAM;WAjCf,IAAI,CAChB,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,uBAAuB,EAAE,WAAW,CAAC,uBAAuB,CAAC,CAAC,CAAC,GAAG;QAC3H,GAAG,EAAE,MAAM,CAAA;QACX,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;QACvB,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAA;KACjB;sBA4BoB,MAAM;kBALX,MAAM;yBAIC,MAAM;;;;gBAJtB,OAAO,EAAE,MAAM,EACd,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,EACvB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,EACpB,QAAQ,GAAE,IAAI,EAAO,EACtB,cAAc,GAAE,MAAgB,EAAE,uCAAuC;IACzE,WAAW,CAAC,EAAE,MAAM;IAI5B,IAAI,OAAO,YAEV;IACD,IAAI,OAAO,YAEV;IAEK,QAAQ,CAAC,GAAG,EAAE,IAAI;IAsBlB,WAAW,CAAC,GAAG,EAAE,GAAG;IAKpB,cAAc,CACnB,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,cAAc,CAAC;;;;;IAKhD,WAAW,CAChB,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,WAAW,CAAC;CAKnD"}
package/dist/index.min.js CHANGED
@@ -1,4 +1,4 @@
1
- import{a as Ke,b as Ue,c as Ie}from"./chunk-4WKM2MPH.min.js";import{a as fe,b as Pe}from"./chunk-ULU4ARX5.min.js";import{c as z,d as Z,e as ue}from"./chunk-R5T56SIO.min.js";import{a as mt,b as gt}from"./chunk-U6LK5UQW.min.js";var He=mt((Fn,Je)=>{"use strict";function nn(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var r=0;r<t.length;r++){var s=t.charAt(r),o=s.charCodeAt(0);if(e[o]!==255)throw new TypeError(s+" is ambiguous");e[o]=r}var i=t.length,c=t.charAt(0),f=Math.log(i)/Math.log(256),d=Math.log(256)/Math.log(i);function u(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var h=0,_=0,m=0,b=l.length;m!==b&&l[m]===0;)m++,h++;for(var v=(b-m)*d+1>>>0,w=new Uint8Array(v);m!==b;){for(var S=l[m],D=0,A=v-1;(S!==0||D<_)&&A!==-1;A--,D++)S+=256*w[A]>>>0,w[A]=S%i>>>0,S=S/i>>>0;if(S!==0)throw new Error("Non-zero carry");_=D,m++}for(var B=v-_;B!==v&&w[B]===0;)B++;for(var G=c.repeat(h);B<v;++B)G+=t.charAt(w[B]);return G}function p(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;for(var h=0,_=0,m=0;l[h]===c;)_++,h++;for(var b=(l.length-h)*f+1>>>0,v=new Uint8Array(b);l[h];){var w=e[l.charCodeAt(h)];if(w===255)return;for(var S=0,D=b-1;(w!==0||S<m)&&D!==-1;D--,S++)w+=i*v[D]>>>0,v[D]=w%256>>>0,w=w/256>>>0;if(w!==0)throw new Error("Non-zero carry");m=S,h++}for(var A=b-m;A!==b&&v[A]===0;)A++;for(var B=new Uint8Array(_+(b-A)),G=_;A!==b;)B[G++]=v[A++];return B}function y(l){var h=p(l);if(h)return h;throw new Error("Non-base"+i+" character")}return{encode:u,decodeUnsafe:p,decode:y}}Je.exports=nn});var Ce=["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"],bt=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Blob","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","WeakRef","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","FormData","URLSearchParams","HTMLElement","NaN",...Ce];function wt(t){return Ce.includes(t)}function xt(t){return bt.includes(t)}function Me(t){let e=toString.call(t).slice(8,-1);if(xt(e))return e}function Et(t){function e(n){return Me(n)===t}return e}function _t(t){return wt(Me(t))}var vt=Et("ArrayBuffer");function k(t){return _t(t)||vt(t)}function R(t){return ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}function de(t,e="utf8"){return ArrayBuffer.isView(t)?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength):typeof t=="string"?globalThis.Buffer.from(t,e):globalThis.Buffer.from(t)}function le(t,e){e||(e=t.reduce((s,o)=>s+o.length,0));let n=new Uint8Array(e),r=0;for(let s of t)n.set(s,r),r+=s.length;return n}function $e(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let n=0;n<t.byteLength;n++)if(t[n]!==e[n])return!1;return!0}var At=new TextDecoder,St=new TextEncoder,x={encode(t){return typeof t=="string"?t:globalThis.Buffer?de(t).toString("utf8"):At.decode(t)},decode(t){return k(t)?R(t):globalThis.Buffer?R(de(t)):St.encode(t)}};var Bt=(t,e,n)=>{let r={};for(let d=0;d<e.length;++d)r[e[d]]=d;let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*n/8|0),i=0,c=0,f=0;for(let d=0;d<s;++d){let u=r[t[d]];if(u===void 0)throw new SyntaxError("Invalid character "+t[d]);c=c<<n|u,i+=n,i>=8&&(i-=8,o[f++]=255&c>>i)}if(i>=n||255&c<<8-i)throw new SyntaxError("Unexpected end of data");return o},Rt=(t,e,n,r)=>{let s=(1<<n)-1,o="",i=0,c=0;for(let f=0;f<t.length;++f)for(c=c<<8|t[f],i+=8;i>n;)i-=n,o+=e[s&c>>i];if(i&&(o+=e[s&c<<n-i]),r)for(;o.length*n&7;)o+="=";return o},Dt={base2:[1,"01"],base8:[3,"01234567"],hex:[4,"0123456789abcdef"],base16:[4,"0123456789ABCDEF"],base32:[5,"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],base32hex:[5,"0123456789ABCDEFGHIJKLMNOPQRSTUV"],base64:[6,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],base64url:[6,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"]};function U(t,e=!1,n){let[r,s]=Dt[t];return{encode(o,i){return typeof o=="string"&&(n&&(o=n(o)),o=x.decode(o)),Rt(R(o),s,r,i??e)},decode(o){return k(o)&&(o=x.encode(o)),n&&(o=n(o)),Bt(o,s,r)}}}var Rn=U("hex",!0,t=>t.toLowerCase()),Dn=U("base2"),Tn=U("base8"),Kn=U("base16"),Un=U("base32"),In=U("base32hex",!0),Ne=U("base64"),pe=U("base64",!0),I=U("base64url",!1);function Oe(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var he=fe({name:"sha2-256",code:18,encode:Oe("SHA-256")}),Mn=fe({name:"sha2-512",code:19,encode:Oe("SHA-512")});var ye=85;function Tt(t,e){try{var n=t()}catch(r){return e(r)}return n&&n.then?n.then(void 0,e):n}function Kt(){let t=new Map;return function(e,n){try{let o=function(c){if(s)return c;let f=t.get(e.didUrl);return f!==void 0?f:Promise.resolve(n()).then(function(d){var u;return((u=d.didResolutionMetadata)==null?void 0:u.error)!=="notFound"&&t.set(e.didUrl,d),d})};var r=o;let s,i=function(){if(e.params&&e.params["no-cache"]==="true")return Promise.resolve(n()).then(function(c){return s=1,c})}();return Promise.resolve(i&&i.then?i.then(o):o(i))}catch(s){return Promise.reject(s)}}}function Ut(t,e){return e()}var It="(?:%[0-9a-fA-F]{2})",ke=`(?:[a-zA-Z0-9._-]|${It})`,Pt="([a-z0-9]+)",Ct=`((?:${ke}*:)*(${ke}+))`,Le="[a-zA-Z0-9_.:%-]",Mt=`;${Le}+=${Le}*`,$t=`((${Mt})*)`,Nt="(/[^#?]*)?",Ot="([?][^#]*)?",kt="(#.*)?",Lt=new RegExp(`^did:${Pt}:${Ct}${$t}${Nt}${Ot}${kt}$`);function me(t){if(t===""||!t)return null;let e=t.match(Lt);if(e){let n={did:`did:${e[1]}:${e[2]}`,method:e[1],id:e[2],didUrl:t};if(e[4]){let r=e[4].slice(1).split(";");n.params={};for(let s of r){let o=s.split("=");n.params[o[0]]=o[1]}}return e[6]&&(n.path=e[6]),e[7]&&(n.query=e[7].slice(1)),e[8]&&(n.fragment=e[8].slice(1)),n}return null}var j={didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}};function Yt(t){return function(e,n,r){try{return Promise.resolve(Tt(function(){return Promise.resolve(t(e,n,r)).then(function(s){return{...j,didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:s}})},function(s){return{...j,didResolutionMetadata:{error:"notFound",message:s.toString()}}}))}catch(s){return Promise.reject(s)}}}var q=class{constructor(e={},n={}){this.registry=void 0,this.cache=void 0,this.registry=e,this.cache=n.cache===!0?Kt():n.cache||Ut,n.legacyResolvers&&Object.keys(n.legacyResolvers).map(r=>{this.registry[r]||(this.registry[r]=Yt(n.legacyResolvers[r]))})}resolve(e,n={}){try{let r=this,s=me(e);if(s===null)return Promise.resolve({...j,didResolutionMetadata:{error:"invalidDid"}});let o=r.registry[s.method];return o?Promise.resolve(r.cache(s,()=>o(s.did,s,r,n))):Promise.resolve({...j,didResolutionMetadata:{error:"unsupportedDidMethod"}})}catch(r){return Promise.reject(r)}}};var Ft=Math.pow(2,31);function Fe(t,e,n=0){e=e||[];let r=n;for(;t>=Ft;)e[n++]=t&255|128,t/=128;for(;t&-128;)e[n++]=t&255|128,t>>>=7;return e[n]=t|0,Fe.bytes=n-r+1,e}var zt=128,Ye=127;function Jt(t,e=0){let n=0,r=0,s=e,o,i=0,c=t.length;do{if(s>=c)throw i=0,new RangeError("Could not decode varint");o=t[s++],n+=r<28?(o&Ye)<<r:(o&Ye)*Math.pow(2,r),r+=7}while(o>=zt);return i=s-e,[n,i]}var Ht=Math.pow(2,7),Vt=Math.pow(2,14),Gt=Math.pow(2,21),Zt=Math.pow(2,28),jt=Math.pow(2,35),qt=Math.pow(2,42),Wt=Math.pow(2,49),Xt=Math.pow(2,56),Qt=Math.pow(2,63),en=function(t){return t<Ht?1:t<Vt?2:t<Gt?3:t<Zt?4:t<jt?5:t<qt?6:t<Wt?7:t<Xt?8:t<Qt?9:10},M={encode:Fe,decode:Jt,encodingLength:en};function W(t,e){let n=M.encodingLength(t),r=new Uint8Array(e.byteLength+n);return M.encode(t,r,0),r.set(e,n),r}function ze(t,e){let[n,r]=M.decode(e);if(n===t)return new Uint8Array(e.buffer,e.byteOffset+r,e.byteLength-r);throw new Error(`Expected multiformat with codec 0x${t.toString(16)} tag instead got 0x${n.toString(16)}`)}var ge=gt(He(),1);var rn={base10:"0123456789",base36:"0123456789abcdefghijklmnopqrstuvwxyz",base58btc:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"};function be(t){let e=rn[t];return{encode(n,r){return typeof n=="string"&&(n=x.decode(n)),(0,ge.default)(e).encode(R(n))},decode(n){return k(n)&&(n=x.encode(n)),(0,ge.default)(e).decode(n)}}}var on=be("base10"),Hn=be("base36"),Vn=be("base58btc");function X(t){return t[0]===2||t[0]===3}function J(t){return t[0]===4}function Q(t){if(!J(t))throw new Error("Expected first byte to be 0x04, meaning uncompressed key.");let e=t.subarray(1),n=e.subarray(0,e.length/2),r=e.subarray(e.length/2,e.length),s=new Uint8Array(n.length+1);return s[0]=2+(r[r.length-1]&1),s.set(n,1),s}var cn={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K",RSA:"RS256"};var P={Ed25519:237,RSA:4613,"P-256":4608,"P-384":4609,"P-521":4610,secp256k1:231},ee={237:"Ed25519",4613:"RSA",4608:"P-256",4609:"P-384",4610:"P-521",231:"secp256k1"};function L(t){let e=cn[t];if(!e)throw new TypeError(`Unsupported key type ${t}`);return e}var $=class t{constructor(e){this.did=e.did,this.didUrl=e.didUrl,this.method=e.method,this.id=e.id,this.path=e.path,this.fragment=e.fragment,this.query=e.query}static fromString(e){let n=me(e);if(n)return new t(n);throw new TypeError(`Invalid DID "${e}"`)}toString(){return this.didUrl}};var Ve="did:key:";function te(t,e){switch(t){case P.secp256k1:{if(e.length!==33)throw new RangeError("Secp256k1 public keys must be 33 bytes.");return e}case P.Ed25519:{if(e.length!==32)throw new RangeError("ed25519 public keys must be 32 bytes.");return e}case P["P-256"]:{if(J(e)&&(e=Q(e)),X(e)&&e.length!==33)throw new RangeError("p256 public keys must be 33 bytes.");return e}case P["P-384"]:{if(J(e)&&(e=Q(e)),X(e)&&e.length!==49)throw new RangeError("p384 public keys must be 49 bytes.");return e}case P["P-521"]:{if(J(e)&&(e=Q(e)),X(e)&&e.length!==67)throw new RangeError("p521 public keys must be 67 bytes.");return e}case P.RSA:{if(e.length!==270&&e.length!==526)throw new RangeError("RSA public keys must be 270 bytes for 2048 bits or 526 bytes for 4096 bits.");return e}default:throw new RangeError(`Unsupported DID encoding, unknown multicode 0x${t.toString(16)}.`)}}var T=class t extends ${constructor(e,n,r){super(e),this.type=n,this.publicKey=r,this.code=P[n],this.alg=L(n),this.url=e,this.didKey=e.did}static fromString(e){let n=$.fromString(e);if(n.method==="key"){let r=z.decode(n.id),[s,o]=M.decode(r),i=te(s,r.slice(o));return new t(n,ee[s],i)}else throw new TypeError(`Invalid DID "${n}", method must be 'key'`)}static fromPublicKey(e,n){let r=P[e];if(!r)throw new TypeError(`Unsupported key type "${e}"`);let s=te(r,R(n)),o=z.encode(W(r,s));return new t({did:`${Ve}${o}`,didUrl:`${Ve}${o}`,id:o,method:"key"},e,s)}get document(){let e=`${this.did}#${this.id}`;return{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1"],id:this.did,verificationMethod:[{id:e,type:"MultiKey",controller:this.did,publicKeyMultibase:this.id}],authentication:[e],assertionMethod:[e],capabilityDelegation:[e],capabilityInvocation:[e]}}};async function an(t,e){let n=T.fromString(t);return{didDocumentMetadata:{},didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:n.document}}var Ge={key:an};async function un(t,e={}){let r=await new q({...Ge,...e.resolvers},{cache:e.cache??!0}).resolve(t,{accept:"application/did+ld+json"});if(r.didResolutionMetadata.error)throw new Error(r.didResolutionMetadata.error);return r.didDocument}function we(t){return $.fromString(t)}function dn(t,e){let n=t.fragment??t.id,r;return e.verificationMethod&&(r=e.verificationMethod.find(s=>s.id===`${t.did}#${n}`)),!r&&e.authentication&&(r=e.authentication.find(s=>typeof s!="string"&&s.id===`${t.did}#${n}`)),r}var ne=class t{constructor(e){this.did=e.did,this.publicKey=e.publicKey,this.alg=e.alg,this.type=e.type,this.document=e.document,this.url=e.url,this.didKey=T.fromPublicKey(e.type,e.publicKey).url.did}static async fromString(e,n={}){let r=we(e),s=await un(r.did,n),o=dn(r,s);if(!o)throw new Error(`No verification method found for ${e}`);if(o.type==="MultiKey"){let i=z.decode(o.publicKeyMultibase),[c,f]=M.decode(i),d=te(c,i.slice(f)),u=ee[c];return new t({did:r.did,alg:L(u),type:u,publicKey:d,url:r,document:s})}if(o.publicKeyJwk&&o.publicKeyJwk.kty==="OKP"){let i=I.decode(o.publicKeyJwk.x),c=o.publicKeyJwk.crv,f=L(c);return new t({did:r.did,alg:f,type:c,publicKey:i,url:r,document:s})}if(o.publicKeyJwk&&o.publicKeyJwk.kty==="EC"){let i=o.publicKeyJwk.crv,c=T.fromPublicKey(i,le([[4],I.decode(o.publicKeyJwk.x),I.decode(o.publicKeyJwk.y)])),f=L(i);return new t({did:r.did,alg:f,type:i,publicKey:c.publicKey,url:r,document:s})}throw new Error(`Unsupported verification method type "${o.type}"`)}toString(){return this.url.didUrl}};function Ze(t){return I.encode(x.decode(JSON.stringify(t)))}function je(t){let e;try{let n=I.decode(t);e=x.encode(n)}catch{throw new Error(`Can't parse: ${t}: Can't parse as base64url.`)}try{return JSON.parse(e)}catch{throw new Error(`Can't parse: ${t}: Can't parse base64url encoded JSON inside.`)}}async function qe(t,e){let n={alg:t.issuer.alg,typ:"JWT"},r={aud:t.audience,iss:t.issuer.did,cap:t.capabilities,exp:t.expiration,ucv:t.version,fct:t.facts,prf:t.proofs?.map(f=>f.toString()),nbf:t.notBefore,nnc:t.nonce},s=`${Ze(n)}.${Ze(r)}`,o=await e.sign(x.decode(s)),i=`${s}.${I.encode(o)}`,c=x.decode(i);return{ucan:i,signature:o,bytes:c,cid:Z.create(1,ye,await he.digest(c))}}async function We(t){let[e,n,r]=t.split(".");if(e===void 0||n===void 0||r===void 0)throw new Error(`Can't parse UCAN: ${t}: Expected JWT format: 3 dot-separated base64url-encoded values.`);let s=je(e);if(s.typ!=="JWT")throw new Error(`Expected type "JWT" got ${s.typ}.`);let o=je(n),i=await ne.fromString(o.iss);if(s.alg!==i.alg)throw new Error(`Expected signature algorithm "${i.alg}" got ${s.alg}.`);let c=I.decode(r),f=x.decode(t);return{props:{audience:we(o.aud).did,issuer:i,capabilities:o.cap,expiration:o.exp,version:o.ucv,facts:o.fct,proofs:o.prf?.map(d=>Z.parse(d)),notBefore:o.nbf,nonce:o.nnc},artifacts:{signature:c,ucan:t,bytes:f,cid:Z.create(1,ye,await he.digest(f))}}}var Xe="0.10.0",xe=()=>Math.floor(Date.now()/1e3),H=class t{constructor(e,n){this.issuer=e.issuer,this.audience=e.audience,this.version=Xe,this.capabilities=e.capabilities,this.expiration=e.expiration,this.notBefore=e.notBefore,this.nonce=e.nonce,this.facts=e.facts,this.proofs=e.proofs,this.signature=n.signature,this.bytes=n.bytes,this.ucan=n.ucan,this.cid=n.cid}static async create(e){let{issuer:n,audience:r,capabilities:s,expiration:o,notBefore:i,nonce:c,facts:f,proofs:d,ttl:u}=e,p={issuer:n,audience:r,capabilities:s,expiration:o??(typeof u=="number"?xe()+u:null),notBefore:i,nonce:c,facts:f,proofs:d,version:Xe};return new t(p,await qe(p,n))}static async fromUcan(e){let{props:n,artifacts:r}=await We(e);return new t(n,r)}block(){return{bytes:this.bytes,cid:this.cid}}async isValid(e){let[n,r]=this.ucan.split(".");return!(!await e.verify({message:x.decode(`${n}.${r}`),signature:this.signature,...this.issuer})||this.expiration&&this.expiration<=xe()||this.notBefore&&this.notBefore>xe())}toString(){return this.ucan}toJSON(){return{issuer:this.issuer.toString(),audience:this.audience.toString(),version:this.version,capabilities:this.capabilities,expiration:this.expiration,notBefore:this.notBefore,nonce:this.nonce,facts:this.facts,proofs:this.proofs?.map(e=>e.toJSON()),signature:Ne.encode(this.signature),ucan:this.ucan,bytes:x.encode(this.bytes),cid:this.cid.toJSON()}}};var g=2n**255n-19n,Y=2n**252n+27742317777372353535851937790883648493n,Ee=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,_e=0x6666666666666666666666666666666666666666666666666666666666666658n,re={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:g,n:Y,h:8,Gx:Ee,Gy:_e},E=(t="")=>{throw new Error(t)},rt=t=>typeof t=="string",ie=(t,e)=>!(t instanceof Uint8Array)||typeof e=="number"&&e>0&&t.length!==e?E("Uint8Array expected"):t,F=t=>new Uint8Array(t),ce=(t,e)=>ie(rt(t)?Se(t):F(t),e),a=(t,e=g)=>{let n=t%e;return n>=0n?n:e+n},Qe=t=>t instanceof C?t:E("Point expected"),et,C=class t{constructor(e,n,r,s){this.ex=e,this.ey=n,this.ez=r,this.et=s}static fromAffine(e){return new t(e.x,e.y,1n,a(e.x*e.y))}static fromHex(e,n=!0){let{d:r}=re;e=ce(e,32);let s=e.slice();s[31]=e[31]&-129;let o=it(s);o===0n||(n&&!(0n<o&&o<g)&&E("bad y coord 1"),!n&&!(0n<o&&o<2n**256n)&&E("bad y coord 2"));let i=a(o*o),c=a(i-1n),f=a(r*i+1n),{isValid:d,value:u}=yn(c,f);d||E("bad y coordinate 3");let p=(u&1n)===1n;return(e[31]&128)!==0!==p&&(u=a(-u)),new t(u,o,1n,a(u*o))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{ex:n,ey:r,ez:s}=this,{ex:o,ey:i,ez:c}=Qe(e),f=a(n*c),d=a(o*s),u=a(r*c),p=a(i*s);return f===d&&u===p}is0(){return this.equals(oe)}negate(){return new t(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{ex:e,ey:n,ez:r}=this,{a:s}=re,o=a(e*e),i=a(n*n),c=a(2n*a(r*r)),f=a(s*o),d=e+n,u=a(a(d*d)-o-i),p=f+i,y=p-c,l=f-i,h=a(u*y),_=a(p*l),m=a(u*l),b=a(y*p);return new t(h,_,b,m)}add(e){let{ex:n,ey:r,ez:s,et:o}=this,{ex:i,ey:c,ez:f,et:d}=Qe(e),{a:u,d:p}=re,y=a(n*i),l=a(r*c),h=a(o*p*d),_=a(s*f),m=a((n+r)*(i+c)-y-l),b=a(_-h),v=a(_+h),w=a(l-u*y),S=a(m*b),D=a(v*w),A=a(m*w),B=a(b*v);return new t(S,D,B,A)}mul(e,n=!0){if(e===0n)return n===!0?E("cannot multiply by 0"):oe;if(typeof e=="bigint"&&0n<e&&e<Y||E("invalid scalar, must be < L"),!n&&this.is0()||e===1n)return this;if(this.equals(O))return xn(e).p;let r=oe,s=O;for(let o=this;e>0n;o=o.double(),e>>=1n)e&1n?r=r.add(o):n&&(s=s.add(o));return r}multiply(e){return this.mul(e)}clearCofactor(){return this.mul(BigInt(re.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(Y/2n,!1).double();return Y%2n&&(e=e.add(this)),e.is0()}toAffine(){let{ex:e,ey:n,ez:r}=this;if(this.is0())return{x:0n,y:0n};let s=ct(r);return a(r*s)!==1n&&E("invalid inverse"),{x:a(e*s),y:a(n*s)}}toRawBytes(){let{x:e,y:n}=this.toAffine(),r=st(n);return r[31]|=e&1n?128:0,r}toHex(){return Ae(this.toRawBytes())}};C.BASE=new C(Ee,_e,1n,a(Ee*_e));C.ZERO=new C(0n,1n,1n,0n);var{BASE:O,ZERO:oe}=C,ot=(t,e)=>t.toString(16).padStart(e,"0"),Ae=t=>Array.from(t).map(e=>ot(e,2)).join(""),Se=t=>{let e=t.length;(!rt(t)||e%2)&&E("hex invalid 1");let n=F(e/2);for(let r=0;r<n.length;r++){let s=r*2,o=t.slice(s,s+2),i=Number.parseInt(o,16);(Number.isNaN(i)||i<0)&&E("hex invalid 2"),n[r]=i}return n},st=t=>Se(ot(t,32*2)).reverse(),it=t=>BigInt("0x"+Ae(F(ie(t)).reverse())),se=(...t)=>{let e=F(t.reduce((r,s)=>r+ie(s).length,0)),n=0;return t.forEach(r=>{e.set(r,n),n+=r.length}),e},ct=(t,e=g)=>{(t===0n||e<=0n)&&E("no inverse n="+t+" mod="+e);let n=a(t,e),r=e,s=0n,o=1n,i=1n,c=0n;for(;n!==0n;){let f=r/n,d=r%n,u=s-i*f,p=o-c*f;r=n,n=d,s=i,o=c,i=u,c=p}return r===1n?a(s,e):E("no inverse")},K=(t,e)=>{let n=t;for(;e-- >0n;)n*=n,n%=g;return n},hn=t=>{let n=t*t%g*t%g,r=K(n,2n)*n%g,s=K(r,1n)*t%g,o=K(s,5n)*s%g,i=K(o,10n)*o%g,c=K(i,20n)*i%g,f=K(c,40n)*c%g,d=K(f,80n)*f%g,u=K(d,80n)*f%g,p=K(u,10n)*o%g;return{pow_p_5_8:K(p,2n)*t%g,b2:n}},tt=19681161376707505956807079304988542015446066515923890162744021073123829784752n,yn=(t,e)=>{let n=a(e*e*e),r=a(n*n*e),s=hn(t*r).pow_p_5_8,o=a(t*n*s),i=a(e*o*o),c=o,f=a(o*tt),d=i===t,u=i===a(-t),p=i===a(-t*tt);return d&&(o=c),(u||p)&&(o=f),(a(o)&1n)===1n&&(o=a(-o)),{isValid:d||u,value:o}},ve=t=>a(it(t),Y),V,Be=(...t)=>Te.sha512Async(...t),at=(...t)=>typeof V=="function"?V(...t):E("etc.sha512Sync not set"),ft=t=>{let e=t.slice(0,32);e[0]&=248,e[31]&=127,e[31]|=64;let n=t.slice(32,64),r=ve(e),s=O.mul(r),o=s.toRawBytes();return{head:e,prefix:n,scalar:r,point:s,pointBytes:o}},Re=t=>Be(ce(t,32)).then(ft),mn=t=>ft(at(ce(t,32))),De=t=>Re(t).then(e=>e.pointBytes);function gn(t,e){return t?Be(e.hashable).then(e.finish):e.finish(at(e.hashable))}var bn=(t,e,n)=>{let{pointBytes:r,scalar:s}=t,o=ve(e),i=O.mul(o).toRawBytes();return{hashable:se(i,r,n),finish:d=>{let u=a(o+ve(d)*s,Y);return ie(se(i,st(u)),64)}}},ut=async(t,e)=>{let n=ce(t),r=await Re(e),s=await Be(r.prefix,n);return gn(!0,bn(r,s,n))};var nt=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Te={bytesToHex:Ae,hexToBytes:Se,concatBytes:se,mod:a,invert:ct,randomBytes:t=>{let e=nt();return e||E("crypto.getRandomValues must be defined"),e.getRandomValues(F(t))},sha512Async:async(...t)=>{let e=nt();e||E("crypto.subtle or etc.sha512Async must be defined");let n=se(...t);return F(await e.subtle.digest("SHA-512",n.buffer))},sha512Sync:void 0};Object.defineProperties(Te,{sha512Sync:{configurable:!1,get(){return V},set(t){V||(V=t)}}});var dt={getExtendedPublicKeyAsync:Re,getExtendedPublicKey:mn,randomPrivateKey:()=>Te.randomBytes(32),precompute(t=8,e=O){return e.multiply(3n),e}},N=8,wn=()=>{let t=[],e=256/N+1,n=O,r=n;for(let s=0;s<e;s++){r=n,t.push(r);for(let o=1;o<2**(N-1);o++)r=r.add(n),t.push(r);n=r.double()}return t},xn=t=>{let e=et||(et=wn()),n=(u,p)=>{let y=p.negate();return u?y:p},r=oe,s=O,o=1+256/N,i=2**(N-1),c=BigInt(2**N-1),f=2**N,d=BigInt(N);for(let u=0;u<o;u++){let p=u*i,y=Number(t&c);t>>=d,y>i&&(y-=f,t+=1n);let l=p,h=p+Math.abs(y)-1,_=u%2!==0,m=y<0;y===0?s=s.add(n(_,e[l])):r=r.add(n(m,e[h]))}return{p:r,f:s}};var lt=globalThis.crypto;function pt(t,e,n){let r=T.fromPublicKey(t,R(e));if(n){if(!$e(n.publicKey,r.publicKey))throw new Error("Public key mismatch");if(n.alg!==r.alg)throw new Error("Algorithm mismatch");if(n.type!==r.type)throw new Error("Key type mismatch");r=n}return r}globalThis.crypto||(globalThis.crypto=lt);function En(t){if(t.type!=="Ed25519")throw new TypeError(`Unsupported key type ${t.type}`);if(t.alg!=="EdDSA")throw new TypeError(`Unsupported algorithm ${t.alg}`)}var ae=class t{static alg="EdDSA";static type="Ed25519";static code=4864;#e;constructor(e,n){En(e),this.did=e.did,this.url=e.url,this.type=e.type,this.publicKey=e.publicKey,this.alg=e.alg,this.document=e.document,this.#e=n,this.didKey=e.didKey}static async generate(e){let n=e||dt.randomPrivateKey(),r=await De(n);return new t(T.fromPublicKey("Ed25519",r),n)}static async import(e,n){let r=ze(t.code,pe.decode(e)),s=await De(r);return new t(pt("Ed25519",s,n),r)}async sign(e){return ut(e,this.#e)}export(){return pe.encode(W(t.code,this.#e))}toString(){return this.url.didUrl}};var{WARN:Or,LOG:kr,DEBUG:ht,VERBOSE:Lr,ERROR:Yr}=ue.setup(ue.INFO),yt=class t{constructor(e,n,r,s=[],o=e){this.baseUrl=e;this.issuerKey=n;this.tmpKey=r;this.ucanList=s;this.gatewayBaseUrl=o}static async init({url:e,issuerKey:n,ucanList:r}){ht("Init UcanStoreProxyConnector:",{url:e,issuerKey:n,ucanList:r});let s=`did:web:${encodeURIComponent(new URL(e).host)}`,o=await ae.generate(),i=await H.create({issuer:n,audience:o.did,capabilities:{[`${s}`]:{"storage/read":[{}],"storage/store":[{}],"storage/pin":[{}]}}});return ht("UCAN for proxy",{selfAuthUcan:i,encoded:i.toString()}),new t(e,n,o,[i])}get isSetup(){return!0}get isValid(){return!0}async storeCar(e){let n=new URL(this.baseUrl),r=`did:web:${encodeURIComponent(n.host)}`,s=this.ucanList[0],o=[s.toString()],i=[s.cid],c=await H.create({issuer:this.tmpKey,audience:r,capabilities:{[`${r}`]:{"storage/store":[{}]}},proofs:i});return Pe(this.baseUrl,e,c,{ucans:o})}async retrieveCar(e){if(!this.gatewayBaseUrl)throw new Error("gatewayBaseUrl required for retrieveCar");return Ie(this.gatewayBaseUrl,e)}async retrieveThread(...e){if(!this.gatewayBaseUrl)throw new Error("gatewayBaseUrl required for retrieveThread");return Ke(this,...e)}async resolveIPNS(...e){if(!this.baseUrl)throw new Error("baseUrl required for resolveIPNS");return Ue(this.baseUrl,...e)}};export{yt as UcanStoreProxyConnector,Ue as resolveIPNS,Ie as retrieveCar,Ke as retrieveThread,Pe as storeCar};
1
+ import{a as vn,b as An,c as Pe,d as Ue,e as Ke}from"./chunk-QUUYIPF7.min.js";import{a as fe,b as Ie}from"./chunk-T4F3ZRAG.min.js";import{c as J,d as Z,e as ue}from"./chunk-OWXA5F6K.min.js";import{a as gt,b as bt}from"./chunk-EHSVSU5O.min.js";var He=gt((Hn,Je)=>{"use strict";function rn(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var r=0;r<t.length;r++){var s=t.charAt(r),o=s.charCodeAt(0);if(e[o]!==255)throw new TypeError(s+" is ambiguous");e[o]=r}var i=t.length,c=t.charAt(0),f=Math.log(i)/Math.log(256),d=Math.log(256)/Math.log(i);function u(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var h=0,v=0,m=0,w=l.length;m!==w&&l[m]===0;)m++,h++;for(var A=(w-m)*d+1>>>0,R=new Uint8Array(A);m!==w;){for(var b=l[m],P=0,S=A-1;(b!==0||P<v)&&S!==-1;S--,P++)b+=256*R[S]>>>0,R[S]=b%i>>>0,b=b/i>>>0;if(b!==0)throw new Error("Non-zero carry");v=P,m++}for(var x=A-v;x!==A&&R[x]===0;)x++;for(var z=c.repeat(h);x<A;++x)z+=t.charAt(R[x]);return z}function p(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;for(var h=0,v=0,m=0;l[h]===c;)v++,h++;for(var w=(l.length-h)*f+1>>>0,A=new Uint8Array(w);l[h];){var R=l.charCodeAt(h);if(R>255)return;var b=e[R];if(b===255)return;for(var P=0,S=w-1;(b!==0||P<m)&&S!==-1;S--,P++)b+=i*A[S]>>>0,A[S]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");m=P,h++}for(var x=w-m;x!==w&&A[x]===0;)x++;for(var z=new Uint8Array(v+(w-x)),mt=v;x!==w;)z[mt++]=A[x++];return z}function y(l){var h=p(l);if(h)return h;throw new Error("Non-base"+i+" character")}return{encode:u,decodeUnsafe:p,decode:y}}Je.exports=rn});var Ce=["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"],wt=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Blob","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","WeakRef","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","FormData","URLSearchParams","HTMLElement","NaN",...Ce];function xt(t){return Ce.includes(t)}function Et(t){return wt.includes(t)}function Me(t){let e=toString.call(t).slice(8,-1);if(Et(e))return e}function _t(t){function e(n){return Me(n)===t}return e}function vt(t){return xt(Me(t))}var At=_t("ArrayBuffer");function k(t){return vt(t)||At(t)}function B(t){return ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}function de(t,e="utf8"){return ArrayBuffer.isView(t)?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength):typeof t=="string"?globalThis.Buffer.from(t,e):globalThis.Buffer.from(t)}function le(t,e){e||(e=t.reduce((s,o)=>s+o.length,0));let n=new Uint8Array(e),r=0;for(let s of t)n.set(s,r),r+=s.length;return n}function $e(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let n=0;n<t.byteLength;n++)if(t[n]!==e[n])return!1;return!0}var St=new TextDecoder,Bt=new TextEncoder,E={encode(t){return typeof t=="string"?t:globalThis.Buffer?de(t).toString("utf8"):St.decode(t)},decode(t){return k(t)?B(t):globalThis.Buffer?B(de(t)):Bt.encode(t)}};var Rt=(t,e,n)=>{let r={};for(let d=0;d<e.length;++d)r[e[d]]=d;let s=t.length;for(;t[s-1]==="=";)--s;let o=new Uint8Array(s*n/8|0),i=0,c=0,f=0;for(let d=0;d<s;++d){let u=r[t[d]];if(u===void 0)throw new SyntaxError("Invalid character "+t[d]);c=c<<n|u,i+=n,i>=8&&(i-=8,o[f++]=255&c>>i)}if(i>=n||255&c<<8-i)throw new SyntaxError("Unexpected end of data");return o},Dt=(t,e,n,r)=>{let s=(1<<n)-1,o="",i=0,c=0;for(let f=0;f<t.length;++f)for(c=c<<8|t[f],i+=8;i>n;)i-=n,o+=e[s&c>>i];if(i&&(o+=e[s&c<<n-i]),r)for(;o.length*n&7;)o+="=";return o},Tt={base2:[1,"01"],base8:[3,"01234567"],hex:[4,"0123456789abcdef"],base16:[4,"0123456789ABCDEF"],base32:[5,"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],base32hex:[5,"0123456789ABCDEFGHIJKLMNOPQRSTUV"],base64:[6,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],base64url:[6,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"]};function U(t,e=!1,n){let[r,s]=Tt[t];return{encode(o,i){return typeof o=="string"&&(n&&(o=n(o)),o=E.decode(o)),Dt(B(o),s,r,i??e)},decode(o){return k(o)&&(o=E.encode(o)),n&&(o=n(o)),Rt(o,s,r)}}}var Pn=U("hex",!0,t=>t.toLowerCase()),Un=U("base2"),Kn=U("base8"),In=U("base16"),Cn=U("base32"),Mn=U("base32hex",!0),Ne=U("base64"),pe=U("base64",!0),K=U("base64url",!1);function Oe(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var he=fe({name:"sha2-256",code:18,encode:Oe("SHA-256")}),On=fe({name:"sha2-512",code:19,encode:Oe("SHA-512")});var ye=85;function Pt(t,e){try{var n=t()}catch(r){return e(r)}return n&&n.then?n.then(void 0,e):n}function Ut(){let t=new Map;return function(e,n){try{let o=function(c){if(s)return c;let f=t.get(e.didUrl);return f!==void 0?f:Promise.resolve(n()).then(function(d){var u;return((u=d.didResolutionMetadata)==null?void 0:u.error)!=="notFound"&&t.set(e.didUrl,d),d})};var r=o;let s,i=function(){if(e.params&&e.params["no-cache"]==="true")return Promise.resolve(n()).then(function(c){return s=1,c})}();return Promise.resolve(i&&i.then?i.then(o):o(i))}catch(s){return Promise.reject(s)}}}function Kt(t,e){return e()}var It="(?:%[0-9a-fA-F]{2})",ke=`(?:[a-zA-Z0-9._-]|${It})`,Ct="([a-z0-9]+)",Mt=`((?:${ke}*:)*(${ke}+))`,Le="[a-zA-Z0-9_.:%-]",$t=`;${Le}+=${Le}*`,Nt=`((${$t})*)`,Ot="(/[^#?]*)?",kt="([?][^#]*)?",Lt="(#.*)?",Ft=new RegExp(`^did:${Ct}:${Mt}${Nt}${Ot}${kt}${Lt}$`);function me(t){if(t===""||!t)return null;let e=t.match(Ft);if(e){let n={did:`did:${e[1]}:${e[2]}`,method:e[1],id:e[2],didUrl:t};if(e[4]){let r=e[4].slice(1).split(";");n.params={};for(let s of r){let o=s.split("=");n.params[o[0]]=o[1]}}return e[6]&&(n.path=e[6]),e[7]&&(n.query=e[7].slice(1)),e[8]&&(n.fragment=e[8].slice(1)),n}return null}var j={didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}};function Yt(t){return function(e,n,r){try{return Promise.resolve(Pt(function(){return Promise.resolve(t(e,n,r)).then(function(s){return{...j,didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:s}})},function(s){return{...j,didResolutionMetadata:{error:"notFound",message:s.toString()}}}))}catch(s){return Promise.reject(s)}}}var q=class{constructor(e={},n={}){this.registry=void 0,this.cache=void 0,this.registry=e,this.cache=n.cache===!0?Ut():n.cache||Kt,n.legacyResolvers&&Object.keys(n.legacyResolvers).map(r=>{this.registry[r]||(this.registry[r]=Yt(n.legacyResolvers[r]))})}resolve(e,n={}){try{let r=this,s=me(e);if(s===null)return Promise.resolve({...j,didResolutionMetadata:{error:"invalidDid"}});let o=r.registry[s.method];return o?Promise.resolve(r.cache(s,()=>o(s.did,s,r,n))):Promise.resolve({...j,didResolutionMetadata:{error:"unsupportedDidMethod"}})}catch(r){return Promise.reject(r)}}};var zt=Math.pow(2,31);function Ye(t,e,n=0){e=e||[];let r=n;for(;t>=zt;)e[n++]=t&255|128,t/=128;for(;t&-128;)e[n++]=t&255|128,t>>>=7;return e[n]=t|0,Ye.bytes=n-r+1,e}var Jt=128,Fe=127;function Ht(t,e=0){let n=0,r=0,s=e,o,i=0,c=t.length;do{if(s>=c)throw i=0,new RangeError("Could not decode varint");o=t[s++],n+=r<28?(o&Fe)<<r:(o&Fe)*Math.pow(2,r),r+=7}while(o>=Jt);return i=s-e,[n,i]}var Vt=Math.pow(2,7),Gt=Math.pow(2,14),Zt=Math.pow(2,21),jt=Math.pow(2,28),qt=Math.pow(2,35),Wt=Math.pow(2,42),Xt=Math.pow(2,49),Qt=Math.pow(2,56),en=Math.pow(2,63),tn=function(t){return t<Vt?1:t<Gt?2:t<Zt?3:t<jt?4:t<qt?5:t<Wt?6:t<Xt?7:t<Qt?8:t<en?9:10},M={encode:Ye,decode:Ht,encodingLength:tn};function W(t,e){let n=M.encodingLength(t),r=new Uint8Array(e.byteLength+n);return M.encode(t,r,0),r.set(e,n),r}function ze(t,e){let[n,r]=M.decode(e);if(n===t)return new Uint8Array(e.buffer,e.byteOffset+r,e.byteLength-r);throw new Error(`Expected multiformat with codec 0x${t.toString(16)} tag instead got 0x${n.toString(16)}`)}var ge=bt(He(),1);var on={base10:"0123456789",base36:"0123456789abcdefghijklmnopqrstuvwxyz",base58btc:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"};function be(t){let e=on[t];return{encode(n,r){return typeof n=="string"&&(n=E.decode(n)),(0,ge.default)(e).encode(B(n))},decode(n){return k(n)&&(n=E.encode(n)),(0,ge.default)(e).decode(n)}}}var sn=be("base10"),Zn=be("base36"),jn=be("base58btc");function X(t){return t[0]===2||t[0]===3}function H(t){return t[0]===4}function Q(t){if(!H(t))throw new Error("Expected first byte to be 0x04, meaning uncompressed key.");let e=t.subarray(1),n=e.subarray(0,e.length/2),r=e.subarray(e.length/2,e.length),s=new Uint8Array(n.length+1);return s[0]=2+(r[r.length-1]&1),s.set(n,1),s}var an={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K",RSA:"RS256"};var I={Ed25519:237,RSA:4613,"P-256":4608,"P-384":4609,"P-521":4610,secp256k1:231},ee={237:"Ed25519",4613:"RSA",4608:"P-256",4609:"P-384",4610:"P-521",231:"secp256k1"};function L(t){let e=an[t];if(!e)throw new TypeError(`Unsupported key type ${t}`);return e}var $=class t{constructor(e){this.did=e.did,this.didUrl=e.didUrl,this.method=e.method,this.id=e.id,this.path=e.path,this.fragment=e.fragment,this.query=e.query}static fromString(e){let n=me(e);if(n)return new t(n);throw new TypeError(`Invalid DID "${e}"`)}toString(){return this.didUrl}};var Ve="did:key:";function te(t,e){switch(t){case I.secp256k1:{if(e.length!==33)throw new RangeError("Secp256k1 public keys must be 33 bytes.");return e}case I.Ed25519:{if(e.length!==32)throw new RangeError("ed25519 public keys must be 32 bytes.");return e}case I["P-256"]:{if(H(e)&&(e=Q(e)),X(e)&&e.length!==33)throw new RangeError("p256 public keys must be 33 bytes.");return e}case I["P-384"]:{if(H(e)&&(e=Q(e)),X(e)&&e.length!==49)throw new RangeError("p384 public keys must be 49 bytes.");return e}case I["P-521"]:{if(H(e)&&(e=Q(e)),X(e)&&e.length!==67)throw new RangeError("p521 public keys must be 67 bytes.");return e}case I.RSA:{if(e.length!==270&&e.length!==526)throw new RangeError("RSA public keys must be 270 bytes for 2048 bits or 526 bytes for 4096 bits.");return e}default:throw new RangeError(`Unsupported DID encoding, unknown multicode 0x${t.toString(16)}.`)}}var D=class t extends ${constructor(e,n,r){super(e),this.type=n,this.publicKey=r,this.code=I[n],this.alg=L(n),this.url=e,this.didKey=e.did}static fromString(e){let n=$.fromString(e);if(n.method==="key"){let r=J.decode(n.id),[s,o]=M.decode(r),i=te(s,r.slice(o));return new t(n,ee[s],i)}else throw new TypeError(`Invalid DID "${n}", method must be 'key'`)}static fromPublicKey(e,n){let r=I[e];if(!r)throw new TypeError(`Unsupported key type "${e}"`);let s=te(r,B(n)),o=J.encode(W(r,s));return new t({did:`${Ve}${o}`,didUrl:`${Ve}${o}`,id:o,method:"key"},e,s)}get document(){let e=`${this.did}#${this.id}`;return{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1"],id:this.did,verificationMethod:[{id:e,type:"MultiKey",controller:this.did,publicKeyMultibase:this.id}],authentication:[e],assertionMethod:[e],capabilityDelegation:[e],capabilityInvocation:[e]}}};async function fn(t,e){let n=D.fromString(t);return{didDocumentMetadata:{},didResolutionMetadata:{contentType:"application/did+ld+json"},didDocument:n.document}}var Ge={key:fn};async function dn(t,e={}){let r=await new q({...Ge,...e.resolvers},{cache:e.cache??!0}).resolve(t,{accept:"application/did+ld+json"});if(r.didResolutionMetadata.error)throw new Error(r.didResolutionMetadata.error);return r.didDocument}function we(t){return $.fromString(t)}function ln(t,e){let n=t.fragment??t.id,r;return e.verificationMethod&&(r=e.verificationMethod.find(s=>s.id===`${t.did}#${n}`)),!r&&e.authentication&&(r=e.authentication.find(s=>typeof s!="string"&&s.id===`${t.did}#${n}`)),r}var ne=class t{constructor(e){this.did=e.did,this.publicKey=e.publicKey,this.alg=e.alg,this.type=e.type,this.document=e.document,this.url=e.url,this.didKey=D.fromPublicKey(e.type,e.publicKey).url.did}static async fromString(e,n={}){let r=we(e),s=await dn(r.did,n),o=ln(r,s);if(!o)throw new Error(`No verification method found for ${e}`);if(o.type==="MultiKey"){let i=J.decode(o.publicKeyMultibase),[c,f]=M.decode(i),d=te(c,i.slice(f)),u=ee[c];return new t({did:r.did,alg:L(u),type:u,publicKey:d,url:r,document:s})}if(o.publicKeyJwk&&o.publicKeyJwk.kty==="OKP"){let i=K.decode(o.publicKeyJwk.x),c=o.publicKeyJwk.crv,f=L(c);return new t({did:r.did,alg:f,type:c,publicKey:i,url:r,document:s})}if(o.publicKeyJwk&&o.publicKeyJwk.kty==="EC"){let i=o.publicKeyJwk.crv,c=D.fromPublicKey(i,le([[4],K.decode(o.publicKeyJwk.x),K.decode(o.publicKeyJwk.y)])),f=L(i);return new t({did:r.did,alg:f,type:i,publicKey:c.publicKey,url:r,document:s})}throw new Error(`Unsupported verification method type "${o.type}"`)}toString(){return this.url.didUrl}};function Ze(t){return K.encode(E.decode(JSON.stringify(t)))}function je(t){let e;try{let n=K.decode(t);e=E.encode(n)}catch{throw new Error(`Can't parse: ${t}: Can't parse as base64url.`)}try{return JSON.parse(e)}catch{throw new Error(`Can't parse: ${t}: Can't parse base64url encoded JSON inside.`)}}async function qe(t,e){let n={alg:t.issuer.alg,typ:"JWT"},r={aud:t.audience,iss:t.issuer.did,cap:t.capabilities,exp:t.expiration,ucv:t.version,fct:t.facts,prf:t.proofs?.map(f=>f.toString()),nbf:t.notBefore,nnc:t.nonce},s=`${Ze(n)}.${Ze(r)}`,o=await e.sign(E.decode(s)),i=`${s}.${K.encode(o)}`,c=E.decode(i);return{ucan:i,signature:o,bytes:c,cid:Z.create(1,ye,await he.digest(c))}}async function We(t){let[e,n,r]=t.split(".");if(e===void 0||n===void 0||r===void 0)throw new Error(`Can't parse UCAN: ${t}: Expected JWT format: 3 dot-separated base64url-encoded values.`);let s=je(e);if(s.typ!=="JWT")throw new Error(`Expected type "JWT" got ${s.typ}.`);let o=je(n),i=await ne.fromString(o.iss);if(s.alg!==i.alg)throw new Error(`Expected signature algorithm "${i.alg}" got ${s.alg}.`);let c=K.decode(r),f=E.decode(t);return{props:{audience:we(o.aud).did,issuer:i,capabilities:o.cap,expiration:o.exp,version:o.ucv,facts:o.fct,proofs:o.prf?.map(d=>Z.parse(d)),notBefore:o.nbf,nonce:o.nnc},artifacts:{signature:c,ucan:t,bytes:f,cid:Z.create(1,ye,await he.digest(f))}}}var Xe="0.10.0",xe=()=>Math.floor(Date.now()/1e3),V=class t{constructor(e,n){this.issuer=e.issuer,this.audience=e.audience,this.version=Xe,this.capabilities=e.capabilities,this.expiration=e.expiration,this.notBefore=e.notBefore,this.nonce=e.nonce,this.facts=e.facts,this.proofs=e.proofs,this.signature=n.signature,this.bytes=n.bytes,this.ucan=n.ucan,this.cid=n.cid}static async create(e){let{issuer:n,audience:r,capabilities:s,expiration:o,notBefore:i,nonce:c,facts:f,proofs:d,ttl:u}=e,p={issuer:n,audience:r,capabilities:s,expiration:o??(typeof u=="number"?xe()+u:null),notBefore:i,nonce:c,facts:f,proofs:d,version:Xe};return new t(p,await qe(p,n))}static async fromUcan(e){let{props:n,artifacts:r}=await We(e);return new t(n,r)}block(){return{bytes:this.bytes,cid:this.cid}}async isValid(e){let[n,r]=this.ucan.split(".");return!(!await e.verify({message:E.decode(`${n}.${r}`),signature:this.signature,...this.issuer})||this.expiration&&this.expiration<=xe()||this.notBefore&&this.notBefore>xe())}toString(){return this.ucan}toJSON(){return{issuer:this.issuer.toString(),audience:this.audience.toString(),version:this.version,capabilities:this.capabilities,expiration:this.expiration,notBefore:this.notBefore,nonce:this.nonce,facts:this.facts,proofs:this.proofs?.map(e=>e.toJSON()),signature:Ne.encode(this.signature),ucan:this.ucan,bytes:E.encode(this.bytes),cid:this.cid.toJSON()}}};var g=2n**255n-19n,F=2n**252n+27742317777372353535851937790883648493n,Ee=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,_e=0x6666666666666666666666666666666666666666666666666666666666666658n,re={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:g,n:F,h:8,Gx:Ee,Gy:_e},_=(t="")=>{throw new Error(t)},rt=t=>typeof t=="string",ie=(t,e)=>!(t instanceof Uint8Array)||typeof e=="number"&&e>0&&t.length!==e?_("Uint8Array expected"):t,Y=t=>new Uint8Array(t),ce=(t,e)=>ie(rt(t)?Se(t):Y(t),e),a=(t,e=g)=>{let n=t%e;return n>=0n?n:e+n},Qe=t=>t instanceof C?t:_("Point expected"),et,C=class t{constructor(e,n,r,s){this.ex=e,this.ey=n,this.ez=r,this.et=s}static fromAffine(e){return new t(e.x,e.y,1n,a(e.x*e.y))}static fromHex(e,n=!0){let{d:r}=re;e=ce(e,32);let s=e.slice();s[31]=e[31]&-129;let o=it(s);o===0n||(n&&!(0n<o&&o<g)&&_("bad y coord 1"),!n&&!(0n<o&&o<2n**256n)&&_("bad y coord 2"));let i=a(o*o),c=a(i-1n),f=a(r*i+1n),{isValid:d,value:u}=mn(c,f);d||_("bad y coordinate 3");let p=(u&1n)===1n;return(e[31]&128)!==0!==p&&(u=a(-u)),new t(u,o,1n,a(u*o))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{ex:n,ey:r,ez:s}=this,{ex:o,ey:i,ez:c}=Qe(e),f=a(n*c),d=a(o*s),u=a(r*c),p=a(i*s);return f===d&&u===p}is0(){return this.equals(oe)}negate(){return new t(a(-this.ex),this.ey,this.ez,a(-this.et))}double(){let{ex:e,ey:n,ez:r}=this,{a:s}=re,o=a(e*e),i=a(n*n),c=a(2n*a(r*r)),f=a(s*o),d=e+n,u=a(a(d*d)-o-i),p=f+i,y=p-c,l=f-i,h=a(u*y),v=a(p*l),m=a(u*l),w=a(y*p);return new t(h,v,w,m)}add(e){let{ex:n,ey:r,ez:s,et:o}=this,{ex:i,ey:c,ez:f,et:d}=Qe(e),{a:u,d:p}=re,y=a(n*i),l=a(r*c),h=a(o*p*d),v=a(s*f),m=a((n+r)*(i+c)-y-l),w=a(v-h),A=a(v+h),R=a(l-u*y),b=a(m*w),P=a(A*R),S=a(m*R),x=a(w*A);return new t(b,P,x,S)}mul(e,n=!0){if(e===0n)return n===!0?_("cannot multiply by 0"):oe;if(typeof e=="bigint"&&0n<e&&e<F||_("invalid scalar, must be < L"),!n&&this.is0()||e===1n)return this;if(this.equals(O))return En(e).p;let r=oe,s=O;for(let o=this;e>0n;o=o.double(),e>>=1n)e&1n?r=r.add(o):n&&(s=s.add(o));return r}multiply(e){return this.mul(e)}clearCofactor(){return this.mul(BigInt(re.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(F/2n,!1).double();return F%2n&&(e=e.add(this)),e.is0()}toAffine(){let{ex:e,ey:n,ez:r}=this;if(this.is0())return{x:0n,y:0n};let s=ct(r);return a(r*s)!==1n&&_("invalid inverse"),{x:a(e*s),y:a(n*s)}}toRawBytes(){let{x:e,y:n}=this.toAffine(),r=st(n);return r[31]|=e&1n?128:0,r}toHex(){return Ae(this.toRawBytes())}};C.BASE=new C(Ee,_e,1n,a(Ee*_e));C.ZERO=new C(0n,1n,1n,0n);var{BASE:O,ZERO:oe}=C,ot=(t,e)=>t.toString(16).padStart(e,"0"),Ae=t=>Array.from(t).map(e=>ot(e,2)).join(""),Se=t=>{let e=t.length;(!rt(t)||e%2)&&_("hex invalid 1");let n=Y(e/2);for(let r=0;r<n.length;r++){let s=r*2,o=t.slice(s,s+2),i=Number.parseInt(o,16);(Number.isNaN(i)||i<0)&&_("hex invalid 2"),n[r]=i}return n},st=t=>Se(ot(t,32*2)).reverse(),it=t=>BigInt("0x"+Ae(Y(ie(t)).reverse())),se=(...t)=>{let e=Y(t.reduce((r,s)=>r+ie(s).length,0)),n=0;return t.forEach(r=>{e.set(r,n),n+=r.length}),e},ct=(t,e=g)=>{(t===0n||e<=0n)&&_("no inverse n="+t+" mod="+e);let n=a(t,e),r=e,s=0n,o=1n,i=1n,c=0n;for(;n!==0n;){let f=r/n,d=r%n,u=s-i*f,p=o-c*f;r=n,n=d,s=i,o=c,i=u,c=p}return r===1n?a(s,e):_("no inverse")},T=(t,e)=>{let n=t;for(;e-- >0n;)n*=n,n%=g;return n},yn=t=>{let n=t*t%g*t%g,r=T(n,2n)*n%g,s=T(r,1n)*t%g,o=T(s,5n)*s%g,i=T(o,10n)*o%g,c=T(i,20n)*i%g,f=T(c,40n)*c%g,d=T(f,80n)*f%g,u=T(d,80n)*f%g,p=T(u,10n)*o%g;return{pow_p_5_8:T(p,2n)*t%g,b2:n}},tt=19681161376707505956807079304988542015446066515923890162744021073123829784752n,mn=(t,e)=>{let n=a(e*e*e),r=a(n*n*e),s=yn(t*r).pow_p_5_8,o=a(t*n*s),i=a(e*o*o),c=o,f=a(o*tt),d=i===t,u=i===a(-t),p=i===a(-t*tt);return d&&(o=c),(u||p)&&(o=f),(a(o)&1n)===1n&&(o=a(-o)),{isValid:d||u,value:o}},ve=t=>a(it(t),F),G,Be=(...t)=>Te.sha512Async(...t),at=(...t)=>typeof G=="function"?G(...t):_("etc.sha512Sync not set"),ft=t=>{let e=t.slice(0,32);e[0]&=248,e[31]&=127,e[31]|=64;let n=t.slice(32,64),r=ve(e),s=O.mul(r),o=s.toRawBytes();return{head:e,prefix:n,scalar:r,point:s,pointBytes:o}},Re=t=>Be(ce(t,32)).then(ft),gn=t=>ft(at(ce(t,32))),De=t=>Re(t).then(e=>e.pointBytes);function bn(t,e){return t?Be(e.hashable).then(e.finish):e.finish(at(e.hashable))}var wn=(t,e,n)=>{let{pointBytes:r,scalar:s}=t,o=ve(e),i=O.mul(o).toRawBytes();return{hashable:se(i,r,n),finish:d=>{let u=a(o+ve(d)*s,F);return ie(se(i,st(u)),64)}}},ut=async(t,e)=>{let n=ce(t),r=await Re(e),s=await Be(r.prefix,n);return bn(!0,wn(r,s,n))};var nt=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Te={bytesToHex:Ae,hexToBytes:Se,concatBytes:se,mod:a,invert:ct,randomBytes:t=>{let e=nt();return e||_("crypto.getRandomValues must be defined"),e.getRandomValues(Y(t))},sha512Async:async(...t)=>{let e=nt();e||_("crypto.subtle or etc.sha512Async must be defined");let n=se(...t);return Y(await e.subtle.digest("SHA-512",n.buffer))},sha512Sync:void 0};Object.defineProperties(Te,{sha512Sync:{configurable:!1,get(){return G},set(t){G||(G=t)}}});var dt={getExtendedPublicKeyAsync:Re,getExtendedPublicKey:gn,randomPrivateKey:()=>Te.randomBytes(32),precompute(t=8,e=O){return e.multiply(3n),e}},N=8,xn=()=>{let t=[],e=256/N+1,n=O,r=n;for(let s=0;s<e;s++){r=n,t.push(r);for(let o=1;o<2**(N-1);o++)r=r.add(n),t.push(r);n=r.double()}return t},En=t=>{let e=et||(et=xn()),n=(u,p)=>{let y=p.negate();return u?y:p},r=oe,s=O,o=1+256/N,i=2**(N-1),c=BigInt(2**N-1),f=2**N,d=BigInt(N);for(let u=0;u<o;u++){let p=u*i,y=Number(t&c);t>>=d,y>i&&(y-=f,t+=1n);let l=p,h=p+Math.abs(y)-1,v=u%2!==0,m=y<0;y===0?s=s.add(n(v,e[l])):r=r.add(n(m,e[h]))}return{p:r,f:s}};var lt=globalThis.crypto;function pt(t,e,n){let r=D.fromPublicKey(t,B(e));if(n){if(!$e(n.publicKey,r.publicKey))throw new Error("Public key mismatch");if(n.alg!==r.alg)throw new Error("Algorithm mismatch");if(n.type!==r.type)throw new Error("Key type mismatch");r=n}return r}globalThis.crypto||(globalThis.crypto=lt);function _n(t){if(t.type!=="Ed25519")throw new TypeError(`Unsupported key type ${t.type}`);if(t.alg!=="EdDSA")throw new TypeError(`Unsupported algorithm ${t.alg}`)}var ae=class t{static alg="EdDSA";static type="Ed25519";static code=4864;#e;constructor(e,n){_n(e),this.did=e.did,this.url=e.url,this.type=e.type,this.publicKey=e.publicKey,this.alg=e.alg,this.document=e.document,this.#e=n,this.didKey=e.didKey}static async generate(e){let n=e||dt.randomPrivateKey(),r=await De(n);return new t(D.fromPublicKey("Ed25519",r),n)}static async import(e,n){let r=ze(t.code,pe.decode(e)),s=await De(r);return new t(pt("Ed25519",s,n),r)}async sign(e){return ut(e,this.#e)}export(){return pe.encode(W(t.code,this.#e))}toString(){return this.url.didUrl}};var{WARN:Fr,LOG:Yr,DEBUG:ht,VERBOSE:zr,ERROR:Jr}=ue.setup(ue.INFO),yt=class t{constructor(e,n,r,s=[],o=e,i){this.baseUrl=e;this.issuerKey=n;this.tmpKey=r;this.ucanList=s;this.gatewayBaseUrl=o;this.nameBaseUrl=i}static async init({url:e,issuerKey:n,ucanList:r,...s}){ht("Init UcanStoreProxyConnector:",{url:e,issuerKey:n,ucanList:r});let o=`did:web:${encodeURIComponent(new URL(e).host)}`,i=await ae.generate(),c=await V.create({issuer:n,audience:i.did,capabilities:{[`${o}`]:{"storage/read":[{}],"storage/store":[{}],"storage/pin":[{}]}}});return ht("UCAN for proxy",{selfAuthUcan:c,encoded:c.toString()}),Object.assign(new t(e,n,i,[c]),s)}get isSetup(){return!0}get isValid(){return!0}async storeCar(e){let n=new URL(this.baseUrl),r=`did:web:${encodeURIComponent(n.host)}`,s=this.ucanList[0],o=[s.toString()],i=[s.cid],c=await V.create({issuer:this.tmpKey,audience:r,capabilities:{[`${r}`]:{"storage/store":[{}]}},proofs:i});return Ie(this.baseUrl,e,c,{ucans:o})}async retrieveCar(e){if(!this.gatewayBaseUrl)throw new Error("gatewayBaseUrl required for retrieveCar");return Ke(this.gatewayBaseUrl,e)}async retrieveThread(...e){if(!this.gatewayBaseUrl)throw new Error("gatewayBaseUrl required for retrieveThread");return Pe(this,...e)}async resolveIPNS(...e){if(!this.baseUrl)throw new Error("baseUrl required for resolveIPNS");return Ue(this,...e)}};export{vn as IPNSNeverPublishedError,An as IPNSResolutionError,yt as UcanStoreProxyConnector,Ue as resolveIPNS,Ke as retrieveCar,Pe as retrieveThread,Ie as storeCar};
2
2
  /*! Bundled license information:
3
3
 
4
4
  @noble/ed25519/index.js: