{"version":3,"file":"account-options.mjs","sourceRoot":"","sources":["../../src/api/account-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,IAAI,EAAE,gCAAgC;AAE9E,OAAO,EACL,OAAO,EACP,YAAY,EACZ,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACP,8BAA8B;AAC/B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,wBAAwB;AAE5D;;GAEG;AACH,MAAM,CAAN,IAAY,+BAgBX;AAhBD,WAAY,+BAA+B;IACzC;;OAEG;IACH,wDAAqB,CAAA;IAErB;;OAEG;IACH,6DAA0B,CAAA;IAE1B;;;OAGG;IACH,oDAAiB,CAAA;AACnB,CAAC,EAhBW,+BAA+B,KAA/B,+BAA+B,QAgB1C;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,0CAA0C,GAAG,MAAM,CAAC;IAC/D;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC,GAAG,+BAA+B,CAAC,QAAQ,EAAE,CAAC;IAE5D;;OAEG;IACH,EAAE,EAAE,MAAM,EAAE,EAAE,4CAA4C;IAE1D;;OAEG;IACH,cAAc,EAAE,MAAM,EAAE;IAExB;;;;;OAKG;IACH,UAAU,EAAE,MAAM,EAAE;CACrB,CAAC,CAAC;AASH;;GAEG;AACH,MAAM,CAAC,MAAM,4CAA4C,GAAG,MAAM,CAAC;IACjE;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC,GAAG,+BAA+B,CAAC,UAAU,EAAE,CAAC;CAC/D,CAAC,CAAC;AASH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAG,MAAM,CAAC;IAC7D;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC,GAAG,+BAA+B,CAAC,MAAM,EAAE,CAAC;CAC3D,CAAC,CAAC;AASH;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,cAAc,CAC9D,CAAC,KAAU,EAAE,EAAE;IACb,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,0CAA0C,CAAC;IACpD,CAAC;IAED,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,+BAA+B,CAAC,UAAU;YAC7C,OAAO,4CAA4C,CAAC;QACtD,KAAK,+BAA+B,CAAC,MAAM;YACzC,OAAO,wCAAwC,CAAC;QAClD,KAAK,+BAA+B,CAAC,QAAQ;YAC3C,OAAO,0CAA0C,CAAC;QACpD;YACE,OAAO,0CAA0C,CAAC;IACtD,CAAC;AACH,CAAC,CACF,CAAC;AASF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,YAAY,CAAC;IACtD,2CAA2C;IAC3C,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC;IAE5B,kEAAkE;IAClE,oEAAoE;IACpE,oEAAoE;IACpE,EAAE;IACF,uBAAuB;IACvB,uEAAuE;IACvE,oCAAoC;IACpC,IAAI,CAAC;QACH;;WAEG;QACH,OAAO,EAAE,aAAa,CAAC,kCAAkC,CAAC;QAE1D;;WAEG;QACH,UAAU,EAAE,aAAa,CAAC,OAAO,EAAE,CAAC;KACrC,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { exactOptional, selectiveUnion, type } from '@metamask/keyring-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n  boolean,\n  intersection,\n  literal,\n  number,\n  object,\n  record,\n  string,\n} from '@metamask/superstruct';\nimport { isPlainObject, JsonStruct } from '@metamask/utils';\n\n/**\n * Keyring account entropy valid types.\n */\nexport enum KeyringAccountEntropyTypeOption {\n  /**\n   * Indicates that the account was created from a mnemonic phrase.\n   */\n  Mnemonic = 'mnemonic',\n\n  /**\n   * Indicates that the account was imported from a private key.\n   */\n  PrivateKey = 'private-key',\n\n  /**\n   * Indicates that the account was created with custom, keyring-specific entropy.\n   * This is an opaque type where the entropy source is managed internally by the keyring.\n   */\n  Custom = 'custom',\n}\n\n/**\n * Keyring account options struct for mnemonics (BIP-44).\n */\nexport const KeyringAccountEntropyMnemonicOptionsStruct = object({\n  /**\n   * Indicates that the account was created from a mnemonic phrase.\n   */\n  type: literal(`${KeyringAccountEntropyTypeOption.Mnemonic}`),\n\n  /**\n   * The ID of the entropy source.\n   */\n  id: string(), // TODO: Define a struct for entropy source.\n\n  /**\n   * The BIP-44 derivation path used to derive the account.\n   */\n  derivationPath: string(),\n\n  /**\n   * Index used to group accounts in the UI.\n   *\n   * Accounts sharing the same `groupIndex` are displayed together as a\n   * multichain account group.\n   */\n  groupIndex: number(),\n});\n\n/**\n * Keyring account options for mnemonics (BIP-44) {@link KeyringAccountEntropyMnemonicOptionsStruct}.\n */\nexport type KeyringAccountEntropyMnemonicOptions = Infer<\n  typeof KeyringAccountEntropyMnemonicOptionsStruct\n>;\n\n/**\n * Keyring account options struct for private keys.\n */\nexport const KeyringAccountEntropyPrivateKeyOptionsStruct = object({\n  /**\n   * Indicates that the account was imported from a private key.\n   */\n  type: literal(`${KeyringAccountEntropyTypeOption.PrivateKey}`),\n});\n\n/**\n * Keyring account options for private keys {@link KeyringAccountEntropyPrivateKeyOptionsStruct}.\n */\nexport type KeyringAccountEntropyPrivateKeyOptions = Infer<\n  typeof KeyringAccountEntropyPrivateKeyOptionsStruct\n>;\n\n/**\n * Keyring account options struct for custom entropy.\n *\n * This is an opaque type where the entropy source is managed internally by the keyring.\n * It behaves similarly to a private key import but allows keyrings to define their own\n * entropy management strategy.\n */\nexport const KeyringAccountEntropyCustomOptionsStruct = object({\n  /**\n   * Indicates that the account was created with custom, keyring-specific entropy.\n   */\n  type: literal(`${KeyringAccountEntropyTypeOption.Custom}`),\n});\n\n/**\n * Keyring account options for custom entropy {@link KeyringAccountEntropyCustomOptionsStruct}.\n */\nexport type KeyringAccountEntropyCustomOptions = Infer<\n  typeof KeyringAccountEntropyCustomOptionsStruct\n>;\n\n/**\n * Keyring account entropy options struct.\n */\nexport const KeyringAccountEntropyOptionsStruct = selectiveUnion(\n  (value: any) => {\n    if (!isPlainObject(value)) {\n      return KeyringAccountEntropyMnemonicOptionsStruct;\n    }\n\n    switch (value.type) {\n      case KeyringAccountEntropyTypeOption.PrivateKey:\n        return KeyringAccountEntropyPrivateKeyOptionsStruct;\n      case KeyringAccountEntropyTypeOption.Custom:\n        return KeyringAccountEntropyCustomOptionsStruct;\n      case KeyringAccountEntropyTypeOption.Mnemonic:\n        return KeyringAccountEntropyMnemonicOptionsStruct;\n      default:\n        return KeyringAccountEntropyMnemonicOptionsStruct;\n    }\n  },\n);\n\n/**\n * Keyring account entropy options {@link KeyringAccountEntropyOptionsStruct}.\n */\nexport type KeyringAccountEntropyOptions = Infer<\n  typeof KeyringAccountEntropyOptionsStruct\n>;\n\n/**\n * Keyring options struct. This represents various options for a Keyring account object.\n *\n * See {@link KeyringAccountEntropyMnemonicOptionsStruct},\n * {@link KeyringAccountEntropyPrivateKeyOptionsStruct}, and\n * {@link KeyringAccountEntropyCustomOptionsStruct}.\n *\n * @example\n * ```ts\n * {\n *   entropy: {\n *     type: 'mnemonic',\n *     id: '01K0BX6VDR5DPDPGGNA8PZVBVB',\n *     derivationPath: \"m/44'/60'/0'/0/0\",\n *     groupIndex: 0,\n *   },\n * }\n * ```\n *\n * @example\n * ```ts\n * {\n *   entropy: {\n *     type: 'private-key',\n *   },\n *   exportable: true,\n * }\n * ```\n *\n * @example\n * ```ts\n * {\n *   entropy: {\n *     type: 'custom',\n *   },\n * }\n * ```\n *\n * @example\n * ```ts\n * {\n *   some: {\n *     untyped: 'options',\n *     something: true,\n *   },\n * }\n * ```\n */\nexport const KeyringAccountOptionsStruct = intersection([\n  // Non-Typed options (retro-compatibility):\n  record(string(), JsonStruct),\n\n  // Typed options. We use `type` instead of `object` here, to allow\n  // extra properties. Also, since we use `record` + `intersection` we\n  // are guaranteed that all field values will match the `JsonStruct`.\n  //\n  // READ THIS CAREFULLY:\n  // Previous options that can be matched by this struct will be breaking\n  // existing keyring account options.\n  type({\n    /**\n     * Entropy options.\n     */\n    entropy: exactOptional(KeyringAccountEntropyOptionsStruct),\n\n    /**\n     * Indicates whether the account can be exported.\n     */\n    exportable: exactOptional(boolean()),\n  }),\n]);\n\n/**\n * Keyring account options {@link KeyringAccountOptionsStruct}.\n */\nexport type KeyringAccountOptions = Infer<typeof KeyringAccountOptionsStruct>;\n"]}