@metamask-previews/account-tree-controller 7.5.5-preview-421b16793 → 7.5.5-preview-e0f702919

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +0 -7
  2. package/dist/AccountTreeController-method-action-types.cjs.map +1 -1
  3. package/dist/AccountTreeController-method-action-types.d.cts +1 -28
  4. package/dist/AccountTreeController-method-action-types.d.cts.map +1 -1
  5. package/dist/AccountTreeController-method-action-types.d.mts +1 -28
  6. package/dist/AccountTreeController-method-action-types.d.mts.map +1 -1
  7. package/dist/AccountTreeController-method-action-types.mjs.map +1 -1
  8. package/dist/AccountTreeController.cjs +0 -36
  9. package/dist/AccountTreeController.cjs.map +1 -1
  10. package/dist/AccountTreeController.d.cts +0 -24
  11. package/dist/AccountTreeController.d.cts.map +1 -1
  12. package/dist/AccountTreeController.d.mts +0 -24
  13. package/dist/AccountTreeController.d.mts.map +1 -1
  14. package/dist/AccountTreeController.mjs +0 -36
  15. package/dist/AccountTreeController.mjs.map +1 -1
  16. package/dist/index.cjs +1 -5
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +1 -4
  19. package/dist/index.d.cts.map +1 -1
  20. package/dist/index.d.mts +1 -4
  21. package/dist/index.d.mts.map +1 -1
  22. package/dist/index.mjs +0 -2
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/types.cjs.map +1 -1
  25. package/dist/types.d.cts +3 -3
  26. package/dist/types.d.cts.map +1 -1
  27. package/dist/types.d.mts +3 -3
  28. package/dist/types.d.mts.map +1 -1
  29. package/dist/types.mjs.map +1 -1
  30. package/package.json +1 -3
  31. package/dist/state/export.cjs +0 -202
  32. package/dist/state/export.cjs.map +0 -1
  33. package/dist/state/export.d.cts +0 -40
  34. package/dist/state/export.d.cts.map +0 -1
  35. package/dist/state/export.d.mts +0 -40
  36. package/dist/state/export.d.mts.map +0 -1
  37. package/dist/state/export.mjs +0 -196
  38. package/dist/state/export.mjs.map +0 -1
  39. package/dist/state/id-map.cjs +0 -59
  40. package/dist/state/id-map.cjs.map +0 -1
  41. package/dist/state/id-map.d.cts +0 -41
  42. package/dist/state/id-map.d.cts.map +0 -1
  43. package/dist/state/id-map.d.mts +0 -41
  44. package/dist/state/id-map.d.mts.map +0 -1
  45. package/dist/state/id-map.mjs +0 -55
  46. package/dist/state/id-map.mjs.map +0 -1
  47. package/dist/state/import.cjs +0 -225
  48. package/dist/state/import.cjs.map +0 -1
  49. package/dist/state/import.d.cts +0 -27
  50. package/dist/state/import.d.cts.map +0 -1
  51. package/dist/state/import.d.mts +0 -27
  52. package/dist/state/import.d.mts.map +0 -1
  53. package/dist/state/import.mjs +0 -221
  54. package/dist/state/import.mjs.map +0 -1
  55. package/dist/state/payload.cjs +0 -67
  56. package/dist/state/payload.cjs.map +0 -1
  57. package/dist/state/payload.d.cts +0 -114
  58. package/dist/state/payload.d.cts.map +0 -1
  59. package/dist/state/payload.d.mts +0 -114
  60. package/dist/state/payload.d.mts.map +0 -1
  61. package/dist/state/payload.mjs +0 -61
  62. package/dist/state/payload.mjs.map +0 -1
  63. package/dist/state/snapshot.cjs +0 -110
  64. package/dist/state/snapshot.cjs.map +0 -1
  65. package/dist/state/snapshot.d.cts +0 -58
  66. package/dist/state/snapshot.d.cts.map +0 -1
  67. package/dist/state/snapshot.d.mts +0 -58
  68. package/dist/state/snapshot.d.mts.map +0 -1
  69. package/dist/state/snapshot.mjs +0 -106
  70. package/dist/state/snapshot.mjs.map +0 -1
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.migrate = exports.toWalletPayloadId = exports.ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION = exports.parsePayloadGroupId = void 0;
4
- const PAYLOAD_GROUP_ID_REGEX = /^(?<walletId>wallet:[^/]+)\/(?<subId>.+)$/u;
5
- /**
6
- * Parses a payload group ID into its wallet ID and group sub-ID components.
7
- *
8
- * @param groupId - The payload group ID to parse.
9
- * @returns The parsed wallet ID and group sub-ID.
10
- * @throws If the group ID format is invalid.
11
- */
12
- function parsePayloadGroupId(groupId) {
13
- const match = PAYLOAD_GROUP_ID_REGEX.exec(groupId);
14
- if (!match?.groups) {
15
- throw new Error(`Invalid payload group ID: "${groupId}"`);
16
- }
17
- return {
18
- walletId: match.groups.walletId,
19
- subId: match.groups.subId,
20
- };
21
- }
22
- exports.parsePayloadGroupId = parsePayloadGroupId;
23
- /** Current version of the {@link AccountTreePayload} format. */
24
- exports.ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION = 1;
25
- /**
26
- * Constructs an {@link AccountWalletPayloadId} from an entropy source ID.
27
- *
28
- * @param entropySourceId - Stable entropy source ID returned by `HdKeyring.toEntropySourceId()`.
29
- * @returns The portable wallet payload ID.
30
- */
31
- function toWalletPayloadId(entropySourceId) {
32
- return `wallet:${entropySourceId}`;
33
- }
34
- exports.toWalletPayloadId = toWalletPayloadId;
35
- const MIGRATORS = {
36
- // v1 is the current version -- identity migration.
37
- [exports.ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION]: (raw) => raw,
38
- };
39
- /**
40
- * Validates a raw value as an `AccountTreePayload` and runs any necessary version migrations.
41
- *
42
- * @param raw - Unknown value to validate.
43
- * @returns A fully migrated `AccountTreePayload`.
44
- * @throws If `raw` is not a valid payload or `version > CURRENT_VERSION`.
45
- */
46
- function migrate(raw) {
47
- if (typeof raw !== 'object' || raw === null) {
48
- throw new Error('Invalid AccountTreePayload: expected an object');
49
- }
50
- const { version } = raw;
51
- if (typeof version !== 'number' || !Number.isInteger(version)) {
52
- throw new Error('Invalid AccountTreePayload: missing numeric version field');
53
- }
54
- if (version > exports.ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION) {
55
- throw new Error(`Unsupported AccountTreePayload version: ${version} (current: ${exports.ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION})`);
56
- }
57
- let result = raw;
58
- for (let ver = version; ver <= exports.ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION; ver++) {
59
- const migrator = MIGRATORS[ver];
60
- if (migrator) {
61
- result = migrator(result);
62
- }
63
- }
64
- return result;
65
- }
66
- exports.migrate = migrate;
67
- //# sourceMappingURL=payload.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payload.cjs","sourceRoot":"","sources":["../../src/state/payload.ts"],"names":[],"mappings":";;;AAkBA,MAAM,sBAAsB,GAAG,4CAA4C,CAAC;AAE5E;;;;;;GAMG;AACH,SAAgB,mBAAmB,CACjC,OAA8B;IAE9B,MAAM,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnD,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,8BAA8B,OAAO,GAAG,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,QAAkC;QACzD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK;KAC1B,CAAC;AACJ,CAAC;AAXD,kDAWC;AAED,gEAAgE;AACnD,QAAA,oCAAoC,GAAG,CAAU,CAAC;AAkF/D;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC/B,eAAuB;IAEvB,OAAO,UAAU,eAAe,EAAE,CAAC;AACrC,CAAC;AAJD,8CAIC;AAUD,MAAM,SAAS,GAA6B;IAC1C,mDAAmD;IACnD,CAAC,4CAAoC,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAyB;CAC3E,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,OAAO,CAAC,GAAY;IAClC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,GAA8B,CAAC;IACnD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,GAAG,4CAAoC,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CACb,2CAA2C,OAAO,cAAc,4CAAoC,GAAG,CACxG,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,GAAY,GAAG,CAAC;IAC1B,KAAK,IAAI,GAAG,GAAG,OAAO,EAAE,GAAG,IAAI,4CAAoC,EAAE,GAAG,EAAE,EAAE,CAAC;QAC3E,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,MAA4B,CAAC;AACtC,CAAC;AA1BD,0BA0BC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\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 = `wallet:${string}/${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/** Current version of the {@link AccountTreePayload} format. */\nexport const ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION = 1 as const;\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/** 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: string;\n encoding: 'hexadecimal' | 'base58' | 'base32';\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: 'mnemonic';\n /** BIP-39 mnemonic phrase. Absent in metadata-only exports. */\n value?: string;\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: 'private-key';\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/** Versioned, portable snapshot of the full account tree state. */\nexport type AccountTreePayload = {\n version: typeof ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION;\n wallets: AccountTreeWalletEntry[];\n};\n\n/** Wallet entry type exposed to {@link AccountTreeSnapshot.filter} predicates. */\nexport type AccountTreeSnapshotEntry =\n | AccountWalletMnemonicPayload\n | AccountWalletPrivateKeyPayload;\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/** Options accepted by {@link AccountTreeController.exportState}. */\nexport type ExportStateOptions = {\n /** When `true`, secrets (mnemonic / private keys) are included. Requires the vault to be unlocked. */\n includeSecrets?: boolean;\n};\n\ntype Migrator = (raw: unknown) => AccountTreePayload;\n\nconst MIGRATORS: Record<number, Migrator> = {\n // v1 is the current version -- identity migration.\n [ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION]: (raw) => raw as AccountTreePayload,\n};\n\n/**\n * Validates a raw value as an `AccountTreePayload` and runs any necessary version migrations.\n *\n * @param raw - Unknown value to validate.\n * @returns A fully migrated `AccountTreePayload`.\n * @throws If `raw` is not a valid payload or `version > CURRENT_VERSION`.\n */\nexport function migrate(raw: unknown): AccountTreePayload {\n if (typeof raw !== 'object' || raw === null) {\n throw new Error('Invalid AccountTreePayload: expected an object');\n }\n\n const { version } = raw as Record<string, unknown>;\n if (typeof version !== 'number' || !Number.isInteger(version)) {\n throw new Error(\n 'Invalid AccountTreePayload: missing numeric version field',\n );\n }\n if (version > ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION) {\n throw new Error(\n `Unsupported AccountTreePayload version: ${version} (current: ${ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION})`,\n );\n }\n\n let result: unknown = raw;\n for (let ver = version; ver <= ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION; ver++) {\n const migrator = MIGRATORS[ver];\n if (migrator) {\n result = migrator(result);\n }\n }\n\n return result as AccountTreePayload;\n}\n"]}
@@ -1,114 +0,0 @@
1
- import type { KeyringAccount } from "@metamask/keyring-api";
2
- /** Stable cross-device wallet identifier. Format: `wallet:<entropySourceId>`. */
3
- export type AccountWalletPayloadId = `wallet:${string}`;
4
- /** Stable cross-device group identifier. Format: `wallet:<entropySourceId>/<groupSubId>`. */
5
- export type AccountGroupPayloadId = `wallet:${string}/${string}`;
6
- /**
7
- * Parsed representation of an {@link AccountGroupPayloadId}.
8
- */
9
- export type ParsedPayloadGroupId = {
10
- /** The wallet portion of the group ID. */
11
- walletId: AccountWalletPayloadId;
12
- /** The group-specific sub-ID (e.g. group index for mnemonic wallets, address for private-key wallets). */
13
- subId: string;
14
- };
15
- /**
16
- * Parses a payload group ID into its wallet ID and group sub-ID components.
17
- *
18
- * @param groupId - The payload group ID to parse.
19
- * @returns The parsed wallet ID and group sub-ID.
20
- * @throws If the group ID format is invalid.
21
- */
22
- export declare function parsePayloadGroupId(groupId: AccountGroupPayloadId): ParsedPayloadGroupId;
23
- /** Current version of the {@link AccountTreePayload} format. */
24
- export declare const ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION: 1;
25
- /** Wallet-level metadata carried in every payload wallet entry. */
26
- export type AccountWalletPayloadMetadata = {
27
- name: string;
28
- };
29
- /** Group-level metadata carried in every payload group entry. */
30
- export type AccountWalletGroupPayloadMetadata = {
31
- name: string;
32
- pinned: boolean;
33
- hidden: boolean;
34
- };
35
- /** A single group entry inside an {@link AccountWalletMnemonicPayload}. */
36
- export type AccountWalletMnemonicGroupEntry = {
37
- /** Stable group payload ID. Format: `<walletPayloadId>/<groupIndex>`. */
38
- id: AccountGroupPayloadId;
39
- /** BIP-44 account index this group was derived at. */
40
- groupIndex: number;
41
- metadata: AccountWalletGroupPayloadMetadata;
42
- };
43
- /** A single group entry inside an {@link AccountWalletPrivateKeyPayload}. */
44
- export type AccountWalletPrivateKeyGroupEntry = {
45
- /** Stable group payload ID. Format: `wallet:private-key/<address>`. */
46
- id: AccountGroupPayloadId;
47
- /**
48
- * Private key material. Shape matches `ExportedAccount` from `@metamask/keyring-api/v2`
49
- * so the importer knows how to decode the key without additional out-of-band information.
50
- * Absent in metadata-only exports.
51
- */
52
- value?: {
53
- privateKey: string;
54
- encoding: 'hexadecimal' | 'base58' | 'base32';
55
- /**
56
- * Account type from `KeyringAccountType` (e.g. `'eip155:eoa'`, `'bip122:p2wpkh'`).
57
- * Absent for EVM accounts -- import via `SimpleKeyring`.
58
- * Present for non-EVM accounts -- routing to the BIP-44 Snap handling this type is not yet implemented.
59
- */
60
- type?: KeyringAccount['type'];
61
- };
62
- metadata: AccountWalletGroupPayloadMetadata;
63
- };
64
- /** Payload entry for an HD (entropy) wallet and its derived account groups. */
65
- export type AccountWalletMnemonicPayload = {
66
- id: AccountWalletPayloadId;
67
- type: 'mnemonic';
68
- /** BIP-39 mnemonic phrase. Absent in metadata-only exports. */
69
- value?: string;
70
- metadata: AccountWalletPayloadMetadata;
71
- groups: AccountWalletMnemonicGroupEntry[];
72
- };
73
- /**
74
- * Payload entry for all imported private-key accounts.
75
- *
76
- * All local simple-keyring wallets are merged into this single entry;
77
- * each account is represented as a separate group entry keyed by address.
78
- */
79
- export type AccountWalletPrivateKeyPayload = {
80
- id: AccountWalletPayloadId;
81
- type: 'private-key';
82
- metadata: AccountWalletPayloadMetadata;
83
- groups: AccountWalletPrivateKeyGroupEntry[];
84
- };
85
- /** Union of all wallet entry types that can appear in an {@link AccountTreePayload}. */
86
- export type AccountTreeWalletEntry = AccountWalletMnemonicPayload | AccountWalletPrivateKeyPayload;
87
- /** Versioned, portable snapshot of the full account tree state. */
88
- export type AccountTreePayload = {
89
- version: typeof ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION;
90
- wallets: AccountTreeWalletEntry[];
91
- };
92
- /** Wallet entry type exposed to {@link AccountTreeSnapshot.filter} predicates. */
93
- export type AccountTreeSnapshotEntry = AccountWalletMnemonicPayload | AccountWalletPrivateKeyPayload;
94
- /**
95
- * Constructs an {@link AccountWalletPayloadId} from an entropy source ID.
96
- *
97
- * @param entropySourceId - Stable entropy source ID returned by `HdKeyring.toEntropySourceId()`.
98
- * @returns The portable wallet payload ID.
99
- */
100
- export declare function toWalletPayloadId(entropySourceId: string): AccountWalletPayloadId;
101
- /** Options accepted by {@link AccountTreeController.exportState}. */
102
- export type ExportStateOptions = {
103
- /** When `true`, secrets (mnemonic / private keys) are included. Requires the vault to be unlocked. */
104
- includeSecrets?: boolean;
105
- };
106
- /**
107
- * Validates a raw value as an `AccountTreePayload` and runs any necessary version migrations.
108
- *
109
- * @param raw - Unknown value to validate.
110
- * @returns A fully migrated `AccountTreePayload`.
111
- * @throws If `raw` is not a valid payload or `version > CURRENT_VERSION`.
112
- */
113
- export declare function migrate(raw: unknown): AccountTreePayload;
114
- //# sourceMappingURL=payload.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payload.d.cts","sourceRoot":"","sources":["../../src/state/payload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D,iFAAiF;AACjF,MAAM,MAAM,sBAAsB,GAAG,UAAU,MAAM,EAAE,CAAC;AAExD,6FAA6F;AAC7F,MAAM,MAAM,qBAAq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B,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,4BAA4B,CAAC;IACvC,MAAM,EAAE,+BAA+B,EAAE,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,EAAE,EAAE,sBAAsB,CAAC;IAC3B,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,4BAA4B,CAAC;IACvC,MAAM,EAAE,iCAAiC,EAAE,CAAC;CAC7C,CAAC;AAEF,wFAAwF;AACxF,MAAM,MAAM,sBAAsB,GAC9B,4BAA4B,GAC5B,8BAA8B,CAAC;AAEnC,mEAAmE;AACnE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,oCAAoC,CAAC;IACrD,OAAO,EAAE,sBAAsB,EAAE,CAAC;CACnC,CAAC;AAEF,kFAAkF;AAClF,MAAM,MAAM,wBAAwB,GAChC,4BAA4B,GAC5B,8BAA8B,CAAC;AAEnC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,MAAM,GACtB,sBAAsB,CAExB;AAED,qEAAqE;AACrE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,sGAAsG;IACtG,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AASF;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,kBAAkB,CA0BxD"}
@@ -1,114 +0,0 @@
1
- import type { KeyringAccount } from "@metamask/keyring-api";
2
- /** Stable cross-device wallet identifier. Format: `wallet:<entropySourceId>`. */
3
- export type AccountWalletPayloadId = `wallet:${string}`;
4
- /** Stable cross-device group identifier. Format: `wallet:<entropySourceId>/<groupSubId>`. */
5
- export type AccountGroupPayloadId = `wallet:${string}/${string}`;
6
- /**
7
- * Parsed representation of an {@link AccountGroupPayloadId}.
8
- */
9
- export type ParsedPayloadGroupId = {
10
- /** The wallet portion of the group ID. */
11
- walletId: AccountWalletPayloadId;
12
- /** The group-specific sub-ID (e.g. group index for mnemonic wallets, address for private-key wallets). */
13
- subId: string;
14
- };
15
- /**
16
- * Parses a payload group ID into its wallet ID and group sub-ID components.
17
- *
18
- * @param groupId - The payload group ID to parse.
19
- * @returns The parsed wallet ID and group sub-ID.
20
- * @throws If the group ID format is invalid.
21
- */
22
- export declare function parsePayloadGroupId(groupId: AccountGroupPayloadId): ParsedPayloadGroupId;
23
- /** Current version of the {@link AccountTreePayload} format. */
24
- export declare const ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION: 1;
25
- /** Wallet-level metadata carried in every payload wallet entry. */
26
- export type AccountWalletPayloadMetadata = {
27
- name: string;
28
- };
29
- /** Group-level metadata carried in every payload group entry. */
30
- export type AccountWalletGroupPayloadMetadata = {
31
- name: string;
32
- pinned: boolean;
33
- hidden: boolean;
34
- };
35
- /** A single group entry inside an {@link AccountWalletMnemonicPayload}. */
36
- export type AccountWalletMnemonicGroupEntry = {
37
- /** Stable group payload ID. Format: `<walletPayloadId>/<groupIndex>`. */
38
- id: AccountGroupPayloadId;
39
- /** BIP-44 account index this group was derived at. */
40
- groupIndex: number;
41
- metadata: AccountWalletGroupPayloadMetadata;
42
- };
43
- /** A single group entry inside an {@link AccountWalletPrivateKeyPayload}. */
44
- export type AccountWalletPrivateKeyGroupEntry = {
45
- /** Stable group payload ID. Format: `wallet:private-key/<address>`. */
46
- id: AccountGroupPayloadId;
47
- /**
48
- * Private key material. Shape matches `ExportedAccount` from `@metamask/keyring-api/v2`
49
- * so the importer knows how to decode the key without additional out-of-band information.
50
- * Absent in metadata-only exports.
51
- */
52
- value?: {
53
- privateKey: string;
54
- encoding: 'hexadecimal' | 'base58' | 'base32';
55
- /**
56
- * Account type from `KeyringAccountType` (e.g. `'eip155:eoa'`, `'bip122:p2wpkh'`).
57
- * Absent for EVM accounts -- import via `SimpleKeyring`.
58
- * Present for non-EVM accounts -- routing to the BIP-44 Snap handling this type is not yet implemented.
59
- */
60
- type?: KeyringAccount['type'];
61
- };
62
- metadata: AccountWalletGroupPayloadMetadata;
63
- };
64
- /** Payload entry for an HD (entropy) wallet and its derived account groups. */
65
- export type AccountWalletMnemonicPayload = {
66
- id: AccountWalletPayloadId;
67
- type: 'mnemonic';
68
- /** BIP-39 mnemonic phrase. Absent in metadata-only exports. */
69
- value?: string;
70
- metadata: AccountWalletPayloadMetadata;
71
- groups: AccountWalletMnemonicGroupEntry[];
72
- };
73
- /**
74
- * Payload entry for all imported private-key accounts.
75
- *
76
- * All local simple-keyring wallets are merged into this single entry;
77
- * each account is represented as a separate group entry keyed by address.
78
- */
79
- export type AccountWalletPrivateKeyPayload = {
80
- id: AccountWalletPayloadId;
81
- type: 'private-key';
82
- metadata: AccountWalletPayloadMetadata;
83
- groups: AccountWalletPrivateKeyGroupEntry[];
84
- };
85
- /** Union of all wallet entry types that can appear in an {@link AccountTreePayload}. */
86
- export type AccountTreeWalletEntry = AccountWalletMnemonicPayload | AccountWalletPrivateKeyPayload;
87
- /** Versioned, portable snapshot of the full account tree state. */
88
- export type AccountTreePayload = {
89
- version: typeof ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION;
90
- wallets: AccountTreeWalletEntry[];
91
- };
92
- /** Wallet entry type exposed to {@link AccountTreeSnapshot.filter} predicates. */
93
- export type AccountTreeSnapshotEntry = AccountWalletMnemonicPayload | AccountWalletPrivateKeyPayload;
94
- /**
95
- * Constructs an {@link AccountWalletPayloadId} from an entropy source ID.
96
- *
97
- * @param entropySourceId - Stable entropy source ID returned by `HdKeyring.toEntropySourceId()`.
98
- * @returns The portable wallet payload ID.
99
- */
100
- export declare function toWalletPayloadId(entropySourceId: string): AccountWalletPayloadId;
101
- /** Options accepted by {@link AccountTreeController.exportState}. */
102
- export type ExportStateOptions = {
103
- /** When `true`, secrets (mnemonic / private keys) are included. Requires the vault to be unlocked. */
104
- includeSecrets?: boolean;
105
- };
106
- /**
107
- * Validates a raw value as an `AccountTreePayload` and runs any necessary version migrations.
108
- *
109
- * @param raw - Unknown value to validate.
110
- * @returns A fully migrated `AccountTreePayload`.
111
- * @throws If `raw` is not a valid payload or `version > CURRENT_VERSION`.
112
- */
113
- export declare function migrate(raw: unknown): AccountTreePayload;
114
- //# sourceMappingURL=payload.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payload.d.mts","sourceRoot":"","sources":["../../src/state/payload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D,iFAAiF;AACjF,MAAM,MAAM,sBAAsB,GAAG,UAAU,MAAM,EAAE,CAAC;AAExD,6FAA6F;AAC7F,MAAM,MAAM,qBAAqB,GAAG,UAAU,MAAM,IAAI,MAAM,EAAE,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,0CAA0C;IAC1C,QAAQ,EAAE,sBAAsB,CAAC;IACjC,0GAA0G;IAC1G,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAIF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,qBAAqB,GAC7B,oBAAoB,CAStB;AAED,gEAAgE;AAChE,eAAO,MAAM,oCAAoC,GAAa,CAAC;AAE/D,mEAAmE;AACnE,MAAM,MAAM,4BAA4B,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5D,iEAAiE;AACjE,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,yEAAyE;IACzE,EAAE,EAAE,qBAAqB,CAAC;IAC1B,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,iCAAiC,CAAC;CAC7C,CAAC;AAEF,6EAA6E;AAC7E,MAAM,MAAM,iCAAiC,GAAG;IAC9C,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AASF;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,kBAAkB,CA0BxD"}
@@ -1,61 +0,0 @@
1
- const PAYLOAD_GROUP_ID_REGEX = /^(?<walletId>wallet:[^/]+)\/(?<subId>.+)$/u;
2
- /**
3
- * Parses a payload group ID into its wallet ID and group sub-ID components.
4
- *
5
- * @param groupId - The payload group ID to parse.
6
- * @returns The parsed wallet ID and group sub-ID.
7
- * @throws If the group ID format is invalid.
8
- */
9
- export function parsePayloadGroupId(groupId) {
10
- const match = PAYLOAD_GROUP_ID_REGEX.exec(groupId);
11
- if (!match?.groups) {
12
- throw new Error(`Invalid payload group ID: "${groupId}"`);
13
- }
14
- return {
15
- walletId: match.groups.walletId,
16
- subId: match.groups.subId,
17
- };
18
- }
19
- /** Current version of the {@link AccountTreePayload} format. */
20
- export const ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION = 1;
21
- /**
22
- * Constructs an {@link AccountWalletPayloadId} from an entropy source ID.
23
- *
24
- * @param entropySourceId - Stable entropy source ID returned by `HdKeyring.toEntropySourceId()`.
25
- * @returns The portable wallet payload ID.
26
- */
27
- export function toWalletPayloadId(entropySourceId) {
28
- return `wallet:${entropySourceId}`;
29
- }
30
- const MIGRATORS = {
31
- // v1 is the current version -- identity migration.
32
- [ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION]: (raw) => raw,
33
- };
34
- /**
35
- * Validates a raw value as an `AccountTreePayload` and runs any necessary version migrations.
36
- *
37
- * @param raw - Unknown value to validate.
38
- * @returns A fully migrated `AccountTreePayload`.
39
- * @throws If `raw` is not a valid payload or `version > CURRENT_VERSION`.
40
- */
41
- export function migrate(raw) {
42
- if (typeof raw !== 'object' || raw === null) {
43
- throw new Error('Invalid AccountTreePayload: expected an object');
44
- }
45
- const { version } = raw;
46
- if (typeof version !== 'number' || !Number.isInteger(version)) {
47
- throw new Error('Invalid AccountTreePayload: missing numeric version field');
48
- }
49
- if (version > ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION) {
50
- throw new Error(`Unsupported AccountTreePayload version: ${version} (current: ${ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION})`);
51
- }
52
- let result = raw;
53
- for (let ver = version; ver <= ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION; ver++) {
54
- const migrator = MIGRATORS[ver];
55
- if (migrator) {
56
- result = migrator(result);
57
- }
58
- }
59
- return result;
60
- }
61
- //# sourceMappingURL=payload.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payload.mjs","sourceRoot":"","sources":["../../src/state/payload.ts"],"names":[],"mappings":"AAkBA,MAAM,sBAAsB,GAAG,4CAA4C,CAAC;AAE5E;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAA8B;IAE9B,MAAM,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnD,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,8BAA8B,OAAO,GAAG,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,QAAkC;QACzD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK;KAC1B,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAU,CAAC;AAkF/D;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,eAAuB;IAEvB,OAAO,UAAU,eAAe,EAAE,CAAC;AACrC,CAAC;AAUD,MAAM,SAAS,GAA6B;IAC1C,mDAAmD;IACnD,CAAC,oCAAoC,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAyB;CAC3E,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,GAAY;IAClC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,GAA8B,CAAC;IACnD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,GAAG,oCAAoC,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CACb,2CAA2C,OAAO,cAAc,oCAAoC,GAAG,CACxG,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,GAAY,GAAG,CAAC;IAC1B,KAAK,IAAI,GAAG,GAAG,OAAO,EAAE,GAAG,IAAI,oCAAoC,EAAE,GAAG,EAAE,EAAE,CAAC;QAC3E,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,MAA4B,CAAC;AACtC,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\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 = `wallet:${string}/${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/** Current version of the {@link AccountTreePayload} format. */\nexport const ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION = 1 as const;\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/** 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: string;\n encoding: 'hexadecimal' | 'base58' | 'base32';\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: 'mnemonic';\n /** BIP-39 mnemonic phrase. Absent in metadata-only exports. */\n value?: string;\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: 'private-key';\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/** Versioned, portable snapshot of the full account tree state. */\nexport type AccountTreePayload = {\n version: typeof ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION;\n wallets: AccountTreeWalletEntry[];\n};\n\n/** Wallet entry type exposed to {@link AccountTreeSnapshot.filter} predicates. */\nexport type AccountTreeSnapshotEntry =\n | AccountWalletMnemonicPayload\n | AccountWalletPrivateKeyPayload;\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/** Options accepted by {@link AccountTreeController.exportState}. */\nexport type ExportStateOptions = {\n /** When `true`, secrets (mnemonic / private keys) are included. Requires the vault to be unlocked. */\n includeSecrets?: boolean;\n};\n\ntype Migrator = (raw: unknown) => AccountTreePayload;\n\nconst MIGRATORS: Record<number, Migrator> = {\n // v1 is the current version -- identity migration.\n [ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION]: (raw) => raw as AccountTreePayload,\n};\n\n/**\n * Validates a raw value as an `AccountTreePayload` and runs any necessary version migrations.\n *\n * @param raw - Unknown value to validate.\n * @returns A fully migrated `AccountTreePayload`.\n * @throws If `raw` is not a valid payload or `version > CURRENT_VERSION`.\n */\nexport function migrate(raw: unknown): AccountTreePayload {\n if (typeof raw !== 'object' || raw === null) {\n throw new Error('Invalid AccountTreePayload: expected an object');\n }\n\n const { version } = raw as Record<string, unknown>;\n if (typeof version !== 'number' || !Number.isInteger(version)) {\n throw new Error(\n 'Invalid AccountTreePayload: missing numeric version field',\n );\n }\n if (version > ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION) {\n throw new Error(\n `Unsupported AccountTreePayload version: ${version} (current: ${ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION})`,\n );\n }\n\n let result: unknown = raw;\n for (let ver = version; ver <= ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION; ver++) {\n const migrator = MIGRATORS[ver];\n if (migrator) {\n result = migrator(result);\n }\n }\n\n return result as AccountTreePayload;\n}\n"]}
@@ -1,110 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _AccountTreeSnapshot_entries, _AccountTreeSnapshot_idMap;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.AccountTreeSnapshot = void 0;
16
- const id_map_js_1 = require("./id-map.cjs");
17
- const payload_js_1 = require("./payload.cjs");
18
- /**
19
- * Immutable value object returned by {@link AccountTreeController.exportState}.
20
- *
21
- * Holds an ID map (local ↔ payload) populated during export so callers can
22
- * bridge between internal controller IDs and the stable cross-device IDs that
23
- * appear in the serialized payload. The map is absent for snapshots produced
24
- * by {@link AccountTreeSnapshot.deserialize} — `toLocalId` / `toPayloadId`
25
- * return `undefined` in that case.
26
- */
27
- class AccountTreeSnapshot {
28
- constructor(entries, idMap) {
29
- _AccountTreeSnapshot_entries.set(this, void 0);
30
- _AccountTreeSnapshot_idMap.set(this, void 0);
31
- __classPrivateFieldSet(this, _AccountTreeSnapshot_entries, entries, "f");
32
- __classPrivateFieldSet(this, _AccountTreeSnapshot_idMap, idMap, "f");
33
- }
34
- /**
35
- * Returns a new snapshot containing only the wallet entries for which
36
- * `predicate` returns `true`. The ID map is pruned to match.
37
- *
38
- * @param predicate - Function called with each wallet entry.
39
- * @returns A filtered snapshot.
40
- */
41
- filter(predicate) {
42
- const filteredEntries = __classPrivateFieldGet(this, _AccountTreeSnapshot_entries, "f").filter(predicate);
43
- if (!__classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f")) {
44
- return new AccountTreeSnapshot(filteredEntries, null);
45
- }
46
- const pairs = [];
47
- for (const entry of filteredEntries) {
48
- const localWalletId = __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f").getLocalId(entry.id);
49
- if (localWalletId !== undefined) {
50
- pairs.push([localWalletId, entry.id]);
51
- }
52
- for (const group of entry.groups) {
53
- const localGroupId = __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f").getLocalId(group.id);
54
- if (localGroupId !== undefined) {
55
- pairs.push([localGroupId, group.id]);
56
- }
57
- }
58
- }
59
- return new AccountTreeSnapshot(filteredEntries, new id_map_js_1.IdMap(pairs));
60
- }
61
- /**
62
- * Converts a payload ID (wallet or group) to the corresponding local
63
- * `AccountTreeController` ID.
64
- *
65
- * @param payloadId - Stable cross-device wallet or group payload ID.
66
- * @returns The local controller ID, or `undefined` if not found or no ID map is present.
67
- */
68
- toLocalId(payloadId) {
69
- return __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f")?.getLocalId(payloadId);
70
- }
71
- /**
72
- * Converts a local `AccountTreeController` ID (wallet or group) to its
73
- * stable cross-device payload ID.
74
- *
75
- * @param localId - Local controller wallet or group ID.
76
- * @returns The payload ID, or `undefined` if not found or no ID map is present.
77
- */
78
- toPayloadId(localId) {
79
- return __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f")?.getPayloadId(localId);
80
- }
81
- /**
82
- * Serializes the snapshot to a versioned {@link AccountTreePayload}.
83
- *
84
- * @returns The versioned payload.
85
- */
86
- serialize() {
87
- return {
88
- version: payload_js_1.ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION,
89
- wallets: __classPrivateFieldGet(this, _AccountTreeSnapshot_entries, "f"),
90
- };
91
- }
92
- /**
93
- * Deserializes and validates a raw value as an `AccountTreePayload`,
94
- * running any necessary version migrations.
95
- *
96
- * The returned snapshot has no ID map — `toLocalId` / `toPayloadId` return
97
- * `undefined`. Use `AccountTreeController.exportState` when you need the map.
98
- *
99
- * @param raw - Unknown value to parse.
100
- * @returns A migrated snapshot.
101
- * @throws If `raw` is not a valid payload or its version exceeds the current version.
102
- */
103
- static deserialize(raw) {
104
- const payload = (0, payload_js_1.migrate)(raw);
105
- return new AccountTreeSnapshot(payload.wallets, null);
106
- }
107
- }
108
- exports.AccountTreeSnapshot = AccountTreeSnapshot;
109
- _AccountTreeSnapshot_entries = new WeakMap(), _AccountTreeSnapshot_idMap = new WeakMap();
110
- //# sourceMappingURL=snapshot.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snapshot.cjs","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoC;AAOpC,8CAA6E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AEzD,OAAO,uBAAA,IAAI,kCAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CACT,OAAoC;QAEpC,OAAO,uBAAA,IAAI,kCAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO;YACL,OAAO,EAAE,iDAAoC;YAC7C,OAAO,EAAE,uBAAA,IAAI,oCAAS;SACvB,CAAC;IACJ,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAC,WAAW,CAAC,GAAY;QAC7B,MAAM,OAAO,GAAG,IAAA,oBAAO,EAAC,GAAG,CAAC,CAAC;QAC7B,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;CACF;AAhGD,kDAgGC","sourcesContent":["import { IdMap } from './id-map.js';\nimport type {\n AccountGroupPayloadId,\n AccountTreePayload,\n AccountTreeSnapshotEntry,\n AccountWalletPayloadId,\n} from './payload.js';\nimport { ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION, migrate } from './payload.js';\n\n/**\n * Immutable value object returned by {@link AccountTreeController.exportState}.\n *\n * Holds an ID map (local ↔ payload) populated during export so callers can\n * bridge between internal controller IDs and the stable cross-device IDs that\n * appear in the serialized payload. The map is absent for snapshots produced\n * by {@link AccountTreeSnapshot.deserialize} — `toLocalId` / `toPayloadId`\n * return `undefined` in that case.\n */\nexport class AccountTreeSnapshot {\n readonly #entries: AccountTreeSnapshotEntry[];\n\n readonly #idMap: IdMap | null;\n\n constructor(entries: AccountTreeSnapshotEntry[], idMap: IdMap | null) {\n this.#entries = entries;\n this.#idMap = idMap;\n }\n\n /**\n * Returns a new snapshot containing only the wallet entries for which\n * `predicate` returns `true`. The ID map is pruned to match.\n *\n * @param predicate - Function called with each wallet entry.\n * @returns A filtered snapshot.\n */\n filter(\n predicate: (entry: AccountTreeSnapshotEntry) => boolean,\n ): AccountTreeSnapshot {\n const filteredEntries = this.#entries.filter(predicate);\n\n if (!this.#idMap) {\n return new AccountTreeSnapshot(filteredEntries, null);\n }\n\n const pairs: Parameters<IdMap['add']>[] = [];\n for (const entry of filteredEntries) {\n const localWalletId = this.#idMap.getLocalId(entry.id);\n if (localWalletId !== undefined) {\n pairs.push([localWalletId, entry.id]);\n }\n for (const group of entry.groups) {\n const localGroupId = this.#idMap.getLocalId(group.id);\n if (localGroupId !== undefined) {\n pairs.push([localGroupId, group.id]);\n }\n }\n }\n\n return new AccountTreeSnapshot(filteredEntries, new IdMap(pairs));\n }\n\n /**\n * Converts a payload ID (wallet or group) to the corresponding local\n * `AccountTreeController` ID.\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 * @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 versioned {@link AccountTreePayload}.\n *\n * @returns The versioned payload.\n */\n serialize(): AccountTreePayload {\n return {\n version: ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION,\n wallets: this.#entries,\n };\n }\n\n /**\n * Deserializes and validates a raw value as an `AccountTreePayload`,\n * running any necessary version migrations.\n *\n * The returned snapshot has no ID map — `toLocalId` / `toPayloadId` return\n * `undefined`. Use `AccountTreeController.exportState` when you need the map.\n *\n * @param raw - Unknown value to parse.\n * @returns A migrated snapshot.\n * @throws If `raw` is not a valid payload or its version exceeds the current version.\n */\n static deserialize(raw: unknown): AccountTreeSnapshot {\n const payload = migrate(raw);\n return new AccountTreeSnapshot(payload.wallets, null);\n }\n}\n"]}
@@ -1,58 +0,0 @@
1
- import { IdMap } from "./id-map.cjs";
2
- import type { AccountGroupPayloadId, AccountTreePayload, AccountTreeSnapshotEntry, AccountWalletPayloadId } from "./payload.cjs";
3
- /**
4
- * Immutable value object returned by {@link AccountTreeController.exportState}.
5
- *
6
- * Holds an ID map (local ↔ payload) populated during export so callers can
7
- * bridge between internal controller IDs and the stable cross-device IDs that
8
- * appear in the serialized payload. The map is absent for snapshots produced
9
- * by {@link AccountTreeSnapshot.deserialize} — `toLocalId` / `toPayloadId`
10
- * return `undefined` in that case.
11
- */
12
- export declare class AccountTreeSnapshot {
13
- #private;
14
- constructor(entries: AccountTreeSnapshotEntry[], idMap: IdMap | null);
15
- /**
16
- * Returns a new snapshot containing only the wallet entries for which
17
- * `predicate` returns `true`. The ID map is pruned to match.
18
- *
19
- * @param predicate - Function called with each wallet entry.
20
- * @returns A filtered snapshot.
21
- */
22
- filter(predicate: (entry: AccountTreeSnapshotEntry) => boolean): AccountTreeSnapshot;
23
- /**
24
- * Converts a payload ID (wallet or group) to the corresponding local
25
- * `AccountTreeController` ID.
26
- *
27
- * @param payloadId - Stable cross-device wallet or group payload ID.
28
- * @returns The local controller ID, or `undefined` if not found or no ID map is present.
29
- */
30
- toLocalId(payloadId: AccountWalletPayloadId | AccountGroupPayloadId): ReturnType<IdMap['getLocalId']>;
31
- /**
32
- * Converts a local `AccountTreeController` ID (wallet or group) to its
33
- * stable cross-device payload ID.
34
- *
35
- * @param localId - Local controller wallet or group ID.
36
- * @returns The payload ID, or `undefined` if not found or no ID map is present.
37
- */
38
- toPayloadId(localId: Parameters<IdMap['add']>[0]): ReturnType<IdMap['getPayloadId']>;
39
- /**
40
- * Serializes the snapshot to a versioned {@link AccountTreePayload}.
41
- *
42
- * @returns The versioned payload.
43
- */
44
- serialize(): AccountTreePayload;
45
- /**
46
- * Deserializes and validates a raw value as an `AccountTreePayload`,
47
- * running any necessary version migrations.
48
- *
49
- * The returned snapshot has no ID map — `toLocalId` / `toPayloadId` return
50
- * `undefined`. Use `AccountTreeController.exportState` when you need the map.
51
- *
52
- * @param raw - Unknown value to parse.
53
- * @returns A migrated snapshot.
54
- * @throws If `raw` is not a valid payload or its version exceeds the current version.
55
- */
56
- static deserialize(raw: unknown): AccountTreeSnapshot;
57
- }
58
- //# sourceMappingURL=snapshot.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snapshot.d.cts","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,qBAAoB;AACpC,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACvB,sBAAqB;AAGtB;;;;;;;;GAQG;AACH,qBAAa,mBAAmB;;gBAKlB,OAAO,EAAE,wBAAwB,EAAE,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAKpE;;;;;;OAMG;IACH,MAAM,CACJ,SAAS,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,OAAO,GACtD,mBAAmB;IAwBtB;;;;;;OAMG;IACH,SAAS,CACP,SAAS,EAAE,sBAAsB,GAAG,qBAAqB,GACxD,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAIlC;;;;;;OAMG;IACH,WAAW,CACT,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GACnC,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAIpC;;;;OAIG;IACH,SAAS,IAAI,kBAAkB;IAO/B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,mBAAmB;CAItD"}