{"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../src/wallet.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountGroupId } from '@metamask/account-api';\nimport type {\n  AccountWalletType,\n  AccountWalletId,\n  MultichainAccountWalletId,\n  AccountWalletStatus,\n} from '@metamask/account-api';\nimport type { MultichainAccountWalletStatus } from '@metamask/account-api';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport type { KeyringTypes } from '@metamask/keyring-controller';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport type {\n  AccountGroupMultichainAccountObject,\n  AccountGroupObject,\n  AccountGroupSingleAccountObject,\n} from './group';\nimport type { UpdatableField, ExtractFieldValues } from './type-utils.js';\n\n/**\n * Persisted metadata for account wallets (stored in controller state for persistence/sync).\n */\nexport type AccountTreeWalletPersistedMetadata = {\n  /** Custom name set by user, overrides default naming logic */\n  name?: UpdatableField<string>;\n};\n\n/**\n * Tree metadata for account wallets (required plain values extracted from persisted metadata).\n */\nexport type AccountTreeWalletMetadata = Required<\n  ExtractFieldValues<AccountTreeWalletPersistedMetadata>\n>;\n\n/**\n * Type constraint for a {@link AccountGroupObject}. If one of its union-members\n * does not match this contraint, {@link AccountGroupObject} will resolve\n * to `never`.\n */\ntype IsAccountWalletObject<\n  Type extends {\n    type: AccountWalletType;\n    id: AccountWalletId;\n    status: string; // Has to be refined by the type extending this base type.\n    groups: {\n      [groupId: AccountGroupId]: AccountGroupObject;\n    };\n    metadata: AccountTreeWalletMetadata;\n  },\n> = Type;\n\n/**\n * Account wallet object for the \"entropy\" wallet category.\n */\nexport type AccountWalletEntropyObject = {\n  type: AccountWalletType.Entropy;\n  id: MultichainAccountWalletId;\n  status: MultichainAccountWalletStatus;\n  groups: {\n    // NOTE: Using `MultichainAccountGroupId` instead of `AccountGroupId` would introduce\n    // some type problems when using a group ID as an `AccountGroupId` directly. This\n    // would require some up-cast to a `MultichainAccountGroupId` which could be considered\n    // unsafe... So we keep it as a `AccountGroupId` for now.\n    [groupId: AccountGroupId]: AccountGroupMultichainAccountObject;\n  };\n  metadata: AccountTreeWalletMetadata & {\n    entropy: {\n      id: EntropySourceId;\n    };\n  };\n};\n\n/**\n * Account wallet object for the \"snap\" wallet category.\n */\nexport type AccountWalletSnapObject = {\n  type: AccountWalletType.Snap;\n  id: AccountWalletId;\n  status: AccountWalletStatus;\n  groups: {\n    [groupId: AccountGroupId]: AccountGroupSingleAccountObject;\n  };\n  metadata: AccountTreeWalletMetadata & {\n    snap: {\n      id: SnapId;\n    };\n  };\n};\n\n/**\n * Account wallet object for the \"keyring\" wallet category.\n */\nexport type AccountWalletKeyringObject = {\n  type: AccountWalletType.Keyring;\n  id: AccountWalletId;\n  status: AccountWalletStatus;\n  groups: {\n    [groupId: AccountGroupId]: AccountGroupSingleAccountObject;\n  };\n  metadata: AccountTreeWalletMetadata & {\n    keyring: {\n      type: KeyringTypes;\n    };\n  };\n};\n\n/**\n * Account wallet metadata for the \"keyring\" wallet category.\n */\nexport type AccountWalletObject = IsAccountWalletObject<\n  | AccountWalletEntropyObject\n  | AccountWalletSnapObject\n  | AccountWalletKeyringObject\n>;\n\nexport type AccountWalletObjectOf<WalletType extends AccountWalletType> =\n  Extract<\n    | { type: AccountWalletType.Entropy; object: AccountWalletEntropyObject }\n    | { type: AccountWalletType.Keyring; object: AccountWalletKeyringObject }\n    | { type: AccountWalletType.Snap; object: AccountWalletSnapObject },\n    { type: WalletType }\n  >['object'];\n"]}