@metamask-previews/account-tree-controller 8.0.0-preview-4f4c98e → 8.0.0-preview-eb263b0ee
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -1
- package/dist/AccountTreeController-method-action-types.cjs +7 -0
- package/dist/AccountTreeController-method-action-types.cjs.map +1 -0
- package/dist/{AccountTreeController-method-action-types.d.ts → AccountTreeController-method-action-types.d.cts} +2 -2
- package/dist/AccountTreeController-method-action-types.d.cts.map +1 -0
- package/dist/AccountTreeController-method-action-types.d.mts +256 -0
- package/dist/AccountTreeController-method-action-types.d.mts.map +1 -0
- package/dist/{AccountTreeController-method-action-types.js → AccountTreeController-method-action-types.mjs} +1 -1
- package/dist/AccountTreeController-method-action-types.mjs.map +1 -0
- package/dist/AccountTreeController.cjs +1247 -0
- package/dist/AccountTreeController.cjs.map +1 -0
- package/dist/{AccountTreeController.d.ts → AccountTreeController.d.cts} +17 -17
- package/dist/AccountTreeController.d.cts.map +1 -0
- package/dist/AccountTreeController.d.mts +269 -0
- package/dist/AccountTreeController.d.mts.map +1 -0
- package/dist/{AccountTreeController.js → AccountTreeController.mjs} +15 -15
- package/dist/AccountTreeController.mjs.map +1 -0
- package/dist/backup-and-sync/analytics/index.cjs +19 -0
- package/dist/backup-and-sync/analytics/index.cjs.map +1 -0
- package/dist/backup-and-sync/analytics/index.d.cts +3 -0
- package/dist/backup-and-sync/analytics/index.d.cts.map +1 -0
- package/dist/backup-and-sync/analytics/index.d.mts +3 -0
- package/dist/backup-and-sync/analytics/index.d.mts.map +1 -0
- package/dist/backup-and-sync/analytics/index.mjs +3 -0
- package/dist/backup-and-sync/analytics/index.mjs.map +1 -0
- package/dist/backup-and-sync/analytics/segment.cjs +38 -0
- package/dist/backup-and-sync/analytics/segment.cjs.map +1 -0
- package/dist/backup-and-sync/analytics/{segment.d.ts → segment.d.cts} +10 -10
- package/dist/backup-and-sync/analytics/segment.d.cts.map +1 -0
- package/dist/backup-and-sync/analytics/segment.d.mts +37 -0
- package/dist/backup-and-sync/analytics/segment.d.mts.map +1 -0
- package/dist/backup-and-sync/analytics/{segment.js → segment.mjs} +1 -1
- package/dist/backup-and-sync/analytics/segment.mjs.map +1 -0
- package/dist/backup-and-sync/analytics/traces.cjs +24 -0
- package/dist/backup-and-sync/analytics/traces.cjs.map +1 -0
- package/dist/backup-and-sync/analytics/{traces.d.ts → traces.d.cts} +3 -3
- package/dist/backup-and-sync/analytics/traces.d.cts.map +1 -0
- package/dist/backup-and-sync/analytics/traces.d.mts +16 -0
- package/dist/backup-and-sync/analytics/traces.d.mts.map +1 -0
- package/dist/backup-and-sync/analytics/{traces.js → traces.mjs} +1 -1
- package/dist/backup-and-sync/analytics/traces.mjs.map +1 -0
- package/dist/backup-and-sync/authentication/index.cjs +18 -0
- package/dist/backup-and-sync/authentication/index.cjs.map +1 -0
- package/dist/backup-and-sync/authentication/index.d.cts +2 -0
- package/dist/backup-and-sync/authentication/index.d.cts.map +1 -0
- package/dist/backup-and-sync/authentication/index.d.mts +2 -0
- package/dist/backup-and-sync/authentication/index.d.mts.map +1 -0
- package/dist/backup-and-sync/authentication/index.mjs +2 -0
- package/dist/backup-and-sync/authentication/index.mjs.map +1 -0
- package/dist/backup-and-sync/authentication/utils.cjs +23 -0
- package/dist/backup-and-sync/authentication/utils.cjs.map +1 -0
- package/dist/backup-and-sync/authentication/{utils.d.ts → utils.d.cts} +3 -3
- package/dist/backup-and-sync/authentication/utils.d.cts.map +1 -0
- package/dist/backup-and-sync/authentication/utils.d.mts +12 -0
- package/dist/backup-and-sync/authentication/utils.d.mts.map +1 -0
- package/dist/backup-and-sync/authentication/{utils.js → utils.mjs} +2 -2
- package/dist/backup-and-sync/authentication/utils.mjs.map +1 -0
- package/dist/backup-and-sync/service/atomic-sync-queue.cjs +123 -0
- package/dist/backup-and-sync/service/atomic-sync-queue.cjs.map +1 -0
- package/dist/backup-and-sync/service/{atomic-sync-queue.d.ts → atomic-sync-queue.d.cts} +1 -1
- package/dist/backup-and-sync/service/atomic-sync-queue.d.cts.map +1 -0
- package/dist/backup-and-sync/service/atomic-sync-queue.d.mts +43 -0
- package/dist/backup-and-sync/service/atomic-sync-queue.d.mts.map +1 -0
- package/dist/backup-and-sync/service/{atomic-sync-queue.js → atomic-sync-queue.mjs} +3 -3
- package/dist/backup-and-sync/service/atomic-sync-queue.mjs.map +1 -0
- package/dist/backup-and-sync/service/index.cjs +403 -0
- package/dist/backup-and-sync/service/index.cjs.map +1 -0
- package/dist/backup-and-sync/service/{index.d.ts → index.d.cts} +4 -4
- package/dist/backup-and-sync/service/index.d.cts.map +1 -0
- package/dist/backup-and-sync/service/index.d.mts +84 -0
- package/dist/backup-and-sync/service/index.d.mts.map +1 -0
- package/dist/backup-and-sync/service/{index.js → index.mjs} +9 -9
- package/dist/backup-and-sync/service/index.mjs.map +1 -0
- package/dist/backup-and-sync/syncing/group.cjs +190 -0
- package/dist/backup-and-sync/syncing/group.cjs.map +1 -0
- package/dist/backup-and-sync/syncing/{group.d.ts → group.d.cts} +6 -6
- package/dist/backup-and-sync/syncing/group.d.cts.map +1 -0
- package/dist/backup-and-sync/syncing/group.d.mts +48 -0
- package/dist/backup-and-sync/syncing/group.d.mts.map +1 -0
- package/dist/backup-and-sync/syncing/{group.js → group.mjs} +9 -9
- package/dist/backup-and-sync/syncing/group.mjs.map +1 -0
- package/dist/backup-and-sync/syncing/index.cjs +21 -0
- package/dist/backup-and-sync/syncing/index.cjs.map +1 -0
- package/dist/backup-and-sync/syncing/index.d.cts +5 -0
- package/dist/backup-and-sync/syncing/index.d.cts.map +1 -0
- package/dist/backup-and-sync/syncing/index.d.mts +5 -0
- package/dist/backup-and-sync/syncing/index.d.mts.map +1 -0
- package/dist/backup-and-sync/syncing/index.mjs +5 -0
- package/dist/backup-and-sync/syncing/index.mjs.map +1 -0
- package/dist/backup-and-sync/syncing/legacy.cjs +74 -0
- package/dist/backup-and-sync/syncing/legacy.cjs.map +1 -0
- package/dist/backup-and-sync/syncing/{legacy.d.ts → legacy.d.cts} +3 -3
- package/dist/backup-and-sync/syncing/legacy.d.cts.map +1 -0
- package/dist/backup-and-sync/syncing/legacy.d.mts +15 -0
- package/dist/backup-and-sync/syncing/legacy.d.mts.map +1 -0
- package/dist/backup-and-sync/syncing/{legacy.js → legacy.mjs} +8 -8
- package/dist/backup-and-sync/syncing/legacy.mjs.map +1 -0
- package/dist/backup-and-sync/syncing/metadata.cjs +56 -0
- package/dist/backup-and-sync/syncing/metadata.cjs.map +1 -0
- package/dist/backup-and-sync/syncing/{metadata.d.ts → metadata.d.cts} +4 -4
- package/dist/backup-and-sync/syncing/metadata.d.cts.map +1 -0
- package/dist/backup-and-sync/syncing/metadata.d.mts +39 -0
- package/dist/backup-and-sync/syncing/metadata.d.mts.map +1 -0
- package/dist/backup-and-sync/syncing/{metadata.js → metadata.mjs} +9 -2
- package/dist/backup-and-sync/syncing/metadata.mjs.map +1 -0
- package/dist/backup-and-sync/syncing/wallet.cjs +64 -0
- package/dist/backup-and-sync/syncing/wallet.cjs.map +1 -0
- package/dist/backup-and-sync/syncing/{wallet.d.ts → wallet.d.cts} +4 -4
- package/dist/backup-and-sync/syncing/wallet.d.cts.map +1 -0
- package/dist/backup-and-sync/syncing/wallet.d.mts +23 -0
- package/dist/backup-and-sync/syncing/wallet.d.mts.map +1 -0
- package/dist/backup-and-sync/syncing/{wallet.js → wallet.mjs} +6 -6
- package/dist/backup-and-sync/syncing/wallet.mjs.map +1 -0
- package/dist/backup-and-sync/types.cjs +41 -0
- package/dist/backup-and-sync/types.cjs.map +1 -0
- package/dist/backup-and-sync/{types.d.ts → types.d.cts} +12 -12
- package/dist/backup-and-sync/types.d.cts.map +1 -0
- package/dist/backup-and-sync/types.d.mts +131 -0
- package/dist/backup-and-sync/types.d.mts.map +1 -0
- package/dist/backup-and-sync/{types.js → types.mjs} +2 -2
- package/dist/backup-and-sync/types.mjs.map +1 -0
- package/dist/backup-and-sync/user-storage/constants.cjs +8 -0
- package/dist/backup-and-sync/user-storage/constants.cjs.map +1 -0
- package/dist/backup-and-sync/user-storage/{constants.d.ts → constants.d.cts} +1 -1
- package/dist/backup-and-sync/user-storage/constants.d.cts.map +1 -0
- package/dist/backup-and-sync/user-storage/constants.d.mts +5 -0
- package/dist/backup-and-sync/user-storage/constants.d.mts.map +1 -0
- package/dist/backup-and-sync/user-storage/{constants.js → constants.mjs} +1 -1
- package/dist/backup-and-sync/user-storage/constants.mjs.map +1 -0
- package/dist/backup-and-sync/user-storage/format-utils.cjs +115 -0
- package/dist/backup-and-sync/user-storage/format-utils.cjs.map +1 -0
- package/dist/backup-and-sync/user-storage/{format-utils.d.ts → format-utils.d.cts} +4 -4
- package/dist/backup-and-sync/user-storage/format-utils.d.cts.map +1 -0
- package/dist/backup-and-sync/user-storage/format-utils.d.mts +54 -0
- package/dist/backup-and-sync/user-storage/format-utils.d.mts.map +1 -0
- package/dist/backup-and-sync/user-storage/{format-utils.js → format-utils.mjs} +6 -6
- package/dist/backup-and-sync/user-storage/format-utils.mjs.map +1 -0
- package/dist/backup-and-sync/user-storage/index.cjs +21 -0
- package/dist/backup-and-sync/user-storage/index.cjs.map +1 -0
- package/dist/backup-and-sync/user-storage/index.d.cts +5 -0
- package/dist/backup-and-sync/user-storage/index.d.cts.map +1 -0
- package/dist/backup-and-sync/user-storage/index.d.mts +5 -0
- package/dist/backup-and-sync/user-storage/index.d.mts.map +1 -0
- package/dist/backup-and-sync/user-storage/index.mjs +5 -0
- package/dist/backup-and-sync/user-storage/index.mjs.map +1 -0
- package/dist/backup-and-sync/user-storage/network-operations.cjs +193 -0
- package/dist/backup-and-sync/user-storage/network-operations.cjs.map +1 -0
- package/dist/backup-and-sync/user-storage/{network-operations.d.ts → network-operations.d.cts} +4 -4
- package/dist/backup-and-sync/user-storage/network-operations.d.cts.map +1 -0
- package/dist/backup-and-sync/user-storage/network-operations.d.mts +80 -0
- package/dist/backup-and-sync/user-storage/network-operations.d.mts.map +1 -0
- package/dist/backup-and-sync/user-storage/{network-operations.js → network-operations.mjs} +7 -7
- package/dist/backup-and-sync/user-storage/network-operations.mjs.map +1 -0
- package/dist/backup-and-sync/user-storage/network-utils.cjs +33 -0
- package/dist/backup-and-sync/user-storage/network-utils.cjs.map +1 -0
- package/dist/backup-and-sync/user-storage/{network-utils.d.ts → network-utils.d.cts} +1 -1
- package/dist/backup-and-sync/user-storage/network-utils.d.cts.map +1 -0
- package/dist/backup-and-sync/user-storage/network-utils.d.mts +10 -0
- package/dist/backup-and-sync/user-storage/network-utils.d.mts.map +1 -0
- package/dist/backup-and-sync/user-storage/{network-utils.js → network-utils.mjs} +1 -1
- package/dist/backup-and-sync/user-storage/network-utils.mjs.map +1 -0
- package/dist/backup-and-sync/user-storage/validation.cjs +76 -0
- package/dist/backup-and-sync/user-storage/validation.cjs.map +1 -0
- package/dist/backup-and-sync/user-storage/{validation.d.ts → validation.d.cts} +2 -2
- package/dist/backup-and-sync/user-storage/validation.d.cts.map +1 -0
- package/dist/backup-and-sync/user-storage/validation.d.mts +23 -0
- package/dist/backup-and-sync/user-storage/validation.d.mts.map +1 -0
- package/dist/backup-and-sync/user-storage/{validation.js → validation.mjs} +3 -3
- package/dist/backup-and-sync/user-storage/validation.mjs.map +1 -0
- package/dist/backup-and-sync/utils/controller.cjs +88 -0
- package/dist/backup-and-sync/utils/controller.cjs.map +1 -0
- package/dist/backup-and-sync/utils/{controller.d.ts → controller.d.cts} +6 -6
- package/dist/backup-and-sync/utils/controller.d.cts.map +1 -0
- package/dist/backup-and-sync/utils/controller.d.mts +57 -0
- package/dist/backup-and-sync/utils/controller.d.mts.map +1 -0
- package/dist/backup-and-sync/utils/{controller.js → controller.mjs} +3 -3
- package/dist/backup-and-sync/utils/controller.mjs.map +1 -0
- package/dist/backup-and-sync/utils/errors.cjs +14 -0
- package/dist/backup-and-sync/utils/errors.cjs.map +1 -0
- package/dist/backup-and-sync/utils/{errors.d.ts → errors.d.cts} +1 -1
- package/dist/backup-and-sync/utils/errors.d.cts.map +1 -0
- package/dist/backup-and-sync/utils/errors.d.mts +8 -0
- package/dist/backup-and-sync/utils/errors.d.mts.map +1 -0
- package/dist/backup-and-sync/utils/{errors.js → errors.mjs} +1 -1
- package/dist/backup-and-sync/utils/errors.mjs.map +1 -0
- package/dist/backup-and-sync/utils/index.cjs +23 -0
- package/dist/backup-and-sync/utils/index.cjs.map +1 -0
- package/dist/backup-and-sync/utils/index.d.cts +4 -0
- package/dist/backup-and-sync/utils/index.d.cts.map +1 -0
- package/dist/backup-and-sync/utils/index.d.mts +4 -0
- package/dist/backup-and-sync/utils/index.d.mts.map +1 -0
- package/dist/backup-and-sync/utils/index.mjs +4 -0
- package/dist/backup-and-sync/utils/index.mjs.map +1 -0
- package/dist/backup-and-sync/utils/mutation-tracker.cjs +29 -0
- package/dist/backup-and-sync/utils/mutation-tracker.cjs.map +1 -0
- package/dist/backup-and-sync/utils/{mutation-tracker.d.ts → mutation-tracker.d.cts} +2 -2
- package/dist/backup-and-sync/utils/mutation-tracker.d.cts.map +1 -0
- package/dist/backup-and-sync/utils/mutation-tracker.d.mts +9 -0
- package/dist/backup-and-sync/utils/mutation-tracker.d.mts.map +1 -0
- package/dist/backup-and-sync/utils/{mutation-tracker.js → mutation-tracker.mjs} +1 -1
- package/dist/backup-and-sync/utils/mutation-tracker.mjs.map +1 -0
- package/dist/group.cjs +60 -0
- package/dist/group.cjs.map +1 -0
- package/dist/{group.d.ts → group.d.cts} +8 -8
- package/dist/group.d.cts.map +1 -0
- package/dist/group.d.mts +97 -0
- package/dist/group.d.mts.map +1 -0
- package/dist/{group.js → group.mjs} +2 -2
- package/dist/group.mjs.map +1 -0
- package/dist/index.cjs +21 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.ts → index.d.cts} +13 -13
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +7 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +7 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/{logger.d.ts → logger.d.cts} +2 -1
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +4 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/{logger.js → logger.mjs} +2 -2
- package/dist/logger.mjs.map +1 -0
- package/dist/rule.cjs +32 -0
- package/dist/rule.cjs.map +1 -0
- package/dist/{rule.d.ts → rule.d.cts} +7 -7
- package/dist/rule.d.cts.map +1 -0
- package/dist/rule.d.mts +83 -0
- package/dist/rule.d.mts.map +1 -0
- package/dist/{rule.js → rule.mjs} +1 -1
- package/dist/rule.mjs.map +1 -0
- package/dist/rules/entropy.cjs +78 -0
- package/dist/rules/entropy.cjs.map +1 -0
- package/dist/rules/{entropy.d.ts → entropy.d.cts} +7 -7
- package/dist/rules/entropy.d.cts.map +1 -0
- package/dist/rules/entropy.d.mts +16 -0
- package/dist/rules/entropy.d.mts.map +1 -0
- package/dist/rules/{entropy.js → entropy.mjs} +5 -5
- package/dist/rules/entropy.mjs.map +1 -0
- package/dist/rules/keyring.cjs +151 -0
- package/dist/rules/keyring.cjs.map +1 -0
- package/dist/rules/{keyring.d.ts → keyring.d.cts} +10 -10
- package/dist/rules/keyring.d.cts.map +1 -0
- package/dist/rules/keyring.d.mts +32 -0
- package/dist/rules/keyring.d.mts.map +1 -0
- package/dist/rules/{keyring.js → keyring.mjs} +7 -7
- package/dist/rules/keyring.mjs.map +1 -0
- package/dist/rules/snap.cjs +80 -0
- package/dist/rules/snap.cjs.map +1 -0
- package/dist/rules/{snap.d.ts → snap.d.cts} +6 -6
- package/dist/rules/snap.d.cts.map +1 -0
- package/dist/rules/snap.d.mts +14 -0
- package/dist/rules/snap.d.mts.map +1 -0
- package/dist/rules/{snap.js → snap.mjs} +8 -8
- package/dist/rules/snap.mjs.map +1 -0
- package/dist/state/export.cjs +230 -0
- package/dist/state/export.cjs.map +1 -0
- package/dist/state/{export.d.ts → export.d.cts} +6 -6
- package/dist/state/export.d.cts.map +1 -0
- package/dist/state/export.d.mts +40 -0
- package/dist/state/export.d.mts.map +1 -0
- package/dist/state/{export.js → export.mjs} +9 -8
- package/dist/state/export.mjs.map +1 -0
- package/dist/state/id-map.cjs +65 -0
- package/dist/state/id-map.cjs.map +1 -0
- package/dist/state/{id-map.d.ts → id-map.d.cts} +3 -3
- package/dist/state/id-map.d.cts.map +1 -0
- package/dist/state/id-map.d.mts +41 -0
- package/dist/state/id-map.d.mts.map +1 -0
- package/dist/state/{id-map.js → id-map.mjs} +2 -2
- package/dist/state/id-map.mjs.map +1 -0
- package/dist/state/import.cjs +285 -0
- package/dist/state/import.cjs.map +1 -0
- package/dist/state/{import.d.ts → import.d.cts} +4 -4
- package/dist/state/import.d.cts.map +1 -0
- package/dist/state/import.d.mts +29 -0
- package/dist/state/import.d.mts.map +1 -0
- package/dist/state/{import.js → import.mjs} +9 -8
- package/dist/state/import.mjs.map +1 -0
- package/dist/state/payload.cjs +169 -0
- package/dist/state/payload.cjs.map +1 -0
- package/dist/state/{payload.d.ts → payload.d.cts} +31 -31
- package/dist/state/payload.d.cts.map +1 -0
- package/dist/state/payload.d.mts +294 -0
- package/dist/state/payload.d.mts.map +1 -0
- package/dist/state/{payload.js → payload.mjs} +4 -4
- package/dist/state/payload.mjs.map +1 -0
- package/dist/state/snapshot.cjs +202 -0
- package/dist/state/snapshot.cjs.map +1 -0
- package/dist/state/{snapshot.d.ts → snapshot.d.cts} +3 -3
- package/dist/state/snapshot.d.cts.map +1 -0
- package/dist/state/snapshot.d.mts +120 -0
- package/dist/state/snapshot.d.mts.map +1 -0
- package/dist/state/{snapshot.js → snapshot.mjs} +3 -3
- package/dist/state/snapshot.mjs.map +1 -0
- package/dist/state/utils.cjs +68 -0
- package/dist/state/utils.cjs.map +1 -0
- package/dist/state/{utils.d.ts → utils.d.cts} +3 -3
- package/dist/state/utils.d.cts.map +1 -0
- package/dist/state/utils.d.mts +49 -0
- package/dist/state/utils.d.mts.map +1 -0
- package/dist/state/{utils.js → utils.mjs} +2 -2
- package/dist/state/utils.mjs.map +1 -0
- package/dist/type-utils.cjs +3 -0
- package/dist/type-utils.cjs.map +1 -0
- package/dist/{type-utils.d.ts → type-utils.d.cts} +1 -1
- package/dist/type-utils.d.cts.map +1 -0
- package/dist/type-utils.d.mts +18 -0
- package/dist/type-utils.d.mts.map +1 -0
- package/dist/type-utils.mjs +2 -0
- package/dist/type-utils.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +16 -16
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +120 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/dist/wallet.cjs +3 -0
- package/dist/wallet.cjs.map +1 -0
- package/dist/{wallet.d.ts → wallet.d.cts} +9 -9
- package/dist/wallet.d.cts.map +1 -0
- package/dist/wallet.d.mts +99 -0
- package/dist/wallet.d.mts.map +1 -0
- package/dist/wallet.mjs +2 -0
- package/dist/wallet.mjs.map +1 -0
- package/package.json +17 -13
- package/dist/AccountTreeController-method-action-types.d.ts.map +0 -1
- package/dist/AccountTreeController-method-action-types.js.map +0 -1
- package/dist/AccountTreeController.d.ts.map +0 -1
- package/dist/AccountTreeController.js.map +0 -1
- package/dist/backup-and-sync/analytics/index.d.ts +0 -3
- package/dist/backup-and-sync/analytics/index.d.ts.map +0 -1
- package/dist/backup-and-sync/analytics/index.js +0 -3
- package/dist/backup-and-sync/analytics/index.js.map +0 -1
- package/dist/backup-and-sync/analytics/segment.d.ts.map +0 -1
- package/dist/backup-and-sync/analytics/segment.js.map +0 -1
- package/dist/backup-and-sync/analytics/traces.d.ts.map +0 -1
- package/dist/backup-and-sync/analytics/traces.js.map +0 -1
- package/dist/backup-and-sync/authentication/index.d.ts +0 -2
- package/dist/backup-and-sync/authentication/index.d.ts.map +0 -1
- package/dist/backup-and-sync/authentication/index.js +0 -2
- package/dist/backup-and-sync/authentication/index.js.map +0 -1
- package/dist/backup-and-sync/authentication/utils.d.ts.map +0 -1
- package/dist/backup-and-sync/authentication/utils.js.map +0 -1
- package/dist/backup-and-sync/service/atomic-sync-queue.d.ts.map +0 -1
- package/dist/backup-and-sync/service/atomic-sync-queue.js.map +0 -1
- package/dist/backup-and-sync/service/index.d.ts.map +0 -1
- package/dist/backup-and-sync/service/index.js.map +0 -1
- package/dist/backup-and-sync/syncing/group.d.ts.map +0 -1
- package/dist/backup-and-sync/syncing/group.js.map +0 -1
- package/dist/backup-and-sync/syncing/index.d.ts +0 -5
- package/dist/backup-and-sync/syncing/index.d.ts.map +0 -1
- package/dist/backup-and-sync/syncing/index.js +0 -5
- package/dist/backup-and-sync/syncing/index.js.map +0 -1
- package/dist/backup-and-sync/syncing/legacy.d.ts.map +0 -1
- package/dist/backup-and-sync/syncing/legacy.js.map +0 -1
- package/dist/backup-and-sync/syncing/metadata.d.ts.map +0 -1
- package/dist/backup-and-sync/syncing/metadata.js.map +0 -1
- package/dist/backup-and-sync/syncing/wallet.d.ts.map +0 -1
- package/dist/backup-and-sync/syncing/wallet.js.map +0 -1
- package/dist/backup-and-sync/types.d.ts.map +0 -1
- package/dist/backup-and-sync/types.js.map +0 -1
- package/dist/backup-and-sync/user-storage/constants.d.ts.map +0 -1
- package/dist/backup-and-sync/user-storage/constants.js.map +0 -1
- package/dist/backup-and-sync/user-storage/format-utils.d.ts.map +0 -1
- package/dist/backup-and-sync/user-storage/format-utils.js.map +0 -1
- package/dist/backup-and-sync/user-storage/index.d.ts +0 -5
- package/dist/backup-and-sync/user-storage/index.d.ts.map +0 -1
- package/dist/backup-and-sync/user-storage/index.js +0 -5
- package/dist/backup-and-sync/user-storage/index.js.map +0 -1
- package/dist/backup-and-sync/user-storage/network-operations.d.ts.map +0 -1
- package/dist/backup-and-sync/user-storage/network-operations.js.map +0 -1
- package/dist/backup-and-sync/user-storage/network-utils.d.ts.map +0 -1
- package/dist/backup-and-sync/user-storage/network-utils.js.map +0 -1
- package/dist/backup-and-sync/user-storage/validation.d.ts.map +0 -1
- package/dist/backup-and-sync/user-storage/validation.js.map +0 -1
- package/dist/backup-and-sync/utils/controller.d.ts.map +0 -1
- package/dist/backup-and-sync/utils/controller.js.map +0 -1
- package/dist/backup-and-sync/utils/errors.d.ts.map +0 -1
- package/dist/backup-and-sync/utils/errors.js.map +0 -1
- package/dist/backup-and-sync/utils/index.d.ts +0 -4
- package/dist/backup-and-sync/utils/index.d.ts.map +0 -1
- package/dist/backup-and-sync/utils/index.js +0 -4
- package/dist/backup-and-sync/utils/index.js.map +0 -1
- package/dist/backup-and-sync/utils/mutation-tracker.d.ts.map +0 -1
- package/dist/backup-and-sync/utils/mutation-tracker.js.map +0 -1
- package/dist/group.d.ts.map +0 -1
- package/dist/group.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -7
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/rule.d.ts.map +0 -1
- package/dist/rule.js.map +0 -1
- package/dist/rules/entropy.d.ts.map +0 -1
- package/dist/rules/entropy.js.map +0 -1
- package/dist/rules/keyring.d.ts.map +0 -1
- package/dist/rules/keyring.js.map +0 -1
- package/dist/rules/snap.d.ts.map +0 -1
- package/dist/rules/snap.js.map +0 -1
- package/dist/state/export.d.ts.map +0 -1
- package/dist/state/export.js.map +0 -1
- package/dist/state/id-map.d.ts.map +0 -1
- package/dist/state/id-map.js.map +0 -1
- package/dist/state/import.d.ts.map +0 -1
- package/dist/state/import.js.map +0 -1
- package/dist/state/payload.d.ts.map +0 -1
- package/dist/state/payload.js.map +0 -1
- package/dist/state/snapshot.d.ts.map +0 -1
- package/dist/state/snapshot.js.map +0 -1
- package/dist/state/utils.d.ts.map +0 -1
- package/dist/state/utils.js.map +0 -1
- package/dist/type-utils.d.ts.map +0 -1
- package/dist/type-utils.js +0 -2
- package/dist/type-utils.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -2
- package/dist/wallet.js.map +0 -1
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _AccountTreeSnapshot_entries, _AccountTreeSnapshot_idMap;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AccountTreeSnapshot = void 0;
|
|
16
|
+
const payload_js_1 = require("./payload.cjs");
|
|
17
|
+
const utils_js_1 = require("./utils.cjs");
|
|
18
|
+
/**
|
|
19
|
+
* Immutable value object returned by {@link AccountTreeController.exportState}.
|
|
20
|
+
*
|
|
21
|
+
* Construct with {@link AccountTreeController.exportState},
|
|
22
|
+
* {@link AccountTreeSnapshot.deserialize}, or `new AccountTreeSnapshot(...)`
|
|
23
|
+
* for tests and advanced use.
|
|
24
|
+
*
|
|
25
|
+
* Wallet and group entries are deep-cloned and deep-frozen once in the
|
|
26
|
+
* constructor. Filtering predicates receive those read-only views directly;
|
|
27
|
+
* each filter method returns a new snapshot that repeats the process for its
|
|
28
|
+
* result.
|
|
29
|
+
*
|
|
30
|
+
* An optional ID map (local ↔ payload) may be supplied when bridging between
|
|
31
|
+
* internal controller IDs and the stable cross-device IDs in the serialized
|
|
32
|
+
* payload. The map covers the original export and is preserved unchanged
|
|
33
|
+
* through filtering until {@link serialize}. Omit it when deterministic IDs
|
|
34
|
+
* make {@link toLocalId} / {@link toPayloadId} unnecessary.
|
|
35
|
+
*/
|
|
36
|
+
class AccountTreeSnapshot {
|
|
37
|
+
/**
|
|
38
|
+
* @param entries - Wallet entries in the snapshot.
|
|
39
|
+
* @param idMap - Optional local ↔ payload ID map from export.
|
|
40
|
+
*/
|
|
41
|
+
constructor(entries, idMap) {
|
|
42
|
+
_AccountTreeSnapshot_entries.set(this, void 0);
|
|
43
|
+
_AccountTreeSnapshot_idMap.set(this, void 0);
|
|
44
|
+
__classPrivateFieldSet(this, _AccountTreeSnapshot_entries, (0, utils_js_1.deepFreeze)(structuredClone(entries)), "f");
|
|
45
|
+
__classPrivateFieldSet(this, _AccountTreeSnapshot_idMap, idMap, "f");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns a new snapshot containing only the wallets for which
|
|
49
|
+
* `predicate` returns `true`.
|
|
50
|
+
*
|
|
51
|
+
* When filtering by wallet ID, compare against stable payload IDs from
|
|
52
|
+
* {@link serialize} or convert local IDs with {@link toPayloadId} first.
|
|
53
|
+
*
|
|
54
|
+
* @param predicate - Function called with each deeply read-only wallet entry.
|
|
55
|
+
* @returns A filtered snapshot.
|
|
56
|
+
*/
|
|
57
|
+
filterWallets(predicate) {
|
|
58
|
+
const filteredEntries = __classPrivateFieldGet(this, _AccountTreeSnapshot_entries, "f").filter((entry) => predicate(entry));
|
|
59
|
+
return new AccountTreeSnapshot(filteredEntries, __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f"));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Filters groups within one wallet. Other wallets are left unchanged.
|
|
63
|
+
*
|
|
64
|
+
* Throws if `walletId` does not identify a wallet in the snapshot.
|
|
65
|
+
* Removes the wallet if no groups remain after filtering — this prevents a
|
|
66
|
+
* mnemonic wallet with zero selected groups from still transferring its secret.
|
|
67
|
+
*
|
|
68
|
+
* **Mnemonic wallets:** group indices must remain contiguous starting at 0
|
|
69
|
+
* after filtering, because the payload schema enforces this invariant.
|
|
70
|
+
* Predicates that produce gaps (e.g. keeping only index 1, or 0 and 2) will
|
|
71
|
+
* cause {@link AccountTreeSnapshot.deserialize} to reject the payload on the
|
|
72
|
+
* receiving end.
|
|
73
|
+
*
|
|
74
|
+
* @param walletId - Stable payload wallet ID to filter groups within.
|
|
75
|
+
* @param predicate - Function called with each deeply read-only group entry.
|
|
76
|
+
* @returns A filtered snapshot.
|
|
77
|
+
* @throws If `walletId` is not present in the snapshot.
|
|
78
|
+
*/
|
|
79
|
+
filterGroups(walletId, predicate) {
|
|
80
|
+
const walletIndex = __classPrivateFieldGet(this, _AccountTreeSnapshot_entries, "f").findIndex((entry) => entry.id === walletId);
|
|
81
|
+
if (walletIndex === -1) {
|
|
82
|
+
throw new Error(`Cannot filter groups: wallet "${walletId}" not found in snapshot`);
|
|
83
|
+
}
|
|
84
|
+
const wallet = __classPrivateFieldGet(this, _AccountTreeSnapshot_entries, "f")[walletIndex];
|
|
85
|
+
const filteredGroups = wallet.groups.filter((group) => predicate(group));
|
|
86
|
+
const filteredEntries = [...__classPrivateFieldGet(this, _AccountTreeSnapshot_entries, "f")];
|
|
87
|
+
if (filteredGroups.length === 0) {
|
|
88
|
+
filteredEntries.splice(walletIndex, 1);
|
|
89
|
+
}
|
|
90
|
+
else if (wallet.type === payload_js_1.AccountWalletPayloadType.Mnemonic) {
|
|
91
|
+
filteredEntries[walletIndex] = {
|
|
92
|
+
...wallet,
|
|
93
|
+
groups: filteredGroups,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
filteredEntries[walletIndex] = {
|
|
98
|
+
...wallet,
|
|
99
|
+
groups: filteredGroups,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return new AccountTreeSnapshot(filteredEntries, __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f"));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Filters groups across every wallet.
|
|
106
|
+
*
|
|
107
|
+
* The parent wallet is provided as context to the predicate. Removes any
|
|
108
|
+
* wallet with no remaining groups after filtering.
|
|
109
|
+
*
|
|
110
|
+
* **Mnemonic wallets:** see {@link filterGroups} for the contiguous-index
|
|
111
|
+
* constraint that applies here as well.
|
|
112
|
+
*
|
|
113
|
+
* @param predicate - Function called with each group and its parent wallet.
|
|
114
|
+
* @returns A filtered snapshot.
|
|
115
|
+
*/
|
|
116
|
+
filterAllGroups(predicate) {
|
|
117
|
+
const filteredEntries = [];
|
|
118
|
+
for (const wallet of __classPrivateFieldGet(this, _AccountTreeSnapshot_entries, "f")) {
|
|
119
|
+
const filteredGroups = wallet.groups.filter((group) => predicate(group, wallet));
|
|
120
|
+
if (filteredGroups.length === 0) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (wallet.type === payload_js_1.AccountWalletPayloadType.Mnemonic) {
|
|
124
|
+
filteredEntries.push({
|
|
125
|
+
...wallet,
|
|
126
|
+
groups: filteredGroups,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
filteredEntries.push({
|
|
131
|
+
...wallet,
|
|
132
|
+
groups: filteredGroups,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return new AccountTreeSnapshot(filteredEntries, __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f"));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Converts a payload ID (wallet or group) to the corresponding local
|
|
140
|
+
* `AccountTreeController` ID.
|
|
141
|
+
*
|
|
142
|
+
* The map reflects the original export, not the wallets/groups currently
|
|
143
|
+
* retained in this snapshot after filtering.
|
|
144
|
+
*
|
|
145
|
+
* @param payloadId - Stable cross-device wallet or group payload ID.
|
|
146
|
+
* @returns The local controller ID, or `undefined` if not found or no ID map is present.
|
|
147
|
+
*/
|
|
148
|
+
toLocalId(payloadId) {
|
|
149
|
+
return __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f")?.getLocalId(payloadId);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Converts a local `AccountTreeController` ID (wallet or group) to its
|
|
153
|
+
* stable cross-device payload ID.
|
|
154
|
+
*
|
|
155
|
+
* The map reflects the original export, not the wallets/groups currently
|
|
156
|
+
* retained in this snapshot after filtering.
|
|
157
|
+
*
|
|
158
|
+
* @param localId - Local controller wallet or group ID.
|
|
159
|
+
* @returns The payload ID, or `undefined` if not found or no ID map is present.
|
|
160
|
+
*/
|
|
161
|
+
toPayloadId(localId) {
|
|
162
|
+
return __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f")?.getPayloadId(localId);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Serializes the snapshot to a flat {@link AccountTreePayload} with `version` inlined
|
|
166
|
+
* alongside the wallet entries.
|
|
167
|
+
*
|
|
168
|
+
* Returns the constructor-frozen wallet tree without copying it again.
|
|
169
|
+
*
|
|
170
|
+
* @returns The versioned flat payload.
|
|
171
|
+
*/
|
|
172
|
+
serialize() {
|
|
173
|
+
return {
|
|
174
|
+
version: payload_js_1.ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION,
|
|
175
|
+
wallets: __classPrivateFieldGet(this, _AccountTreeSnapshot_entries, "f"),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Validates a raw value as an {@link AccountTreePayload}, running any
|
|
180
|
+
* necessary version migrations, and returns an immutable snapshot.
|
|
181
|
+
*
|
|
182
|
+
* This is the entry point for untrusted serialized data. Unsupported schema
|
|
183
|
+
* versions and wallet types fail closed with an error instead of returning a
|
|
184
|
+
* partial snapshot.
|
|
185
|
+
*
|
|
186
|
+
* The returned snapshot has no ID map — {@link toLocalId} / {@link toPayloadId}
|
|
187
|
+
* return `undefined`. Pass an {@link IdMap} to the constructor when you need
|
|
188
|
+
* the map.
|
|
189
|
+
*
|
|
190
|
+
* @param raw - Unknown value to parse.
|
|
191
|
+
* @returns A validated snapshot.
|
|
192
|
+
* @throws If `raw` is not a valid payload or its version is unsupported.
|
|
193
|
+
*/
|
|
194
|
+
static async deserialize(raw) {
|
|
195
|
+
// TODO: Use migration framework here.
|
|
196
|
+
(0, payload_js_1.assertAccountTreePayload)(raw);
|
|
197
|
+
return new AccountTreeSnapshot(raw.wallets);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.AccountTreeSnapshot = AccountTreeSnapshot;
|
|
201
|
+
_AccountTreeSnapshot_entries = new WeakMap(), _AccountTreeSnapshot_idMap = new WeakMap();
|
|
202
|
+
//# sourceMappingURL=snapshot.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.cjs","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAWA,8CAIsB;AACtB,0CAAwC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,mBAAmB;IAK9B;;;OAGG;IACH,YAAY,OAAiC,EAAE,KAAa;QARnD,+CAAmC;QAEnC,6CAA0B;QAOjC,uBAAA,IAAI,gCAAY,IAAA,qBAAU,EAAC,eAAe,CAAC,OAAO,CAAC,CAAC,MAAA,CAAC;QACrD,uBAAA,IAAI,8BAAU,KAAK,MAAA,CAAC;IACtB,CAAC;IAED;;;;;;;;;OASG;IACH,aAAa,CACX,SAAyD;QAEzD,MAAM,eAAe,GAAG,uBAAA,IAAI,oCAAS,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CACrD,SAA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AAA,qCAAwB,EAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,IAAI,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF;AA7MD,kDA6MC","sourcesContent":["import type { IdMap } from './id-map.js';\nimport type {\n AccountGroupPayloadId,\n AccountTreePayload,\n AccountTreeSnapshotGroup,\n AccountTreeSnapshotWallet,\n AccountTreeWalletEntry,\n AccountWalletMnemonicGroupEntry,\n AccountWalletPayloadId,\n AccountWalletPrivateKeyGroupEntry,\n} from './payload.js';\nimport {\n AccountWalletPayloadType,\n assertAccountTreePayload,\n ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION,\n} from './payload.js';\nimport { deepFreeze } from './utils.js';\n\n/**\n * Immutable value object returned by {@link AccountTreeController.exportState}.\n *\n * Construct with {@link AccountTreeController.exportState},\n * {@link AccountTreeSnapshot.deserialize}, or `new AccountTreeSnapshot(...)`\n * for tests and advanced use.\n *\n * Wallet and group entries are deep-cloned and deep-frozen once in the\n * constructor. Filtering predicates receive those read-only views directly;\n * each filter method returns a new snapshot that repeats the process for its\n * result.\n *\n * An optional ID map (local ↔ payload) may be supplied when bridging between\n * internal controller IDs and the stable cross-device IDs in the serialized\n * payload. The map covers the original export and is preserved unchanged\n * through filtering until {@link serialize}. Omit it when deterministic IDs\n * make {@link toLocalId} / {@link toPayloadId} unnecessary.\n */\nexport class AccountTreeSnapshot {\n readonly #entries: AccountTreeWalletEntry[];\n\n readonly #idMap: IdMap | undefined;\n\n /**\n * @param entries - Wallet entries in the snapshot.\n * @param idMap - Optional local ↔ payload ID map from export.\n */\n constructor(entries: AccountTreeWalletEntry[], idMap?: IdMap) {\n this.#entries = deepFreeze(structuredClone(entries));\n this.#idMap = idMap;\n }\n\n /**\n * Returns a new snapshot containing only the wallets for which\n * `predicate` returns `true`.\n *\n * When filtering by wallet ID, compare against stable payload IDs from\n * {@link serialize} or convert local IDs with {@link toPayloadId} first.\n *\n * @param predicate - Function called with each deeply read-only wallet entry.\n * @returns A filtered snapshot.\n */\n filterWallets(\n predicate: (wallet: AccountTreeSnapshotWallet) => boolean,\n ): AccountTreeSnapshot {\n const filteredEntries = this.#entries.filter((entry) =>\n predicate(entry as AccountTreeSnapshotWallet),\n );\n\n return new AccountTreeSnapshot(filteredEntries, this.#idMap);\n }\n\n /**\n * Filters groups within one wallet. Other wallets are left unchanged.\n *\n * Throws if `walletId` does not identify a wallet in the snapshot.\n * Removes the wallet if no groups remain after filtering — this prevents a\n * mnemonic wallet with zero selected groups from still transferring its secret.\n *\n * **Mnemonic wallets:** group indices must remain contiguous starting at 0\n * after filtering, because the payload schema enforces this invariant.\n * Predicates that produce gaps (e.g. keeping only index 1, or 0 and 2) will\n * cause {@link AccountTreeSnapshot.deserialize} to reject the payload on the\n * receiving end.\n *\n * @param walletId - Stable payload wallet ID to filter groups within.\n * @param predicate - Function called with each deeply read-only group entry.\n * @returns A filtered snapshot.\n * @throws If `walletId` is not present in the snapshot.\n */\n filterGroups(\n walletId: AccountWalletPayloadId,\n predicate: (group: AccountTreeSnapshotGroup) => boolean,\n ): AccountTreeSnapshot {\n const walletIndex = this.#entries.findIndex(\n (entry) => entry.id === walletId,\n );\n if (walletIndex === -1) {\n throw new Error(\n `Cannot filter groups: wallet \"${walletId}\" not found in snapshot`,\n );\n }\n\n const wallet = this.#entries[walletIndex];\n\n const filteredGroups = wallet.groups.filter((group) =>\n predicate(group as AccountTreeSnapshotGroup),\n );\n\n const filteredEntries = [...this.#entries];\n if (filteredGroups.length === 0) {\n filteredEntries.splice(walletIndex, 1);\n } else if (wallet.type === AccountWalletPayloadType.Mnemonic) {\n filteredEntries[walletIndex] = {\n ...wallet,\n groups: filteredGroups as AccountWalletMnemonicGroupEntry[],\n };\n } else {\n filteredEntries[walletIndex] = {\n ...wallet,\n groups: filteredGroups as AccountWalletPrivateKeyGroupEntry[],\n };\n }\n\n return new AccountTreeSnapshot(filteredEntries, this.#idMap);\n }\n\n /**\n * Filters groups across every wallet.\n *\n * The parent wallet is provided as context to the predicate. Removes any\n * wallet with no remaining groups after filtering.\n *\n * **Mnemonic wallets:** see {@link filterGroups} for the contiguous-index\n * constraint that applies here as well.\n *\n * @param predicate - Function called with each group and its parent wallet.\n * @returns A filtered snapshot.\n */\n filterAllGroups(\n predicate: (\n group: AccountTreeSnapshotGroup,\n wallet: AccountTreeSnapshotWallet,\n ) => boolean,\n ): AccountTreeSnapshot {\n const filteredEntries: AccountTreeWalletEntry[] = [];\n\n for (const wallet of this.#entries) {\n const filteredGroups = wallet.groups.filter((group) =>\n predicate(\n group as AccountTreeSnapshotGroup,\n wallet as AccountTreeSnapshotWallet,\n ),\n );\n\n if (filteredGroups.length === 0) {\n continue;\n }\n\n if (wallet.type === AccountWalletPayloadType.Mnemonic) {\n filteredEntries.push({\n ...wallet,\n groups: filteredGroups as AccountWalletMnemonicGroupEntry[],\n });\n } else {\n filteredEntries.push({\n ...wallet,\n groups: filteredGroups as AccountWalletPrivateKeyGroupEntry[],\n });\n }\n }\n\n return new AccountTreeSnapshot(filteredEntries, this.#idMap);\n }\n\n /**\n * Converts a payload ID (wallet or group) to the corresponding local\n * `AccountTreeController` ID.\n *\n * The map reflects the original export, not the wallets/groups currently\n * retained in this snapshot after filtering.\n *\n * @param payloadId - Stable cross-device wallet or group payload ID.\n * @returns The local controller ID, or `undefined` if not found or no ID map is present.\n */\n toLocalId(\n payloadId: AccountWalletPayloadId | AccountGroupPayloadId,\n ): ReturnType<IdMap['getLocalId']> {\n return this.#idMap?.getLocalId(payloadId);\n }\n\n /**\n * Converts a local `AccountTreeController` ID (wallet or group) to its\n * stable cross-device payload ID.\n *\n * The map reflects the original export, not the wallets/groups currently\n * retained in this snapshot after filtering.\n *\n * @param localId - Local controller wallet or group ID.\n * @returns The payload ID, or `undefined` if not found or no ID map is present.\n */\n toPayloadId(\n localId: Parameters<IdMap['add']>[0],\n ): ReturnType<IdMap['getPayloadId']> {\n return this.#idMap?.getPayloadId(localId);\n }\n\n /**\n * Serializes the snapshot to a flat {@link AccountTreePayload} with `version` inlined\n * alongside the wallet entries.\n *\n * Returns the constructor-frozen wallet tree without copying it again.\n *\n * @returns The versioned flat payload.\n */\n serialize(): AccountTreePayload {\n return {\n version: ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION,\n wallets: this.#entries,\n };\n }\n\n /**\n * Validates a raw value as an {@link AccountTreePayload}, running any\n * necessary version migrations, and returns an immutable snapshot.\n *\n * This is the entry point for untrusted serialized data. Unsupported schema\n * versions and wallet types fail closed with an error instead of returning a\n * partial snapshot.\n *\n * The returned snapshot has no ID map — {@link toLocalId} / {@link toPayloadId}\n * return `undefined`. Pass an {@link IdMap} to the constructor when you need\n * the map.\n *\n * @param raw - Unknown value to parse.\n * @returns A validated snapshot.\n * @throws If `raw` is not a valid payload or its version is unsupported.\n */\n static async deserialize(raw: unknown): Promise<AccountTreeSnapshot> {\n // TODO: Use migration framework here.\n assertAccountTreePayload(raw);\n return new AccountTreeSnapshot(raw.wallets);\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IdMap } from
|
|
2
|
-
import type { AccountGroupPayloadId, AccountTreePayload, AccountTreeSnapshotGroup, AccountTreeSnapshotWallet, AccountTreeWalletEntry, AccountWalletPayloadId } from
|
|
1
|
+
import type { IdMap } from "./id-map.cjs";
|
|
2
|
+
import type { AccountGroupPayloadId, AccountTreePayload, AccountTreeSnapshotGroup, AccountTreeSnapshotWallet, AccountTreeWalletEntry, AccountWalletPayloadId } from "./payload.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Immutable value object returned by {@link AccountTreeController.exportState}.
|
|
5
5
|
*
|
|
@@ -117,4 +117,4 @@ export declare class AccountTreeSnapshot {
|
|
|
117
117
|
*/
|
|
118
118
|
static deserialize(raw: unknown): Promise<AccountTreeSnapshot>;
|
|
119
119
|
}
|
|
120
|
-
//# sourceMappingURL=snapshot.d.
|
|
120
|
+
//# sourceMappingURL=snapshot.d.cts.map
|
|
@@ -0,0 +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
|
+
import type { IdMap } from "./id-map.mjs";
|
|
2
|
+
import type { AccountGroupPayloadId, AccountTreePayload, AccountTreeSnapshotGroup, AccountTreeSnapshotWallet, AccountTreeWalletEntry, AccountWalletPayloadId } from "./payload.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Immutable value object returned by {@link AccountTreeController.exportState}.
|
|
5
|
+
*
|
|
6
|
+
* Construct with {@link AccountTreeController.exportState},
|
|
7
|
+
* {@link AccountTreeSnapshot.deserialize}, or `new AccountTreeSnapshot(...)`
|
|
8
|
+
* for tests and advanced use.
|
|
9
|
+
*
|
|
10
|
+
* Wallet and group entries are deep-cloned and deep-frozen once in the
|
|
11
|
+
* constructor. Filtering predicates receive those read-only views directly;
|
|
12
|
+
* each filter method returns a new snapshot that repeats the process for its
|
|
13
|
+
* result.
|
|
14
|
+
*
|
|
15
|
+
* An optional ID map (local ↔ payload) may be supplied when bridging between
|
|
16
|
+
* internal controller IDs and the stable cross-device IDs in the serialized
|
|
17
|
+
* payload. The map covers the original export and is preserved unchanged
|
|
18
|
+
* through filtering until {@link serialize}. Omit it when deterministic IDs
|
|
19
|
+
* make {@link toLocalId} / {@link toPayloadId} unnecessary.
|
|
20
|
+
*/
|
|
21
|
+
export declare class AccountTreeSnapshot {
|
|
22
|
+
#private;
|
|
23
|
+
/**
|
|
24
|
+
* @param entries - Wallet entries in the snapshot.
|
|
25
|
+
* @param idMap - Optional local ↔ payload ID map from export.
|
|
26
|
+
*/
|
|
27
|
+
constructor(entries: AccountTreeWalletEntry[], idMap?: IdMap);
|
|
28
|
+
/**
|
|
29
|
+
* Returns a new snapshot containing only the wallets for which
|
|
30
|
+
* `predicate` returns `true`.
|
|
31
|
+
*
|
|
32
|
+
* When filtering by wallet ID, compare against stable payload IDs from
|
|
33
|
+
* {@link serialize} or convert local IDs with {@link toPayloadId} first.
|
|
34
|
+
*
|
|
35
|
+
* @param predicate - Function called with each deeply read-only wallet entry.
|
|
36
|
+
* @returns A filtered snapshot.
|
|
37
|
+
*/
|
|
38
|
+
filterWallets(predicate: (wallet: AccountTreeSnapshotWallet) => boolean): AccountTreeSnapshot;
|
|
39
|
+
/**
|
|
40
|
+
* Filters groups within one wallet. Other wallets are left unchanged.
|
|
41
|
+
*
|
|
42
|
+
* Throws if `walletId` does not identify a wallet in the snapshot.
|
|
43
|
+
* Removes the wallet if no groups remain after filtering — this prevents a
|
|
44
|
+
* mnemonic wallet with zero selected groups from still transferring its secret.
|
|
45
|
+
*
|
|
46
|
+
* **Mnemonic wallets:** group indices must remain contiguous starting at 0
|
|
47
|
+
* after filtering, because the payload schema enforces this invariant.
|
|
48
|
+
* Predicates that produce gaps (e.g. keeping only index 1, or 0 and 2) will
|
|
49
|
+
* cause {@link AccountTreeSnapshot.deserialize} to reject the payload on the
|
|
50
|
+
* receiving end.
|
|
51
|
+
*
|
|
52
|
+
* @param walletId - Stable payload wallet ID to filter groups within.
|
|
53
|
+
* @param predicate - Function called with each deeply read-only group entry.
|
|
54
|
+
* @returns A filtered snapshot.
|
|
55
|
+
* @throws If `walletId` is not present in the snapshot.
|
|
56
|
+
*/
|
|
57
|
+
filterGroups(walletId: AccountWalletPayloadId, predicate: (group: AccountTreeSnapshotGroup) => boolean): AccountTreeSnapshot;
|
|
58
|
+
/**
|
|
59
|
+
* Filters groups across every wallet.
|
|
60
|
+
*
|
|
61
|
+
* The parent wallet is provided as context to the predicate. Removes any
|
|
62
|
+
* wallet with no remaining groups after filtering.
|
|
63
|
+
*
|
|
64
|
+
* **Mnemonic wallets:** see {@link filterGroups} for the contiguous-index
|
|
65
|
+
* constraint that applies here as well.
|
|
66
|
+
*
|
|
67
|
+
* @param predicate - Function called with each group and its parent wallet.
|
|
68
|
+
* @returns A filtered snapshot.
|
|
69
|
+
*/
|
|
70
|
+
filterAllGroups(predicate: (group: AccountTreeSnapshotGroup, wallet: AccountTreeSnapshotWallet) => boolean): AccountTreeSnapshot;
|
|
71
|
+
/**
|
|
72
|
+
* Converts a payload ID (wallet or group) to the corresponding local
|
|
73
|
+
* `AccountTreeController` ID.
|
|
74
|
+
*
|
|
75
|
+
* The map reflects the original export, not the wallets/groups currently
|
|
76
|
+
* retained in this snapshot after filtering.
|
|
77
|
+
*
|
|
78
|
+
* @param payloadId - Stable cross-device wallet or group payload ID.
|
|
79
|
+
* @returns The local controller ID, or `undefined` if not found or no ID map is present.
|
|
80
|
+
*/
|
|
81
|
+
toLocalId(payloadId: AccountWalletPayloadId | AccountGroupPayloadId): ReturnType<IdMap['getLocalId']>;
|
|
82
|
+
/**
|
|
83
|
+
* Converts a local `AccountTreeController` ID (wallet or group) to its
|
|
84
|
+
* stable cross-device payload ID.
|
|
85
|
+
*
|
|
86
|
+
* The map reflects the original export, not the wallets/groups currently
|
|
87
|
+
* retained in this snapshot after filtering.
|
|
88
|
+
*
|
|
89
|
+
* @param localId - Local controller wallet or group ID.
|
|
90
|
+
* @returns The payload ID, or `undefined` if not found or no ID map is present.
|
|
91
|
+
*/
|
|
92
|
+
toPayloadId(localId: Parameters<IdMap['add']>[0]): ReturnType<IdMap['getPayloadId']>;
|
|
93
|
+
/**
|
|
94
|
+
* Serializes the snapshot to a flat {@link AccountTreePayload} with `version` inlined
|
|
95
|
+
* alongside the wallet entries.
|
|
96
|
+
*
|
|
97
|
+
* Returns the constructor-frozen wallet tree without copying it again.
|
|
98
|
+
*
|
|
99
|
+
* @returns The versioned flat payload.
|
|
100
|
+
*/
|
|
101
|
+
serialize(): AccountTreePayload;
|
|
102
|
+
/**
|
|
103
|
+
* Validates a raw value as an {@link AccountTreePayload}, running any
|
|
104
|
+
* necessary version migrations, and returns an immutable snapshot.
|
|
105
|
+
*
|
|
106
|
+
* This is the entry point for untrusted serialized data. Unsupported schema
|
|
107
|
+
* versions and wallet types fail closed with an error instead of returning a
|
|
108
|
+
* partial snapshot.
|
|
109
|
+
*
|
|
110
|
+
* The returned snapshot has no ID map — {@link toLocalId} / {@link toPayloadId}
|
|
111
|
+
* return `undefined`. Pass an {@link IdMap} to the constructor when you need
|
|
112
|
+
* the map.
|
|
113
|
+
*
|
|
114
|
+
* @param raw - Unknown value to parse.
|
|
115
|
+
* @returns A validated snapshot.
|
|
116
|
+
* @throws If `raw` is not a valid payload or its version is unsupported.
|
|
117
|
+
*/
|
|
118
|
+
static deserialize(raw: unknown): Promise<AccountTreeSnapshot>;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=snapshot.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.mts","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,qBAAoB;AACzC,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EAEtB,sBAAsB,EAEvB,sBAAqB;AAQtB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,mBAAmB;;IAK9B;;;OAGG;gBACS,OAAO,EAAE,sBAAsB,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK;IAK5D;;;;;;;;;OASG;IACH,aAAa,CACX,SAAS,EAAE,CAAC,MAAM,EAAE,yBAAyB,KAAK,OAAO,GACxD,mBAAmB;IAQtB;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CACV,QAAQ,EAAE,sBAAsB,EAChC,SAAS,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,OAAO,GACtD,mBAAmB;IAkCtB;;;;;;;;;;;OAWG;IACH,eAAe,CACb,SAAS,EAAE,CACT,KAAK,EAAE,wBAAwB,EAC/B,MAAM,EAAE,yBAAyB,KAC9B,OAAO,GACX,mBAAmB;IA+BtB;;;;;;;;;OASG;IACH,SAAS,CACP,SAAS,EAAE,sBAAsB,GAAG,qBAAqB,GACxD,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAIlC;;;;;;;;;OASG;IACH,WAAW,CACT,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GACnC,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAIpC;;;;;;;OAOG;IACH,SAAS,IAAI,kBAAkB;IAO/B;;;;;;;;;;;;;;;OAeG;WACU,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAKrE"}
|
|
@@ -10,8 +10,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _AccountTreeSnapshot_entries, _AccountTreeSnapshot_idMap;
|
|
13
|
-
import { AccountWalletPayloadType, assertAccountTreePayload, ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION
|
|
14
|
-
import { deepFreeze } from
|
|
13
|
+
import { AccountWalletPayloadType, assertAccountTreePayload, ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION } from "./payload.mjs";
|
|
14
|
+
import { deepFreeze } from "./utils.mjs";
|
|
15
15
|
/**
|
|
16
16
|
* Immutable value object returned by {@link AccountTreeController.exportState}.
|
|
17
17
|
*
|
|
@@ -195,4 +195,4 @@ export class AccountTreeSnapshot {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
_AccountTreeSnapshot_entries = new WeakMap(), _AccountTreeSnapshot_idMap = new WeakMap();
|
|
198
|
-
//# sourceMappingURL=snapshot.
|
|
198
|
+
//# sourceMappingURL=snapshot.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.mjs","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":";;;;;;;;;;;;AAWA,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,oCAAoC,EACrC,sBAAqB;AACtB,OAAO,EAAE,UAAU,EAAE,oBAAmB;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OA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C;IAC5C,CAAC;IAED;;;;;;;;;OASG;IACH,WAAW,CACT,OAAoC;QAEpC,OAAO,uBAAA,IAAI,kCAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACH,SAAS;QACP,OAAO;YACL,OAAO,EAAE,oCAAoC;YAC7C,OAAO,EAAE,uBAAA,IAAI,oCAAS;SACvB,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,GAAY;QACnC,sCAAsC;QACtC,wBAAwB,CAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,IAAI,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF","sourcesContent":["import type { IdMap } from './id-map.js';\nimport type {\n AccountGroupPayloadId,\n AccountTreePayload,\n AccountTreeSnapshotGroup,\n AccountTreeSnapshotWallet,\n AccountTreeWalletEntry,\n AccountWalletMnemonicGroupEntry,\n AccountWalletPayloadId,\n AccountWalletPrivateKeyGroupEntry,\n} from './payload.js';\nimport {\n AccountWalletPayloadType,\n assertAccountTreePayload,\n ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION,\n} from './payload.js';\nimport { deepFreeze } from './utils.js';\n\n/**\n * Immutable value object returned by {@link AccountTreeController.exportState}.\n *\n * Construct with {@link AccountTreeController.exportState},\n * {@link AccountTreeSnapshot.deserialize}, or `new AccountTreeSnapshot(...)`\n * for tests and advanced use.\n *\n * Wallet and group entries are deep-cloned and deep-frozen once in the\n * constructor. Filtering predicates receive those read-only views directly;\n * each filter method returns a new snapshot that repeats the process for its\n * result.\n *\n * An optional ID map (local ↔ payload) may be supplied when bridging between\n * internal controller IDs and the stable cross-device IDs in the serialized\n * payload. The map covers the original export and is preserved unchanged\n * through filtering until {@link serialize}. Omit it when deterministic IDs\n * make {@link toLocalId} / {@link toPayloadId} unnecessary.\n */\nexport class AccountTreeSnapshot {\n readonly #entries: AccountTreeWalletEntry[];\n\n readonly #idMap: IdMap | undefined;\n\n /**\n * @param entries - Wallet entries in the snapshot.\n * @param idMap - Optional local ↔ payload ID map from export.\n */\n constructor(entries: AccountTreeWalletEntry[], idMap?: IdMap) {\n this.#entries = deepFreeze(structuredClone(entries));\n this.#idMap = idMap;\n }\n\n /**\n * Returns a new snapshot containing only the wallets for which\n * `predicate` returns `true`.\n *\n * When filtering by wallet ID, compare against stable payload IDs from\n * {@link serialize} or convert local IDs with {@link toPayloadId} first.\n *\n * @param predicate - Function called with each deeply read-only wallet entry.\n * @returns A filtered snapshot.\n */\n filterWallets(\n predicate: (wallet: AccountTreeSnapshotWallet) => boolean,\n ): AccountTreeSnapshot {\n const filteredEntries = this.#entries.filter((entry) =>\n predicate(entry as AccountTreeSnapshotWallet),\n );\n\n return new AccountTreeSnapshot(filteredEntries, this.#idMap);\n }\n\n /**\n * Filters groups within one wallet. Other wallets are left unchanged.\n *\n * Throws if `walletId` does not identify a wallet in the snapshot.\n * Removes the wallet if no groups remain after filtering — this prevents a\n * mnemonic wallet with zero selected groups from still transferring its secret.\n *\n * **Mnemonic wallets:** group indices must remain contiguous starting at 0\n * after filtering, because the payload schema enforces this invariant.\n * Predicates that produce gaps (e.g. keeping only index 1, or 0 and 2) will\n * cause {@link AccountTreeSnapshot.deserialize} to reject the payload on the\n * receiving end.\n *\n * @param walletId - Stable payload wallet ID to filter groups within.\n * @param predicate - Function called with each deeply read-only group entry.\n * @returns A filtered snapshot.\n * @throws If `walletId` is not present in the snapshot.\n */\n filterGroups(\n walletId: AccountWalletPayloadId,\n predicate: (group: AccountTreeSnapshotGroup) => boolean,\n ): AccountTreeSnapshot {\n const walletIndex = this.#entries.findIndex(\n (entry) => entry.id === walletId,\n );\n if (walletIndex === -1) {\n throw new Error(\n `Cannot filter groups: wallet \"${walletId}\" not found in snapshot`,\n );\n }\n\n const wallet = this.#entries[walletIndex];\n\n const filteredGroups = wallet.groups.filter((group) =>\n predicate(group as AccountTreeSnapshotGroup),\n );\n\n const filteredEntries = [...this.#entries];\n if (filteredGroups.length === 0) {\n filteredEntries.splice(walletIndex, 1);\n } else if (wallet.type === AccountWalletPayloadType.Mnemonic) {\n filteredEntries[walletIndex] = {\n ...wallet,\n groups: filteredGroups as AccountWalletMnemonicGroupEntry[],\n };\n } else {\n filteredEntries[walletIndex] = {\n ...wallet,\n groups: filteredGroups as AccountWalletPrivateKeyGroupEntry[],\n };\n }\n\n return new AccountTreeSnapshot(filteredEntries, this.#idMap);\n }\n\n /**\n * Filters groups across every wallet.\n *\n * The parent wallet is provided as context to the predicate. Removes any\n * wallet with no remaining groups after filtering.\n *\n * **Mnemonic wallets:** see {@link filterGroups} for the contiguous-index\n * constraint that applies here as well.\n *\n * @param predicate - Function called with each group and its parent wallet.\n * @returns A filtered snapshot.\n */\n filterAllGroups(\n predicate: (\n group: AccountTreeSnapshotGroup,\n wallet: AccountTreeSnapshotWallet,\n ) => boolean,\n ): AccountTreeSnapshot {\n const filteredEntries: AccountTreeWalletEntry[] = [];\n\n for (const wallet of this.#entries) {\n const filteredGroups = wallet.groups.filter((group) =>\n predicate(\n group as AccountTreeSnapshotGroup,\n wallet as AccountTreeSnapshotWallet,\n ),\n );\n\n if (filteredGroups.length === 0) {\n continue;\n }\n\n if (wallet.type === AccountWalletPayloadType.Mnemonic) {\n filteredEntries.push({\n ...wallet,\n groups: filteredGroups as AccountWalletMnemonicGroupEntry[],\n });\n } else {\n filteredEntries.push({\n ...wallet,\n groups: filteredGroups as AccountWalletPrivateKeyGroupEntry[],\n });\n }\n }\n\n return new AccountTreeSnapshot(filteredEntries, this.#idMap);\n }\n\n /**\n * Converts a payload ID (wallet or group) to the corresponding local\n * `AccountTreeController` ID.\n *\n * The map reflects the original export, not the wallets/groups currently\n * retained in this snapshot after filtering.\n *\n * @param payloadId - Stable cross-device wallet or group payload ID.\n * @returns The local controller ID, or `undefined` if not found or no ID map is present.\n */\n toLocalId(\n payloadId: AccountWalletPayloadId | AccountGroupPayloadId,\n ): ReturnType<IdMap['getLocalId']> {\n return this.#idMap?.getLocalId(payloadId);\n }\n\n /**\n * Converts a local `AccountTreeController` ID (wallet or group) to its\n * stable cross-device payload ID.\n *\n * The map reflects the original export, not the wallets/groups currently\n * retained in this snapshot after filtering.\n *\n * @param localId - Local controller wallet or group ID.\n * @returns The payload ID, or `undefined` if not found or no ID map is present.\n */\n toPayloadId(\n localId: Parameters<IdMap['add']>[0],\n ): ReturnType<IdMap['getPayloadId']> {\n return this.#idMap?.getPayloadId(localId);\n }\n\n /**\n * Serializes the snapshot to a flat {@link AccountTreePayload} with `version` inlined\n * alongside the wallet entries.\n *\n * Returns the constructor-frozen wallet tree without copying it again.\n *\n * @returns The versioned flat payload.\n */\n serialize(): AccountTreePayload {\n return {\n version: ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION,\n wallets: this.#entries,\n };\n }\n\n /**\n * Validates a raw value as an {@link AccountTreePayload}, running any\n * necessary version migrations, and returns an immutable snapshot.\n *\n * This is the entry point for untrusted serialized data. Unsupported schema\n * versions and wallet types fail closed with an error instead of returning a\n * partial snapshot.\n *\n * The returned snapshot has no ID map — {@link toLocalId} / {@link toPayloadId}\n * return `undefined`. Pass an {@link IdMap} to the constructor when you need\n * the map.\n *\n * @param raw - Unknown value to parse.\n * @returns A validated snapshot.\n * @throws If `raw` is not a valid payload or its version is unsupported.\n */\n static async deserialize(raw: unknown): Promise<AccountTreeSnapshot> {\n // TODO: Use migration framework here.\n assertAccountTreePayload(raw);\n return new AccountTreeSnapshot(raw.wallets);\n }\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatValidationErrorMessages = exports.deepFreeze = exports.decodeBytes = exports.encodeBytes = exports.BytesStruct = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
/**
|
|
6
|
+
* Superstruct struct that validates an {@link EncodedBytes} value.
|
|
7
|
+
*/
|
|
8
|
+
exports.BytesStruct = (0, superstruct_1.refine)((0, superstruct_1.array)((0, superstruct_1.integer)()), 'bytes', (value) => {
|
|
9
|
+
const invalid = value.find((b) => b < 0 || b > 255);
|
|
10
|
+
return invalid === undefined
|
|
11
|
+
? true
|
|
12
|
+
: `each byte must be in [0, 255]; got ${invalid}`;
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Encodes a `Uint8Array` as a JSON-compatible {@link EncodedBytes}.
|
|
16
|
+
*
|
|
17
|
+
* @param bytes - The bytes to encode.
|
|
18
|
+
* @returns An array of integers in [0, 255].
|
|
19
|
+
*/
|
|
20
|
+
function encodeBytes(bytes) {
|
|
21
|
+
return Array.from(bytes);
|
|
22
|
+
}
|
|
23
|
+
exports.encodeBytes = encodeBytes;
|
|
24
|
+
/**
|
|
25
|
+
* Decodes an {@link EncodedBytes} produced by {@link encodeBytes} back into a `Uint8Array`.
|
|
26
|
+
* The caller is responsible for zeroing the result when the data is no longer needed.
|
|
27
|
+
*
|
|
28
|
+
* @param encoded - The encoded byte array.
|
|
29
|
+
* @returns The decoded `Uint8Array`.
|
|
30
|
+
*/
|
|
31
|
+
function decodeBytes(encoded) {
|
|
32
|
+
return new Uint8Array(encoded);
|
|
33
|
+
}
|
|
34
|
+
exports.decodeBytes = decodeBytes;
|
|
35
|
+
/**
|
|
36
|
+
* Recursively freezes a value and its nested properties.
|
|
37
|
+
*
|
|
38
|
+
* @param value - Value to freeze.
|
|
39
|
+
* @returns The frozen value.
|
|
40
|
+
*/
|
|
41
|
+
function deepFreeze(value) {
|
|
42
|
+
if (value === null || typeof value !== 'object') {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
Object.freeze(value);
|
|
46
|
+
for (const nested of Object.values(value)) {
|
|
47
|
+
deepFreeze(nested);
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
exports.deepFreeze = deepFreeze;
|
|
52
|
+
/**
|
|
53
|
+
* Formats Superstruct validation failures into a single error message string.
|
|
54
|
+
*
|
|
55
|
+
* @param error - The StructError thrown during validation.
|
|
56
|
+
* @returns A comma-separated list of `[path] expected: <type>` entries.
|
|
57
|
+
*/
|
|
58
|
+
function formatValidationErrorMessages(error) {
|
|
59
|
+
return error
|
|
60
|
+
.failures()
|
|
61
|
+
.map(({ path, type, refinement }) => {
|
|
62
|
+
const location = path.length > 0 ? path.join('.') : '<root>';
|
|
63
|
+
return `[${location}] expected: ${refinement ?? type}`;
|
|
64
|
+
})
|
|
65
|
+
.join(', ');
|
|
66
|
+
}
|
|
67
|
+
exports.formatValidationErrorMessages = formatValidationErrorMessages;
|
|
68
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":";;;AACA,uDAA4E;AAQ5E;;GAEG;AACU,QAAA,WAAW,GAAyB,IAAA,oBAAM,EACrD,IAAA,mBAAK,EAAC,IAAA,qBAAO,GAAE,CAAC,EAChB,OAAO,EACP,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACpD,OAAO,OAAO,KAAK,SAAS;QAC1B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,sCAAsC,OAAO,EAAE,CAAC;AACtD,CAAC,CACF,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,KAAiB;IAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAFD,kCAEC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,OAAqB;IAC/C,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAFD,kCAEC;AAaD;;;;;GAKG;AACH,SAAgB,UAAU,CAAQ,KAAY;IAC5C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAErB,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1C,UAAU,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAZD,gCAYC;AAED;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAC,KAAkB;IAC9D,OAAO,KAAK;SACT,QAAQ,EAAE;SACV,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC7D,OAAO,IAAI,QAAQ,eAAe,UAAU,IAAI,IAAI,EAAE,CAAC;IACzD,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AARD,sEAQC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { array, integer, refine, StructError } from '@metamask/superstruct';\n\n/**\n * A JSON-compatible representation of a `Uint8Array` as an array of integers\n * in [0, 255]. Use {@link encodeBytes} and {@link decodeBytes} to convert.\n */\nexport type EncodedBytes = number[];\n\n/**\n * Superstruct struct that validates an {@link EncodedBytes} value.\n */\nexport const BytesStruct: Struct<EncodedBytes> = refine(\n array(integer()),\n 'bytes',\n (value) => {\n const invalid = value.find((b) => b < 0 || b > 255);\n return invalid === undefined\n ? true\n : `each byte must be in [0, 255]; got ${invalid}`;\n },\n);\n\n/**\n * Encodes a `Uint8Array` as a JSON-compatible {@link EncodedBytes}.\n *\n * @param bytes - The bytes to encode.\n * @returns An array of integers in [0, 255].\n */\nexport function encodeBytes(bytes: Uint8Array): EncodedBytes {\n return Array.from(bytes);\n}\n\n/**\n * Decodes an {@link EncodedBytes} produced by {@link encodeBytes} back into a `Uint8Array`.\n * The caller is responsible for zeroing the result when the data is no longer needed.\n *\n * @param encoded - The encoded byte array.\n * @returns The decoded `Uint8Array`.\n */\nexport function decodeBytes(encoded: EncodedBytes): Uint8Array {\n return new Uint8Array(encoded);\n}\n\n/**\n * Recursively readonly view of `Value` used by snapshot filtering predicate types.\n *\n * @typeParam T - The mutable source type to expose as deeply read-only.\n */\nexport type DeepReadonly<Value> = Value extends readonly (infer Item)[]\n ? readonly DeepReadonly<Item>[]\n : Value extends object\n ? { readonly [Key in keyof Value]: DeepReadonly<Value[Key]> }\n : Value;\n\n/**\n * Recursively freezes a value and its nested properties.\n *\n * @param value - Value to freeze.\n * @returns The frozen value.\n */\nexport function deepFreeze<Value>(value: Value): Value {\n if (value === null || typeof value !== 'object') {\n return value;\n }\n\n Object.freeze(value);\n\n for (const nested of Object.values(value)) {\n deepFreeze(nested);\n }\n\n return value;\n}\n\n/**\n * Formats Superstruct validation failures into a single error message string.\n *\n * @param error - The StructError thrown during validation.\n * @returns A comma-separated list of `[path] expected: <type>` entries.\n */\nexport function formatValidationErrorMessages(error: StructError): string {\n return error\n .failures()\n .map(({ path, type, refinement }) => {\n const location = path.length > 0 ? path.join('.') : '<root>';\n return `[${location}] expected: ${refinement ?? type}`;\n })\n .join(', ');\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Struct } from
|
|
2
|
-
import { StructError } from
|
|
1
|
+
import type { Struct } from "@metamask/superstruct";
|
|
2
|
+
import { StructError } from "@metamask/superstruct";
|
|
3
3
|
/**
|
|
4
4
|
* A JSON-compatible representation of a `Uint8Array` as an array of integers
|
|
5
5
|
* in [0, 255]. Use {@link encodeBytes} and {@link decodeBytes} to convert.
|
|
@@ -46,4 +46,4 @@ export declare function deepFreeze<Value>(value: Value): Value;
|
|
|
46
46
|
* @returns A comma-separated list of `[path] expected: <type>` entries.
|
|
47
47
|
*/
|
|
48
48
|
export declare function formatValidationErrorMessages(error: StructError): string;
|
|
49
|
-
//# sourceMappingURL=utils.d.
|
|
49
|
+
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AACpD,OAAO,EAA0B,WAAW,EAAE,8BAA8B;AAE5E;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,EAAE,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,YAAY,CAS5C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,UAAU,CAE7D;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,KAAK,IAAI,KAAK,SAAS,SAAS,CAAC,MAAM,IAAI,CAAC,EAAE,GACnE,SAAS,YAAY,CAAC,IAAI,CAAC,EAAE,GAC7B,KAAK,SAAS,MAAM,GAClB;IAAE,QAAQ,EAAE,GAAG,IAAI,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;CAAE,GAC3D,KAAK,CAAC;AAEZ;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAYrD;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAQxE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Struct } from "@metamask/superstruct";
|
|
2
|
+
import { StructError } from "@metamask/superstruct";
|
|
3
|
+
/**
|
|
4
|
+
* A JSON-compatible representation of a `Uint8Array` as an array of integers
|
|
5
|
+
* in [0, 255]. Use {@link encodeBytes} and {@link decodeBytes} to convert.
|
|
6
|
+
*/
|
|
7
|
+
export type EncodedBytes = number[];
|
|
8
|
+
/**
|
|
9
|
+
* Superstruct struct that validates an {@link EncodedBytes} value.
|
|
10
|
+
*/
|
|
11
|
+
export declare const BytesStruct: Struct<EncodedBytes>;
|
|
12
|
+
/**
|
|
13
|
+
* Encodes a `Uint8Array` as a JSON-compatible {@link EncodedBytes}.
|
|
14
|
+
*
|
|
15
|
+
* @param bytes - The bytes to encode.
|
|
16
|
+
* @returns An array of integers in [0, 255].
|
|
17
|
+
*/
|
|
18
|
+
export declare function encodeBytes(bytes: Uint8Array): EncodedBytes;
|
|
19
|
+
/**
|
|
20
|
+
* Decodes an {@link EncodedBytes} produced by {@link encodeBytes} back into a `Uint8Array`.
|
|
21
|
+
* The caller is responsible for zeroing the result when the data is no longer needed.
|
|
22
|
+
*
|
|
23
|
+
* @param encoded - The encoded byte array.
|
|
24
|
+
* @returns The decoded `Uint8Array`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function decodeBytes(encoded: EncodedBytes): Uint8Array;
|
|
27
|
+
/**
|
|
28
|
+
* Recursively readonly view of `Value` used by snapshot filtering predicate types.
|
|
29
|
+
*
|
|
30
|
+
* @typeParam T - The mutable source type to expose as deeply read-only.
|
|
31
|
+
*/
|
|
32
|
+
export type DeepReadonly<Value> = Value extends readonly (infer Item)[] ? readonly DeepReadonly<Item>[] : Value extends object ? {
|
|
33
|
+
readonly [Key in keyof Value]: DeepReadonly<Value[Key]>;
|
|
34
|
+
} : Value;
|
|
35
|
+
/**
|
|
36
|
+
* Recursively freezes a value and its nested properties.
|
|
37
|
+
*
|
|
38
|
+
* @param value - Value to freeze.
|
|
39
|
+
* @returns The frozen value.
|
|
40
|
+
*/
|
|
41
|
+
export declare function deepFreeze<Value>(value: Value): Value;
|
|
42
|
+
/**
|
|
43
|
+
* Formats Superstruct validation failures into a single error message string.
|
|
44
|
+
*
|
|
45
|
+
* @param error - The StructError thrown during validation.
|
|
46
|
+
* @returns A comma-separated list of `[path] expected: <type>` entries.
|
|
47
|
+
*/
|
|
48
|
+
export declare function formatValidationErrorMessages(error: StructError): string;
|
|
49
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AACpD,OAAO,EAA0B,WAAW,EAAE,8BAA8B;AAE5E;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,EAAE,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,YAAY,CAS5C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,UAAU,CAE7D;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,KAAK,IAAI,KAAK,SAAS,SAAS,CAAC,MAAM,IAAI,CAAC,EAAE,GACnE,SAAS,YAAY,CAAC,IAAI,CAAC,EAAE,GAC7B,KAAK,SAAS,MAAM,GAClB;IAAE,QAAQ,EAAE,GAAG,IAAI,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;CAAE,GAC3D,KAAK,CAAC;AAEZ;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAYrD;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAQxE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { array, integer, refine } from
|
|
1
|
+
import { array, integer, refine, StructError } from "@metamask/superstruct";
|
|
2
2
|
/**
|
|
3
3
|
* Superstruct struct that validates an {@link EncodedBytes} value.
|
|
4
4
|
*/
|
|
@@ -58,4 +58,4 @@ export function formatValidationErrorMessages(error) {
|
|
|
58
58
|
})
|
|
59
59
|
.join(', ');
|
|
60
60
|
}
|
|
61
|
-
//# sourceMappingURL=utils.
|
|
61
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,8BAA8B;AAQ5E;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAyB,MAAM,CACrD,KAAK,CAAC,OAAO,EAAE,CAAC,EAChB,OAAO,EACP,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IACpD,OAAO,OAAO,KAAK,SAAS;QAC1B,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,sCAAsC,OAAO,EAAE,CAAC;AACtD,CAAC,CACF,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,OAAqB;IAC/C,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAaD;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAQ,KAAY;IAC5C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAErB,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1C,UAAU,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAkB;IAC9D,OAAO,KAAK;SACT,QAAQ,EAAE;SACV,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC7D,OAAO,IAAI,QAAQ,eAAe,UAAU,IAAI,IAAI,EAAE,CAAC;IACzD,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC","sourcesContent":["import type { Struct } from '@metamask/superstruct';\nimport { array, integer, refine, StructError } from '@metamask/superstruct';\n\n/**\n * A JSON-compatible representation of a `Uint8Array` as an array of integers\n * in [0, 255]. Use {@link encodeBytes} and {@link decodeBytes} to convert.\n */\nexport type EncodedBytes = number[];\n\n/**\n * Superstruct struct that validates an {@link EncodedBytes} value.\n */\nexport const BytesStruct: Struct<EncodedBytes> = refine(\n array(integer()),\n 'bytes',\n (value) => {\n const invalid = value.find((b) => b < 0 || b > 255);\n return invalid === undefined\n ? true\n : `each byte must be in [0, 255]; got ${invalid}`;\n },\n);\n\n/**\n * Encodes a `Uint8Array` as a JSON-compatible {@link EncodedBytes}.\n *\n * @param bytes - The bytes to encode.\n * @returns An array of integers in [0, 255].\n */\nexport function encodeBytes(bytes: Uint8Array): EncodedBytes {\n return Array.from(bytes);\n}\n\n/**\n * Decodes an {@link EncodedBytes} produced by {@link encodeBytes} back into a `Uint8Array`.\n * The caller is responsible for zeroing the result when the data is no longer needed.\n *\n * @param encoded - The encoded byte array.\n * @returns The decoded `Uint8Array`.\n */\nexport function decodeBytes(encoded: EncodedBytes): Uint8Array {\n return new Uint8Array(encoded);\n}\n\n/**\n * Recursively readonly view of `Value` used by snapshot filtering predicate types.\n *\n * @typeParam T - The mutable source type to expose as deeply read-only.\n */\nexport type DeepReadonly<Value> = Value extends readonly (infer Item)[]\n ? readonly DeepReadonly<Item>[]\n : Value extends object\n ? { readonly [Key in keyof Value]: DeepReadonly<Value[Key]> }\n : Value;\n\n/**\n * Recursively freezes a value and its nested properties.\n *\n * @param value - Value to freeze.\n * @returns The frozen value.\n */\nexport function deepFreeze<Value>(value: Value): Value {\n if (value === null || typeof value !== 'object') {\n return value;\n }\n\n Object.freeze(value);\n\n for (const nested of Object.values(value)) {\n deepFreeze(nested);\n }\n\n return value;\n}\n\n/**\n * Formats Superstruct validation failures into a single error message string.\n *\n * @param error - The StructError thrown during validation.\n * @returns A comma-separated list of `[path] expected: <type>` entries.\n */\nexport function formatValidationErrorMessages(error: StructError): string {\n return error\n .failures()\n .map(({ path, type, refinement }) => {\n const location = path.length > 0 ? path.join('.') : '<root>';\n return `[${location}] expected: ${refinement ?? type}`;\n })\n .join(', ');\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-utils.cjs","sourceRoot":"","sources":["../src/type-utils.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Updatable field with timestamp tracking for persistence and synchronization.\n */\nexport type UpdatableField<T> = {\n value: T;\n lastUpdatedAt: number;\n};\n\n/**\n * Type utility to extract value from UpdatableField or return field as-is.\n */\nexport type ExtractFieldValue<Field> =\n Field extends UpdatableField<unknown> ? Field['value'] : Field;\n\n/**\n * Type utility to extract plain values from an object with UpdatableField properties.\n */\nexport type ExtractFieldValues<ObjectValue extends Record<string, unknown>> = {\n [Key in keyof ObjectValue]: ExtractFieldValue<ObjectValue[Key]>;\n};\n"]}
|
|
@@ -15,4 +15,4 @@ export type ExtractFieldValue<Field> = Field extends UpdatableField<unknown> ? F
|
|
|
15
15
|
export type ExtractFieldValues<ObjectValue extends Record<string, unknown>> = {
|
|
16
16
|
[Key in keyof ObjectValue]: ExtractFieldValue<ObjectValue[Key]>;
|
|
17
17
|
};
|
|
18
|
-
//# sourceMappingURL=type-utils.d.
|
|
18
|
+
//# sourceMappingURL=type-utils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-utils.d.cts","sourceRoot":"","sources":["../src/type-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,KAAK,EAAE,CAAC,CAAC;IACT,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,KAAK,IACjC,KAAK,SAAS,cAAc,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KAC3E,GAAG,IAAI,MAAM,WAAW,GAAG,iBAAiB,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;CAChE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updatable field with timestamp tracking for persistence and synchronization.
|
|
3
|
+
*/
|
|
4
|
+
export type UpdatableField<T> = {
|
|
5
|
+
value: T;
|
|
6
|
+
lastUpdatedAt: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Type utility to extract value from UpdatableField or return field as-is.
|
|
10
|
+
*/
|
|
11
|
+
export type ExtractFieldValue<Field> = Field extends UpdatableField<unknown> ? Field['value'] : Field;
|
|
12
|
+
/**
|
|
13
|
+
* Type utility to extract plain values from an object with UpdatableField properties.
|
|
14
|
+
*/
|
|
15
|
+
export type ExtractFieldValues<ObjectValue extends Record<string, unknown>> = {
|
|
16
|
+
[Key in keyof ObjectValue]: ExtractFieldValue<ObjectValue[Key]>;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=type-utils.d.mts.map
|