@metamask-previews/account-tree-controller 8.1.0-preview-d8fceeabc → 8.1.0-preview-efd9e28b2
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 -10
- package/dist/state/import.cjs +4 -8
- package/dist/state/import.cjs.map +1 -1
- package/dist/state/import.d.cts.map +1 -1
- package/dist/state/import.d.mts.map +1 -1
- package/dist/state/import.mjs +4 -8
- package/dist/state/import.mjs.map +1 -1
- package/dist/state/payload.cjs +4 -4
- package/dist/state/payload.cjs.map +1 -1
- package/dist/state/payload.d.cts +37 -37
- package/dist/state/payload.d.cts.map +1 -1
- package/dist/state/payload.d.mts +37 -37
- package/dist/state/payload.d.mts.map +1 -1
- package/dist/state/payload.mjs +4 -4
- package/dist/state/payload.mjs.map +1 -1
- package/dist/state/snapshot.cjs +2 -49
- package/dist/state/snapshot.cjs.map +1 -1
- package/dist/state/snapshot.d.cts +2 -25
- package/dist/state/snapshot.d.cts.map +1 -1
- package/dist/state/snapshot.d.mts +2 -25
- package/dist/state/snapshot.d.mts.map +1 -1
- package/dist/state/snapshot.mjs +2 -49
- package/dist/state/snapshot.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload.d.cts","sourceRoot":"","sources":["../../src/state/payload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAiB5D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,oBAAmB;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;IAC1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AAE,KAAK,CAAC;IACvB,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB,CAAC;AAqFN,gEAAgE;AAChE,eAAO,MAAM,oCAAoC,IAAI,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGnC,CAAC;AAEH,sFAAsF;AACtF,MAAM,MAAM,4BAA4B,GAAG,KAAK,CAC9C,OAAO,wBAAwB,CAChC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,KAAK,IAAI,kBAAkB,CAcrC"}
|
package/dist/state/payload.d.mts
CHANGED
|
@@ -49,7 +49,7 @@ export type AccountWalletMnemonicGroupEntry = {
|
|
|
49
49
|
id: AccountGroupPayloadId;
|
|
50
50
|
/** BIP-44 account index this group was derived at. */
|
|
51
51
|
groupIndex: number;
|
|
52
|
-
metadata
|
|
52
|
+
metadata: AccountWalletGroupPayloadMetadata;
|
|
53
53
|
};
|
|
54
54
|
/**
|
|
55
55
|
* Encoding formats for exported private key material.
|
|
@@ -79,7 +79,7 @@ export type AccountWalletPrivateKeyGroupEntry = {
|
|
|
79
79
|
*/
|
|
80
80
|
type?: KeyringAccount['type'];
|
|
81
81
|
};
|
|
82
|
-
metadata
|
|
82
|
+
metadata: AccountWalletGroupPayloadMetadata;
|
|
83
83
|
};
|
|
84
84
|
/** Payload entry for an HD (entropy) wallet and its derived account groups. */
|
|
85
85
|
export type AccountWalletMnemonicPayload = {
|
|
@@ -87,7 +87,7 @@ export type AccountWalletMnemonicPayload = {
|
|
|
87
87
|
type: typeof AccountWalletPayloadType.Mnemonic;
|
|
88
88
|
/** BIP-39 mnemonic phrase encoded as bytes. Absent in metadata-only exports. */
|
|
89
89
|
value?: EncodedBytes;
|
|
90
|
-
metadata
|
|
90
|
+
metadata: AccountWalletPayloadMetadata;
|
|
91
91
|
groups: AccountWalletMnemonicGroupEntry[];
|
|
92
92
|
};
|
|
93
93
|
/**
|
|
@@ -99,7 +99,7 @@ export type AccountWalletMnemonicPayload = {
|
|
|
99
99
|
export type AccountWalletPrivateKeyPayload = {
|
|
100
100
|
id: AccountWalletPayloadId;
|
|
101
101
|
type: typeof AccountWalletPayloadType.PrivateKey;
|
|
102
|
-
metadata
|
|
102
|
+
metadata: AccountWalletPayloadMetadata;
|
|
103
103
|
groups: AccountWalletPrivateKeyGroupEntry[];
|
|
104
104
|
};
|
|
105
105
|
/** Union of all wallet entry types that can appear in an {@link AccountTreePayload}. */
|
|
@@ -169,38 +169,38 @@ export declare const AccountTreePayloadStruct: import("@metamask/superstruct").S
|
|
|
169
169
|
wallets: ({
|
|
170
170
|
id: `wallet:${string}`;
|
|
171
171
|
type: "mnemonic";
|
|
172
|
+
metadata: {
|
|
173
|
+
name: string;
|
|
174
|
+
};
|
|
172
175
|
groups: {
|
|
173
176
|
id: `wallet:${string}/${string}`;
|
|
174
|
-
|
|
175
|
-
metadata?: {
|
|
177
|
+
metadata: {
|
|
176
178
|
name: string;
|
|
177
179
|
pinned: boolean;
|
|
178
180
|
hidden: boolean;
|
|
179
|
-
}
|
|
181
|
+
};
|
|
182
|
+
groupIndex: number;
|
|
180
183
|
}[];
|
|
181
|
-
metadata?: {
|
|
182
|
-
name: string;
|
|
183
|
-
} | undefined;
|
|
184
184
|
value?: EncodedBytes | undefined;
|
|
185
185
|
} | {
|
|
186
186
|
id: `wallet:${string}`;
|
|
187
187
|
type: "private-key";
|
|
188
|
+
metadata: {
|
|
189
|
+
name: string;
|
|
190
|
+
};
|
|
188
191
|
groups: {
|
|
189
192
|
id: `wallet:${string}/${string}`;
|
|
190
|
-
metadata
|
|
193
|
+
metadata: {
|
|
191
194
|
name: string;
|
|
192
195
|
pinned: boolean;
|
|
193
196
|
hidden: boolean;
|
|
194
|
-
}
|
|
197
|
+
};
|
|
195
198
|
value?: {
|
|
196
199
|
privateKey: EncodedBytes;
|
|
197
200
|
encoding: "hexadecimal" | "base58" | "base32";
|
|
198
201
|
type?: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account" | undefined;
|
|
199
202
|
} | undefined;
|
|
200
203
|
}[];
|
|
201
|
-
metadata?: {
|
|
202
|
-
name: string;
|
|
203
|
-
} | undefined;
|
|
204
204
|
})[];
|
|
205
205
|
version: 1;
|
|
206
206
|
}, {
|
|
@@ -208,73 +208,73 @@ export declare const AccountTreePayloadStruct: import("@metamask/superstruct").S
|
|
|
208
208
|
wallets: import("@metamask/superstruct").Struct<({
|
|
209
209
|
id: `wallet:${string}`;
|
|
210
210
|
type: "mnemonic";
|
|
211
|
+
metadata: {
|
|
212
|
+
name: string;
|
|
213
|
+
};
|
|
211
214
|
groups: {
|
|
212
215
|
id: `wallet:${string}/${string}`;
|
|
213
|
-
|
|
214
|
-
metadata?: {
|
|
216
|
+
metadata: {
|
|
215
217
|
name: string;
|
|
216
218
|
pinned: boolean;
|
|
217
219
|
hidden: boolean;
|
|
218
|
-
}
|
|
220
|
+
};
|
|
221
|
+
groupIndex: number;
|
|
219
222
|
}[];
|
|
220
|
-
metadata?: {
|
|
221
|
-
name: string;
|
|
222
|
-
} | undefined;
|
|
223
223
|
value?: EncodedBytes | undefined;
|
|
224
224
|
} | {
|
|
225
225
|
id: `wallet:${string}`;
|
|
226
226
|
type: "private-key";
|
|
227
|
+
metadata: {
|
|
228
|
+
name: string;
|
|
229
|
+
};
|
|
227
230
|
groups: {
|
|
228
231
|
id: `wallet:${string}/${string}`;
|
|
229
|
-
metadata
|
|
232
|
+
metadata: {
|
|
230
233
|
name: string;
|
|
231
234
|
pinned: boolean;
|
|
232
235
|
hidden: boolean;
|
|
233
|
-
}
|
|
236
|
+
};
|
|
234
237
|
value?: {
|
|
235
238
|
privateKey: EncodedBytes;
|
|
236
239
|
encoding: "hexadecimal" | "base58" | "base32";
|
|
237
240
|
type?: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account" | undefined;
|
|
238
241
|
} | undefined;
|
|
239
242
|
}[];
|
|
240
|
-
metadata?: {
|
|
241
|
-
name: string;
|
|
242
|
-
} | undefined;
|
|
243
243
|
})[], import("@metamask/superstruct").Struct<{
|
|
244
244
|
id: `wallet:${string}`;
|
|
245
245
|
type: "mnemonic";
|
|
246
|
+
metadata: {
|
|
247
|
+
name: string;
|
|
248
|
+
};
|
|
246
249
|
groups: {
|
|
247
250
|
id: `wallet:${string}/${string}`;
|
|
248
|
-
|
|
249
|
-
metadata?: {
|
|
251
|
+
metadata: {
|
|
250
252
|
name: string;
|
|
251
253
|
pinned: boolean;
|
|
252
254
|
hidden: boolean;
|
|
253
|
-
}
|
|
255
|
+
};
|
|
256
|
+
groupIndex: number;
|
|
254
257
|
}[];
|
|
255
|
-
metadata?: {
|
|
256
|
-
name: string;
|
|
257
|
-
} | undefined;
|
|
258
258
|
value?: EncodedBytes | undefined;
|
|
259
259
|
} | {
|
|
260
260
|
id: `wallet:${string}`;
|
|
261
261
|
type: "private-key";
|
|
262
|
+
metadata: {
|
|
263
|
+
name: string;
|
|
264
|
+
};
|
|
262
265
|
groups: {
|
|
263
266
|
id: `wallet:${string}/${string}`;
|
|
264
|
-
metadata
|
|
267
|
+
metadata: {
|
|
265
268
|
name: string;
|
|
266
269
|
pinned: boolean;
|
|
267
270
|
hidden: boolean;
|
|
268
|
-
}
|
|
271
|
+
};
|
|
269
272
|
value?: {
|
|
270
273
|
privateKey: EncodedBytes;
|
|
271
274
|
encoding: "hexadecimal" | "base58" | "base32";
|
|
272
275
|
type?: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "stellar:account" | "any:account" | undefined;
|
|
273
276
|
} | undefined;
|
|
274
277
|
}[];
|
|
275
|
-
metadata?: {
|
|
276
|
-
name: string;
|
|
277
|
-
} | undefined;
|
|
278
278
|
}, null>>;
|
|
279
279
|
}>;
|
|
280
280
|
/** Inferred TypeScript type for a value matching {@link AccountTreePayloadStruct}. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload.d.mts","sourceRoot":"","sources":["../../src/state/payload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAiB5D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,oBAAmB;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,sBAAsB,CAAC;IACjC,0GAA0G;IAC1G,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAIF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,qBAAqB,GAC7B,oBAAoB,CAStB;AAED;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB;;;CAG3B,CAAC;AAEX,MAAM,MAAM,wBAAwB,GAClC,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,OAAO,wBAAwB,CAAC,CAAC;AAE3E,mEAAmE;AACnE,MAAM,MAAM,4BAA4B,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5D,iEAAiE;AACjE,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,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O,CAAC,KAAK,IAAI,kBAAkB,CAcrC"}
|
package/dist/state/payload.mjs
CHANGED
|
@@ -78,12 +78,12 @@ const AccountWalletPrivateKeyValueStruct = object({
|
|
|
78
78
|
const AccountWalletMnemonicGroupEntryStruct = object({
|
|
79
79
|
id: AccountGroupPayloadIdStruct,
|
|
80
80
|
groupIndex: integer(),
|
|
81
|
-
metadata:
|
|
81
|
+
metadata: AccountWalletGroupPayloadMetadataStruct,
|
|
82
82
|
});
|
|
83
83
|
const AccountWalletPrivateKeyGroupEntryStruct = object({
|
|
84
84
|
id: AccountGroupPayloadIdStruct,
|
|
85
85
|
value: exactOptional(AccountWalletPrivateKeyValueStruct),
|
|
86
|
-
metadata:
|
|
86
|
+
metadata: AccountWalletGroupPayloadMetadataStruct,
|
|
87
87
|
});
|
|
88
88
|
// The `groups` array in a mnemonic wallet payload must have contiguous group indices starting at 0.
|
|
89
89
|
const AccountWalletMnemonicGroupsStruct = refine(array(AccountWalletMnemonicGroupEntryStruct), 'contiguous-group-indices', (groups) => {
|
|
@@ -103,13 +103,13 @@ const AccountWalletMnemonicPayloadStruct = object({
|
|
|
103
103
|
id: AccountWalletPayloadIdStruct,
|
|
104
104
|
type: literal(AccountWalletPayloadType.Mnemonic),
|
|
105
105
|
value: exactOptional(sensitive(BytesStruct)),
|
|
106
|
-
metadata:
|
|
106
|
+
metadata: AccountWalletPayloadMetadataStruct,
|
|
107
107
|
groups: AccountWalletMnemonicGroupsStruct,
|
|
108
108
|
});
|
|
109
109
|
const AccountWalletPrivateKeyPayloadStruct = object({
|
|
110
110
|
id: AccountWalletPayloadIdStruct,
|
|
111
111
|
type: literal(AccountWalletPayloadType.PrivateKey),
|
|
112
|
-
metadata:
|
|
112
|
+
metadata: AccountWalletPayloadMetadataStruct,
|
|
113
113
|
groups: array(AccountWalletPrivateKeyGroupEntryStruct),
|
|
114
114
|
});
|
|
115
115
|
const AccountTreeWalletEntryStruct = union([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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AChE,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;IAC7C,OAAO,EAAE,OAAO,CAAC,oCAAoC,CAAC;IACtD,OAAO,EAAE,KAAK,CAAC,4BAA4B,CAAC;CAC7C,CAAC,CAAC;AAOH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CACtC,KAAc;IAEd,IAAI,CAAC;QACH,iFAAiF;QACjF,iFAAiF;QACjF,MAAM,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,+BAA+B,6BAA6B,CAAC,KAAK,CAAC,EAAE,CACtE,CAAC;QACJ,CAAC;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: exactOptional(AccountWalletGroupPayloadMetadataStruct),\n});\n\nconst AccountWalletPrivateKeyGroupEntryStruct = object({\n id: AccountGroupPayloadIdStruct,\n value: exactOptional(AccountWalletPrivateKeyValueStruct),\n metadata: exactOptional(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: exactOptional(AccountWalletPayloadMetadataStruct),\n groups: AccountWalletMnemonicGroupsStruct,\n});\n\nconst AccountWalletPrivateKeyPayloadStruct = object({\n id: AccountWalletPayloadIdStruct,\n type: literal(AccountWalletPayloadType.PrivateKey),\n metadata: exactOptional(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
|
+
{"version":3,"file":"payload.mjs","sourceRoot":"","sources":["../../src/state/payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,8BAA8B;AAEjE,OAAO,EACL,KAAK,EACL,MAAM,EACN,OAAO,EACP,MAAM,EACN,KAAK,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,aAAa,EACb,MAAM,EACN,SAAS,EACT,MAAM,EACN,WAAW,EACX,KAAK,EACN,8BAA8B;AAI/B,OAAO,EAAE,WAAW,EAAE,6BAA6B,EAAE,oBAAmB;AAkBxE,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;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,QAAQ,EAAE,UAAU;IACpB,UAAU,EAAE,aAAa;CACjB,CAAC;AAwBX;;GAEG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,WAAW,EAAE,aAAa;IAC1B,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;CACR,CAAC;AAmFX;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,eAAuB;IAEvB,O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,KAAK,CAAC;IACzC,kCAAkC;IAClC,oCAAoC;CACrC,CAAC,CAAC;AAEH,gEAAgE;AAChE,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC,CAAC;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;IAC7C,OAAO,EAAE,OAAO,CAAC,oCAAoC,CAAC;IACtD,OAAO,EAAE,KAAK,CAAC,4BAA4B,CAAC;CAC7C,CAAC,CAAC;AAOH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CACtC,KAAc;IAEd,IAAI,CAAC;QACH,iFAAiF;QACjF,iFAAiF;QACjF,MAAM,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,+BAA+B,6BAA6B,CAAC,KAAK,CAAC,EAAE,CACtE,CAAC;QACJ,CAAC;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"]}
|
package/dist/state/snapshot.cjs
CHANGED
|
@@ -62,7 +62,7 @@ class AccountTreeSnapshot {
|
|
|
62
62
|
* Filters groups within one wallet. Other wallets are left unchanged.
|
|
63
63
|
*
|
|
64
64
|
* Throws if `walletId` does not identify a wallet in the snapshot.
|
|
65
|
-
* Removes the wallet if no groups remain after filtering
|
|
65
|
+
* Removes the wallet if no groups remain after filtering — this prevents a
|
|
66
66
|
* mnemonic wallet with zero selected groups from still transferring its secret.
|
|
67
67
|
*
|
|
68
68
|
* **Mnemonic wallets:** group indices must remain contiguous starting at 0
|
|
@@ -135,53 +135,6 @@ class AccountTreeSnapshot {
|
|
|
135
135
|
}
|
|
136
136
|
return new AccountTreeSnapshot(filteredEntries, __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f"));
|
|
137
137
|
}
|
|
138
|
-
/**
|
|
139
|
-
* Returns a new snapshot with all secret material removed - mnemonic
|
|
140
|
-
* {@link AccountWalletMnemonicPayload.value | values} and private-key group
|
|
141
|
-
* {@link AccountWalletPrivateKeyGroupEntry.value | values} are omitted.
|
|
142
|
-
* Wallet and group metadata (names, pin, hidden) are preserved.
|
|
143
|
-
*
|
|
144
|
-
* Useful when only metadata (names, layout) needs to be applied and secrets
|
|
145
|
-
* are already present in the vault.
|
|
146
|
-
*
|
|
147
|
-
* @returns A secrets-stripped snapshot.
|
|
148
|
-
*/
|
|
149
|
-
stripSecrets() {
|
|
150
|
-
const entries = __classPrivateFieldGet(this, _AccountTreeSnapshot_entries, "f").map((wallet) => {
|
|
151
|
-
if (wallet.type === payload_js_1.AccountWalletPayloadType.Mnemonic) {
|
|
152
|
-
const { value: _value, ...rest } = wallet;
|
|
153
|
-
return rest;
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
...wallet,
|
|
157
|
-
groups: wallet.groups.map(({ value: _value, ...group }) => group),
|
|
158
|
-
};
|
|
159
|
-
});
|
|
160
|
-
return new AccountTreeSnapshot(entries, __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f"));
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Returns a new snapshot with all metadata reset to defaults - wallet names
|
|
164
|
-
* are cleared and group metadata (`name`, `pinned`, `hidden`) is reset.
|
|
165
|
-
* Secret values are preserved.
|
|
166
|
-
*
|
|
167
|
-
* Useful when importing secrets into a vault in a separate step from applying
|
|
168
|
-
* metadata - the metadata can be re-applied later from the original snapshot.
|
|
169
|
-
*
|
|
170
|
-
* @returns A metadata-stripped snapshot.
|
|
171
|
-
*/
|
|
172
|
-
stripMetadata() {
|
|
173
|
-
const entries = __classPrivateFieldGet(this, _AccountTreeSnapshot_entries, "f").map((wallet) => {
|
|
174
|
-
const { metadata: _walletMetadata, ...walletRest } = wallet;
|
|
175
|
-
return {
|
|
176
|
-
...walletRest,
|
|
177
|
-
groups: wallet.groups.map((group) => {
|
|
178
|
-
const { metadata: _groupMetadata, ...groupRest } = group;
|
|
179
|
-
return groupRest;
|
|
180
|
-
}),
|
|
181
|
-
}; // Looks like the compiler is not able to infer this correctly, but we just remove the `metadata` field out of any entry.
|
|
182
|
-
});
|
|
183
|
-
return new AccountTreeSnapshot(entries, __classPrivateFieldGet(this, _AccountTreeSnapshot_idMap, "f"));
|
|
184
|
-
}
|
|
185
138
|
/**
|
|
186
139
|
* Converts a payload ID (wallet or group) to the corresponding local
|
|
187
140
|
* `AccountTreeController` ID.
|
|
@@ -230,7 +183,7 @@ class AccountTreeSnapshot {
|
|
|
230
183
|
* versions and wallet types fail closed with an error instead of returning a
|
|
231
184
|
* partial snapshot.
|
|
232
185
|
*
|
|
233
|
-
* The returned snapshot has no ID map
|
|
186
|
+
* The returned snapshot has no ID map — {@link toLocalId} / {@link toPayloadId}
|
|
234
187
|
* return `undefined`. Pass an {@link IdMap} to the constructor when you need
|
|
235
188
|
* the map.
|
|
236
189
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.cjs","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAWA,8CAIsB;AACtB,0CAAwC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,mBAAmB;IAK9B;;;OAGG;IACH,YAAY,OAAiC,EAAE,KAAa;QARnD,+CAAmC;QAEnC,6CAA0B;QAOjC,uBAAA,IAAI,gCAAY,IAAA,qBAAU,EAAC,eAAe,CAAC,OAAO,CAAC,CAAC,MAAA,CAAC;QACrD,uBAAA,IAAI,8BAAU,KAAK,MAAA,CAAC;IACtB,CAAC;IAED;;;;;;;;;OASG;IACH,aAAa,CACX,SAAyD;QAEzD,MAAM,eAAe,GAAG,uBAAA,IAAI,oCAAS,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CACrD,SAAS,CAAC,KAAkC,CAAC,CAC9C,CAAC;QAEF,OAAO,IAAI,mBAAmB,CAAC,eAAe,EAAE,uBAAA,IAAI,kCAAO,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CACV,QAAgC,EAChC,SAAuD;QAEvD,MAAM,WAAW,GAAG,uBAAA,IAAI,oCAAS,CAAC,SAAS,CACzC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,QAAQ,CACjC,CAAC;QACF,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,iCAAiC,QAAQ,yBAAyB,CACnE,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,uBAAA,IAAI,oCAAS,CAAC,WAAW,CAAC,CAAC;QAE1C,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC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AAC,CAAC,CAAC;QACH,OAAO,IAAI,mBAAmB,CAAC,OAAO,EAAE,uBAAA,IAAI,kCAAO,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;;OASG;IACH,SAAS,CACP,SAAyD;QAEzD,OAAO,uBAAA,IAAI,kCAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;;;OASG;IACH,WAAW,CACT,OAAoC;QAEpC,OAAO,uBAAA,IAAI,kCAAO,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACH,SAAS;QACP,OAAO;YACL,OAAO,EAAE,iDAAoC;YAC7C,OAAO,EAAE,uBAAA,IAAI,oCAAS;SACvB,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,GAAY;QACnC,sCAAsC;QACtC,IAAA,qCAAwB,EAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,IAAI,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF;AAjQD,kDAiQC","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 * Returns a new snapshot with all secret material removed - mnemonic\n * {@link AccountWalletMnemonicPayload.value | values} and private-key group\n * {@link AccountWalletPrivateKeyGroupEntry.value | values} are omitted.\n * Wallet and group metadata (names, pin, hidden) are preserved.\n *\n * Useful when only metadata (names, layout) needs to be applied and secrets\n * are already present in the vault.\n *\n * @returns A secrets-stripped snapshot.\n */\n stripSecrets(): AccountTreeSnapshot {\n const entries = this.#entries.map((wallet): AccountTreeWalletEntry => {\n if (wallet.type === AccountWalletPayloadType.Mnemonic) {\n const { value: _value, ...rest } = wallet;\n return rest;\n }\n return {\n ...wallet,\n groups: wallet.groups.map(\n ({ value: _value, ...group }): AccountWalletPrivateKeyGroupEntry =>\n group,\n ),\n };\n });\n return new AccountTreeSnapshot(entries, this.#idMap);\n }\n\n /**\n * Returns a new snapshot with all metadata reset to defaults - wallet names\n * are cleared and group metadata (`name`, `pinned`, `hidden`) is reset.\n * Secret values are preserved.\n *\n * Useful when importing secrets into a vault in a separate step from applying\n * metadata - the metadata can be re-applied later from the original snapshot.\n *\n * @returns A metadata-stripped snapshot.\n */\n stripMetadata(): AccountTreeSnapshot {\n const entries = this.#entries.map((wallet): AccountTreeWalletEntry => {\n const { metadata: _walletMetadata, ...walletRest } = wallet;\n return {\n ...walletRest,\n groups: wallet.groups.map((group) => {\n const { metadata: _groupMetadata, ...groupRest } = group;\n return groupRest as typeof group;\n }),\n } as AccountTreeWalletEntry; // Looks like the compiler is not able to infer this correctly, but we just remove the `metadata` field out of any entry.\n });\n return new AccountTreeSnapshot(entries, 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
|
+
{"version":3,"file":"snapshot.cjs","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAWA,8CAIsB;AACtB,0CAAwC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,mBAAmB;IAK9B;;;OAGG;IACH,YAAY,OAAiC,EAAE,KAAa;QARnD,+CAAmC;QAEnC,6CAA0B;QAOjC,uBAAA,IAAI,gCAAY,IAAA,q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CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACH,SAAS;QACP,OAAO;YACL,OAAO,EAAE,iDAAoC;YAC7C,OAAO,EAAE,uBAAA,IAAI,oCAAS;SACvB,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,GAAY;QACnC,sCAAsC;QACtC,IAAA,qCAAwB,EAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,IAAI,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF;AA7MD,kDA6MC","sourcesContent":["import type { IdMap } from './id-map.js';\nimport type {\n AccountGroupPayloadId,\n AccountTreePayload,\n AccountTreeSnapshotGroup,\n AccountTreeSnapshotWallet,\n AccountTreeWalletEntry,\n AccountWalletMnemonicGroupEntry,\n AccountWalletPayloadId,\n AccountWalletPrivateKeyGroupEntry,\n} from './payload.js';\nimport {\n AccountWalletPayloadType,\n assertAccountTreePayload,\n ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION,\n} from './payload.js';\nimport { deepFreeze } from './utils.js';\n\n/**\n * Immutable value object returned by {@link AccountTreeController.exportState}.\n *\n * Construct with {@link AccountTreeController.exportState},\n * {@link AccountTreeSnapshot.deserialize}, or `new AccountTreeSnapshot(...)`\n * for tests and advanced use.\n *\n * Wallet and group entries are deep-cloned and deep-frozen once in the\n * constructor. Filtering predicates receive those read-only views directly;\n * each filter method returns a new snapshot that repeats the process for its\n * result.\n *\n * An optional ID map (local ↔ payload) may be supplied when bridging between\n * internal controller IDs and the stable cross-device IDs in the serialized\n * payload. The map covers the original export and is preserved unchanged\n * through filtering until {@link serialize}. Omit it when deterministic IDs\n * make {@link toLocalId} / {@link toPayloadId} unnecessary.\n */\nexport class AccountTreeSnapshot {\n readonly #entries: AccountTreeWalletEntry[];\n\n readonly #idMap: IdMap | undefined;\n\n /**\n * @param entries - Wallet entries in the snapshot.\n * @param idMap - Optional local ↔ payload ID map from export.\n */\n constructor(entries: AccountTreeWalletEntry[], idMap?: IdMap) {\n this.#entries = deepFreeze(structuredClone(entries));\n this.#idMap = idMap;\n }\n\n /**\n * Returns a new snapshot containing only the wallets for which\n * `predicate` returns `true`.\n *\n * When filtering by wallet ID, compare against stable payload IDs from\n * {@link serialize} or convert local IDs with {@link toPayloadId} first.\n *\n * @param predicate - Function called with each deeply read-only wallet entry.\n * @returns A filtered snapshot.\n */\n filterWallets(\n predicate: (wallet: AccountTreeSnapshotWallet) => boolean,\n ): AccountTreeSnapshot {\n const filteredEntries = this.#entries.filter((entry) =>\n predicate(entry as AccountTreeSnapshotWallet),\n );\n\n return new AccountTreeSnapshot(filteredEntries, this.#idMap);\n }\n\n /**\n * Filters groups within one wallet. Other wallets are left unchanged.\n *\n * Throws if `walletId` does not identify a wallet in the snapshot.\n * Removes the wallet if no groups remain after filtering — this prevents a\n * mnemonic wallet with zero selected groups from still transferring its secret.\n *\n * **Mnemonic wallets:** group indices must remain contiguous starting at 0\n * after filtering, because the payload schema enforces this invariant.\n * Predicates that produce gaps (e.g. keeping only index 1, or 0 and 2) will\n * cause {@link AccountTreeSnapshot.deserialize} to reject the payload on the\n * receiving end.\n *\n * @param walletId - Stable payload wallet ID to filter groups within.\n * @param predicate - Function called with each deeply read-only group entry.\n * @returns A filtered snapshot.\n * @throws If `walletId` is not present in the snapshot.\n */\n filterGroups(\n walletId: AccountWalletPayloadId,\n predicate: (group: AccountTreeSnapshotGroup) => boolean,\n ): AccountTreeSnapshot {\n const walletIndex = this.#entries.findIndex(\n (entry) => entry.id === walletId,\n );\n if (walletIndex === -1) {\n throw new Error(\n `Cannot filter groups: wallet \"${walletId}\" not found in snapshot`,\n );\n }\n\n const wallet = this.#entries[walletIndex];\n\n const filteredGroups = wallet.groups.filter((group) =>\n predicate(group as AccountTreeSnapshotGroup),\n );\n\n const filteredEntries = [...this.#entries];\n if (filteredGroups.length === 0) {\n filteredEntries.splice(walletIndex, 1);\n } else if (wallet.type === AccountWalletPayloadType.Mnemonic) {\n filteredEntries[walletIndex] = {\n ...wallet,\n groups: filteredGroups as AccountWalletMnemonicGroupEntry[],\n };\n } else {\n filteredEntries[walletIndex] = {\n ...wallet,\n groups: filteredGroups as AccountWalletPrivateKeyGroupEntry[],\n };\n }\n\n return new AccountTreeSnapshot(filteredEntries, this.#idMap);\n }\n\n /**\n * Filters groups across every wallet.\n *\n * The parent wallet is provided as context to the predicate. Removes any\n * wallet with no remaining groups after filtering.\n *\n * **Mnemonic wallets:** see {@link filterGroups} for the contiguous-index\n * constraint that applies here as well.\n *\n * @param predicate - Function called with each group and its parent wallet.\n * @returns A filtered snapshot.\n */\n filterAllGroups(\n predicate: (\n group: AccountTreeSnapshotGroup,\n wallet: AccountTreeSnapshotWallet,\n ) => boolean,\n ): AccountTreeSnapshot {\n const filteredEntries: AccountTreeWalletEntry[] = [];\n\n for (const wallet of this.#entries) {\n const filteredGroups = wallet.groups.filter((group) =>\n predicate(\n group as AccountTreeSnapshotGroup,\n wallet as AccountTreeSnapshotWallet,\n ),\n );\n\n if (filteredGroups.length === 0) {\n continue;\n }\n\n if (wallet.type === AccountWalletPayloadType.Mnemonic) {\n filteredEntries.push({\n ...wallet,\n groups: filteredGroups as AccountWalletMnemonicGroupEntry[],\n });\n } else {\n filteredEntries.push({\n ...wallet,\n groups: filteredGroups as AccountWalletPrivateKeyGroupEntry[],\n });\n }\n }\n\n return new AccountTreeSnapshot(filteredEntries, this.#idMap);\n }\n\n /**\n * Converts a payload ID (wallet or group) to the corresponding local\n * `AccountTreeController` ID.\n *\n * The map reflects the original export, not the wallets/groups currently\n * retained in this snapshot after filtering.\n *\n * @param payloadId - Stable cross-device wallet or group payload ID.\n * @returns The local controller ID, or `undefined` if not found or no ID map is present.\n */\n toLocalId(\n payloadId: AccountWalletPayloadId | AccountGroupPayloadId,\n ): ReturnType<IdMap['getLocalId']> {\n return this.#idMap?.getLocalId(payloadId);\n }\n\n /**\n * Converts a local `AccountTreeController` ID (wallet or group) to its\n * stable cross-device payload ID.\n *\n * The map reflects the original export, not the wallets/groups currently\n * retained in this snapshot after filtering.\n *\n * @param localId - Local controller wallet or group ID.\n * @returns The payload ID, or `undefined` if not found or no ID map is present.\n */\n toPayloadId(\n localId: Parameters<IdMap['add']>[0],\n ): ReturnType<IdMap['getPayloadId']> {\n return this.#idMap?.getPayloadId(localId);\n }\n\n /**\n * Serializes the snapshot to a flat {@link AccountTreePayload} with `version` inlined\n * alongside the wallet entries.\n *\n * Returns the constructor-frozen wallet tree without copying it again.\n *\n * @returns The versioned flat payload.\n */\n serialize(): AccountTreePayload {\n return {\n version: ACCOUNT_TREE_PAYLOAD_CURRENT_VERSION,\n wallets: this.#entries,\n };\n }\n\n /**\n * Validates a raw value as an {@link AccountTreePayload}, running any\n * necessary version migrations, and returns an immutable snapshot.\n *\n * This is the entry point for untrusted serialized data. Unsupported schema\n * versions and wallet types fail closed with an error instead of returning a\n * partial snapshot.\n *\n * The returned snapshot has no ID map — {@link toLocalId} / {@link toPayloadId}\n * return `undefined`. Pass an {@link IdMap} to the constructor when you need\n * the map.\n *\n * @param raw - Unknown value to parse.\n * @returns A validated snapshot.\n * @throws If `raw` is not a valid payload or its version is unsupported.\n */\n static async deserialize(raw: unknown): Promise<AccountTreeSnapshot> {\n // TODO: Use migration framework here.\n assertAccountTreePayload(raw);\n return new AccountTreeSnapshot(raw.wallets);\n }\n}\n"]}
|
|
@@ -40,7 +40,7 @@ export declare class AccountTreeSnapshot {
|
|
|
40
40
|
* Filters groups within one wallet. Other wallets are left unchanged.
|
|
41
41
|
*
|
|
42
42
|
* Throws if `walletId` does not identify a wallet in the snapshot.
|
|
43
|
-
* Removes the wallet if no groups remain after filtering
|
|
43
|
+
* Removes the wallet if no groups remain after filtering — this prevents a
|
|
44
44
|
* mnemonic wallet with zero selected groups from still transferring its secret.
|
|
45
45
|
*
|
|
46
46
|
* **Mnemonic wallets:** group indices must remain contiguous starting at 0
|
|
@@ -68,29 +68,6 @@ export declare class AccountTreeSnapshot {
|
|
|
68
68
|
* @returns A filtered snapshot.
|
|
69
69
|
*/
|
|
70
70
|
filterAllGroups(predicate: (group: AccountTreeSnapshotGroup, wallet: AccountTreeSnapshotWallet) => boolean): AccountTreeSnapshot;
|
|
71
|
-
/**
|
|
72
|
-
* Returns a new snapshot with all secret material removed - mnemonic
|
|
73
|
-
* {@link AccountWalletMnemonicPayload.value | values} and private-key group
|
|
74
|
-
* {@link AccountWalletPrivateKeyGroupEntry.value | values} are omitted.
|
|
75
|
-
* Wallet and group metadata (names, pin, hidden) are preserved.
|
|
76
|
-
*
|
|
77
|
-
* Useful when only metadata (names, layout) needs to be applied and secrets
|
|
78
|
-
* are already present in the vault.
|
|
79
|
-
*
|
|
80
|
-
* @returns A secrets-stripped snapshot.
|
|
81
|
-
*/
|
|
82
|
-
stripSecrets(): AccountTreeSnapshot;
|
|
83
|
-
/**
|
|
84
|
-
* Returns a new snapshot with all metadata reset to defaults - wallet names
|
|
85
|
-
* are cleared and group metadata (`name`, `pinned`, `hidden`) is reset.
|
|
86
|
-
* Secret values are preserved.
|
|
87
|
-
*
|
|
88
|
-
* Useful when importing secrets into a vault in a separate step from applying
|
|
89
|
-
* metadata - the metadata can be re-applied later from the original snapshot.
|
|
90
|
-
*
|
|
91
|
-
* @returns A metadata-stripped snapshot.
|
|
92
|
-
*/
|
|
93
|
-
stripMetadata(): AccountTreeSnapshot;
|
|
94
71
|
/**
|
|
95
72
|
* Converts a payload ID (wallet or group) to the corresponding local
|
|
96
73
|
* `AccountTreeController` ID.
|
|
@@ -130,7 +107,7 @@ export declare class AccountTreeSnapshot {
|
|
|
130
107
|
* versions and wallet types fail closed with an error instead of returning a
|
|
131
108
|
* partial snapshot.
|
|
132
109
|
*
|
|
133
|
-
* The returned snapshot has no ID map
|
|
110
|
+
* The returned snapshot has no ID map — {@link toLocalId} / {@link toPayloadId}
|
|
134
111
|
* return `undefined`. Pass an {@link IdMap} to the constructor when you need
|
|
135
112
|
* the map.
|
|
136
113
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.d.cts","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,qBAAoB;AACzC,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EAEtB,sBAAsB,EAEvB,sBAAqB;AAQtB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,mBAAmB;;IAK9B;;;OAGG;gBACS,OAAO,EAAE,sBAAsB,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK;IAK5D;;;;;;;;;OASG;IACH,aAAa,CACX,SAAS,EAAE,CAAC,MAAM,EAAE,yBAAyB,KAAK,OAAO,GACxD,mBAAmB;IAQtB;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CACV,QAAQ,EAAE,sBAAsB,EAChC,SAAS,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,OAAO,GACtD,mBAAmB;IAkCtB;;;;;;;;;;;OAWG;IACH,eAAe,CACb,SAAS,EAAE,CACT,KAAK,EAAE,wBAAwB,EAC/B,MAAM,EAAE,yBAAyB,KAC9B,OAAO,GACX,mBAAmB;IA+BtB
|
|
1
|
+
{"version":3,"file":"snapshot.d.cts","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,qBAAoB;AACzC,OAAO,KAAK,EACV,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EAEtB,sBAAsB,EAEvB,sBAAqB;AAQtB;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,mBAAmB;;IAK9B;;;OAGG;gBACS,OAAO,EAAE,sBAAsB,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK;IAK5D;;;;;;;;;OASG;IACH,aAAa,CACX,SAAS,EAAE,CAAC,MAAM,EAAE,yBAAyB,KAAK,OAAO,GACxD,mBAAmB;IAQtB;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CACV,QAAQ,EAAE,sBAAsB,EAChC,SAAS,EAAE,CAAC,KAAK,EAAE,wBAAwB,KAAK,OAAO,GACtD,mBAAmB;IAkCtB;;;;;;;;;;;OAWG;IACH,eAAe,CACb,SAAS,EAAE,CACT,KAAK,EAAE,wBAAwB,EAC/B,MAAM,EAAE,yBAAyB,KAC9B,OAAO,GACX,mBAAmB;IA+BtB;;;;;;;;;OASG;IACH,SAAS,CACP,SAAS,EAAE,sBAAsB,GAAG,qBAAqB,GACxD,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAIlC;;;;;;;;;OASG;IACH,WAAW,CACT,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GACnC,UAAU,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAIpC;;;;;;;OAOG;IACH,SAAS,IAAI,kBAAkB;IAO/B;;;;;;;;;;;;;;;OAeG;WACU,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAKrE"}
|
|
@@ -40,7 +40,7 @@ export declare class AccountTreeSnapshot {
|
|
|
40
40
|
* Filters groups within one wallet. Other wallets are left unchanged.
|
|
41
41
|
*
|
|
42
42
|
* Throws if `walletId` does not identify a wallet in the snapshot.
|
|
43
|
-
* Removes the wallet if no groups remain after filtering
|
|
43
|
+
* Removes the wallet if no groups remain after filtering — this prevents a
|
|
44
44
|
* mnemonic wallet with zero selected groups from still transferring its secret.
|
|
45
45
|
*
|
|
46
46
|
* **Mnemonic wallets:** group indices must remain contiguous starting at 0
|
|
@@ -68,29 +68,6 @@ export declare class AccountTreeSnapshot {
|
|
|
68
68
|
* @returns A filtered snapshot.
|
|
69
69
|
*/
|
|
70
70
|
filterAllGroups(predicate: (group: AccountTreeSnapshotGroup, wallet: AccountTreeSnapshotWallet) => boolean): AccountTreeSnapshot;
|
|
71
|
-
/**
|
|
72
|
-
* Returns a new snapshot with all secret material removed - mnemonic
|
|
73
|
-
* {@link AccountWalletMnemonicPayload.value | values} and private-key group
|
|
74
|
-
* {@link AccountWalletPrivateKeyGroupEntry.value | values} are omitted.
|
|
75
|
-
* Wallet and group metadata (names, pin, hidden) are preserved.
|
|
76
|
-
*
|
|
77
|
-
* Useful when only metadata (names, layout) needs to be applied and secrets
|
|
78
|
-
* are already present in the vault.
|
|
79
|
-
*
|
|
80
|
-
* @returns A secrets-stripped snapshot.
|
|
81
|
-
*/
|
|
82
|
-
stripSecrets(): AccountTreeSnapshot;
|
|
83
|
-
/**
|
|
84
|
-
* Returns a new snapshot with all metadata reset to defaults - wallet names
|
|
85
|
-
* are cleared and group metadata (`name`, `pinned`, `hidden`) is reset.
|
|
86
|
-
* Secret values are preserved.
|
|
87
|
-
*
|
|
88
|
-
* Useful when importing secrets into a vault in a separate step from applying
|
|
89
|
-
* metadata - the metadata can be re-applied later from the original snapshot.
|
|
90
|
-
*
|
|
91
|
-
* @returns A metadata-stripped snapshot.
|
|
92
|
-
*/
|
|
93
|
-
stripMetadata(): AccountTreeSnapshot;
|
|
94
71
|
/**
|
|
95
72
|
* Converts a payload ID (wallet or group) to the corresponding local
|
|
96
73
|
* `AccountTreeController` ID.
|
|
@@ -130,7 +107,7 @@ export declare class AccountTreeSnapshot {
|
|
|
130
107
|
* versions and wallet types fail closed with an error instead of returning a
|
|
131
108
|
* partial snapshot.
|
|
132
109
|
*
|
|
133
|
-
* The returned snapshot has no ID map
|
|
110
|
+
* The returned snapshot has no ID map — {@link toLocalId} / {@link toPayloadId}
|
|
134
111
|
* return `undefined`. Pass an {@link IdMap} to the constructor when you need
|
|
135
112
|
* the map.
|
|
136
113
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.d.mts","sourceRoot":"","sources":["../../src/state/snapshot.ts"],"names":[],"mappings":"AA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