UNPKG

@metamask/snaps-sdk

Version:

A library containing the core functionality for building MetaMask Snaps

1 lines 5.21 kB
{"version":3,"file":"permissions.cjs","sourceRoot":"","sources":["../../src/types/permissions.ts"],"names":[],"mappings":"","sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport type { CaipChainId, JsonRpcParams } from '@metamask/utils';\n\nexport type EmptyObject = Record<string, never>;\n\ntype CronjobRequest = {\n /**\n * The request to provide to the `onCronjob` handler for the Snap to determine\n * how to handle the request, when the cronjob is triggered.\n */\n request: {\n /**\n * The method to call. This can be an arbitrary method, and is provided to\n * the `onCronjob` handler for the Snap to determine how to handle the\n * request.\n */\n method: string;\n\n /**\n * The parameters to pass to the method. This can be used to provide\n * additional information about the request, and is provided to the\n * `onCronjob` handler for the Snap to determine how to handle the request.\n */\n params?: JsonRpcParams;\n };\n};\n\ntype CronjobWithExpression = CronjobRequest & {\n expression: string;\n};\n\ntype CronjobWithDuration = CronjobRequest & {\n duration: string;\n};\n\nexport type Cronjob = CronjobWithExpression | CronjobWithDuration;\n\nexport type NameLookupMatchers =\n | {\n tlds: string[];\n }\n | {\n schemes: string[];\n }\n | {\n tlds: string[];\n schemes: string[];\n };\n\nexport type Bip32Entropy = {\n /**\n * The curve to use for the derived key. This must be a curve supported by\n * [`@metamask/key-tree`](https://npmjs.com/package/@metamask/key-tree).\n */\n curve: SupportedCurve;\n\n /**\n * The derivation path to use for the derived key, represented as an array of\n * path segments. For example, the path `m/44'/1'/0'/0/0` would be represented\n * as `['m', \"44'\", \"1'\", \"0'\", '0', '0']`.\n */\n path: string[];\n};\n\nexport type Bip44Entropy = {\n /**\n * The coin type to use for the derived key, as specified in the\n * [SLIP-44 registry](https://github.com/satoshilabs/slips/blob/master/slip-0044.md).\n */\n coinType: number;\n};\n\nexport type RequestedSnap = {\n version?: string;\n};\n\n/**\n * Supported encoding formats for private keys.\n *\n * Mirrors `PrivateKeyEncoding` from `@metamask/keyring-api`.\n * Keep in sync with `PrivateKeyEncoding` in `@metamask/keyring-api`.\n */\ntype PrivateKeyEncoding = 'hexadecimal' | 'base58';\n\n/**\n * Supported account types for keyring accounts.\n *\n * Mirrors `KeyringAccountType` from `@metamask/keyring-api`.\n * Keep in sync with `KeyringAccountType` in `@metamask/keyring-api`.\n */\ntype KeyringAccountType =\n | 'eip155:eoa'\n | 'eip155:erc4337'\n | 'bip122:p2pkh'\n | 'bip122:p2sh'\n | 'bip122:p2wpkh'\n | 'bip122:p2tr'\n | 'solana:data-account'\n | 'tron:eoa'\n | 'entropy:account';\n\n/**\n * Capabilities object supported by a keyring Snap.\n *\n * Mirrors the shape validated by `KeyringCapabilitiesStruct` in\n * `@metamask/keyring-api`. Keep in sync with that struct.\n *\n * Runtime validation uses the struct in `@metamask/snaps-utils`; this type\n * exists purely for the `InitialPermissions` type signature.\n */\ntype Capabilities = {\n scopes: CaipChainId[];\n bip44?: {\n derivePath?: boolean;\n deriveIndex?: boolean;\n deriveIndexRange?: boolean;\n discover?: boolean;\n };\n privateKey?: {\n importFormats?: {\n encoding: PrivateKeyEncoding;\n type?: KeyringAccountType;\n }[];\n exportFormats?: {\n encoding: PrivateKeyEncoding;\n }[];\n };\n custom?: {\n createAccounts?: boolean;\n };\n};\n\nexport type InitialPermissions = Partial<{\n 'endowment:cronjob': {\n jobs?: Cronjob[];\n maxRequestTime?: number;\n };\n 'endowment:ethereum-provider': EmptyObject;\n 'endowment:keyring': {\n allowedOrigins?: string[];\n capabilities?: Capabilities;\n maxRequestTime?: number;\n };\n 'endowment:lifecycle-hooks'?: {\n maxRequestTime?: number;\n };\n 'endowment:name-lookup': {\n chains?: CaipChainId[];\n matchers?: NameLookupMatchers;\n maxRequestTime?: number;\n };\n 'endowment:network-access': EmptyObject;\n 'endowment:page-home'?: {\n maxRequestTime?: number;\n };\n 'endowment:page-settings'?: {\n maxRequestTime?: number;\n };\n 'endowment:rpc': {\n dapps?: boolean;\n snaps?: boolean;\n allowedOrigins?: string[];\n maxRequestTime?: number;\n };\n 'endowment:signature-insight': {\n allowSignatureOrigin?: boolean;\n maxRequestTime?: number;\n };\n 'endowment:transaction-insight': {\n allowTransactionOrigin?: boolean;\n maxRequestTime?: number;\n };\n 'endowment:webassembly': EmptyObject;\n\n /* eslint-disable @typescript-eslint/naming-convention */\n snap_dialog: EmptyObject;\n snap_getBip32Entropy: Bip32Entropy[];\n snap_getBip32PublicKey: Bip32Entropy[];\n snap_getBip44Entropy: Bip44Entropy[];\n snap_getEntropy: EmptyObject;\n snap_getLocale: EmptyObject;\n snap_manageAccounts: EmptyObject;\n snap_manageState: EmptyObject;\n snap_notify: EmptyObject;\n wallet_snap: Record<string, RequestedSnap>;\n /* eslint-enable @typescript-eslint/naming-convention */\n}>;\n"]}