buckyos 0.7.119 → 0.7.121

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 (44) hide show
  1. package/cli/README.md +24 -3
  2. package/cli/core/app.ts +28 -0
  3. package/cli/deno.json +2 -1
  4. package/cli/dist/cli.mjs +777 -169
  5. package/cli/dist/cli.mjs.map +1 -1
  6. package/cli/modules/app.ts +213 -94
  7. package/cli/modules/provision.ts +690 -0
  8. package/cli/runtime/host.ts +25 -2
  9. package/cli/runtime/host_deno.ts +4 -0
  10. package/cli/runtime/host_node.ts +4 -0
  11. package/cli/version.ts +1 -1
  12. package/dist/browser.cjs +1 -1
  13. package/dist/browser.mjs +124 -124
  14. package/dist/index.cjs +1 -1
  15. package/dist/index.mjs +124 -124
  16. package/dist/{ndm_proxy-c00bc561.mjs → ndm_proxy-8f547002.mjs} +113 -216
  17. package/dist/ndm_proxy-8f547002.mjs.map +1 -0
  18. package/dist/ndm_proxy-93a8869b.js +13 -0
  19. package/dist/ndm_proxy-93a8869b.js.map +1 -0
  20. package/dist/ndn_types-44c69036.js +2 -0
  21. package/dist/ndn_types-44c69036.js.map +1 -0
  22. package/dist/{ndn_types-f6c08d20.mjs → ndn_types-d768245f.mjs} +149 -39
  23. package/dist/ndn_types-d768245f.mjs.map +1 -0
  24. package/dist/node.cjs +1 -1
  25. package/dist/node.mjs +124 -124
  26. package/dist/provision.cjs +6 -6
  27. package/dist/provision.cjs.map +1 -1
  28. package/dist/provision.d.ts +2 -0
  29. package/dist/provision.d.ts.map +1 -1
  30. package/dist/provision.mjs +1084 -35
  31. package/dist/provision.mjs.map +1 -1
  32. package/dist/provision_activate.d.ts +146 -0
  33. package/dist/provision_activate.d.ts.map +1 -0
  34. package/dist/{tus_client-573066b3.mjs → tus_client-b1c35e8c.mjs} +2 -2
  35. package/dist/{tus_client-573066b3.mjs.map → tus_client-b1c35e8c.mjs.map} +1 -1
  36. package/dist/{tus_client-83ad0f4f.js → tus_client-d0798623.js} +2 -2
  37. package/dist/{tus_client-83ad0f4f.js.map → tus_client-d0798623.js.map} +1 -1
  38. package/package.json +1 -1
  39. package/dist/ndm_proxy-68354a89.js +0 -13
  40. package/dist/ndm_proxy-68354a89.js.map +0 -1
  41. package/dist/ndm_proxy-c00bc561.mjs.map +0 -1
  42. package/dist/ndn_types-859bbd48.js +0 -2
  43. package/dist/ndn_types-859bbd48.js.map +0 -1
  44. package/dist/ndn_types-f6c08d20.mjs.map +0 -1
@@ -653,6 +653,108 @@ class ht {
653
653
  return this.P.getHMAC(t2, n2);
654
654
  }
655
655
  }
656
+ const LEGACY_ACCOUNT_STORAGE_KEY = "buckyos.account_info";
657
+ const BROWSER_USER_INFO_STORAGE_KEY = "user_info";
658
+ function getAccountStorageKey(appId) {
659
+ return `buckyos.account_info.${appId}`;
660
+ }
661
+ function parseAccountInfo(raw) {
662
+ if (raw == null) {
663
+ return null;
664
+ }
665
+ try {
666
+ return JSON.parse(raw);
667
+ } catch {
668
+ return null;
669
+ }
670
+ }
671
+ function parseBrowserUserInfo(raw) {
672
+ if (raw == null) {
673
+ return null;
674
+ }
675
+ try {
676
+ const parsed = JSON.parse(raw);
677
+ const userId = typeof parsed.user_id === "string" ? parsed.user_id.trim() : "";
678
+ const userType = typeof parsed.user_type === "string" ? parsed.user_type.trim() : "";
679
+ const userNameCandidate = typeof parsed.user_name === "string" ? parsed.user_name.trim() : typeof parsed.show_name === "string" ? parsed.show_name.trim() : "";
680
+ if (!userId || !userType) {
681
+ return null;
682
+ }
683
+ return {
684
+ user_name: userNameCandidate || userId,
685
+ user_id: userId,
686
+ user_type: userType
687
+ };
688
+ } catch {
689
+ return null;
690
+ }
691
+ }
692
+ function parseTokenAppId(sessionToken) {
693
+ const parts = sessionToken.split(".");
694
+ if (parts.length < 2) {
695
+ return null;
696
+ }
697
+ try {
698
+ const base64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
699
+ const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
700
+ const payload = JSON.parse(atob(padded));
701
+ if (typeof payload.appid === "string" && payload.appid.trim().length > 0) {
702
+ return payload.appid;
703
+ }
704
+ } catch {
705
+ return null;
706
+ }
707
+ return null;
708
+ }
709
+ function hashPassword(username, password, nonce = null) {
710
+ const shaObj = new ht("SHA-256", "TEXT", { encoding: "UTF8" });
711
+ shaObj.update(password + username + ".buckyos");
712
+ let org_password_hash_str = shaObj.getHash("B64");
713
+ if (nonce == null) {
714
+ return org_password_hash_str;
715
+ }
716
+ const shaObj2 = new ht("SHA-256", "TEXT", { encoding: "UTF8" });
717
+ let salt = org_password_hash_str + nonce.toString();
718
+ shaObj2.update(salt);
719
+ let result = shaObj2.getHash("B64");
720
+ return result;
721
+ }
722
+ function cleanLocalAccountInfo(appId) {
723
+ localStorage.removeItem(getAccountStorageKey(appId));
724
+ localStorage.removeItem(BROWSER_USER_INFO_STORAGE_KEY);
725
+ const legacy = parseAccountInfo(localStorage.getItem(LEGACY_ACCOUNT_STORAGE_KEY));
726
+ if ((legacy == null ? void 0 : legacy.session_token) && parseTokenAppId(legacy.session_token) === appId) {
727
+ localStorage.removeItem(LEGACY_ACCOUNT_STORAGE_KEY);
728
+ }
729
+ let cookie_options = {
730
+ path: "/",
731
+ expires: /* @__PURE__ */ new Date(0),
732
+ secure: true,
733
+ sameSite: "Lax"
734
+ };
735
+ document.cookie = `${appId}_token=; ${Object.entries(cookie_options).map(([key, value]) => `${key}=${value}`).join("; ")}`;
736
+ }
737
+ function saveLocalAccountInfo(appId, account_info) {
738
+ if (account_info.session_token == null) {
739
+ console.error("session_token is null,can't save account info");
740
+ return;
741
+ }
742
+ localStorage.setItem(getAccountStorageKey(appId), JSON.stringify(account_info));
743
+ let cookie_options = {
744
+ path: "/",
745
+ expires: new Date(Date.now() + 1e3 * 60 * 60 * 24 * 30),
746
+ // 30天
747
+ secure: true,
748
+ sameSite: "Lax"
749
+ };
750
+ document.cookie = `${appId}_token=${account_info.session_token}; ${Object.entries(cookie_options).map(([key, value]) => `${key}=${value}`).join("; ")}`;
751
+ }
752
+ function saveBrowserUserInfo(userInfo) {
753
+ localStorage.setItem(BROWSER_USER_INFO_STORAGE_KEY, JSON.stringify(userInfo));
754
+ }
755
+ function getBrowserUserInfo() {
756
+ return parseBrowserUserInfo(localStorage.getItem(BROWSER_USER_INFO_STORAGE_KEY));
757
+ }
656
758
  const DID_OBJECT_SERVICE_TYPE = "DIDObjectService";
657
759
  const DID_OBJECT_SERVICE_ID = "#did-object";
658
760
  const NODE_IDENTITY_SCHEMA_V2 = "buckyos.node_identity.v2";
@@ -3639,60 +3741,68 @@ const ndn_types = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePro
3639
3741
  verifyNamedObjectFromStr
3640
3742
  }, Symbol.toStringTag, { value: "Module" }));
3641
3743
  export {
3642
- buildNamedObjectByJson as $,
3643
- newDeviceDocumentByJwk as A,
3644
- verifyJwtEdDSA as B,
3744
+ encodeDeviceDocument as $,
3745
+ canonicalize$1 as A,
3746
+ signJwtEdDSA as B,
3645
3747
  ChunkId as C,
3646
3748
  DID_OBJECT_SERVICE_TYPE as D,
3647
- deviceDocumentToOrderedJson as E,
3749
+ sha256Bytes as E,
3648
3750
  FileObject as F,
3649
- decodeJwtClaimWithoutVerify as G,
3650
- commonjsGlobal as H,
3651
- createJwkByX as I,
3652
- newOwnerDocument as J,
3653
- ownerDocumentToOrderedJson as K,
3654
- parseOODDescription as L,
3655
- oodDescriptionToString as M,
3751
+ DirObject as G,
3752
+ newDeviceDocumentByJwk as H,
3753
+ verifyJwtEdDSA as I,
3754
+ deviceDocumentToOrderedJson as J,
3755
+ decodeJwtClaimWithoutVerify as K,
3756
+ commonjsGlobal as L,
3757
+ DEFAULT_EXPIRE_TIME as M,
3656
3758
  NODE_IDENTITY_SCHEMA_V2 as N,
3657
3759
  ObjId as O,
3658
- newZoneBootDocument as P,
3659
- newZoneDocument as Q,
3660
- encodeZoneBootDocument as R,
3760
+ buckyosGetUnixTimestamp as P,
3761
+ getPublicKeyXFromPrivatePem as Q,
3762
+ getXFromJwk as R,
3661
3763
  SimpleChunkList as S,
3662
- DEFAULT_EXPIRE_TIME as T,
3663
- zoneDocumentToOrderedJson as U,
3664
- newDeviceMiniDocument as V,
3665
- deviceMiniDocumentToJwt as W,
3666
- encodeDeviceDocument as X,
3667
- newDeviceMiniDocumentByDeviceDocument as Y,
3668
- newDeviceDocumentByMiniDocument as Z,
3669
- buckyosGetUnixTimestamp as _,
3764
+ createJwkByX as T,
3765
+ newOwnerDocument as U,
3766
+ ownerDocumentSetDefaultZoneDid as V,
3767
+ ownerDocumentToOrderedJson as W,
3768
+ oodDescriptionToString as X,
3769
+ parseOODDescription as Y,
3770
+ encodeZoneBootDocument as Z,
3771
+ newZoneBootDocument as _,
3670
3772
  ndn_types as a,
3671
- getDefaultExportFromCjs as a0,
3773
+ newDeviceMiniDocumentByDeviceDocument as a0,
3774
+ deviceMiniDocumentToJwt as a1,
3775
+ newZoneDocument as a2,
3776
+ encodeZoneDocument as a3,
3777
+ zoneDocumentToOrderedJson as a4,
3778
+ newDeviceMiniDocument as a5,
3779
+ newDeviceDocumentByMiniDocument as a6,
3780
+ buildNamedObjectByJson as a7,
3781
+ getDefaultExportFromCjs as a8,
3672
3782
  DID_OBJECT_SERVICE_ID as b,
3673
3783
  isBuckyOSOwnerDocument as c,
3674
3784
  isBuckyOSDeviceMiniDocument as d,
3675
3785
  isBuckyOSZoneBootDocument as e,
3676
3786
  isBuckyOSNodeIdentityConfig as f,
3677
3787
  isBuckyOSLocalNodeIdentityConfig as g,
3678
- isBuckyOSDeviceDocument as h,
3788
+ hashPassword as h,
3679
3789
  isW3CDIDDocumentBase as i,
3680
- isBuckyOSAgentDocument as j,
3681
- isBuckyOSZoneDocument as k,
3682
- isBuckyOSDIDObjectCard as l,
3683
- isBuckyOSZoneConfig as m,
3790
+ isBuckyOSDeviceDocument as j,
3791
+ isBuckyOSAgentDocument as k,
3792
+ isBuckyOSZoneDocument as l,
3793
+ isBuckyOSDIDObjectCard as m,
3684
3794
  namelib as n,
3685
- parseBuckyOSOwnerDocument as o,
3795
+ isBuckyOSZoneConfig as o,
3686
3796
  parseW3CDIDDocumentBase as p,
3687
- parseBuckyOSDeviceMiniDocument as q,
3688
- parseBuckyOSDIDDocument as r,
3689
- getDidMethod as s,
3690
- getDidIdentifier as t,
3691
- ht as u,
3797
+ parseBuckyOSOwnerDocument as q,
3798
+ parseBuckyOSDeviceMiniDocument as r,
3799
+ parseBuckyOSDIDDocument as s,
3800
+ getDidMethod as t,
3801
+ getDidIdentifier as u,
3692
3802
  DID as v,
3693
- canonicalize$1 as w,
3694
- signJwtEdDSA as x,
3695
- sha256Bytes as y,
3696
- DirObject as z
3803
+ getBrowserUserInfo as w,
3804
+ saveBrowserUserInfo as x,
3805
+ saveLocalAccountInfo as y,
3806
+ cleanLocalAccountInfo as z
3697
3807
  };
3698
- //# sourceMappingURL=ndn_types-f6c08d20.mjs.map
3808
+ //# sourceMappingURL=ndn_types-d768245f.mjs.map