UNPKG

@metamask/keyring-api

Version:
80 lines 2.7 kB
import { object } from "@metamask/keyring-utils"; import { nonempty, array, enums, literal } from "@metamask/superstruct"; import { definePattern } from "@metamask/utils"; import { EthScope } from "./index.mjs"; import { CaipChainIdStruct, EthAccountType, KeyringAccountStruct } from "../api/index.mjs"; export const EthBytesStruct = definePattern('EthBytes', /^0x[0-9a-f]*$/iu); export const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu); export const EthUint256Struct = definePattern('EthUint256', /^0x([1-9a-f][0-9a-f]*|0)$/iu); /** * Supported Ethereum methods. */ export var EthMethod; (function (EthMethod) { // General signing methods EthMethod["PersonalSign"] = "personal_sign"; EthMethod["Sign"] = "eth_sign"; EthMethod["SignTransaction"] = "eth_signTransaction"; EthMethod["SignTypedDataV1"] = "eth_signTypedData_v1"; EthMethod["SignTypedDataV3"] = "eth_signTypedData_v3"; EthMethod["SignTypedDataV4"] = "eth_signTypedData_v4"; // ERC-4337 methods EthMethod["PrepareUserOperation"] = "eth_prepareUserOperation"; EthMethod["PatchUserOperation"] = "eth_patchUserOperation"; EthMethod["SignUserOperation"] = "eth_signUserOperation"; })(EthMethod || (EthMethod = {})); export const EthEoaAccountStruct = object({ ...KeyringAccountStruct.schema, /** * Account address. */ address: EthAddressStruct, /** * Account type. */ type: literal(`${EthAccountType.Eoa}`), /** * Account scopes (must be ['eip155:0']). */ scopes: nonempty(array(literal(EthScope.Eoa))), /** * Account supported methods. */ methods: array(enums([ `${EthMethod.PersonalSign}`, `${EthMethod.Sign}`, `${EthMethod.SignTransaction}`, `${EthMethod.SignTypedDataV1}`, `${EthMethod.SignTypedDataV3}`, `${EthMethod.SignTypedDataV4}`, ])), }); export const EthErc4337AccountStruct = object({ ...KeyringAccountStruct.schema, /** * Account address. */ address: EthAddressStruct, /** * Account type. */ type: literal(`${EthAccountType.Erc4337}`), /** * Account supported scopes (CAIP-2 chain IDs). */ scopes: nonempty(array(CaipChainIdStruct)), /** * Account supported methods. */ methods: array(enums([ `${EthMethod.PersonalSign}`, `${EthMethod.Sign}`, `${EthMethod.SignTypedDataV1}`, `${EthMethod.SignTypedDataV3}`, `${EthMethod.SignTypedDataV4}`, `${EthMethod.PrepareUserOperation}`, `${EthMethod.PatchUserOperation}`, `${EthMethod.SignUserOperation}`, ])), }); //# sourceMappingURL=types.mjs.map