{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/v2/api/create-account/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAyHA,oFAeC;AAxID,2DAAyD;AAGzD,uCAKiB;AACjB,yCAA4D;AAC5D,mDAAqE;AAErE,8CAAwB;AACxB,+CAAyB;AACzB,oDAA8B;AAE9B;;GAEG;AACH,IAAY,mBA6CX;AA7CD,WAAY,mBAAmB;IAC7B;;OAEG;IACH,4DAAqC,CAAA;IAErC;;;;;;OAMG;IACH,8DAAuC,CAAA;IAEvC;;;;;;OAMG;IACH,yEAAkD,CAAA;IAElD;;;;;;OAMG;IACH,uDAAgC,CAAA;IAEhC;;OAEG;IACH,8DAAuC,CAAA;IAEvC;;;;;OAKG;IACH,wCAAiB,CAAA;AACnB,CAAC,EA7CW,mBAAmB,mCAAnB,mBAAmB,QA6C9B;AAED;;GAEG;AACU,QAAA,0BAA0B,GAAG,IAAA,8BAAc,EAAC,CAAC,KAAU,EAAE,EAAE;IACtE,MAAM,mBAAmB,GAAG,KAAK,EAAE,IAA2B,CAAC;IAC/D,QAAQ,mBAAmB,EAAE,CAAC;QAC5B,KAAK,mBAAmB,CAAC,eAAe;YACtC,OAAO,iDAAyC,CAAC;QACnD,KAAK,mBAAmB,CAAC,gBAAgB;YACvC,OAAO,kDAA0C,CAAC;QACpD,KAAK,mBAAmB,CAAC,qBAAqB;YAC5C,OAAO,uDAA+C,CAAC;QACzD,KAAK,mBAAmB,CAAC,aAAa;YACpC,OAAO,+CAAuC,CAAC;QACjD,KAAK,mBAAmB,CAAC,gBAAgB;YACvC,OAAO,kDAAoC,CAAC;QAC9C,KAAK,mBAAmB,CAAC,MAAM;YAC7B,OAAO,yCAAgC,CAAC;QAC1C;YACE,wGAAwG;YACxG,OAAO,iDAAyC,CAAC;IACrD,CAAC;AACH,CAAC,CAAC,CAAC;AAOH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,oCAAoC,CAKlD,OAAgB,EAChB,cAAoC;IAGpC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACzB,MAAM,KAAK,GAA4C,cAAc,CAAC;IAEtE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,2CAA2C,IAAI,EAAE,CAAC,CAAC;IACrE,CAAC;AACH,CAAC","sourcesContent":["import { selectiveUnion } from '@metamask/keyring-utils';\nimport type { Infer } from '@metamask/superstruct';\n\nimport {\n  CreateAccountBip44DiscoverOptionsStruct,\n  CreateAccountBip44DeriveIndexOptionsStruct,\n  CreateAccountBip44DeriveIndexRangeOptionsStruct,\n  CreateAccountBip44DerivePathOptionsStruct,\n} from './bip44';\nimport { CreateAccountCustomOptionsStruct } from './custom';\nimport { CreateAccountPrivateKeyOptionsStruct } from './private-key';\n\nexport * from './bip44';\nexport * from './custom';\nexport * from './private-key';\n\n/**\n * Enum representing the different ways an account can be created.\n */\nexport enum AccountCreationType {\n  /**\n   * Represents an account created using a BIP-44 derivation path.\n   */\n  Bip44DerivePath = 'bip44:derive-path',\n\n  /**\n   * Represents accounts created using a BIP-44 account index.\n   *\n   * More than one account can be created, for example, the keyring can create\n   * multiple account types (e.g., P2PKH, P2TR, P2WPKH) for the same account\n   * index.\n   */\n  Bip44DeriveIndex = 'bip44:derive-index',\n\n  /**\n   * Represents accounts created by deriving a range of BIP-44 account indices.\n   *\n   * More than one account can be created per index, for example, the keyring\n   * can create multiple account types (e.g., P2PKH, P2TR, P2WPKH) for each\n   * account index in the range.\n   */\n  Bip44DeriveIndexRange = 'bip44:derive-index-range',\n\n  /**\n   * Represents accounts created through BIP-44 account discovery.\n   *\n   * More than one account can be created, for example, the keyring can create\n   * multiple account types (e.g., P2PKH, P2TR, P2WPKH) for the same account\n   * index.\n   */\n  Bip44Discover = 'bip44:discover',\n\n  /**\n   * Represents an account imported from a private key.\n   */\n  PrivateKeyImport = 'private-key:import',\n\n  /**\n   * Represents an account created using a custom, keyring-specific method.\n   *\n   * This is used by keyrings that have non-standard account creation flows\n   * and declare `custom.createAccounts: true` in their capabilities.\n   */\n  Custom = 'custom',\n}\n\n/**\n * Struct for {@link CreateAccountOptions}.\n */\nexport const CreateAccountOptionsStruct = selectiveUnion((value: any) => {\n  const accountCreationType = value?.type as AccountCreationType;\n  switch (accountCreationType) {\n    case AccountCreationType.Bip44DerivePath:\n      return CreateAccountBip44DerivePathOptionsStruct;\n    case AccountCreationType.Bip44DeriveIndex:\n      return CreateAccountBip44DeriveIndexOptionsStruct;\n    case AccountCreationType.Bip44DeriveIndexRange:\n      return CreateAccountBip44DeriveIndexRangeOptionsStruct;\n    case AccountCreationType.Bip44Discover:\n      return CreateAccountBip44DiscoverOptionsStruct;\n    case AccountCreationType.PrivateKeyImport:\n      return CreateAccountPrivateKeyOptionsStruct;\n    case AccountCreationType.Custom:\n      return CreateAccountCustomOptionsStruct;\n    default:\n      // Return first struct as fallback - validation will fail with proper error indicating the type mismatch\n      return CreateAccountBip44DerivePathOptionsStruct;\n  }\n});\n\n/**\n * Represents the available options for creating a new account.\n */\nexport type CreateAccountOptions = Infer<typeof CreateAccountOptionsStruct>;\n\n/**\n * Asserts that a given create account option type is supported by the keyring.\n *\n * @example\n * ```ts\n * createAccounts(options: CreateAccountOptions) {\n *   assertCreateAccountOptionIsSupported(options, [\n *     ${AccountCreationType.Bip44DeriveIndex},\n *     ${AccountCreationType.Bip44DeriveIndexRange},\n *   ] as const);\n *\n *   // At this point, TypeScript knows that options.type is either Bip44DeriveIndex or Bip44DeriveIndexRange.\n *   if (options.type === AccountCreationType.Bip44DeriveIndex) {\n *     ... // Handle Bip44DeriveIndex case.\n *   } else {\n *     ... // Handle Bip44DeriveIndexRange case.\n *   }\n *   ...\n *   return accounts;\n * }\n * ```\n *\n * @param options - The create account option object to check.\n * @param supportedTypes - The list of supported create account option types for this keyring.\n * @throws Will throw an error if the provided options are not supported.\n */\nexport function assertCreateAccountOptionIsSupported<\n  Options extends CreateAccountOptions,\n  // We use template literal types to enforce string-literal over strict enum values.\n  Type extends `${CreateAccountOptions['type']}`,\n>(\n  options: Options,\n  supportedTypes: readonly `${Type}`[],\n  // Use intersection to avoid widening `type` beyond `Options['type']`.\n): asserts options is Options & { type: `${Type}` & `${Options['type']}` } {\n  const { type } = options;\n  const types: readonly CreateAccountOptions['type'][] = supportedTypes;\n\n  if (!types.includes(type)) {\n    throw new Error(`Unsupported create account option type: ${type}`);\n  }\n}\n"]}