@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format-utils.js","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/format-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAG7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAQtD,OAAO,EAAE,kCAAkC,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,mCAAmC,GACpC,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC7C,OAA6B,EAC7B,MAAkC,EACT,EAAE;IAC3B,2DAA2D;IAC3D,MAAM,uBAAuB,GAC3B,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAE7D,OAAO;QACL,GAAG,CAAC,uBAAuB,IAAI,EAAE,CAAC;QAClC,8BAA8B,EAAE,IAAI,EAAE,yHAAyH;KAChK,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,OAA6B,EAC7B,KAA0C,EACZ,EAAE;IAChC,uFAAuF;IACvF,MAAM,sBAAsB,GAC1B,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC3D,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;IAE9C,IAAI,CAAC;QACH,kFAAkF;QAClF,2BAA2B;QAC3B,OAAO,IAAI,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AC,CAAC;QACjD,OAAO,WAAW,CAAC;IACrB,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,oEAAoE,cAAc,CAAC,KAAK,CAAC,EAAE,CAC5F,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { mask } from '@metamask/superstruct';\n\nimport type { AccountGroupMultichainAccountObject } from '../../group.js';\nimport { backupAndSyncLogger } from '../../logger.js';\nimport type { AccountWalletEntropyObject } from '../../wallet.js';\nimport type {\n BackupAndSyncContext,\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types.js';\nimport { UserStorageSyncedWalletGroupSchema } from '../types.js';\nimport { toErrorMessage } from '../utils/errors.js';\nimport {\n assertValidUserStorageWallet,\n assertValidUserStorageGroup,\n assertValidLegacyUserStorageAccount,\n} from './validation.js';\n\n/**\n * Formats the wallet for user storage usage.\n * This function extracts the necessary metadata from the wallet\n * and formats it according to the user storage requirements.\n *\n * @param context - The backup and sync context.\n * @param wallet - The wallet object to format.\n * @returns The formatted wallet for user storage.\n */\nexport const formatWalletForUserStorageUsage = (\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n): UserStorageSyncedWallet => {\n // This can be null if the user has not manually set a name\n const persistedWalletMetadata =\n context.controller.state.accountWalletsMetadata[wallet.id];\n\n return {\n ...(persistedWalletMetadata ?? {}),\n isLegacyAccountSyncingDisabled: true, // If we're here, it means legacy account syncing has been performed at least once, so we can disable it for this wallet.\n };\n};\n\n/**\n * Formats the group for user storage usage.\n * This function extracts the necessary metadata from the group\n * and formats it according to the user storage requirements.\n *\n * @param context - The backup and sync context.\n * @param group - The group object to format.\n * @returns The formatted group for user storage.\n */\nexport const formatGroupForUserStorageUsage = (\n context: BackupAndSyncContext,\n group: AccountGroupMultichainAccountObject,\n): UserStorageSyncedWalletGroup => {\n // This can be null if the user has not manually set a name, pinned or hidden the group\n const persistedGroupMetadata =\n context.controller.state.accountGroupsMetadata[group.id];\n const { groupIndex } = group.metadata.entropy;\n\n try {\n // We mask and we try catch, since `mask` will throw if the persisted metadata has\n // fields with wrong types.\n return mask(\n {\n ...(persistedGroupMetadata ?? {}),\n groupIndex,\n },\n UserStorageSyncedWalletGroupSchema,\n );\n } catch (error) {\n backupAndSyncLogger(\n `Error trying to format group for user storage usage: ${toErrorMessage(error)}`,\n );\n\n // If anything goes wrong with this group, we use blank metadata for it.\n return { groupIndex };\n }\n};\n\n/**\n * Parses the wallet from user storage response.\n * This function attempts to parse the wallet data from a string format\n * and returns it as a UserStorageSyncedWallet object.\n *\n * @param wallet - The wallet data in string format.\n * @returns The parsed UserStorageSyncedWallet object.\n * @throws If the wallet data is not in valid JSON format or fails validation.\n */\nexport const parseWalletFromUserStorageResponse = (\n wallet: string,\n): UserStorageSyncedWallet => {\n try {\n const walletData = JSON.parse(wallet);\n assertValidUserStorageWallet(walletData);\n return walletData;\n } catch (error: unknown) {\n throw new Error(\n `Error trying to parse wallet from user storage response: ${toErrorMessage(error)}`,\n );\n }\n};\n\n/**\n * Parses the group from user storage response.\n * This function attempts to parse the group data from a string format\n * and returns it as a UserStorageSyncedWalletGroup object.\n *\n * @param group - The group data in string format.\n * @returns The parsed UserStorageSyncedWalletGroup object.\n * @throws If the group data is not in valid JSON format or fails validation.\n */\nexport const parseGroupFromUserStorageResponse = (\n group: string,\n): UserStorageSyncedWalletGroup => {\n try {\n const groupData = JSON.parse(group);\n assertValidUserStorageGroup(groupData);\n return groupData;\n } catch (error: unknown) {\n throw new Error(\n `Error trying to parse group from user storage response: ${toErrorMessage(error)}`,\n );\n }\n};\n\n/**\n * Parses the legacy account from user storage response.\n * This function attempts to parse the account data from a string format\n * and returns it as a LegacyUserStorageSyncedAccount object.\n *\n * @param account - The account data in string format.\n * @returns The parsed LegacyUserStorageSyncedAccount object.\n * @throws If the account data is not in valid JSON format or fails validation.\n */\nexport const parseLegacyAccountFromUserStorageResponse = (\n account: string,\n): LegacyUserStorageSyncedAccount => {\n try {\n const accountData = JSON.parse(account);\n assertValidLegacyUserStorageAccount(accountData);\n return accountData;\n } catch (error: unknown) {\n throw new Error(\n `Error trying to parse legacy account from user storage response: ${toErrorMessage(error)}`,\n );\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './format-utils.js';\nexport * from './network-utils.js';\nexport * from './network-operations.js';\nexport * from './validation.js';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"network-operations.d.ts","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-operations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,gBAAgB,CAAC;AAE1E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EACV,oBAAoB,EACpB,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,aAAa,CAAC;AAgBrB;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,YAC1B,oBAAoB,mBACZ,MAAM,KACtB,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAuBxC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,YACzB,oBAAoB,UACrB,0BAA0B,KACjC,OAAO,CAAC,IAAI,CAiBd,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,2BAA2B,YAC7B,oBAAoB,mBACZ,MAAM,KACtB,OAAO,CAAC,4BAA4B,EAAE,CA8BxC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,YACzB,oBAAoB,mBACZ,MAAM,cACX,MAAM,KACjB,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAoB7C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,YACxB,oBAAoB,SACtB,mCAAmC,mBACzB,MAAM,KACtB,OAAO,CAAC,IAAI,CAgBd,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,YAC7B,oBAAoB,UACrB,mCAAmC,EAAE,mBAC5B,MAAM,KACtB,OAAO,CAAC,IAAI,CAwBd,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,+BAA+B,YACjC,oBAAoB,mBACZ,MAAM,KACtB,OAAO,CAAC,8BAA8B,EAAE,CAkC1C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"network-operations.js","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mCAAmC,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAQtD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACL,+BAA+B,EAC/B,sCAAsC,EACtC,gCAAgC,GACjC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,+BAA+B,EAC/B,8BAA8B,EAC9B,kCAAkC,EAClC,iCAAiC,EACjC,yCAAyC,GAC1C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;;;;;;GAQG;AACH,MAAM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K,EAAE,CAAC;gBACf,mBAAmB,CACjB,0DAA0D,cAAc,CAAC,KAAK,CAAC,EAAE,CAClF,CAAC;gBACF,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC,CAAC;aACD,MAAM,CACL,CAAC,OAAO,EAA6C,EAAE,CACrD,OAAO,KAAK,IAAI,CACnB,CAAC;QAEJ,mBAAmB,CACjB,gDAAgD,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAC9E,CAAC;QAEF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import { SDK } from '@metamask/profile-sync-controller';\n\nimport type { AccountGroupMultichainAccountObject } from '../../group.js';\nimport { backupAndSyncLogger } from '../../logger.js';\nimport type { AccountWalletEntropyObject } from '../../wallet.js';\nimport type {\n BackupAndSyncContext,\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types.js';\nimport { toErrorMessage } from '../utils/errors.js';\nimport {\n USER_STORAGE_GROUPS_FEATURE_KEY,\n USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY,\n USER_STORAGE_WALLETS_FEATURE_KEY,\n} from './constants.js';\nimport {\n formatWalletForUserStorageUsage,\n formatGroupForUserStorageUsage,\n parseWalletFromUserStorageResponse,\n parseGroupFromUserStorageResponse,\n parseLegacyAccountFromUserStorageResponse,\n} from './format-utils.js';\nimport { executeWithRetry } from './network-utils.js';\n\n/**\n * Retrieves the wallet from user storage.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @returns The wallet from user storage or null if not found or invalid.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getWalletFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<UserStorageSyncedWallet | null> => {\n return executeWithRetry(async () => {\n const walletData = await context.messenger.call(\n 'UserStorageController:performGetStorage',\n `${USER_STORAGE_WALLETS_FEATURE_KEY}.${USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY}`,\n entropySourceId,\n );\n if (!walletData) {\n return null;\n }\n\n try {\n backupAndSyncLogger(\n `Retrieved wallet data from user storage: ${JSON.stringify(walletData)}`,\n );\n return parseWalletFromUserStorageResponse(walletData);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse wallet data from user storage: ${toErrorMessage(error)}`,\n );\n return null;\n }\n });\n};\n\n/**\n * Pushes the wallet to user storage.\n *\n * @param context - The backup and sync context.\n * @param wallet - The wallet to push to user storage.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on the formatted wallet data.\n */\nexport const pushWalletToUserStorage = async (\n context: BackupAndSyncContext,\n wallet: AccountWalletEntropyObject,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedWallet = formatWalletForUserStorageUsage(context, wallet);\n const stringifiedWallet = JSON.stringify(formattedWallet);\n const entropySourceId = wallet.metadata.entropy.id;\n\n backupAndSyncLogger(`Pushing wallet to user storage: ${stringifiedWallet}`);\n\n const result = await context.messenger.call(\n 'UserStorageController:performSetStorage',\n `${USER_STORAGE_WALLETS_FEATURE_KEY}.${USER_STORAGE_WALLETS_FEATURE_ENTRY_KEY}`,\n stringifiedWallet,\n entropySourceId,\n );\n context.mutationTracker?.setRemoteWrite(true);\n return result;\n });\n};\n\n/**\n * Retrieves all groups from user storage.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @returns An array of groups from user storage.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getAllGroupsFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<UserStorageSyncedWalletGroup[]> => {\n return executeWithRetry(async () => {\n const groupData = await context.messenger.call(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}`,\n entropySourceId,\n );\n if (!groupData) {\n return [];\n }\n\n const allGroups = groupData\n .map((stringifiedGroup) => {\n try {\n return parseGroupFromUserStorageResponse(stringifiedGroup);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse group data from user storage: ${toErrorMessage(error)}`,\n );\n return null;\n }\n })\n .filter((group): group is UserStorageSyncedWalletGroup => group !== null);\n\n backupAndSyncLogger(\n `Retrieved groups from user storage: ${JSON.stringify(allGroups)}`,\n );\n\n return allGroups;\n });\n};\n\n/**\n * Retrieves a single group from user storage by group index.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index to retrieve.\n * @returns The group from user storage or null if not found or invalid.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getGroupFromUserStorage = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n): Promise<UserStorageSyncedWalletGroup | null> => {\n return executeWithRetry(async () => {\n const groupData = await context.messenger.call(\n 'UserStorageController:performGetStorage',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}.${groupIndex}`,\n entropySourceId,\n );\n if (!groupData) {\n return null;\n }\n\n try {\n return parseGroupFromUserStorageResponse(groupData);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse group data from user storage: ${toErrorMessage(error)}`,\n );\n return null;\n }\n });\n};\n\n/**\n * Pushes a group to user storage.\n *\n * @param context - The backup and sync context.\n * @param group - The group to push to user storage.\n * @param entropySourceId - The entropy source ID.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on the formatted group data.\n */\nexport const pushGroupToUserStorage = async (\n context: BackupAndSyncContext,\n group: AccountGroupMultichainAccountObject,\n entropySourceId: string,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedGroup = formatGroupForUserStorageUsage(context, group);\n const stringifiedGroup = JSON.stringify(formattedGroup);\n\n backupAndSyncLogger(`Pushing group to user storage: ${stringifiedGroup}`);\n\n const result = await context.messenger.call(\n 'UserStorageController:performSetStorage',\n `${USER_STORAGE_GROUPS_FEATURE_KEY}.${formattedGroup.groupIndex}`,\n stringifiedGroup,\n entropySourceId,\n );\n context.mutationTracker?.setRemoteWrite(true);\n return result;\n });\n};\n\n/**\n * Pushes a batch of groups to user storage.\n *\n * @param context - The backup and sync context.\n * @param groups - The groups to push to user storage.\n * @param entropySourceId - The entropy source ID.\n * @returns A promise that resolves when the operation is complete.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n * @throws When JSON.stringify fails on any of the formatted group data.\n */\nexport const pushGroupToUserStorageBatch = async (\n context: BackupAndSyncContext,\n groups: AccountGroupMultichainAccountObject[],\n entropySourceId: string,\n): Promise<void> => {\n return executeWithRetry(async () => {\n const formattedGroups = groups.map((group) =>\n formatGroupForUserStorageUsage(context, group),\n );\n\n const entries: [string, string][] = formattedGroups.map((group) => [\n String(group.groupIndex),\n JSON.stringify(group),\n ]);\n\n backupAndSyncLogger(\n `Pushing groups to user storage: ${entries.map(([_, value]) => value).join(', ')}`,\n );\n\n const result = await context.messenger.call(\n 'UserStorageController:performBatchSetStorage',\n USER_STORAGE_GROUPS_FEATURE_KEY,\n entries,\n entropySourceId,\n );\n context.mutationTracker?.setRemoteWrite(true);\n return result;\n });\n};\n\n/**\n * Retrieves legacy user storage accounts for a specific entropy source ID.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID to retrieve data for.\n * @returns A promise that resolves with the legacy user storage accounts.\n * @throws When network operations fail after maximum retry attempts.\n * @throws When messenger calls to UserStorageController fail due to authentication errors, encryption/decryption failures, or network issues.\n */\nexport const getAllLegacyUserStorageAccounts = async (\n context: BackupAndSyncContext,\n entropySourceId: string,\n): Promise<LegacyUserStorageSyncedAccount[]> => {\n return executeWithRetry(async () => {\n const accountsData = await context.messenger.call(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n SDK.USER_STORAGE_FEATURE_NAMES.accounts,\n entropySourceId,\n );\n\n if (!accountsData) {\n return [];\n }\n\n const allAccounts = accountsData\n .map((stringifiedAccount) => {\n try {\n return parseLegacyAccountFromUserStorageResponse(stringifiedAccount);\n } catch (error) {\n backupAndSyncLogger(\n `Failed to parse legacy account data from user storage: ${toErrorMessage(error)}`,\n );\n return null;\n }\n })\n .filter(\n (account): account is LegacyUserStorageSyncedAccount =>\n account !== null,\n );\n\n backupAndSyncLogger(\n `Retrieved legacy accounts from user storage: ${JSON.stringify(allAccounts)}`,\n );\n\n return allAccounts;\n });\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"network-utils.d.ts","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,UAAU,SAAI,EACd,WAAW,SAAO,GACjB,OAAO,CAAC,CAAC,CAAC,CAuBZ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"network-utils.js","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/network-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,SAA2B,EAC3B,UAAU,GAAG,CAAC,EACd,WAAW,GAAG,IAAI;IAElB,IAAI,SAAS,GAAU,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IAElD,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAEtE,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;gBAC3B,MAAM,CAAC,gCAAgC;YACzC,CAAC;YAED,sCAAsC;YACtC,MAAM,OAAO,GAAG,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YAEnD,oBAAoB;YACpB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IAED,mDAAmD;IACnD,MAAM,SAAS,CAAC;AAClB,CAAC","sourcesContent":["/**\n * Executes a network operation with retry logic for transient failures.\n *\n * @param operation - The async operation to execute.\n * @param maxRetries - Maximum number of retry attempts.\n * @param baseDelayMs - Base delay between retries in milliseconds.\n * @returns Promise that resolves with the operation result.\n */\nexport async function executeWithRetry<T>(\n operation: () => Promise<T>,\n maxRetries = 3,\n baseDelayMs = 1000,\n): Promise<T> {\n let lastError: Error = new Error('Unknown error');\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await operation();\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n\n if (attempt === maxRetries) {\n break; // Exit loop after final attempt\n }\n\n // Calculate exponential backoff delay\n const delayMs = baseDelayMs * Math.pow(2, attempt);\n\n // Wait before retry\n await new Promise((resolve) => setTimeout(resolve, delayMs));\n }\n }\n\n // This will only be reached if all attempts failed\n throw lastError;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/validation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,aAAa,CAAC;AAqBrB;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,UAAU,IAAI,uBAAuB,CAY/C;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,SAAS,IAAI,4BAA4B,CAYnD;AAED;;;;;GAKG;AACH,wBAAgB,mCAAmC,CACjD,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,WAAW,IAAI,8BAA8B,CAYvD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/backup-and-sync/user-storage/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAO5D,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,EAClC,oCAAoC,GACrC,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,MAAM,6BAA6B,GAAG,CAAC,KAAkB,EAAE,EAAE;IAC3D,MAAM,kBAAkB,GAAG,KAAK;SAC7B,QAAQ,EAAE;SACV,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE,CAAC;SAC5D,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO,8BAA8B,kBAAkB,EAAE,CAAC;AAC5D,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,UAAmB;IAEnB,IAAI,CAAC;QACH,MAAM,CAAC,UAAU,EAAE,6BAA6B,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,qCAAqC,6BAA6B,CAAC,KAAK,CAAC,EAAE,CAC5E,CAAC;QACJ,CAAC;QACD,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,SAAkB;IAElB,IAAI,CAAC;QACH,MAAM,CAAC,SAAS,EAAE,kCAAkC,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,oCAAoC,6BAA6B,CAAC,KAAK,CAAC,EAAE,CAC3E,CAAC;QACJ,CAAC;QACD,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mCAAmC,CACjD,WAAoB;IAEpB,IAAI,CAAC;QACH,MAAM,CAAC,WAAW,EAAE,oCAAoC,CAAC,CAAC;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,6CAA6C,6BAA6B,CAAC,KAAK,CAAC,EAAE,CACpF,CAAC;QACJ,CAAC;QACD,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { assert, StructError } from '@metamask/superstruct';\n\nimport type {\n LegacyUserStorageSyncedAccount,\n UserStorageSyncedWallet,\n UserStorageSyncedWalletGroup,\n} from '../types.js';\nimport {\n UserStorageSyncedWalletSchema,\n UserStorageSyncedWalletGroupSchema,\n LegacyUserStorageSyncedAccountSchema,\n} from '../types.js';\n\n/**\n * Formats validation error messages for user storage data.\n *\n * @param error - The StructError thrown during validation.\n * @returns A formatted string of validation error messages.\n */\nconst formatValidationErrorMessages = (error: StructError) => {\n const validationFailures = error\n .failures()\n .map(({ path, message }) => `[${path.join('.')}] ${message}`)\n .join(', ');\n return `Invalid user storage data: ${validationFailures}`;\n};\n\n/**\n * Validates and asserts user storage wallet data, throwing detailed errors if invalid.\n *\n * @param walletData - The wallet data from user storage to validate.\n * @throws StructError if the wallet data is invalid.\n */\nexport function assertValidUserStorageWallet(\n walletData: unknown,\n): asserts walletData is UserStorageSyncedWallet {\n try {\n assert(walletData, UserStorageSyncedWalletSchema);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Invalid user storage wallet data: ${formatValidationErrorMessages(error)}`,\n );\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Validates and asserts user storage group data, throwing detailed errors if invalid.\n *\n * @param groupData - The group data from user storage to validate.\n * @throws StructError if the group data is invalid.\n */\nexport function assertValidUserStorageGroup(\n groupData: unknown,\n): asserts groupData is UserStorageSyncedWalletGroup {\n try {\n assert(groupData, UserStorageSyncedWalletGroupSchema);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Invalid user storage group data: ${formatValidationErrorMessages(error)}`,\n );\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Validates and asserts legacy user storage account data, throwing detailed errors if invalid.\n *\n * @param accountData - The account data from user storage to validate.\n * @throws StructError if the account data is invalid.\n */\nexport function assertValidLegacyUserStorageAccount(\n accountData: unknown,\n): asserts accountData is LegacyUserStorageSyncedAccount {\n try {\n assert(accountData, LegacyUserStorageSyncedAccountSchema);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Invalid legacy user storage account data: ${formatValidationErrorMessages(error)}`,\n );\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/controller.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAA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nimport type { AccountWalletId } from '@metamask/account-api';\n\nimport type { AccountGroupMultichainAccountObject } from '../../group.js';\nimport { backupAndSyncLogger } from '../../logger.js';\nimport type { AccountTreeControllerState } from '../../types.js';\nimport type { AccountWalletEntropyObject } from '../../wallet.js';\nimport type { BackupAndSyncContext } from '../types.js';\n\n/**\n * Gets all local entropy wallets that can be synced.\n *\n * @param context - The backup and sync context.\n * @returns Array of entropy wallet objects.\n */\nexport function getLocalEntropyWallets(\n context: BackupAndSyncContext,\n): AccountWalletEntropyObject[] {\n return Object.values(context.controller.state.accountTree.wallets).filter(\n (wallet) => wallet.type === AccountWalletType.Entropy,\n );\n}\n\n/**\n * Gets the local group for a specific entropy wallet by its source ID and group index.\n *\n * @param context - The backup and sync context.\n * @param entropySourceId - The entropy source ID.\n * @param groupIndex - The group index.\n * @returns The local group object if it exists, undefined otherwise.\n */\nexport const getLocalGroupForEntropyWallet = (\n context: BackupAndSyncContext,\n entropySourceId: string,\n groupIndex: number,\n): AccountGroupMultichainAccountObject | undefined => {\n const walletId = toMultichainAccountWalletId(entropySourceId);\n const wallet = context.controller.state.accountTree.wallets[walletId];\n\n if (wallet?.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return undefined;\n }\n\n const groupId = toMultichainAccountGroupId(walletId, groupIndex);\n\n return wallet.groups[groupId];\n};\n\n/**\n * Gets all groups for a specific entropy wallet.\n *\n * @param context - The backup and sync context.\n * @param walletId - The wallet ID to get groups for.\n * @returns Array of multichain account group objects.\n */\nexport function getLocalGroupsForEntropyWallet(\n context: BackupAndSyncContext,\n walletId: AccountWalletId,\n): AccountGroupMultichainAccountObject[] {\n const wallet = context.controller.state.accountTree.wallets[walletId];\n if (wallet?.type !== AccountWalletType.Entropy) {\n backupAndSyncLogger(\n `Wallet ${walletId} not found or is not an entropy wallet`,\n );\n return [];\n }\n\n return Object.values(wallet.groups);\n}\n\n/**\n * State snapshot type for rollback operations.\n * Captures all the state that needs to be restored in case of sync failures.\n */\nexport type StateSnapshot = {\n accountGroupsMetadata: AccountTreeControllerState['accountGroupsMetadata'];\n accountWalletsMetadata: AccountTreeControllerState['accountWalletsMetadata'];\n selectedAccountGroup: AccountTreeControllerState['selectedAccountGroup'];\n accountTreeWallets: AccountTreeControllerState['accountTree']['wallets'];\n};\n\n/**\n * Creates a snapshot of the current controller state for rollback purposes.\n * Captures all state including the account tree structure.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @returns A deep copy of relevant state that can be restored later.\n */\nexport function createStateSnapshot(\n context: BackupAndSyncContext,\n): StateSnapshot {\n return {\n accountGroupsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountGroupsMetadata),\n ),\n accountWalletsMetadata: JSON.parse(\n JSON.stringify(context.controller.state.accountWalletsMetadata),\n ),\n selectedAccountGroup: context.controller.state.selectedAccountGroup,\n accountTreeWallets: JSON.parse(\n JSON.stringify(context.controller.state.accountTree.wallets),\n ),\n };\n}\n\n/**\n * Restores state using an update callback.\n * Restores both persisted metadata and the complete account tree structure.\n * Uses the controller's init() method to rebuild internal maps correctly.\n *\n * @param context - The backup and sync context containing controller and messenger.\n * @param snapshot - The state snapshot to restore.\n */\nexport function restoreStateFromSnapshot(\n context: BackupAndSyncContext,\n snapshot: StateSnapshot,\n): void {\n context.controllerStateUpdateFn((state) => {\n state.accountGroupsMetadata = snapshot.accountGroupsMetadata;\n state.accountWalletsMetadata = snapshot.accountWalletsMetadata;\n state.selectedAccountGroup = snapshot.selectedAccountGroup;\n state.accountTree.wallets = snapshot.accountTreeWallets;\n });\n\n // Use init() to rebuild the internal maps from the restored account tree state\n // This ensures that the internal maps (#accountIdToContext and #groupIdToWalletId)\n // are correctly synchronized with the restored account tree structure\n context.controller.init();\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAErD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC","sourcesContent":["/**\n * Extracts a string message from an unknown error value.\n *\n * @param error - The caught error value.\n * @returns The error message string.\n */\nexport function toErrorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export * from './controller.js';\nexport { toErrorMessage } from './errors.js';\nexport { createSyncMutationTracker } from './mutation-tracker.js';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-tracker.d.ts","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/mutation-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,QAAO,mBAiB5C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-tracker.js","sourceRoot":"","sources":["../../../src/backup-and-sync/utils/mutation-tracker.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAwB,EAAE;IACjE,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,OAAO;QACL,cAAc,EAAE,CAAC,KAAc,EAAQ,EAAE;YACvC,WAAW,GAAG,KAAK,CAAC;QACtB,CAAC;QACD,aAAa,EAAE,GAAY,EAAE,CAAC,UAAU;QACxC,aAAa,EAAE,CAAC,KAAc,EAAQ,EAAE;YACtC,UAAU,GAAG,KAAK,CAAC;QACrB,CAAC;QACD,WAAW,EAAE,GAAY,EAAE,CAAC,WAAW,IAAI,UAAU;QACrD,KAAK,EAAE,GAAS,EAAE;YAChB,WAAW,GAAG,KAAK,CAAC;YACpB,UAAU,GAAG,KAAK,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { SyncMutationTracker } from '../types.js';\n\n/**\n * Creates a tracker that records whether the current full sync run performed a\n * real write.\n *\n * @returns A fresh mutation tracker.\n */\nexport const createSyncMutationTracker = (): SyncMutationTracker => {\n let remoteWrite = false;\n let localWrite = false;\n return {\n setRemoteWrite: (value: boolean): void => {\n remoteWrite = value;\n },\n getLocalWrite: (): boolean => localWrite,\n setLocalWrite: (value: boolean): void => {\n localWrite = value;\n },\n hasOccurred: (): boolean => remoteWrite || localWrite,\n reset: (): void => {\n remoteWrite = false;\n localWrite = false;\n },\n };\n};\n"]}
|
package/dist/group.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAAA,OAAO,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AAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,KAAiC,EACjC,OAAuB,EACvB,IAAY;IAEZ,0DAA0D;IAC1D,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9D,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,mDAAmD;YACnD,OAAO,kCAAkC,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import type {\n AccountGroupType,\n MultichainAccountGroupId,\n} from '@metamask/account-api';\nimport type { AccountGroupId } from '@metamask/account-api';\nimport type { AccountId } from '@metamask/accounts-controller';\nimport {\n AnyAccountType,\n BtcAccountType,\n EthAccountType,\n SolAccountType,\n TrxAccountType,\n XlmAccountType,\n} from '@metamask/keyring-api';\nimport type { KeyringAccountType } from '@metamask/keyring-api';\n\nimport type { UpdatableField, ExtractFieldValues } from './type-utils.js';\nimport type { AccountTreeControllerState } from './types.js';\nimport type { AccountWalletObject } from './wallet.js';\n\n/**\n * Persisted metadata for account groups (stored in controller state for persistence/sync).\n */\nexport type AccountTreeGroupPersistedMetadata = {\n /** Custom name set by user, overrides default naming logic */\n name?: UpdatableField<string>;\n /** Whether this group is pinned in the UI */\n pinned?: UpdatableField<boolean>;\n /** Whether this group is hidden in the UI */\n hidden?: UpdatableField<boolean>;\n /** Timestamp of the last time this group was selected (local-only, not synced) */\n lastSelected?: number;\n};\n\nexport const MAX_SORT_ORDER = 9999;\n\n/**\n * Order of account types.\n */\nexport const ACCOUNT_TYPE_TO_SORT_ORDER: Record<KeyringAccountType, number> = {\n [EthAccountType.Eoa]: 0,\n [EthAccountType.Erc4337]: 1,\n [SolAccountType.DataAccount]: 2,\n [BtcAccountType.P2pkh]: 3,\n [BtcAccountType.P2sh]: 4,\n [BtcAccountType.P2wpkh]: 5,\n [BtcAccountType.P2tr]: 6,\n [TrxAccountType.Eoa]: 7,\n [XlmAccountType.Account]: 8,\n [AnyAccountType.Account]: MAX_SORT_ORDER,\n};\n\nexport type AccountTypeOrderKey = keyof typeof ACCOUNT_TYPE_TO_SORT_ORDER;\n\n/**\n * Tree metadata for account groups (required plain values extracted from persisted metadata).\n */\nexport type AccountTreeGroupMetadata = Required<\n ExtractFieldValues<AccountTreeGroupPersistedMetadata>\n>;\n\n/**\n * Type constraint for a {@link AccountGroupObject}. If one of its union-members\n * does not match this contraint, {@link AccountGroupObject} will resolve\n * to `never`.\n */\ntype IsAccountGroupObject<\n Type extends {\n type: AccountGroupType;\n id: AccountGroupId;\n accounts: AccountId[];\n metadata: AccountTreeGroupMetadata;\n },\n> = Type;\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupMultichainAccountObject = {\n type: AccountGroupType.MultichainAccount;\n id: MultichainAccountGroupId;\n // Blockchain Accounts (at least 1 account per multichain-accounts):\n accounts: [AccountId, ...AccountId[]];\n metadata: AccountTreeGroupMetadata & {\n entropy: {\n groupIndex: number;\n };\n };\n};\n\n/**\n * Multichain-account group object.\n */\nexport type AccountGroupSingleAccountObject = {\n type: AccountGroupType.SingleAccount;\n id: AccountGroupId;\n // Blockchain Accounts (1 account per group):\n accounts: [AccountId];\n metadata: AccountTreeGroupMetadata;\n};\n\n/**\n * Account group object.\n */\nexport type AccountGroupObject = IsAccountGroupObject<\n AccountGroupMultichainAccountObject | AccountGroupSingleAccountObject\n>;\n\nexport type AccountGroupObjectOf<GroupType extends AccountGroupType> = Extract<\n | {\n type: AccountGroupType.MultichainAccount;\n object: AccountGroupMultichainAccountObject;\n }\n | {\n type: AccountGroupType.SingleAccount;\n object: AccountGroupSingleAccountObject;\n },\n { type: GroupType }\n>['object'];\n\n/**\n * Checks if a group name is unique within a specific wallet.\n *\n * @param wallet - The wallet to check within.\n * @param groupId - The account group ID to exclude from the check.\n * @param name - The name to validate for uniqueness.\n * @returns True if the name is unique within the wallet, false otherwise.\n */\nexport function isAccountGroupNameUniqueFromWallet(\n wallet: AccountWalletObject,\n groupId: AccountGroupId,\n name: string,\n): boolean {\n const trimmedName = name.trim();\n\n // Check for duplicates within this wallet\n for (const group of Object.values(wallet.groups)) {\n if (group.id !== groupId && group.metadata.name.trim() === trimmedName) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Checks if an account group name is unique within the same wallet.\n *\n * @param state - The account tree controller state.\n * @param groupId - The account group ID to exclude from the check.\n * @param name - The name to validate for uniqueness.\n * @returns True if the name is unique within the same wallet, false otherwise.\n * @throws Error if the group ID does not exist.\n */\nexport function isAccountGroupNameUnique(\n state: AccountTreeControllerState,\n groupId: AccountGroupId,\n name: string,\n): boolean {\n // Find the wallet that contains the group being validated\n for (const wallet of Object.values(state.accountTree.wallets)) {\n if (wallet.groups[groupId]) {\n // Use the wallet-specific function for consistency\n return isAccountGroupNameUniqueFromWallet(wallet, groupId, name);\n }\n }\n\n throw new Error('Account group not found in tree');\n}\n"]}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,GACjC,MAAM,6CAA6C,CAAC;AAErD,YAAY,EACV,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,EAC5B,qCAAqC,EACrC,2CAA2C,EAC3C,oDAAoD,EACpD,6CAA6C,EAC7C,6CAA6C,EAC7C,6CAA6C,EAC7C,qCAAqC,EACrC,uCAAuC,EACvC,2BAA2B,EAC3B,8BAA8B,GAC/B,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,iDAAiD,EACjD,kDAAkD,EAClD,8DAA8D,EAC9D,6DAA6D,EAC7D,gDAAgD,EAChD,4CAA4C,EAC5C,kDAAkD,EAClD,kDAAkD,EAClD,6DAA6D,EAC7D,8CAA8C,EAC9C,+CAA+C,EAC/C,gDAAgD,EAChD,gDAAgD,EAChD,qCAAqC,EACrC,8CAA8C,EAC9C,yDAAyD,EACzD,+BAA+B,EAC/B,iCAAiC,EACjC,sCAAsC,EACtC,sCAAsC,GACvC,MAAM,gDAAgD,CAAC;AAExD,YAAY,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,EACL,qBAAqB,EACrB,oCAAoC,GACrC,MAAM,4BAA4B,CAAC;AAEpC,YAAY,EACV,kBAAkB,EAClB,4BAA4B,EAC5B,4BAA4B,EAC5B,8BAA8B,EAC9B,+BAA+B,EAC/B,iCAAiC,EACjC,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,wBAAwB,EACxB,+BAA+B,EAC/B,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { isAccountGroupNameUnique } from './group.js';
|
|
2
|
-
export { USER_STORAGE_GROUPS_FEATURE_KEY, USER_STORAGE_WALLETS_FEATURE_KEY, } from './backup-and-sync/user-storage/constants.js';
|
|
3
|
-
export { AccountTreeController, getDefaultAccountTreeControllerState, } from './AccountTreeController.js';
|
|
4
|
-
export { AccountWalletPayloadType, AccountWalletPrivateKeyEncoding, AccountTreePayloadStruct, assertAccountTreePayload, } from './state/payload.js';
|
|
5
|
-
export { AccountTreeSnapshot } from './state/snapshot.js';
|
|
6
|
-
export { IdMap } from './state/id-map.js';
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EACL,+BAA+B,EAC/B,gCAAgC,GACjC,MAAM,6CAA6C,CAAC;AA2CrD,OAAO,EACL,qBAAqB,EACrB,oCAAoC,GACrC,MAAM,4BAA4B,CAAC;AAgBpC,OAAO,EACL,wBAAwB,EACxB,+BAA+B,EAC/B,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export type { AccountWalletObject } from './wallet.js';\nexport type { AccountGroupObject } from './group.js';\nexport { isAccountGroupNameUnique } from './group.js';\n\nexport {\n USER_STORAGE_GROUPS_FEATURE_KEY,\n USER_STORAGE_WALLETS_FEATURE_KEY,\n} from './backup-and-sync/user-storage/constants.js';\n\nexport type {\n AccountTreeControllerState,\n AccountTreeControllerGetStateAction,\n AccountTreeControllerActions,\n AccountTreeControllerStateChangeEvent,\n AccountTreeControllerAccountTreeChangeEvent,\n AccountTreeControllerSelectedAccountGroupChangeEvent,\n AccountTreeControllerAccountGroupCreatedEvent,\n AccountTreeControllerAccountGroupUpdatedEvent,\n AccountTreeControllerAccountGroupRemovedEvent,\n AccountTreeControllerInitializedEvent,\n AccountTreeControllerUninitializedEvent,\n AccountTreeControllerEvents,\n AccountTreeControllerMessenger,\n} from './types.js';\n\nexport type {\n AccountTreeControllerGetAccountWalletObjectAction,\n AccountTreeControllerGetAccountWalletObjectsAction,\n AccountTreeControllerGetAccountsFromSelectedAccountGroupAction,\n AccountTreeControllerGetAccountFromSelectedAccountGroupAction,\n AccountTreeControllerGetAccountGroupObjectAction,\n AccountTreeControllerGetAccountContextAction,\n AccountTreeControllerGetSelectedAccountGroupAction,\n AccountTreeControllerSetSelectedAccountGroupAction,\n AccountTreeControllerSetSelectedAccountGroupByAccountIdAction,\n AccountTreeControllerSetAccountGroupNameAction,\n AccountTreeControllerSetAccountWalletNameAction,\n AccountTreeControllerSetAccountGroupPinnedAction,\n AccountTreeControllerSetAccountGroupHiddenAction,\n AccountTreeControllerClearStateAction,\n AccountTreeControllerSyncWithUserStorageAction,\n AccountTreeControllerSyncWithUserStorageAtLeastOnceAction,\n AccountTreeControllerInitAction,\n AccountTreeControllerReinitAction,\n AccountTreeControllerExportStateAction,\n AccountTreeControllerImportStateAction,\n} from './AccountTreeController-method-action-types.js';\n\nexport type { AccountContext } from './AccountTreeController.js';\n\nexport {\n AccountTreeController,\n getDefaultAccountTreeControllerState,\n} from './AccountTreeController.js';\n\nexport type {\n AccountTreePayload,\n AccountTreePayloadStructType,\n AccountWalletMnemonicPayload,\n AccountWalletPrivateKeyPayload,\n AccountWalletMnemonicGroupEntry,\n AccountWalletPrivateKeyGroupEntry,\n AccountWalletPayloadId,\n AccountGroupPayloadId,\n AccountTreeSnapshotWallet,\n AccountTreeSnapshotGroup,\n ExportStateOptions,\n} from './state/payload.js';\n\nexport {\n AccountWalletPayloadType,\n AccountWalletPrivateKeyEncoding,\n AccountTreePayloadStruct,\n assertAccountTreePayload,\n} from './state/payload.js';\n\nexport { AccountTreeSnapshot } from './state/snapshot.js';\nexport { IdMap } from './state/id-map.js';\n"]}
|
package/dist/logger.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,0BAAiD,CAAC;AAC5E,eAAO,MAAM,mBAAmB,0BAG/B,CAAC"}
|
package/dist/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC,yBAAyB,CAAC,CAAC;AAC5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,kBAAkB,CACnD,aAAa,EACb,iBAAiB,CAClB,CAAC","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('account-tree-controller');\nexport const backupAndSyncLogger = createModuleLogger(\n projectLogger,\n 'Backup and sync',\n);\n"]}
|
package/dist/rule.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rule.d.ts","sourceRoot":"","sources":["../src/rule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAE9E,MAAM,MAAM,UAAU,CACpB,UAAU,SAAS,iBAAiB,EACpC,SAAS,SAAS,gBAAgB,IAChC;IACF,MAAM,EAAE;QACN,IAAI,EAAE,UAAU,CAAC;QACjB,EAAE,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAElC,QAAQ,EAAE,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,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","sourceRoot":"","sources":["../src/rule.ts"],"names":[],"mappings":"AA6FA,MAAM,OAAO,QAAQ;IAGnB,YAAY,SAAyC;QACnD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,2BAA2B,CAAC,KAAyB;QACnD,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CACjC,+BAA+B;QAC/B,kEAAkE;QAClE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAClB,CAAC;QAEF,OAAO,OAAO,EAAE,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACH,6DAA6D;IAC7D,4BAA4B,CAAC,MAA2B;QACtD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import type {\n AccountGroupType,\n AccountWalletType,\n} from '@metamask/account-api';\nimport type {\n AccountGroupIdOf,\n AccountWalletIdOf,\n} from '@metamask/account-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountGroupObject, AccountGroupObjectOf } from './group.js';\nimport type { AccountTreeControllerMessenger } from './types.js';\nimport type { AccountWalletObject, AccountWalletObjectOf } from './wallet.js';\n\nexport type RuleResult<\n WalletType extends AccountWalletType,\n GroupType extends AccountGroupType,\n> = {\n wallet: {\n type: WalletType;\n id: AccountWalletIdOf<WalletType>;\n // Omit `name` since it will get computed after the tree is built.\n metadata: Omit<AccountWalletObjectOf<WalletType>['metadata'], 'name'>;\n };\n group: {\n type: GroupType;\n id: AccountGroupIdOf<WalletType>;\n // Omit `name` since it will get computed after the tree is built.\n metadata: Omit<AccountGroupObjectOf<GroupType>['metadata'], 'name'>;\n };\n};\n\nexport type Rule<\n WalletType extends AccountWalletType,\n GroupType extends AccountGroupType,\n> = {\n /**\n * Account wallet type for this rule.\n */\n readonly walletType: WalletType;\n\n /**\n * Account group type for this rule.\n */\n readonly groupType: GroupType;\n\n /**\n * Applies the rule and check if the account matches.\n *\n * If the account matches, then the rule will return a {@link RuleResult} which means\n * this account needs to be grouped within a wallet associated with this rule.\n *\n * If a wallet already exists for this account (based on {@link RuleResult}) then\n * the account will be added to that wallet instance into its proper group (different for\n * every wallets).\n *\n * @param account - The account to match.\n * @returns A {@link RuleResult} if this account is part of that rule/wallet, returns\n * `undefined` otherwise.\n */\n match(\n account: InternalAccount,\n ): RuleResult<WalletType, GroupType> | undefined;\n\n /**\n * Gets default name for a wallet.\n *\n * @param wallet - Wallet associated to this rule.\n * @returns The default name for that wallet.\n */\n getDefaultAccountWalletName(\n wallet: AccountWalletObjectOf<WalletType>,\n ): string;\n\n /**\n * Gets computed name for a group based on its accounts.\n *\n * @param group - Group associated to this rule.\n * @returns The computed name based on existing accounts.\n */\n getComputedAccountGroupName(group: AccountGroupObjectOf<GroupType>): string;\n\n /**\n * Gets default name for a group based on its position in the wallet.\n *\n * @param wallet - Wallet associated to this rule.\n * @returns The default name prefix for groups of that wallet.\n */\n getDefaultAccountGroupPrefix(\n wallet: AccountWalletObjectOf<WalletType>,\n ): string;\n};\n\nexport class BaseRule {\n protected readonly messenger: AccountTreeControllerMessenger;\n\n constructor(messenger: AccountTreeControllerMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Gets computed name for a group based on its accounts.\n *\n * @param group - Group associated to this rule.\n * @returns The computed name based on existing accounts.\n */\n getComputedAccountGroupName(group: AccountGroupObject): string {\n const account = this.messenger.call(\n 'AccountsController:getAccount',\n // Type-wise, we are guaranteed to always have at least 1 account.\n group.accounts[0],\n );\n\n return account?.metadata.name ?? '';\n }\n\n /**\n * Gets default prefix name for a group.\n *\n * @param wallet - Wallet of this group.\n * @returns The default prefix name for that group.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n getDefaultAccountGroupPrefix(wallet: AccountWalletObject): string {\n return 'Account';\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entropy.d.ts","sourceRoot":"","sources":["../../src/rules/entrop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ichainAccountGroupId,\n toMultichainAccountWalletId,\n} from '@metamask/account-api';\nimport { isEvmAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountGroupObjectOf } from '../group.js';\nimport { BaseRule } from '../rule.js';\nimport type { Rule, RuleResult } from '../rule.js';\nimport type { AccountWalletObjectOf } from '../wallet.js';\n\nexport class EntropyRule\n extends BaseRule\n implements\n Rule<AccountWalletType.Entropy, AccountGroupType.MultichainAccount>\n{\n readonly walletType = AccountWalletType.Entropy;\n\n readonly groupType = AccountGroupType.MultichainAccount;\n\n getEntropySourceIndex(entropySource: string) {\n const { keyrings } = this.messenger.call('KeyringController:getState');\n\n return keyrings\n .filter((keyring) => keyring.type === (KeyringTypes.hd as string))\n .findIndex((keyring) => keyring.metadata.id === entropySource);\n }\n\n match(\n account: InternalAccount,\n ):\n | RuleResult<AccountWalletType.Entropy, AccountGroupType.MultichainAccount>\n | undefined {\n if (!isBip44Account(account)) {\n return undefined;\n }\n\n const entropySource = account.options.entropy.id;\n const entropySourceIndex = this.getEntropySourceIndex(entropySource);\n if (entropySourceIndex === -1) {\n console.warn(\n `! Found an unknown entropy ID: \"${entropySource}\", account \"${account.id}\" won't be grouped by entropy.`,\n );\n return undefined;\n }\n\n const walletId = toMultichainAccountWalletId(entropySource);\n const groupId = toMultichainAccountGroupId(\n walletId,\n account.options.entropy.groupIndex,\n );\n\n return {\n wallet: {\n type: this.walletType,\n id: walletId,\n metadata: {\n entropy: {\n id: entropySource,\n },\n },\n },\n\n group: {\n type: this.groupType,\n id: groupId,\n metadata: {\n entropy: {\n groupIndex: account.options.entropy.groupIndex,\n },\n pinned: false,\n hidden: false,\n lastSelected: 0,\n },\n },\n };\n }\n\n getDefaultAccountWalletName(\n wallet: AccountWalletObjectOf<AccountWalletType.Entropy>,\n ): string {\n // NOTE: We have checked during the rule matching, so we can safely assume it will\n // well-defined here.\n const entropySourceIndex = this.getEntropySourceIndex(\n wallet.metadata.entropy.id,\n );\n\n return `Wallet ${entropySourceIndex + 1}`; // Use human indexing (starts at 1).\n }\n\n getComputedAccountGroupName(\n group: AccountGroupObjectOf<AccountGroupType.MultichainAccount>,\n ): string {\n // Only use EVM account names for multichain groups to avoid chain-specific names becoming group names.\n // Non-EVM account names should not be used as group names since groups represent multichain collections.\n for (const id of group.accounts) {\n const account = this.messenger.call('AccountsController:getAccount', id);\n\n if (account && isEvmAccountType(account.type)) {\n return account.metadata.name;\n }\n }\n\n return '';\n }\n\n getDefaultAccountGroupPrefix(\n _wallet: AccountWalletObjectOf<AccountWalletType.Entropy>,\n ): string {\n return 'Account';\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyring.d.ts","sourceRoot":"","sources":["../../src/rules/keyring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D;;;;;GAKG;AACH,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,YAAY,GAAG,WAAW,GAC/B,MAAM,CAyCR;AAED;;;;;GAKG;AACH,wBAAgB,oCAAoC,CAClD,IAAI,EAAE,YAAY,GAAG,WAAW,GAC/B,MAAM,CAyCR;AAED,qB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;gBACN,IAAI,EAAE,IAAI,CAAC,UAAU;gBACrB,EAAE,EAAE,QAAQ;gBACZ,QAAQ,EAAE;oBACR,OAAO,EAAE;wBACP,IAAI,EAAE,WAAW;qBAClB;iBACF;aACF;YAED,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,SAAS;gBACpB,EAAE,EAAE,OAAO;gBACX,QAAQ,EAAE;oBACR,MAAM,EAAE,KAAK;oBACb,MAAM,EAAE,KAAK;oBACb,YAAY,EAAE,CAAC;iBAChB;aACF;SACF,CAAC;IACJ,CAAC;IAED,2BAA2B,CACzB,MAAwD;QAExD,OAAO,mCAAmC,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3E,CAAC;IAED,2BAA2B,CACzB,KAA2D;QAE3D,OAAO,KAAK,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IAED,4BAA4B,CAC1B,MAAwD;QAExD,OAAO,oCAAoC,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E,CAAC;CACF","sourcesContent":["import { AccountGroupType } from '@metamask/account-api';\nimport { AccountWalletType } from '@metamask/account-api';\nimport { toAccountGroupId, toAccountWalletId } from '@metamask/account-api';\nimport { KeyringType } from '@metamask/keyring-api/v2';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountGroupObjectOf } from '../group.js';\nimport { BaseRule } from '../rule.js';\nimport type { Rule, RuleResult } from '../rule.js';\nimport type { AccountWalletObjectOf } from '../wallet.js';\n\n/**\n * Get wallet name from a keyring type.\n *\n * @param type - Keyring's type.\n * @returns Wallet name.\n */\nexport function getAccountWalletNameFromKeyringType(\n type: KeyringTypes | KeyringType,\n): string {\n switch (type) {\n case KeyringType.PrivateKey:\n case KeyringTypes.simple: {\n return 'Imported accounts';\n }\n case KeyringType.Trezor:\n case KeyringTypes.trezor: {\n return 'Trezor';\n }\n case KeyringType.OneKey:\n case KeyringTypes.oneKey: {\n return 'OneKey';\n }\n case KeyringType.Ledger:\n case KeyringTypes.ledger: {\n return 'Ledger';\n }\n case KeyringType.Lattice:\n case KeyringTypes.lattice: {\n return 'Lattice';\n }\n case KeyringType.Qr:\n case KeyringTypes.qr: {\n return 'QR';\n }\n // Those keyrings should never really be used in such context since they\n // should be used by other grouping rules.\n case KeyringType.Hd:\n case KeyringTypes.hd: {\n return 'HD Wallet';\n }\n case KeyringType.Snap:\n case KeyringTypes.snap: {\n return 'Snap Wallet';\n }\n // ------------------------------------------------------------------------\n default: {\n return 'Unknown';\n }\n }\n}\n\n/**\n * Get group name prefix from a keyring type.\n *\n * @param type - Keyring's type.\n * @returns Wallet name.\n */\nexport function getAccountGroupPrefixFromKeyringType(\n type: KeyringTypes | KeyringType,\n): string {\n switch (type) {\n case KeyringType.PrivateKey:\n case KeyringTypes.simple: {\n return 'Imported Account';\n }\n case KeyringType.Trezor:\n case KeyringTypes.trezor: {\n return 'Trezor Account';\n }\n case KeyringType.OneKey:\n case KeyringTypes.oneKey: {\n return 'OneKey Account';\n }\n case KeyringType.Ledger:\n case KeyringTypes.ledger: {\n return 'Ledger Account';\n }\n case KeyringType.Lattice:\n case KeyringTypes.lattice: {\n return 'Lattice Account';\n }\n case KeyringType.Qr:\n case KeyringTypes.qr: {\n return 'QR Account';\n }\n // Those keyrings should never really be used in such context since they\n // should be used by other grouping rules.\n case KeyringType.Hd:\n case KeyringTypes.hd: {\n return 'Account';\n }\n case KeyringType.Snap:\n case KeyringTypes.snap: {\n return 'Snap Account';\n }\n // ------------------------------------------------------------------------\n default: {\n return 'Unknown Account';\n }\n }\n}\n\nexport class KeyringRule\n extends BaseRule\n implements Rule<AccountWalletType.Keyring, AccountGroupType.SingleAccount>\n{\n readonly walletType = AccountWalletType.Keyring;\n\n readonly groupType = AccountGroupType.SingleAccount;\n\n match(\n account: InternalAccount,\n // No `| undefined` return type for this rule, as it cannot fail.\n ): RuleResult<AccountWalletType.Keyring, AccountGroupType.SingleAccount> {\n // We assume that `type` is really a `KeyringTypes`.\n const keyringType = account.metadata.keyring.type as KeyringTypes;\n\n const walletId = toAccountWalletId(this.walletType, keyringType);\n const groupId = toAccountGroupId(walletId, account.address);\n\n return {\n wallet: {\n type: this.walletType,\n id: walletId,\n metadata: {\n keyring: {\n type: keyringType,\n },\n },\n },\n\n group: {\n type: this.groupType,\n id: groupId,\n metadata: {\n pinned: false,\n hidden: false,\n lastSelected: 0,\n },\n },\n };\n }\n\n getDefaultAccountWalletName(\n wallet: AccountWalletObjectOf<AccountWalletType.Keyring>,\n ): string {\n return getAccountWalletNameFromKeyringType(wallet.metadata.keyring.type);\n }\n\n getComputedAccountGroupName(\n group: AccountGroupObjectOf<AccountGroupType.SingleAccount>,\n ): string {\n return super.getComputedAccountGroupName(group);\n }\n\n getDefaultAccountGroupPrefix(\n wallet: AccountWalletObjectOf<AccountWalletType.Keyring>,\n ): string {\n return getAccountGroupPrefixFromKeyringType(wallet.metadata.keyring.type);\n }\n}\n"]}
|
package/dist/rules/snap.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snap.d.ts","sourceRoot":"","sources":["../../src/rules/snap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAItE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAc1D,qBAAa,QACX,SAAQ,QACR,YAAW,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,CAAC,aAAa,CAAC;;IAEvE,QAAQ,CAAC,UAAU,0BAA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ED,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;IACnE,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC;IAClD,MAAM,kBAAkB,GACtB,WAAW,KAAK,YAAY,CAAC,IAAI,IAAI,WAAW,KAAK,WAAW,CAAC,IAAI,CAAC;IAExE,OAAO,kBAAkB,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;AAC7D,CAAC","sourcesContent":["import { AccountGroupType, AccountWalletType } from '@metamask/account-api';\nimport { toAccountWalletId, toAccountGroupId } from '@metamask/account-api';\nimport { KeyringType } from '@metamask/keyring-api/v2';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { stripSnapPrefix } from '@metamask/snaps-utils';\n\nimport { BaseRule } from '../rule.js';\nimport type { Rule, RuleResult } from '../rule.js';\nimport type { AccountWalletObjectOf } from '../wallet.js';\nimport { getAccountGroupPrefixFromKeyringType } from './keyring.js';\n\n/**\n * Snap account type.\n */\ntype SnapAccount<Account extends InternalAccount> = Account & {\n metadata: Account['metadata'] & {\n snap: {\n id: SnapId;\n };\n };\n};\n\nexport class SnapRule\n extends BaseRule\n implements Rule<AccountWalletType.Snap, AccountGroupType.SingleAccount>\n{\n readonly walletType = AccountWalletType.Snap;\n\n readonly groupType = AccountGroupType.SingleAccount;\n\n match(\n account: InternalAccount,\n ):\n | RuleResult<AccountWalletType.Snap, AccountGroupType.SingleAccount>\n | undefined {\n if (!this.#isSnapAccount(account)) {\n return undefined;\n }\n\n const { id: snapId } = account.metadata.snap;\n\n const walletId = toAccountWalletId(this.walletType, snapId);\n const groupId = toAccountGroupId(walletId, account.address);\n\n return {\n wallet: {\n type: this.walletType,\n id: walletId,\n metadata: {\n snap: {\n id: snapId,\n },\n },\n },\n\n group: {\n type: this.groupType,\n id: groupId,\n metadata: {\n pinned: false,\n hidden: false,\n lastSelected: 0,\n },\n },\n };\n }\n\n getDefaultAccountWalletName(\n wallet: AccountWalletObjectOf<AccountWalletType.Snap>,\n ): string {\n const snapId = wallet.metadata.snap.id;\n const snap = this.messenger.call('SnapController:getSnap', snapId);\n const snapName = snap\n ? // TODO: Handle localization here, but that's a \"client thing\", so we don't have a `core` controller\n // to refer to.\n snap.manifest.proposedName\n : stripSnapPrefix(snapId);\n\n return snapName;\n }\n\n getDefaultAccountGroupPrefix(\n _wallet: AccountWalletObjectOf<AccountWalletType.Snap>,\n ): string {\n return getAccountGroupPrefixFromKeyringType(KeyringTypes.snap);\n }\n\n /**\n * Check if an account is a Snap account.\n *\n * @param account - The account to check.\n * @returns True if the account is a Snap account, false otherwise.\n */\n #isSnapAccount(\n account: InternalAccount,\n ): account is SnapAccount<InternalAccount> {\n const snapId = account.metadata.snap?.id;\n if (snapId === undefined) {\n return false;\n }\n\n const snap = this.messenger.call('SnapController:getSnap', snapId);\n if (snap === null) {\n return false;\n }\n\n const keyringType = account.metadata.keyring.type;\n const hasSnapKeyringType =\n keyringType === KeyringTypes.snap || keyringType === KeyringType.Snap;\n\n return hasSnapKeyringType && snap.enabled && !snap.blocked;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/state/export.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,8BAA8B,EAC9B,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC3B,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAMV,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGpD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,mBAAmB,GAC1B,MAAM,IAAI,0BAA0B,CAEtC;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,mBAAmB,GAC1B,MAAM,IAAI,0BAA0B,CAKtC;AAED,+CAA+C;AAC/C,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,0BAA0B,CAAC;IAC3C,SAAS,EAAE,8BAA8B,CAAC;CAC3C,CAAC;AAmMF;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,aAAa,EACtB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CA+D9B"}
|
package/dist/state/export.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/state/export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAW5D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AASpC,OAAO,EACL,wBAAwB,EACxB,+BAA+B,EAC/B,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAA2B;IAE3B,OAAO,MAAM,CAAC,IAAI,KAAK,iBAAiB,CAAC,OAAO,CAAC;AACnD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,MA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CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,iEAAiE;QACnE,CAAC;IACH,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,IAAI,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { AccountWalletType } from '@metamask/account-api';\nimport { HdKeyring } from '@metamask/eth-hd-keyring/v2';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { PrivateKeyExportedAccount } from '@metamask/keyring-api/v2';\nimport { KeyringTypes } from '@metamask/keyring-controller';\n\nimport type {\n AccountTreeControllerMessenger,\n AccountTreeControllerState,\n} from '../types.js';\nimport type { AccountWalletObject } from '../wallet.js';\nimport {\n AccountWalletEntropyObject,\n AccountWalletKeyringObject,\n} from '../wallet.js';\nimport { IdMap } from './id-map.js';\nimport type {\n AccountTreeWalletEntry,\n AccountWalletMnemonicGroupEntry,\n AccountWalletMnemonicPayload,\n AccountWalletPrivateKeyGroupEntry,\n AccountWalletPrivateKeyPayload,\n ExportStateOptions,\n} from './payload.js';\nimport {\n AccountWalletPayloadType,\n AccountWalletPrivateKeyEncoding,\n toWalletPayloadId,\n toGroupPayloadId,\n} from './payload.js';\nimport { AccountTreeSnapshot } from './snapshot.js';\nimport { encodeBytes } from './utils.js';\n\n/**\n * Returns `true` if `wallet` is an HD entropy wallet ({@link AccountWalletEntropyObject}).\n *\n * @param wallet - The wallet object to test.\n * @returns Type predicate narrowing to {@link AccountWalletEntropyObject}.\n */\nexport function isMnemonicWalletObject(\n wallet: AccountWalletObject,\n): wallet is AccountWalletEntropyObject {\n return wallet.type === AccountWalletType.Entropy;\n}\n\n/**\n * Returns `true` if `wallet` is an imported private-key wallet\n * ({@link AccountWalletKeyringObject} with keyring type {@link KeyringTypes.simple}).\n *\n * @param wallet - The wallet object to test.\n * @returns Type predicate narrowing to {@link AccountWalletKeyringObject}.\n */\nexport function isPrivateKeyWalletObject(\n wallet: AccountWalletObject,\n): wallet is AccountWalletKeyringObject {\n return (\n wallet.type === AccountWalletType.Keyring &&\n wallet.metadata.keyring.type === KeyringTypes.simple\n );\n}\n\n/** Context required by {@link exportState}. */\nexport type ExportContext = {\n getState: () => AccountTreeControllerState;\n messenger: AccountTreeControllerMessenger;\n};\n\n/**\n * Exports a single entropy (HD) wallet object as an {@link AccountWalletMnemonicPayload}.\n *\n * Calls `KeyringController:withKeyringV2Unsafe` to derive the stable entropy source ID\n * via {@link HdKeyring.toEntropySourceId} and, when `includeSecrets` is `true`, to read\n * the raw mnemonic bytes.\n *\n * @param context - Export context.\n * @param walletObj - The local entropy wallet to export.\n * @param includeSecrets - When `true`, the BIP-39 mnemonic is included in the payload.\n * @param idMap - ID map to populate with local↔payload ID pairs for this wallet and its groups.\n * @returns The mnemonic wallet payload entry.\n * @throws If `includeSecrets` is `true` but the mnemonic cannot be read from the keyring.\n */\nasync function exportMnemonicWalletObject(\n context: ExportContext,\n walletObj: AccountWalletEntropyObject,\n includeSecrets: boolean,\n idMap: IdMap,\n): Promise<AccountWalletMnemonicPayload> {\n const result = await context.messenger.call(\n 'KeyringController:withKeyringV2Unsafe',\n // The local wallet entropy ID is the keyring ID.\n { id: walletObj.metadata.entropy.id },\n async ({ keyring }) => {\n const hdKeyring = keyring as HdKeyring;\n const includeMnemonic =\n includeSecrets &&\n hdKeyring.mnemonic !== null &&\n hdKeyring.mnemonic !== undefined;\n\n return {\n // Compute the stable entropy source ID from the keyring's mnemonic (BIP-39 seed).\n entropySourceId: await hdKeyring.toEntropySourceId(),\n // No need to include the mnemonic here if we're not exporting secrets.\n mnemonic: includeMnemonic ? hdKeyring.mnemonic : undefined,\n };\n },\n );\n const { entropySourceId, mnemonic } = result as {\n entropySourceId: string;\n mnemonic?: Uint8Array;\n };\n\n // We use the stable entropy source ID as the payload wallet ID, rather than the local wallet ID, to\n // ensure that the exported snapshot is stable across different installations and sessions.\n const wallet: AccountWalletMnemonicPayload = {\n type: AccountWalletPayloadType.Mnemonic,\n id: toWalletPayloadId(entropySourceId),\n metadata: { name: walletObj.metadata.name },\n groups: [],\n };\n\n idMap.add(walletObj.id, wallet.id);\n\n for (const groupObj of Object.values(walletObj.groups)) {\n const { groupIndex } = groupObj.metadata.entropy;\n\n const group: AccountWalletMnemonicGroupEntry = {\n id: toGroupPayloadId(wallet.id, groupIndex),\n groupIndex,\n metadata: {\n name: groupObj.metadata.name,\n pinned: groupObj.metadata.pinned,\n hidden: groupObj.metadata.hidden,\n },\n };\n\n idMap.add(groupObj.id, group.id);\n\n wallet.groups.push(group);\n }\n\n // Sort the groups by their `groupIndex` to ensure a stable order in the exported payload.\n wallet.groups.sort(\n (group, otherGroup) => group.groupIndex - otherGroup.groupIndex,\n );\n\n // Defensive check: group indices must be contiguous starting at 0. This should never happen\n // in practice since groups are only ever appended, but guards against future regressions\n // producing a payload that silently fails validation on import.\n for (let i = 0; i < wallet.groups.length; i++) {\n if (wallet.groups[i]?.groupIndex !== i) {\n throw new Error('Found non-contiguous groups in mnemonic wallet');\n }\n }\n\n if (includeSecrets) {\n if (mnemonic === undefined) {\n throw new Error(`Failed to export mnemonic for wallet ${wallet.id}`);\n }\n\n wallet.value = encodeBytes(mnemonic);\n }\n\n return wallet;\n}\n\n/**\n * Exports a single simple-keyring wallet object as an {@link AccountWalletPrivateKeyPayload}.\n *\n * All groups from the wallet are merged into the `'private-key'` singleton payload entry.\n * When `includeSecrets` is `true`, each group's private key is exported via\n * `KeyringController:withKeyringV2`.\n *\n * @param context - Export context.\n * @param walletObj - The local simple-keyring wallet to export.\n * @param includeSecrets - When `true`, private keys are included in the payload.\n * @param idMap - ID map to populate with local↔payload ID pairs for this wallet and its groups.\n * @returns The private-key wallet payload entry.\n * @throws If `includeSecrets` is `true` but a private key cannot be exported for an account.\n */\nasync function exportPrivateKeyWalletObject(\n context: ExportContext,\n walletObj: AccountWalletKeyringObject,\n includeSecrets: boolean,\n idMap: IdMap,\n): Promise<AccountWalletPrivateKeyPayload> {\n // We use a singleton wallet ID for private keys.\n const wallet: AccountWalletPrivateKeyPayload = {\n type: AccountWalletPayloadType.PrivateKey,\n id: toWalletPayloadId(AccountWalletPayloadType.PrivateKey),\n metadata: { name: walletObj.metadata.name },\n groups: [],\n };\n\n for (const groupObj of Object.values(walletObj.groups)) {\n const accountId = groupObj.accounts[0];\n if (!accountId) {\n continue;\n }\n const account = context.messenger.call(\n 'AccountsController:getAccount',\n accountId,\n );\n if (!account) {\n continue;\n }\n\n const { address } = account;\n\n let exported: PrivateKeyExportedAccount | undefined;\n if (includeSecrets) {\n const result = await context.messenger.call(\n 'KeyringController:withKeyringV2',\n { address },\n async ({ keyring }) => {\n if (!keyring.exportAccount) {\n throw new Error(\n `Keyring for account ${accountId} does not support exportAccount`,\n );\n }\n\n return keyring.exportAccount(accountId, {\n type: 'private-key',\n encoding: AccountWalletPrivateKeyEncoding.Hexadecimal,\n });\n },\n );\n\n exported = result as PrivateKeyExportedAccount;\n }\n\n const group: AccountWalletPrivateKeyGroupEntry = {\n id: toGroupPayloadId(wallet.id, address),\n metadata: {\n name: groupObj.metadata.name,\n pinned: groupObj.metadata.pinned,\n hidden: groupObj.metadata.hidden,\n },\n };\n\n if (includeSecrets) {\n if (!exported) {\n throw new Error(\n `Failed to export private key for account ${accountId}`,\n );\n }\n group.value = {\n privateKey: encodeBytes(new TextEncoder().encode(exported.privateKey)),\n encoding: exported.encoding,\n type: EthAccountType.Eoa,\n };\n }\n\n idMap.add(groupObj.id, group.id);\n\n wallet.groups.push(group);\n }\n\n return wallet;\n}\n\n/**\n * Builds an {@link AccountTreeSnapshot} from the current controller state.\n *\n * Iterates over all wallets in the tree:\n * - {@link AccountWalletType.Entropy} (HD) wallets -> `'mnemonic'` payload entries.\n * - {@link AccountWalletType.Keyring} wallets of type `simple` -> `'private-key'` payload entries.\n * - Snap wallets and hardware keyrings are skipped in v1.\n *\n * @param context - Export context providing state and messenger access.\n * @param options - Export options.\n * @returns A promise that resolves to the built snapshot.\n * @throws If the vault is locked.\n */\nexport async function exportState(\n context: ExportContext,\n options: ExportStateOptions = {},\n): Promise<AccountTreeSnapshot> {\n const state = context.getState();\n\n const { isUnlocked } = context.messenger.call('KeyringController:getState');\n if (!isUnlocked) {\n throw new Error('Cannot export account tree when vault is locked');\n }\n\n // Use `options` here to let the compiler infer the type of `includeSecrets` based on the\n // discriminated union.\n if (options.includeSecrets) {\n // We verify the password here to force consumers to have it in their flow\n // before calling exportState. The password is never stored, so the only\n // way to supply it is to ask the user, ensuring they are prompted upstream\n // rather than having the export silently succeed without their interaction.\n await context.messenger.call(\n 'KeyringController:verifyPassword',\n options.password,\n );\n }\n\n const includeSecrets = options.includeSecrets ?? false;\n\n const idMap = new IdMap();\n const entries: AccountTreeWalletEntry[] = [];\n let privateKeyWallet: AccountWalletPrivateKeyPayload | undefined;\n\n for (const walletObj of Object.values(state.accountTree.wallets)) {\n if (isMnemonicWalletObject(walletObj)) {\n entries.push(\n await exportMnemonicWalletObject(\n context,\n walletObj,\n includeSecrets,\n idMap,\n ),\n );\n } else if (isPrivateKeyWalletObject(walletObj)) {\n const exported = await exportPrivateKeyWalletObject(\n context,\n walletObj,\n includeSecrets,\n idMap,\n );\n\n if (privateKeyWallet) {\n privateKeyWallet.groups.push(...exported.groups);\n } else {\n privateKeyWallet = exported;\n\n // Register only once, since all private keys are exported into the same wallet entry.\n idMap.add(walletObj.id, exported.id);\n }\n } else {\n // AccountWalletType.Snap and hardware keyrings: skipped for now.\n }\n }\n\n if (privateKeyWallet) {\n entries.push(privateKeyWallet);\n }\n\n return new AccountTreeSnapshot(entries, idMap);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"id-map.d.ts","sourceRoot":"","sources":["../../src/state/id-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAA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AAA,IAAI,6BAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,EAClC,gCAAgC,OAAO,EAAE,CAC1C,CAAC;QACF,MAAM,CACJ,CAAC,uBAAA,IAAI,6BAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,EACpC,kCAAkC,SAAS,EAAE,CAC9C,CAAC;QACF,uBAAA,IAAI,6BAAgB,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC7C,uBAAA,IAAI,6BAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,OAAgB;QAC3B,OAAO,uBAAA,IAAI,6BAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,SAAoB;QAC7B,OAAO,uBAAA,IAAI,6BAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC;CACF","sourcesContent":["import type { AccountGroupId, AccountWalletId } from '@metamask/account-api';\nimport { assert } from '@metamask/utils';\n\nimport type {\n AccountGroupPayloadId,\n AccountWalletPayloadId,\n} from './payload.js';\n\ntype LocalId = AccountWalletId | AccountGroupId;\ntype PayloadId = AccountWalletPayloadId | AccountGroupPayloadId;\n\n/**\n * Bidirectional map between local controller IDs and portable payload IDs.\n *\n * Populated during {@link exportState} so that callers can bridge between\n * device-local wallet/group IDs and the stable cross-device IDs that appear\n * in a serialized {@link AccountTreePayload}.\n */\nexport class IdMap {\n readonly #localToPayload: Map<LocalId, PayloadId> = new Map();\n\n readonly #payloadToLocal: Map<PayloadId, LocalId> = new Map();\n\n /**\n * @param entries - Optional seed pairs `[localId, payloadId]` to pre-populate the map.\n */\n constructor(entries: [localId: LocalId, payloadId: PayloadId][] = []) {\n for (const [localId, payloadId] of entries) {\n this.add(localId, payloadId);\n }\n }\n\n /**\n * Registers a local↔payload ID pair.\n *\n * @param localId - Local controller wallet or group ID.\n * @param payloadId - Corresponding portable payload ID.\n */\n add(localId: LocalId, payloadId: PayloadId): void {\n // Each local ID maps to exactly one payload ID and vice versa: wallet and\n // group IDs are unique by construction, so a duplicate signals a bug in the\n // caller (e.g. exportState visiting the same node twice).\n assert(\n !this.#localToPayload.has(localId),\n `Local ID already registered: ${localId}`,\n );\n assert(\n !this.#payloadToLocal.has(payloadId),\n `Payload ID already registered: ${payloadId}`,\n );\n this.#localToPayload.set(localId, payloadId);\n this.#payloadToLocal.set(payloadId, localId);\n }\n\n /**\n * Returns the portable payload ID for a given local ID.\n *\n * @param localId - Local controller wallet or group ID.\n * @returns The payload ID, or `undefined` if not registered.\n */\n getPayloadId(localId: LocalId): PayloadId | undefined {\n return this.#localToPayload.get(localId);\n }\n\n /**\n * Returns the local controller ID for a given payload ID.\n *\n * @param payloadId - Portable payload ID.\n * @returns The local wallet or group ID, or `undefined` if not registered.\n */\n getLocalId(payloadId: PayloadId): LocalId | undefined {\n return this.#payloadToLocal.get(payloadId);\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/state/import.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAM7E,OAAO,KAAK,EACV,8BAA8B,EAC9B,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AAiBrB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGzD,+CAA+C;AAC/C,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,0BAA0B,CAAC;IAC3C,SAAS,EAAE,8BAA8B,CAAC;IAC1C,aAAa,EAAE,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjE,oFAAoF;IACpF,mBAAmB,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM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AE,CAAC;YAChB,SAAS;QACX,CAAC;QACD,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAsB,EACtB,QAA6B;IAE7B,MAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;IAErC,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACrC,IAAI,MAAM,CAAC,IAAI,KAAK,wBAAwB,CAAC,QAAQ,EAAE,CAAC;YACtD,MAAM,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,MAAM,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import {\n AccountWalletType,\n toAccountGroupId,\n toAccountWalletId,\n toMultichainAccountGroupId,\n} from '@metamask/account-api';\nimport type { AccountGroupId, AccountWalletId } from '@metamask/account-api';\nimport { getUUIDFromAddressOfNormalAccount } from '@metamask/accounts-controller';\nimport { HdKeyring } from '@metamask/eth-hd-keyring/v2';\nimport { EthAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\n\nimport type {\n AccountTreeControllerMessenger,\n AccountTreeControllerState,\n} from '../types.js';\nimport type {\n AccountWalletEntropyObject,\n AccountWalletKeyringObject,\n} from '../wallet.js';\nimport { isMnemonicWalletObject } from './export.js';\nimport type {\n AccountWalletMnemonicGroupEntry,\n AccountWalletMnemonicPayload,\n AccountWalletPayloadId,\n AccountWalletPrivateKeyGroupEntry,\n} from './payload.js';\nimport {\n AccountWalletPayloadType,\n parsePayloadGroupId,\n toWalletPayloadId,\n} from './payload.js';\nimport type { AccountTreeSnapshot } from './snapshot.js';\nimport { decodeBytes } from './utils.js';\n\n/** Context required by {@link importState}. */\nexport type ImportContext = {\n getState: () => AccountTreeControllerState;\n messenger: AccountTreeControllerMessenger;\n setWalletName: (walletId: AccountWalletId, name: string) => void;\n /** Sets a group name. Implementations must resolve name conflicts automatically. */\n setAccountGroupName: (groupId: AccountGroupId, name: string) => void;\n setAccountGroupPinned: (groupId: AccountGroupId, pinned: boolean) => void;\n setAccountGroupHidden: (groupId: AccountGroupId, hidden: boolean) => void;\n};\n\n/**\n * Searches the local wallet tree for an entropy wallet whose stable payload ID\n * matches `payloadWalletId`. The entropy source ID is derived on-the-fly via\n * `KeyringController:withKeyringV2Unsafe` rather than relying on cached metadata.\n *\n * @param context - Import context.\n * @param payloadWalletId - Payload wallet ID to match against.\n * @returns The matching local entropy wallet, or `undefined` if not found.\n */\nasync function findLocalWalletMnemonicFromPayloadId(\n context: ImportContext,\n payloadWalletId: AccountWalletPayloadId,\n): Promise<AccountWalletEntropyObject | undefined> {\n const wallets = Object.values(context.getState().accountTree.wallets);\n\n for (const wallet of wallets) {\n if (isMnemonicWalletObject(wallet)) {\n const result = await context.messenger.call(\n 'KeyringController:withKeyringV2Unsafe',\n { id: wallet.metadata.entropy.id },\n async ({ keyring }) => {\n const hdKeyring = keyring as HdKeyring;\n\n return toWalletPayloadId(await hdKeyring.toEntropySourceId());\n },\n );\n\n const localPayloadId = result as AccountWalletPayloadId;\n if (localPayloadId === payloadWalletId) {\n return wallet;\n }\n }\n }\n\n return undefined;\n}\n\n/**\n * Returns the local entropy wallet for the given ID.\n *\n * @param context - Import context.\n * @param id - Local wallet ID.\n * @returns The entropy wallet object.\n * @throws If the wallet is not found or is not an entropy wallet.\n */\nfunction findLocalWalletMnemonicFromId(\n context: ImportContext,\n id: AccountWalletId,\n): AccountWalletEntropyObject {\n const localWallets = context.getState().accountTree.wallets;\n const localWallet = localWallets[id];\n\n if (!localWallet) {\n throw new Error(\n `Failed to import mnemonic wallet: wallet not found after creation`,\n );\n }\n if (!isMnemonicWalletObject(localWallet)) {\n throw new Error(\n `Failed to import mnemonic wallet: wallet is not of type 'mnemonic'`,\n );\n }\n return localWallet;\n}\n\n/**\n * Returns the local simple-keyring wallet, or `undefined` if none exists yet.\n *\n * The private-key wallet ID is static (derived solely from {@link KeyringTypes.simple}),\n * so no runtime argument is needed to locate it.\n *\n * @param context - Import context.\n * @returns The keyring wallet object, or `undefined` if not present in state.\n */\nfunction findLocalWalletPrivateKey(\n context: ImportContext,\n): AccountWalletKeyringObject | undefined {\n const localWalletId = toAccountWalletId(\n AccountWalletType.Keyring,\n KeyringTypes.simple,\n );\n const localWallet = context.getState().accountTree.wallets[localWalletId];\n return localWallet?.type === AccountWalletType.Keyring\n ? localWallet\n : undefined;\n}\n\n/**\n * Returns `true` if the given payload group is already present in the local simple-keyring wallet.\n *\n * @param localWallet - The local simple-keyring wallet, or `undefined` if none exists yet.\n * @param group - The payload group entry to check.\n * @returns Whether the group's account is already tracked locally.\n */\nfunction hasLocalGroupPrivateKey(\n localWallet: AccountWalletKeyringObject | undefined,\n group: AccountWalletPrivateKeyGroupEntry,\n): boolean {\n const address = parsePayloadGroupId(group.id).subId;\n\n const localWalletId = toAccountWalletId(\n AccountWalletType.Keyring,\n KeyringTypes.simple,\n );\n const localGroupId = toAccountGroupId(localWalletId, address);\n const localGroup = localWallet?.groups[localGroupId];\n\n const accountId = getUUIDFromAddressOfNormalAccount(address);\n\n return localGroup?.accounts.some((id) => id === accountId) ?? false;\n}\n\n/**\n * Applies name, pinned, and hidden metadata from a payload group entry to a local group.\n *\n * @param context - Import context providing the metadata setters.\n * @param localGroupId - Local group ID to update.\n * @param payloadGroupMetadata - Metadata from the payload group entry.\n */\nfunction setGroupMetadata(\n context: ImportContext,\n localGroupId: AccountGroupId,\n payloadGroupMetadata: AccountWalletMnemonicGroupEntry['metadata'],\n): void {\n context.setAccountGroupName(localGroupId, payloadGroupMetadata.name);\n context.setAccountGroupPinned(localGroupId, payloadGroupMetadata.pinned);\n context.setAccountGroupHidden(localGroupId, payloadGroupMetadata.hidden);\n}\n\n/**\n * Computes the contiguous ranges of group indices that are present in the payload\n * but absent from the local wallet, so they can be created in batches.\n *\n * @param localWallet - The local entropy wallet to check existing groups against.\n * @param payloadGroups - Ordered group entries from the payload.\n * @returns An array of `[fromGroupIndex, toGroupIndex]` ranges to create.\n */\nfunction getRangesFromPayloadGroups(\n localWallet: AccountWalletEntropyObject,\n payloadGroups: AccountWalletMnemonicGroupEntry[],\n): [number, number][] {\n let rangeIndex: number | undefined;\n const ranges: [number, number][] = [];\n\n // Keep track of the last payload group so we can close the final range if needed.\n let lastPayloadGroup: AccountWalletMnemonicGroupEntry | undefined;\n for (const payloadGroup of payloadGroups) {\n const localGroupId = toMultichainAccountGroupId(\n localWallet.id,\n payloadGroup.groupIndex,\n );\n\n if (localWallet.groups[localGroupId]) {\n if (rangeIndex !== undefined) {\n ranges.push([rangeIndex, payloadGroup.groupIndex - 1]);\n rangeIndex = undefined;\n }\n continue;\n }\n\n rangeIndex ??= payloadGroup.groupIndex;\n lastPayloadGroup = payloadGroup;\n }\n\n if (rangeIndex !== undefined && lastPayloadGroup !== undefined) {\n ranges.push([rangeIndex, lastPayloadGroup.groupIndex]);\n }\n\n return ranges;\n}\n\n/**\n * Applies a mnemonic wallet payload entry to the local state.\n *\n * If no local wallet with the same entropy source ID exists and a mnemonic is\n * present in the payload, a new HD wallet is created via\n * `MultichainAccountService:createMultichainAccountWallet`. Missing groups are\n * created in batches via `MultichainAccountService:createMultichainAccountGroups`.\n * Metadata (name, pinned, hidden) is applied to all groups afterward.\n *\n * @param context - Import context.\n * @param payloadWallet - The mnemonic wallet entry from the payload.\n */\nasync function importMnemonicWallet(\n context: ImportContext,\n payloadWallet: AccountWalletMnemonicPayload,\n): Promise<void> {\n // Find the local wallet with the same entropy source ID if it exists.\n let localWallet = await findLocalWalletMnemonicFromPayloadId(\n context,\n payloadWallet.id,\n );\n\n if (!localWallet) {\n if (!payloadWallet.value) {\n // No mnemonic in payload and wallet doesn't exist locally -- nothing to do.\n return;\n }\n\n // Import the mnemonic as a new HD wallet.\n const mnemonic = decodeBytes(payloadWallet.value);\n const { id } = await context.messenger.call(\n 'MultichainAccountService:createMultichainAccountWallet',\n { type: 'import', mnemonic },\n );\n\n // Event handlers fire synchronously, so the wallet is in the tree now.\n localWallet = findLocalWalletMnemonicFromId(context, id);\n }\n\n context.setWalletName(localWallet.id, payloadWallet.metadata.name);\n\n // Apply metadata to groups that are already present locally before attempting\n // to create missing ones. If createMultichainAccountGroups throws partway\n // through, these groups would otherwise be left without their payload metadata.\n const localExistingGroupIds = new Set(Object.keys(localWallet.groups));\n for (const payloadGroup of payloadWallet.groups) {\n const localGroupId = toMultichainAccountGroupId(\n localWallet.id,\n payloadGroup.groupIndex,\n );\n if (localExistingGroupIds.has(localGroupId)) {\n setGroupMetadata(context, localGroupId, payloadGroup.metadata);\n }\n }\n\n for (const range of getRangesFromPayloadGroups(\n localWallet,\n payloadWallet.groups,\n )) {\n await context.messenger.call(\n 'MultichainAccountService:createMultichainAccountGroups',\n {\n entropySource: localWallet.metadata.entropy.id,\n fromGroupIndex: range[0],\n toGroupIndex: range[1],\n },\n );\n }\n\n // Re-read wallet after groups creation.\n localWallet = findLocalWalletMnemonicFromId(context, localWallet.id);\n\n // Apply metadata to newly created groups. Skip groups that were already\n // handled above, and guard against groups that failed to be created so a\n // partial failure doesn't throw and abort the rest of the snapshot import.\n for (const payloadGroup of payloadWallet.groups) {\n const localGroupId = toMultichainAccountGroupId(\n localWallet.id,\n payloadGroup.groupIndex,\n );\n if (\n localExistingGroupIds.has(localGroupId) ||\n !localWallet.groups[localGroupId]\n ) {\n continue;\n }\n setGroupMetadata(context, localGroupId, payloadGroup.metadata);\n }\n}\n\n/**\n * Applies private-key wallet group entries from the payload to the local state.\n *\n * For each group the account address is derived from the payload group ID. If the\n * account does not yet exist locally and a private key is provided, it is imported\n * via `KeyringController:withKeyringV2` using the `'private-key:import'` constructor.\n * Metadata (name, pinned, hidden) is then applied to the local group.\n *\n * @param context - Import context.\n * @param payloadGroups - Private-key group entries from the payload.\n */\nasync function importPrivateKeyWallet(\n context: ImportContext,\n payloadGroups: AccountWalletPrivateKeyGroupEntry[],\n): Promise<void> {\n const localWalletId = toAccountWalletId(\n AccountWalletType.Keyring,\n KeyringTypes.simple,\n );\n\n // Only EVM EOA accounts are supported for now. Non-EVM private keys require\n // Snap-based import routing (ADR-0007), which is not yet implemented. Skip the\n // entire entry so payloads from future clients are accepted without crashing.\n // In the same pass, collect groups whose key is not yet present locally.\n const localWallet = findLocalWalletPrivateKey(context);\n const supportedGroups: AccountWalletPrivateKeyGroupEntry[] = [];\n const missingGroups: AccountWalletPrivateKeyGroupEntry[] = [];\n\n for (const group of payloadGroups) {\n const type = group.value?.type;\n if (type !== undefined && type !== EthAccountType.Eoa) {\n continue;\n }\n\n supportedGroups.push(group);\n\n if (\n !hasLocalGroupPrivateKey(localWallet, group) &&\n group.value !== undefined\n ) {\n missingGroups.push(group);\n }\n }\n\n // Import all missing keys in a single :withController call to avoid\n // triggering multiple `KeyringController:stateChanged` events.\n if (missingGroups.length > 0) {\n await context.messenger.call(\n 'KeyringController:withController',\n async (controller) => {\n // Find the existing simple keyring or create one if this is the\n // first private-key import (e.g. during onboarding).\n const existing = controller.keyrings.find(\n ({ keyring }) => keyring.type === KeyringTypes.simple,\n );\n const { keyringV2 } =\n existing ?? (await controller.addNewKeyring(KeyringTypes.simple));\n\n if (!keyringV2) {\n throw new Error('Simple keyring has no v2 interface');\n }\n\n for (const group of missingGroups) {\n // Safe to assert `group.value` is present because we filtered out groups\n // without a `value` above.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { privateKey: privateKeyBytes, encoding } = group.value!;\n const privateKey = new TextDecoder().decode(\n decodeBytes(privateKeyBytes),\n );\n const [account] = await keyringV2.createAccounts({\n type: 'private-key:import',\n accountType: EthAccountType.Eoa,\n privateKey,\n encoding,\n });\n\n if (!account) {\n throw new Error('Failed to import private key for account');\n }\n }\n },\n );\n }\n\n // Re-read state once after all imports, then apply metadata to every group\n // that now exists locally.\n for (const group of supportedGroups) {\n const address = parsePayloadGroupId(group.id).subId;\n const localGroupId = toAccountGroupId(localWalletId, address);\n const localGroup = findLocalWalletPrivateKey(context)?.groups[localGroupId];\n if (!localGroup) {\n continue;\n }\n setGroupMetadata(context, localGroup.id, group.metadata);\n }\n}\n\n/**\n * Applies an {@link AccountTreeSnapshot} to the current controller state.\n *\n * The snapshot must already have been validated — typically via\n * {@link AccountTreeSnapshot.deserialize}. For each retained wallet:\n *\n * - `'mnemonic'`: imports the mnemonic when provided and not already present,\n * then applies metadata to all groups.\n * - `'private-key'`: imports each retained group's key when provided and not\n * already present, then applies metadata.\n *\n * @param context - Import context providing state, messenger, and setters.\n * @param snapshot - The validated snapshot to import.\n */\nexport async function importState(\n context: ImportContext,\n snapshot: AccountTreeSnapshot,\n): Promise<void> {\n const payload = snapshot.serialize();\n\n for (const wallet of payload.wallets) {\n if (wallet.type === AccountWalletPayloadType.Mnemonic) {\n await importMnemonicWallet(context, wallet);\n } else {\n await importPrivateKeyWallet(context, wallet.groups);\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../src/state/payload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAiB5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG7D,iFAAiF;AACjF,MAAM,MAAM,sBAAsB,GAAG,UAAU,MAAM,EAAE,CAAC;AAExD,6FAA6F;AAC7F,MAAM,MAAM,qBAAqB,GAAG,GAAG,sBAAsB,IAAI,MAAM,EAAE,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,0CAA0C;IAC1C,QAAQ,EAAE,sBAA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AAC;QACD,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { KeyringAccountTypeStruct } from '@metamask/keyring-api';\nimport type { KeyringAccount } from '@metamask/keyring-api';\nimport {\n array,\n assert,\n boolean,\n define,\n enums,\n integer,\n literal,\n object,\n exactOptional,\n refine,\n sensitive,\n string,\n StructError,\n union,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\n\nimport type { DeepReadonly, EncodedBytes } from './utils.js';\nimport { BytesStruct, formatValidationErrorMessages } from './utils.js';\n\n/** Stable cross-device wallet identifier. Format: `wallet:<entropySourceId>`. */\nexport type AccountWalletPayloadId = `wallet:${string}`;\n\n/** Stable cross-device group identifier. Format: `wallet:<entropySourceId>/<groupSubId>`. */\nexport type AccountGroupPayloadId = `${AccountWalletPayloadId}/${string}`;\n\n/**\n * Parsed representation of an {@link AccountGroupPayloadId}.\n */\nexport type ParsedPayloadGroupId = {\n /** The wallet portion of the group ID. */\n walletId: AccountWalletPayloadId;\n /** The group-specific sub-ID (e.g. group index for mnemonic wallets, address for private-key wallets). */\n subId: string;\n};\n\nconst PAYLOAD_GROUP_ID_REGEX = /^(?<walletId>wallet:[^/]+)\\/(?<subId>.+)$/u;\n\n/**\n * Parses a payload group ID into its wallet ID and group sub-ID components.\n *\n * @param groupId - The payload group ID to parse.\n * @returns The parsed wallet ID and group sub-ID.\n * @throws If the group ID format is invalid.\n */\nexport function parsePayloadGroupId(\n groupId: AccountGroupPayloadId,\n): ParsedPayloadGroupId {\n const match = PAYLOAD_GROUP_ID_REGEX.exec(groupId);\n if (!match?.groups) {\n throw new Error(`Invalid payload group ID: \"${groupId}\"`);\n }\n return {\n walletId: match.groups.walletId as AccountWalletPayloadId,\n subId: match.groups.subId,\n };\n}\n\n/**\n * Wallet type discriminants used in serialized {@link AccountTreePayload} entries.\n *\n * Use these constants instead of raw string literals so callers get autocomplete\n * and a single source of truth for the discriminant values.\n */\nexport const AccountWalletPayloadType = {\n Mnemonic: 'mnemonic',\n PrivateKey: 'private-key',\n} as const;\n\nexport type AccountWalletPayloadType =\n (typeof AccountWalletPayloadType)[keyof typeof AccountWalletPayloadType];\n\n/** Wallet-level metadata carried in every payload wallet entry. */\nexport type AccountWalletPayloadMetadata = { name: string };\n\n/** Group-level metadata carried in every payload group entry. */\nexport type AccountWalletGroupPayloadMetadata = {\n name: string;\n pinned: boolean;\n hidden: boolean;\n};\n\n/** A single group entry inside an {@link AccountWalletMnemonicPayload}. */\nexport type AccountWalletMnemonicGroupEntry = {\n /** Stable group payload ID. Format: `<walletPayloadId>/<groupIndex>`. */\n id: AccountGroupPayloadId;\n /** BIP-44 account index this group was derived at. */\n groupIndex: number;\n metadata: AccountWalletGroupPayloadMetadata;\n};\n\n/**\n * Encoding formats for exported private key material.\n */\nexport const AccountWalletPrivateKeyEncoding = {\n Hexadecimal: 'hexadecimal',\n Base58: 'base58',\n Base32: 'base32',\n} as const;\n\nexport type AccountWalletPrivateKeyEncoding =\n (typeof AccountWalletPrivateKeyEncoding)[keyof typeof AccountWalletPrivateKeyEncoding];\n\n/** A single group entry inside an {@link AccountWalletPrivateKeyPayload}. */\nexport type AccountWalletPrivateKeyGroupEntry = {\n /** Stable group payload ID. Format: `wallet:private-key/<address>`. */\n id: AccountGroupPayloadId;\n /**\n * Private key material. Shape matches `ExportedAccount` from `@metamask/keyring-api/v2`\n * so the importer knows how to decode the key without additional out-of-band information.\n * Absent in metadata-only exports.\n */\n value?: {\n privateKey: EncodedBytes;\n encoding: AccountWalletPrivateKeyEncoding;\n /**\n * Account type from `KeyringAccountType` (e.g. `'eip155:eoa'`, `'bip122:p2wpkh'`).\n * Absent for EVM accounts -- import via `SimpleKeyring`.\n * Present for non-EVM accounts -- routing to the BIP-44 Snap handling this type is not yet implemented.\n */\n type?: KeyringAccount['type'];\n };\n metadata: AccountWalletGroupPayloadMetadata;\n};\n\n/** Payload entry for an HD (entropy) wallet and its derived account groups. */\nexport type AccountWalletMnemonicPayload = {\n id: AccountWalletPayloadId;\n type: typeof AccountWalletPayloadType.Mnemonic;\n /** BIP-39 mnemonic phrase encoded as bytes. Absent in metadata-only exports. */\n value?: EncodedBytes;\n metadata: AccountWalletPayloadMetadata;\n groups: AccountWalletMnemonicGroupEntry[];\n};\n\n/**\n * Payload entry for all imported private-key accounts.\n *\n * All local simple-keyring wallets are merged into this single entry;\n * each account is represented as a separate group entry keyed by address.\n */\nexport type AccountWalletPrivateKeyPayload = {\n id: AccountWalletPayloadId;\n type: typeof AccountWalletPayloadType.PrivateKey;\n metadata: AccountWalletPayloadMetadata;\n groups: AccountWalletPrivateKeyGroupEntry[];\n};\n\n/** Union of all wallet entry types that can appear in an {@link AccountTreePayload}. */\nexport type AccountTreeWalletEntry =\n | AccountWalletMnemonicPayload\n | AccountWalletPrivateKeyPayload;\n\n/** Portable snapshot of the full account tree state (flat versioned format). */\nexport type AccountTreePayload = {\n version: number;\n wallets: AccountTreeWalletEntry[];\n};\n\n/**\n * Deeply read-only wallet view passed to {@link AccountTreeSnapshot.filterWallets}\n * and {@link AccountTreeSnapshot.filterAllGroups} predicates.\n *\n * Entries are deep-cloned and deep-frozen when a snapshot is constructed, so\n * callers cannot mutate wallet IDs, types, secrets, metadata, or groups.\n */\nexport type AccountTreeSnapshotWallet = DeepReadonly<\n AccountWalletMnemonicPayload | AccountWalletPrivateKeyPayload\n>;\n\n/**\n * Deeply read-only group view passed to {@link AccountTreeSnapshot.filterGroups}\n * and {@link AccountTreeSnapshot.filterAllGroups} predicates.\n *\n * Entries are deep-cloned and deep-frozen when a snapshot is constructed, so\n * callers cannot mutate group IDs, secrets, metadata, or parent wallet references.\n */\nexport type AccountTreeSnapshotGroup = DeepReadonly<\n AccountWalletMnemonicGroupEntry | AccountWalletPrivateKeyGroupEntry\n>;\n\n/**\n * Constructs an {@link AccountWalletPayloadId} from an entropy source ID.\n *\n * @param entropySourceId - Stable entropy source ID returned by `HdKeyring.toEntropySourceId()`.\n * @returns The portable wallet payload ID.\n */\nexport function toWalletPayloadId(\n entropySourceId: string,\n): AccountWalletPayloadId {\n return `wallet:${entropySourceId}`;\n}\n\n/**\n * Constructs an {@link AccountGroupPayloadId} from a wallet payload ID and a sub-ID.\n *\n * @param walletId - The wallet payload ID this group belongs to.\n * @param subId - The group-specific sub-ID (e.g. group index for mnemonic wallets, address for private-key wallets).\n * @returns The portable group payload ID.\n */\nexport function toGroupPayloadId(\n walletId: AccountWalletPayloadId,\n subId: string | number,\n): AccountGroupPayloadId {\n return `${walletId}/${subId}`;\n}\n\n/** Options accepted by {@link AccountTreeController.exportState}. */\nexport type ExportStateOptions =\n | {\n /** When `true`, secrets (mnemonic / private keys) are included in the snapshot. */\n includeSecrets: true;\n /** Password verified against the vault before any secret is read. */\n password: string;\n }\n | {\n /** When `false` or omitted, only metadata is exported — no password needed. */\n includeSecrets?: false;\n password?: never;\n };\n\nconst AccountWalletPayloadIdStruct = define<AccountWalletPayloadId>(\n 'AccountWalletPayloadId',\n (value) =>\n typeof value === 'string' && value.startsWith('wallet:')\n ? true\n : 'Expected a wallet payload ID starting with \"wallet:\"',\n);\n\nconst AccountGroupPayloadIdStruct = define<AccountGroupPayloadId>(\n 'AccountGroupPayloadId',\n (value) =>\n typeof value === 'string' && PAYLOAD_GROUP_ID_REGEX.test(value)\n ? true\n : 'Expected a group payload ID in the form \"wallet:<id>/<subId>\"',\n);\n\nconst AccountWalletPayloadMetadataStruct = object({\n name: string(),\n});\n\nconst AccountWalletGroupPayloadMetadataStruct = object({\n name: string(),\n pinned: boolean(),\n hidden: boolean(),\n});\n\nconst AccountWalletPrivateKeyValueStruct = object({\n privateKey: sensitive(BytesStruct),\n encoding: enums(Object.values(AccountWalletPrivateKeyEncoding)),\n type: exactOptional(KeyringAccountTypeStruct),\n});\n\nconst AccountWalletMnemonicGroupEntryStruct = object({\n id: AccountGroupPayloadIdStruct,\n groupIndex: integer(),\n metadata: AccountWalletGroupPayloadMetadataStruct,\n});\n\nconst AccountWalletPrivateKeyGroupEntryStruct = object({\n id: AccountGroupPayloadIdStruct,\n value: exactOptional(AccountWalletPrivateKeyValueStruct),\n metadata: AccountWalletGroupPayloadMetadataStruct,\n});\n\n// The `groups` array in a mnemonic wallet payload must have contiguous group indices starting at 0.\nconst AccountWalletMnemonicGroupsStruct = refine(\n array(AccountWalletMnemonicGroupEntryStruct),\n 'contiguous-group-indices',\n (groups) => {\n let prev: AccountWalletMnemonicGroupEntry | undefined;\n for (const curr of groups) {\n if (prev === undefined && curr.groupIndex !== 0) {\n return `group indices must start at 0; got ${curr.groupIndex}`;\n }\n if (prev !== undefined && curr.groupIndex !== prev.groupIndex + 1) {\n return `group indices must be contiguous and sorted; found gap between index ${prev.groupIndex} and ${curr.groupIndex}`;\n }\n prev = curr;\n }\n return true;\n },\n);\n\nconst AccountWalletMnemonicPayloadStruct = object({\n id: AccountWalletPayloadIdStruct,\n type: literal(AccountWalletPayloadType.Mnemonic),\n value: exactOptional(sensitive(BytesStruct)),\n metadata: AccountWalletPayloadMetadataStruct,\n groups: AccountWalletMnemonicGroupsStruct,\n});\n\nconst AccountWalletPrivateKeyPayloadStruct = object({\n id: AccountWalletPayloadIdStruct,\n type: literal(AccountWalletPayloadType.PrivateKey),\n metadata: AccountWalletPayloadMetadataStruct,\n groups: array(AccountWalletPrivateKeyGroupEntryStruct),\n});\n\nconst AccountTreeWalletEntryStruct = union([\n AccountWalletMnemonicPayloadStruct,\n AccountWalletPrivateKeyPayloadStruct,\n]);\n\n/** Current version of the {@link AccountTreePayload} format. */\nexport const ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION = 1;\n\n/**\n * Superstruct schema for a fully versioned {@link AccountTreePayload}.\n *\n * Pins `version` to exactly {@link ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION} so\n * payloads from newer clients (v2+) are rejected rather than silently\n * mis-handled as v1. Once a migration framework is wired up in\n * {@link AccountTreeSnapshot.deserialize}, older versions will be up-migrated\n * before this struct is checked, and newer versions will require a new struct.\n *\n * Secret fields (`value`, `privateKey`) use the Superstruct `sensitive()`\n * wrapper so validation failures redact secrets from error output.\n */\nexport const AccountTreePayloadStruct = object({\n version: literal(ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION),\n wallets: array(AccountTreeWalletEntryStruct),\n});\n\n/** Inferred TypeScript type for a value matching {@link AccountTreePayloadStruct}. */\nexport type AccountTreePayloadStructType = Infer<\n typeof AccountTreePayloadStruct\n>;\n\n/**\n * Asserts that `value` conforms to the v1 {@link AccountTreePayload} schema.\n *\n * Prefer {@link AccountTreeSnapshot.deserialize} at transport boundaries so\n * validation stays paired with snapshot construction. Use this helper when you\n * already hold a parsed object and need to assert its shape before further\n * processing.\n *\n * @param value - Value to validate.\n * @throws If `value` is not a valid v1 payload, including unsupported wallet types.\n */\nexport function assertAccountTreePayload(\n value: unknown,\n): asserts value is AccountTreePayload {\n try {\n // AccountTreePayloadStruct pins version to ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION,\n // so unknown future versions are rejected here rather than silently mis-handled.\n assert(value, AccountTreePayloadStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Invalid AccountTreePayload: ${formatValidationErrorMessages(error)}`,\n );\n }\n /* istanbul ignore next */\n throw error;\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EAEtB,sBAAsB,EAEvB,MAAM,cAAc,CAAC;AAQtB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,mBAAmB;;IAK9B;;;OAGG;IACH,YAAY,OAAO,EAAE,sBAAsB,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,EAG3D;IAED;;;;;;;;;OASG;IACH,aA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AC;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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAA0B,WAAW,EAAE,MAAM,uBAAuB,CAAC;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,CAA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AAO,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"]}
|