@metamask/keyring-utils
Version:
MetaMask Keyring utils
1 lines • 2.65 kB
Source Map (JSON)
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,8BAA8B;AAC3D,OAAO,EAAE,aAAa,EAAE,wBAAwB;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AACF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC,CAAC,oCAAoC;AAG/E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from '@metamask/superstruct';\nimport { definePattern } from '@metamask/utils';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n/**\n * Account ID (UUIDv4).\n */\nexport const AccountIdStruct = UuidStruct; // Alias for better naming purposes.\nexport type AccountId = Infer<typeof AccountIdStruct>; // Alias for better naming purposes.\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n\n/**\n * This is a helper type used by the {@link Equals} type.\n */\ntype EqualsHelper<Type> = <Dummy>() => Dummy extends Type ? 1 : 2;\n\n/**\n * A utility type that checks whether two types are exactly the same.\n *\n * This type evaluates to `true` if `TypeA` and `TypeB` are identical,\n * otherwise it evaluates to `false`.\n *\n * @template TypeA - The first type to compare.\n * @template TypeB - The second type to compare.\n *\n * @example\n * ```ts\n * // Example usage:\n * type Test1 = Equals<number, number>; // true\n * type Test2 = Equals<number, string>; // false\n * type Test3 = Equals<{ a: string }, { a: string }>; // true\n * type Test4 = Equals<{ a: string }, { a: number }>; // false\n * ```\n */\nexport type Equals<TypeA, TypeB> =\n EqualsHelper<TypeA> extends EqualsHelper<TypeB> ? true : false;\n"]}