@metamask-previews/chain-agnostic-permission 1.2.2-preview-7cfbb337 → 1.2.2-preview-6c66772
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/caip25Permission.cjs.map +1 -1
- package/dist/caip25Permission.d.cts +2 -3
- package/dist/caip25Permission.d.cts.map +1 -1
- package/dist/caip25Permission.d.mts +2 -3
- package/dist/caip25Permission.d.mts.map +1 -1
- package/dist/caip25Permission.mjs.map +1 -1
- package/dist/operators/caip-permission-operator-accounts.cjs.map +1 -1
- package/dist/operators/caip-permission-operator-accounts.d.cts +1 -1
- package/dist/operators/caip-permission-operator-accounts.d.cts.map +1 -1
- package/dist/operators/caip-permission-operator-accounts.d.mts +1 -1
- package/dist/operators/caip-permission-operator-accounts.d.mts.map +1 -1
- package/dist/operators/caip-permission-operator-accounts.mjs.map +1 -1
- package/dist/operators/caip-permission-operator-permittedChains.cjs.map +1 -1
- package/dist/operators/caip-permission-operator-permittedChains.d.cts +1 -1
- package/dist/operators/caip-permission-operator-permittedChains.d.cts.map +1 -1
- package/dist/operators/caip-permission-operator-permittedChains.d.mts +1 -1
- package/dist/operators/caip-permission-operator-permittedChains.d.mts.map +1 -1
- package/dist/operators/caip-permission-operator-permittedChains.mjs.map +1 -1
- package/dist/operators/caip-permission-operator-session-scopes.cjs.map +1 -1
- package/dist/operators/caip-permission-operator-session-scopes.d.cts +1 -1
- package/dist/operators/caip-permission-operator-session-scopes.d.cts.map +1 -1
- package/dist/operators/caip-permission-operator-session-scopes.d.mts +1 -1
- package/dist/operators/caip-permission-operator-session-scopes.d.mts.map +1 -1
- package/dist/operators/caip-permission-operator-session-scopes.mjs.map +1 -1
- package/dist/scope/assert.cjs.map +1 -1
- package/dist/scope/assert.d.cts +1 -1
- package/dist/scope/assert.d.cts.map +1 -1
- package/dist/scope/assert.d.mts +1 -1
- package/dist/scope/assert.d.mts.map +1 -1
- package/dist/scope/assert.mjs.map +1 -1
- package/dist/scope/constants.cjs +1 -0
- package/dist/scope/constants.cjs.map +1 -1
- package/dist/scope/constants.d.cts +2 -1
- package/dist/scope/constants.d.cts.map +1 -1
- package/dist/scope/constants.d.mts +2 -1
- package/dist/scope/constants.d.mts.map +1 -1
- package/dist/scope/constants.mjs +1 -0
- package/dist/scope/constants.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add `TronAccountChangedNotifications` property in `KnownSessionProperties` enum ([#7304](https://github.com/MetaMask/core/pull/7304))
|
|
13
|
+
|
|
10
14
|
### Changed
|
|
11
15
|
|
|
12
16
|
- Bump `@metamask/network-controller` from `^26.0.0` to `^27.0.0` ([#7202](https://github.com/MetaMask/core/pull/7202), [#7258](https://github.com/MetaMask/core/pull/7258))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip25Permission.cjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":";;;AASA,2EAGyC;AAEzC,2CAOyB;AACzB,mCAAkD;AAElD,+CAA0D;AAC1D,yGAGuD;AACvD,uHAG8D;AAC9D,+CAA8D;AAC9D,qDAI2B;AAC3B,qDAAwD;AACxD,6CAKuB;AAcvB;;GAEG;AACU,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;GAEG;AACU,QAAA,6BAA6B,GAAG,kBAAkB,CAAC;AAEhE;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC7D,OAAO;QACL,IAAI,EAAE,wBAAgB;QACtB,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,kBAAkB,sBAK7B;AASF;;;;;;;GAOG;AACH,SAAgB,8BAA8B,CAC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CAAC,EAAE;gBAC/B,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,wBAAgB;wBACtB,KAAK,EAAE,qBAAqB;qBAC7B;iBACF;aACF;SACF,EACD,OAAO,CACR,CAAC;QACF,OAAO;IACT,CAAC;IAED,KAAK,CAAC,2BAA2B,CAAC;QAChC,OAAO,EAAE,EAAE,MAAM,EAAE;QACnB,mBAAmB,EAAE;YACnB,CAAC,qCAA6B,CAAC,EAAE;gBAC/B,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,wBAAgB;wBACtB,KAAK,EAAE,qBAAqB;qBAC7B;iBACF;aACF;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AAjFW,QAAA,2CAA2C,+CAiFtD","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport type { CaipAccountId, CaipChainId, Json } from '@metamask/utils';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n isObject,\n type Hex,\n type NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual, pick } from 'lodash';\n\nimport { CaveatTypes, PermissionKeys } from './constants';\nimport {\n setEthAccounts,\n setNonSCACaipAccountIdsInCaip25CaveatValue,\n} from './operators/caip-permission-operator-accounts';\nimport {\n setChainIdsInCaip25CaveatValue,\n setPermittedEthChainIds,\n} from './operators/caip-permission-operator-permittedChains';\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport {\n isSupportedAccount,\n isSupportedScopeString,\n isSupportedSessionProperty,\n} from './scope/supported';\nimport { mergeInternalScopes } from './scope/transform';\nimport {\n parseScopeString,\n type ExternalScopeString,\n type InternalScopeObject,\n type InternalScopesObject,\n} from './scope/types';\n\n/**\n * The CAIP-25 permission caveat value.\n * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.\n * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.\n */\nexport type Caip25CaveatValue = {\n requiredScopes: InternalScopesObject;\n optionalScopes: InternalScopesObject;\n sessionProperties: Record<string, Json>;\n isMultichainOrigin: boolean;\n};\n\n/**\n * The name of the CAIP-25 permission caveat.\n */\nexport const Caip25CaveatType = 'authorizedScopes';\n\n/**\n * The target name of the CAIP-25 endowment permission.\n */\nexport const Caip25EndowmentPermissionName = 'endowment:caip25';\n\n/**\n * Creates a CAIP-25 permission caveat.\n *\n * @param value - The CAIP-25 permission caveat value.\n * @returns The CAIP-25 permission caveat (now including the type).\n */\nexport const createCaip25Caveat = (value: Caip25CaveatValue) => {\n return {\n type: Caip25CaveatType,\n value,\n };\n};\n\ntype Caip25EndowmentCaveatSpecificationBuilderOptions = {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;\n listAccounts: () => { type: string; address: Hex }[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n};\n\n/**\n * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.\n *\n * @param originalValue - The existing CAIP-25 permission caveat value.\n * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.\n * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.\n * @returns The difference between original and merged CAIP-25 permission caveat values.\n */\nexport function diffScopesForCaip25CaveatValue(\n originalValue: Caip25CaveatValue,\n mergedValue: Caip25CaveatValue,\n scopeToDiff: 'optionalScopes' | 'requiredScopes',\n): Caip25CaveatValue {\n const diff = cloneDeep(originalValue);\n\n const mergedScopeToDiff = mergedValue[scopeToDiff];\n for (const [scopeString, mergedScopeObject] of Object.entries(\n mergedScopeToDiff,\n )) {\n const internalScopeString = scopeString as keyof typeof mergedScopeToDiff;\n const originalScopeObject = diff[scopeToDiff][internalScopeString];\n\n if (originalScopeObject) {\n const newAccounts = mergedScopeObject.accounts.filter(\n (account) => !originalScopeObject?.accounts.includes(account),\n );\n if (newAccounts.length > 0) {\n diff[scopeToDiff][internalScopeString] = {\n accounts: newAccounts,\n };\n continue;\n }\n delete diff[scopeToDiff][internalScopeString];\n } else {\n diff[scopeToDiff][internalScopeString] = mergedScopeObject;\n }\n }\n\n return diff;\n}\n\n/**\n * Checks if every account in the given scopes object is supported.\n *\n * @param scopesObject - The scopes object to iterate over.\n * @param listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * addresses.\n * @returns True if every account in the scopes object is supported, false otherwise.\n */\nfunction isEveryAccountInScopesObjectSupported(\n scopesObject: InternalScopesObject,\n listAccounts: () => { type: string; address: Hex }[],\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[],\n) {\n return Object.values(scopesObject).every((scopeObject) =>\n scopeObject.accounts.every((account) =>\n isSupportedAccount(account, {\n getEvmInternalAccounts: listAccounts,\n getNonEvmAccountAddresses,\n }),\n ),\n );\n}\n\n/**\n * Helper that returns a `authorizedScopes` CAIP-25 caveat specification\n * that can be passed into the PermissionController constructor.\n *\n * @param options - The specification builder options.\n * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.\n * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.\n * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns The specification for the `caip25` caveat.\n */\nexport const caip25CaveatBuilder = ({\n findNetworkClientIdByChainId,\n listAccounts,\n isNonEvmScopeSupported,\n getNonEvmAccountAddresses,\n}: Caip25EndowmentCaveatSpecificationBuilderOptions): EndowmentCaveatSpecificationConstraint &\n Required<\n Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>\n > => {\n return {\n type: Caip25CaveatType,\n validator: (\n caveat: { type: typeof Caip25CaveatType; value: unknown },\n _origin?: string,\n _target?: string,\n ) => {\n if (\n !caveat.value ||\n !hasProperty(caveat.value, 'requiredScopes') ||\n !hasProperty(caveat.value, 'optionalScopes') ||\n !hasProperty(caveat.value, 'isMultichainOrigin') ||\n !hasProperty(caveat.value, 'sessionProperties') ||\n typeof caveat.value.isMultichainOrigin !== 'boolean' ||\n !isObject(caveat.value.sessionProperties)\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received invalid value for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const { requiredScopes, optionalScopes, sessionProperties } =\n caveat.value;\n\n const allSessionPropertiesSupported = Object.keys(\n sessionProperties,\n ).every((sessionProperty) => isSupportedSessionProperty(sessionProperty));\n\n if (!allSessionPropertiesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received unknown session property(s) for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n if (\n Object.keys(requiredScopes).length === 0 &&\n Object.keys(optionalScopes).length === 0\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received no scopes for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const unsupportedScopes = Object.keys({\n ...requiredScopes,\n ...optionalScopes,\n }).filter(\n (scopeString) =>\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n\n if (unsupportedScopes.length > 0) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s): ${unsupportedScopes.join(', ')} for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedSessionProperties = {\n ...leftValue.sessionProperties,\n ...rightValue.sessionProperties,\n };\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\n sessionProperties: mergedSessionProperties,\n isMultichainOrigin: leftValue.isMultichainOrigin,\n };\n\n const partialDiff = diffScopesForCaip25CaveatValue(\n leftValue,\n mergedValue,\n 'requiredScopes',\n );\n\n const diff = diffScopesForCaip25CaveatValue(\n partialDiff,\n mergedValue,\n 'optionalScopes',\n );\n\n return [mergedValue, diff];\n },\n };\n};\n\ntype Caip25EndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof Caip25EndowmentPermissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => null;\n validator: PermissionValidatorConstraint;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * Helper that returns a `endowment:caip25` specification that\n * can be passed into the PermissionController constructor.\n *\n * @returns The specification for the `caip25` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n Record<never, never>,\n Caip25EndowmentSpecification\n> = () => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: Caip25EndowmentPermissionName,\n allowedCaveats: [Caip25CaveatType],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => null,\n validator: (permission: PermissionConstraint) => {\n if (\n permission.caveats?.length !== 1 ||\n permission.caveats?.[0]?.type !== Caip25CaveatType\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Invalid caveats. There must be a single caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n },\n };\n};\n\n/**\n * The `caip25` endowment specification builder. Passed to the\n * `PermissionController` for constructing and validating the\n * `endowment:caip25` permission.\n */\nexport const caip25EndowmentBuilder = Object.freeze({\n targetName: Caip25EndowmentPermissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Factories that construct caveat mutator functions that are passed to\n * PermissionController.updatePermissionsByCaveat.\n */\nexport const Caip25CaveatMutators = {\n [Caip25CaveatType]: {\n removeScope,\n removeAccount,\n },\n};\n\n/**\n * Removes the account from the scope object.\n *\n * @param targetAddress - The address to remove from the scope object.\n * @returns A function that removes the account from the scope object.\n */\nfunction removeAccountFilterFn(targetAddress: string) {\n return (account: CaipAccountId) => {\n const parsed = parseCaipAccountId(account);\n return parsed.address !== targetAddress;\n };\n}\n\n/**\n * Removes the account from the scope object.\n *\n * @param scopeObject - The scope object to remove the account from.\n * @param targetAddress - The address to remove from the scope object.\n */\nfunction removeAccountFromScopeObject(\n scopeObject: InternalScopeObject,\n targetAddress: string,\n) {\n if (scopeObject.accounts) {\n scopeObject.accounts = scopeObject.accounts.filter(\n removeAccountFilterFn(targetAddress),\n );\n }\n}\n\n/**\n * Removes the target account from the scope object.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).\n * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.\n * @returns The updated scope object.\n */\nfunction removeAccount(\n caip25CaveatValue: Caip25CaveatValue,\n targetAddress: Hex,\n) {\n const updatedCaveatValue = cloneDeep(caip25CaveatValue);\n\n [\n updatedCaveatValue.requiredScopes,\n updatedCaveatValue.optionalScopes,\n ].forEach((scopes) => {\n Object.entries(scopes).forEach(([, scopeObject]) => {\n removeAccountFromScopeObject(scopeObject, targetAddress);\n });\n });\n\n const noChange = isEqual(updatedCaveatValue, caip25CaveatValue);\n\n if (noChange) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const hasAccounts = [\n ...Object.values(updatedCaveatValue.requiredScopes),\n ...Object.values(updatedCaveatValue.optionalScopes),\n ].some(({ accounts }) => accounts.length > 0);\n\n if (hasAccounts) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Removes the target scope from the value arrays of the given\n * `endowment:caip25` caveat. No-ops if the target scopeString is not in\n * the existing scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.\n * @param targetScopeString - The scope that is being removed.\n * @returns The updated CAIP-25 permission caveat value.\n */\nfunction removeScope(\n caip25CaveatValue: Caip25CaveatValue,\n targetScopeString: ExternalScopeString,\n) {\n const newRequiredScopes = Object.entries(\n caip25CaveatValue.requiredScopes,\n ).filter(([scope]) => scope !== targetScopeString);\n const newOptionalScopes = Object.entries(\n caip25CaveatValue.optionalScopes,\n ).filter(([scope]) => {\n return scope !== targetScopeString;\n });\n\n const requiredScopesRemoved =\n newRequiredScopes.length !==\n Object.keys(caip25CaveatValue.requiredScopes).length;\n const optionalScopesRemoved =\n newOptionalScopes.length !==\n Object.keys(caip25CaveatValue.optionalScopes).length;\n\n if (!requiredScopesRemoved && !optionalScopesRemoved) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const updatedCaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: Object.fromEntries(newRequiredScopes),\n optionalScopes: Object.fromEntries(newOptionalScopes),\n };\n\n const hasNonWalletScopes = [...newRequiredScopes, ...newOptionalScopes].some(\n ([scopeString]) => {\n const { namespace } = parseScopeString(scopeString);\n return namespace !== KnownCaipNamespace.Wallet;\n },\n );\n\n if (hasNonWalletScopes) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Modifies the requested CAIP-25 permissions object after UI confirmation.\n *\n * @param caip25CaveatValue - The requested CAIP-25 caveat value to modify.\n * @param accountAddresses - The list of permitted eth addresses.\n * @param chainIds - The list of permitted eth chainIds.\n * @returns The updated CAIP-25 caveat value with the permitted accounts and chainIds set.\n */\nexport const generateCaip25Caveat = (\n caip25CaveatValue: Caip25CaveatValue,\n accountAddresses: CaipAccountId[],\n chainIds: CaipChainId[],\n): {\n [Caip25EndowmentPermissionName]: {\n caveats: [{ type: string; value: Caip25CaveatValue }];\n };\n} => {\n const caveatValueWithChains = setChainIdsInCaip25CaveatValue(\n caip25CaveatValue,\n chainIds,\n );\n\n const caveatValueWithAccounts = setNonSCACaipAccountIdsInCaip25CaveatValue(\n caveatValueWithChains,\n accountAddresses,\n );\n\n return {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithAccounts,\n },\n ],\n },\n };\n};\n\n/**\n * Helper to get the CAIP-25 caveat from a permission\n *\n * @param [caip25Permission] - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns The CAIP-25 caveat or undefined if not found\n */\nexport function getCaip25CaveatFromPermission(caip25Permission?: {\n caveats: (\n | {\n type: string;\n value: unknown;\n }\n | {\n type: typeof Caip25CaveatType;\n value: Caip25CaveatValue;\n }\n )[];\n}) {\n return caip25Permission?.caveats.find(\n (caveat) => caveat.type === (Caip25CaveatType as string),\n ) as\n | {\n type: typeof Caip25CaveatType;\n value: Caip25CaveatValue;\n }\n | undefined;\n}\n\n/**\n * Requests user approval for the CAIP-25 permission\n * and returns a granted permissions object.\n *\n * @param requestedPermissions - The legacy permissions to request approval for.\n * @param requestedPermissions.caveats - The legacy caveats processed by the function.\n * - `restrictReturnedAccounts`: Restricts which Ethereum accounts can be accessed\n * - `restrictNetworkSwitching`: Restricts which blockchain networks can be used\n * @returns The converted CAIP-25 permission object.\n */\nexport const getCaip25PermissionFromLegacyPermissions =\n (requestedPermissions?: {\n [PermissionKeys.eth_accounts]?: {\n caveats?: {\n type: keyof typeof CaveatTypes;\n value: Hex[];\n }[];\n };\n [PermissionKeys.permittedChains]?: {\n caveats?: {\n type: keyof typeof CaveatTypes;\n value: Hex[];\n }[];\n };\n }): {\n [Caip25EndowmentPermissionName]: {\n caveats: NonEmptyArray<{\n type: typeof Caip25CaveatType;\n value: typeof caveatValueWithAccountsAndChains;\n }>;\n };\n } => {\n const permissions = pick(requestedPermissions, [\n PermissionKeys.eth_accounts,\n PermissionKeys.permittedChains,\n ]);\n\n if (!permissions[PermissionKeys.eth_accounts]) {\n permissions[PermissionKeys.eth_accounts] = {};\n }\n\n if (!permissions[PermissionKeys.permittedChains]) {\n permissions[PermissionKeys.permittedChains] = {};\n }\n\n const requestedAccounts =\n permissions[PermissionKeys.eth_accounts]?.caveats?.find(\n (caveat) => caveat.type === CaveatTypes.restrictReturnedAccounts,\n )?.value ?? [];\n\n const requestedChains =\n permissions[PermissionKeys.permittedChains]?.caveats?.find(\n (caveat) => caveat.type === CaveatTypes.restrictNetworkSwitching,\n )?.value ?? [];\n\n const newCaveatValue = {\n requiredScopes: {},\n optionalScopes: {\n 'wallet:eip155': {\n accounts: [],\n },\n },\n sessionProperties: {},\n isMultichainOrigin: false,\n };\n\n const caveatValueWithChains = setPermittedEthChainIds(\n newCaveatValue,\n requestedChains,\n );\n\n const caveatValueWithAccountsAndChains = setEthAccounts(\n caveatValueWithChains,\n requestedAccounts,\n );\n\n return {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithAccountsAndChains,\n },\n ],\n },\n };\n };\n\n/**\n * Requests incremental permittedChains permission for the specified origin.\n * and updates the existing CAIP-25 permission.\n * Allows for granting without prompting for user approval which\n * would be used as part of flows like `wallet_addEthereumChain`\n * requests where the addition of the network and the permitting\n * of the chain are combined into one approval.\n *\n * @param options - The options object\n * @param options.origin - The origin to request approval for.\n * @param options.chainId - The chainId to add to the existing permittedChains.\n * @param options.autoApprove - If the chain should be granted without prompting for user approval.\n * @param options.metadata - Request data for the approval.\n * @param options.metadata.options - Additional metadata about the permission request.\n * @param options.hooks - Permission controller hooks for incremental operations.\n * @param options.hooks.requestPermissionsIncremental - Initiates an incremental permission request that prompts for user approval.\n * Incremental permission requests allow the caller to replace existing and/or add brand new permissions and caveats for the specified subject.\n * @param options.hooks.grantPermissionsIncremental - Incrementally grants approved permissions to the specified subject without prompting for user approval.\n * Every permission and caveat is stringently validated and an error is thrown if validation fails.\n */\nexport const requestPermittedChainsPermissionIncremental = async ({\n origin,\n chainId,\n autoApprove,\n hooks,\n metadata,\n}: {\n origin: string;\n chainId: Hex;\n autoApprove: boolean;\n hooks: {\n requestPermissionsIncremental: (\n subject: { origin: string },\n requestedPermissions: Record<\n string,\n { caveats: { type: string; value: unknown }[] }\n >,\n options?: { metadata?: Record<string, Json> },\n ) => Promise<\n | [\n Partial<Record<string, unknown>>,\n { data?: Record<string, unknown>; id: string; origin: string },\n ]\n | []\n >;\n grantPermissionsIncremental: (params: {\n subject: { origin: string };\n approvedPermissions: Record<\n string,\n { caveats: { type: string; value: unknown }[] }\n >;\n requestData?: Record<string, unknown>;\n }) => Partial<Record<string, unknown>>;\n };\n metadata?: { options: Record<string, Json> };\n}) => {\n const caveatValueWithChains = setPermittedEthChainIds(\n {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: {},\n isMultichainOrigin: false,\n },\n [chainId],\n );\n\n if (!autoApprove) {\n let options;\n if (metadata) {\n options = { metadata };\n }\n await hooks.requestPermissionsIncremental(\n { origin },\n {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithChains,\n },\n ],\n },\n },\n options,\n );\n return;\n }\n\n hooks.grantPermissionsIncremental({\n subject: { origin },\n approvedPermissions: {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithChains,\n },\n ],\n },\n },\n });\n};\n"]}
|
|
1
|
+
{"version":3,"file":"caip25Permission.cjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":";;;AASA,2EAGyC;AACzC,2CAKyB;AAQzB,mCAAkD;AAElD,+CAA0D;AAC1D,yGAGuD;AACvD,uHAG8D;AAC9D,+CAA8D;AAC9D,qDAI2B;AAC3B,qDAAwD;AACxD,6CAAiD;AAmBjD;;GAEG;AACU,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;GAEG;AACU,QAAA,6BAA6B,GAAG,kBAAkB,CAAC;AAEhE;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC7D,OAAO;QACL,IAAI,EAAE,wBAAgB;QACtB,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,kBAAkB,sBAK7B;AASF;;;;;;;GAOG;AACH,SAAgB,8BAA8B,CAC5C,aAAgC,EAChC,WAA8B,EAC9B,WAAgD;IAEhD,MAAM,IAAI,GAAG,IAAA,kBAAS,EAAC,aAAa,CAAC,CAAC;IAEtC,MAAM,iBAAiB,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IACnD,KAAK,MAAM,CAAC,WAAW,EAAE,iBAAiB,CAAC,IAAI,MAAM,CAAC,OAAO,CAC3D,iBAAiB,CAClB,EAAE,CAAC;QACF,MAAM,mBAAmB,GAAG,WAA6C,CAAC;QAC1E,MAAM,mBAAmB,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;QAEnE,IAAI,mBAAmB,EAAE,CAAC;YACxB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FW,QAAA,2CAA2C,+CAiFtD","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n isObject,\n} from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipChainId,\n Json,\n Hex,\n NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual, pick } from 'lodash';\n\nimport { CaveatTypes, PermissionKeys } from './constants';\nimport {\n setEthAccounts,\n setNonSCACaipAccountIdsInCaip25CaveatValue,\n} from './operators/caip-permission-operator-accounts';\nimport {\n setChainIdsInCaip25CaveatValue,\n setPermittedEthChainIds,\n} from './operators/caip-permission-operator-permittedChains';\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport {\n isSupportedAccount,\n isSupportedScopeString,\n isSupportedSessionProperty,\n} from './scope/supported';\nimport { mergeInternalScopes } from './scope/transform';\nimport { parseScopeString } from './scope/types';\nimport type {\n ExternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n} from './scope/types';\n\n/**\n * The CAIP-25 permission caveat value.\n * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.\n * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.\n */\nexport type Caip25CaveatValue = {\n requiredScopes: InternalScopesObject;\n optionalScopes: InternalScopesObject;\n sessionProperties: Record<string, Json>;\n isMultichainOrigin: boolean;\n};\n\n/**\n * The name of the CAIP-25 permission caveat.\n */\nexport const Caip25CaveatType = 'authorizedScopes';\n\n/**\n * The target name of the CAIP-25 endowment permission.\n */\nexport const Caip25EndowmentPermissionName = 'endowment:caip25';\n\n/**\n * Creates a CAIP-25 permission caveat.\n *\n * @param value - The CAIP-25 permission caveat value.\n * @returns The CAIP-25 permission caveat (now including the type).\n */\nexport const createCaip25Caveat = (value: Caip25CaveatValue) => {\n return {\n type: Caip25CaveatType,\n value,\n };\n};\n\ntype Caip25EndowmentCaveatSpecificationBuilderOptions = {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;\n listAccounts: () => { type: string; address: Hex }[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n};\n\n/**\n * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.\n *\n * @param originalValue - The existing CAIP-25 permission caveat value.\n * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.\n * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.\n * @returns The difference between original and merged CAIP-25 permission caveat values.\n */\nexport function diffScopesForCaip25CaveatValue(\n originalValue: Caip25CaveatValue,\n mergedValue: Caip25CaveatValue,\n scopeToDiff: 'optionalScopes' | 'requiredScopes',\n): Caip25CaveatValue {\n const diff = cloneDeep(originalValue);\n\n const mergedScopeToDiff = mergedValue[scopeToDiff];\n for (const [scopeString, mergedScopeObject] of Object.entries(\n mergedScopeToDiff,\n )) {\n const internalScopeString = scopeString as keyof typeof mergedScopeToDiff;\n const originalScopeObject = diff[scopeToDiff][internalScopeString];\n\n if (originalScopeObject) {\n const newAccounts = mergedScopeObject.accounts.filter(\n (account) => !originalScopeObject?.accounts.includes(account),\n );\n if (newAccounts.length > 0) {\n diff[scopeToDiff][internalScopeString] = {\n accounts: newAccounts,\n };\n continue;\n }\n delete diff[scopeToDiff][internalScopeString];\n } else {\n diff[scopeToDiff][internalScopeString] = mergedScopeObject;\n }\n }\n\n return diff;\n}\n\n/**\n * Checks if every account in the given scopes object is supported.\n *\n * @param scopesObject - The scopes object to iterate over.\n * @param listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * addresses.\n * @returns True if every account in the scopes object is supported, false otherwise.\n */\nfunction isEveryAccountInScopesObjectSupported(\n scopesObject: InternalScopesObject,\n listAccounts: () => { type: string; address: Hex }[],\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[],\n) {\n return Object.values(scopesObject).every((scopeObject) =>\n scopeObject.accounts.every((account) =>\n isSupportedAccount(account, {\n getEvmInternalAccounts: listAccounts,\n getNonEvmAccountAddresses,\n }),\n ),\n );\n}\n\n/**\n * Helper that returns a `authorizedScopes` CAIP-25 caveat specification\n * that can be passed into the PermissionController constructor.\n *\n * @param options - The specification builder options.\n * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.\n * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.\n * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns The specification for the `caip25` caveat.\n */\nexport const caip25CaveatBuilder = ({\n findNetworkClientIdByChainId,\n listAccounts,\n isNonEvmScopeSupported,\n getNonEvmAccountAddresses,\n}: Caip25EndowmentCaveatSpecificationBuilderOptions): EndowmentCaveatSpecificationConstraint &\n Required<\n Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>\n > => {\n return {\n type: Caip25CaveatType,\n validator: (\n caveat: { type: typeof Caip25CaveatType; value: unknown },\n _origin?: string,\n _target?: string,\n ) => {\n if (\n !caveat.value ||\n !hasProperty(caveat.value, 'requiredScopes') ||\n !hasProperty(caveat.value, 'optionalScopes') ||\n !hasProperty(caveat.value, 'isMultichainOrigin') ||\n !hasProperty(caveat.value, 'sessionProperties') ||\n typeof caveat.value.isMultichainOrigin !== 'boolean' ||\n !isObject(caveat.value.sessionProperties)\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received invalid value for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const { requiredScopes, optionalScopes, sessionProperties } =\n caveat.value;\n\n const allSessionPropertiesSupported = Object.keys(\n sessionProperties,\n ).every((sessionProperty) => isSupportedSessionProperty(sessionProperty));\n\n if (!allSessionPropertiesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received unknown session property(s) for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n if (\n Object.keys(requiredScopes).length === 0 &&\n Object.keys(optionalScopes).length === 0\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received no scopes for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const unsupportedScopes = Object.keys({\n ...requiredScopes,\n ...optionalScopes,\n }).filter(\n (scopeString) =>\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n\n if (unsupportedScopes.length > 0) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s): ${unsupportedScopes.join(', ')} for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedSessionProperties = {\n ...leftValue.sessionProperties,\n ...rightValue.sessionProperties,\n };\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\n sessionProperties: mergedSessionProperties,\n isMultichainOrigin: leftValue.isMultichainOrigin,\n };\n\n const partialDiff = diffScopesForCaip25CaveatValue(\n leftValue,\n mergedValue,\n 'requiredScopes',\n );\n\n const diff = diffScopesForCaip25CaveatValue(\n partialDiff,\n mergedValue,\n 'optionalScopes',\n );\n\n return [mergedValue, diff];\n },\n };\n};\n\ntype Caip25EndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof Caip25EndowmentPermissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => null;\n validator: PermissionValidatorConstraint;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * Helper that returns a `endowment:caip25` specification that\n * can be passed into the PermissionController constructor.\n *\n * @returns The specification for the `caip25` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n Record<never, never>,\n Caip25EndowmentSpecification\n> = () => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: Caip25EndowmentPermissionName,\n allowedCaveats: [Caip25CaveatType],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => null,\n validator: (permission: PermissionConstraint) => {\n if (\n permission.caveats?.length !== 1 ||\n permission.caveats?.[0]?.type !== Caip25CaveatType\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Invalid caveats. There must be a single caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n },\n };\n};\n\n/**\n * The `caip25` endowment specification builder. Passed to the\n * `PermissionController` for constructing and validating the\n * `endowment:caip25` permission.\n */\nexport const caip25EndowmentBuilder = Object.freeze({\n targetName: Caip25EndowmentPermissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Factories that construct caveat mutator functions that are passed to\n * PermissionController.updatePermissionsByCaveat.\n */\nexport const Caip25CaveatMutators = {\n [Caip25CaveatType]: {\n removeScope,\n removeAccount,\n },\n};\n\n/**\n * Removes the account from the scope object.\n *\n * @param targetAddress - The address to remove from the scope object.\n * @returns A function that removes the account from the scope object.\n */\nfunction removeAccountFilterFn(targetAddress: string) {\n return (account: CaipAccountId) => {\n const parsed = parseCaipAccountId(account);\n return parsed.address !== targetAddress;\n };\n}\n\n/**\n * Removes the account from the scope object.\n *\n * @param scopeObject - The scope object to remove the account from.\n * @param targetAddress - The address to remove from the scope object.\n */\nfunction removeAccountFromScopeObject(\n scopeObject: InternalScopeObject,\n targetAddress: string,\n) {\n if (scopeObject.accounts) {\n scopeObject.accounts = scopeObject.accounts.filter(\n removeAccountFilterFn(targetAddress),\n );\n }\n}\n\n/**\n * Removes the target account from the scope object.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).\n * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.\n * @returns The updated scope object.\n */\nfunction removeAccount(\n caip25CaveatValue: Caip25CaveatValue,\n targetAddress: Hex,\n) {\n const updatedCaveatValue = cloneDeep(caip25CaveatValue);\n\n [\n updatedCaveatValue.requiredScopes,\n updatedCaveatValue.optionalScopes,\n ].forEach((scopes) => {\n Object.entries(scopes).forEach(([, scopeObject]) => {\n removeAccountFromScopeObject(scopeObject, targetAddress);\n });\n });\n\n const noChange = isEqual(updatedCaveatValue, caip25CaveatValue);\n\n if (noChange) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const hasAccounts = [\n ...Object.values(updatedCaveatValue.requiredScopes),\n ...Object.values(updatedCaveatValue.optionalScopes),\n ].some(({ accounts }) => accounts.length > 0);\n\n if (hasAccounts) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Removes the target scope from the value arrays of the given\n * `endowment:caip25` caveat. No-ops if the target scopeString is not in\n * the existing scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.\n * @param targetScopeString - The scope that is being removed.\n * @returns The updated CAIP-25 permission caveat value.\n */\nfunction removeScope(\n caip25CaveatValue: Caip25CaveatValue,\n targetScopeString: ExternalScopeString,\n) {\n const newRequiredScopes = Object.entries(\n caip25CaveatValue.requiredScopes,\n ).filter(([scope]) => scope !== targetScopeString);\n const newOptionalScopes = Object.entries(\n caip25CaveatValue.optionalScopes,\n ).filter(([scope]) => {\n return scope !== targetScopeString;\n });\n\n const requiredScopesRemoved =\n newRequiredScopes.length !==\n Object.keys(caip25CaveatValue.requiredScopes).length;\n const optionalScopesRemoved =\n newOptionalScopes.length !==\n Object.keys(caip25CaveatValue.optionalScopes).length;\n\n if (!requiredScopesRemoved && !optionalScopesRemoved) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const updatedCaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: Object.fromEntries(newRequiredScopes),\n optionalScopes: Object.fromEntries(newOptionalScopes),\n };\n\n const hasNonWalletScopes = [...newRequiredScopes, ...newOptionalScopes].some(\n ([scopeString]) => {\n const { namespace } = parseScopeString(scopeString);\n return namespace !== KnownCaipNamespace.Wallet;\n },\n );\n\n if (hasNonWalletScopes) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Modifies the requested CAIP-25 permissions object after UI confirmation.\n *\n * @param caip25CaveatValue - The requested CAIP-25 caveat value to modify.\n * @param accountAddresses - The list of permitted eth addresses.\n * @param chainIds - The list of permitted eth chainIds.\n * @returns The updated CAIP-25 caveat value with the permitted accounts and chainIds set.\n */\nexport const generateCaip25Caveat = (\n caip25CaveatValue: Caip25CaveatValue,\n accountAddresses: CaipAccountId[],\n chainIds: CaipChainId[],\n): {\n [Caip25EndowmentPermissionName]: {\n caveats: [{ type: string; value: Caip25CaveatValue }];\n };\n} => {\n const caveatValueWithChains = setChainIdsInCaip25CaveatValue(\n caip25CaveatValue,\n chainIds,\n );\n\n const caveatValueWithAccounts = setNonSCACaipAccountIdsInCaip25CaveatValue(\n caveatValueWithChains,\n accountAddresses,\n );\n\n return {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithAccounts,\n },\n ],\n },\n };\n};\n\n/**\n * Helper to get the CAIP-25 caveat from a permission\n *\n * @param [caip25Permission] - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns The CAIP-25 caveat or undefined if not found\n */\nexport function getCaip25CaveatFromPermission(caip25Permission?: {\n caveats: (\n | {\n type: string;\n value: unknown;\n }\n | {\n type: typeof Caip25CaveatType;\n value: Caip25CaveatValue;\n }\n )[];\n}) {\n return caip25Permission?.caveats.find(\n (caveat) => caveat.type === (Caip25CaveatType as string),\n ) as\n | {\n type: typeof Caip25CaveatType;\n value: Caip25CaveatValue;\n }\n | undefined;\n}\n\n/**\n * Requests user approval for the CAIP-25 permission\n * and returns a granted permissions object.\n *\n * @param requestedPermissions - The legacy permissions to request approval for.\n * @param requestedPermissions.caveats - The legacy caveats processed by the function.\n * - `restrictReturnedAccounts`: Restricts which Ethereum accounts can be accessed\n * - `restrictNetworkSwitching`: Restricts which blockchain networks can be used\n * @returns The converted CAIP-25 permission object.\n */\nexport const getCaip25PermissionFromLegacyPermissions =\n (requestedPermissions?: {\n [PermissionKeys.eth_accounts]?: {\n caveats?: {\n type: keyof typeof CaveatTypes;\n value: Hex[];\n }[];\n };\n [PermissionKeys.permittedChains]?: {\n caveats?: {\n type: keyof typeof CaveatTypes;\n value: Hex[];\n }[];\n };\n }): {\n [Caip25EndowmentPermissionName]: {\n caveats: NonEmptyArray<{\n type: typeof Caip25CaveatType;\n value: typeof caveatValueWithAccountsAndChains;\n }>;\n };\n } => {\n const permissions = pick(requestedPermissions, [\n PermissionKeys.eth_accounts,\n PermissionKeys.permittedChains,\n ]);\n\n if (!permissions[PermissionKeys.eth_accounts]) {\n permissions[PermissionKeys.eth_accounts] = {};\n }\n\n if (!permissions[PermissionKeys.permittedChains]) {\n permissions[PermissionKeys.permittedChains] = {};\n }\n\n const requestedAccounts =\n permissions[PermissionKeys.eth_accounts]?.caveats?.find(\n (caveat) => caveat.type === CaveatTypes.restrictReturnedAccounts,\n )?.value ?? [];\n\n const requestedChains =\n permissions[PermissionKeys.permittedChains]?.caveats?.find(\n (caveat) => caveat.type === CaveatTypes.restrictNetworkSwitching,\n )?.value ?? [];\n\n const newCaveatValue = {\n requiredScopes: {},\n optionalScopes: {\n 'wallet:eip155': {\n accounts: [],\n },\n },\n sessionProperties: {},\n isMultichainOrigin: false,\n };\n\n const caveatValueWithChains = setPermittedEthChainIds(\n newCaveatValue,\n requestedChains,\n );\n\n const caveatValueWithAccountsAndChains = setEthAccounts(\n caveatValueWithChains,\n requestedAccounts,\n );\n\n return {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithAccountsAndChains,\n },\n ],\n },\n };\n };\n\n/**\n * Requests incremental permittedChains permission for the specified origin.\n * and updates the existing CAIP-25 permission.\n * Allows for granting without prompting for user approval which\n * would be used as part of flows like `wallet_addEthereumChain`\n * requests where the addition of the network and the permitting\n * of the chain are combined into one approval.\n *\n * @param options - The options object\n * @param options.origin - The origin to request approval for.\n * @param options.chainId - The chainId to add to the existing permittedChains.\n * @param options.autoApprove - If the chain should be granted without prompting for user approval.\n * @param options.metadata - Request data for the approval.\n * @param options.metadata.options - Additional metadata about the permission request.\n * @param options.hooks - Permission controller hooks for incremental operations.\n * @param options.hooks.requestPermissionsIncremental - Initiates an incremental permission request that prompts for user approval.\n * Incremental permission requests allow the caller to replace existing and/or add brand new permissions and caveats for the specified subject.\n * @param options.hooks.grantPermissionsIncremental - Incrementally grants approved permissions to the specified subject without prompting for user approval.\n * Every permission and caveat is stringently validated and an error is thrown if validation fails.\n */\nexport const requestPermittedChainsPermissionIncremental = async ({\n origin,\n chainId,\n autoApprove,\n hooks,\n metadata,\n}: {\n origin: string;\n chainId: Hex;\n autoApprove: boolean;\n hooks: {\n requestPermissionsIncremental: (\n subject: { origin: string },\n requestedPermissions: Record<\n string,\n { caveats: { type: string; value: unknown }[] }\n >,\n options?: { metadata?: Record<string, Json> },\n ) => Promise<\n | [\n Partial<Record<string, unknown>>,\n { data?: Record<string, unknown>; id: string; origin: string },\n ]\n | []\n >;\n grantPermissionsIncremental: (params: {\n subject: { origin: string };\n approvedPermissions: Record<\n string,\n { caveats: { type: string; value: unknown }[] }\n >;\n requestData?: Record<string, unknown>;\n }) => Partial<Record<string, unknown>>;\n };\n metadata?: { options: Record<string, Json> };\n}) => {\n const caveatValueWithChains = setPermittedEthChainIds(\n {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: {},\n isMultichainOrigin: false,\n },\n [chainId],\n );\n\n if (!autoApprove) {\n let options;\n if (metadata) {\n options = { metadata };\n }\n await hooks.requestPermissionsIncremental(\n { origin },\n {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithChains,\n },\n ],\n },\n },\n options,\n );\n return;\n }\n\n hooks.grantPermissionsIncremental({\n subject: { origin },\n approvedPermissions: {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithChains,\n },\n ],\n },\n },\n });\n};\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { NetworkClientId } from "@metamask/network-controller";
|
|
2
2
|
import type { PermissionSpecificationBuilder, EndowmentGetterParams, PermissionValidatorConstraint, EndowmentCaveatSpecificationConstraint } from "@metamask/permission-controller";
|
|
3
3
|
import { CaveatMutatorOperation, PermissionType } from "@metamask/permission-controller";
|
|
4
|
-
import type { CaipAccountId, CaipChainId, Json } from "@metamask/utils";
|
|
5
|
-
import { type Hex, type NonEmptyArray } from "@metamask/utils";
|
|
4
|
+
import type { CaipAccountId, CaipChainId, Json, Hex, NonEmptyArray } from "@metamask/utils";
|
|
6
5
|
import { CaveatTypes, PermissionKeys } from "./constants.cjs";
|
|
7
|
-
import {
|
|
6
|
+
import type { ExternalScopeString, InternalScopeObject, InternalScopesObject } from "./scope/types.cjs";
|
|
8
7
|
/**
|
|
9
8
|
* The CAIP-25 permission caveat value.
|
|
10
9
|
* This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip25Permission.d.cts","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EACV,8BAA8B,EAC9B,qBAAqB,EAErB,6BAA6B,EAE7B,sCAAsC,EACvC,wCAAwC;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;
|
|
1
|
+
{"version":3,"file":"caip25Permission.d.cts","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EACV,8BAA8B,EAC9B,qBAAqB,EAErB,6BAA6B,EAE7B,sCAAsC,EACvC,wCAAwC;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;AAOzC,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,IAAI,EACJ,GAAG,EACH,aAAa,EACd,wBAAwB;AAGzB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,wBAAoB;AAiB1D,OAAO,KAAK,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,KAAK,EAAE,GAAG,EAAE,CAAC;SACd,EAAE,CAAC;KACL,CAAC;CACH;;;kBAGW,uBAAuB;;;;CA2DlC,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,2CAA2C;YAO9C,MAAM;aACL,GAAG;iBACC,OAAO;;;oBAGG,MAAM;iCACH,OACpB,MAAM,EACN;YAAE,OAAO,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAC;gBAAC,KAAK,EAAE,OAAO,CAAA;aAAE,EAAE,CAAA;SAAE,CAChD;;;;gBAKyC,MAAM;oBAAU,MAAM;;;;wBAK7C,MAAM;;iCACJ,OACnB,MAAM,EACN;gBAAE,OAAO,EAAE;oBAAE,IAAI,EAAE,MAAM,CAAC;oBAAC,KAAK,EAAE,OAAO,CAAA;iBAAE,EAAE,CAAA;aAAE,CAChD;;cAEG,QAAQ,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC;;;iBAElB,OAAO,MAAM,EAAE,IAAI,CAAC;;mBA+C3C,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { NetworkClientId } from "@metamask/network-controller";
|
|
2
2
|
import type { PermissionSpecificationBuilder, EndowmentGetterParams, PermissionValidatorConstraint, EndowmentCaveatSpecificationConstraint } from "@metamask/permission-controller";
|
|
3
3
|
import { CaveatMutatorOperation, PermissionType } from "@metamask/permission-controller";
|
|
4
|
-
import type { CaipAccountId, CaipChainId, Json } from "@metamask/utils";
|
|
5
|
-
import { type Hex, type NonEmptyArray } from "@metamask/utils";
|
|
4
|
+
import type { CaipAccountId, CaipChainId, Json, Hex, NonEmptyArray } from "@metamask/utils";
|
|
6
5
|
import { CaveatTypes, PermissionKeys } from "./constants.mjs";
|
|
7
|
-
import {
|
|
6
|
+
import type { ExternalScopeString, InternalScopeObject, InternalScopesObject } from "./scope/types.mjs";
|
|
8
7
|
/**
|
|
9
8
|
* The CAIP-25 permission caveat value.
|
|
10
9
|
* This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip25Permission.d.mts","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EACV,8BAA8B,EAC9B,qBAAqB,EAErB,6BAA6B,EAE7B,sCAAsC,EACvC,wCAAwC;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;
|
|
1
|
+
{"version":3,"file":"caip25Permission.d.mts","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EACV,8BAA8B,EAC9B,qBAAqB,EAErB,6BAA6B,EAE7B,sCAAsC,EACvC,wCAAwC;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;AAOzC,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,IAAI,EACJ,GAAG,EACH,aAAa,EACd,wBAAwB;AAGzB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,wBAAoB;AAiB1D,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACrB,0BAAsB;AAEvB;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,oBAAoB,CAAC;IACrC,cAAc,EAAE,oBAAoB,CAAC;IACrC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACxC,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,6BAA6B,qBAAqB,CAAC;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,UA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E;oBACP;wBACE,IAAI,EAAE,gBAAgB;wBACtB,KAAK,EAAE,qBAAqB;qBAC7B;iBACF;aACF;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport type { CaipAccountId, CaipChainId, Json } from '@metamask/utils';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n isObject,\n type Hex,\n type NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual, pick } from 'lodash';\n\nimport { CaveatTypes, PermissionKeys } from './constants';\nimport {\n setEthAccounts,\n setNonSCACaipAccountIdsInCaip25CaveatValue,\n} from './operators/caip-permission-operator-accounts';\nimport {\n setChainIdsInCaip25CaveatValue,\n setPermittedEthChainIds,\n} from './operators/caip-permission-operator-permittedChains';\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport {\n isSupportedAccount,\n isSupportedScopeString,\n isSupportedSessionProperty,\n} from './scope/supported';\nimport { mergeInternalScopes } from './scope/transform';\nimport {\n parseScopeString,\n type ExternalScopeString,\n type InternalScopeObject,\n type InternalScopesObject,\n} from './scope/types';\n\n/**\n * The CAIP-25 permission caveat value.\n * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.\n * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.\n */\nexport type Caip25CaveatValue = {\n requiredScopes: InternalScopesObject;\n optionalScopes: InternalScopesObject;\n sessionProperties: Record<string, Json>;\n isMultichainOrigin: boolean;\n};\n\n/**\n * The name of the CAIP-25 permission caveat.\n */\nexport const Caip25CaveatType = 'authorizedScopes';\n\n/**\n * The target name of the CAIP-25 endowment permission.\n */\nexport const Caip25EndowmentPermissionName = 'endowment:caip25';\n\n/**\n * Creates a CAIP-25 permission caveat.\n *\n * @param value - The CAIP-25 permission caveat value.\n * @returns The CAIP-25 permission caveat (now including the type).\n */\nexport const createCaip25Caveat = (value: Caip25CaveatValue) => {\n return {\n type: Caip25CaveatType,\n value,\n };\n};\n\ntype Caip25EndowmentCaveatSpecificationBuilderOptions = {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;\n listAccounts: () => { type: string; address: Hex }[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n};\n\n/**\n * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.\n *\n * @param originalValue - The existing CAIP-25 permission caveat value.\n * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.\n * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.\n * @returns The difference between original and merged CAIP-25 permission caveat values.\n */\nexport function diffScopesForCaip25CaveatValue(\n originalValue: Caip25CaveatValue,\n mergedValue: Caip25CaveatValue,\n scopeToDiff: 'optionalScopes' | 'requiredScopes',\n): Caip25CaveatValue {\n const diff = cloneDeep(originalValue);\n\n const mergedScopeToDiff = mergedValue[scopeToDiff];\n for (const [scopeString, mergedScopeObject] of Object.entries(\n mergedScopeToDiff,\n )) {\n const internalScopeString = scopeString as keyof typeof mergedScopeToDiff;\n const originalScopeObject = diff[scopeToDiff][internalScopeString];\n\n if (originalScopeObject) {\n const newAccounts = mergedScopeObject.accounts.filter(\n (account) => !originalScopeObject?.accounts.includes(account),\n );\n if (newAccounts.length > 0) {\n diff[scopeToDiff][internalScopeString] = {\n accounts: newAccounts,\n };\n continue;\n }\n delete diff[scopeToDiff][internalScopeString];\n } else {\n diff[scopeToDiff][internalScopeString] = mergedScopeObject;\n }\n }\n\n return diff;\n}\n\n/**\n * Checks if every account in the given scopes object is supported.\n *\n * @param scopesObject - The scopes object to iterate over.\n * @param listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * addresses.\n * @returns True if every account in the scopes object is supported, false otherwise.\n */\nfunction isEveryAccountInScopesObjectSupported(\n scopesObject: InternalScopesObject,\n listAccounts: () => { type: string; address: Hex }[],\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[],\n) {\n return Object.values(scopesObject).every((scopeObject) =>\n scopeObject.accounts.every((account) =>\n isSupportedAccount(account, {\n getEvmInternalAccounts: listAccounts,\n getNonEvmAccountAddresses,\n }),\n ),\n );\n}\n\n/**\n * Helper that returns a `authorizedScopes` CAIP-25 caveat specification\n * that can be passed into the PermissionController constructor.\n *\n * @param options - The specification builder options.\n * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.\n * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.\n * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns The specification for the `caip25` caveat.\n */\nexport const caip25CaveatBuilder = ({\n findNetworkClientIdByChainId,\n listAccounts,\n isNonEvmScopeSupported,\n getNonEvmAccountAddresses,\n}: Caip25EndowmentCaveatSpecificationBuilderOptions): EndowmentCaveatSpecificationConstraint &\n Required<\n Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>\n > => {\n return {\n type: Caip25CaveatType,\n validator: (\n caveat: { type: typeof Caip25CaveatType; value: unknown },\n _origin?: string,\n _target?: string,\n ) => {\n if (\n !caveat.value ||\n !hasProperty(caveat.value, 'requiredScopes') ||\n !hasProperty(caveat.value, 'optionalScopes') ||\n !hasProperty(caveat.value, 'isMultichainOrigin') ||\n !hasProperty(caveat.value, 'sessionProperties') ||\n typeof caveat.value.isMultichainOrigin !== 'boolean' ||\n !isObject(caveat.value.sessionProperties)\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received invalid value for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const { requiredScopes, optionalScopes, sessionProperties } =\n caveat.value;\n\n const allSessionPropertiesSupported = Object.keys(\n sessionProperties,\n ).every((sessionProperty) => isSupportedSessionProperty(sessionProperty));\n\n if (!allSessionPropertiesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received unknown session property(s) for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n if (\n Object.keys(requiredScopes).length === 0 &&\n Object.keys(optionalScopes).length === 0\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received no scopes for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const unsupportedScopes = Object.keys({\n ...requiredScopes,\n ...optionalScopes,\n }).filter(\n (scopeString) =>\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n\n if (unsupportedScopes.length > 0) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s): ${unsupportedScopes.join(', ')} for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedSessionProperties = {\n ...leftValue.sessionProperties,\n ...rightValue.sessionProperties,\n };\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\n sessionProperties: mergedSessionProperties,\n isMultichainOrigin: leftValue.isMultichainOrigin,\n };\n\n const partialDiff = diffScopesForCaip25CaveatValue(\n leftValue,\n mergedValue,\n 'requiredScopes',\n );\n\n const diff = diffScopesForCaip25CaveatValue(\n partialDiff,\n mergedValue,\n 'optionalScopes',\n );\n\n return [mergedValue, diff];\n },\n };\n};\n\ntype Caip25EndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof Caip25EndowmentPermissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => null;\n validator: PermissionValidatorConstraint;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * Helper that returns a `endowment:caip25` specification that\n * can be passed into the PermissionController constructor.\n *\n * @returns The specification for the `caip25` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n Record<never, never>,\n Caip25EndowmentSpecification\n> = () => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: Caip25EndowmentPermissionName,\n allowedCaveats: [Caip25CaveatType],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => null,\n validator: (permission: PermissionConstraint) => {\n if (\n permission.caveats?.length !== 1 ||\n permission.caveats?.[0]?.type !== Caip25CaveatType\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Invalid caveats. There must be a single caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n },\n };\n};\n\n/**\n * The `caip25` endowment specification builder. Passed to the\n * `PermissionController` for constructing and validating the\n * `endowment:caip25` permission.\n */\nexport const caip25EndowmentBuilder = Object.freeze({\n targetName: Caip25EndowmentPermissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Factories that construct caveat mutator functions that are passed to\n * PermissionController.updatePermissionsByCaveat.\n */\nexport const Caip25CaveatMutators = {\n [Caip25CaveatType]: {\n removeScope,\n removeAccount,\n },\n};\n\n/**\n * Removes the account from the scope object.\n *\n * @param targetAddress - The address to remove from the scope object.\n * @returns A function that removes the account from the scope object.\n */\nfunction removeAccountFilterFn(targetAddress: string) {\n return (account: CaipAccountId) => {\n const parsed = parseCaipAccountId(account);\n return parsed.address !== targetAddress;\n };\n}\n\n/**\n * Removes the account from the scope object.\n *\n * @param scopeObject - The scope object to remove the account from.\n * @param targetAddress - The address to remove from the scope object.\n */\nfunction removeAccountFromScopeObject(\n scopeObject: InternalScopeObject,\n targetAddress: string,\n) {\n if (scopeObject.accounts) {\n scopeObject.accounts = scopeObject.accounts.filter(\n removeAccountFilterFn(targetAddress),\n );\n }\n}\n\n/**\n * Removes the target account from the scope object.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).\n * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.\n * @returns The updated scope object.\n */\nfunction removeAccount(\n caip25CaveatValue: Caip25CaveatValue,\n targetAddress: Hex,\n) {\n const updatedCaveatValue = cloneDeep(caip25CaveatValue);\n\n [\n updatedCaveatValue.requiredScopes,\n updatedCaveatValue.optionalScopes,\n ].forEach((scopes) => {\n Object.entries(scopes).forEach(([, scopeObject]) => {\n removeAccountFromScopeObject(scopeObject, targetAddress);\n });\n });\n\n const noChange = isEqual(updatedCaveatValue, caip25CaveatValue);\n\n if (noChange) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const hasAccounts = [\n ...Object.values(updatedCaveatValue.requiredScopes),\n ...Object.values(updatedCaveatValue.optionalScopes),\n ].some(({ accounts }) => accounts.length > 0);\n\n if (hasAccounts) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Removes the target scope from the value arrays of the given\n * `endowment:caip25` caveat. No-ops if the target scopeString is not in\n * the existing scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.\n * @param targetScopeString - The scope that is being removed.\n * @returns The updated CAIP-25 permission caveat value.\n */\nfunction removeScope(\n caip25CaveatValue: Caip25CaveatValue,\n targetScopeString: ExternalScopeString,\n) {\n const newRequiredScopes = Object.entries(\n caip25CaveatValue.requiredScopes,\n ).filter(([scope]) => scope !== targetScopeString);\n const newOptionalScopes = Object.entries(\n caip25CaveatValue.optionalScopes,\n ).filter(([scope]) => {\n return scope !== targetScopeString;\n });\n\n const requiredScopesRemoved =\n newRequiredScopes.length !==\n Object.keys(caip25CaveatValue.requiredScopes).length;\n const optionalScopesRemoved =\n newOptionalScopes.length !==\n Object.keys(caip25CaveatValue.optionalScopes).length;\n\n if (!requiredScopesRemoved && !optionalScopesRemoved) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const updatedCaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: Object.fromEntries(newRequiredScopes),\n optionalScopes: Object.fromEntries(newOptionalScopes),\n };\n\n const hasNonWalletScopes = [...newRequiredScopes, ...newOptionalScopes].some(\n ([scopeString]) => {\n const { namespace } = parseScopeString(scopeString);\n return namespace !== KnownCaipNamespace.Wallet;\n },\n );\n\n if (hasNonWalletScopes) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Modifies the requested CAIP-25 permissions object after UI confirmation.\n *\n * @param caip25CaveatValue - The requested CAIP-25 caveat value to modify.\n * @param accountAddresses - The list of permitted eth addresses.\n * @param chainIds - The list of permitted eth chainIds.\n * @returns The updated CAIP-25 caveat value with the permitted accounts and chainIds set.\n */\nexport const generateCaip25Caveat = (\n caip25CaveatValue: Caip25CaveatValue,\n accountAddresses: CaipAccountId[],\n chainIds: CaipChainId[],\n): {\n [Caip25EndowmentPermissionName]: {\n caveats: [{ type: string; value: Caip25CaveatValue }];\n };\n} => {\n const caveatValueWithChains = setChainIdsInCaip25CaveatValue(\n caip25CaveatValue,\n chainIds,\n );\n\n const caveatValueWithAccounts = setNonSCACaipAccountIdsInCaip25CaveatValue(\n caveatValueWithChains,\n accountAddresses,\n );\n\n return {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithAccounts,\n },\n ],\n },\n };\n};\n\n/**\n * Helper to get the CAIP-25 caveat from a permission\n *\n * @param [caip25Permission] - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns The CAIP-25 caveat or undefined if not found\n */\nexport function getCaip25CaveatFromPermission(caip25Permission?: {\n caveats: (\n | {\n type: string;\n value: unknown;\n }\n | {\n type: typeof Caip25CaveatType;\n value: Caip25CaveatValue;\n }\n )[];\n}) {\n return caip25Permission?.caveats.find(\n (caveat) => caveat.type === (Caip25CaveatType as string),\n ) as\n | {\n type: typeof Caip25CaveatType;\n value: Caip25CaveatValue;\n }\n | undefined;\n}\n\n/**\n * Requests user approval for the CAIP-25 permission\n * and returns a granted permissions object.\n *\n * @param requestedPermissions - The legacy permissions to request approval for.\n * @param requestedPermissions.caveats - The legacy caveats processed by the function.\n * - `restrictReturnedAccounts`: Restricts which Ethereum accounts can be accessed\n * - `restrictNetworkSwitching`: Restricts which blockchain networks can be used\n * @returns The converted CAIP-25 permission object.\n */\nexport const getCaip25PermissionFromLegacyPermissions =\n (requestedPermissions?: {\n [PermissionKeys.eth_accounts]?: {\n caveats?: {\n type: keyof typeof CaveatTypes;\n value: Hex[];\n }[];\n };\n [PermissionKeys.permittedChains]?: {\n caveats?: {\n type: keyof typeof CaveatTypes;\n value: Hex[];\n }[];\n };\n }): {\n [Caip25EndowmentPermissionName]: {\n caveats: NonEmptyArray<{\n type: typeof Caip25CaveatType;\n value: typeof caveatValueWithAccountsAndChains;\n }>;\n };\n } => {\n const permissions = pick(requestedPermissions, [\n PermissionKeys.eth_accounts,\n PermissionKeys.permittedChains,\n ]);\n\n if (!permissions[PermissionKeys.eth_accounts]) {\n permissions[PermissionKeys.eth_accounts] = {};\n }\n\n if (!permissions[PermissionKeys.permittedChains]) {\n permissions[PermissionKeys.permittedChains] = {};\n }\n\n const requestedAccounts =\n permissions[PermissionKeys.eth_accounts]?.caveats?.find(\n (caveat) => caveat.type === CaveatTypes.restrictReturnedAccounts,\n )?.value ?? [];\n\n const requestedChains =\n permissions[PermissionKeys.permittedChains]?.caveats?.find(\n (caveat) => caveat.type === CaveatTypes.restrictNetworkSwitching,\n )?.value ?? [];\n\n const newCaveatValue = {\n requiredScopes: {},\n optionalScopes: {\n 'wallet:eip155': {\n accounts: [],\n },\n },\n sessionProperties: {},\n isMultichainOrigin: false,\n };\n\n const caveatValueWithChains = setPermittedEthChainIds(\n newCaveatValue,\n requestedChains,\n );\n\n const caveatValueWithAccountsAndChains = setEthAccounts(\n caveatValueWithChains,\n requestedAccounts,\n );\n\n return {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithAccountsAndChains,\n },\n ],\n },\n };\n };\n\n/**\n * Requests incremental permittedChains permission for the specified origin.\n * and updates the existing CAIP-25 permission.\n * Allows for granting without prompting for user approval which\n * would be used as part of flows like `wallet_addEthereumChain`\n * requests where the addition of the network and the permitting\n * of the chain are combined into one approval.\n *\n * @param options - The options object\n * @param options.origin - The origin to request approval for.\n * @param options.chainId - The chainId to add to the existing permittedChains.\n * @param options.autoApprove - If the chain should be granted without prompting for user approval.\n * @param options.metadata - Request data for the approval.\n * @param options.metadata.options - Additional metadata about the permission request.\n * @param options.hooks - Permission controller hooks for incremental operations.\n * @param options.hooks.requestPermissionsIncremental - Initiates an incremental permission request that prompts for user approval.\n * Incremental permission requests allow the caller to replace existing and/or add brand new permissions and caveats for the specified subject.\n * @param options.hooks.grantPermissionsIncremental - Incrementally grants approved permissions to the specified subject without prompting for user approval.\n * Every permission and caveat is stringently validated and an error is thrown if validation fails.\n */\nexport const requestPermittedChainsPermissionIncremental = async ({\n origin,\n chainId,\n autoApprove,\n hooks,\n metadata,\n}: {\n origin: string;\n chainId: Hex;\n autoApprove: boolean;\n hooks: {\n requestPermissionsIncremental: (\n subject: { origin: string },\n requestedPermissions: Record<\n string,\n { caveats: { type: string; value: unknown }[] }\n >,\n options?: { metadata?: Record<string, Json> },\n ) => Promise<\n | [\n Partial<Record<string, unknown>>,\n { data?: Record<string, unknown>; id: string; origin: string },\n ]\n | []\n >;\n grantPermissionsIncremental: (params: {\n subject: { origin: string };\n approvedPermissions: Record<\n string,\n { caveats: { type: string; value: unknown }[] }\n >;\n requestData?: Record<string, unknown>;\n }) => Partial<Record<string, unknown>>;\n };\n metadata?: { options: Record<string, Json> };\n}) => {\n const caveatValueWithChains = setPermittedEthChainIds(\n {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: {},\n isMultichainOrigin: false,\n },\n [chainId],\n );\n\n if (!autoApprove) {\n let options;\n if (metadata) {\n options = { metadata };\n }\n await hooks.requestPermissionsIncremental(\n { origin },\n {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithChains,\n },\n ],\n },\n },\n options,\n );\n return;\n }\n\n hooks.grantPermissionsIncremental({\n subject: { origin },\n approvedPermissions: {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithChains,\n },\n ],\n },\n },\n });\n};\n"]}
|
|
1
|
+
{"version":3,"file":"caip25Permission.mjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":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AgC;iBACxC;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,2CAA2C,GAAG,KAAK,EAAE,EAChE,MAAM,EACN,OAAO,EACP,WAAW,EACX,KAAK,EACL,QAAQ,GA8BT,EAAE,EAAE;IACH,MAAM,qBAAqB,GAAG,uBAAuB,CACnD;QACE,cAAc,EAAE,EAAE;QAClB,cAAc,EAAE,EAAE;QAClB,iBAAiB,EAAE,EAAE;QACrB,kBAAkB,EAAE,KAAK;KAC1B,EACD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,IAAI,OAAO,CAAC;QACZ,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,GAAG,EAAE,QAAQ,EAAE,CAAC;QACzB,CAAC;QACD,MAAM,KAAK,CAAC,6BAA6B,CACvC,EAAE,MAAM,EAAE,EACV;YACE,CAAC,6BAA6B,CAAC,EAAE;gBAC/B,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,gBAAgB;wBACtB,KAAK,EAAE,qBAAqB;qBAC7B;iBACF;aACF;SACF,EACD,OAAO,CACR,CAAC;QACF,OAAO;IACT,CAAC;IAED,KAAK,CAAC,2BAA2B,CAAC;QAChC,OAAO,EAAE,EAAE,MAAM,EAAE;QACnB,mBAAmB,EAAE;YACnB,CAAC,6BAA6B,CAAC,EAAE;gBAC/B,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,gBAAgB;wBACtB,KAAK,EAAE,qBAAqB;qBAC7B;iBACF;aACF;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n isObject,\n} from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipChainId,\n Json,\n Hex,\n NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual, pick } from 'lodash';\n\nimport { CaveatTypes, PermissionKeys } from './constants';\nimport {\n setEthAccounts,\n setNonSCACaipAccountIdsInCaip25CaveatValue,\n} from './operators/caip-permission-operator-accounts';\nimport {\n setChainIdsInCaip25CaveatValue,\n setPermittedEthChainIds,\n} from './operators/caip-permission-operator-permittedChains';\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport {\n isSupportedAccount,\n isSupportedScopeString,\n isSupportedSessionProperty,\n} from './scope/supported';\nimport { mergeInternalScopes } from './scope/transform';\nimport { parseScopeString } from './scope/types';\nimport type {\n ExternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n} from './scope/types';\n\n/**\n * The CAIP-25 permission caveat value.\n * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.\n * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.\n */\nexport type Caip25CaveatValue = {\n requiredScopes: InternalScopesObject;\n optionalScopes: InternalScopesObject;\n sessionProperties: Record<string, Json>;\n isMultichainOrigin: boolean;\n};\n\n/**\n * The name of the CAIP-25 permission caveat.\n */\nexport const Caip25CaveatType = 'authorizedScopes';\n\n/**\n * The target name of the CAIP-25 endowment permission.\n */\nexport const Caip25EndowmentPermissionName = 'endowment:caip25';\n\n/**\n * Creates a CAIP-25 permission caveat.\n *\n * @param value - The CAIP-25 permission caveat value.\n * @returns The CAIP-25 permission caveat (now including the type).\n */\nexport const createCaip25Caveat = (value: Caip25CaveatValue) => {\n return {\n type: Caip25CaveatType,\n value,\n };\n};\n\ntype Caip25EndowmentCaveatSpecificationBuilderOptions = {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;\n listAccounts: () => { type: string; address: Hex }[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n};\n\n/**\n * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.\n *\n * @param originalValue - The existing CAIP-25 permission caveat value.\n * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.\n * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.\n * @returns The difference between original and merged CAIP-25 permission caveat values.\n */\nexport function diffScopesForCaip25CaveatValue(\n originalValue: Caip25CaveatValue,\n mergedValue: Caip25CaveatValue,\n scopeToDiff: 'optionalScopes' | 'requiredScopes',\n): Caip25CaveatValue {\n const diff = cloneDeep(originalValue);\n\n const mergedScopeToDiff = mergedValue[scopeToDiff];\n for (const [scopeString, mergedScopeObject] of Object.entries(\n mergedScopeToDiff,\n )) {\n const internalScopeString = scopeString as keyof typeof mergedScopeToDiff;\n const originalScopeObject = diff[scopeToDiff][internalScopeString];\n\n if (originalScopeObject) {\n const newAccounts = mergedScopeObject.accounts.filter(\n (account) => !originalScopeObject?.accounts.includes(account),\n );\n if (newAccounts.length > 0) {\n diff[scopeToDiff][internalScopeString] = {\n accounts: newAccounts,\n };\n continue;\n }\n delete diff[scopeToDiff][internalScopeString];\n } else {\n diff[scopeToDiff][internalScopeString] = mergedScopeObject;\n }\n }\n\n return diff;\n}\n\n/**\n * Checks if every account in the given scopes object is supported.\n *\n * @param scopesObject - The scopes object to iterate over.\n * @param listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * addresses.\n * @returns True if every account in the scopes object is supported, false otherwise.\n */\nfunction isEveryAccountInScopesObjectSupported(\n scopesObject: InternalScopesObject,\n listAccounts: () => { type: string; address: Hex }[],\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[],\n) {\n return Object.values(scopesObject).every((scopeObject) =>\n scopeObject.accounts.every((account) =>\n isSupportedAccount(account, {\n getEvmInternalAccounts: listAccounts,\n getNonEvmAccountAddresses,\n }),\n ),\n );\n}\n\n/**\n * Helper that returns a `authorizedScopes` CAIP-25 caveat specification\n * that can be passed into the PermissionController constructor.\n *\n * @param options - The specification builder options.\n * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.\n * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.\n * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns The specification for the `caip25` caveat.\n */\nexport const caip25CaveatBuilder = ({\n findNetworkClientIdByChainId,\n listAccounts,\n isNonEvmScopeSupported,\n getNonEvmAccountAddresses,\n}: Caip25EndowmentCaveatSpecificationBuilderOptions): EndowmentCaveatSpecificationConstraint &\n Required<\n Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>\n > => {\n return {\n type: Caip25CaveatType,\n validator: (\n caveat: { type: typeof Caip25CaveatType; value: unknown },\n _origin?: string,\n _target?: string,\n ) => {\n if (\n !caveat.value ||\n !hasProperty(caveat.value, 'requiredScopes') ||\n !hasProperty(caveat.value, 'optionalScopes') ||\n !hasProperty(caveat.value, 'isMultichainOrigin') ||\n !hasProperty(caveat.value, 'sessionProperties') ||\n typeof caveat.value.isMultichainOrigin !== 'boolean' ||\n !isObject(caveat.value.sessionProperties)\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received invalid value for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const { requiredScopes, optionalScopes, sessionProperties } =\n caveat.value;\n\n const allSessionPropertiesSupported = Object.keys(\n sessionProperties,\n ).every((sessionProperty) => isSupportedSessionProperty(sessionProperty));\n\n if (!allSessionPropertiesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received unknown session property(s) for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n if (\n Object.keys(requiredScopes).length === 0 &&\n Object.keys(optionalScopes).length === 0\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received no scopes for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const unsupportedScopes = Object.keys({\n ...requiredScopes,\n ...optionalScopes,\n }).filter(\n (scopeString) =>\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n\n if (unsupportedScopes.length > 0) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s): ${unsupportedScopes.join(', ')} for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedSessionProperties = {\n ...leftValue.sessionProperties,\n ...rightValue.sessionProperties,\n };\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\n sessionProperties: mergedSessionProperties,\n isMultichainOrigin: leftValue.isMultichainOrigin,\n };\n\n const partialDiff = diffScopesForCaip25CaveatValue(\n leftValue,\n mergedValue,\n 'requiredScopes',\n );\n\n const diff = diffScopesForCaip25CaveatValue(\n partialDiff,\n mergedValue,\n 'optionalScopes',\n );\n\n return [mergedValue, diff];\n },\n };\n};\n\ntype Caip25EndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof Caip25EndowmentPermissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => null;\n validator: PermissionValidatorConstraint;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * Helper that returns a `endowment:caip25` specification that\n * can be passed into the PermissionController constructor.\n *\n * @returns The specification for the `caip25` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n Record<never, never>,\n Caip25EndowmentSpecification\n> = () => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: Caip25EndowmentPermissionName,\n allowedCaveats: [Caip25CaveatType],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => null,\n validator: (permission: PermissionConstraint) => {\n if (\n permission.caveats?.length !== 1 ||\n permission.caveats?.[0]?.type !== Caip25CaveatType\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Invalid caveats. There must be a single caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n },\n };\n};\n\n/**\n * The `caip25` endowment specification builder. Passed to the\n * `PermissionController` for constructing and validating the\n * `endowment:caip25` permission.\n */\nexport const caip25EndowmentBuilder = Object.freeze({\n targetName: Caip25EndowmentPermissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Factories that construct caveat mutator functions that are passed to\n * PermissionController.updatePermissionsByCaveat.\n */\nexport const Caip25CaveatMutators = {\n [Caip25CaveatType]: {\n removeScope,\n removeAccount,\n },\n};\n\n/**\n * Removes the account from the scope object.\n *\n * @param targetAddress - The address to remove from the scope object.\n * @returns A function that removes the account from the scope object.\n */\nfunction removeAccountFilterFn(targetAddress: string) {\n return (account: CaipAccountId) => {\n const parsed = parseCaipAccountId(account);\n return parsed.address !== targetAddress;\n };\n}\n\n/**\n * Removes the account from the scope object.\n *\n * @param scopeObject - The scope object to remove the account from.\n * @param targetAddress - The address to remove from the scope object.\n */\nfunction removeAccountFromScopeObject(\n scopeObject: InternalScopeObject,\n targetAddress: string,\n) {\n if (scopeObject.accounts) {\n scopeObject.accounts = scopeObject.accounts.filter(\n removeAccountFilterFn(targetAddress),\n );\n }\n}\n\n/**\n * Removes the target account from the scope object.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).\n * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.\n * @returns The updated scope object.\n */\nfunction removeAccount(\n caip25CaveatValue: Caip25CaveatValue,\n targetAddress: Hex,\n) {\n const updatedCaveatValue = cloneDeep(caip25CaveatValue);\n\n [\n updatedCaveatValue.requiredScopes,\n updatedCaveatValue.optionalScopes,\n ].forEach((scopes) => {\n Object.entries(scopes).forEach(([, scopeObject]) => {\n removeAccountFromScopeObject(scopeObject, targetAddress);\n });\n });\n\n const noChange = isEqual(updatedCaveatValue, caip25CaveatValue);\n\n if (noChange) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const hasAccounts = [\n ...Object.values(updatedCaveatValue.requiredScopes),\n ...Object.values(updatedCaveatValue.optionalScopes),\n ].some(({ accounts }) => accounts.length > 0);\n\n if (hasAccounts) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Removes the target scope from the value arrays of the given\n * `endowment:caip25` caveat. No-ops if the target scopeString is not in\n * the existing scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.\n * @param targetScopeString - The scope that is being removed.\n * @returns The updated CAIP-25 permission caveat value.\n */\nfunction removeScope(\n caip25CaveatValue: Caip25CaveatValue,\n targetScopeString: ExternalScopeString,\n) {\n const newRequiredScopes = Object.entries(\n caip25CaveatValue.requiredScopes,\n ).filter(([scope]) => scope !== targetScopeString);\n const newOptionalScopes = Object.entries(\n caip25CaveatValue.optionalScopes,\n ).filter(([scope]) => {\n return scope !== targetScopeString;\n });\n\n const requiredScopesRemoved =\n newRequiredScopes.length !==\n Object.keys(caip25CaveatValue.requiredScopes).length;\n const optionalScopesRemoved =\n newOptionalScopes.length !==\n Object.keys(caip25CaveatValue.optionalScopes).length;\n\n if (!requiredScopesRemoved && !optionalScopesRemoved) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const updatedCaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: Object.fromEntries(newRequiredScopes),\n optionalScopes: Object.fromEntries(newOptionalScopes),\n };\n\n const hasNonWalletScopes = [...newRequiredScopes, ...newOptionalScopes].some(\n ([scopeString]) => {\n const { namespace } = parseScopeString(scopeString);\n return namespace !== KnownCaipNamespace.Wallet;\n },\n );\n\n if (hasNonWalletScopes) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Modifies the requested CAIP-25 permissions object after UI confirmation.\n *\n * @param caip25CaveatValue - The requested CAIP-25 caveat value to modify.\n * @param accountAddresses - The list of permitted eth addresses.\n * @param chainIds - The list of permitted eth chainIds.\n * @returns The updated CAIP-25 caveat value with the permitted accounts and chainIds set.\n */\nexport const generateCaip25Caveat = (\n caip25CaveatValue: Caip25CaveatValue,\n accountAddresses: CaipAccountId[],\n chainIds: CaipChainId[],\n): {\n [Caip25EndowmentPermissionName]: {\n caveats: [{ type: string; value: Caip25CaveatValue }];\n };\n} => {\n const caveatValueWithChains = setChainIdsInCaip25CaveatValue(\n caip25CaveatValue,\n chainIds,\n );\n\n const caveatValueWithAccounts = setNonSCACaipAccountIdsInCaip25CaveatValue(\n caveatValueWithChains,\n accountAddresses,\n );\n\n return {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithAccounts,\n },\n ],\n },\n };\n};\n\n/**\n * Helper to get the CAIP-25 caveat from a permission\n *\n * @param [caip25Permission] - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns The CAIP-25 caveat or undefined if not found\n */\nexport function getCaip25CaveatFromPermission(caip25Permission?: {\n caveats: (\n | {\n type: string;\n value: unknown;\n }\n | {\n type: typeof Caip25CaveatType;\n value: Caip25CaveatValue;\n }\n )[];\n}) {\n return caip25Permission?.caveats.find(\n (caveat) => caveat.type === (Caip25CaveatType as string),\n ) as\n | {\n type: typeof Caip25CaveatType;\n value: Caip25CaveatValue;\n }\n | undefined;\n}\n\n/**\n * Requests user approval for the CAIP-25 permission\n * and returns a granted permissions object.\n *\n * @param requestedPermissions - The legacy permissions to request approval for.\n * @param requestedPermissions.caveats - The legacy caveats processed by the function.\n * - `restrictReturnedAccounts`: Restricts which Ethereum accounts can be accessed\n * - `restrictNetworkSwitching`: Restricts which blockchain networks can be used\n * @returns The converted CAIP-25 permission object.\n */\nexport const getCaip25PermissionFromLegacyPermissions =\n (requestedPermissions?: {\n [PermissionKeys.eth_accounts]?: {\n caveats?: {\n type: keyof typeof CaveatTypes;\n value: Hex[];\n }[];\n };\n [PermissionKeys.permittedChains]?: {\n caveats?: {\n type: keyof typeof CaveatTypes;\n value: Hex[];\n }[];\n };\n }): {\n [Caip25EndowmentPermissionName]: {\n caveats: NonEmptyArray<{\n type: typeof Caip25CaveatType;\n value: typeof caveatValueWithAccountsAndChains;\n }>;\n };\n } => {\n const permissions = pick(requestedPermissions, [\n PermissionKeys.eth_accounts,\n PermissionKeys.permittedChains,\n ]);\n\n if (!permissions[PermissionKeys.eth_accounts]) {\n permissions[PermissionKeys.eth_accounts] = {};\n }\n\n if (!permissions[PermissionKeys.permittedChains]) {\n permissions[PermissionKeys.permittedChains] = {};\n }\n\n const requestedAccounts =\n permissions[PermissionKeys.eth_accounts]?.caveats?.find(\n (caveat) => caveat.type === CaveatTypes.restrictReturnedAccounts,\n )?.value ?? [];\n\n const requestedChains =\n permissions[PermissionKeys.permittedChains]?.caveats?.find(\n (caveat) => caveat.type === CaveatTypes.restrictNetworkSwitching,\n )?.value ?? [];\n\n const newCaveatValue = {\n requiredScopes: {},\n optionalScopes: {\n 'wallet:eip155': {\n accounts: [],\n },\n },\n sessionProperties: {},\n isMultichainOrigin: false,\n };\n\n const caveatValueWithChains = setPermittedEthChainIds(\n newCaveatValue,\n requestedChains,\n );\n\n const caveatValueWithAccountsAndChains = setEthAccounts(\n caveatValueWithChains,\n requestedAccounts,\n );\n\n return {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithAccountsAndChains,\n },\n ],\n },\n };\n };\n\n/**\n * Requests incremental permittedChains permission for the specified origin.\n * and updates the existing CAIP-25 permission.\n * Allows for granting without prompting for user approval which\n * would be used as part of flows like `wallet_addEthereumChain`\n * requests where the addition of the network and the permitting\n * of the chain are combined into one approval.\n *\n * @param options - The options object\n * @param options.origin - The origin to request approval for.\n * @param options.chainId - The chainId to add to the existing permittedChains.\n * @param options.autoApprove - If the chain should be granted without prompting for user approval.\n * @param options.metadata - Request data for the approval.\n * @param options.metadata.options - Additional metadata about the permission request.\n * @param options.hooks - Permission controller hooks for incremental operations.\n * @param options.hooks.requestPermissionsIncremental - Initiates an incremental permission request that prompts for user approval.\n * Incremental permission requests allow the caller to replace existing and/or add brand new permissions and caveats for the specified subject.\n * @param options.hooks.grantPermissionsIncremental - Incrementally grants approved permissions to the specified subject without prompting for user approval.\n * Every permission and caveat is stringently validated and an error is thrown if validation fails.\n */\nexport const requestPermittedChainsPermissionIncremental = async ({\n origin,\n chainId,\n autoApprove,\n hooks,\n metadata,\n}: {\n origin: string;\n chainId: Hex;\n autoApprove: boolean;\n hooks: {\n requestPermissionsIncremental: (\n subject: { origin: string },\n requestedPermissions: Record<\n string,\n { caveats: { type: string; value: unknown }[] }\n >,\n options?: { metadata?: Record<string, Json> },\n ) => Promise<\n | [\n Partial<Record<string, unknown>>,\n { data?: Record<string, unknown>; id: string; origin: string },\n ]\n | []\n >;\n grantPermissionsIncremental: (params: {\n subject: { origin: string };\n approvedPermissions: Record<\n string,\n { caveats: { type: string; value: unknown }[] }\n >;\n requestData?: Record<string, unknown>;\n }) => Partial<Record<string, unknown>>;\n };\n metadata?: { options: Record<string, Json> };\n}) => {\n const caveatValueWithChains = setPermittedEthChainIds(\n {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: {},\n isMultichainOrigin: false,\n },\n [chainId],\n );\n\n if (!autoApprove) {\n let options;\n if (metadata) {\n options = { metadata };\n }\n await hooks.requestPermissionsIncremental(\n { origin },\n {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithChains,\n },\n ],\n },\n },\n options,\n );\n return;\n }\n\n hooks.grantPermissionsIncremental({\n subject: { origin },\n approvedPermissions: {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithChains,\n },\n ],\n },\n },\n });\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-permission-operator-accounts.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"names":[],"mappings":";;;AAAA,iEAAoE;AAEpE,2CASyB;AAGzB,sDAA4D;AAC5D,sDAAyD;AAEzD,8CAAkD;AAElD;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,CAAC,WAAgC,EAAE,EAAE;IAC/D,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAEpD,OAAO,CAC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AChC,iBAAkC;IAElC,kGAAkG;IAClG,mHAAmH;IACnH,0HAA0H;IAC1H,yCAAyC;IACzC,IAAI,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,0BAA0B,GAAG,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACtE,OAAO,IAAA,wBAAgB,EAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,OAAO,8CAA8C,CACnD,eAAe,CAAC,OAAO,EACvB,0BAA0B,EAC1B,iBAAiB,CAClB,CAAC;AACJ,CAAC;AArBD,wFAqBC;AAED;;;;;;;GAOG;AACH,SAAgB,oCAAoC,CAClD,SAAwB,EACxB,iBAAkC;IAElC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAA,0BAAkB,EAAC,SAAS,CAAC,CAAC;IAEzD,OAAO,8CAA8C,CACnD,OAAO,EACP,CAAC,KAAK,CAAC,EACP,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,oFAWC","sourcesContent":["import { isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport {\n assertIsStrictHexString,\n type CaipAccountAddress,\n type CaipAccountId,\n type CaipNamespace,\n type CaipReference,\n type Hex,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { KnownWalletScopeString } from '../scope/constants';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopeString, InternalScopesObject } from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n *\n * Checks if a scope string is either an EIP155 or wallet namespaced scope string.\n *\n * @param scopeString - The scope string to check.\n * @returns True if the scope string is an EIP155 or wallet namespaced scope string, false otherwise.\n */\nconst isEip155ScopeString = (scopeString: InternalScopeString) => {\n const { namespace } = parseScopeString(scopeString);\n\n return (\n namespace === KnownCaipNamespace.Eip155 ||\n scopeString === KnownWalletScopeString.Eip155\n );\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum accounts.\n * @returns An array of Ethereum accounts.\n */\nconst getEthAccountsFromScopes = (scopes: InternalScopesObject) => {\n const ethAccounts: Hex[] = [];\n\n Object.entries(scopes).forEach(([_, { accounts }]) => {\n accounts?.forEach((account) => {\n const { address, chainId } = parseCaipAccountId(account);\n\n if (isEip155ScopeString(chainId)) {\n // This address should always be a valid Hex string because\n // it's an EIP155/Ethereum account\n assertIsStrictHexString(address);\n ethAccounts.push(address);\n }\n });\n });\n\n return ethAccounts;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to get the Ethereum accounts from.\n * @returns An array of Ethereum accounts.\n */\nexport const getEthAccounts = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n): Hex[] => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethAccounts: Hex[] = [\n ...getEthAccountsFromScopes(requiredScopes),\n ...getEthAccountsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethAccounts);\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given scopes object.\n *\n * @param scopesObject - The scopes object to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated scopes object with the Ethereum accounts set.\n */\nconst setEthAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: Hex[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const isWalletNamespace = scopeString === KnownCaipNamespace.Wallet;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!isEip155ScopeString(scopeString) && !isWalletNamespace) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.map<CaipAccountId>(\n (account) => `${namespace}:${reference}:${account}`,\n );\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: caipAccounts,\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given CAIP-25 caveat value.\n * We set the same accounts for all the scopes that are EIP155 or Wallet namespaced because\n * we do not provide UI/UX flows for selecting different accounts across different chains.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated CAIP-25 caveat value with the Ethereum accounts set.\n */\nexport const setEthAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: Hex[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/*\n *\n *\n * GENERALIZED GETTERS AND SETTERS\n *\n *\n */\n\n/**\n *\n * Getters\n *\n */\n\n/**\n * Gets all accounts from an array of scopes objects\n * This extracts all account IDs from both required and optional scopes\n * and returns a unique set.\n *\n * @param scopesObjects - The scopes objects to extract accounts from\n * @returns Array of unique account IDs\n */\nexport function getCaipAccountIdsFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): CaipAccountId[] {\n const allAccounts = new Set<CaipAccountId>();\n\n for (const scopeObject of scopesObjects) {\n for (const { accounts } of Object.values(scopeObject)) {\n for (const account of accounts) {\n allAccounts.add(account);\n }\n }\n }\n\n return Array.from(allAccounts);\n}\n\n/**\n * Gets all permitted accounts from a CAIP-25 caveat\n * This extracts all account IDs from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract accounts from\n * @returns Array of unique account IDs\n */\nexport function getCaipAccountIdsFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipAccountId[] {\n return getCaipAccountIdsFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]);\n}\n\n/**\n *\n * Setters\n *\n */\n\n/**\n * Sets the CAIP account IDs to scopes with matching namespaces in the given scopes object.\n * This function should not be used with Smart Contract Accounts (SCA) because\n * it adds the same account ID to all the scopes that have the same namespace.\n *\n * @param scopesObject - The scopes object to set the CAIP account IDs for.\n * @param accounts - The CAIP account IDs to add to the appropriate scopes.\n * @returns The updated scopes object with the CAIP account IDs set.\n */\nconst setNonSCACaipAccountIdsInScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: CaipAccountId[],\n) => {\n const accountsByNamespace = new Map<string, Set<string>>();\n\n for (const account of accounts) {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(account);\n\n if (!accountsByNamespace.has(namespace)) {\n accountsByNamespace.set(namespace, new Set());\n }\n\n accountsByNamespace.get(namespace)?.add(address);\n }\n\n const updatedScopesObject: InternalScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopesObject)) {\n const { namespace, reference } = parseScopeString(scopeString);\n\n let caipAccounts: CaipAccountId[] = [];\n\n if (namespace && reference && accountsByNamespace.has(namespace)) {\n const addressSet = accountsByNamespace.get(namespace);\n if (addressSet) {\n caipAccounts = Array.from(addressSet).map(\n (address) => `${namespace}:${reference}:${address}` as const,\n );\n }\n }\n\n updatedScopesObject[scopeString as keyof typeof scopesObject] = {\n ...scopeObject,\n accounts: getUniqueArrayItems(caipAccounts),\n };\n }\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted accounts to scopes with matching namespaces in the given CAIP-25 caveat value.\n * This function should not be used with Smart Contract Accounts (SCA) because\n * it adds the same account ID to all scopes that have the same namespace as the account.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated CAIP-25 caveat value with the permitted accounts set.\n */\nexport const setNonSCACaipAccountIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: CaipAccountId[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setNonSCACaipAccountIdsInScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setNonSCACaipAccountIdsInScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/**\n * Checks if an address and list of parsed scopes are connected to any of\n * the permitted accounts based on scope matching\n *\n * @param address - The CAIP account address to check against permitted accounts\n * @param parsedAccountScopes - The list of parsed CAIP chain ID to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the address and any account scope is connected to any permitted account\n */\nfunction isAddressWithParsedScopesInPermittedAccountIds(\n address: CaipAccountAddress,\n parsedAccountScopes: {\n namespace?: CaipNamespace;\n reference?: CaipReference;\n }[],\n permittedAccounts: CaipAccountId[],\n) {\n if (!address || !parsedAccountScopes.length || !permittedAccounts.length) {\n return false;\n }\n\n return permittedAccounts.some((account) => {\n const parsedPermittedAccount = parseCaipAccountId(account);\n\n return parsedAccountScopes.some(({ namespace, reference }) => {\n if (\n namespace !== parsedPermittedAccount.chain.namespace &&\n parsedPermittedAccount.chain.namespace !== KnownCaipNamespace.Wallet\n ) {\n return false;\n }\n\n // handle wallet:<namespace>:<address> case where namespaces are mismatched but addresses match\n // i.e. wallet:notSolana:12389812309123 and solana:0:12389812309123\n if (\n parsedPermittedAccount.chain.namespace === KnownCaipNamespace.Wallet &&\n namespace !== parsedPermittedAccount.chain.reference\n ) {\n return false;\n }\n\n // handle eip155:0 case and insensitive evm address comparison\n if (namespace === KnownCaipNamespace.Eip155) {\n return (\n (reference === '0' ||\n reference === parsedPermittedAccount.chain.reference) &&\n isEqualCaseInsensitive(address, parsedPermittedAccount.address)\n );\n }\n\n // handle wallet:<namespace>:<address> case\n if (\n parsedPermittedAccount.chain.namespace === KnownCaipNamespace.Wallet\n ) {\n return address === parsedPermittedAccount.address;\n }\n\n return (\n reference === parsedPermittedAccount.chain.reference &&\n address === parsedPermittedAccount.address\n );\n });\n });\n}\n\n/**\n * Checks if an internal account is connected to any of the permitted accounts\n * based on scope matching\n *\n * @param internalAccount - The internal account to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the account is connected to any permitted account\n */\nexport function isInternalAccountInPermittedAccountIds(\n internalAccount: InternalAccount,\n permittedAccounts: CaipAccountId[],\n): boolean {\n // temporary fix for the issue where the internal account has no scopes and or scopes is undefined\n // TODO: remove this once the bug is fixed (tracked here: https://github.com/MetaMask/accounts-planning/issues/941)\n // there is currently a bug where an account associated with a snap can fail to add scopes to the internal account in time\n // before we attempt to access this state\n if (!internalAccount?.scopes?.length) {\n return false;\n }\n\n const parsedInteralAccountScopes = internalAccount.scopes.map((scope) => {\n return parseScopeString(scope);\n });\n\n return isAddressWithParsedScopesInPermittedAccountIds(\n internalAccount.address,\n parsedInteralAccountScopes,\n permittedAccounts,\n );\n}\n\n/**\n * Checks if an CAIP account ID is connected to any of the permitted accounts\n * based on scope matching\n *\n * @param accountId - The CAIP account ID to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the account is connected to any permitted account\n */\nexport function isCaipAccountIdInPermittedAccountIds(\n accountId: CaipAccountId,\n permittedAccounts: CaipAccountId[],\n): boolean {\n const { address, chain } = parseCaipAccountId(accountId);\n\n return isAddressWithParsedScopesInPermittedAccountIds(\n address,\n [chain],\n permittedAccounts,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"caip-permission-operator-accounts.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"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,KAAK,sBAAsB,CAAC,OAAO,CAAC;YACpD,CAAC;YAED,OAAO,CACL,SAAS,KAAK,sBAAsB,CAAC,KAAK,CAAC,SAAS;gBACpD,OAAO,KAAK,sBAAsB,CAAC,OAAO,CAC3C,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,sCAAsC,CACpD,eAAgC,EAChC,iBAAkC;IAElC,kGAAkG;IAClG,mHAAmH;IACnH,0HAA0H;IAC1H,yCAAyC;IACzC,IAAI,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,0BAA0B,GAAG,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACtE,OAAO,IAAA,wBAAgB,EAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,OAAO,8CAA8C,CACnD,eAAe,CAAC,OAAO,EACvB,0BAA0B,EAC1B,iBAAiB,CAClB,CAAC;AACJ,CAAC;AArBD,wFAqBC;AAED;;;;;;;GAOG;AACH,SAAgB,oCAAoC,CAClD,SAAwB,EACxB,iBAAkC;IAElC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAA,0BAAkB,EAAC,SAAS,CAAC,CAAC;IAEzD,OAAO,8CAA8C,CACnD,OAAO,EACP,CAAC,KAAK,CAAC,EACP,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,oFAWC","sourcesContent":["import { isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport {\n assertIsStrictHexString,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type {\n CaipAccountAddress,\n CaipAccountId,\n CaipNamespace,\n CaipReference,\n Hex,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { KnownWalletScopeString } from '../scope/constants';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopeString, InternalScopesObject } from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n *\n * Checks if a scope string is either an EIP155 or wallet namespaced scope string.\n *\n * @param scopeString - The scope string to check.\n * @returns True if the scope string is an EIP155 or wallet namespaced scope string, false otherwise.\n */\nconst isEip155ScopeString = (scopeString: InternalScopeString) => {\n const { namespace } = parseScopeString(scopeString);\n\n return (\n namespace === KnownCaipNamespace.Eip155 ||\n scopeString === KnownWalletScopeString.Eip155\n );\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum accounts.\n * @returns An array of Ethereum accounts.\n */\nconst getEthAccountsFromScopes = (scopes: InternalScopesObject) => {\n const ethAccounts: Hex[] = [];\n\n Object.entries(scopes).forEach(([_, { accounts }]) => {\n accounts?.forEach((account) => {\n const { address, chainId } = parseCaipAccountId(account);\n\n if (isEip155ScopeString(chainId)) {\n // This address should always be a valid Hex string because\n // it's an EIP155/Ethereum account\n assertIsStrictHexString(address);\n ethAccounts.push(address);\n }\n });\n });\n\n return ethAccounts;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to get the Ethereum accounts from.\n * @returns An array of Ethereum accounts.\n */\nexport const getEthAccounts = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n): Hex[] => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethAccounts: Hex[] = [\n ...getEthAccountsFromScopes(requiredScopes),\n ...getEthAccountsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethAccounts);\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given scopes object.\n *\n * @param scopesObject - The scopes object to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated scopes object with the Ethereum accounts set.\n */\nconst setEthAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: Hex[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const isWalletNamespace = scopeString === KnownCaipNamespace.Wallet;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!isEip155ScopeString(scopeString) && !isWalletNamespace) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.map<CaipAccountId>(\n (account) => `${namespace}:${reference}:${account}`,\n );\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: caipAccounts,\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given CAIP-25 caveat value.\n * We set the same accounts for all the scopes that are EIP155 or Wallet namespaced because\n * we do not provide UI/UX flows for selecting different accounts across different chains.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated CAIP-25 caveat value with the Ethereum accounts set.\n */\nexport const setEthAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: Hex[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/*\n *\n *\n * GENERALIZED GETTERS AND SETTERS\n *\n *\n */\n\n/**\n *\n * Getters\n *\n */\n\n/**\n * Gets all accounts from an array of scopes objects\n * This extracts all account IDs from both required and optional scopes\n * and returns a unique set.\n *\n * @param scopesObjects - The scopes objects to extract accounts from\n * @returns Array of unique account IDs\n */\nexport function getCaipAccountIdsFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): CaipAccountId[] {\n const allAccounts = new Set<CaipAccountId>();\n\n for (const scopeObject of scopesObjects) {\n for (const { accounts } of Object.values(scopeObject)) {\n for (const account of accounts) {\n allAccounts.add(account);\n }\n }\n }\n\n return Array.from(allAccounts);\n}\n\n/**\n * Gets all permitted accounts from a CAIP-25 caveat\n * This extracts all account IDs from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract accounts from\n * @returns Array of unique account IDs\n */\nexport function getCaipAccountIdsFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipAccountId[] {\n return getCaipAccountIdsFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]);\n}\n\n/**\n *\n * Setters\n *\n */\n\n/**\n * Sets the CAIP account IDs to scopes with matching namespaces in the given scopes object.\n * This function should not be used with Smart Contract Accounts (SCA) because\n * it adds the same account ID to all the scopes that have the same namespace.\n *\n * @param scopesObject - The scopes object to set the CAIP account IDs for.\n * @param accounts - The CAIP account IDs to add to the appropriate scopes.\n * @returns The updated scopes object with the CAIP account IDs set.\n */\nconst setNonSCACaipAccountIdsInScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: CaipAccountId[],\n) => {\n const accountsByNamespace = new Map<string, Set<string>>();\n\n for (const account of accounts) {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(account);\n\n if (!accountsByNamespace.has(namespace)) {\n accountsByNamespace.set(namespace, new Set());\n }\n\n accountsByNamespace.get(namespace)?.add(address);\n }\n\n const updatedScopesObject: InternalScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopesObject)) {\n const { namespace, reference } = parseScopeString(scopeString);\n\n let caipAccounts: CaipAccountId[] = [];\n\n if (namespace && reference && accountsByNamespace.has(namespace)) {\n const addressSet = accountsByNamespace.get(namespace);\n if (addressSet) {\n caipAccounts = Array.from(addressSet).map(\n (address) => `${namespace}:${reference}:${address}` as const,\n );\n }\n }\n\n updatedScopesObject[scopeString as keyof typeof scopesObject] = {\n ...scopeObject,\n accounts: getUniqueArrayItems(caipAccounts),\n };\n }\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted accounts to scopes with matching namespaces in the given CAIP-25 caveat value.\n * This function should not be used with Smart Contract Accounts (SCA) because\n * it adds the same account ID to all scopes that have the same namespace as the account.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated CAIP-25 caveat value with the permitted accounts set.\n */\nexport const setNonSCACaipAccountIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: CaipAccountId[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setNonSCACaipAccountIdsInScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setNonSCACaipAccountIdsInScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/**\n * Checks if an address and list of parsed scopes are connected to any of\n * the permitted accounts based on scope matching\n *\n * @param address - The CAIP account address to check against permitted accounts\n * @param parsedAccountScopes - The list of parsed CAIP chain ID to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the address and any account scope is connected to any permitted account\n */\nfunction isAddressWithParsedScopesInPermittedAccountIds(\n address: CaipAccountAddress,\n parsedAccountScopes: {\n namespace?: CaipNamespace;\n reference?: CaipReference;\n }[],\n permittedAccounts: CaipAccountId[],\n) {\n if (!address || !parsedAccountScopes.length || !permittedAccounts.length) {\n return false;\n }\n\n return permittedAccounts.some((account) => {\n const parsedPermittedAccount = parseCaipAccountId(account);\n\n return parsedAccountScopes.some(({ namespace, reference }) => {\n if (\n namespace !== parsedPermittedAccount.chain.namespace &&\n parsedPermittedAccount.chain.namespace !== KnownCaipNamespace.Wallet\n ) {\n return false;\n }\n\n // handle wallet:<namespace>:<address> case where namespaces are mismatched but addresses match\n // i.e. wallet:notSolana:12389812309123 and solana:0:12389812309123\n if (\n parsedPermittedAccount.chain.namespace === KnownCaipNamespace.Wallet &&\n namespace !== parsedPermittedAccount.chain.reference\n ) {\n return false;\n }\n\n // handle eip155:0 case and insensitive evm address comparison\n if (namespace === KnownCaipNamespace.Eip155) {\n return (\n (reference === '0' ||\n reference === parsedPermittedAccount.chain.reference) &&\n isEqualCaseInsensitive(address, parsedPermittedAccount.address)\n );\n }\n\n // handle wallet:<namespace>:<address> case\n if (\n parsedPermittedAccount.chain.namespace === KnownCaipNamespace.Wallet\n ) {\n return address === parsedPermittedAccount.address;\n }\n\n return (\n reference === parsedPermittedAccount.chain.reference &&\n address === parsedPermittedAccount.address\n );\n });\n });\n}\n\n/**\n * Checks if an internal account is connected to any of the permitted accounts\n * based on scope matching\n *\n * @param internalAccount - The internal account to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the account is connected to any permitted account\n */\nexport function isInternalAccountInPermittedAccountIds(\n internalAccount: InternalAccount,\n permittedAccounts: CaipAccountId[],\n): boolean {\n // temporary fix for the issue where the internal account has no scopes and or scopes is undefined\n // TODO: remove this once the bug is fixed (tracked here: https://github.com/MetaMask/accounts-planning/issues/941)\n // there is currently a bug where an account associated with a snap can fail to add scopes to the internal account in time\n // before we attempt to access this state\n if (!internalAccount?.scopes?.length) {\n return false;\n }\n\n const parsedInteralAccountScopes = internalAccount.scopes.map((scope) => {\n return parseScopeString(scope);\n });\n\n return isAddressWithParsedScopesInPermittedAccountIds(\n internalAccount.address,\n parsedInteralAccountScopes,\n permittedAccounts,\n );\n}\n\n/**\n * Checks if an CAIP account ID is connected to any of the permitted accounts\n * based on scope matching\n *\n * @param accountId - The CAIP account ID to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the account is connected to any permitted account\n */\nexport function isCaipAccountIdInPermittedAccountIds(\n accountId: CaipAccountId,\n permittedAccounts: CaipAccountId[],\n): boolean {\n const { address, chain } = parseCaipAccountId(accountId);\n\n return isAddressWithParsedScopesInPermittedAccountIds(\n address,\n [chain],\n permittedAccounts,\n );\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
-
import {
|
|
2
|
+
import type { CaipAccountId, Hex } from "@metamask/utils";
|
|
3
3
|
import type { Caip25CaveatValue } from "../caip25Permission.cjs";
|
|
4
4
|
import type { InternalScopesObject } from "../scope/types.cjs";
|
|
5
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-permission-operator-accounts.d.cts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;
|
|
1
|
+
{"version":3,"file":"caip-permission-operator-accounts.d.cts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAMtE,OAAO,KAAK,EAEV,aAAa,EAGb,GAAG,EACJ,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAG7D,OAAO,KAAK,EAAuB,oBAAoB,EAAE,2BAAuB;AAoDhF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,sBACN,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,KACA,GAAG,EASL,CAAC;AAwCF;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,sBACN,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAYF,CAAC;AAUF;;;;GAIG;AAEH;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CAChD,aAAa,EAAE,oBAAoB,EAAE,GACpC,aAAa,EAAE,CAYjB;AAED;;;;;;;GAOG;AACH,wBAAgB,sCAAsC,CACpD,iBAAiB,EAAE,iBAAiB,GACnC,aAAa,EAAE,CAKjB;AA6DD;;;;;;;;GAQG;AACH,eAAO,MAAM,0CAA0C,sBAClC,iBAAiB,YAC1B,aAAa,EAAE,KACxB,iBAYF,CAAC;AAmEF;;;;;;;GAOG;AACH,wBAAgB,sCAAsC,CACpD,eAAe,EAAE,eAAe,EAChC,iBAAiB,EAAE,aAAa,EAAE,GACjC,OAAO,CAkBT;AAED;;;;;;;GAOG;AACH,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,aAAa,EACxB,iBAAiB,EAAE,aAAa,EAAE,GACjC,OAAO,CAQT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
-
import {
|
|
2
|
+
import type { CaipAccountId, Hex } from "@metamask/utils";
|
|
3
3
|
import type { Caip25CaveatValue } from "../caip25Permission.mjs";
|
|
4
4
|
import type { InternalScopesObject } from "../scope/types.mjs";
|
|
5
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caip-permission-operator-accounts.d.mts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;
|
|
1
|
+
{"version":3,"file":"caip-permission-operator-accounts.d.mts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAMtE,OAAO,KAAK,EAEV,aAAa,EAGb,GAAG,EACJ,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAG7D,OAAO,KAAK,EAAuB,oBAAoB,EAAE,2BAAuB;AAoDhF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,sBACN,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,KACA,GAAG,EASL,CAAC;AAwCF;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,sBACN,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAYF,CAAC;AAUF;;;;GAIG;AAEH;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CAChD,aAAa,EAAE,oBAAoB,EAAE,GACpC,aAAa,EAAE,CAYjB;AAED;;;;;;;GAOG;AACH,wBAAgB,sCAAsC,CACpD,iBAAiB,EAAE,iBAAiB,GACnC,aAAa,EAAE,CAKjB;AA6DD;;;;;;;;GAQG;AACH,eAAO,MAAM,0CAA0C,sBAClC,iBAAiB,YAC1B,aAAa,EAAE,KACxB,iBAYF,CAAC;AAmEF;;;;;;;GAOG;AACH,wBAAgB,sCAAsC,CACpD,eAAe,EAAE,eAAe,EAChC,iBAAiB,EAAE,aAAa,EAAE,GACjC,OAAO,CAkBT;AAED;;;;;;;GAOG;AACH,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,aAAa,EACxB,iBAAiB,EAAE,aAAa,EAAE,GACjC,OAAO,CAQT"}
|