buckyos 0.7.170 → 0.7.177
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.
- package/cli/core/app.ts +2 -0
- package/cli/core/argv.ts +45 -239
- package/cli/core/command.ts +3 -35
- package/cli/dist/cli.mjs +2151 -673
- package/cli/dist/cli.mjs.map +1 -1
- package/cli/modules/agent.ts +3 -1
- package/cli/modules/app.ts +13 -2
- package/cli/modules/pikg.ts +70 -1
- package/cli/modules/runtime.ts +497 -0
- package/cli/modules/skill.ts +583 -161
- package/cli/modules/skill_lint.ts +462 -0
- package/cli/version.ts +1 -1
- package/dist/account-7a7bde6f.mjs +105 -0
- package/dist/account-7a7bde6f.mjs.map +1 -0
- package/dist/account-b12ac6b9.js +2 -0
- package/dist/account-b12ac6b9.js.map +1 -0
- package/dist/aicc-67851c41.mjs +582 -0
- package/dist/aicc-67851c41.mjs.map +1 -0
- package/dist/aicc-ccb36ef7.js +2 -0
- package/dist/aicc-ccb36ef7.js.map +1 -0
- package/dist/aiworkspace_client.d.ts +36 -2
- package/dist/aiworkspace_client.d.ts.map +1 -1
- package/dist/app-frame.cjs +1 -1
- package/dist/app-frame.cjs.map +1 -1
- package/dist/app-frame.d.ts +56 -1
- package/dist/app-frame.d.ts.map +1 -1
- package/dist/app-frame.mjs +285 -4
- package/dist/app-frame.mjs.map +1 -1
- package/dist/browser.cjs +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +4 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.mjs +218 -194
- package/dist/browser.mjs.map +1 -1
- package/dist/content.cjs +1 -1
- package/dist/content.cjs.map +1 -1
- package/dist/content.d.ts +77 -0
- package/dist/content.d.ts.map +1 -1
- package/dist/content.mjs +65 -0
- package/dist/content.mjs.map +1 -1
- package/dist/content_objid-1aff74b6.js +2 -0
- package/dist/content_objid-1aff74b6.js.map +1 -0
- package/dist/content_objid-9232bcaf.mjs +29 -0
- package/dist/content_objid-9232bcaf.mjs.map +1 -0
- package/dist/content_objid.d.ts +15 -0
- package/dist/content_objid.d.ts.map +1 -0
- package/dist/did_object_client-6a1b108a.js +2 -0
- package/dist/did_object_client-6a1b108a.js.map +1 -0
- package/dist/did_object_client-7fa36f90.mjs +87 -0
- package/dist/did_object_client-7fa36f90.mjs.map +1 -0
- package/dist/did_object_client.d.ts +39 -0
- package/dist/did_object_client.d.ts.map +1 -0
- package/dist/executor_client-7ce0ddc7.js +13 -0
- package/dist/executor_client-7ce0ddc7.js.map +1 -0
- package/dist/{executor_client-5f4d0468.mjs → executor_client-bfc8a1e1.mjs} +308 -752
- package/dist/executor_client-bfc8a1e1.mjs.map +1 -0
- package/dist/executor_client.d.ts +129 -0
- package/dist/executor_client.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +218 -199
- package/dist/index.mjs.map +1 -1
- package/dist/internal/command_args.d.ts +67 -0
- package/dist/internal/command_args.d.ts.map +1 -0
- package/dist/krpc_client-26c2dc8b.js +2 -0
- package/dist/krpc_client-26c2dc8b.js.map +1 -0
- package/dist/krpc_client-673448e5.mjs +173 -0
- package/dist/krpc_client-673448e5.mjs.map +1 -0
- package/dist/krpc_client.d.ts +5 -1
- package/dist/krpc_client.d.ts.map +1 -1
- package/dist/{ndn_types-ab30fac0.mjs → ndn_types-0fac2499.mjs} +115 -215
- package/dist/ndn_types-0fac2499.mjs.map +1 -0
- package/dist/ndn_types-5b138882.js +2 -0
- package/dist/ndn_types-5b138882.js.map +1 -0
- package/dist/node.cjs +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.mjs +201 -194
- package/dist/node.mjs.map +1 -1
- package/dist/object_url-8fb5a7bf.js +2 -0
- package/dist/object_url-8fb5a7bf.js.map +1 -0
- package/dist/object_url-f72c1704.mjs +412 -0
- package/dist/object_url-f72c1704.mjs.map +1 -0
- package/dist/openai-ae2978de.mjs +163 -0
- package/dist/openai-ae2978de.mjs.map +1 -0
- package/dist/openai-f560d518.js +2 -0
- package/dist/openai-f560d518.js.map +1 -0
- package/dist/provision.cjs +6 -6
- package/dist/provision.cjs.map +1 -1
- package/dist/provision.mjs +4 -3
- package/dist/provision.mjs.map +1 -1
- package/dist/site_manager-11a7a468.mjs +6410 -0
- package/dist/site_manager-11a7a468.mjs.map +1 -0
- package/dist/site_manager-334b1a51.js +2 -0
- package/dist/site_manager-334b1a51.js.map +1 -0
- package/dist/{tus_client-b231b248.js → tus_client-809c90ab.js} +2 -2
- package/dist/{tus_client-b231b248.js.map → tus_client-809c90ab.js.map} +1 -1
- package/dist/{tus_client-d1ffe2d6.mjs → tus_client-893a3287.mjs} +2 -2
- package/dist/{tus_client-d1ffe2d6.mjs.map → tus_client-893a3287.mjs.map} +1 -1
- package/dist/xllm/core/action_parser.d.ts +15 -0
- package/dist/xllm/core/action_parser.d.ts.map +1 -0
- package/dist/xllm/core/behavior_loop.d.ts +20 -0
- package/dist/xllm/core/behavior_loop.d.ts.map +1 -0
- package/dist/xllm/core/behavior_result.d.ts +11 -0
- package/dist/xllm/core/behavior_result.d.ts.map +1 -0
- package/dist/xllm/core/config.d.ts +62 -0
- package/dist/xllm/core/config.d.ts.map +1 -0
- package/dist/xllm/core/context_window.d.ts +15 -0
- package/dist/xllm/core/context_window.d.ts.map +1 -0
- package/dist/xllm/core/deps.d.ts +97 -0
- package/dist/xllm/core/deps.d.ts.map +1 -0
- package/dist/xllm/core/errors.d.ts +94 -0
- package/dist/xllm/core/errors.d.ts.map +1 -0
- package/dist/xllm/core/interrupt.d.ts +31 -0
- package/dist/xllm/core/interrupt.d.ts.map +1 -0
- package/dist/xllm/core/json.d.ts +11 -0
- package/dist/xllm/core/json.d.ts.map +1 -0
- package/dist/xllm/core/json_check.d.ts +17 -0
- package/dist/xllm/core/json_check.d.ts.map +1 -0
- package/dist/xllm/core/loop.d.ts +135 -0
- package/dist/xllm/core/loop.d.ts.map +1 -0
- package/dist/xllm/core/messages.d.ts +18 -0
- package/dist/xllm/core/messages.d.ts.map +1 -0
- package/dist/xllm/core/observer.d.ts +14 -0
- package/dist/xllm/core/observer.d.ts.map +1 -0
- package/dist/xllm/core/open_runtime.d.ts +22 -0
- package/dist/xllm/core/open_runtime.d.ts.map +1 -0
- package/dist/xllm/core/prepare.d.ts +54 -0
- package/dist/xllm/core/prepare.d.ts.map +1 -0
- package/dist/xllm/core/prompt.d.ts +40 -0
- package/dist/xllm/core/prompt.d.ts.map +1 -0
- package/dist/xllm/core/protocol.d.ts +15 -0
- package/dist/xllm/core/protocol.d.ts.map +1 -0
- package/dist/xllm/core/result.d.ts +12 -0
- package/dist/xllm/core/result.d.ts.map +1 -0
- package/dist/xllm/core/run.d.ts +198 -0
- package/dist/xllm/core/run.d.ts.map +1 -0
- package/dist/xllm/core/rust_text.d.ts +20 -0
- package/dist/xllm/core/rust_text.d.ts.map +1 -0
- package/dist/xllm/core/site_policy.d.ts +5 -0
- package/dist/xllm/core/site_policy.d.ts.map +1 -0
- package/dist/xllm/core/store.d.ts +60 -0
- package/dist/xllm/core/store.d.ts.map +1 -0
- package/dist/xllm/core/suspension.d.ts +13 -0
- package/dist/xllm/core/suspension.d.ts.map +1 -0
- package/dist/xllm/core/tokenizer.d.ts +8 -0
- package/dist/xllm/core/tokenizer.d.ts.map +1 -0
- package/dist/xllm/core/types.d.ts +826 -0
- package/dist/xllm/core/types.d.ts.map +1 -0
- package/dist/xllm/core/xml.d.ts +19 -0
- package/dist/xllm/core/xml.d.ts.map +1 -0
- package/dist/xllm/dev/openai.d.ts +17 -0
- package/dist/xllm/dev/openai.d.ts.map +1 -0
- package/dist/xllm/dev/scripted.d.ts +46 -0
- package/dist/xllm/dev/scripted.d.ts.map +1 -0
- package/dist/xllm/dev.d.ts +5 -0
- package/dist/xllm/dev.d.ts.map +1 -0
- package/dist/xllm/hosts/browser/store.d.ts +41 -0
- package/dist/xllm/hosts/browser/store.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/deno_api.d.ts +103 -0
- package/dist/xllm/hosts/deno/deno_api.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/identity.d.ts +29 -0
- package/dist/xllm/hosts/deno/identity.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/index.d.ts +47 -0
- package/dist/xllm/hosts/deno/index.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/native_runtime.d.ts +93 -0
- package/dist/xllm/hosts/deno/native_runtime.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/native_tools.d.ts +105 -0
- package/dist/xllm/hosts/deno/native_tools.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/provider.d.ts +13 -0
- package/dist/xllm/hosts/deno/provider.d.ts.map +1 -0
- package/dist/xllm/hosts/deno/store.d.ts +60 -0
- package/dist/xllm/hosts/deno/store.d.ts.map +1 -0
- package/dist/xllm/index.d.ts +48 -0
- package/dist/xllm/index.d.ts.map +1 -0
- package/dist/xllm/providers/aicc.d.ts +22 -0
- package/dist/xllm/providers/aicc.d.ts.map +1 -0
- package/dist/xllm/providers/timeout.d.ts +12 -0
- package/dist/xllm/providers/timeout.d.ts.map +1 -0
- package/dist/xllm/runtime/compress.d.ts +149 -0
- package/dist/xllm/runtime/compress.d.ts.map +1 -0
- package/dist/xllm/runtime/did_object_resources.d.ts +21 -0
- package/dist/xllm/runtime/did_object_resources.d.ts.map +1 -0
- package/dist/xllm/runtime/hints.d.ts +23 -0
- package/dist/xllm/runtime/hints.d.ts.map +1 -0
- package/dist/xllm/runtime/site.d.ts +22 -0
- package/dist/xllm/runtime/site.d.ts.map +1 -0
- package/dist/xllm/runtime/site_manager.d.ts +38 -0
- package/dist/xllm/runtime/site_manager.d.ts.map +1 -0
- package/dist/xllm/runtime/site_tools.d.ts +76 -0
- package/dist/xllm/runtime/site_tools.d.ts.map +1 -0
- package/dist/xllm/runtime/step_renderer.d.ts +54 -0
- package/dist/xllm/runtime/step_renderer.d.ts.map +1 -0
- package/dist/xllm/runtime/task_model.d.ts +64 -0
- package/dist/xllm/runtime/task_model.d.ts.map +1 -0
- package/dist/xllm/runtime/tool_result.d.ts +39 -0
- package/dist/xllm/runtime/tool_result.d.ts.map +1 -0
- package/dist/xllm/runtime/types.d.ts +99 -0
- package/dist/xllm/runtime/types.d.ts.map +1 -0
- package/dist/xllm.cjs +2 -0
- package/dist/xllm.cjs.map +1 -0
- package/dist/xllm.mjs +1167 -0
- package/dist/xllm.mjs.map +1 -0
- package/dist/xllm_deno.cjs +2 -0
- package/dist/xllm_deno.cjs.map +1 -0
- package/dist/xllm_deno.mjs +2487 -0
- package/dist/xllm_deno.mjs.map +1 -0
- package/dist/xllm_dev.cjs +2 -0
- package/dist/xllm_dev.cjs.map +1 -0
- package/dist/xllm_dev.mjs +70 -0
- package/dist/xllm_dev.mjs.map +1 -0
- package/package.json +22 -1
- package/src/internal/command_args.ts +268 -0
- package/dist/executor_client-1ee523cf.js +0 -13
- package/dist/executor_client-1ee523cf.js.map +0 -1
- package/dist/executor_client-5f4d0468.mjs.map +0 -1
- package/dist/ndn_types-8c2696d5.js +0 -2
- package/dist/ndn_types-8c2696d5.js.map +0 -1
- package/dist/ndn_types-ab30fac0.mjs.map +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e="ARRAYBUFFER not supported by this environment",n="UINT8ARRAY not supported by this environment";function r(t,e,n,r){let o,i,s;const a=e||[0],c=(n=n||0)>>>3,u=-1===r?3:0;for(o=0;o<t.length;o+=1)s=o+c,i=s>>>2,a.length<=i&&a.push(0),a[i]|=t[o]<<8*(u+r*(s%4));return{value:a,binLen:8*t.length+n}}function o(o,i,s){switch(i){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(o){case"HEX":return function(t,e,n){return function(t,e,n,r){let o,i,s,a;if(0!=t.length%2)throw new Error("String of HEX type must be in byte increments");const c=e||[0],u=(n=n||0)>>>3,l=-1===r?3:0;for(o=0;o<t.length;o+=2){if(i=parseInt(t.substr(o,2),16),isNaN(i))throw new Error("String of HEX type contains invalid characters");for(a=(o>>>1)+u,s=a>>>2;c.length<=s;)c.push(0);c[s]|=i<<8*(l+r*(a%4))}return{value:c,binLen:4*t.length+n}}(t,e,n,s)};case"TEXT":return function(t,e,n){return function(t,e,n,r,o){let i,s,a,c,u,l,h,d,f=0;const p=n||[0],w=(r=r||0)>>>3;if("UTF8"===e)for(h=-1===o?3:0,a=0;a<t.length;a+=1)for(i=t.charCodeAt(a),s=[],128>i?s.push(i):2048>i?(s.push(192|i>>>6),s.push(128|63&i)):55296>i||57344<=i?s.push(224|i>>>12,128|i>>>6&63,128|63&i):(a+=1,i=65536+((1023&i)<<10|1023&t.charCodeAt(a)),s.push(240|i>>>18,128|i>>>12&63,128|i>>>6&63,128|63&i)),c=0;c<s.length;c+=1){for(l=f+w,u=l>>>2;p.length<=u;)p.push(0);p[u]|=s[c]<<8*(h+o*(l%4)),f+=1}else for(h=-1===o?2:0,d="UTF16LE"===e&&1!==o||"UTF16LE"!==e&&1===o,a=0;a<t.length;a+=1){for(i=t.charCodeAt(a),!0===d&&(c=255&i,i=c<<8|i>>>8),l=f+w,u=l>>>2;p.length<=u;)p.push(0);p[u]|=i<<8*(h+o*(l%4)),f+=2}return{value:p,binLen:8*f+r}}(t,i,e,n,s)};case"B64":return function(e,n,r){return function(e,n,r,o){let i,s,a,c,u,l,h,d=0;const f=n||[0],p=(r=r||0)>>>3,w=-1===o?3:0,m=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==m&&m<e.length)throw new Error("Invalid '=' found in base-64 string");for(s=0;s<e.length;s+=4){for(u=e.substr(s,4),c=0,a=0;a<u.length;a+=1)i=t.indexOf(u.charAt(a)),c|=i<<18-6*a;for(a=0;a<u.length-1;a+=1){for(h=d+p,l=h>>>2;f.length<=l;)f.push(0);f[l]|=(c>>>16-8*a&255)<<8*(w+o*(h%4)),d+=1}}return{value:f,binLen:8*d+r}}(e,n,r,s)};case"BYTES":return function(t,e,n){return function(t,e,n,r){let o,i,s,a;const c=e||[0],u=(n=n||0)>>>3,l=-1===r?3:0;for(i=0;i<t.length;i+=1)o=t.charCodeAt(i),a=i+u,s=a>>>2,c.length<=s&&c.push(0),c[s]|=o<<8*(l+r*(a%4));return{value:c,binLen:8*t.length+n}}(t,e,n,s)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(a){throw new Error(e)}return function(t,e,n){return o=e,i=n,a=s,r(new Uint8Array(t),o,i,a);var o,i,a};case"UINT8ARRAY":try{new Uint8Array(0)}catch(a){throw new Error(n)}return function(t,e,n){return r(t,e,n,s)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function i(r,o,i,s){switch(r){case"HEX":return function(t){return function(t,e,n,r){const o="0123456789abcdef";let i,s,a="";const c=e/8,u=-1===n?3:0;for(i=0;i<c;i+=1)s=t[i>>>2]>>>8*(u+n*(i%4)),a+=o.charAt(s>>>4&15)+o.charAt(15&s);return r.outputUpper?a.toUpperCase():a}(t,o,i,s)};case"B64":return function(e){return function(e,n,r,o){let i,s,a,c,u,l="";const h=n/8,d=-1===r?3:0;for(i=0;i<h;i+=3)for(c=i+1<h?e[i+1>>>2]:0,u=i+2<h?e[i+2>>>2]:0,a=(e[i>>>2]>>>8*(d+r*(i%4))&255)<<16|(c>>>8*(d+r*((i+1)%4))&255)<<8|u>>>8*(d+r*((i+2)%4))&255,s=0;s<4;s+=1)l+=8*i+6*s<=n?t.charAt(a>>>6*(3-s)&63):o.b64Pad;return l}(e,o,i,s)};case"BYTES":return function(t){return function(t,e,n){let r,o,i="";const s=e/8,a=-1===n?3:0;for(r=0;r<s;r+=1)o=t[r>>>2]>>>8*(a+n*(r%4))&255,i+=String.fromCharCode(o);return i}(t,o,i)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(a){throw new Error(e)}return function(t){return function(t,e,n){let r;const o=e/8,i=new ArrayBuffer(o),s=new Uint8Array(i),a=-1===n?3:0;for(r=0;r<o;r+=1)s[r]=t[r>>>2]>>>8*(a+n*(r%4))&255;return i}(t,o,i)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(a){throw new Error(n)}return function(t){return function(t,e,n){let r;const o=e/8,i=-1===n?3:0,s=new Uint8Array(o);for(r=0;r<o;r+=1)s[r]=t[r>>>2]>>>8*(i+n*(r%4))&255;return s}(t,o,i)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}const s=4294967296,a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],c=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],u=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],l="Chosen SHA variant is not supported",h="Cannot set numRounds with MAC";function d(t,e){let n,r;const o=t.binLen>>>3,i=e.binLen>>>3,s=o<<3,a=4-o<<3;if(o%4!=0){for(n=0;n<i;n+=4)r=o+n>>>2,t.value[r]|=e.value[n>>>2]<<s,t.value.push(0),t.value[r+1]|=e.value[n>>>2]>>>a;return(t.value.length<<2)-4>=i+o&&t.value.pop(),{value:t.value,binLen:t.binLen+e.binLen}}return{value:t.value.concat(e.value),binLen:t.binLen+e.binLen}}function f(t){const e={outputUpper:!1,b64Pad:"=",outputLen:-1},n=t||{},r="Output length must be a multiple of 8";if(e.outputUpper=n.outputUpper||!1,n.b64Pad&&(e.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);e.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);e.outputLen=n.shakeLen}if("boolean"!=typeof e.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof e.b64Pad)throw new Error("Invalid b64Pad formatting option");return e}function p(t,e,n,r){const i=t+" must include a value and format";if(!e){if(!r)throw new Error(i);return r}if(void 0===e.value||!e.format)throw new Error(i);return o(e.format,e.encoding||"UTF8",n)(e.value)}class w{constructor(t,e,n){const r=n||{};if(this.t=e,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=t,this.h=[],this.u=0,this.l=!1,this.A=0,this.H=!1,this.S=[],this.p=[]}update(t){let e,n=0;const r=this.m>>>5,o=this.C(t,this.h,this.u),i=o.binLen,s=o.value,a=i>>>5;for(e=0;e<a;e+=r)n+this.m<=i&&(this.U=this.v(s.slice(e,e+r),this.U),n+=this.m);return this.A+=n,this.h=s.slice(n>>>5),this.u=i%this.m,this.l=!0,this}getHash(t,e){let n,r,o=this.R;const s=f(e);if(this.K){if(-1===s.outputLen)throw new Error("Output length must be specified in options");o=s.outputLen}const a=i(t,o,this.T,s);if(this.H&&this.g)return a(this.g(s));for(r=this.F(this.h.slice(),this.u,this.A,this.L(this.U),o),n=1;n<this.numRounds;n+=1)this.K&&o%32!=0&&(r[r.length-1]&=16777215>>>24-o%32),r=this.F(r,o,0,this.B(this.o),o);return a(r)}setHMACKey(t,e,n){if(!this.M)throw new Error("Variant does not support HMAC");if(this.l)throw new Error("Cannot set MAC key after calling update");const r=o(e,(n||{}).encoding||"UTF8",this.T);this.k(r(t))}k(t){const e=this.m>>>3,n=e/4-1;let r;if(1!==this.numRounds)throw new Error(h);if(this.H)throw new Error("MAC key already set");for(e<t.binLen/8&&(t.value=this.F(t.value,t.binLen,0,this.B(this.o),this.R));t.value.length<=n;)t.value.push(0);for(r=0;r<=n;r+=1)this.S[r]=909522486^t.value[r],this.p[r]=1549556828^t.value[r];this.U=this.v(this.S,this.U),this.A=this.m,this.H=!0}getHMAC(t,e){const n=f(e);return i(t,this.R,this.T,n)(this.Y())}Y(){let t;if(!this.H)throw new Error("Cannot call getHMAC without first setting MAC key");const e=this.F(this.h.slice(),this.u,this.A,this.L(this.U),this.R);return t=this.v(this.p,this.B(this.o)),t=this.F(e,this.R,this.m,t,this.R),t}}function m(t,e){return t<<e|t>>>32-e}function y(t,e){return t>>>e|t<<32-e}function b(t,e){return t>>>e}function g(t,e,n){return t^e^n}function v(t,e,n){return t&e^~t&n}function _(t,e,n){return t&e^t&n^e&n}function j(t){return y(t,2)^y(t,13)^y(t,22)}function x(t,e){const n=(65535&t)+(65535&e);return(65535&(t>>>16)+(e>>>16)+(n>>>16))<<16|65535&n}function I(t,e,n,r){const o=(65535&t)+(65535&e)+(65535&n)+(65535&r);return(65535&(t>>>16)+(e>>>16)+(n>>>16)+(r>>>16)+(o>>>16))<<16|65535&o}function O(t,e,n,r,o){const i=(65535&t)+(65535&e)+(65535&n)+(65535&r)+(65535&o);return(65535&(t>>>16)+(e>>>16)+(n>>>16)+(r>>>16)+(o>>>16)+(i>>>16))<<16|65535&i}function S(t){return y(t,7)^y(t,18)^b(t,3)}function k(t){return y(t,6)^y(t,11)^y(t,25)}function E(t){return[1732584193,4023233417,2562383102,271733878,3285377520]}function A(t,e){let n,r,o,i,s,a,c;const u=[];for(n=e[0],r=e[1],o=e[2],i=e[3],s=e[4],c=0;c<80;c+=1)u[c]=c<16?t[c]:m(u[c-3]^u[c-8]^u[c-14]^u[c-16],1),a=c<20?O(m(n,5),v(r,o,i),s,1518500249,u[c]):c<40?O(m(n,5),g(r,o,i),s,1859775393,u[c]):c<60?O(m(n,5),_(r,o,i),s,2400959708,u[c]):O(m(n,5),g(r,o,i),s,3395469782,u[c]),s=i,i=o,o=m(r,30),r=n,n=a;return e[0]=x(n,e[0]),e[1]=x(r,e[1]),e[2]=x(o,e[2]),e[3]=x(i,e[3]),e[4]=x(s,e[4]),e}function N(t,e,n,r){let o;const i=15+(e+65>>>9<<4),a=e+n;for(;t.length<=i;)t.push(0);for(t[e>>>5]|=128<<24-e%32,t[i]=4294967295&a,t[i-1]=a/s|0,o=0;o<t.length;o+=16)r=A(t.slice(o,o+16),r);return r}let D=class extends w{constructor(t,e,n){if("SHA-1"!==t)throw new Error(l);super(t,e,n);const r=n||{};this.M=!0,this.g=this.Y,this.T=-1,this.C=o(this.t,this.i,this.T),this.v=A,this.L=function(t){return t.slice()},this.B=E,this.F=N,this.U=[1732584193,4023233417,2562383102,271733878,3285377520],this.m=512,this.R=160,this.K=!1,r.hmacKey&&this.k(p("hmacKey",r.hmacKey,this.T))}};function T(t){let e;return e="SHA-224"==t?c.slice():u.slice(),e}function $(t,e){let n,r,o,i,s,c,u,l,h,d,f;const p=[];for(n=e[0],r=e[1],o=e[2],i=e[3],s=e[4],c=e[5],u=e[6],l=e[7],f=0;f<64;f+=1)p[f]=f<16?t[f]:I(y(w=p[f-2],17)^y(w,19)^b(w,10),p[f-7],S(p[f-15]),p[f-16]),h=O(l,k(s),v(s,c,u),a[f],p[f]),d=x(j(n),_(n,r,o)),l=u,u=c,c=s,s=x(i,h),i=o,o=r,r=n,n=x(h,d);var w;return e[0]=x(n,e[0]),e[1]=x(r,e[1]),e[2]=x(o,e[2]),e[3]=x(i,e[3]),e[4]=x(s,e[4]),e[5]=x(c,e[5]),e[6]=x(u,e[6]),e[7]=x(l,e[7]),e}let J=class extends w{constructor(t,e,n){if("SHA-224"!==t&&"SHA-256"!==t)throw new Error(l);super(t,e,n);const r=n||{};this.g=this.Y,this.M=!0,this.T=-1,this.C=o(this.t,this.i,this.T),this.v=$,this.L=function(t){return t.slice()},this.B=T,this.F=function(e,n,r,o){return function(t,e,n,r,o){let i,a;const c=15+(e+65>>>9<<4),u=e+n;for(;t.length<=c;)t.push(0);for(t[e>>>5]|=128<<24-e%32,t[c]=4294967295&u,t[c-1]=u/s|0,i=0;i<t.length;i+=16)r=$(t.slice(i,i+16),r);return a="SHA-224"===o?[r[0],r[1],r[2],r[3],r[4],r[5],r[6]]:r,a}(e,n,r,o,t)},this.U=T(t),this.m=512,this.R="SHA-224"===t?224:256,this.K=!1,r.hmacKey&&this.k(p("hmacKey",r.hmacKey,this.T))}};class C{constructor(t,e){this.N=t,this.I=e}}function K(t,e){let n;return e>32?(n=64-e,new C(t.I<<e|t.N>>>n,t.N<<e|t.I>>>n)):0!==e?(n=32-e,new C(t.N<<e|t.I>>>n,t.I<<e|t.N>>>n)):t}function R(t,e){let n;return e<32?(n=32-e,new C(t.N>>>e|t.I<<n,t.I>>>e|t.N<<n)):(n=64-e,new C(t.I>>>e|t.N<<n,t.N>>>e|t.I<<n))}function M(t,e){return new C(t.N>>>e,t.I>>>e|t.N<<32-e)}function B(t,e,n){return new C(t.N&e.N^t.N&n.N^e.N&n.N,t.I&e.I^t.I&n.I^e.I&n.I)}function H(t){const e=R(t,28),n=R(t,34),r=R(t,39);return new C(e.N^n.N^r.N,e.I^n.I^r.I)}function P(t,e){let n,r;n=(65535&t.I)+(65535&e.I),r=(t.I>>>16)+(e.I>>>16)+(n>>>16);const o=(65535&r)<<16|65535&n;return n=(65535&t.N)+(65535&e.N)+(r>>>16),r=(t.N>>>16)+(e.N>>>16)+(n>>>16),new C((65535&r)<<16|65535&n,o)}function U(t,e,n,r){let o,i;o=(65535&t.I)+(65535&e.I)+(65535&n.I)+(65535&r.I),i=(t.I>>>16)+(e.I>>>16)+(n.I>>>16)+(r.I>>>16)+(o>>>16);const s=(65535&i)<<16|65535&o;return o=(65535&t.N)+(65535&e.N)+(65535&n.N)+(65535&r.N)+(i>>>16),i=(t.N>>>16)+(e.N>>>16)+(n.N>>>16)+(r.N>>>16)+(o>>>16),new C((65535&i)<<16|65535&o,s)}function L(t,e,n,r,o){let i,s;i=(65535&t.I)+(65535&e.I)+(65535&n.I)+(65535&r.I)+(65535&o.I),s=(t.I>>>16)+(e.I>>>16)+(n.I>>>16)+(r.I>>>16)+(o.I>>>16)+(i>>>16);const a=(65535&s)<<16|65535&i;return i=(65535&t.N)+(65535&e.N)+(65535&n.N)+(65535&r.N)+(65535&o.N)+(s>>>16),s=(t.N>>>16)+(e.N>>>16)+(n.N>>>16)+(r.N>>>16)+(o.N>>>16)+(i>>>16),new C((65535&s)<<16|65535&i,a)}function z(t,e){return new C(t.N^e.N,t.I^e.I)}function F(t){const e=R(t,19),n=R(t,61),r=M(t,6);return new C(e.N^n.N^r.N,e.I^n.I^r.I)}function Y(t){const e=R(t,1),n=R(t,8),r=M(t,7);return new C(e.N^n.N^r.N,e.I^n.I^r.I)}function q(t){const e=R(t,14),n=R(t,18),r=R(t,41);return new C(e.N^n.N^r.N,e.I^n.I^r.I)}const W=[new C(a[0],3609767458),new C(a[1],602891725),new C(a[2],3964484399),new C(a[3],2173295548),new C(a[4],4081628472),new C(a[5],3053834265),new C(a[6],2937671579),new C(a[7],3664609560),new C(a[8],2734883394),new C(a[9],1164996542),new C(a[10],1323610764),new C(a[11],3590304994),new C(a[12],4068182383),new C(a[13],991336113),new C(a[14],633803317),new C(a[15],3479774868),new C(a[16],2666613458),new C(a[17],944711139),new C(a[18],2341262773),new C(a[19],2007800933),new C(a[20],1495990901),new C(a[21],1856431235),new C(a[22],3175218132),new C(a[23],2198950837),new C(a[24],3999719339),new C(a[25],766784016),new C(a[26],2566594879),new C(a[27],3203337956),new C(a[28],1034457026),new C(a[29],2466948901),new C(a[30],3758326383),new C(a[31],168717936),new C(a[32],1188179964),new C(a[33],1546045734),new C(a[34],1522805485),new C(a[35],2643833823),new C(a[36],2343527390),new C(a[37],1014477480),new C(a[38],1206759142),new C(a[39],344077627),new C(a[40],1290863460),new C(a[41],3158454273),new C(a[42],3505952657),new C(a[43],106217008),new C(a[44],3606008344),new C(a[45],1432725776),new C(a[46],1467031594),new C(a[47],851169720),new C(a[48],3100823752),new C(a[49],1363258195),new C(a[50],3750685593),new C(a[51],3785050280),new C(a[52],3318307427),new C(a[53],3812723403),new C(a[54],2003034995),new C(a[55],3602036899),new C(a[56],1575990012),new C(a[57],1125592928),new C(a[58],2716904306),new C(a[59],442776044),new C(a[60],593698344),new C(a[61],3733110249),new C(a[62],2999351573),new C(a[63],3815920427),new C(3391569614,3928383900),new C(3515267271,566280711),new C(3940187606,3454069534),new C(4118630271,4000239992),new C(116418474,1914138554),new C(174292421,2731055270),new C(289380356,3203993006),new C(460393269,320620315),new C(685471733,587496836),new C(852142971,1086792851),new C(1017036298,365543100),new C(1126000580,2618297676),new C(1288033470,3409855158),new C(1501505948,4234509866),new C(1607167915,987167468),new C(1816402316,1246189591)];function V(t){return"SHA-384"===t?[new C(3418070365,c[0]),new C(1654270250,c[1]),new C(2438529370,c[2]),new C(355462360,c[3]),new C(1731405415,c[4]),new C(41048885895,c[5]),new C(3675008525,c[6]),new C(1203062813,c[7])]:[new C(u[0],4089235720),new C(u[1],2227873595),new C(u[2],4271175723),new C(u[3],1595750129),new C(u[4],2917565137),new C(u[5],725511199),new C(u[6],4215389547),new C(u[7],327033209)]}function G(t,e){let n,r,o,i,s,a,c,u,l,h,d,f;const p=[];for(n=e[0],r=e[1],o=e[2],i=e[3],s=e[4],a=e[5],c=e[6],u=e[7],d=0;d<80;d+=1)d<16?(f=2*d,p[d]=new C(t[f],t[f+1])):p[d]=U(F(p[d-2]),p[d-7],Y(p[d-15]),p[d-16]),l=L(u,q(s),(m=a,y=c,new C((w=s).N&m.N^~w.N&y.N,w.I&m.I^~w.I&y.I)),W[d],p[d]),h=P(H(n),B(n,r,o)),u=c,c=a,a=s,s=P(i,l),i=o,o=r,r=n,n=P(l,h);var w,m,y;return e[0]=P(n,e[0]),e[1]=P(r,e[1]),e[2]=P(o,e[2]),e[3]=P(i,e[3]),e[4]=P(s,e[4]),e[5]=P(a,e[5]),e[6]=P(c,e[6]),e[7]=P(u,e[7]),e}let Z=class extends w{constructor(t,e,n){if("SHA-384"!==t&&"SHA-512"!==t)throw new Error(l);super(t,e,n);const r=n||{};this.g=this.Y,this.M=!0,this.T=-1,this.C=o(this.t,this.i,this.T),this.v=G,this.L=function(t){return t.slice()},this.B=V,this.F=function(e,n,r,o){return function(t,e,n,r,o){let i,a;const c=31+(e+129>>>10<<5),u=e+n;for(;t.length<=c;)t.push(0);for(t[e>>>5]|=128<<24-e%32,t[c]=4294967295&u,t[c-1]=u/s|0,i=0;i<t.length;i+=32)r=G(t.slice(i,i+32),r);return a="SHA-384"===o?[r[0].N,r[0].I,r[1].N,r[1].I,r[2].N,r[2].I,r[3].N,r[3].I,r[4].N,r[4].I,r[5].N,r[5].I]:[r[0].N,r[0].I,r[1].N,r[1].I,r[2].N,r[2].I,r[3].N,r[3].I,r[4].N,r[4].I,r[5].N,r[5].I,r[6].N,r[6].I,r[7].N,r[7].I],a}(e,n,r,o,t)},this.U=V(t),this.m=1024,this.R="SHA-384"===t?384:512,this.K=!1,r.hmacKey&&this.k(p("hmacKey",r.hmacKey,this.T))}};const X=[new C(0,1),new C(0,32898),new C(2147483648,32906),new C(2147483648,2147516416),new C(0,32907),new C(0,2147483649),new C(2147483648,2147516545),new C(2147483648,32777),new C(0,138),new C(0,136),new C(0,2147516425),new C(0,2147483658),new C(0,2147516555),new C(2147483648,139),new C(2147483648,32905),new C(2147483648,32771),new C(2147483648,32770),new C(2147483648,128),new C(0,32778),new C(2147483648,2147483658),new C(2147483648,2147516545),new C(2147483648,32896),new C(0,2147483649),new C(2147483648,2147516424)],Q=[[0,36,3,41,18],[1,44,10,45,2],[62,6,43,15,61],[28,55,25,21,56],[27,20,39,8,14]];function tt(t){let e;const n=[];for(e=0;e<5;e+=1)n[e]=[new C(0,0),new C(0,0),new C(0,0),new C(0,0),new C(0,0)];return n}function et(t){let e;const n=[];for(e=0;e<5;e+=1)n[e]=t[e].slice();return n}function nt(t,e){let n,r,o,i;const s=[],a=[];if(null!==t)for(r=0;r<t.length;r+=2)e[(r>>>1)%5][(r>>>1)/5|0]=z(e[(r>>>1)%5][(r>>>1)/5|0],new C(t[r+1],t[r]));for(n=0;n<24;n+=1){for(i=tt(),r=0;r<5;r+=1)s[r]=(c=e[r][0],u=e[r][1],l=e[r][2],h=e[r][3],d=e[r][4],new C(c.N^u.N^l.N^h.N^d.N,c.I^u.I^l.I^h.I^d.I));for(r=0;r<5;r+=1)a[r]=z(s[(r+4)%5],K(s[(r+1)%5],1));for(r=0;r<5;r+=1)for(o=0;o<5;o+=1)e[r][o]=z(e[r][o],a[r]);for(r=0;r<5;r+=1)for(o=0;o<5;o+=1)i[o][(2*r+3*o)%5]=K(e[r][o],Q[r][o]);for(r=0;r<5;r+=1)for(o=0;o<5;o+=1)e[r][o]=z(i[r][o],new C(~i[(r+1)%5][o].N&i[(r+2)%5][o].N,~i[(r+1)%5][o].I&i[(r+2)%5][o].I));e[0][0]=z(e[0][0],X[n])}var c,u,l,h,d;return e}function rt(t){let e,n,r=0;const o=[0,0],i=[4294967295&t,t/s&2097151];for(e=6;e>=0;e--)n=i[e>>2]>>>8*e&255,0===n&&0===r||(o[r+1>>2]|=n<<8*(r+1),r+=1);return r=0!==r?r:1,o[0]|=r,{value:r+1>4?o:[o[0]],binLen:8+8*r}}function ot(t){return d(rt(t.binLen),t)}function it(t,e){let n,r=rt(e);r=d(r,t);const o=e>>>2,i=(o-r.value.length%o)%o;for(n=0;n<i;n++)r.value.push(0);return r.value}let st=class extends w{constructor(t,e,n){let r=6,i=0;super(t,e,n);const s=n||{};if(1!==this.numRounds){if(s.kmacKey||s.hmacKey)throw new Error(h);if("CSHAKE128"===this.o||"CSHAKE256"===this.o)throw new Error("Cannot set numRounds for CSHAKE variants")}switch(this.T=1,this.C=o(this.t,this.i,this.T),this.v=nt,this.L=et,this.B=tt,this.U=tt(),this.K=!1,t){case"SHA3-224":this.m=i=1152,this.R=224,this.M=!0,this.g=this.Y;break;case"SHA3-256":this.m=i=1088,this.R=256,this.M=!0,this.g=this.Y;break;case"SHA3-384":this.m=i=832,this.R=384,this.M=!0,this.g=this.Y;break;case"SHA3-512":this.m=i=576,this.R=512,this.M=!0,this.g=this.Y;break;case"SHAKE128":r=31,this.m=i=1344,this.R=-1,this.K=!0,this.M=!1,this.g=null;break;case"SHAKE256":r=31,this.m=i=1088,this.R=-1,this.K=!0,this.M=!1,this.g=null;break;case"KMAC128":r=4,this.m=i=1344,this.X(n),this.R=-1,this.K=!0,this.M=!1,this.g=this._;break;case"KMAC256":r=4,this.m=i=1088,this.X(n),this.R=-1,this.K=!0,this.M=!1,this.g=this._;break;case"CSHAKE128":this.m=i=1344,r=this.O(n),this.R=-1,this.K=!0,this.M=!1,this.g=null;break;case"CSHAKE256":this.m=i=1088,r=this.O(n),this.R=-1,this.K=!0,this.M=!1,this.g=null;break;default:throw new Error(l)}this.F=function(t,e,n,o,s){return function(t,e,n,r,o,i,s){let a,c,u=0;const l=[],h=o>>>5,d=e>>>5;for(a=0;a<d&&e>=o;a+=h)r=nt(t.slice(a,a+h),r),e-=o;for(t=t.slice(a),e%=o;t.length<h;)t.push(0);for(a=e>>>3,t[a>>2]^=i<<a%4*8,t[h-1]^=2147483648,r=nt(t,r);32*l.length<s&&(c=r[u%5][u/5|0],l.push(c.I),!(32*l.length>=s));)l.push(c.N),u+=1,0==64*u%o&&(nt(null,r),u=0);return l}(t,e,0,o,i,r,s)},s.hmacKey&&this.k(p("hmacKey",s.hmacKey,this.T))}O(t,e){const n=function(t){const e=t||{};return{funcName:p("funcName",e.funcName,1,{value:[],binLen:0}),customization:p("Customization",e.customization,1,{value:[],binLen:0})}}(t||{});e&&(n.funcName=e);const r=d(ot(n.funcName),ot(n.customization));if(0!==n.customization.binLen||0!==n.funcName.binLen){const t=it(r,this.m>>>3);for(let e=0;e<t.length;e+=this.m>>>5)this.U=this.v(t.slice(e,e+(this.m>>>5)),this.U),this.A+=this.m;return 4}return 31}X(t){const e=function(t){const e=t||{};return{kmacKey:p("kmacKey",e.kmacKey,1),funcName:{value:[1128353099],binLen:32},customization:p("Customization",e.customization,1,{value:[],binLen:0})}}(t||{});this.O(t,e.funcName);const n=it(ot(e.kmacKey),this.m>>>3);for(let r=0;r<n.length;r+=this.m>>>5)this.U=this.v(n.slice(r,r+(this.m>>>5)),this.U),this.A+=this.m;this.H=!0}_(t){const e=d({value:this.h.slice(),binLen:this.u},function(t){let e,n,r=0;const o=[0,0],i=[4294967295&t,t/s&2097151];for(e=6;e>=0;e--)n=i[e>>2]>>>8*e&255,0===n&&0===r||(o[r>>2]|=n<<8*r,r+=1);return r=0!==r?r:1,o[r>>2]|=r<<8*r,{value:r+1>4?o:[o[0]],binLen:8+8*r}}(t.outputLen));return this.F(e.value,e.binLen,this.A,this.L(this.U),t.outputLen)}};class at{constructor(t,e,n){if("SHA-1"==t)this.P=new D(t,e,n);else if("SHA-224"==t||"SHA-256"==t)this.P=new J(t,e,n);else if("SHA-384"==t||"SHA-512"==t)this.P=new Z(t,e,n);else{if("SHA3-224"!=t&&"SHA3-256"!=t&&"SHA3-384"!=t&&"SHA3-512"!=t&&"SHAKE128"!=t&&"SHAKE256"!=t&&"CSHAKE128"!=t&&"CSHAKE256"!=t&&"KMAC128"!=t&&"KMAC256"!=t)throw new Error(l);this.P=new st(t,e,n)}}update(t){return this.P.update(t),this}getHash(t,e){return this.P.getHash(t,e)}setHMACKey(t,e,n){this.P.setHMACKey(t,e,n)}getHMAC(t,e){return this.P.getHMAC(t,e)}}const ct="user_info",ut="buckyos.identity";function lt(t){return`buckyos.account_info.${t}`}var ht="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function dt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}const ft=dt((function t(e){if("number"==typeof e&&isNaN(e))throw new Error("NaN is not allowed");if("number"==typeof e&&!isFinite(e))throw new Error("Infinity is not allowed");if(null===e||"object"!=typeof e)return JSON.stringify(e);if(e.toJSON instanceof Function)return t(e.toJSON());if(Array.isArray(e)){return`[${e.reduce(((e,n,r)=>`${e}${0===r?"":","}${t(void 0===n||"symbol"==typeof n?null:n)}`),"")}]`}return`{${Object.keys(e).sort().reduce(((n,r)=>{if(void 0===e[r]||"symbol"==typeof e[r])return n;return`${n}${0===n.length?"":","}${t(r)}:${t(e[r])}`}),"")}}`})),pt="DIDObjectService",wt="buckyos.node_identity.v2";function mt(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function yt(t){return"string"==typeof t||Array.isArray(t)&&t.every((t=>"string"==typeof t))}function bt(t){return!!mt(t)&&(yt(t["@context"])&&"string"==typeof t.id&&function(t){return Array.isArray(t)}(t.verificationMethod)&&Array.isArray(t.authentication)&&"number"==typeof t.exp&&"number"==typeof t.iat&&function(t){return void 0===t||Array.isArray(t)}(t.service))}function gt(t){return bt(t)&&"string"==typeof t.name&&("string"==typeof t.display_name||"string"==typeof t.displayName||"string"==typeof t.full_name)}function vt(t){return mt(t)&&"string"==typeof t.n&&"string"==typeof t.x&&"number"==typeof t.exp}function _t(t){return bt(t)&&"string"==typeof t.owner&&"string"==typeof t.device_type&&"string"==typeof t.name}function jt(t){return bt(t)&&"string"==typeof t.owner&&mt(t.httpServicePorts)}function xt(t){return bt(t)&&"string"==typeof t.hostname&&"string"==typeof t.owner&&Array.isArray(t.oods)&&"string"==typeof t.boot_jwt}function It(t){if(!mt(t)||!yt(t["@context"])||"string"!=typeof t.id)return!1;const e=t.service;return Array.isArray(e)&&e.some((t=>mt(t)&&t.type===pt))}const Ot="https://www.w3.org/ns/did/v1",St="https://buckyos.org/ns",kt=15768e4,Et=31536e4;function At(t){return[Ot,`${St}/${t}/v1`]}function Nt(){return Math.floor(Date.now()/1e3)}const Dt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Tt(t){let e="";for(let n=0;n<t.length;n+=3){const r=t[n],o=n+1<t.length?t[n+1]:0,i=n+2<t.length?t[n+2]:0;e+=Dt[r>>2],e+=Dt[(3&r)<<4|o>>4],e+=n+1<t.length?Dt[(15&o)<<2|i>>6]:"=",e+=n+2<t.length?Dt[63&i]:"="}return e}function $t(t){const e=t.replace(/[^A-Za-z0-9+/]/g,""),n=Math.floor(3*e.length/4),r=new Uint8Array(n);let o=0;for(let i=0;i<e.length;i+=4){const t=Dt.indexOf(e[i]),n=Dt.indexOf(e[i+1]),s=i+2<e.length?Dt.indexOf(e[i+2]):-1,a=i+3<e.length?Dt.indexOf(e[i+3]):-1;r[o++]=t<<2|n>>4,s>=0&&(r[o++]=(15&n)<<4|s>>2),a>=0&&(r[o++]=(3&s)<<6|a)}return r.subarray(0,o)}function Jt(t){return Tt(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function Ct(t){return $t(t.replace(/-/g,"+").replace(/_/g,"/"))}function Kt(t){if("undefined"!=typeof TextEncoder)return(new TextEncoder).encode(t);const e=[];for(let n=0;n<t.length;n++){let r=t.codePointAt(n);r>65535&&n++,r<128?e.push(r):r<2048?e.push(192|r>>6,128|63&r):r<65536?e.push(224|r>>12,128|r>>6&63,128|63&r):e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)}return new Uint8Array(e)}function Rt(t){return Jt(Kt(t))}function Mt(t){return function(t){if("undefined"!=typeof TextDecoder)return(new TextDecoder).decode(t);let e="";for(let n=0;n<t.length;){const r=t[n];if(r<128)e+=String.fromCharCode(r),n+=1;else if(r<224)e+=String.fromCharCode((31&r)<<6|63&t[n+1]),n+=2;else if(r<240)e+=String.fromCharCode((15&r)<<12|(63&t[n+1])<<6|63&t[n+2]),n+=3;else{const o=(7&r)<<18|(63&t[n+1])<<12|(63&t[n+2])<<6|63&t[n+3];e+=String.fromCodePoint(o),n+=4}}return e}(Ct(t))}async function Bt(){if(!function(){var t;const e=globalThis.process;return Boolean(null==(t=null==e?void 0:e.versions)?void 0:t.node)}())return null;try{return await async function(t){return"function"==typeof require?require(t):Function("name","return import(name)")(t)}("node:crypto")}catch{return null}}function Ht(){var t;const e=null==(t=globalThis.crypto)?void 0:t.subtle;if(!e)throw new Error("namelib: no crypto backend available (need node:crypto or WebCrypto with Ed25519 support)");return e}const Pt=new Uint8Array([48,42,48,5,6,3,43,101,112,3,33,0]);function Ut(t){return $t(t.replace(/-----BEGIN [^-]+-----/g,"").replace(/-----END [^-]+-----/g,"").replace(/\s+/g,""))}function Lt(t){const e=Tt(t),n=[];for(let r=0;r<e.length;r+=64)n.push(e.slice(r,r+64));return`-----BEGIN PRIVATE KEY-----\n${n.join("\n")}\n-----END PRIVATE KEY-----\n`}function zt(t){const e=Ct(t.x);if(32!==e.length)throw new Error(`namelib: invalid Ed25519 jwk, x must be 32 bytes, got ${e.length}`);return function(t,e){const n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}(Pt,e)}async function Ft(t){const e=await Bt();if(e){const n=e.createPrivateKey({key:t,format:"pem"});return e.createPublicKey(n).export({format:"jwk"}).x}const n=Ht(),r=Ut(t),o=await n.importKey("pkcs8",r,{name:"Ed25519"},!0,["sign"]),i=await n.exportKey("jwk",o);if(!i.x)throw new Error("namelib: cannot derive public key from private pem");return i.x}function Yt(t){const e=t.x;if("string"!=typeof e||0===e.length)throw new Error("namelib: invalid jwk, missing x");return e}function qt(t){return{kty:"OKP",crv:"Ed25519",x:t}}async function Wt(t,e,n){const r=`${Rt(JSON.stringify(n??{alg:"EdDSA"}))}.${Rt(JSON.stringify(t))}`,o=await async function(t,e){const n=await Bt();if(n){const r=n.createPrivateKey({key:e,format:"pem"});return new Uint8Array(n.sign(null,t,r))}const r=Ht(),o=Ut(e),i=await r.importKey("pkcs8",o,{name:"Ed25519"},!1,["sign"]),s=await r.sign({name:"Ed25519"},i,t);return new Uint8Array(s)}(Kt(r),e);return`${r}.${Jt(o)}`}function Vt(t){const e=t.split(".");if(3!==e.length)throw new Error("namelib: invalid jwt, parts.len != 3");return JSON.parse(Mt(e[1]))}function Gt(t){const e=t.split(".");if(3!==e.length)throw new Error("namelib: invalid jwt, parts.len != 3");return JSON.parse(Mt(e[0]))}async function Zt(t,e){const n=t.split(".");if(3!==n.length)throw new Error("namelib: invalid jwt, parts.len != 3");const r=JSON.parse(Mt(n[0]));if("EdDSA"!==r.alg)throw new Error(`namelib: unsupported jwt alg: ${r.alg}`);const o=`${n[0]}.${n[1]}`,i=await async function(t,e,n){const r=await Bt();if(r){const o=r.createPublicKey({key:{kty:n.kty,crv:n.crv,x:n.x},format:"jwk"});return r.verify(null,t,o,e)}const o=Ht(),i=zt(n),s=await o.importKey("spki",i,{name:"Ed25519"},!1,["verify"]);return o.verify({name:"Ed25519"},s,e,t)}(Kt(o),Ct(n[2]),e);if(!i)throw new Error("namelib: jwt signature verify failed");return JSON.parse(Mt(n[1]))}function Xt(t){return t.startsWith("{")||t.startsWith("[")?{type:"json",value:JSON.parse(t)}:{type:"jwt",jwt:t}}function Qt(t){return"jwt"===t.type?Vt(t.jwt):t.value}let te=null;class ee{constructor(t,e){this.method=t,this.id=e}static undefined(){return new ee("undefined","undefined")}isUndefined(){return"undefined"===this.method}isValid(){return"undefined"!==this.method}static isDid(t){return t.startsWith("did:")}static fromStr(t){const e=t.split(":");if("did"!==e[0]){const e=ee.fromHostName(t);if(e)return e;throw new Error(`namelib: invalid did ${t}`)}if(e.length<3)throw new Error(`namelib: invalid did ${t}`);return new ee(e[1],e.slice(2).join(":"))}static fromHostName(t){if(t.endsWith(".did")){const e=t.slice(0,-4),n=e.lastIndexOf(".");if(n>0&&n<e.length-1)return new ee(e.slice(n+1),e.slice(0,n))}if(te)for(const e of Object.keys(te)){const n=te[e];if(t.endsWith(n)){if(t===n)break;const r=t.slice(0,t.length-n.length-1);return new ee(e,r)}}return new ee("web",t)}static fromHostNameByBridge(t,e,n){if(t.endsWith(n)&&t!==n){const r=t.slice(0,t.length-n.length-1);return new ee(e,r)}if(t.endsWith(".did")){const e=t.slice(0,-4),n=e.lastIndexOf(".");if(n>0&&n<e.length-1)return new ee(e.slice(n+1),e.slice(0,n))}return new ee("web",t)}toString(){return`did:${this.method}:${this.id}`}isNamedObjId(){return"dev"===this.method}getPathFromId(){const t=this.id.split(":");return t.length>1?t.slice(1).join("/"):null}upperDid(){const t=(this.id.split(":")[0]??"").split("%")[0]??"";switch(this.method){case"web":{if(ie(t))return null;const e=t.indexOf(".");if(e<0)return null;const n=t.slice(e+1);return n.includes(".")?new ee("web",n):null}case"bns":{const e=t.indexOf(".");return e<0?null:new ee("bns",t.slice(e+1))}default:return null}}toFilename(){const t="0123456789ABCDEF",e=Kt(this.toRawHostUri());let n="";for(const r of e){const e=String.fromCharCode(r);/[A-Za-z0-9._-]/.test(e)?n+=e:n+=`%${t[r>>4]}${t[15&r]}`}return n}getEd25519AuthKey(){if("dev"!==this.method)return null;try{const t=Ct(this.id);return 32===t.length&&Jt(t)===this.id?t:null}catch{return null}}getAuthKeyJwk(){return this.getEd25519AuthKey()?qt(this.id):null}toRawHostName(){const t=this.id.split(":")[0];return"web"===this.method?t:`${t}.${this.method}.did`}toRawHostUri(){const t=this.toRawHostName(),e=this.getPathFromId();return e?`${t}/${e}`:t}toHostNameByBridge(t){const e=this.id.split(":")[0];return"web"===this.method?e:`${e}.${t}`}toHostName(){const t=this.id.split(":")[0];if("web"===this.method)return t;if(te){const e=te[this.method];if(e)return`${t}.${e}`}return`${t}.${this.method}.did`}toHostUri(){const t=this.toHostName(),e=this.getPathFromId();return e?`${t}/${e}`:t}equals(t){return this.method===t.method&&this.id===t.id}}function ne(t){let e,n="OOD",r=t;t.startsWith("#")?(n="Gateway",r=t.slice(1)):t.startsWith("$")&&(n="OODOnly",r=t.slice(1));const o=r.lastIndexOf("@");let i,s=r;o>=0&&(s=r.slice(0,o),e=r.slice(o+1));let a=s;const c=s.indexOf(":");if(c>=0&&(a=s.slice(0,c),i=s.slice(c+1),!ie(i)))throw new Error(`namelib: invalid ip addr: ${i}`);if(void 0!==i&&void 0===e&&(e="wan"),!a)throw new Error("namelib: name in OODDescriptionString is empty");return se({name:a,nodeType:n,netId:e,ip:i})}function re(t){let e;switch(t.nodeType){case"OOD":e=t.name;break;case"Gateway":e=`#${t.name}`;break;case"OODOnly":e=`$${t.name}`;break;default:throw new Error("namelib: node type is not allow in oods")}return void 0!==t.ip?(e+=`:${t.ip}`,void 0!==t.netId&&"wan"!==t.netId&&(e+=`@${t.netId}`),e):(void 0!==t.netId&&(e+=`@${t.netId}`),e)}function oe(t){return"Gateway"===t||"OOD"===t}function ie(t){const e=t.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);return e?e.slice(1).every((t=>Number(t)<=255)):/^[0-9a-fA-F:]+$/.test(t)&&t.includes(":")}function se(t){for(const e of Object.keys(t))void 0===t[e]&&delete t[e];return t}function ae(t){return t instanceof ee?t:ee.fromStr(t)}function ce(t){const e=ae(t.did),n=t.now??Nt(),r=e.toString();return{"@context":At("owner"),id:r,verificationMethod:[{type:"Ed25519VerificationKey2020",id:"#main_key",controller:r,publicKeyJwk:t.publicKeyJwk}],authentication:["#main_key"],assertion_method:["#main_key"],capabilityInvocation:["#main_key"],exp:n+Et,iat:n,version_seq:0,name:t.name,display_name:t.displayName,zone_binding_model_version:2}}function ue(t,e){const n=ae(e).toString(),r=(t.binded_zone_list??[]).filter((t=>t!==n));r.unshift(n),t.binded_zone_list=r,t.zone_binding_model_version=2,le(t)}function le(t){var e;const n=null==(e=t.binded_zone_list)?void 0:e[0],r=`${t.id}#lastDoc`,o=(t.service??[]).filter((t=>t.id!==r));if(void 0!==n){const e=ae(n);o.push({id:r,type:"DIDDoc",serviceEndpoint:`https://${e.toHostName()}/resolve/${t.id}`})}t.service=o}function he(t,e){const n=ae(e).toString();return(t.binded_zone_list??[]).includes(n)}function de(t){const e=ae(t.id),n=ae(t.ownerDid),r=t.now??Nt(),o=e.toString();return{"@context":At("zone"),id:o,verificationMethod:[{type:"Ed25519VerificationKey2020",id:"#main_key",controller:n.toString(),publicKeyJwk:t.publicKeyJwk}],authentication:["#main_key"],assertionMethod:["#main_key"],capabilityInvocation:["#main_key"],service:[{id:`${o}#lastDoc`,type:"DIDDoc",serviceEndpoint:`https://${e.toHostName()}/resolve/this_zone`}],exp:r+Et,iat:r,version_seq:0,hostname:e.toHostName(),owner:n.toString(),oods:[],boot_jwt:""}}function fe(t){return se({id:void 0!==t.id?ae(t.id).toString():void 0,oods:[...t.oods],sn:t.sn,exp:t.exp,owner:void 0!==t.owner?ae(t.owner).toString():void 0,owner_key:t.ownerKey})}async function pe(t,e){const{id:n,oods:r,sn:o,exp:i,owner:s,owner_key:a,...c}=t;return Wt(se({id:n,oods:r,sn:o,exp:i,owner:s,...c,owner_key:a}),e)}function we(t){const e=t.now??Nt(),n=`did:dev:${t.pkx}`;return{"@context":At("device"),id:n,verificationMethod:[{type:"Ed25519VerificationKey2020",id:"#main_key",controller:n,publicKeyJwk:qt(t.pkx)}],authentication:["#main_key"],assertion_method:["#main_key"],capabilityInvocation:["#main_key"],exp:e+kt,iat:e,version_seq:0,owner:ee.undefined().toString(),device_type:"ood",name:t.name}}function me(t,e,n){return we({name:t,pkx:Yt(e),now:n})}function ye(t,e,n,r){const o=`did:dev:${e.x}`,i={"@context":At("device"),id:o,verificationMethod:[{type:"Ed25519VerificationKey2020",id:"#main_key",controller:o,publicKeyJwk:qt(e.x)}],authentication:["#main_key"],assertion_method:["#main_key"],capabilityInvocation:["#main_key"],exp:e.exp,iat:e.exp-kt,version_seq:0,zone_did:ae(n).toString(),owner:ae(r).toString(),device_type:"ood",device_mini_document_jwt:t,name:e.n};return void 0!==e.p&&(i.rtcp_port=e.p),i}async function be(t,e){if(void 0===t.version_seq)throw new Error("namelib: DeviceDocument version_seq is required when encoding as JWT");return Wt(ge(t),e)}function ge(t){const{"@context":e,id:n,verificationMethod:r,authentication:o,assertion_method:i,capabilityInvocation:s,service:a,exp:c,iat:u,version_seq:l,keyScope:h,"buckyos:scopes":d,zone_did:f,owner:p,device_type:w,device_mini_document_jwt:m,name:y,rtcp_port:b,ips:g,net_id:v,ddns_sn_url:_,support_container:j,capbilities:x,...I}=t,O=h??d;return se({"@context":e,id:n,verificationMethod:r,authentication:o,assertion_method:i&&i.length>0?i:void 0,capabilityInvocation:s&&s.length>0?s:void 0,service:a&&a.length>0?a:void 0,exp:c,iat:u,version_seq:l,...I,keyScope:O&&Object.keys(O).length>0?O:void 0,zone_did:f,owner:p,device_type:w,device_mini_document_jwt:m,name:y,rtcp_port:b,ips:g&&g.length>0?g:void 0,net_id:v,ddns_sn_url:_,support_container:!1!==j&&void 0,capbilities:x&&Object.keys(x).length>0?x:void 0})}function ve(t){return se({n:t.name,x:t.x,p:t.rtcpPort,exp:t.exp})}function _e(t){const e=t.verificationMethod.find((t=>"#main_key"===t.id));if(!e)throw new Error("namelib: device document has no #main_key verification method");return ve({name:t.name,x:Yt(e.publicKeyJwk),rtcpPort:t.rtcp_port,exp:t.exp})}async function je(t,e){const{n:n,x:r,p:o,exp:i,...s}=t;return Wt(se({n:n,x:r,p:o,exp:i,...s}),e)}function xe(t){const{"@context":e,id:n,verificationMethod:r,authentication:o,assertion_method:i,capabilityInvocation:s,service:a,exp:c,iat:u,version_seq:l,mini_version_seq:h,valid_iat:d,keyScope:f,"buckyos:scopes":p,name:w,display_name:m,avatar:y,meta:b,zone_binding_model_version:g,binded_zone_list:v,wallets:_,...j}=t,x=f??p;return se({"@context":e,id:n,verificationMethod:r,authentication:o,assertion_method:i&&i.length>0?i:void 0,capabilityInvocation:s&&s.length>0?s:void 0,service:a&&a.length>0?a:void 0,exp:c,iat:u,version_seq:l,mini_version_seq:h,valid_iat:d,...j,keyScope:x&&Object.keys(x).length>0?x:void 0,name:w,display_name:m,avatar:y,meta:b,zone_binding_model_version:g,binded_zone_list:v&&v.length>0?v:void 0,wallets:_&&Object.keys(_).length>0?_:void 0})}async function Ie(t,e){if(void 0===t.version_seq)throw new Error("namelib: ZoneDocument version_seq is required when encoding as JWT");return Wt(Oe(t),e)}function Oe(t){const{"@context":e,id:n,verificationMethod:r,authentication:o,assertionMethod:i,capabilityInvocation:s,service:a,exp:c,iat:u,version_seq:l,keyScope:h,"buckyos:scopes":d,hostname:f,owner:p,oods:w,boot_jwt:m,mini_device_jwts:y,devices:b,sn:g,...v}=t,_=h??d;return se({"@context":e,id:n,verificationMethod:r,authentication:o,assertionMethod:i&&i.length>0?i:void 0,capabilityInvocation:s&&s.length>0?s:void 0,service:a&&a.length>0?a:void 0,exp:c,iat:u,version_seq:l,...v,keyScope:_&&Object.keys(_).length>0?_:void 0,hostname:f,owner:p,oods:w,boot_jwt:m,mini_device_jwts:y&&Object.keys(y).length>0?y:void 0,devices:b&&Object.keys(b).length>0?b:void 0,sn:g})}function Se(t){return xe(t)}function ke(t){return Oe(t)}function Ee(t){return ge(t)}function Ae(t){return t.keyScope??t["buckyos:scopes"]??{}}function Ne(t,e){const n=t.verificationMethod??[];if(0===n.length)return null;if(void 0===e)return n[0].publicKeyJwk;const r=n.find((t=>t.id===e));return r?r.publicKeyJwk:null}function De(t,e){return Ae(t)[e]??null}function Te(t){return Object.keys(Ae(t)).length>0}function $e(t){const e=t.capabilityInvocation;if(Array.isArray(e)&&e.length>0)return e;const n=t.authentication;if(Array.isArray(n)&&n.length>0)return n;if(It(t)){const e=t.assertionMethod;if(Array.isArray(e)&&e.length>0)return e}return null}function Je(t,e){const n=t.id;if(e.startsWith(n)){const t=e.slice(n.length);if(t.startsWith("#"))return t}return e}function Ce(t,e){return e.startsWith("#")?`${t.id}${e}`:e}function Ke(t,e,n){return e===n||Je(t,e)===Je(t,n)||Ce(t,e)===Ce(t,n)}function Re(t,e){for(const n of e){const e=Ne(t,Je(t,n));if(e)return[n,e]}return null}function Me(t){const e="string"==typeof t?Xt(t):t,n="jwt"===e.type,r=Qt(e);if("object"!=typeof r||null===r)throw new Error("namelib: unknown did document");const o=t=>{if(n&&"number"!=typeof r.version_seq)throw new Error(`namelib: ${t} version_seq is required when encoding as JWT`)};if(void 0!==r.verificationMethod&&void 0!==r.name&&(void 0!==r.display_name||void 0!==r.displayName||void 0!==r.full_name))return o("OwnerDocument"),{docType:"owner",doc:r};if(void 0!==r.httpServicePorts)return o("AgentDocument"),{docType:"agent",doc:r};if(void 0!==r.device_type)return o("DeviceDocument"),{docType:"device",doc:r};if(void 0!==r.oods)return o("ZoneDocument"),{docType:"zone",doc:r};if(Array.isArray(r.service)&&r.service.some((t=>(null==t?void 0:t.type)===pt)))return o("DIDObjectCard"),{docType:"did-object",doc:r};throw new Error("namelib: unknown did document")}const Be=Object.freeze(Object.defineProperty({__proto__:null,BUCKYOS_CONTEXT_BASE:St,DEFAULT_EXPIRE_TIME:kt,DID:ee,DID_CORE_CONTEXT:Ot,DID_DOC_AUTHKEY:"#auth-key",KEY_SCOPE_AGENT_CREATE_CONTENT:"agent:create-content",KEY_SCOPE_AGENT_RECEIVE:"agent:receive",KEY_SCOPE_AGENT_SPEND:"agent:spend",KEY_SCOPE_CONTENT_CREATE:"content:create",KEY_SCOPE_MANUAL:"manual",KEY_SCOPE_MESSAGE_CREATE:"message:create",KEY_SCOPE_ZONE_PUBLISH:"zone:publish",ZONE_BINDING_MODEL_VERSION:2,base64UrlDecodeToBytes:Ct,base64UrlDecodeToString:Mt,base64UrlEncodeBytes:Jt,base64UrlEncodeString:Rt,buckyosContext:At,buckyosGetUnixTimestamp:Nt,createJwkByX:qt,decodeDeviceDocument:async function(t,e){const n=e?await Zt(t,e):Vt(t);if(void 0===n.version_seq)throw new Error("namelib: DeviceDocument version_seq is required when decoding from JWT");return n},decodeJwtClaimWithoutVerify:Vt,decodeJwtHeaderWithoutVerify:Gt,decodeZoneBootDocument:async function(t,e){return e?await Zt(t,e):Vt(t)},derToPkcs8Pem:Lt,deviceDocumentToOrderedJson:Ee,deviceMiniDocumentFromJwt:async function(t,e){return e?await Zt(t,e):Vt(t)},deviceMiniDocumentToJwt:je,encodeDeviceDocument:be,encodeOwnerDocument:async function(t,e){if(void 0===t.version_seq)throw new Error("namelib: OwnerDocument version_seq is required when encoding as JWT");return Wt(xe(t),e)},encodeZoneBootDocument:pe,encodeZoneDocument:Ie,encodedDocumentFromStr:Xt,encodedDocumentToJsonValue:Qt,encodedDocumentToString:function(t){return"jwt"===t.type?t.jwt:JSON.stringify(t.value)},expandLocalKeyId:Ce,generateEd25519KeyPair:async function(){const t=await Bt();if(t){const{privateKey:e,publicKey:n}=t.generateKeyPairSync("ed25519");return{privateKeyPem:e.export({type:"pkcs8",format:"pem"}).toString(),publicKeyJwk:qt(n.export({format:"jwk"}).x)}}const e=Ht(),n=await e.generateKey({name:"Ed25519"},!0,["sign","verify"]),r=new Uint8Array(await e.exportKey("pkcs8",n.privateKey)),o=await e.exportKey("jwk",n.publicKey);if(!o.x)throw new Error("namelib: WebCrypto did not return Ed25519 public jwk");return{privateKeyPem:Lt(r),publicKeyJwk:qt(o.x)}},getDeviceDidFromJwk:function(t){return`did:dev:${Yt(t)}`},getDidDocType:function(t){return t.docType},getDocumentAuthKey:Ne,getDocumentDefaultKey:function(t){const e=(t.verificationMethod??[]).find((t=>"#main_key"===t.id));return e?e.publicKeyJwk:null},getDocumentKeyScope:Ae,getKeyByScope:function(t,e){const n=De(t,e);if(n)return Re(t,n);if(Te(t))return null;const r=$e(t);if(r){const e=Re(t,r);if(e)return e}const o=Ne(t);return o?["",o]:null},getKeyFromKeyIds:Re,getKeyIdsByScope:De,getKnownWeb3BridgeConfig:function(){return te},getPublicKeyXFromPrivatePem:Ft,getStandardScopeKeyIds:$e,getXFromJwk:Yt,hasKeyScope:Te,isKeyAllowedInScope:function(t,e,n){const r=De(t,e);if(r)return r.some((e=>Ke(t,e,n)));if(Te(t))return!1;const o=$e(t);return o?o.some((e=>Ke(t,e,n))):null!==Ne(t,Je(t,n))},isSameDocumentKeyId:Ke,newDeviceDocument:we,newDeviceDocumentByJwk:me,newDeviceDocumentByMiniDocument:ye,newDeviceMiniDocument:ve,newDeviceMiniDocumentByDeviceDocument:_e,newOwnerDocument:ce,newOwnerDocumentByPkx:function(t,e){const n=t.split(":");if(0===n.length||!n[0])throw new Error("namelib: invalid pkx: empty x");const r=n[0];if(!/^[A-Za-z0-9_-]+$/.test(r))throw new Error("namelib: invalid pkx: x must be base64url");if(32!==Ct(r).length)throw new Error("namelib: invalid pkx: x length must be 32 bytes");const o=qt(r);if(1===n.length){const t=ee.fromStr(e),n=t.id;return ce({did:t,name:n,displayName:`${n}@${e}`,publicKeyJwk:o})}if(n.length>=3){const t=n[2];return ce({did:new ee(n[1],n[2]),name:t,displayName:`${t}@${e}`,publicKeyJwk:o})}throw new Error(`namelib: invalid pkx: ${t}`)},newZoneBootDocument:fe,newZoneDocument:de,normalizeKeyIdForLocalLookup:Je,oodDescriptionToString:re,oodNodeTypeIsGateway:oe,oodNodeTypeIsOod:function(t){return"OOD"===t||"OODOnly"===t},ownerDocumentGetDefaultZoneDid:function(t){var e;return(null==(e=t.binded_zone_list)?void 0:e[0])??null},ownerDocumentGetHistoricalKeys:function(t){return t.verificationMethod.filter((t=>"#main_key"!==t.id)).map((t=>[t.id,t.publicKeyJwk]))},ownerDocumentGetZoneBindingState:function(t,e){const n=t.zone_binding_model_version;return void 0===n?"legacy":2!==n?"unsupported_version":he(t,e)?"bound_v2":"unbound_v2"},ownerDocumentIsBoundToZone:he,ownerDocumentRemoveBoundZone:function(t,e){var n;const r=ae(e).toString(),o=(null==(n=t.binded_zone_list)?void 0:n.length)??0;t.binded_zone_list=(t.binded_zone_list??[]).filter((t=>t!==r));const i=t.binded_zone_list.length!==o;return t.zone_binding_model_version=2,le(t),i},ownerDocumentSetDefaultZoneDid:ue,ownerDocumentToOrderedJson:Se,ownerDocumentValidateJwtRevocation:function(t,e,n){if(void 0===t.mini_version_seq&&void 0===t.valid_iat)return;if("jwt"!==n.type)return;const r=Qt(n);if(void 0!==t.mini_version_seq){const n="number"==typeof(null==r?void 0:r.version_seq)?r.version_seq:void 0;if(void 0===n)throw new Error(`namelib: ${e} JWT missing version_seq required by owner revocation policy`);if(n<=t.mini_version_seq)throw new Error(`namelib: ${e} JWT version_seq ${n} is not greater than owner mini_version_seq ${t.mini_version_seq}`)}if(void 0!==t.valid_iat){const n="number"==typeof(null==r?void 0:r.iat)?r.iat:void 0;if(void 0===n)throw new Error(`namelib: ${e} JWT missing iat required by owner revocation policy`);if(n<=t.valid_iat)throw new Error(`namelib: ${e} JWT iat ${n} is not greater than owner valid_iat ${t.valid_iat}`)}},parseDidDoc:Me,parseDidDocAs:function(t,e){const n=Me(t);if(n.docType!==e)throw new Error(`namelib: expected ${e} document, got ${n.docType}`);return n.doc},parseOODDescription:ne,pemToDer:Ut,resetKnownWeb3BridgeConfigForTest:function(){te=null},setKnownWeb3BridgeConfig:function(t){return null===te&&(te={...t},!0)},signJwtEdDSA:Wt,verifyJwtEdDSA:Zt,zoneBootDocumentGetGatewayName:function(t){for(const e of t.oods){const t=ne(e);if(oe(t.nodeType))return t.name}return""},zoneBootDocumentToZoneDocument:function(t,e){if(!t.id||!t.owner_key)throw new Error("namelib: zone boot document needs id and owner_key to build zone document");const n=t.owner?ee.fromStr(t.owner):ee.undefined(),r=de({id:t.id,ownerDid:n,publicKeyJwk:t.owner_key});return r.boot_jwt=e,r.oods=[...t.oods],void 0!==t.sn?r.sn=t.sn:delete r.sn,r.exp=t.exp,r.iat=t.exp-kt,r.version_seq=0,r.owner=t.owner??ee.undefined().toString(),r},zoneDocumentGetDefaultGateway:function(t){for(const e of t.oods){const t=ne(e);if(oe(t.nodeType))return t.name}return null},zoneDocumentGetSnApiUrl:function(t){return void 0!==t.sn?`https://${t.sn}/kapi/sn`:null},zoneDocumentToOrderedJson:ke},Symbol.toStringTag,{value:"Module"}));class He extends Error{constructor(t,e){super(`${t}: ${e}`),this.kind=t,this.name="NdnError"}}const Pe="cyfile",Ue="cydir",Le="cymsg",ze="cypath",Fe="cyinc",Ye="cyrel",qe="cypack",We="cymap",Ve="cylist",Ge="clist",Ze="same",Xe="part_of",Qe="0123456789abcdef";function tn(t){let e="";for(let n=0;n<t.length;n++){const r=t[n];e+=Qe[r>>>4&15],e+=Qe[15&r]}return e}function en(t){if(t.length%2!=0)throw new He("InvalidId",`invalid hex length: ${t.length}`);const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=Qe.indexOf(t[2*n].toLowerCase()),o=Qe.indexOf(t[2*n+1].toLowerCase());if(r<0||o<0)throw new He("InvalidId","invalid hex char at offset "+2*n);e[n]=r<<4|o}return e}const nn="abcdefghijklmnopqrstuvwxyz234567";function rn(t){let e=0,n=0,r="";for(let o=0;o<t.length;o++)for(n=n<<8|t[o],e+=8;e>=5;)e-=5,r+=nn[n>>>e&31];return e>0&&(r+=nn[n<<5-e&31]),r}function on(t){const e=t.toLowerCase();let n=0,r=0;const o=[];for(let i=0;i<e.length;i++){const t=e[i],s=nn.indexOf(t);if(s<0)throw new He("InvalidId",`invalid base32 char '${t}' at ${i}`);r=r<<5|s,n+=5,n>=8&&(n-=8,o.push(r>>>n&255))}return new Uint8Array(o)}function sn(t){if(!Number.isFinite(t)||t<0)throw new He("InvalidParam",`varint must be non-negative finite: ${t}`);if(!Number.isSafeInteger(t))throw new He("InvalidParam",`varint exceeds safe integer range: ${t}`);const e=[];let n=t;for(;n>=128;)e.push(127&n|128),n=Math.floor(n/128);return e.push(127&n),new Uint8Array(e)}function an(t,e=0){let n=0,r=1,o=e,i=0;for(;o<t.length;){const e=t[o++];i++;if(n+=(127&e)*r,!Number.isSafeInteger(n))throw new He("InvalidData","varint exceeds safe integer range");if(!(128&e))return[n,i];if(r*=128,i>10)throw new He("InvalidData","varint too long")}throw new He("InvalidData","varint truncated")}function cn(t){const e=new at("SHA-256","TEXT",{encoding:"UTF8"});return e.update(t),e.getHash("UINT8ARRAY")}function un(t){for(let e=0;e<t.length;e++){const n=t.charCodeAt(e);if(!(n<55296||n>57343)){if(n<=56319){const n=t.charCodeAt(e+1);if(e+1<t.length&&n>=56320&&n<=57343){e++;continue}}throw new He("InvalidData","JSON string contains lone surrogate")}}}function ln(t,e,n){"__proto__"===e?Object.defineProperty(t,e,{value:n,enumerable:!0,writable:!0,configurable:!0}):t[e]=n}function hn(t){if(function(t){switch(typeof t){case"string":return void un(t);case"number":if(!Number.isFinite(t))throw new He("InvalidData","JSON number MUST be finite for JCS");if(Object.is(t,-0))throw new He("InvalidData","JSON number MUST NOT be negative zero for JCS");return;case"boolean":case"object":return;case"undefined":throw new He("InvalidData","undefined is not a valid JSON value");case"bigint":throw new He("InvalidData","bigint is not a valid JSON value");case"function":throw new He("InvalidData","function is not a valid JSON value");case"symbol":throw new He("InvalidData","symbol is not a valid JSON value")}}(t),null===t||"object"!=typeof t)return t;if(Array.isArray(t)){const e=new Array(t.length);for(let n=0;n<t.length;n++){if(!Object.prototype.hasOwnProperty.call(t,n))throw new He("InvalidData","sparse arrays are not valid JSON values");e[n]=hn(t[n])}return e}const e=Object.keys(t).sort(),n={};for(const r of e)un(r),ln(n,r,hn(t[r]));return n}function dn(t){const e=hn(t),n=ft(e);if(void 0===n)throw new He("InvalidData","failed to canonicalize JSON value");return n}const fn={Sha256:"sha256",Sha512:"sha512",QCID:"qcid",Blake2s256:"blake2s256",Keccak256:"keccak256",hashResultSize(t){switch(t){case"sha256":case"qcid":case"blake2s256":case"keccak256":return 32;case"sha512":return 64}},parse(t){const e=t.startsWith("mix");return[fn.fromString(t),e]},fromString(t){switch(t){case"sha256":case"mix256":return"sha256";case"sha512":case"mix512":return"sha512";case"qcid":case"mixqcid":return"qcid";case"blake2s256":case"mixblake2s256":return"blake2s256";case"keccak256":case"mixkeccak256":return"keccak256";default:throw new He("InvalidData",`Invalid hash method: ${t}`)}}},pn={Sha256:"sha256",Mix256:"mix256",Sha512:"sha512",Mix512:"mix512",QCID:"qcid",Blake2s256:"blake2s256",MixBlake2s256:"mixblake2s256",Keccak256:"keccak256",MixKeccak256:"mixkeccak256",isChunkType(t){switch(t){case"sha256":case"mix256":case"sha512":case"mix512":case"qcid":case"blake2s256":case"mixblake2s256":case"keccak256":case"mixkeccak256":return!0;default:return!1}},isMix(t){switch(t){case"mix256":case"mix512":case"mixblake2s256":case"mixkeccak256":case"qcid":return!0;default:return!1}},fromHashType(t,e){switch(t){case"sha256":return e?"mix256":"sha256";case"sha512":return e?"mix512":"sha512";case"qcid":if(!e)throw new He("InvalidObjType","QCID must be mix hash");return"qcid";case"blake2s256":return e?"mixblake2s256":"blake2s256";case"keccak256":return e?"mixkeccak256":"keccak256"}},toHashMethod(t){switch(t){case"sha256":case"mix256":return"sha256";case"sha512":case"mix512":return"sha512";case"qcid":return"qcid";case"blake2s256":case"mixblake2s256":return"blake2s256";case"keccak256":case"mixkeccak256":return"keccak256";default:throw new He("InvalidObjType",`invalid chunk type: ${t}`)}}};class wn{constructor(t,e){this.objType=t,this.objHash=e}static fromString(t){const e=t.split(":");if(1===e.length){const t=on(e[0]);let n=-1;for(let e=0;e<t.length;e++)if(58===t[e]){n=e;break}if(n<0)throw new He("InvalidId","separator ':' not found");const r=vr(t.subarray(0,n)),o=t.slice(n+1);return new wn(r,o)}if(2===e.length)return new wn(e[0],en(e[1]));throw new He("InvalidId",t)}static fromBytes(t){if(t.length<3)throw new He("InvalidId","objid bytes too short");let e=-1;for(let o=0;o<t.length;o++)if(58===t[o]){e=o;break}if(e<0)throw new He("InvalidId","separator ':' not found");const n=vr(t.subarray(0,e)),r=t.slice(e+1);return new wn(n,r)}static fromValue(t){if("string"==typeof t)return wn.fromString(t);throw new He("InvalidData","ObjId MUST be string")}static fromHostname(t){const e=t.split(".")[0];return wn.fromString(e)}static fromPath(t){const e=t.split("/");for(let n=0;n<e.length;n++){const t=e[n];if(0!==t.length)try{const r=wn.fromString(t);return n<e.length-1?{objId:r,subPath:"/"+e.slice(n+1).join("/")}:{objId:r,subPath:null}}catch{}}throw new He("InvalidId",`no objid found in path: ${t}`)}static fromRaw(t,e){return new wn(t,e)}isChunk(){return pn.isChunkType(this.objType)}isChunkList(){return this.objType===Ge}isJson(){return!this.isChunk()&&!this.isContainer()&&this.objType!==qe}isDirObject(){return this.objType===Ue}isFileObject(){return this.objType===Pe}isContainer(){switch(this.objType){case Ue:case We:case Ve:case Ge:return!0;default:return!1}}isBigContainer(){switch(this.objType){case We:case Ve:case Ge:return!0;default:return!1}}toString(){return`${this.objType}:${tn(this.objHash)}`}toFilename(){return`${tn(this.objHash)}.${this.objType}`}toBase32(){return rn(this.toBytes())}toBytes(){const t=gr(this.objType),e=new Uint8Array(t.length+1+this.objHash.length);return e.set(t,0),e[t.length]=58,e.set(this.objHash,t.length+1),e}toJSON(){return this.toString()}equals(t){if(this.objType!==t.objType)return!1;if(this.objHash.length!==t.objHash.length)return!1;for(let e=0;e<this.objHash.length;e++)if(this.objHash[e]!==t.objHash[e])return!1;return!0}}class mn{constructor(t,e){this.chunkType=t,this.hashResult=e}static defaultChunkType(){return"mix256"}static fromString(t){const e=wn.fromString(t);if(!e.isChunk())throw new He("InvalidId",`invalid chunk id: ${t}`);return new mn(e.objType,e.objHash)}static fromObjId(t){return new mn(t.objType,new Uint8Array(t.objHash))}static fromBytes(t){const e=wn.fromBytes(t);return new mn(e.objType,e.objHash)}static fromHashResult(t,e){return new mn(e,new Uint8Array(t))}static fromMixHashResult(t,e,n){return new mn(n,mn.mixLengthAndHashResult(t,e))}static fromMixHashResultByHashMethod(t,e,n){const r=pn.fromHashType(n,!0);return new mn(r,mn.mixLengthAndHashResult(t,e))}static fromSha256Result(t){return new mn("sha256",new Uint8Array(t))}static fromMix256Result(t,e){return new mn("mix256",mn.mixLengthAndHashResult(t,e))}static mixLengthAndHashResult(t,e){const n=sn(t),r=new Uint8Array(n.length+e.length);return r.set(n,0),r.set(e,n.length),r}toObjId(){return new wn(this.chunkType,new Uint8Array(this.hashResult))}toString(){return`${this.chunkType}:${tn(this.hashResult)}`}toBase32(){const t=gr(this.chunkType),e=new Uint8Array(t.length+1+this.hashResult.length);return e.set(t,0),e[t.length]=58,e.set(this.hashResult,t.length+1),rn(e)}toDidString(){return`did:${this.chunkType}:${tn(this.hashResult)}`}toBytes(){return this.toObjId().toBytes()}toJSON(){return this.toString()}getLength(){if(0===this.hashResult.length)return null;if(!pn.isMix(this.chunkType))return null;try{const[t]=an(this.hashResult,0);return t}catch{return null}}equalsHash(t){if(this.hashResult.length!==t.length)return!1;for(let e=0;e<this.hashResult.length;e++)if(this.hashResult[e]!==t[e])return!1;return!0}}class yn{genObjId(){return gn(this.getObjType(),this.toJSON())}}function bn(t,e){const n=cn(e);return wn.fromRaw(t,n)}function gn(t,e){const n=dn(e);return[bn(t,n),n]}function vn(t,e){const[n]=gn(t.objType,e);return t.equals(n)}const _n="\\u0009-\\u000d\\u0020\\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000",jn=new RegExp(`^[${_n}]+`),xn=new RegExp(`^[${_n}]|[${_n}]$`);function In(t){try{return Vt(t)}catch(e){throw new He("DecodeError",`decode jwt failed: ${e.message}`)}}function On(t){const e=t.replace(jn,"");if(e.startsWith("{")||e.startsWith("["))try{return JSON.parse(t)}catch(n){throw new He("InvalidId",`failed to parse obj_str: ${n.message}`)}return In(t)}function Sn(t,e){return gn(t,In(e))}class kn{constructor(t={}){this.did=t.did??null,this.name=t.name??"",this.author=t.author??"",this.owner=t.owner??"",this.create_time=t.create_time??0,this.last_update_time=t.last_update_time??0,this.copyright=t.copyright??null,this.tags=t.tags??[],this.categories=t.categories??[],this.base_on=t.base_on??null,this.directory=t.directory??{},this.references=t.references??{},this.exp=t.exp??0}toJSON(){const t={};return null!=this.did&&(t.did=this.did),this.name.length>0&&(t.name=this.name),this.author.length>0&&(t.author=this.author),this.owner.length>0&&(t.owner=this.owner),t.create_time=this.create_time,t.last_update_time=this.last_update_time,null!=this.copyright&&(t.copyright=this.copyright),this.tags.length>0&&(t.tags=this.tags),this.categories.length>0&&(t.categories=this.categories),null!=this.base_on&&(t.base_on=this.base_on.toString()),Object.keys(this.directory).length>0&&(t.directory=this.directory),Object.keys(this.references).length>0&&(t.references=this.references),0!==this.exp&&(t.exp=this.exp),t}}function En(){return Math.floor(Date.now()/1e3)}class An extends yn{constructor(t,e,n){super(),this.content_obj=new kn({name:t}),this.size=e,this.content=n,this.meta={}}static fromJSON(t){const e=new An("",0,""),n={},r={},o=new Set(["did","name","author","owner","create_time","last_update_time","copyright","tags","categories","base_on","directory","references","exp"]);for(const[i,s]of Object.entries(t))"size"===i?e.size=s??0:"content"===i?e.content=s??"":o.has(i)?"base_on"===i&&"string"==typeof s?n.base_on=wn.fromString(s):n[i]=s:r[i]=s;return e.content_obj=new kn(n),e.meta=r,e}getObjType(){return Pe}toJSON(){const t={...this.content_obj.toJSON()};0!==this.size&&(t.size=this.size),this.content.length>0&&(t.content=this.content);for(const[e,n]of Object.entries(this.meta))t[e]=n;return t}}class Nn extends yn{constructor(t,e,n,r,o){super();const i=En();this.path=t,this.target=e,this.iat=n??i,this.exp=r??i+94608e3,this.host=o}static fromJSON(t){const e=String(t.path??""),n=wn.fromString(String(t.target??"")),r=Number(t.iat??0),o=Number(t.exp??0),i="string"==typeof t.host?t.host:void 0;return new Nn(e,n,r,o,i)}getObjType(){return ze}toJSON(){const t={path:this.path,iat:this.iat,target:this.target.toString(),exp:this.exp};return null!=this.host&&(t.host=this.host),t}}class Dn extends yn{constructor(t,e,n,r,o){super();const i=En();this.content_id=t.toString(),this.content_obj=e,this.curator=n,this.editor=[],this.meta=null,this.rank=r,this.collection=o,this.review_url=null,this.iat=i,this.exp=i+31104e3}static fromJSON(t){const e=new Dn(wn.fromString(String(t.content_id??"")),t.content_obj??null,String(t.curator??""),Number(t.rank??0),Array.isArray(t.collection)?t.collection.slice():[]);return e.content_id=String(t.content_id??""),e.editor=Array.isArray(t.editor)?t.editor.slice():[],e.meta=t.meta??null,e.review_url="string"==typeof t.review_url?t.review_url:null,e.iat=Number(t.iat??0),e.exp=Number(t.exp??0),e}getObjType(){return Fe}toJSON(){const t={content_id:this.content_id,content_obj:this.content_obj,curator:this.curator,editor:this.editor,meta:this.meta,rank:this.rank,iat:this.iat,exp:this.exp};return this.collection.length>0&&(t.collection=this.collection),null!=this.review_url&&(t.review_url=this.review_url),t}}const Tn={fromObjId:t=>({kind:"objId",objId:t}),fromObject:(t,e)=>({kind:"object",objType:t,obj:e}),fromObjectJwt:(t,e)=>({kind:"objectJwt",objType:t,jwt:e}),getObjType(t){switch(t.kind){case"objId":return t.objId.objType;case"object":case"objectJwt":return t.objType}},getObjId(t){switch(t.kind){case"objId":return[t.objId,""];case"object":return gn(t.objType,t.obj);case"objectJwt":return Sn(t.objType,t.jwt)}},toJSON(t){switch(t.kind){case"objId":return t.objId.toString();case"object":return{obj_type:t.objType,body:t.obj};case"objectJwt":return{obj_type:t.objType,jwt:t.jwt}}},fromJSON(t){if("string"==typeof t)return{kind:"objId",objId:wn.fromString(t)};if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t,n=e.obj_type;if("string"!=typeof n)throw new He("InvalidData","SimpleMapItem must have obj_type field");if("string"==typeof e.jwt)return{kind:"objectJwt",objType:n,jwt:e.jwt};if("body"in e)return{kind:"object",objType:n,obj:e.body};throw new He("InvalidData","SimpleMapItem must have body or jwt field")}throw new He("InvalidData","SimpleMapItem must be string or object")}};class $n{constructor(){this.body=new Map}static fromJSON(t){const e=new $n;if(!t||"object"!=typeof t)throw new He("InvalidData","SimpleObjectMap must be an object");const n=t.body;if(null==n)return e;if("object"!=typeof n||Array.isArray(n))throw new He("InvalidData","SimpleObjectMap.body must be an object");for(const[r,o]of Object.entries(n))e.body.set(r,Tn.fromJSON(o));return e}genObjIdWithRealObj(t,e){const n={};for(const[r,o]of this.body){const[t]=Tn.getObjId(o);n[r]=t.toString()}return e.body=n,gn(t,e)}get size(){return this.body.size}isEmpty(){return 0===this.body.size}get(t){return this.body.get(t)}set(t,e){this.body.set(t,e)}delete(t){return this.body.delete(t)}has(t){return this.body.has(t)}keys(){return this.body.keys()}values(){return this.body.values()}entries(){return this.body.entries()}toJSON(){const t={};for(const[e,n]of this.body)t[e]=Tn.toJSON(n);return{body:t}}}class Jn extends yn{constructor(t){super(),this.content_obj=null!=t?new kn({name:t}):new kn,this.meta={},this.total_size=0,this.file_count=0,this.file_size=0,this.object_map=new $n}static fromJSON(t){const e=new Jn,n=new Set(["did","name","author","owner","create_time","last_update_time","copyright","tags","categories","base_on","directory","references","exp"]),r={};for(const[o,i]of Object.entries(t))if("meta"===o)e.meta=i??{};else if("total_size"===o)e.total_size=Number(i??0);else if("file_count"===o)e.file_count=Number(i??0);else if("file_size"===o)e.file_size=Number(i??0);else if("body"===o){const t=i;if(t)for(const[n,r]of Object.entries(t))e.object_map.set(n,Tn.fromJSON(r))}else n.has(o)&&("base_on"===o&&"string"==typeof i?r.base_on=wn.fromString(i):r[o]=i);return e.content_obj=new kn(r),e}getObjType(){return Ue}toJSON(){const t={...this.content_obj.toJSON()};return Object.keys(this.meta).length>0&&(t.meta=this.meta),t.total_size=this.total_size,t.file_count=this.file_count,t.file_size=this.file_size,t.body=this.object_map.toJSON().body,t}genObjId(){const t={...this.content_obj.toJSON()};return t.total_size=this.total_size,t.file_count=this.file_count,t.file_size=this.file_size,this.object_map.genObjIdWithRealObj(Ue,t)}get size(){return this.object_map.size}isEmpty(){return this.object_map.isEmpty()}get(t){return this.object_map.get(t)}delete(t){return this.object_map.delete(t)}has(t){return this.object_map.has(t)}keys(){return this.object_map.keys()}values(){return this.object_map.values()}entries(){return this.object_map.entries()}addFile(t,e,n){this.file_size+=n,this.file_count+=1,this.total_size+=n,this.object_map.set(t,Tn.fromObject(Pe,e))}addDirectory(t,e,n){if(e.objType!==Ue)throw new He("InvalidParam","dir_obj_id is not a directory");this.total_size+=n,this.object_map.set(t,Tn.fromObjId(e))}listEntries(){return Array.from(this.object_map.keys())}isFile(t){const e=this.object_map.get(t);return!!e&&("object"===e.kind&&e.objType===Pe)}isDirectory(t){const e=this.object_map.get(t);if(!e)return!1;switch(e.kind){case"objId":return e.objId.objType===Ue;case"objectJwt":return e.objType===Ue;default:return!1}}}class Cn{constructor(){this.total_size=0,this.body=[]}static fromChunkList(t){const e=new Cn;for(const n of t){const t=n.getLength();if(null==t)throw new He("InvalidParam","get chunk length from chunkid failed");e.total_size+=t}return e.body=t.slice(),e}static fromJson(t){let e;try{e=JSON.parse(t)}catch(n){throw new He("InvalidParam",`parse chunk list from json failed: ${n.message}`)}return Cn.fromJsonValue(e)}static fromJsonValue(t){if(!Array.isArray(t))throw new He("InvalidParam","chunk list must be a JSON array");const e=t.map((t=>{if("string"!=typeof t)throw new He("InvalidParam","chunk list item must be a string");return mn.fromString(t)}));return Cn.fromChunkList(e)}appendChunk(t){const e=t.getLength();if(null==e)throw new He("InvalidParam","get chunk length from chunkid failed");this.body.push(t),this.total_size+=e}genObjId(){const t=this.body.map((t=>t.toString())),[e,n]=gn(Ge,t),r=mn.mixLengthAndHashResult(this.total_size,e.objHash);return[wn.fromRaw(Ge,r),n]}}class Kn extends yn{constructor(t,e,n,r={}){super(),this.source=t,this.relation=e,this.target=n,this.body=r,this.iat=null,this.exp=null}static fromJSON(t){const e=new Set(["source","relation","target","iat","exp"]),n={};for(const[o,i]of Object.entries(t))e.has(o)||(n[o]=i);const r=new Kn(wn.fromString(String(t.source??"")),String(t.relation??""),wn.fromString(String(t.target??"")),n);return r.iat="number"==typeof t.iat?t.iat:null,r.exp="number"==typeof t.exp?t.exp:null,r}static createByLinkData(t,e){switch(e.kind){case"sameAs":return new Kn(t,Ze,e.target);case"partOf":return new Kn(t,Xe,e.target,{range:{start:e.range.start,end:e.range.end}})}}getLinkData(){switch(this.relation){case Ze:return{kind:"sameAs",target:this.target};case Xe:{const t=this.body.range;if(!t||"number"!=typeof t.start||"number"!=typeof t.end)throw new He("InvalidLink",`invalid range: ${JSON.stringify(this.body.range)}`);return{kind:"partOf",target:this.target,range:{start:t.start,end:t.end}}}default:throw new He("InvalidLink",`invalid relation: ${this.relation}`)}}getObjType(){return Ye}toJSON(){const t={source:this.source.toString(),relation:this.relation,target:this.target.toString()};for(const[e,n]of Object.entries(this.body))t[e]=n;return null!=this.iat&&(t.iat=this.iat),null!=this.exp&&(t.exp=this.exp),t}}function Rn(t,e){return new He("DecodeError",`${t} must be ${e}`)}function Mn(t,e){if(null===t||"object"!=typeof t||Array.isArray(t))throw Rn(e,"an object");return t}function Bn(t,e){if("string"!=typeof t)throw Rn(e,"a string");return t}function Hn(t,e){if("number"!=typeof t||!Number.isSafeInteger(t)||t<0)throw Rn(e,"a non-negative safe integer");return t}function Pn(t,e){const n=Bn(t,e);try{return wn.fromString(n).toString()}catch(r){throw Rn(e,`an ObjId (${r.message})`)}}function Un(t,e){const n=Bn(t,e),r=n.split(":");if(r.length<3||"did"!==r[0])throw Rn(e,"a did:method:id");return n}function Ln(t,e,n){if("string"!=typeof e||!t.includes(e))throw Rn(n,`one of ${t.join(", ")}`);return e}function zn(t,e,n){if(!Array.isArray(t))throw Rn(e,"an array");return t.map(((t,r)=>n(t,`${e}[${r}]`)))}function Fn(t,e,n){return null==t?void 0:n(t,e)}function Yn(t){const e={};for(const[n,r]of Object.entries(t))void 0!==r&&ln(e,n,r);return e}const qn=["chat","group_msg","deliver","notify","event","operation"],Wn=new Map([["image/jpg","image/jpeg"],["image/svg","image/svg+xml"],["video/avi","video/x-msvideo"],["audio/mp3","audio/mpeg"],["audio/x-wav","audio/wav"]]),Vn=["edit","redact","reaction","thread"],Gn=["context","input","output","evidence","control"],Zn=["from","to","kind","to_session","thread","relates_to","mentions","workspace","created_at_ms","expires_at_ms","nonce","content","proof"];function Xn(t){if(!t||"."===t||".."===t||xn.test(t))return!1;let e=0;for(const n of t){const t=n.codePointAt(0)??0;if(t<=31||t>=127&&t<=159)return!1;e+=1}return e<=200}function Qn(t){var e;const n=t.to_session;if(null!=n){if(!Xn(n))throw new He("InvalidData",`invalid msg to_session: ${JSON.stringify(n)}`);if(1!==t.to.length)throw new He("InvalidData","msg.to_session requires exactly one msg.to")}const r=t.mentions;if(null!=r&&!(null==(e=r.dids)?void 0:e.length)&&!0!==r.all)throw new He("InvalidData","msg.mentions must be omitted when empty");const o=t.relates_to;if(null!=o){if(wn.fromString(o.target).objType!==Le)throw new He("InvalidData",`msg.relates_to.target must be a ${Le} object`);const t=o.key??void 0;if("reaction"===o.rel){if(void 0===t)throw new He("InvalidData","reaction requires msg.relates_to.key");const e=gr(t).length;if(0===e||e>64)throw new He("InvalidData","msg.relates_to.key must be 1-64 bytes")}else if(Vn.includes(o.rel)&&void 0!==t)throw new He("InvalidData","msg.relates_to.key is only allowed for reaction")}if(void 0!==t.proof)throw new He("InvalidData","msg meta key 'proof' is reserved")}function tr(t,e){const n=Mn(t,e);return Yn({rel:Bn(n.rel,`${e}.rel`),target:Pn(n.target,`${e}.target`),key:Fn(n.key,`${e}.key`,Bn)})}function er(t,e){const n=Mn(t,e),r=void 0===n.dids?[]:zn(n.dids,`${e}.dids`,Un);if(void 0!==n.all&&"boolean"!=typeof n.all)throw Rn(`${e}.all`,"a boolean");return Yn({dids:r.length>0?r:void 0,all:!0===n.all||void 0})}function nr(t,e){const n=Mn(t,e),r=void 0===n.data?{}:Mn(n.data,`${e}.data`);return Yn({intent:Fn(n.intent,`${e}.intent`,Bn),data:Object.keys(r).length>0?r:void 0})}function rr(t,e){const n=Mn(t,e);switch(n.type){case"data_obj":return Yn({type:"data_obj",obj_id:Pn(n.obj_id,`${e}.obj_id`),uri_hint:Fn(n.uri_hint,`${e}.uri_hint`,Bn)});case"service_did":return{type:"service_did",did:Un(n.did,`${e}.did`)};default:throw Rn(`${e}.type`,"data_obj or service_did")}}function or(t,e){const n=Mn(t,e);return Yn({role:Ln(Gn,n.role,`${e}.role`),target:rr(n.target,`${e}.target`),label:Fn(n.label,`${e}.label`,Bn)})}function ir(t,e){const n=Bn(t,e);return Wn.get(n)??n}function sr(t,e){const n=Mn(t,e),r=void 0===n.content?"":Bn(n.content,`${e}.content`),o=void 0===n.refs?[]:zn(n.refs,`${e}.refs`,or);return Yn({title:Fn(n.title,`${e}.title`,Bn),format:Fn(n.format,`${e}.format`,ir),content:r.length>0?r:void 0,machine:Fn(n.machine,`${e}.machine`,nr),refs:o.length>0?o:void 0})}const ar=new Set(Zn.filter((t=>"proof"!==t)));function cr(t){const e=Mn(t,"MsgObject"),n=void 0===e.thread?{}:function(t,e){const n=Mn(t,e);return Yn({topic:Fn(n.topic,`${e}.topic`,Bn),reply_to:Fn(n.reply_to,`${e}.reply_to`,Pn),correlation_id:Fn(n.correlation_id,`${e}.correlation_id`,Bn)})}(e.thread,"MsgObject.thread"),r=void 0===e.created_at_ms?0:Hn(e.created_at_ms,"MsgObject.created_at_ms"),o=Yn({from:Un(e.from,"MsgObject.from"),to:zn(e.to,"MsgObject.to",Un),kind:Ln(qn,e.kind,"MsgObject.kind"),to_session:Fn(e.to_session,"MsgObject.to_session",Bn),thread:Object.keys(n).length>0?n:void 0,relates_to:Fn(e.relates_to,"MsgObject.relates_to",tr),mentions:Fn(e.mentions,"MsgObject.mentions",er),workspace:Fn(e.workspace,"MsgObject.workspace",Un),created_at_ms:0!==r?r:void 0,expires_at_ms:Fn(e.expires_at_ms,"MsgObject.expires_at_ms",Hn),nonce:Fn(e.nonce,"MsgObject.nonce",Hn),content:sr(e.content,"MsgObject.content")});for(const[i,s]of Object.entries(e))ar.has(i)||ln(o,i,s);return o}function ur(t){const[e]=gn(Le,t),n=cr(t);Qn(n);const[r]=gn(Le,n);if(!r.equals(e))throw new He("InvalidData","MsgObject JSON is not in canonical form");return[n,e]}function lr(t){let e;try{e=Gt(t)}catch(o){throw new He("DecodeError",`decode msg jwt header failed: ${o.message}`)}const{alg:n,kid:r}=Mn(e,"msg jwt header");if("EdDSA"!==n)throw new He("InvalidData",`msg jwt alg must be EdDSA, got ${String(n)}`);if("string"!=typeof r||0===r.length)throw new He("InvalidData","msg jwt header requires kid");return r}const hr=["accepted","rejected","quarantined"];function dr(t){const e={...t},n=(t,n)=>{t in e&&n(e[t])&&delete e[t]};return n("did",(t=>null==t)),n("name",(t=>""===t)),n("author",(t=>""===t)),n("owner",(t=>null==t||"did:undefined:undefined"===t)),n("copyright",(t=>null==t)),n("tags",(t=>Array.isArray(t)&&0===t.length)),n("categories",(t=>Array.isArray(t)&&0===t.length)),n("base_on",(t=>null==t)),n("directory",(t=>t&&"object"==typeof t&&0===Object.keys(t).length)),n("references",(t=>t&&"object"==typeof t&&0===Object.keys(t).length)),n("exp",(t=>0===t)),n("size",(t=>0===t)),n("content",(t=>""===t)),n("version_tag",(t=>null==t)),n("deps",(t=>t&&"object"==typeof t&&0===Object.keys(t).length)),e}const fr="application/cyfs-named-object+json",pr="application/cyfs-named-object+jwt";function wr(t){const e=t.split(";")[0].trim().toLowerCase();return e===fr?"json":e===pr?"jwt":null}const mr={fromObjData(t,e){switch(t.objType){case Ue:{let t;try{t=JSON.parse(e)}catch(n){throw new He("InvalidParam",`parse dir object from json failed: ${n.message}`)}return{kind:"dir",obj:Jn.fromJSON(t),objStr:e}}case Pe:{let t;try{t=JSON.parse(e)}catch(n){throw new He("InvalidParam",`parse file object from json failed: ${n.message}`)}return{kind:"file",obj:An.fromJSON(t),objStr:e}}case Ge:return{kind:"chunkList",obj:Cn.fromJson(e),objStr:e};default:throw new He("InvalidParam",`Unknown object type: ${t.objType}`)}},getChildObjs(t){switch(t.kind){case"dir":{const e=[];for(const[,n]of t.obj.entries()){const[t,r]=Tn.getObjId(n);e.push({objId:t,objStr:r.length>0?r:null})}return e}case"file":return 0===t.obj.content.length?[]:[{objId:wn.fromString(t.obj.content),objStr:null}];case"chunkList":return t.obj.body.map((t=>({objId:t.toObjId(),objStr:null})))}}},yr="undefined"!=typeof TextEncoder?new TextEncoder:null,br="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function gr(t){if(yr)return yr.encode(t);const e=[];for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);if(r<128)e.push(r);else if(r<2048)e.push(192|r>>6,128|63&r);else if(r>=55296&&r<=56319&&n+1<t.length){const o=65536+((1023&r)<<10|1023&t.charCodeAt(++n));e.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|63&o)}else e.push(224|r>>12,128|r>>6&63,128|63&r)}return new Uint8Array(e)}function vr(t){if(br)return br.decode(t);let e="",n=0;for(;n<t.length;){const r=t[n++];if(r<128)e+=String.fromCharCode(r);else if(r<224)e+=String.fromCharCode((31&r)<<6|63&t[n++]);else if(r<240)e+=String.fromCharCode((15&r)<<12|(63&t[n++])<<6|63&t[n++]);else{const o=((7&r)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536;e+=String.fromCharCode(55296+(o>>10),56320+(1023&o))}}return e}exports.ACTION_TYPE_DOWNLOAD="download",exports.ACTION_TYPE_INSTALLED="installed",exports.ACTION_TYPE_LIKED="liked",exports.ACTION_TYPE_PURCHASED="purchased",exports.ACTION_TYPE_SHARED="shared",exports.ACTION_TYPE_UNLIKED="unliked",exports.ACTION_TYPE_VIEWED="viewed",exports.BaseContentObject=kn,exports.CYFS_CONTENT_TYPE_NAMED_OBJECT_JSON=fr,exports.CYFS_CONTENT_TYPE_NAMED_OBJECT_JWT=pr,exports.ChunkId=mn,exports.ChunkType=pn,exports.DEFAULT_EXPIRE_TIME=kt,exports.DEFAULT_HASH_METHOD="sha256",exports.DID=ee,exports.DID_OBJECT_SERVICE_ID="#did-object",exports.DID_OBJECT_SERVICE_TYPE=pt,exports.DirObject=Jn,exports.FileObject=An,exports.HashMethod=fn,exports.InclusionProof=Dn,exports.KnownStandardObject=mr,exports.MSG_OBJECT_RESERVED_KEYS=Zn,exports.MSG_REACTION_KEY_MAX_BYTES=64,exports.MSG_SESSION_ID_MAX_CHARS=200,exports.NODE_IDENTITY_SCHEMA_V2=wt,exports.NamedObjectBase=yn,exports.NdnError=He,exports.OBJ_TYPE_ACTION="cyact",exports.OBJ_TYPE_CHUNK_LIST=Ge,exports.OBJ_TYPE_DIR=Ue,exports.OBJ_TYPE_FILE=Pe,exports.OBJ_TYPE_INCLUSION_PROOF=Fe,exports.OBJ_TYPE_LIST=Ve,exports.OBJ_TYPE_MSG=Le,exports.OBJ_TYPE_OBJMAP=We,exports.OBJ_TYPE_PACK=qe,exports.OBJ_TYPE_PATH=ze,exports.OBJ_TYPE_PKG="pkg",exports.OBJ_TYPE_RECEIPT="cyrece",exports.OBJ_TYPE_RELATION=Ye,exports.ObjId=wn,exports.PathObject=Nn,exports.RELATION_TYPE_PART_OF=Xe,exports.RELATION_TYPE_SAME=Ze,exports.RelationObject=Kn,exports.SimpleChunkList=Cn,exports.SimpleMapItem=Tn,exports.SimpleObjectMap=$n,exports.actionObjectFromJson=function(t){const e=Mn(t,"ActionObject");return Yn({subject:Pn(e.subject,"ActionObject.subject"),action:Bn(e.action,"ActionObject.action"),target:Pn(e.target,"ActionObject.target"),base_on:Fn(e.base_on,"ActionObject.base_on",Pn),details:e.details??void 0,iat:Hn(e.iat,"ActionObject.iat"),exp:Hn(e.exp,"ActionObject.exp")})},exports.base32Decode=on,exports.base32Encode=rn,exports.buckyosGetUnixTimestamp=Nt,exports.buildNamedObjectByJson=gn,exports.buildNamedObjectByJwt=Sn,exports.buildObjId=bn,exports.bytesToHex=tn,exports.calcPkgMetaObjId=function(t){const e=dr(t),[n]=gn("pkg",e);return n.toString()},exports.canonicalize=ft,exports.canonicalizeJson=hn,exports.cleanLocalAccountInfo=function(t){localStorage.removeItem(lt(t)),localStorage.removeItem(ct),localStorage.removeItem(ut);let e={path:"/",expires:new Date(0),secure:!0,sameSite:"Lax"};document.cookie=`${t}_token=; ${Object.entries(e).map((([t,e])=>`${t}=${e}`)).join("; ")}`},exports.clearBrowserIdentity=function(){localStorage.removeItem(ut)},exports.clearBrowserUserInfo=function(){localStorage.removeItem(ct)},exports.commonjsGlobal=ht,exports.createJwkByX=qt,exports.decodeJwtClaimWithoutVerify=Vt,exports.decodeMsgObjectJwt=function(t){const e=lr(t),[n,r]=ur(In(t));return{msg:n,objId:r,kid:e}},exports.deviceDocumentToOrderedJson=Ee,exports.deviceMiniDocumentToJwt=je,exports.encodeDeviceDocument=be,exports.encodeZoneBootDocument=pe,exports.encodeZoneDocument=Ie,exports.extractObjIdByPath=function(t,e){const n=e.split("/").filter((t=>t.length>0));let r=t;for(const i of n){if(null==r)throw new He("InvalidParam",`objid path not found: ${e}`);if(Array.isArray(r)){const t=Number(i);if(!Number.isInteger(t)||t<0||t>=r.length)throw new He("InvalidParam",`objid path not found: ${e}`);r=r[t]}else{if("object"!=typeof r)throw new He("InvalidParam",`objid path not found: ${e}`);if(!(i in r))throw new He("InvalidParam",`objid path not found: ${e}`);r=r[i]}}try{return wn.fromValue(r)}catch(o){throw new He("InvalidData",`invalid objid at path ${e}: ${o.message}`)}},exports.getBrowserIdentityRaw=function(){const t=localStorage.getItem(ut);if(!t)return null;try{return JSON.parse(t)}catch{return null}},exports.getBrowserUserInfo=function(){return function(t){if(null==t)return null;try{const e=JSON.parse(t),n="string"==typeof e.user_id?e.user_id.trim():"",r="string"==typeof e.user_type?e.user_type.trim():"",o="string"==typeof e.user_name?e.user_name.trim():"string"==typeof e.show_name?e.show_name.trim():"";return n&&r?{user_name:o||n,user_id:n,user_type:r}:null}catch{return null}}(localStorage.getItem(ct))},exports.getDefaultExportFromCjs=dt,exports.getDidIdentifier=function(t){if("string"!=typeof t||!t.startsWith("did:"))return null;const e=t.split(":");return e.length>=3?e.slice(2).join(":"):null},exports.getDidMethod=function(t){if("string"!=typeof t||!t.startsWith("did:"))return null;const e=t.split(":");return e.length>=3?e[1]:null},exports.getPublicKeyXFromPrivatePem=Ft,exports.getXFromJwk=Yt,exports.hashPassword=function(t,e,n=null){const r=new at("SHA-256","TEXT",{encoding:"UTF8"});r.update(e+t+".buckyos");let o=r.getHash("B64");if(null==n)return o;const i=new at("SHA-256","TEXT",{encoding:"UTF8"});let s=o+n.toString();return i.update(s),i.getHash("B64")},exports.hexToBytes=en,exports.isBuckyOSAgentDocument=jt,exports.isBuckyOSDIDObjectCard=It,exports.isBuckyOSDeviceDocument=_t,exports.isBuckyOSDeviceMiniDocument=vt,exports.isBuckyOSLocalNodeIdentityConfig=function(t){return mt(t)&&t.schema===wt&&"string"==typeof t.zone_did&&"string"==typeof t.owner_did&&mt(t.owner_public_key)&&"string"==typeof t.device_name&&"string"==typeof t.device_did&&"number"==typeof t.zone_iat},exports.isBuckyOSOwnerDocument=gt,exports.isBuckyOSZoneBootDocument=function(t){return mt(t)&&Array.isArray(t.oods)&&t.oods.every((t=>"string"==typeof t))&&"number"==typeof t.exp},exports.isBuckyOSZoneConfig=function(t){return mt(t)&&"string"==typeof t.zone_document},exports.isBuckyOSZoneDocument=xt,exports.isCyfsNamedObjectContentType=function(t){return null!==wr(t)},exports.isValidMsgSessionId=Xn,exports.isW3CDIDDocumentBase=bt,exports.loadNamedObj=function(t){return On(t)},exports.loadNamedObjAndVerify=function(t,e){const n=On(e);if(!vn(t,n))throw new He("InvalidId",`verify named object failed for obj_id: ${t.toString()}`);return n},exports.loadNamedObjectFromObjStr=On,exports.msgJwtKidDid=function(t){try{return ee.fromStr(t.split("#")[0]).toString()}catch{return null}},exports.msgObjectFromJsonChecked=ur,exports.namedObjectEncodingFromContentType=wr,exports.namelib=Be,exports.newDeviceDocumentByJwk=me,exports.newDeviceDocumentByMiniDocument=ye,exports.newDeviceMiniDocument=ve,exports.newDeviceMiniDocumentByDeviceDocument=_e,exports.newOwnerDocument=ce,exports.newZoneBootDocument=fe,exports.newZoneDocument=de,exports.normalizePackageMetaForObjId=dr,exports.oodDescriptionToString=re,exports.ownerDocumentSetDefaultZoneDid=ue,exports.ownerDocumentToOrderedJson=Se,exports.parseBuckyOSDIDDocument=function(t){return gt(t)||jt(t)||_t(t)||xt(t)||It(t)?t:null},exports.parseBuckyOSDeviceMiniDocument=function(t){return vt(t)?t:null},exports.parseBuckyOSOwnerDocument=function(t){return gt(t)?t:null},exports.parseOODDescription=ne,exports.parseW3CDIDDocumentBase=function(t){return bt(t)?t:null},exports.randomMsgNonce=function(){const[t,e]=crypto.getRandomValues(new Uint32Array(2));return 4294967296*(2097151&t)+e},exports.receiptObjFromJson=function(t){const e=Mn(t,"ReceiptObj");return Yn({obj_id:Pn(e.obj_id,"ReceiptObj.obj_id"),iss:Un(e.iss,"ReceiptObj.iss"),channel:Fn(e.channel,"ReceiptObj.channel",Bn),iat:Hn(e.iat,"ReceiptObj.iat"),status:Ln(hr,e.status,"ReceiptObj.status"),reason:Fn(e.reason,"ReceiptObj.reason",Bn)})},exports.saveBrowserIdentity=function(t){localStorage.setItem(ut,JSON.stringify(t))},exports.saveBrowserUserInfo=function(t){localStorage.setItem(ct,JSON.stringify(t))},exports.saveLocalAccountInfo=function(t,e){if(null==e.session_token)return void console.error("session_token is null,can't save account info");localStorage.setItem(lt(t),JSON.stringify(e));let n={path:"/",expires:new Date(Date.now()+2592e6),secure:!0,sameSite:"Lax"};document.cookie=`${t}_token=${e.session_token}; ${Object.entries(n).map((([t,e])=>`${t}=${e}`)).join("; ")}`},exports.sha256Bytes=function(t){const e=new at("SHA-256","UINT8ARRAY");return e.update(t),e.getHash("UINT8ARRAY")},exports.sha256Utf8=cn,exports.signJwtEdDSA=Wt,exports.toCanonicalJsonString=dn,exports.validateMsgObject=Qn,exports.varintDecode=an,exports.varintEncode=sn,exports.verifyJwtEdDSA=Zt,exports.verifyMsgObjectJwt=async function(t,e){const n=lr(t);let r;try{r=await Zt(t,e)}catch(s){throw new He("VerifyError",`verify msg jwt failed: ${s.message}`)}const[o,i]=ur(r);return{msg:o,objId:i,kid:n}},exports.verifyNamedObject=vn,exports.verifyNamedObjectFromJwt=function(t,e){const[n]=Sn(t.objType,e);return t.equals(n)},exports.verifyNamedObjectFromStr=function(t,e){let n;try{n=JSON.parse(e)}catch(r){throw new He("InvalidId",`failed to parse obj_str: ${r.message}`)}if(!vn(t,n))throw new He("InvalidId",`verify named object failed: ${e}`);return n},exports.zoneDocumentToOrderedJson=ke;
|
|
2
|
-
//# sourceMappingURL=ndn_types-8c2696d5.js.map
|