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.
Files changed (220) hide show
  1. package/cli/core/app.ts +2 -0
  2. package/cli/core/argv.ts +45 -239
  3. package/cli/core/command.ts +3 -35
  4. package/cli/dist/cli.mjs +2151 -673
  5. package/cli/dist/cli.mjs.map +1 -1
  6. package/cli/modules/agent.ts +3 -1
  7. package/cli/modules/app.ts +13 -2
  8. package/cli/modules/pikg.ts +70 -1
  9. package/cli/modules/runtime.ts +497 -0
  10. package/cli/modules/skill.ts +583 -161
  11. package/cli/modules/skill_lint.ts +462 -0
  12. package/cli/version.ts +1 -1
  13. package/dist/account-7a7bde6f.mjs +105 -0
  14. package/dist/account-7a7bde6f.mjs.map +1 -0
  15. package/dist/account-b12ac6b9.js +2 -0
  16. package/dist/account-b12ac6b9.js.map +1 -0
  17. package/dist/aicc-67851c41.mjs +582 -0
  18. package/dist/aicc-67851c41.mjs.map +1 -0
  19. package/dist/aicc-ccb36ef7.js +2 -0
  20. package/dist/aicc-ccb36ef7.js.map +1 -0
  21. package/dist/aiworkspace_client.d.ts +36 -2
  22. package/dist/aiworkspace_client.d.ts.map +1 -1
  23. package/dist/app-frame.cjs +1 -1
  24. package/dist/app-frame.cjs.map +1 -1
  25. package/dist/app-frame.d.ts +56 -1
  26. package/dist/app-frame.d.ts.map +1 -1
  27. package/dist/app-frame.mjs +285 -4
  28. package/dist/app-frame.mjs.map +1 -1
  29. package/dist/browser.cjs +1 -1
  30. package/dist/browser.cjs.map +1 -1
  31. package/dist/browser.d.ts +4 -0
  32. package/dist/browser.d.ts.map +1 -1
  33. package/dist/browser.mjs +218 -194
  34. package/dist/browser.mjs.map +1 -1
  35. package/dist/content.cjs +1 -1
  36. package/dist/content.cjs.map +1 -1
  37. package/dist/content.d.ts +77 -0
  38. package/dist/content.d.ts.map +1 -1
  39. package/dist/content.mjs +65 -0
  40. package/dist/content.mjs.map +1 -1
  41. package/dist/content_objid-1aff74b6.js +2 -0
  42. package/dist/content_objid-1aff74b6.js.map +1 -0
  43. package/dist/content_objid-9232bcaf.mjs +29 -0
  44. package/dist/content_objid-9232bcaf.mjs.map +1 -0
  45. package/dist/content_objid.d.ts +15 -0
  46. package/dist/content_objid.d.ts.map +1 -0
  47. package/dist/did_object_client-6a1b108a.js +2 -0
  48. package/dist/did_object_client-6a1b108a.js.map +1 -0
  49. package/dist/did_object_client-7fa36f90.mjs +87 -0
  50. package/dist/did_object_client-7fa36f90.mjs.map +1 -0
  51. package/dist/did_object_client.d.ts +39 -0
  52. package/dist/did_object_client.d.ts.map +1 -0
  53. package/dist/executor_client-7ce0ddc7.js +13 -0
  54. package/dist/executor_client-7ce0ddc7.js.map +1 -0
  55. package/dist/{executor_client-5f4d0468.mjs → executor_client-bfc8a1e1.mjs} +308 -752
  56. package/dist/executor_client-bfc8a1e1.mjs.map +1 -0
  57. package/dist/executor_client.d.ts +129 -0
  58. package/dist/executor_client.d.ts.map +1 -1
  59. package/dist/index.cjs +1 -1
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.ts +3 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.mjs +218 -199
  64. package/dist/index.mjs.map +1 -1
  65. package/dist/internal/command_args.d.ts +67 -0
  66. package/dist/internal/command_args.d.ts.map +1 -0
  67. package/dist/krpc_client-26c2dc8b.js +2 -0
  68. package/dist/krpc_client-26c2dc8b.js.map +1 -0
  69. package/dist/krpc_client-673448e5.mjs +173 -0
  70. package/dist/krpc_client-673448e5.mjs.map +1 -0
  71. package/dist/krpc_client.d.ts +5 -1
  72. package/dist/krpc_client.d.ts.map +1 -1
  73. package/dist/{ndn_types-ab30fac0.mjs → ndn_types-0fac2499.mjs} +115 -215
  74. package/dist/ndn_types-0fac2499.mjs.map +1 -0
  75. package/dist/ndn_types-5b138882.js +2 -0
  76. package/dist/ndn_types-5b138882.js.map +1 -0
  77. package/dist/node.cjs +1 -1
  78. package/dist/node.cjs.map +1 -1
  79. package/dist/node.mjs +201 -194
  80. package/dist/node.mjs.map +1 -1
  81. package/dist/object_url-8fb5a7bf.js +2 -0
  82. package/dist/object_url-8fb5a7bf.js.map +1 -0
  83. package/dist/object_url-f72c1704.mjs +412 -0
  84. package/dist/object_url-f72c1704.mjs.map +1 -0
  85. package/dist/openai-ae2978de.mjs +163 -0
  86. package/dist/openai-ae2978de.mjs.map +1 -0
  87. package/dist/openai-f560d518.js +2 -0
  88. package/dist/openai-f560d518.js.map +1 -0
  89. package/dist/provision.cjs +6 -6
  90. package/dist/provision.cjs.map +1 -1
  91. package/dist/provision.mjs +4 -3
  92. package/dist/provision.mjs.map +1 -1
  93. package/dist/site_manager-11a7a468.mjs +6410 -0
  94. package/dist/site_manager-11a7a468.mjs.map +1 -0
  95. package/dist/site_manager-334b1a51.js +2 -0
  96. package/dist/site_manager-334b1a51.js.map +1 -0
  97. package/dist/{tus_client-b231b248.js → tus_client-809c90ab.js} +2 -2
  98. package/dist/{tus_client-b231b248.js.map → tus_client-809c90ab.js.map} +1 -1
  99. package/dist/{tus_client-d1ffe2d6.mjs → tus_client-893a3287.mjs} +2 -2
  100. package/dist/{tus_client-d1ffe2d6.mjs.map → tus_client-893a3287.mjs.map} +1 -1
  101. package/dist/xllm/core/action_parser.d.ts +15 -0
  102. package/dist/xllm/core/action_parser.d.ts.map +1 -0
  103. package/dist/xllm/core/behavior_loop.d.ts +20 -0
  104. package/dist/xllm/core/behavior_loop.d.ts.map +1 -0
  105. package/dist/xllm/core/behavior_result.d.ts +11 -0
  106. package/dist/xllm/core/behavior_result.d.ts.map +1 -0
  107. package/dist/xllm/core/config.d.ts +62 -0
  108. package/dist/xllm/core/config.d.ts.map +1 -0
  109. package/dist/xllm/core/context_window.d.ts +15 -0
  110. package/dist/xllm/core/context_window.d.ts.map +1 -0
  111. package/dist/xllm/core/deps.d.ts +97 -0
  112. package/dist/xllm/core/deps.d.ts.map +1 -0
  113. package/dist/xllm/core/errors.d.ts +94 -0
  114. package/dist/xllm/core/errors.d.ts.map +1 -0
  115. package/dist/xllm/core/interrupt.d.ts +31 -0
  116. package/dist/xllm/core/interrupt.d.ts.map +1 -0
  117. package/dist/xllm/core/json.d.ts +11 -0
  118. package/dist/xllm/core/json.d.ts.map +1 -0
  119. package/dist/xllm/core/json_check.d.ts +17 -0
  120. package/dist/xllm/core/json_check.d.ts.map +1 -0
  121. package/dist/xllm/core/loop.d.ts +135 -0
  122. package/dist/xllm/core/loop.d.ts.map +1 -0
  123. package/dist/xllm/core/messages.d.ts +18 -0
  124. package/dist/xllm/core/messages.d.ts.map +1 -0
  125. package/dist/xllm/core/observer.d.ts +14 -0
  126. package/dist/xllm/core/observer.d.ts.map +1 -0
  127. package/dist/xllm/core/open_runtime.d.ts +22 -0
  128. package/dist/xllm/core/open_runtime.d.ts.map +1 -0
  129. package/dist/xllm/core/prepare.d.ts +54 -0
  130. package/dist/xllm/core/prepare.d.ts.map +1 -0
  131. package/dist/xllm/core/prompt.d.ts +40 -0
  132. package/dist/xllm/core/prompt.d.ts.map +1 -0
  133. package/dist/xllm/core/protocol.d.ts +15 -0
  134. package/dist/xllm/core/protocol.d.ts.map +1 -0
  135. package/dist/xllm/core/result.d.ts +12 -0
  136. package/dist/xllm/core/result.d.ts.map +1 -0
  137. package/dist/xllm/core/run.d.ts +198 -0
  138. package/dist/xllm/core/run.d.ts.map +1 -0
  139. package/dist/xllm/core/rust_text.d.ts +20 -0
  140. package/dist/xllm/core/rust_text.d.ts.map +1 -0
  141. package/dist/xllm/core/site_policy.d.ts +5 -0
  142. package/dist/xllm/core/site_policy.d.ts.map +1 -0
  143. package/dist/xllm/core/store.d.ts +60 -0
  144. package/dist/xllm/core/store.d.ts.map +1 -0
  145. package/dist/xllm/core/suspension.d.ts +13 -0
  146. package/dist/xllm/core/suspension.d.ts.map +1 -0
  147. package/dist/xllm/core/tokenizer.d.ts +8 -0
  148. package/dist/xllm/core/tokenizer.d.ts.map +1 -0
  149. package/dist/xllm/core/types.d.ts +826 -0
  150. package/dist/xllm/core/types.d.ts.map +1 -0
  151. package/dist/xllm/core/xml.d.ts +19 -0
  152. package/dist/xllm/core/xml.d.ts.map +1 -0
  153. package/dist/xllm/dev/openai.d.ts +17 -0
  154. package/dist/xllm/dev/openai.d.ts.map +1 -0
  155. package/dist/xllm/dev/scripted.d.ts +46 -0
  156. package/dist/xllm/dev/scripted.d.ts.map +1 -0
  157. package/dist/xllm/dev.d.ts +5 -0
  158. package/dist/xllm/dev.d.ts.map +1 -0
  159. package/dist/xllm/hosts/browser/store.d.ts +41 -0
  160. package/dist/xllm/hosts/browser/store.d.ts.map +1 -0
  161. package/dist/xllm/hosts/deno/deno_api.d.ts +103 -0
  162. package/dist/xllm/hosts/deno/deno_api.d.ts.map +1 -0
  163. package/dist/xllm/hosts/deno/identity.d.ts +29 -0
  164. package/dist/xllm/hosts/deno/identity.d.ts.map +1 -0
  165. package/dist/xllm/hosts/deno/index.d.ts +47 -0
  166. package/dist/xllm/hosts/deno/index.d.ts.map +1 -0
  167. package/dist/xllm/hosts/deno/native_runtime.d.ts +93 -0
  168. package/dist/xllm/hosts/deno/native_runtime.d.ts.map +1 -0
  169. package/dist/xllm/hosts/deno/native_tools.d.ts +105 -0
  170. package/dist/xllm/hosts/deno/native_tools.d.ts.map +1 -0
  171. package/dist/xllm/hosts/deno/provider.d.ts +13 -0
  172. package/dist/xllm/hosts/deno/provider.d.ts.map +1 -0
  173. package/dist/xllm/hosts/deno/store.d.ts +60 -0
  174. package/dist/xllm/hosts/deno/store.d.ts.map +1 -0
  175. package/dist/xllm/index.d.ts +48 -0
  176. package/dist/xllm/index.d.ts.map +1 -0
  177. package/dist/xllm/providers/aicc.d.ts +22 -0
  178. package/dist/xllm/providers/aicc.d.ts.map +1 -0
  179. package/dist/xllm/providers/timeout.d.ts +12 -0
  180. package/dist/xllm/providers/timeout.d.ts.map +1 -0
  181. package/dist/xllm/runtime/compress.d.ts +149 -0
  182. package/dist/xllm/runtime/compress.d.ts.map +1 -0
  183. package/dist/xllm/runtime/did_object_resources.d.ts +21 -0
  184. package/dist/xllm/runtime/did_object_resources.d.ts.map +1 -0
  185. package/dist/xllm/runtime/hints.d.ts +23 -0
  186. package/dist/xllm/runtime/hints.d.ts.map +1 -0
  187. package/dist/xllm/runtime/site.d.ts +22 -0
  188. package/dist/xllm/runtime/site.d.ts.map +1 -0
  189. package/dist/xllm/runtime/site_manager.d.ts +38 -0
  190. package/dist/xllm/runtime/site_manager.d.ts.map +1 -0
  191. package/dist/xllm/runtime/site_tools.d.ts +76 -0
  192. package/dist/xllm/runtime/site_tools.d.ts.map +1 -0
  193. package/dist/xllm/runtime/step_renderer.d.ts +54 -0
  194. package/dist/xllm/runtime/step_renderer.d.ts.map +1 -0
  195. package/dist/xllm/runtime/task_model.d.ts +64 -0
  196. package/dist/xllm/runtime/task_model.d.ts.map +1 -0
  197. package/dist/xllm/runtime/tool_result.d.ts +39 -0
  198. package/dist/xllm/runtime/tool_result.d.ts.map +1 -0
  199. package/dist/xllm/runtime/types.d.ts +99 -0
  200. package/dist/xllm/runtime/types.d.ts.map +1 -0
  201. package/dist/xllm.cjs +2 -0
  202. package/dist/xllm.cjs.map +1 -0
  203. package/dist/xllm.mjs +1167 -0
  204. package/dist/xllm.mjs.map +1 -0
  205. package/dist/xllm_deno.cjs +2 -0
  206. package/dist/xllm_deno.cjs.map +1 -0
  207. package/dist/xllm_deno.mjs +2487 -0
  208. package/dist/xllm_deno.mjs.map +1 -0
  209. package/dist/xllm_dev.cjs +2 -0
  210. package/dist/xllm_dev.cjs.map +1 -0
  211. package/dist/xllm_dev.mjs +70 -0
  212. package/dist/xllm_dev.mjs.map +1 -0
  213. package/package.json +22 -1
  214. package/src/internal/command_args.ts +268 -0
  215. package/dist/executor_client-1ee523cf.js +0 -13
  216. package/dist/executor_client-1ee523cf.js.map +0 -1
  217. package/dist/executor_client-5f4d0468.mjs.map +0 -1
  218. package/dist/ndn_types-8c2696d5.js +0 -2
  219. package/dist/ndn_types-8c2696d5.js.map +0 -1
  220. package/dist/ndn_types-ab30fac0.mjs.map +0 -1
@@ -0,0 +1,2 @@
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 i,o,s;const a=e||[0],c=(n=n||0)>>>3,u=-1===r?3:0;for(i=0;i<t.length;i+=1)s=i+c,o=s>>>2,a.length<=o&&a.push(0),a[o]|=t[i]<<8*(u+r*(s%4));return{value:a,binLen:8*t.length+n}}function i(i,o,s){switch(o){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(i){case"HEX":return function(t,e,n){return function(t,e,n,r){let i,o,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,h=-1===r?3:0;for(i=0;i<t.length;i+=2){if(o=parseInt(t.substr(i,2),16),isNaN(o))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+u,s=a>>>2;c.length<=s;)c.push(0);c[s]|=o<<8*(h+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,i){let o,s,a,c,u,h,l,d,f=0;const p=n||[0],w=(r=r||0)>>>3;if("UTF8"===e)for(l=-1===i?3:0,a=0;a<t.length;a+=1)for(o=t.charCodeAt(a),s=[],128>o?s.push(o):2048>o?(s.push(192|o>>>6),s.push(128|63&o)):55296>o||57344<=o?s.push(224|o>>>12,128|o>>>6&63,128|63&o):(a+=1,o=65536+((1023&o)<<10|1023&t.charCodeAt(a)),s.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),c=0;c<s.length;c+=1){for(h=f+w,u=h>>>2;p.length<=u;)p.push(0);p[u]|=s[c]<<8*(l+i*(h%4)),f+=1}else for(l=-1===i?2:0,d="UTF16LE"===e&&1!==i||"UTF16LE"!==e&&1===i,a=0;a<t.length;a+=1){for(o=t.charCodeAt(a),!0===d&&(c=255&o,o=c<<8|o>>>8),h=f+w,u=h>>>2;p.length<=u;)p.push(0);p[u]|=o<<8*(l+i*(h%4)),f+=2}return{value:p,binLen:8*f+r}}(t,o,e,n,s)};case"B64":return function(e,n,r){return function(e,n,r,i){let o,s,a,c,u,h,l,d=0;const f=n||[0],p=(r=r||0)>>>3,w=-1===i?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)o=t.indexOf(u.charAt(a)),c|=o<<18-6*a;for(a=0;a<u.length-1;a+=1){for(l=d+p,h=l>>>2;f.length<=h;)f.push(0);f[h]|=(c>>>16-8*a&255)<<8*(w+i*(l%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 i,o,s,a;const c=e||[0],u=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<t.length;o+=1)i=t.charCodeAt(o),a=o+u,s=a>>>2,c.length<=s&&c.push(0),c[s]|=i<<8*(h+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 i=e,o=n,a=s,r(new Uint8Array(t),i,o,a);var i,o,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 o(r,i,o,s){switch(r){case"HEX":return function(t){return function(t,e,n,r){const i="0123456789abcdef";let o,s,a="";const c=e/8,u=-1===n?3:0;for(o=0;o<c;o+=1)s=t[o>>>2]>>>8*(u+n*(o%4)),a+=i.charAt(s>>>4&15)+i.charAt(15&s);return r.outputUpper?a.toUpperCase():a}(t,i,o,s)};case"B64":return function(e){return function(e,n,r,i){let o,s,a,c,u,h="";const l=n/8,d=-1===r?3:0;for(o=0;o<l;o+=3)for(c=o+1<l?e[o+1>>>2]:0,u=o+2<l?e[o+2>>>2]:0,a=(e[o>>>2]>>>8*(d+r*(o%4))&255)<<16|(c>>>8*(d+r*((o+1)%4))&255)<<8|u>>>8*(d+r*((o+2)%4))&255,s=0;s<4;s+=1)h+=8*o+6*s<=n?t.charAt(a>>>6*(3-s)&63):i.b64Pad;return h}(e,i,o,s)};case"BYTES":return function(t){return function(t,e,n){let r,i,o="";const s=e/8,a=-1===n?3:0;for(r=0;r<s;r+=1)i=t[r>>>2]>>>8*(a+n*(r%4))&255,o+=String.fromCharCode(i);return o}(t,i,o)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(a){throw new Error(e)}return function(t){return function(t,e,n){let r;const i=e/8,o=new ArrayBuffer(i),s=new Uint8Array(o),a=-1===n?3:0;for(r=0;r<i;r+=1)s[r]=t[r>>>2]>>>8*(a+n*(r%4))&255;return o}(t,i,o)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(a){throw new Error(n)}return function(t){return function(t,e,n){let r;const i=e/8,o=-1===n?3:0,s=new Uint8Array(i);for(r=0;r<i;r+=1)s[r]=t[r>>>2]>>>8*(o+n*(r%4))&255;return s}(t,i,o)};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],h="Chosen SHA variant is not supported",l="Cannot set numRounds with MAC";function d(t,e){let n,r;const i=t.binLen>>>3,o=e.binLen>>>3,s=i<<3,a=4-i<<3;if(i%4!=0){for(n=0;n<o;n+=4)r=i+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>=o+i&&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 o=t+" must include a value and format";if(!e){if(!r)throw new Error(o);return r}if(void 0===e.value||!e.format)throw new Error(o);return i(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,i=this.C(t,this.h,this.u),o=i.binLen,s=i.value,a=o>>>5;for(e=0;e<a;e+=r)n+this.m<=o&&(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=o%this.m,this.l=!0,this}getHash(t,e){let n,r,i=this.R;const s=f(e);if(this.K){if(-1===s.outputLen)throw new Error("Output length must be specified in options");i=s.outputLen}const a=o(t,i,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),i),n=1;n<this.numRounds;n+=1)this.K&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.F(r,i,0,this.B(this.o),i);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=i(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(l);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 o(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 O(t,e,n,r){const i=(65535&t)+(65535&e)+(65535&n)+(65535&r);return(65535&(t>>>16)+(e>>>16)+(n>>>16)+(r>>>16)+(i>>>16))<<16|65535&i}function I(t,e,n,r,i){const o=(65535&t)+(65535&e)+(65535&n)+(65535&r)+(65535&i);return(65535&(t>>>16)+(e>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(o>>>16))<<16|65535&o}function k(t){return y(t,7)^y(t,18)^b(t,3)}function S(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,i,o,s,a,c;const u=[];for(n=e[0],r=e[1],i=e[2],o=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?I(m(n,5),v(r,i,o),s,1518500249,u[c]):c<40?I(m(n,5),g(r,i,o),s,1859775393,u[c]):c<60?I(m(n,5),_(r,i,o),s,2400959708,u[c]):I(m(n,5),g(r,i,o),s,3395469782,u[c]),s=o,o=i,i=m(r,30),r=n,n=a;return e[0]=x(n,e[0]),e[1]=x(r,e[1]),e[2]=x(i,e[2]),e[3]=x(o,e[3]),e[4]=x(s,e[4]),e}function D(t,e,n,r){let i;const o=15+(e+65>>>9<<4),a=e+n;for(;t.length<=o;)t.push(0);for(t[e>>>5]|=128<<24-e%32,t[o]=4294967295&a,t[o-1]=a/s|0,i=0;i<t.length;i+=16)r=A(t.slice(i,i+16),r);return r}let N=class extends w{constructor(t,e,n){if("SHA-1"!==t)throw new Error(h);super(t,e,n);const r=n||{};this.M=!0,this.g=this.Y,this.T=-1,this.C=i(this.t,this.i,this.T),this.v=A,this.L=function(t){return t.slice()},this.B=E,this.F=D,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 C(t,e){let n,r,i,o,s,c,u,h,l,d,f;const p=[];for(n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],c=e[5],u=e[6],h=e[7],f=0;f<64;f+=1)p[f]=f<16?t[f]:O(y(w=p[f-2],17)^y(w,19)^b(w,10),p[f-7],k(p[f-15]),p[f-16]),l=I(h,S(s),v(s,c,u),a[f],p[f]),d=x(j(n),_(n,r,i)),h=u,u=c,c=s,s=x(o,l),o=i,i=r,r=n,n=x(l,d);var w;return e[0]=x(n,e[0]),e[1]=x(r,e[1]),e[2]=x(i,e[2]),e[3]=x(o,e[3]),e[4]=x(s,e[4]),e[5]=x(c,e[5]),e[6]=x(u,e[6]),e[7]=x(h,e[7]),e}let J=class extends w{constructor(t,e,n){if("SHA-224"!==t&&"SHA-256"!==t)throw new Error(h);super(t,e,n);const r=n||{};this.g=this.Y,this.M=!0,this.T=-1,this.C=i(this.t,this.i,this.T),this.v=C,this.L=function(t){return t.slice()},this.B=T,this.F=function(e,n,r,i){return function(t,e,n,r,i){let o,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,o=0;o<t.length;o+=16)r=C(t.slice(o,o+16),r);return a="SHA-224"===i?[r[0],r[1],r[2],r[3],r[4],r[5],r[6]]:r,a}(e,n,r,i,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 ${constructor(t,e){this.N=t,this.I=e}}function K(t,e){let n;return e>32?(n=64-e,new $(t.I<<e|t.N>>>n,t.N<<e|t.I>>>n)):0!==e?(n=32-e,new $(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 $(t.N>>>e|t.I<<n,t.I>>>e|t.N<<n)):(n=64-e,new $(t.I>>>e|t.N<<n,t.N>>>e|t.I<<n))}function M(t,e){return new $(t.N>>>e,t.I>>>e|t.N<<32-e)}function B(t,e,n){return new $(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 $(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 i=(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 $((65535&r)<<16|65535&n,i)}function U(t,e,n,r){let i,o;i=(65535&t.I)+(65535&e.I)+(65535&n.I)+(65535&r.I),o=(t.I>>>16)+(e.I>>>16)+(n.I>>>16)+(r.I>>>16)+(i>>>16);const s=(65535&o)<<16|65535&i;return i=(65535&t.N)+(65535&e.N)+(65535&n.N)+(65535&r.N)+(o>>>16),o=(t.N>>>16)+(e.N>>>16)+(n.N>>>16)+(r.N>>>16)+(i>>>16),new $((65535&o)<<16|65535&i,s)}function L(t,e,n,r,i){let o,s;o=(65535&t.I)+(65535&e.I)+(65535&n.I)+(65535&r.I)+(65535&i.I),s=(t.I>>>16)+(e.I>>>16)+(n.I>>>16)+(r.I>>>16)+(i.I>>>16)+(o>>>16);const a=(65535&s)<<16|65535&o;return o=(65535&t.N)+(65535&e.N)+(65535&n.N)+(65535&r.N)+(65535&i.N)+(s>>>16),s=(t.N>>>16)+(e.N>>>16)+(n.N>>>16)+(r.N>>>16)+(i.N>>>16)+(o>>>16),new $((65535&s)<<16|65535&o,a)}function z(t,e){return new $(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 $(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 $(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 $(e.N^n.N^r.N,e.I^n.I^r.I)}const W=[new $(a[0],3609767458),new $(a[1],602891725),new $(a[2],3964484399),new $(a[3],2173295548),new $(a[4],4081628472),new $(a[5],3053834265),new $(a[6],2937671579),new $(a[7],3664609560),new $(a[8],2734883394),new $(a[9],1164996542),new $(a[10],1323610764),new $(a[11],3590304994),new $(a[12],4068182383),new $(a[13],991336113),new $(a[14],633803317),new $(a[15],3479774868),new $(a[16],2666613458),new $(a[17],944711139),new $(a[18],2341262773),new $(a[19],2007800933),new $(a[20],1495990901),new $(a[21],1856431235),new $(a[22],3175218132),new $(a[23],2198950837),new $(a[24],3999719339),new $(a[25],766784016),new $(a[26],2566594879),new $(a[27],3203337956),new $(a[28],1034457026),new $(a[29],2466948901),new $(a[30],3758326383),new $(a[31],168717936),new $(a[32],1188179964),new $(a[33],1546045734),new $(a[34],1522805485),new $(a[35],2643833823),new $(a[36],2343527390),new $(a[37],1014477480),new $(a[38],1206759142),new $(a[39],344077627),new $(a[40],1290863460),new $(a[41],3158454273),new $(a[42],3505952657),new $(a[43],106217008),new $(a[44],3606008344),new $(a[45],1432725776),new $(a[46],1467031594),new $(a[47],851169720),new $(a[48],3100823752),new $(a[49],1363258195),new $(a[50],3750685593),new $(a[51],3785050280),new $(a[52],3318307427),new $(a[53],3812723403),new $(a[54],2003034995),new $(a[55],3602036899),new $(a[56],1575990012),new $(a[57],1125592928),new $(a[58],2716904306),new $(a[59],442776044),new $(a[60],593698344),new $(a[61],3733110249),new $(a[62],2999351573),new $(a[63],3815920427),new $(3391569614,3928383900),new $(3515267271,566280711),new $(3940187606,3454069534),new $(4118630271,4000239992),new $(116418474,1914138554),new $(174292421,2731055270),new $(289380356,3203993006),new $(460393269,320620315),new $(685471733,587496836),new $(852142971,1086792851),new $(1017036298,365543100),new $(1126000580,2618297676),new $(1288033470,3409855158),new $(1501505948,4234509866),new $(1607167915,987167468),new $(1816402316,1246189591)];function V(t){return"SHA-384"===t?[new $(3418070365,c[0]),new $(1654270250,c[1]),new $(2438529370,c[2]),new $(355462360,c[3]),new $(1731405415,c[4]),new $(41048885895,c[5]),new $(3675008525,c[6]),new $(1203062813,c[7])]:[new $(u[0],4089235720),new $(u[1],2227873595),new $(u[2],4271175723),new $(u[3],1595750129),new $(u[4],2917565137),new $(u[5],725511199),new $(u[6],4215389547),new $(u[7],327033209)]}function G(t,e){let n,r,i,o,s,a,c,u,h,l,d,f;const p=[];for(n=e[0],r=e[1],i=e[2],o=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 $(t[f],t[f+1])):p[d]=U(F(p[d-2]),p[d-7],Y(p[d-15]),p[d-16]),h=L(u,q(s),(m=a,y=c,new $((w=s).N&m.N^~w.N&y.N,w.I&m.I^~w.I&y.I)),W[d],p[d]),l=P(H(n),B(n,r,i)),u=c,c=a,a=s,s=P(o,h),o=i,i=r,r=n,n=P(h,l);var w,m,y;return e[0]=P(n,e[0]),e[1]=P(r,e[1]),e[2]=P(i,e[2]),e[3]=P(o,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(h);super(t,e,n);const r=n||{};this.g=this.Y,this.M=!0,this.T=-1,this.C=i(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,i){return function(t,e,n,r,i){let o,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,o=0;o<t.length;o+=32)r=G(t.slice(o,o+32),r);return a="SHA-384"===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[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,i,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 $(0,1),new $(0,32898),new $(2147483648,32906),new $(2147483648,2147516416),new $(0,32907),new $(0,2147483649),new $(2147483648,2147516545),new $(2147483648,32777),new $(0,138),new $(0,136),new $(0,2147516425),new $(0,2147483658),new $(0,2147516555),new $(2147483648,139),new $(2147483648,32905),new $(2147483648,32771),new $(2147483648,32770),new $(2147483648,128),new $(0,32778),new $(2147483648,2147483658),new $(2147483648,2147516545),new $(2147483648,32896),new $(0,2147483649),new $(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 $(0,0),new $(0,0),new $(0,0),new $(0,0),new $(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,i,o;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 $(t[r+1],t[r]));for(n=0;n<24;n+=1){for(o=tt(),r=0;r<5;r+=1)s[r]=(c=e[r][0],u=e[r][1],h=e[r][2],l=e[r][3],d=e[r][4],new $(c.N^u.N^h.N^l.N^d.N,c.I^u.I^h.I^l.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(i=0;i<5;i+=1)e[r][i]=z(e[r][i],a[r]);for(r=0;r<5;r+=1)for(i=0;i<5;i+=1)o[i][(2*r+3*i)%5]=K(e[r][i],Q[r][i]);for(r=0;r<5;r+=1)for(i=0;i<5;i+=1)e[r][i]=z(o[r][i],new $(~o[(r+1)%5][i].N&o[(r+2)%5][i].N,~o[(r+1)%5][i].I&o[(r+2)%5][i].I));e[0][0]=z(e[0][0],X[n])}var c,u,h,l,d;return e}function rt(t){let e,n,r=0;const i=[0,0],o=[4294967295&t,t/s&2097151];for(e=6;e>=0;e--)n=o[e>>2]>>>8*e&255,0===n&&0===r||(i[r+1>>2]|=n<<8*(r+1),r+=1);return r=0!==r?r:1,i[0]|=r,{value:r+1>4?i:[i[0]],binLen:8+8*r}}function it(t){return d(rt(t.binLen),t)}function ot(t,e){let n,r=rt(e);r=d(r,t);const i=e>>>2,o=(i-r.value.length%i)%i;for(n=0;n<o;n++)r.value.push(0);return r.value}let st=class extends w{constructor(t,e,n){let r=6,o=0;super(t,e,n);const s=n||{};if(1!==this.numRounds){if(s.kmacKey||s.hmacKey)throw new Error(l);if("CSHAKE128"===this.o||"CSHAKE256"===this.o)throw new Error("Cannot set numRounds for CSHAKE variants")}switch(this.T=1,this.C=i(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=o=1152,this.R=224,this.M=!0,this.g=this.Y;break;case"SHA3-256":this.m=o=1088,this.R=256,this.M=!0,this.g=this.Y;break;case"SHA3-384":this.m=o=832,this.R=384,this.M=!0,this.g=this.Y;break;case"SHA3-512":this.m=o=576,this.R=512,this.M=!0,this.g=this.Y;break;case"SHAKE128":r=31,this.m=o=1344,this.R=-1,this.K=!0,this.M=!1,this.g=null;break;case"SHAKE256":r=31,this.m=o=1088,this.R=-1,this.K=!0,this.M=!1,this.g=null;break;case"KMAC128":r=4,this.m=o=1344,this.X(n),this.R=-1,this.K=!0,this.M=!1,this.g=this._;break;case"KMAC256":r=4,this.m=o=1088,this.X(n),this.R=-1,this.K=!0,this.M=!1,this.g=this._;break;case"CSHAKE128":this.m=o=1344,r=this.O(n),this.R=-1,this.K=!0,this.M=!1,this.g=null;break;case"CSHAKE256":this.m=o=1088,r=this.O(n),this.R=-1,this.K=!0,this.M=!1,this.g=null;break;default:throw new Error(h)}this.F=function(t,e,n,i,s){return function(t,e,n,r,i,o,s){let a,c,u=0;const h=[],l=i>>>5,d=e>>>5;for(a=0;a<d&&e>=i;a+=l)r=nt(t.slice(a,a+l),r),e-=i;for(t=t.slice(a),e%=i;t.length<l;)t.push(0);for(a=e>>>3,t[a>>2]^=o<<a%4*8,t[l-1]^=2147483648,r=nt(t,r);32*h.length<s&&(c=r[u%5][u/5|0],h.push(c.I),!(32*h.length>=s));)h.push(c.N),u+=1,0==64*u%i&&(nt(null,r),u=0);return h}(t,e,0,i,o,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(it(n.funcName),it(n.customization));if(0!==n.customization.binLen||0!==n.funcName.binLen){const t=ot(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=ot(it(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 i=[0,0],o=[4294967295&t,t/s&2097151];for(e=6;e>=0;e--)n=o[e>>2]>>>8*e&255,0===n&&0===r||(i[r>>2]|=n<<8*r,r+=1);return r=0!==r?r:1,i[r>>2]|=r<<8*r,{value:r+1>4?i:[i[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 N(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(h);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)}}var ct="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ut(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}const ht=ut((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])}`}),"")}}`})),lt="DIDObjectService",dt="buckyos.node_identity.v2";function ft(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)}function pt(t){return"string"==typeof t||Array.isArray(t)&&t.every((t=>"string"==typeof t))}function wt(t){return!!ft(t)&&(pt(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 mt(t){return wt(t)&&"string"==typeof t.name&&("string"==typeof t.display_name||"string"==typeof t.displayName||"string"==typeof t.full_name)}function yt(t){return ft(t)&&"string"==typeof t.n&&"string"==typeof t.x&&"number"==typeof t.exp}function bt(t){return wt(t)&&"string"==typeof t.owner&&"string"==typeof t.device_type&&"string"==typeof t.name}function gt(t){return wt(t)&&"string"==typeof t.owner&&ft(t.httpServicePorts)}function vt(t){return wt(t)&&"string"==typeof t.hostname&&"string"==typeof t.owner&&Array.isArray(t.oods)&&"string"==typeof t.boot_jwt}function _t(t){if(!ft(t)||!pt(t["@context"])||"string"!=typeof t.id)return!1;const e=t.service;return Array.isArray(e)&&e.some((t=>ft(t)&&t.type===lt))}const jt="https://www.w3.org/ns/did/v1",xt="https://buckyos.org/ns",Ot=15768e4,It=31536e4;function kt(t){return[jt,`${xt}/${t}/v1`]}function St(){return Math.floor(Date.now()/1e3)}const Et="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function At(t){let e="";for(let n=0;n<t.length;n+=3){const r=t[n],i=n+1<t.length?t[n+1]:0,o=n+2<t.length?t[n+2]:0;e+=Et[r>>2],e+=Et[(3&r)<<4|i>>4],e+=n+1<t.length?Et[(15&i)<<2|o>>6]:"=",e+=n+2<t.length?Et[63&o]:"="}return e}function Dt(t){const e=t.replace(/[^A-Za-z0-9+/]/g,""),n=Math.floor(3*e.length/4),r=new Uint8Array(n);let i=0;for(let o=0;o<e.length;o+=4){const t=Et.indexOf(e[o]),n=Et.indexOf(e[o+1]),s=o+2<e.length?Et.indexOf(e[o+2]):-1,a=o+3<e.length?Et.indexOf(e[o+3]):-1;r[i++]=t<<2|n>>4,s>=0&&(r[i++]=(15&n)<<4|s>>2),a>=0&&(r[i++]=(3&s)<<6|a)}return r.subarray(0,i)}function Nt(t){return At(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function Tt(t){return Dt(t.replace(/-/g,"+").replace(/_/g,"/"))}function Ct(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 Jt(t){return Nt(Ct(t))}function $t(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 i=(7&r)<<18|(63&t[n+1])<<12|(63&t[n+2])<<6|63&t[n+3];e+=String.fromCodePoint(i),n+=4}}return e}(Tt(t))}async function Kt(){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 Rt(){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 Mt=new Uint8Array([48,42,48,5,6,3,43,101,112,3,33,0]);function Bt(t){return Dt(t.replace(/-----BEGIN [^-]+-----/g,"").replace(/-----END [^-]+-----/g,"").replace(/\s+/g,""))}function Ht(t){const e=At(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 Pt(t){const e=Tt(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}(Mt,e)}async function Ut(t){const e=await Kt();if(e){const n=e.createPrivateKey({key:t,format:"pem"});return e.createPublicKey(n).export({format:"jwk"}).x}const n=Rt(),r=Bt(t),i=await n.importKey("pkcs8",r,{name:"Ed25519"},!0,["sign"]),o=await n.exportKey("jwk",i);if(!o.x)throw new Error("namelib: cannot derive public key from private pem");return o.x}function Lt(t){const e=t.x;if("string"!=typeof e||0===e.length)throw new Error("namelib: invalid jwk, missing x");return e}function zt(t){return{kty:"OKP",crv:"Ed25519",x:t}}async function Ft(t,e,n){const r=`${Jt(JSON.stringify(n??{alg:"EdDSA"}))}.${Jt(JSON.stringify(t))}`,i=await async function(t,e){const n=await Kt();if(n){const r=n.createPrivateKey({key:e,format:"pem"});return new Uint8Array(n.sign(null,t,r))}const r=Rt(),i=Bt(e),o=await r.importKey("pkcs8",i,{name:"Ed25519"},!1,["sign"]),s=await r.sign({name:"Ed25519"},o,t);return new Uint8Array(s)}(Ct(r),e);return`${r}.${Nt(i)}`}function Yt(t){const e=t.split(".");if(3!==e.length)throw new Error("namelib: invalid jwt, parts.len != 3");return JSON.parse($t(e[1]))}function qt(t){const e=t.split(".");if(3!==e.length)throw new Error("namelib: invalid jwt, parts.len != 3");return JSON.parse($t(e[0]))}async function Wt(t,e){const n=t.split(".");if(3!==n.length)throw new Error("namelib: invalid jwt, parts.len != 3");const r=JSON.parse($t(n[0]));if("EdDSA"!==r.alg)throw new Error(`namelib: unsupported jwt alg: ${r.alg}`);const i=`${n[0]}.${n[1]}`,o=await async function(t,e,n){const r=await Kt();if(r){const i=r.createPublicKey({key:{kty:n.kty,crv:n.crv,x:n.x},format:"jwk"});return r.verify(null,t,i,e)}const i=Rt(),o=Pt(n),s=await i.importKey("spki",o,{name:"Ed25519"},!1,["verify"]);return i.verify({name:"Ed25519"},s,e,t)}(Ct(i),Tt(n[2]),e);if(!o)throw new Error("namelib: jwt signature verify failed");return JSON.parse($t(n[1]))}function Vt(t){return t.startsWith("{")||t.startsWith("[")?{type:"json",value:JSON.parse(t)}:{type:"jwt",jwt:t}}function Gt(t){return"jwt"===t.type?Yt(t.jwt):t.value}let Zt=null;class Xt{constructor(t,e){this.method=t,this.id=e}static undefined(){return new Xt("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=Xt.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 Xt(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 Xt(e.slice(n+1),e.slice(0,n))}if(Zt)for(const e of Object.keys(Zt)){const n=Zt[e];if(t.endsWith(n)){if(t===n)break;const r=t.slice(0,t.length-n.length-1);return new Xt(e,r)}}return new Xt("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 Xt(e,r)}if(t.endsWith(".did")){const e=t.slice(0,-4),n=e.lastIndexOf(".");if(n>0&&n<e.length-1)return new Xt(e.slice(n+1),e.slice(0,n))}return new Xt("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(ne(t))return null;const e=t.indexOf(".");if(e<0)return null;const n=t.slice(e+1);return n.includes(".")?new Xt("web",n):null}case"bns":{const e=t.indexOf(".");return e<0?null:new Xt("bns",t.slice(e+1))}default:return null}}toFilename(){const t="0123456789ABCDEF",e=Ct(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=Tt(this.id);return 32===t.length&&Nt(t)===this.id?t:null}catch{return null}}getAuthKeyJwk(){return this.getEd25519AuthKey()?zt(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(Zt){const e=Zt[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 Qt(t){let e,n="OOD",r=t;t.startsWith("#")?(n="Gateway",r=t.slice(1)):t.startsWith("$")&&(n="OODOnly",r=t.slice(1));const i=r.lastIndexOf("@");let o,s=r;i>=0&&(s=r.slice(0,i),e=r.slice(i+1));let a=s;const c=s.indexOf(":");if(c>=0&&(a=s.slice(0,c),o=s.slice(c+1),!ne(o)))throw new Error(`namelib: invalid ip addr: ${o}`);if(void 0!==o&&void 0===e&&(e="wan"),!a)throw new Error("namelib: name in OODDescriptionString is empty");return re({name:a,nodeType:n,netId:e,ip:o})}function te(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 ee(t){return"Gateway"===t||"OOD"===t}function ne(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 re(t){for(const e of Object.keys(t))void 0===t[e]&&delete t[e];return t}function ie(t){return t instanceof Xt?t:Xt.fromStr(t)}function oe(t){const e=ie(t.did),n=t.now??St(),r=e.toString();return{"@context":kt("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+It,iat:n,version_seq:0,name:t.name,display_name:t.displayName,zone_binding_model_version:2}}function se(t,e){const n=ie(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,ae(t)}function ae(t){var e;const n=null==(e=t.binded_zone_list)?void 0:e[0],r=`${t.id}#lastDoc`,i=(t.service??[]).filter((t=>t.id!==r));if(void 0!==n){const e=ie(n);i.push({id:r,type:"DIDDoc",serviceEndpoint:`https://${e.toHostName()}/resolve/${t.id}`})}t.service=i}function ce(t,e){const n=ie(e).toString();return(t.binded_zone_list??[]).includes(n)}function ue(t){const e=ie(t.id),n=ie(t.ownerDid),r=t.now??St(),i=e.toString();return{"@context":kt("zone"),id:i,verificationMethod:[{type:"Ed25519VerificationKey2020",id:"#main_key",controller:n.toString(),publicKeyJwk:t.publicKeyJwk}],authentication:["#main_key"],assertionMethod:["#main_key"],capabilityInvocation:["#main_key"],service:[{id:`${i}#lastDoc`,type:"DIDDoc",serviceEndpoint:`https://${e.toHostName()}/resolve/this_zone`}],exp:r+It,iat:r,version_seq:0,hostname:e.toHostName(),owner:n.toString(),oods:[],boot_jwt:""}}function he(t){return re({id:void 0!==t.id?ie(t.id).toString():void 0,oods:[...t.oods],sn:t.sn,exp:t.exp,owner:void 0!==t.owner?ie(t.owner).toString():void 0,owner_key:t.ownerKey})}async function le(t,e){const{id:n,oods:r,sn:i,exp:o,owner:s,owner_key:a,...c}=t;return Ft(re({id:n,oods:r,sn:i,exp:o,owner:s,...c,owner_key:a}),e)}function de(t){const e=t.now??St(),n=`did:dev:${t.pkx}`;return{"@context":kt("device"),id:n,verificationMethod:[{type:"Ed25519VerificationKey2020",id:"#main_key",controller:n,publicKeyJwk:zt(t.pkx)}],authentication:["#main_key"],assertion_method:["#main_key"],capabilityInvocation:["#main_key"],exp:e+Ot,iat:e,version_seq:0,owner:Xt.undefined().toString(),device_type:"ood",name:t.name}}function fe(t,e,n){return de({name:t,pkx:Lt(e),now:n})}function pe(t,e,n,r){const i=`did:dev:${e.x}`,o={"@context":kt("device"),id:i,verificationMethod:[{type:"Ed25519VerificationKey2020",id:"#main_key",controller:i,publicKeyJwk:zt(e.x)}],authentication:["#main_key"],assertion_method:["#main_key"],capabilityInvocation:["#main_key"],exp:e.exp,iat:e.exp-Ot,version_seq:0,zone_did:ie(n).toString(),owner:ie(r).toString(),device_type:"ood",device_mini_document_jwt:t,name:e.n};return void 0!==e.p&&(o.rtcp_port=e.p),o}async function we(t,e){if(void 0===t.version_seq)throw new Error("namelib: DeviceDocument version_seq is required when encoding as JWT");return Ft(me(t),e)}function me(t){const{"@context":e,id:n,verificationMethod:r,authentication:i,assertion_method:o,capabilityInvocation:s,service:a,exp:c,iat:u,version_seq:h,keyScope:l,"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,...O}=t,I=l??d;return re({"@context":e,id:n,verificationMethod:r,authentication:i,assertion_method:o&&o.length>0?o:void 0,capabilityInvocation:s&&s.length>0?s:void 0,service:a&&a.length>0?a:void 0,exp:c,iat:u,version_seq:h,...O,keyScope:I&&Object.keys(I).length>0?I: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 ye(t){return re({n:t.name,x:t.x,p:t.rtcpPort,exp:t.exp})}function be(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 ye({name:t.name,x:Lt(e.publicKeyJwk),rtcpPort:t.rtcp_port,exp:t.exp})}async function ge(t,e){const{n:n,x:r,p:i,exp:o,...s}=t;return Ft(re({n:n,x:r,p:i,exp:o,...s}),e)}function ve(t){const{"@context":e,id:n,verificationMethod:r,authentication:i,assertion_method:o,capabilityInvocation:s,service:a,exp:c,iat:u,version_seq:h,mini_version_seq:l,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 re({"@context":e,id:n,verificationMethod:r,authentication:i,assertion_method:o&&o.length>0?o:void 0,capabilityInvocation:s&&s.length>0?s:void 0,service:a&&a.length>0?a:void 0,exp:c,iat:u,version_seq:h,mini_version_seq:l,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 _e(t,e){if(void 0===t.version_seq)throw new Error("namelib: ZoneDocument version_seq is required when encoding as JWT");return Ft(je(t),e)}function je(t){const{"@context":e,id:n,verificationMethod:r,authentication:i,assertionMethod:o,capabilityInvocation:s,service:a,exp:c,iat:u,version_seq:h,keyScope:l,"buckyos:scopes":d,hostname:f,owner:p,oods:w,boot_jwt:m,mini_device_jwts:y,devices:b,sn:g,...v}=t,_=l??d;return re({"@context":e,id:n,verificationMethod:r,authentication:i,assertionMethod:o&&o.length>0?o:void 0,capabilityInvocation:s&&s.length>0?s:void 0,service:a&&a.length>0?a:void 0,exp:c,iat:u,version_seq:h,...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 xe(t){return ve(t)}function Oe(t){return je(t)}function Ie(t){return me(t)}function ke(t){return t.keyScope??t["buckyos:scopes"]??{}}function Se(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 Ee(t,e){return ke(t)[e]??null}function Ae(t){return Object.keys(ke(t)).length>0}function De(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(_t(t)){const e=t.assertionMethod;if(Array.isArray(e)&&e.length>0)return e}return null}function Ne(t,e){const n=t.id;if(e.startsWith(n)){const t=e.slice(n.length);if(t.startsWith("#"))return t}return e}function Te(t,e){return e.startsWith("#")?`${t.id}${e}`:e}function Ce(t,e,n){return e===n||Ne(t,e)===Ne(t,n)||Te(t,e)===Te(t,n)}function Je(t,e){for(const n of e){const e=Se(t,Ne(t,n));if(e)return[n,e]}return null}function $e(t){const e="string"==typeof t?Vt(t):t,n="jwt"===e.type,r=Gt(e);if("object"!=typeof r||null===r)throw new Error("namelib: unknown did document");const i=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 i("OwnerDocument"),{docType:"owner",doc:r};if(void 0!==r.httpServicePorts)return i("AgentDocument"),{docType:"agent",doc:r};if(void 0!==r.device_type)return i("DeviceDocument"),{docType:"device",doc:r};if(void 0!==r.oods)return i("ZoneDocument"),{docType:"zone",doc:r};if(Array.isArray(r.service)&&r.service.some((t=>(null==t?void 0:t.type)===lt)))return i("DIDObjectCard"),{docType:"did-object",doc:r};throw new Error("namelib: unknown did document")}const Ke=Object.freeze(Object.defineProperty({__proto__:null,BUCKYOS_CONTEXT_BASE:xt,DEFAULT_EXPIRE_TIME:Ot,DID:Xt,DID_CORE_CONTEXT:jt,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:Tt,base64UrlDecodeToString:$t,base64UrlEncodeBytes:Nt,base64UrlEncodeString:Jt,buckyosContext:kt,buckyosGetUnixTimestamp:St,createJwkByX:zt,decodeDeviceDocument:async function(t,e){const n=e?await Wt(t,e):Yt(t);if(void 0===n.version_seq)throw new Error("namelib: DeviceDocument version_seq is required when decoding from JWT");return n},decodeJwtClaimWithoutVerify:Yt,decodeJwtHeaderWithoutVerify:qt,decodeZoneBootDocument:async function(t,e){return e?await Wt(t,e):Yt(t)},derToPkcs8Pem:Ht,deviceDocumentToOrderedJson:Ie,deviceMiniDocumentFromJwt:async function(t,e){return e?await Wt(t,e):Yt(t)},deviceMiniDocumentToJwt:ge,encodeDeviceDocument:we,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 Ft(ve(t),e)},encodeZoneBootDocument:le,encodeZoneDocument:_e,encodedDocumentFromStr:Vt,encodedDocumentToJsonValue:Gt,encodedDocumentToString:function(t){return"jwt"===t.type?t.jwt:JSON.stringify(t.value)},expandLocalKeyId:Te,generateEd25519KeyPair:async function(){const t=await Kt();if(t){const{privateKey:e,publicKey:n}=t.generateKeyPairSync("ed25519");return{privateKeyPem:e.export({type:"pkcs8",format:"pem"}).toString(),publicKeyJwk:zt(n.export({format:"jwk"}).x)}}const e=Rt(),n=await e.generateKey({name:"Ed25519"},!0,["sign","verify"]),r=new Uint8Array(await e.exportKey("pkcs8",n.privateKey)),i=await e.exportKey("jwk",n.publicKey);if(!i.x)throw new Error("namelib: WebCrypto did not return Ed25519 public jwk");return{privateKeyPem:Ht(r),publicKeyJwk:zt(i.x)}},getDeviceDidFromJwk:function(t){return`did:dev:${Lt(t)}`},getDidDocType:function(t){return t.docType},getDocumentAuthKey:Se,getDocumentDefaultKey:function(t){const e=(t.verificationMethod??[]).find((t=>"#main_key"===t.id));return e?e.publicKeyJwk:null},getDocumentKeyScope:ke,getKeyByScope:function(t,e){const n=Ee(t,e);if(n)return Je(t,n);if(Ae(t))return null;const r=De(t);if(r){const e=Je(t,r);if(e)return e}const i=Se(t);return i?["",i]:null},getKeyFromKeyIds:Je,getKeyIdsByScope:Ee,getKnownWeb3BridgeConfig:function(){return Zt},getPublicKeyXFromPrivatePem:Ut,getStandardScopeKeyIds:De,getXFromJwk:Lt,hasKeyScope:Ae,isKeyAllowedInScope:function(t,e,n){const r=Ee(t,e);if(r)return r.some((e=>Ce(t,e,n)));if(Ae(t))return!1;const i=De(t);return i?i.some((e=>Ce(t,e,n))):null!==Se(t,Ne(t,n))},isSameDocumentKeyId:Ce,newDeviceDocument:de,newDeviceDocumentByJwk:fe,newDeviceDocumentByMiniDocument:pe,newDeviceMiniDocument:ye,newDeviceMiniDocumentByDeviceDocument:be,newOwnerDocument:oe,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!==Tt(r).length)throw new Error("namelib: invalid pkx: x length must be 32 bytes");const i=zt(r);if(1===n.length){const t=Xt.fromStr(e),n=t.id;return oe({did:t,name:n,displayName:`${n}@${e}`,publicKeyJwk:i})}if(n.length>=3){const t=n[2];return oe({did:new Xt(n[1],n[2]),name:t,displayName:`${t}@${e}`,publicKeyJwk:i})}throw new Error(`namelib: invalid pkx: ${t}`)},newZoneBootDocument:he,newZoneDocument:ue,normalizeKeyIdForLocalLookup:Ne,oodDescriptionToString:te,oodNodeTypeIsGateway:ee,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":ce(t,e)?"bound_v2":"unbound_v2"},ownerDocumentIsBoundToZone:ce,ownerDocumentRemoveBoundZone:function(t,e){var n;const r=ie(e).toString(),i=(null==(n=t.binded_zone_list)?void 0:n.length)??0;t.binded_zone_list=(t.binded_zone_list??[]).filter((t=>t!==r));const o=t.binded_zone_list.length!==i;return t.zone_binding_model_version=2,ae(t),o},ownerDocumentSetDefaultZoneDid:se,ownerDocumentToOrderedJson:xe,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=Gt(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:$e,parseDidDocAs:function(t,e){const n=$e(t);if(n.docType!==e)throw new Error(`namelib: expected ${e} document, got ${n.docType}`);return n.doc},parseOODDescription:Qt,pemToDer:Bt,resetKnownWeb3BridgeConfigForTest:function(){Zt=null},setKnownWeb3BridgeConfig:function(t){return null===Zt&&(Zt={...t},!0)},signJwtEdDSA:Ft,verifyJwtEdDSA:Wt,zoneBootDocumentGetGatewayName:function(t){for(const e of t.oods){const t=Qt(e);if(ee(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?Xt.fromStr(t.owner):Xt.undefined(),r=ue({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-Ot,r.version_seq=0,r.owner=t.owner??Xt.undefined().toString(),r},zoneDocumentGetDefaultGateway:function(t){for(const e of t.oods){const t=Qt(e);if(ee(t.nodeType))return t.name}return null},zoneDocumentGetSnApiUrl:function(t){return void 0!==t.sn?`https://${t.sn}/kapi/sn`:null},zoneDocumentToOrderedJson:Oe},Symbol.toStringTag,{value:"Module"}));class Re extends Error{constructor(t,e){super(`${t}: ${e}`),this.kind=t,this.name="NdnError"}}const Me="cyfile",Be="cydir",He="cymsg",Pe="cypath",Ue="cyinc",Le="cyrel",ze="cypack",Fe="cymap",Ye="cylist",qe="clist",We="same",Ve="part_of",Ge="0123456789abcdef";function Ze(t){let e="";for(let n=0;n<t.length;n++){const r=t[n];e+=Ge[r>>>4&15],e+=Ge[15&r]}return e}function Xe(t){if(t.length%2!=0)throw new Re("InvalidId",`invalid hex length: ${t.length}`);const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=Ge.indexOf(t[2*n].toLowerCase()),i=Ge.indexOf(t[2*n+1].toLowerCase());if(r<0||i<0)throw new Re("InvalidId","invalid hex char at offset "+2*n);e[n]=r<<4|i}return e}const Qe="abcdefghijklmnopqrstuvwxyz234567";function tn(t){let e=0,n=0,r="";for(let i=0;i<t.length;i++)for(n=n<<8|t[i],e+=8;e>=5;)e-=5,r+=Qe[n>>>e&31];return e>0&&(r+=Qe[n<<5-e&31]),r}function en(t){const e=t.toLowerCase();let n=0,r=0;const i=[];for(let o=0;o<e.length;o++){const t=e[o],s=Qe.indexOf(t);if(s<0)throw new Re("InvalidId",`invalid base32 char '${t}' at ${o}`);r=r<<5|s,n+=5,n>=8&&(n-=8,i.push(r>>>n&255))}return new Uint8Array(i)}function nn(t){if(!Number.isFinite(t)||t<0)throw new Re("InvalidParam",`varint must be non-negative finite: ${t}`);if(!Number.isSafeInteger(t))throw new Re("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 rn(t,e=0){let n=0,r=1,i=e,o=0;for(;i<t.length;){const e=t[i++];o++;if(n+=(127&e)*r,!Number.isSafeInteger(n))throw new Re("InvalidData","varint exceeds safe integer range");if(!(128&e))return[n,o];if(r*=128,o>10)throw new Re("InvalidData","varint too long")}throw new Re("InvalidData","varint truncated")}function on(t){const e=new at("SHA-256","TEXT",{encoding:"UTF8"});return e.update(t),e.getHash("UINT8ARRAY")}function sn(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 Re("InvalidData","JSON string contains lone surrogate")}}}function an(t,e,n){"__proto__"===e?Object.defineProperty(t,e,{value:n,enumerable:!0,writable:!0,configurable:!0}):t[e]=n}function cn(t){if(function(t){switch(typeof t){case"string":return void sn(t);case"number":if(!Number.isFinite(t))throw new Re("InvalidData","JSON number MUST be finite for JCS");if(Object.is(t,-0))throw new Re("InvalidData","JSON number MUST NOT be negative zero for JCS");return;case"boolean":case"object":return;case"undefined":throw new Re("InvalidData","undefined is not a valid JSON value");case"bigint":throw new Re("InvalidData","bigint is not a valid JSON value");case"function":throw new Re("InvalidData","function is not a valid JSON value");case"symbol":throw new Re("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 Re("InvalidData","sparse arrays are not valid JSON values");e[n]=cn(t[n])}return e}const e=Object.keys(t).sort(),n={};for(const r of e)sn(r),an(n,r,cn(t[r]));return n}function un(t){const e=cn(t),n=ht(e);if(void 0===n)throw new Re("InvalidData","failed to canonicalize JSON value");return n}const hn={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[hn.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 Re("InvalidData",`Invalid hash method: ${t}`)}}},ln={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 Re("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 Re("InvalidObjType",`invalid chunk type: ${t}`)}}};class dn{constructor(t,e){this.objType=t,this.objHash=e}static fromString(t){const e=t.split(":");if(1===e.length){const t=en(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 Re("InvalidId","separator ':' not found");const r=yr(t.subarray(0,n)),i=t.slice(n+1);return new dn(r,i)}if(2===e.length)return new dn(e[0],Xe(e[1]));throw new Re("InvalidId",t)}static fromBytes(t){if(t.length<3)throw new Re("InvalidId","objid bytes too short");let e=-1;for(let i=0;i<t.length;i++)if(58===t[i]){e=i;break}if(e<0)throw new Re("InvalidId","separator ':' not found");const n=yr(t.subarray(0,e)),r=t.slice(e+1);return new dn(n,r)}static fromValue(t){if("string"==typeof t)return dn.fromString(t);throw new Re("InvalidData","ObjId MUST be string")}static fromHostname(t){const e=t.split(".")[0];return dn.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=dn.fromString(t);return n<e.length-1?{objId:r,subPath:"/"+e.slice(n+1).join("/")}:{objId:r,subPath:null}}catch{}}throw new Re("InvalidId",`no objid found in path: ${t}`)}static fromRaw(t,e){return new dn(t,e)}isChunk(){return ln.isChunkType(this.objType)}isChunkList(){return this.objType===qe}isJson(){return!this.isChunk()&&!this.isContainer()&&this.objType!==ze}isDirObject(){return this.objType===Be}isFileObject(){return this.objType===Me}isContainer(){switch(this.objType){case Be:case Fe:case Ye:case qe:return!0;default:return!1}}isBigContainer(){switch(this.objType){case Fe:case Ye:case qe:return!0;default:return!1}}toString(){return`${this.objType}:${Ze(this.objHash)}`}toFilename(){return`${Ze(this.objHash)}.${this.objType}`}toBase32(){return tn(this.toBytes())}toBytes(){const t=mr(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 fn{constructor(t,e){this.chunkType=t,this.hashResult=e}static defaultChunkType(){return"mix256"}static fromString(t){const e=dn.fromString(t);if(!e.isChunk())throw new Re("InvalidId",`invalid chunk id: ${t}`);return new fn(e.objType,e.objHash)}static fromObjId(t){return new fn(t.objType,new Uint8Array(t.objHash))}static fromBytes(t){const e=dn.fromBytes(t);return new fn(e.objType,e.objHash)}static fromHashResult(t,e){return new fn(e,new Uint8Array(t))}static fromMixHashResult(t,e,n){return new fn(n,fn.mixLengthAndHashResult(t,e))}static fromMixHashResultByHashMethod(t,e,n){const r=ln.fromHashType(n,!0);return new fn(r,fn.mixLengthAndHashResult(t,e))}static fromSha256Result(t){return new fn("sha256",new Uint8Array(t))}static fromMix256Result(t,e){return new fn("mix256",fn.mixLengthAndHashResult(t,e))}static mixLengthAndHashResult(t,e){const n=nn(t),r=new Uint8Array(n.length+e.length);return r.set(n,0),r.set(e,n.length),r}toObjId(){return new dn(this.chunkType,new Uint8Array(this.hashResult))}toString(){return`${this.chunkType}:${Ze(this.hashResult)}`}toBase32(){const t=mr(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),tn(e)}toDidString(){return`did:${this.chunkType}:${Ze(this.hashResult)}`}toBytes(){return this.toObjId().toBytes()}toJSON(){return this.toString()}getLength(){if(0===this.hashResult.length)return null;if(!ln.isMix(this.chunkType))return null;try{const[t]=rn(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 pn{genObjId(){return mn(this.getObjType(),this.toJSON())}}function wn(t,e){const n=on(e);return dn.fromRaw(t,n)}function mn(t,e){const n=un(e);return[wn(t,n),n]}function yn(t,e){const[n]=mn(t.objType,e);return t.equals(n)}const bn="\\u0009-\\u000d\\u0020\\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000",gn=new RegExp(`^[${bn}]+`),vn=new RegExp(`^[${bn}]|[${bn}]$`);function _n(t){try{return Yt(t)}catch(e){throw new Re("DecodeError",`decode jwt failed: ${e.message}`)}}function jn(t){const e=t.replace(gn,"");if(e.startsWith("{")||e.startsWith("["))try{return JSON.parse(t)}catch(n){throw new Re("InvalidId",`failed to parse obj_str: ${n.message}`)}return _n(t)}function xn(t,e){return mn(t,_n(e))}class On{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 In(){return Math.floor(Date.now()/1e3)}class kn extends pn{constructor(t,e,n){super(),this.content_obj=new On({name:t}),this.size=e,this.content=n,this.meta={}}static fromJSON(t){const e=new kn("",0,""),n={},r={},i=new Set(["did","name","author","owner","create_time","last_update_time","copyright","tags","categories","base_on","directory","references","exp"]);for(const[o,s]of Object.entries(t))"size"===o?e.size=s??0:"content"===o?e.content=s??"":i.has(o)?"base_on"===o&&"string"==typeof s?n.base_on=dn.fromString(s):n[o]=s:r[o]=s;return e.content_obj=new On(n),e.meta=r,e}getObjType(){return Me}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 Sn extends pn{constructor(t,e,n,r,i){super();const o=In();this.path=t,this.target=e,this.iat=n??o,this.exp=r??o+94608e3,this.host=i}static fromJSON(t){const e=String(t.path??""),n=dn.fromString(String(t.target??"")),r=Number(t.iat??0),i=Number(t.exp??0),o="string"==typeof t.host?t.host:void 0;return new Sn(e,n,r,i,o)}getObjType(){return Pe}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 En extends pn{constructor(t,e,n,r,i){super();const o=In();this.content_id=t.toString(),this.content_obj=e,this.curator=n,this.editor=[],this.meta=null,this.rank=r,this.collection=i,this.review_url=null,this.iat=o,this.exp=o+31104e3}static fromJSON(t){const e=new En(dn.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 Ue}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 An={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 mn(t.objType,t.obj);case"objectJwt":return xn(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:dn.fromString(t)};if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t,n=e.obj_type;if("string"!=typeof n)throw new Re("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 Re("InvalidData","SimpleMapItem must have body or jwt field")}throw new Re("InvalidData","SimpleMapItem must be string or object")}};class Dn{constructor(){this.body=new Map}static fromJSON(t){const e=new Dn;if(!t||"object"!=typeof t)throw new Re("InvalidData","SimpleObjectMap must be an object");const n=t.body;if(null==n)return e;if("object"!=typeof n||Array.isArray(n))throw new Re("InvalidData","SimpleObjectMap.body must be an object");for(const[r,i]of Object.entries(n))e.body.set(r,An.fromJSON(i));return e}genObjIdWithRealObj(t,e){const n={};for(const[r,i]of this.body){const[t]=An.getObjId(i);n[r]=t.toString()}return e.body=n,mn(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]=An.toJSON(n);return{body:t}}}class Nn extends pn{constructor(t){super(),this.content_obj=null!=t?new On({name:t}):new On,this.meta={},this.total_size=0,this.file_count=0,this.file_size=0,this.object_map=new Dn}static fromJSON(t){const e=new Nn,n=new Set(["did","name","author","owner","create_time","last_update_time","copyright","tags","categories","base_on","directory","references","exp"]),r={};for(const[i,o]of Object.entries(t))if("meta"===i)e.meta=o??{};else if("total_size"===i)e.total_size=Number(o??0);else if("file_count"===i)e.file_count=Number(o??0);else if("file_size"===i)e.file_size=Number(o??0);else if("body"===i){const t=o;if(t)for(const[n,r]of Object.entries(t))e.object_map.set(n,An.fromJSON(r))}else n.has(i)&&("base_on"===i&&"string"==typeof o?r.base_on=dn.fromString(o):r[i]=o);return e.content_obj=new On(r),e}getObjType(){return Be}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(Be,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,An.fromObject(Me,e))}addDirectory(t,e,n){if(e.objType!==Be)throw new Re("InvalidParam","dir_obj_id is not a directory");this.total_size+=n,this.object_map.set(t,An.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===Me)}isDirectory(t){const e=this.object_map.get(t);if(!e)return!1;switch(e.kind){case"objId":return e.objId.objType===Be;case"objectJwt":return e.objType===Be;default:return!1}}}class Tn{constructor(){this.total_size=0,this.body=[]}static fromChunkList(t){const e=new Tn;for(const n of t){const t=n.getLength();if(null==t)throw new Re("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 Re("InvalidParam",`parse chunk list from json failed: ${n.message}`)}return Tn.fromJsonValue(e)}static fromJsonValue(t){if(!Array.isArray(t))throw new Re("InvalidParam","chunk list must be a JSON array");const e=t.map((t=>{if("string"!=typeof t)throw new Re("InvalidParam","chunk list item must be a string");return fn.fromString(t)}));return Tn.fromChunkList(e)}appendChunk(t){const e=t.getLength();if(null==e)throw new Re("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]=mn(qe,t),r=fn.mixLengthAndHashResult(this.total_size,e.objHash);return[dn.fromRaw(qe,r),n]}}class Cn extends pn{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[i,o]of Object.entries(t))e.has(i)||(n[i]=o);const r=new Cn(dn.fromString(String(t.source??"")),String(t.relation??""),dn.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 Cn(t,We,e.target);case"partOf":return new Cn(t,Ve,e.target,{range:{start:e.range.start,end:e.range.end}})}}getLinkData(){switch(this.relation){case We:return{kind:"sameAs",target:this.target};case Ve:{const t=this.body.range;if(!t||"number"!=typeof t.start||"number"!=typeof t.end)throw new Re("InvalidLink",`invalid range: ${JSON.stringify(this.body.range)}`);return{kind:"partOf",target:this.target,range:{start:t.start,end:t.end}}}default:throw new Re("InvalidLink",`invalid relation: ${this.relation}`)}}getObjType(){return Le}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 Jn(t,e){return new Re("DecodeError",`${t} must be ${e}`)}function $n(t,e){if(null===t||"object"!=typeof t||Array.isArray(t))throw Jn(e,"an object");return t}function Kn(t,e){if("string"!=typeof t)throw Jn(e,"a string");return t}function Rn(t,e){if("number"!=typeof t||!Number.isSafeInteger(t)||t<0)throw Jn(e,"a non-negative safe integer");return t}function Mn(t,e){const n=Kn(t,e);try{return dn.fromString(n).toString()}catch(r){throw Jn(e,`an ObjId (${r.message})`)}}function Bn(t,e){const n=Kn(t,e),r=n.split(":");if(r.length<3||"did"!==r[0])throw Jn(e,"a did:method:id");return n}function Hn(t,e,n){if("string"!=typeof e||!t.includes(e))throw Jn(n,`one of ${t.join(", ")}`);return e}function Pn(t,e,n){if(!Array.isArray(t))throw Jn(e,"an array");return t.map(((t,r)=>n(t,`${e}[${r}]`)))}function Un(t,e,n){return null==t?void 0:n(t,e)}function Ln(t){const e={};for(const[n,r]of Object.entries(t))void 0!==r&&an(e,n,r);return e}const zn=["chat","group_msg","deliver","notify","event","operation"],Fn=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"]]),Yn=["edit","redact","reaction","thread"],qn=["context","input","output","evidence","control"],Wn=["from","to","kind","to_session","thread","relates_to","mentions","workspace","created_at_ms","expires_at_ms","nonce","content","proof"];function Vn(t){if(!t||"."===t||".."===t||vn.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 Gn(t){var e;const n=t.to_session;if(null!=n){if(!Vn(n))throw new Re("InvalidData",`invalid msg to_session: ${JSON.stringify(n)}`);if(1!==t.to.length)throw new Re("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 Re("InvalidData","msg.mentions must be omitted when empty");const i=t.relates_to;if(null!=i){if(dn.fromString(i.target).objType!==He)throw new Re("InvalidData",`msg.relates_to.target must be a ${He} object`);const t=i.key??void 0;if("reaction"===i.rel){if(void 0===t)throw new Re("InvalidData","reaction requires msg.relates_to.key");const e=mr(t).length;if(0===e||e>64)throw new Re("InvalidData","msg.relates_to.key must be 1-64 bytes")}else if(Yn.includes(i.rel)&&void 0!==t)throw new Re("InvalidData","msg.relates_to.key is only allowed for reaction")}if(void 0!==t.proof)throw new Re("InvalidData","msg meta key 'proof' is reserved")}function Zn(t,e){const n=$n(t,e);return Ln({rel:Kn(n.rel,`${e}.rel`),target:Mn(n.target,`${e}.target`),key:Un(n.key,`${e}.key`,Kn)})}function Xn(t,e){const n=$n(t,e),r=void 0===n.dids?[]:Pn(n.dids,`${e}.dids`,Bn);if(void 0!==n.all&&"boolean"!=typeof n.all)throw Jn(`${e}.all`,"a boolean");return Ln({dids:r.length>0?r:void 0,all:!0===n.all||void 0})}function Qn(t,e){const n=$n(t,e),r=void 0===n.data?{}:$n(n.data,`${e}.data`);return Ln({intent:Un(n.intent,`${e}.intent`,Kn),data:Object.keys(r).length>0?r:void 0})}function tr(t,e){const n=$n(t,e);switch(n.type){case"data_obj":return Ln({type:"data_obj",obj_id:Mn(n.obj_id,`${e}.obj_id`),uri_hint:Un(n.uri_hint,`${e}.uri_hint`,Kn)});case"service_did":return{type:"service_did",did:Bn(n.did,`${e}.did`)};default:throw Jn(`${e}.type`,"data_obj or service_did")}}function er(t,e){const n=$n(t,e);return Ln({role:Hn(qn,n.role,`${e}.role`),target:tr(n.target,`${e}.target`),label:Un(n.label,`${e}.label`,Kn)})}function nr(t,e){const n=Kn(t,e);return Fn.get(n)??n}function rr(t,e){const n=$n(t,e),r=void 0===n.content?"":Kn(n.content,`${e}.content`),i=void 0===n.refs?[]:Pn(n.refs,`${e}.refs`,er);return Ln({title:Un(n.title,`${e}.title`,Kn),format:Un(n.format,`${e}.format`,nr),content:r.length>0?r:void 0,machine:Un(n.machine,`${e}.machine`,Qn),refs:i.length>0?i:void 0})}const ir=new Set(Wn.filter((t=>"proof"!==t)));function or(t){const e=$n(t,"MsgObject"),n=void 0===e.thread?{}:function(t,e){const n=$n(t,e);return Ln({topic:Un(n.topic,`${e}.topic`,Kn),reply_to:Un(n.reply_to,`${e}.reply_to`,Mn),correlation_id:Un(n.correlation_id,`${e}.correlation_id`,Kn)})}(e.thread,"MsgObject.thread"),r=void 0===e.created_at_ms?0:Rn(e.created_at_ms,"MsgObject.created_at_ms"),i=Ln({from:Bn(e.from,"MsgObject.from"),to:Pn(e.to,"MsgObject.to",Bn),kind:Hn(zn,e.kind,"MsgObject.kind"),to_session:Un(e.to_session,"MsgObject.to_session",Kn),thread:Object.keys(n).length>0?n:void 0,relates_to:Un(e.relates_to,"MsgObject.relates_to",Zn),mentions:Un(e.mentions,"MsgObject.mentions",Xn),workspace:Un(e.workspace,"MsgObject.workspace",Bn),created_at_ms:0!==r?r:void 0,expires_at_ms:Un(e.expires_at_ms,"MsgObject.expires_at_ms",Rn),nonce:Un(e.nonce,"MsgObject.nonce",Rn),content:rr(e.content,"MsgObject.content")});for(const[o,s]of Object.entries(e))ir.has(o)||an(i,o,s);return i}function sr(t){const[e]=mn(He,t),n=or(t);Gn(n);const[r]=mn(He,n);if(!r.equals(e))throw new Re("InvalidData","MsgObject JSON is not in canonical form");return[n,e]}function ar(t){let e;try{e=qt(t)}catch(i){throw new Re("DecodeError",`decode msg jwt header failed: ${i.message}`)}const{alg:n,kid:r}=$n(e,"msg jwt header");if("EdDSA"!==n)throw new Re("InvalidData",`msg jwt alg must be EdDSA, got ${String(n)}`);if("string"!=typeof r||0===r.length)throw new Re("InvalidData","msg jwt header requires kid");return r}const cr=["accepted","rejected","quarantined"];function ur(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 hr="application/cyfs-named-object+json",lr="application/cyfs-named-object+jwt";function dr(t){const e=t.split(";")[0].trim().toLowerCase();return e===hr?"json":e===lr?"jwt":null}const fr={fromObjData(t,e){switch(t.objType){case Be:{let t;try{t=JSON.parse(e)}catch(n){throw new Re("InvalidParam",`parse dir object from json failed: ${n.message}`)}return{kind:"dir",obj:Nn.fromJSON(t),objStr:e}}case Me:{let t;try{t=JSON.parse(e)}catch(n){throw new Re("InvalidParam",`parse file object from json failed: ${n.message}`)}return{kind:"file",obj:kn.fromJSON(t),objStr:e}}case qe:return{kind:"chunkList",obj:Tn.fromJson(e),objStr:e};default:throw new Re("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]=An.getObjId(n);e.push({objId:t,objStr:r.length>0?r:null})}return e}case"file":return 0===t.obj.content.length?[]:[{objId:dn.fromString(t.obj.content),objStr:null}];case"chunkList":return t.obj.body.map((t=>({objId:t.toObjId(),objStr:null})))}}},pr="undefined"!=typeof TextEncoder?new TextEncoder:null,wr="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function mr(t){if(pr)return pr.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 i=65536+((1023&r)<<10|1023&t.charCodeAt(++n));e.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i)}else e.push(224|r>>12,128|r>>6&63,128|63&r)}return new Uint8Array(e)}function yr(t){if(wr)return wr.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 i=((7&r)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536;e+=String.fromCharCode(55296+(i>>10),56320+(1023&i))}}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=On,exports.CYFS_CONTENT_TYPE_NAMED_OBJECT_JSON=hr,exports.CYFS_CONTENT_TYPE_NAMED_OBJECT_JWT=lr,exports.ChunkId=fn,exports.ChunkType=ln,exports.DEFAULT_EXPIRE_TIME=Ot,exports.DEFAULT_HASH_METHOD="sha256",exports.DID=Xt,exports.DID_OBJECT_SERVICE_ID="#did-object",exports.DID_OBJECT_SERVICE_TYPE=lt,exports.DirObject=Nn,exports.FileObject=kn,exports.HashMethod=hn,exports.InclusionProof=En,exports.KnownStandardObject=fr,exports.MSG_OBJECT_RESERVED_KEYS=Wn,exports.MSG_REACTION_KEY_MAX_BYTES=64,exports.MSG_SESSION_ID_MAX_CHARS=200,exports.NODE_IDENTITY_SCHEMA_V2=dt,exports.NamedObjectBase=pn,exports.NdnError=Re,exports.OBJ_TYPE_ACTION="cyact",exports.OBJ_TYPE_CHUNK_LIST=qe,exports.OBJ_TYPE_DIR=Be,exports.OBJ_TYPE_FILE=Me,exports.OBJ_TYPE_INCLUSION_PROOF=Ue,exports.OBJ_TYPE_LIST=Ye,exports.OBJ_TYPE_MSG=He,exports.OBJ_TYPE_OBJMAP=Fe,exports.OBJ_TYPE_PACK=ze,exports.OBJ_TYPE_PATH=Pe,exports.OBJ_TYPE_PKG="pkg",exports.OBJ_TYPE_RECEIPT="cyrece",exports.OBJ_TYPE_RELATION=Le,exports.ObjId=dn,exports.PathObject=Sn,exports.RELATION_TYPE_PART_OF=Ve,exports.RELATION_TYPE_SAME=We,exports.RelationObject=Cn,exports.SimpleChunkList=Tn,exports.SimpleMapItem=An,exports.SimpleObjectMap=Dn,exports.actionObjectFromJson=function(t){const e=$n(t,"ActionObject");return Ln({subject:Mn(e.subject,"ActionObject.subject"),action:Kn(e.action,"ActionObject.action"),target:Mn(e.target,"ActionObject.target"),base_on:Un(e.base_on,"ActionObject.base_on",Mn),details:e.details??void 0,iat:Rn(e.iat,"ActionObject.iat"),exp:Rn(e.exp,"ActionObject.exp")})},exports.base32Decode=en,exports.base32Encode=tn,exports.buckyosGetUnixTimestamp=St,exports.buildNamedObjectByJson=mn,exports.buildNamedObjectByJwt=xn,exports.buildObjId=wn,exports.bytesToHex=Ze,exports.calcPkgMetaObjId=function(t){const e=ur(t),[n]=mn("pkg",e);return n.toString()},exports.canonicalize=ht,exports.canonicalizeJson=cn,exports.commonjsGlobal=ct,exports.createJwkByX=zt,exports.decodeJwtClaimWithoutVerify=Yt,exports.decodeMsgObjectJwt=function(t){const e=ar(t),[n,r]=sr(_n(t));return{msg:n,objId:r,kid:e}},exports.deviceDocumentToOrderedJson=Ie,exports.deviceMiniDocumentToJwt=ge,exports.encodeDeviceDocument=we,exports.encodeZoneBootDocument=le,exports.encodeZoneDocument=_e,exports.extractObjIdByPath=function(t,e){const n=e.split("/").filter((t=>t.length>0));let r=t;for(const o of n){if(null==r)throw new Re("InvalidParam",`objid path not found: ${e}`);if(Array.isArray(r)){const t=Number(o);if(!Number.isInteger(t)||t<0||t>=r.length)throw new Re("InvalidParam",`objid path not found: ${e}`);r=r[t]}else{if("object"!=typeof r)throw new Re("InvalidParam",`objid path not found: ${e}`);if(!(o in r))throw new Re("InvalidParam",`objid path not found: ${e}`);r=r[o]}}try{return dn.fromValue(r)}catch(i){throw new Re("InvalidData",`invalid objid at path ${e}: ${i.message}`)}},exports.getDefaultExportFromCjs=ut,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=Ut,exports.getXFromJwk=Lt,exports.hexToBytes=Xe,exports.ht=at,exports.isBuckyOSAgentDocument=gt,exports.isBuckyOSDIDObjectCard=_t,exports.isBuckyOSDeviceDocument=bt,exports.isBuckyOSDeviceMiniDocument=yt,exports.isBuckyOSLocalNodeIdentityConfig=function(t){return ft(t)&&t.schema===dt&&"string"==typeof t.zone_did&&"string"==typeof t.owner_did&&ft(t.owner_public_key)&&"string"==typeof t.device_name&&"string"==typeof t.device_did&&"number"==typeof t.zone_iat},exports.isBuckyOSOwnerDocument=mt,exports.isBuckyOSZoneBootDocument=function(t){return ft(t)&&Array.isArray(t.oods)&&t.oods.every((t=>"string"==typeof t))&&"number"==typeof t.exp},exports.isBuckyOSZoneConfig=function(t){return ft(t)&&"string"==typeof t.zone_document},exports.isBuckyOSZoneDocument=vt,exports.isCyfsNamedObjectContentType=function(t){return null!==dr(t)},exports.isValidMsgSessionId=Vn,exports.isW3CDIDDocumentBase=wt,exports.loadNamedObj=function(t){return jn(t)},exports.loadNamedObjAndVerify=function(t,e){const n=jn(e);if(!yn(t,n))throw new Re("InvalidId",`verify named object failed for obj_id: ${t.toString()}`);return n},exports.loadNamedObjectFromObjStr=jn,exports.msgJwtKidDid=function(t){try{return Xt.fromStr(t.split("#")[0]).toString()}catch{return null}},exports.msgObjectFromJsonChecked=sr,exports.namedObjectEncodingFromContentType=dr,exports.namelib=Ke,exports.newDeviceDocumentByJwk=fe,exports.newDeviceDocumentByMiniDocument=pe,exports.newDeviceMiniDocument=ye,exports.newDeviceMiniDocumentByDeviceDocument=be,exports.newOwnerDocument=oe,exports.newZoneBootDocument=he,exports.newZoneDocument=ue,exports.normalizePackageMetaForObjId=ur,exports.oodDescriptionToString=te,exports.ownerDocumentSetDefaultZoneDid=se,exports.ownerDocumentToOrderedJson=xe,exports.parseBuckyOSDIDDocument=function(t){return mt(t)||gt(t)||bt(t)||vt(t)||_t(t)?t:null},exports.parseBuckyOSDeviceMiniDocument=function(t){return yt(t)?t:null},exports.parseBuckyOSOwnerDocument=function(t){return mt(t)?t:null},exports.parseOODDescription=Qt,exports.parseW3CDIDDocumentBase=function(t){return wt(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=$n(t,"ReceiptObj");return Ln({obj_id:Mn(e.obj_id,"ReceiptObj.obj_id"),iss:Bn(e.iss,"ReceiptObj.iss"),channel:Un(e.channel,"ReceiptObj.channel",Kn),iat:Rn(e.iat,"ReceiptObj.iat"),status:Hn(cr,e.status,"ReceiptObj.status"),reason:Un(e.reason,"ReceiptObj.reason",Kn)})},exports.sha256Bytes=function(t){const e=new at("SHA-256","UINT8ARRAY");return e.update(t),e.getHash("UINT8ARRAY")},exports.sha256Utf8=on,exports.signJwtEdDSA=Ft,exports.toCanonicalJsonString=un,exports.validateMsgObject=Gn,exports.varintDecode=rn,exports.varintEncode=nn,exports.verifyJwtEdDSA=Wt,exports.verifyMsgObjectJwt=async function(t,e){const n=ar(t);let r;try{r=await Wt(t,e)}catch(s){throw new Re("VerifyError",`verify msg jwt failed: ${s.message}`)}const[i,o]=sr(r);return{msg:i,objId:o,kid:n}},exports.verifyNamedObject=yn,exports.verifyNamedObjectFromJwt=function(t,e){const[n]=xn(t.objType,e);return t.equals(n)},exports.verifyNamedObjectFromStr=function(t,e){let n;try{n=JSON.parse(e)}catch(r){throw new Re("InvalidId",`failed to parse obj_str: ${r.message}`)}if(!yn(t,n))throw new Re("InvalidId",`verify named object failed: ${e}`);return n},exports.zoneDocumentToOrderedJson=Oe;
2
+ //# sourceMappingURL=ndn_types-5b138882.js.map