@metamask-previews/chain-agnostic-permission 1.2.2-preview-5c1b2b1 → 1.2.2-preview-7cfbb337

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.
Files changed (31) hide show
  1. package/dist/caip25Permission.cjs.map +1 -1
  2. package/dist/caip25Permission.d.cts +3 -2
  3. package/dist/caip25Permission.d.cts.map +1 -1
  4. package/dist/caip25Permission.d.mts +3 -2
  5. package/dist/caip25Permission.d.mts.map +1 -1
  6. package/dist/caip25Permission.mjs.map +1 -1
  7. package/dist/operators/caip-permission-operator-accounts.cjs.map +1 -1
  8. package/dist/operators/caip-permission-operator-accounts.d.cts +1 -1
  9. package/dist/operators/caip-permission-operator-accounts.d.cts.map +1 -1
  10. package/dist/operators/caip-permission-operator-accounts.d.mts +1 -1
  11. package/dist/operators/caip-permission-operator-accounts.d.mts.map +1 -1
  12. package/dist/operators/caip-permission-operator-accounts.mjs.map +1 -1
  13. package/dist/operators/caip-permission-operator-permittedChains.cjs.map +1 -1
  14. package/dist/operators/caip-permission-operator-permittedChains.d.cts +1 -1
  15. package/dist/operators/caip-permission-operator-permittedChains.d.cts.map +1 -1
  16. package/dist/operators/caip-permission-operator-permittedChains.d.mts +1 -1
  17. package/dist/operators/caip-permission-operator-permittedChains.d.mts.map +1 -1
  18. package/dist/operators/caip-permission-operator-permittedChains.mjs.map +1 -1
  19. package/dist/operators/caip-permission-operator-session-scopes.cjs.map +1 -1
  20. package/dist/operators/caip-permission-operator-session-scopes.d.cts +1 -1
  21. package/dist/operators/caip-permission-operator-session-scopes.d.cts.map +1 -1
  22. package/dist/operators/caip-permission-operator-session-scopes.d.mts +1 -1
  23. package/dist/operators/caip-permission-operator-session-scopes.d.mts.map +1 -1
  24. package/dist/operators/caip-permission-operator-session-scopes.mjs.map +1 -1
  25. package/dist/scope/assert.cjs.map +1 -1
  26. package/dist/scope/assert.d.cts +1 -1
  27. package/dist/scope/assert.d.cts.map +1 -1
  28. package/dist/scope/assert.d.mts +1 -1
  29. package/dist/scope/assert.d.mts.map +1 -1
  30. package/dist/scope/assert.mjs.map +1 -1
  31. package/package.json +1 -1
@@ -1 +1 @@
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,MAAM,WAAW,GAAG,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CACnD,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,mBAAmB,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO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gB;oBACtB,KAAK,EAAE,gCAAgC;iBACxC;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AA5ES,QAAA,wCAAwC,4CA4EjD;AAEJ;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,2CAA2C,GAAG,KAAK,EAAE,EAChE,MAAM,EACN,OAAO,EACP,WAAW,EACX,KAAK,EACL,QAAQ,GA8BT,EAAE,EAAE;IACH,MAAM,qBAAqB,GAAG,IAAA,kEAAuB,EACnD;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,qCAA6B,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 {\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
+ {"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;A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D,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,qCAA6B,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,9 +1,10 @@
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, Hex, NonEmptyArray } from "@metamask/utils";
4
+ import type { CaipAccountId, CaipChainId, Json } from "@metamask/utils";
5
+ import { type Hex, type NonEmptyArray } from "@metamask/utils";
5
6
  import { CaveatTypes, PermissionKeys } from "./constants.cjs";
6
- import type { ExternalScopeString, InternalScopeObject, InternalScopesObject } from "./scope/types.cjs";
7
+ import { type ExternalScopeString, type InternalScopeObject, type InternalScopesObject } from "./scope/types.cjs";
7
8
  /**
8
9
  * The CAIP-25 permission caveat value.
9
10
  * 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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AAO,CAAC,EAAE;YACR,IAAI,EAAE,MAAM,kBAAkB,CAAC;YAC/B,KAAK,EAAE,GAAG,EAAE,CAAC;SACd,EAAE,CAAC;KACL,CAAC;IACF,CAAC,eAAe,eAAe,CAAC,CAAC,EAAE;QACjC,OAAO,CAAC,EAAE;YACR,IAAI,EAAE,MAAM,kBAAkB,CAAC;YAC/B,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,9 +1,10 @@
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, Hex, NonEmptyArray } from "@metamask/utils";
4
+ import type { CaipAccountId, CaipChainId, Json } from "@metamask/utils";
5
+ import { type Hex, type NonEmptyArray } from "@metamask/utils";
5
6
  import { CaveatTypes, PermissionKeys } from "./constants.mjs";
6
- import type { ExternalScopeString, InternalScopeObject, InternalScopesObject } from "./scope/types.mjs";
7
+ import { type ExternalScopeString, type InternalScopeObject, type InternalScopesObject } from "./scope/types.mjs";
7
8
  /**
8
9
  * The CAIP-25 permission caveat value.
9
10
  * 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;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,UAAW,iBAAiB;;;CAK1D,CAAC;AAEF,KAAK,gDAAgD,GAAG;IACtD,4BAA4B,EAAE,CAAC,OAAO,EAAE,GAAG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BAA6B,CAAC,EAAE;YAC/B,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,gCAAgC;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
+ {"version":3,"file":"caip25Permission.mjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AASA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;AAEzC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EAGT,wBAAwB;;;AAGzB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,wBAAoB;AAC1D,OAAO,EACL,cAAc,EACd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;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 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 +1 @@
1
- {"version":3,"file":"caip-permission-operator-accounts.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"names":[],"mappings":";;;AAAA,iEAAoE;AAEpE,2CAIyB;AAUzB,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,CACL,SAAS,KAAK,0BAAkB,CAAC,MAAM;QACvC,WAAW,KAAK,kCAAsB,CAAC,MAAM,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,MAA4B,EAAE,EAAE;IAChE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,OAAO,CAAC,MAA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AE,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
+ {"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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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 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,5 +1,5 @@
1
1
  import type { InternalAccount } from "@metamask/keyring-internal-api";
2
- import type { CaipAccountId, Hex } from "@metamask/utils";
2
+ import { type CaipAccountId, type 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;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
+ {"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;AACtE,OAAO,EAGL,KAAK,aAAa,EAGlB,KAAK,GAAG,EAGT,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 type { CaipAccountId, Hex } from "@metamask/utils";
2
+ import { type CaipAccountId, type 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;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
+ {"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;AACtE,OAAO,EAGL,KAAK,aAAa,EAGlB,KAAK,GAAG,EAGT,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 +1 @@
1
- {"version":3,"file":"caip-permission-operator-accounts.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,mCAAmC;AAEpE,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AAUzB,OAAO,EAAE,sBAAsB,EAAE,+BAA2B;AAC5D,OAAO,EAAE,mBAAmB,EAAE,+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J,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,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,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,OAAO,8CAA8C,CACnD,eAAe,CAAC,OAAO,EACvB,0BAA0B,EAC1B,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oCAAoC,CAClD,SAAwB,EACxB,iBAAkC;IAElC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAEzD,OAAO,8CAA8C,CACnD,OAAO,EACP,CAAC,KAAK,CAAC,EACP,iBAAiB,CAClB,CAAC;AACJ,CAAC","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
+ {"version":3,"file":"caip-permission-operator-accounts.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,mCAAmC;AAEpE,OAAO,EACL,uBAAuB,EAMvB,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EAAE,sBAAsB,EAAE,+BAA2B;AAC5D,OAAO,EAAE,mBAAmB,EAAE,+BAA2B;AAEzD,OAAO,EAAE,gBAAgB,EAAE,2BAAuB;AAElD;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,CAAC,WAAgC,EAAE,EAAE;IAC/D,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAEpD,OAAO,CACL,SAAS,KAAK,kBAAkB,CAAC,MAAM;QACvC,WAAW,KAAK,sBAAsB,CAAC,MAAM,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,MAA4B,EAAE,EAAE;IAChE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QACnD,QAAQ,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;YAEzD,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC;gBACjC,2DAA2D;gBAC3D,kCAAkC;gBAClC,uBAAuB,CAAC,OAAO,CAAC,CAAC;gBACjC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAA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C;YACJ,CAAC;YAED,2CAA2C;YAC3C,IACE,sBAAsB,CAAC,KAAK,CAAC,SAAS,KAAK,kBAAkB,CAAC,MAAM,EACpE,CAAC;gBACD,OAAO,OAAO,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,MAAM,UAAU,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,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,OAAO,8CAA8C,CACnD,eAAe,CAAC,OAAO,EACvB,0BAA0B,EAC1B,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oCAAoC,CAClD,SAAwB,EACxB,iBAAkC;IAElC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAEzD,OAAO,8CAA8C,CACnD,OAAO,EACP,CAAC,KAAK,CAAC,EACP,iBAAiB,CAClB,CAAC;AACJ,CAAC","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 +1 @@
1
- {"version":3,"file":"caip-permission-operator-permittedChains.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AAEnD,2CAAkE;AAElE,8DAAuD;AAEvD,sDAAyD;AAEzD,8CAAiE;AAEjE;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,iCAAiC,GAAG,CAAC,MAA4B,EAAE,EAAE;IACzE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YACzD,WAAW,CAAC,IAAI,CAAC,IAAA,wBAAK,EAAC,SAAS,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,iBAGC,EACD,EAAE;IACF,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,iBAAiB,CAAC;IAE7D,MAAM,WAAW,GAAU;QACzB,GAAG,iCAAiC,CAAC,cAAc,CAAC;QACpD,GAAG,iCAAiC,CAAC,cAAc,CAAC;KACrD,CAAC;IAEF,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AAI,IAAA,qBAAa,EAAC,WAAW,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YACvE,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAjCW,QAAA,8BAA8B,kCAiCzC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex, CaipChainId, CaipNamespace } from '@metamask/utils';\nimport { hexToBigInt, KnownCaipNamespace } from '@metamask/utils';\n\nimport { Caip25CaveatType } from '../caip25Permission';\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopesObject, InternalScopeString } from '../scope/types';\nimport { isWalletScope, parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nconst getPermittedEthChainIdsFromScopes = (scopes: InternalScopesObject) => {\n const ethChainIds: Hex[] = [];\n\n Object.keys(scopes).forEach((scopeString) => {\n const { namespace, reference } = parseScopeString(scopeString);\n if (namespace === KnownCaipNamespace.Eip155 && reference) {\n ethChainIds.push(toHex(reference));\n }\n });\n\n return ethChainIds;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nexport const getPermittedEthChainIds = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n) => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethChainIds: Hex[] = [\n ...getPermittedEthChainIdsFromScopes(requiredScopes),\n ...getPermittedEthChainIdsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethChainIds);\n};\n\n/**\n * Adds an Ethereum (EIP155 namespaced) chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.\n * @param chainId - The Ethereum chainID to add.\n * @returns The updated CAIP-25 caveat value with the added Ethereum chainID.\n */\nexport const addPermittedEthChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: Hex,\n): Caip25CaveatValue => {\n const scopeString = `eip155:${hexToBigInt(chainId).toString(10)}`;\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(scopeString) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(scopeString)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [scopeString]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - EIP155 scopes for the given chainIDs\n * - Non EIP155 scopes (e.g. \"bip122:\" or any other non ethereum namespaces)\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The chainIDs to filter EIP155 scopes by.\n * @returns The filtered scopes object.\n */\nconst filterEthScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: Hex[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\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 { namespace, reference } = parseScopeString(scopeString);\n if (!reference) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n if (namespace === KnownCaipNamespace.Eip155) {\n const chainId = toHex(reference);\n if (chainIds.includes(chainId)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n } else {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.\n * @param chainIds - The Ethereum chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.\n */\nexport const setPermittedEthChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: Hex[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedEthChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\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 scopes from a CAIP-25 caveat value\n *\n * @param scopesObjects - The scopes objects to get the scopes from.\n * @returns An array of InternalScopeStrings.\n */\nexport function getAllScopesFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): InternalScopeString[] {\n const scopeSet = new Set<InternalScopeString>();\n\n for (const scopeObject of scopesObjects) {\n for (const key of Object.keys(scopeObject)) {\n scopeSet.add(key as InternalScopeString);\n }\n }\n\n return Array.from(scopeSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 caveat\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract scopes from\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipChainId[] {\n return getAllScopesFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]) as CaipChainId[];\n}\n\n/**\n * Gets all non-wallet namespaces from a CAIP-25 caveat value\n * This extracts all namespaces from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract namespaces from\n * @returns Array of unique namespace strings\n */\nexport function getAllNamespacesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipNamespace[] {\n const allScopes = getAllScopesFromCaip25CaveatValue(caip25CaveatValue);\n const namespaceSet = new Set<CaipNamespace>();\n\n for (const scope of allScopes) {\n const { namespace, reference } = parseScopeString(scope);\n if (namespace === KnownCaipNamespace.Wallet) {\n namespaceSet.add(reference ?? namespace);\n } else if (namespace) {\n namespaceSet.add(namespace);\n }\n }\n\n return Array.from(namespaceSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 permission\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25Permission - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromPermission(caip25Permission: {\n caveats: {\n type: string;\n value: Caip25CaveatValue;\n }[];\n}): CaipChainId[] {\n const caip25Caveat = caip25Permission.caveats.find(\n (caveat) => caveat.type === Caip25CaveatType,\n );\n if (!caip25Caveat) {\n return [];\n }\n\n return getAllScopesFromCaip25CaveatValue(caip25Caveat.value);\n}\n\n/*\n *\n * SETTERS\n *\n */\n\n/**\n * Adds a chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.\n * @param chainId - The chainID to add.\n * @returns The updated CAIP-25 caveat value with the added chainID.\n */\nexport const addCaipChainIdInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: CaipChainId,\n): Caip25CaveatValue => {\n if (\n caip25CaveatValue.requiredScopes[chainId] ||\n caip25CaveatValue.optionalScopes[chainId]\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [chainId]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Sets the CAIP-2 chainIds for the required and optional scopes.\n * If the caip25CaveatValue contains chainIds not in the chainIds array arg they are filtered out\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.\n * @param chainIds - The CAIP-2 chainIDs to set.\n * @returns The updated CAIP-25 caveat value with the CAIP-2 chainIDs.\n */\nexport const setChainIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: CaipChainId[],\n): Caip25CaveatValue => {\n const chainIdSet = new Set(chainIds);\n const result: Caip25CaveatValue = {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: caip25CaveatValue.sessionProperties,\n isMultichainOrigin: caip25CaveatValue.isMultichainOrigin,\n };\n\n for (const [key, value] of Object.entries(caip25CaveatValue.requiredScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.requiredScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.requiredScopes[scopeString] = value;\n }\n }\n\n for (const [key, value] of Object.entries(caip25CaveatValue.optionalScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.optionalScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.optionalScopes[scopeString] = value;\n }\n }\n\n for (const chainId of chainIds) {\n if (!result.requiredScopes[chainId] && !result.optionalScopes[chainId]) {\n result.optionalScopes[chainId] = { accounts: [] };\n }\n }\n\n return result;\n};\n"]}
1
+ {"version":3,"file":"caip-permission-operator-permittedChains.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AAEnD,2CAAkE;AAElE,8DAA+E;AAC/E,sDAAyD;AAEzD,8CAAiE;AAEjE;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,iCAAiC,GAAG,CAAC,MAA4B,EAAE,EAAE;IACzE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YACzD,WAAW,CAAC,IAAI,CAAC,IAAA,wBAAK,EAAC,SAAS,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,iBAGC,EACD,EAAE;IACF,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,iBAAiB,CAAC;IAE7D,MAAM,WAAW,GAAU;QACzB,GAAG,iCAAiC,CAAC,cAAc,CAAC;QACpD,GAAG,iCAAiC,CAAC,cAAc,CAAC;KACrD,CAAC;IAEF,OAAO,IAAA,+BAAmB,EAAC,WAAW,CAAC,CAAC;AAC1C,CAAC,CAAC;AAdW,QAAA,uBAAuB,2BAclC;AAEF;;;;;;;GAOG;AACI,MAAM,sBAAsB,GAAG,CACpC,iBAAoC,EACpC,OAAY,EACO,EAAE;IACrB,MAAM,WAAW,GAAG,UAAU,IAAA,mBAAW,EAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,C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CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YACvE,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAjCW,QAAA,8BAA8B,kCAiCzC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex, CaipChainId, CaipNamespace } from '@metamask/utils';\nimport { hexToBigInt, KnownCaipNamespace } from '@metamask/utils';\n\nimport { Caip25CaveatType, type Caip25CaveatValue } from '../caip25Permission';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopesObject, InternalScopeString } from '../scope/types';\nimport { isWalletScope, parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nconst getPermittedEthChainIdsFromScopes = (scopes: InternalScopesObject) => {\n const ethChainIds: Hex[] = [];\n\n Object.keys(scopes).forEach((scopeString) => {\n const { namespace, reference } = parseScopeString(scopeString);\n if (namespace === KnownCaipNamespace.Eip155 && reference) {\n ethChainIds.push(toHex(reference));\n }\n });\n\n return ethChainIds;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nexport const getPermittedEthChainIds = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n) => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethChainIds: Hex[] = [\n ...getPermittedEthChainIdsFromScopes(requiredScopes),\n ...getPermittedEthChainIdsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethChainIds);\n};\n\n/**\n * Adds an Ethereum (EIP155 namespaced) chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.\n * @param chainId - The Ethereum chainID to add.\n * @returns The updated CAIP-25 caveat value with the added Ethereum chainID.\n */\nexport const addPermittedEthChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: Hex,\n): Caip25CaveatValue => {\n const scopeString = `eip155:${hexToBigInt(chainId).toString(10)}`;\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(scopeString) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(scopeString)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [scopeString]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - EIP155 scopes for the given chainIDs\n * - Non EIP155 scopes (e.g. \"bip122:\" or any other non ethereum namespaces)\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The chainIDs to filter EIP155 scopes by.\n * @returns The filtered scopes object.\n */\nconst filterEthScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: Hex[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\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 { namespace, reference } = parseScopeString(scopeString);\n if (!reference) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n if (namespace === KnownCaipNamespace.Eip155) {\n const chainId = toHex(reference);\n if (chainIds.includes(chainId)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n } else {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.\n * @param chainIds - The Ethereum chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.\n */\nexport const setPermittedEthChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: Hex[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedEthChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\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 scopes from a CAIP-25 caveat value\n *\n * @param scopesObjects - The scopes objects to get the scopes from.\n * @returns An array of InternalScopeStrings.\n */\nexport function getAllScopesFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): InternalScopeString[] {\n const scopeSet = new Set<InternalScopeString>();\n\n for (const scopeObject of scopesObjects) {\n for (const key of Object.keys(scopeObject)) {\n scopeSet.add(key as InternalScopeString);\n }\n }\n\n return Array.from(scopeSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 caveat\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract scopes from\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipChainId[] {\n return getAllScopesFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]) as CaipChainId[];\n}\n\n/**\n * Gets all non-wallet namespaces from a CAIP-25 caveat value\n * This extracts all namespaces from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract namespaces from\n * @returns Array of unique namespace strings\n */\nexport function getAllNamespacesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipNamespace[] {\n const allScopes = getAllScopesFromCaip25CaveatValue(caip25CaveatValue);\n const namespaceSet = new Set<CaipNamespace>();\n\n for (const scope of allScopes) {\n const { namespace, reference } = parseScopeString(scope);\n if (namespace === KnownCaipNamespace.Wallet) {\n namespaceSet.add(reference ?? namespace);\n } else if (namespace) {\n namespaceSet.add(namespace);\n }\n }\n\n return Array.from(namespaceSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 permission\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25Permission - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromPermission(caip25Permission: {\n caveats: {\n type: string;\n value: Caip25CaveatValue;\n }[];\n}): CaipChainId[] {\n const caip25Caveat = caip25Permission.caveats.find(\n (caveat) => caveat.type === Caip25CaveatType,\n );\n if (!caip25Caveat) {\n return [];\n }\n\n return getAllScopesFromCaip25CaveatValue(caip25Caveat.value);\n}\n\n/*\n *\n * SETTERS\n *\n */\n\n/**\n * Adds a chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.\n * @param chainId - The chainID to add.\n * @returns The updated CAIP-25 caveat value with the added chainID.\n */\nexport const addCaipChainIdInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: CaipChainId,\n): Caip25CaveatValue => {\n if (\n caip25CaveatValue.requiredScopes[chainId] ||\n caip25CaveatValue.optionalScopes[chainId]\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [chainId]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Sets the CAIP-2 chainIds for the required and optional scopes.\n * If the caip25CaveatValue contains chainIds not in the chainIds array arg they are filtered out\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.\n * @param chainIds - The CAIP-2 chainIDs to set.\n * @returns The updated CAIP-25 caveat value with the CAIP-2 chainIDs.\n */\nexport const setChainIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: CaipChainId[],\n): Caip25CaveatValue => {\n const chainIdSet = new Set(chainIds);\n const result: Caip25CaveatValue = {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: caip25CaveatValue.sessionProperties,\n isMultichainOrigin: caip25CaveatValue.isMultichainOrigin,\n };\n\n for (const [key, value] of Object.entries(caip25CaveatValue.requiredScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.requiredScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.requiredScopes[scopeString] = value;\n }\n }\n\n for (const [key, value] of Object.entries(caip25CaveatValue.optionalScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.optionalScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.optionalScopes[scopeString] = value;\n }\n }\n\n for (const chainId of chainIds) {\n if (!result.requiredScopes[chainId] && !result.optionalScopes[chainId]) {\n result.optionalScopes[chainId] = { accounts: [] };\n }\n }\n\n return result;\n};\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { Hex, CaipChainId, CaipNamespace } from "@metamask/utils";
2
- import type { Caip25CaveatValue } from "../caip25Permission.cjs";
2
+ import { type Caip25CaveatValue } from "../caip25Permission.cjs";
3
3
  import type { InternalScopesObject, InternalScopeString } from "../scope/types.cjs";
4
4
  /**
5
5
  * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-permittedChains.d.cts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAE7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,2BAAuB;AA8BhF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,oBAAoB,EAAE,GACpC,mBAAmB,EAAE,CAUvB;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,iBAAiB,EAAE,iBAAiB,GACnC,WAAW,EAAE,CAKf;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACnD,iBAAiB,EAAE,iBAAiB,GACnC,aAAa,EAAE,CAcjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE;IAC3D,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,iBAAiB,CAAC;KAC1B,EAAE,CAAC;CACL,GAAG,WAAW,EAAE,CAShB;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,sBACzB,iBAAiB,WAC3B,WAAW,KACnB,iBAiBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,sBACtB,iBAAiB,YAC1B,WAAW,EAAE,KACtB,iBA8BF,CAAC"}
1
+ {"version":3,"file":"caip-permission-operator-permittedChains.d.cts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AAGvE,OAAO,EAAoB,KAAK,iBAAiB,EAAE,gCAA4B;AAE/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,2BAAuB;AA8BhF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,oBAAoB,EAAE,GACpC,mBAAmB,EAAE,CAUvB;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,iBAAiB,EAAE,iBAAiB,GACnC,WAAW,EAAE,CAKf;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACnD,iBAAiB,EAAE,iBAAiB,GACnC,aAAa,EAAE,CAcjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE;IAC3D,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,iBAAiB,CAAC;KAC1B,EAAE,CAAC;CACL,GAAG,WAAW,EAAE,CAShB;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,sBACzB,iBAAiB,WAC3B,WAAW,KACnB,iBAiBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,sBACtB,iBAAiB,YAC1B,WAAW,EAAE,KACtB,iBA8BF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { Hex, CaipChainId, CaipNamespace } from "@metamask/utils";
2
- import type { Caip25CaveatValue } from "../caip25Permission.mjs";
2
+ import { type Caip25CaveatValue } from "../caip25Permission.mjs";
3
3
  import type { InternalScopesObject, InternalScopeString } from "../scope/types.mjs";
4
4
  /**
5
5
  * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-permittedChains.d.mts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAE7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,2BAAuB;AA8BhF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,oBAAoB,EAAE,GACpC,mBAAmB,EAAE,CAUvB;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,iBAAiB,EAAE,iBAAiB,GACnC,WAAW,EAAE,CAKf;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACnD,iBAAiB,EAAE,iBAAiB,GACnC,aAAa,EAAE,CAcjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE;IAC3D,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,iBAAiB,CAAC;KAC1B,EAAE,CAAC;CACL,GAAG,WAAW,EAAE,CAShB;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,sBACzB,iBAAiB,WAC3B,WAAW,KACnB,iBAiBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,sBACtB,iBAAiB,YAC1B,WAAW,EAAE,KACtB,iBA8BF,CAAC"}
1
+ {"version":3,"file":"caip-permission-operator-permittedChains.d.mts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AAGvE,OAAO,EAAoB,KAAK,iBAAiB,EAAE,gCAA4B;AAE/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,2BAAuB;AA8BhF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,oBAAoB,EAAE,GACpC,mBAAmB,EAAE,CAUvB;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,iBAAiB,EAAE,iBAAiB,GACnC,WAAW,EAAE,CAKf;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACnD,iBAAiB,EAAE,iBAAiB,GACnC,aAAa,EAAE,CAcjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE;IAC3D,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,iBAAiB,CAAC;KAC1B,EAAE,CAAC;CACL,GAAG,WAAW,EAAE,CAShB;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,sBACzB,iBAAiB,WAC3B,WAAW,KACnB,iBAiBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,sBACtB,iBAAiB,YAC1B,WAAW,EAAE,KACtB,iBA8BF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-permittedChains.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAEnD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,wBAAwB;AAElE,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,OAAO,EAAE,mBAAmB,EAAE,+BAA2B;AAEzD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,2BAAuB;AAEjE;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,iCAAiC,GAAG,CAAC,MAA4B,EAAE,EAAE;IACzE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,SAAS,KAAK,kBAAkB,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YACzD,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uB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c,CAAC,EAAE,CAAC;QAC5E,MAAM,WAAW,GAAG,GAAoD,CAAC;QACzE,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YACvE,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex, CaipChainId, CaipNamespace } from '@metamask/utils';\nimport { hexToBigInt, KnownCaipNamespace } from '@metamask/utils';\n\nimport { Caip25CaveatType } from '../caip25Permission';\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopesObject, InternalScopeString } from '../scope/types';\nimport { isWalletScope, parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nconst getPermittedEthChainIdsFromScopes = (scopes: InternalScopesObject) => {\n const ethChainIds: Hex[] = [];\n\n Object.keys(scopes).forEach((scopeString) => {\n const { namespace, reference } = parseScopeString(scopeString);\n if (namespace === KnownCaipNamespace.Eip155 && reference) {\n ethChainIds.push(toHex(reference));\n }\n });\n\n return ethChainIds;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nexport const getPermittedEthChainIds = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n) => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethChainIds: Hex[] = [\n ...getPermittedEthChainIdsFromScopes(requiredScopes),\n ...getPermittedEthChainIdsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethChainIds);\n};\n\n/**\n * Adds an Ethereum (EIP155 namespaced) chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.\n * @param chainId - The Ethereum chainID to add.\n * @returns The updated CAIP-25 caveat value with the added Ethereum chainID.\n */\nexport const addPermittedEthChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: Hex,\n): Caip25CaveatValue => {\n const scopeString = `eip155:${hexToBigInt(chainId).toString(10)}`;\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(scopeString) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(scopeString)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [scopeString]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - EIP155 scopes for the given chainIDs\n * - Non EIP155 scopes (e.g. \"bip122:\" or any other non ethereum namespaces)\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The chainIDs to filter EIP155 scopes by.\n * @returns The filtered scopes object.\n */\nconst filterEthScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: Hex[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\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 { namespace, reference } = parseScopeString(scopeString);\n if (!reference) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n if (namespace === KnownCaipNamespace.Eip155) {\n const chainId = toHex(reference);\n if (chainIds.includes(chainId)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n } else {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.\n * @param chainIds - The Ethereum chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.\n */\nexport const setPermittedEthChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: Hex[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedEthChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\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 scopes from a CAIP-25 caveat value\n *\n * @param scopesObjects - The scopes objects to get the scopes from.\n * @returns An array of InternalScopeStrings.\n */\nexport function getAllScopesFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): InternalScopeString[] {\n const scopeSet = new Set<InternalScopeString>();\n\n for (const scopeObject of scopesObjects) {\n for (const key of Object.keys(scopeObject)) {\n scopeSet.add(key as InternalScopeString);\n }\n }\n\n return Array.from(scopeSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 caveat\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract scopes from\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipChainId[] {\n return getAllScopesFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]) as CaipChainId[];\n}\n\n/**\n * Gets all non-wallet namespaces from a CAIP-25 caveat value\n * This extracts all namespaces from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract namespaces from\n * @returns Array of unique namespace strings\n */\nexport function getAllNamespacesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipNamespace[] {\n const allScopes = getAllScopesFromCaip25CaveatValue(caip25CaveatValue);\n const namespaceSet = new Set<CaipNamespace>();\n\n for (const scope of allScopes) {\n const { namespace, reference } = parseScopeString(scope);\n if (namespace === KnownCaipNamespace.Wallet) {\n namespaceSet.add(reference ?? namespace);\n } else if (namespace) {\n namespaceSet.add(namespace);\n }\n }\n\n return Array.from(namespaceSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 permission\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25Permission - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromPermission(caip25Permission: {\n caveats: {\n type: string;\n value: Caip25CaveatValue;\n }[];\n}): CaipChainId[] {\n const caip25Caveat = caip25Permission.caveats.find(\n (caveat) => caveat.type === Caip25CaveatType,\n );\n if (!caip25Caveat) {\n return [];\n }\n\n return getAllScopesFromCaip25CaveatValue(caip25Caveat.value);\n}\n\n/*\n *\n * SETTERS\n *\n */\n\n/**\n * Adds a chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.\n * @param chainId - The chainID to add.\n * @returns The updated CAIP-25 caveat value with the added chainID.\n */\nexport const addCaipChainIdInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: CaipChainId,\n): Caip25CaveatValue => {\n if (\n caip25CaveatValue.requiredScopes[chainId] ||\n caip25CaveatValue.optionalScopes[chainId]\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [chainId]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Sets the CAIP-2 chainIds for the required and optional scopes.\n * If the caip25CaveatValue contains chainIds not in the chainIds array arg they are filtered out\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.\n * @param chainIds - The CAIP-2 chainIDs to set.\n * @returns The updated CAIP-25 caveat value with the CAIP-2 chainIDs.\n */\nexport const setChainIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: CaipChainId[],\n): Caip25CaveatValue => {\n const chainIdSet = new Set(chainIds);\n const result: Caip25CaveatValue = {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: caip25CaveatValue.sessionProperties,\n isMultichainOrigin: caip25CaveatValue.isMultichainOrigin,\n };\n\n for (const [key, value] of Object.entries(caip25CaveatValue.requiredScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.requiredScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.requiredScopes[scopeString] = value;\n }\n }\n\n for (const [key, value] of Object.entries(caip25CaveatValue.optionalScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.optionalScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.optionalScopes[scopeString] = value;\n }\n }\n\n for (const chainId of chainIds) {\n if (!result.requiredScopes[chainId] && !result.optionalScopes[chainId]) {\n result.optionalScopes[chainId] = { accounts: [] };\n }\n }\n\n return result;\n};\n"]}
1
+ {"version":3,"file":"caip-permission-operator-permittedChains.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAEnD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,wBAAwB;AAElE,OAAO,EAAE,gBAAgB,EAA0B,gCAA4B;AAC/E,OAAO,EAAE,mBAAmB,EAAE,+BAA2B;AAEzD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,2BAAuB;AAEjE;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,iCAAiC,GAAG,CAAC,MAA4B,EAAE,EAAE;IACzE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,SAAS,KAAK,kBAAkB,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YACzD,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,iBAGC,EACD,EAAE;IACF,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,iBAAiB,CAAC;IAE7D,MAAM,WAAW,GAAU;QACzB,GAAG,iCAAiC,CAAC,cAAc,CAAC;QACpD,GAAG,iCAAiC,CAAC,cAAc,CAAC;KACrD,CAAC;IAEF,OAAO,mBAAmB,CAAC,WAAW,CAAC,CAAC;AAC1C,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,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C,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YACvE,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex, CaipChainId, CaipNamespace } from '@metamask/utils';\nimport { hexToBigInt, KnownCaipNamespace } from '@metamask/utils';\n\nimport { Caip25CaveatType, type Caip25CaveatValue } from '../caip25Permission';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopesObject, InternalScopeString } from '../scope/types';\nimport { isWalletScope, parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nconst getPermittedEthChainIdsFromScopes = (scopes: InternalScopesObject) => {\n const ethChainIds: Hex[] = [];\n\n Object.keys(scopes).forEach((scopeString) => {\n const { namespace, reference } = parseScopeString(scopeString);\n if (namespace === KnownCaipNamespace.Eip155 && reference) {\n ethChainIds.push(toHex(reference));\n }\n });\n\n return ethChainIds;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nexport const getPermittedEthChainIds = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n) => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethChainIds: Hex[] = [\n ...getPermittedEthChainIdsFromScopes(requiredScopes),\n ...getPermittedEthChainIdsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethChainIds);\n};\n\n/**\n * Adds an Ethereum (EIP155 namespaced) chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.\n * @param chainId - The Ethereum chainID to add.\n * @returns The updated CAIP-25 caveat value with the added Ethereum chainID.\n */\nexport const addPermittedEthChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: Hex,\n): Caip25CaveatValue => {\n const scopeString = `eip155:${hexToBigInt(chainId).toString(10)}`;\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(scopeString) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(scopeString)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [scopeString]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - EIP155 scopes for the given chainIDs\n * - Non EIP155 scopes (e.g. \"bip122:\" or any other non ethereum namespaces)\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The chainIDs to filter EIP155 scopes by.\n * @returns The filtered scopes object.\n */\nconst filterEthScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: Hex[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\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 { namespace, reference } = parseScopeString(scopeString);\n if (!reference) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n if (namespace === KnownCaipNamespace.Eip155) {\n const chainId = toHex(reference);\n if (chainIds.includes(chainId)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n } else {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.\n * @param chainIds - The Ethereum chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.\n */\nexport const setPermittedEthChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: Hex[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedEthChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\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 scopes from a CAIP-25 caveat value\n *\n * @param scopesObjects - The scopes objects to get the scopes from.\n * @returns An array of InternalScopeStrings.\n */\nexport function getAllScopesFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): InternalScopeString[] {\n const scopeSet = new Set<InternalScopeString>();\n\n for (const scopeObject of scopesObjects) {\n for (const key of Object.keys(scopeObject)) {\n scopeSet.add(key as InternalScopeString);\n }\n }\n\n return Array.from(scopeSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 caveat\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract scopes from\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipChainId[] {\n return getAllScopesFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]) as CaipChainId[];\n}\n\n/**\n * Gets all non-wallet namespaces from a CAIP-25 caveat value\n * This extracts all namespaces from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract namespaces from\n * @returns Array of unique namespace strings\n */\nexport function getAllNamespacesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipNamespace[] {\n const allScopes = getAllScopesFromCaip25CaveatValue(caip25CaveatValue);\n const namespaceSet = new Set<CaipNamespace>();\n\n for (const scope of allScopes) {\n const { namespace, reference } = parseScopeString(scope);\n if (namespace === KnownCaipNamespace.Wallet) {\n namespaceSet.add(reference ?? namespace);\n } else if (namespace) {\n namespaceSet.add(namespace);\n }\n }\n\n return Array.from(namespaceSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 permission\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25Permission - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromPermission(caip25Permission: {\n caveats: {\n type: string;\n value: Caip25CaveatValue;\n }[];\n}): CaipChainId[] {\n const caip25Caveat = caip25Permission.caveats.find(\n (caveat) => caveat.type === Caip25CaveatType,\n );\n if (!caip25Caveat) {\n return [];\n }\n\n return getAllScopesFromCaip25CaveatValue(caip25Caveat.value);\n}\n\n/*\n *\n * SETTERS\n *\n */\n\n/**\n * Adds a chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.\n * @param chainId - The chainID to add.\n * @returns The updated CAIP-25 caveat value with the added chainID.\n */\nexport const addCaipChainIdInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: CaipChainId,\n): Caip25CaveatValue => {\n if (\n caip25CaveatValue.requiredScopes[chainId] ||\n caip25CaveatValue.optionalScopes[chainId]\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [chainId]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Sets the CAIP-2 chainIds for the required and optional scopes.\n * If the caip25CaveatValue contains chainIds not in the chainIds array arg they are filtered out\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.\n * @param chainIds - The CAIP-2 chainIDs to set.\n * @returns The updated CAIP-25 caveat value with the CAIP-2 chainIDs.\n */\nexport const setChainIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: CaipChainId[],\n): Caip25CaveatValue => {\n const chainIdSet = new Set(chainIds);\n const result: Caip25CaveatValue = {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: caip25CaveatValue.sessionProperties,\n isMultichainOrigin: caip25CaveatValue.isMultichainOrigin,\n };\n\n for (const [key, value] of Object.entries(caip25CaveatValue.requiredScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.requiredScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.requiredScopes[scopeString] = value;\n }\n }\n\n for (const [key, value] of Object.entries(caip25CaveatValue.optionalScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.optionalScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.optionalScopes[scopeString] = value;\n }\n }\n\n for (const chainId of chainIds) {\n if (!result.requiredScopes[chainId] && !result.optionalScopes[chainId]) {\n result.optionalScopes[chainId] = { accounts: [] };\n }\n }\n\n return result;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-session-scopes.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":";;;AAAA,2CAAoE;AAIpE,sDAK4B;AAC5B,sDAA2D;AAK3D,8CAAkD;AAElD;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,sBAA8C,EAC9C,EAAE;IACF,MAAM,cAAc,GAAyB,EAAE,CAAC;IA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QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;AACrC,CAAC,CAAC;AArBW,QAAA,6BAA6B,iCAqBxC","sourcesContent":["import { isCaipChainId, KnownCaipNamespace } from '@metamask/utils';\nimport type { CaipAccountId, CaipChainId } from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n\n/**\n * Get the permitted accounts for the given scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for\n * @param scopes - The scopes to get the permitted accounts for\n * @returns An array of permitted accounts\n */\nexport const getPermittedAccountsForScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n scopes: CaipChainId[],\n): CaipAccountId[] => {\n const scopeAccounts: CaipAccountId[] = [];\n\n scopes.forEach((scope) => {\n const requiredScope = caip25CaveatValue.requiredScopes[scope];\n const optionalScope = caip25CaveatValue.optionalScopes[scope];\n if (requiredScope) {\n scopeAccounts.push(...requiredScope.accounts);\n }\n\n if (optionalScope) {\n scopeAccounts.push(...optionalScope.accounts);\n }\n });\n return [...new Set(scopeAccounts)];\n};\n"]}
1
+ {"version":3,"file":"caip-permission-operator-session-scopes.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":";;;AAAA,2CAKyB;AAGzB,sDAK4B;AAC5B,sDAA2D;AAK3D,8CAAkD;AAElD;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,sBAA8C,EAC9C,EAAE;IACF,MAAM,cAAc,GAAyB,EAAE,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAC5C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAmD,CAAC;QAExE,cAAc,CAAC,WAAW,CAAC,GAAG;YAC5B,QAAQ;SACT,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAhBW,QAAA,uBAAuB,2BAgBlC;AAEF;;;;;;;GAOG;AACH,MAAM,yBAAyB,GAAG,CAChC,oBAA0C,EAC1C,EACE,yBAAyB,GAG1B,EACD,EAAE;IACF,MAAM,gBAAgB,GAA2B,EAAE,CAAC;IAEpD,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAC1C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAiD,CAAC;QACtE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,OAAO,GAAa,EAAE,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M,6BAA6B,GAAG,CAC3C,iBAGC,EACD,MAAqB,EACJ,EAAE;IACnB,MAAM,aAAa,GAAoB,EAAE,CAAC;IAE1C,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;AACrC,CAAC,CAAC;AArBW,QAAA,6BAA6B,iCAqBxC","sourcesContent":["import {\n type CaipAccountId,\n type CaipChainId,\n isCaipChainId,\n KnownCaipNamespace,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n\n/**\n * Get the permitted accounts for the given scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for\n * @param scopes - The scopes to get the permitted accounts for\n * @returns An array of permitted accounts\n */\nexport const getPermittedAccountsForScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n scopes: CaipChainId[],\n): CaipAccountId[] => {\n const scopeAccounts: CaipAccountId[] = [];\n\n scopes.forEach((scope) => {\n const requiredScope = caip25CaveatValue.requiredScopes[scope];\n const optionalScope = caip25CaveatValue.optionalScopes[scope];\n if (requiredScope) {\n scopeAccounts.push(...requiredScope.accounts);\n }\n\n if (optionalScope) {\n scopeAccounts.push(...optionalScope.accounts);\n }\n });\n return [...new Set(scopeAccounts)];\n};\n"]}
@@ -1,4 +1,4 @@
1
- import type { CaipAccountId, CaipChainId } from "@metamask/utils";
1
+ import { type CaipAccountId, type CaipChainId } from "@metamask/utils";
2
2
  import type { Caip25CaveatValue } from "../caip25Permission.cjs";
3
3
  import type { InternalScopesObject, NormalizedScopesObject } from "../scope/types.cjs";
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-session-scopes.d.cts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,wBAAwB;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,sBACrB,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,UACO,WAAW,EAAE,KACpB,aAAa,EAef,CAAC"}
1
+ {"version":3,"file":"caip-permission-operator-session-scopes.d.cts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAGjB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,sBACrB,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,UACO,WAAW,EAAE,KACpB,aAAa,EAef,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { CaipAccountId, CaipChainId } from "@metamask/utils";
1
+ import { type CaipAccountId, type CaipChainId } from "@metamask/utils";
2
2
  import type { Caip25CaveatValue } from "../caip25Permission.mjs";
3
3
  import type { InternalScopesObject, NormalizedScopesObject } from "../scope/types.mjs";
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-session-scopes.d.mts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,wBAAwB;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,sBACrB,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,UACO,WAAW,EAAE,KACpB,aAAa,EAef,CAAC"}
1
+ {"version":3,"file":"caip-permission-operator-session-scopes.d.mts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAGjB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,sBACrB,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,UACO,WAAW,EAAE,KACpB,aAAa,EAef,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-session-scopes.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,wBAAwB;AAIpE,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,8BAA8B,EAC9B,qBAAqB,EACtB,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,+BAA2B;AAK3D,OAAO,EAAE,gBAAgB,EAAE,2BAAuB;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,sBAA8C,EAC9C,EAAE;IACF,MAAM,cAAc,GAAyB,EAAE,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAC5C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAmD,CAAC;QAExE,cAAc,CAAC,WAAW,CAAC,GAAG;YAC5B,QAAQ;SACT,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,yBAAyB,GAAG,CAChC,oBAA0C,EAC1C,EACE,yBAAyB,GAG1B,EACD,EAAE;IACF,MAAM,gBAAgB,GAA2B,EAAE,CAAC;IAEpD,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAC1C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAiD,CAAC;QACtE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,OAAO,GAAa,EAAE,CAAC;QAC3B,IAAI,aAAa,GAAa,EAAE,CAAC;QAEjC,IACE,WAAW,KAAK,kBAAkB,CAAC,MAAM;YACzC,SAAS,KAAK,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C,KAAK,EAAE,EAAE;QACvB,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import { isCaipChainId, KnownCaipNamespace } from '@metamask/utils';\nimport type { CaipAccountId, CaipChainId } from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n\n/**\n * Get the permitted accounts for the given scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for\n * @param scopes - The scopes to get the permitted accounts for\n * @returns An array of permitted accounts\n */\nexport const getPermittedAccountsForScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n scopes: CaipChainId[],\n): CaipAccountId[] => {\n const scopeAccounts: CaipAccountId[] = [];\n\n scopes.forEach((scope) => {\n const requiredScope = caip25CaveatValue.requiredScopes[scope];\n const optionalScope = caip25CaveatValue.optionalScopes[scope];\n if (requiredScope) {\n scopeAccounts.push(...requiredScope.accounts);\n }\n\n if (optionalScope) {\n scopeAccounts.push(...optionalScope.accounts);\n }\n });\n return [...new Set(scopeAccounts)];\n};\n"]}
1
+ {"version":3,"file":"caip-permission-operator-session-scopes.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACb,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,8BAA8B,EAC9B,qBAAqB,EACtB,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,+BAA2B;AAK3D,OAAO,EAAE,gBAAgB,EAAE,2BAAuB;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,sBAA8C,EAC9C,EAAE;IACF,MAAM,cAAc,GAAyB,EAAE,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAC5C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAmD,CAAC;QAExE,cAAc,CAAC,WAAW,CAAC,GAAG;YAC5B,QAAQ;SACT,CAAC;IACJ,CAAC,C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AAa;YACb,QAAQ;SACT,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,iBAGC,EACD,EACE,yBAAyB,GAG1B,EACD,EAAE;IACF,OAAO,qBAAqB,CAC1B,yBAAyB,CAAC,iBAAiB,CAAC,cAAc,EAAE;QAC1D,yBAAyB;KAC1B,CAAC,EACF,yBAAyB,CAAC,iBAAiB,CAAC,cAAc,EAAE;QAC1D,yBAAyB;KAC1B,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,iBAGC,EACD,MAAqB,EACJ,EAAE;IACnB,MAAM,aAAa,GAAoB,EAAE,CAAC;IAE1C,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import {\n type CaipAccountId,\n type CaipChainId,\n isCaipChainId,\n KnownCaipNamespace,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n\n/**\n * Get the permitted accounts for the given scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for\n * @param scopes - The scopes to get the permitted accounts for\n * @returns An array of permitted accounts\n */\nexport const getPermittedAccountsForScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n scopes: CaipChainId[],\n): CaipAccountId[] => {\n const scopeAccounts: CaipAccountId[] = [];\n\n scopes.forEach((scope) => {\n const requiredScope = caip25CaveatValue.requiredScopes[scope];\n const optionalScope = caip25CaveatValue.optionalScopes[scope];\n if (requiredScope) {\n scopeAccounts.push(...requiredScope.accounts);\n }\n\n if (optionalScope) {\n scopeAccounts.push(...optionalScope.accounts);\n }\n });\n return [...new Set(scopeAccounts)];\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"assert.cjs","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":";;;AAAA,2CAOyB;AAGzB,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AAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7D,2BAA2B,CAAC,WAAW,CAAC,CAAC;QACzC,2BAA2B,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAXD,oEAWC","sourcesContent":["import {\n hasProperty,\n isCaipAccountId,\n isCaipChainId,\n isCaipNamespace,\n isCaipReference,\n KnownCaipNamespace,\n} from '@metamask/utils';\nimport type { CaipChainId, Hex } from '@metamask/utils';\n\nimport { Caip25Errors } from './errors';\nimport {\n isSupportedMethod,\n isSupportedNotification,\n isSupportedScopeString,\n} from './supported';\nimport type {\n ExternalScopeObject,\n ExternalScopesObject,\n ExternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Asserts that a scope string and its associated scope object are supported.\n *\n * @param scopeString - The scope string against which to assert support.\n * @param scopeObject - The scope object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopeSupported = (\n scopeString: string,\n scopeObject: NormalizedScopeObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n if (\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n })\n ) {\n throw Caip25Errors.requestedChainsNotSupportedError();\n }\n\n const allMethodsSupported = methods.every((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n if (!allMethodsSupported) {\n throw Caip25Errors.requestedMethodsNotSupportedError();\n }\n\n if (\n notifications &&\n !notifications.every((notification) =>\n isSupportedNotification(scopeString, notification),\n )\n ) {\n throw Caip25Errors.requestedNotificationsNotSupportedError();\n }\n};\n\n/**\n * Asserts that all scope strings and their associated scope objects are supported.\n *\n * @param scopes - The scopes object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopesSupported = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n }\n};\n/**\n * Asserts that an object is a valid ExternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsExternalScopeObject(\n obj: unknown,\n): asserts obj is ExternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopeObject must be an object');\n }\n\n if (hasProperty(obj, 'references')) {\n if (\n !Array.isArray(obj.references) ||\n !obj.references.every(isCaipReference)\n ) {\n throw new Error(\n 'ExternalScopeObject.references must be an array of CaipReference',\n );\n }\n }\n\n if (hasProperty(obj, 'accounts')) {\n if (!Array.isArray(obj.accounts) || !obj.accounts.every(isCaipAccountId)) {\n throw new Error(\n 'ExternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n }\n\n if (hasProperty(obj, 'methods')) {\n if (\n !Array.isArray(obj.methods) ||\n !obj.methods.every((method) => typeof method === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.methods must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'notifications')) {\n if (\n !Array.isArray(obj.notifications) ||\n !obj.notifications.every(\n (notification) => typeof notification === 'string',\n )\n ) {\n throw new Error(\n 'ExternalScopeObject.notifications must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcDocuments')) {\n if (\n !Array.isArray(obj.rpcDocuments) ||\n !obj.rpcDocuments.every((doc) => typeof doc === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcDocuments must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcEndpoints')) {\n if (\n !Array.isArray(obj.rpcEndpoints) ||\n !obj.rpcEndpoints.every((endpoint) => typeof endpoint === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcEndpoints must be an array of strings',\n );\n }\n }\n}\n\n/**\n * Asserts that a scope string is a valid ExternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nfunction assertIsExternalScopeString(\n scopeString: unknown,\n): asserts scopeString is ExternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n (!isCaipNamespace(scopeString) && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid ExternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid ExternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsExternalScopesObject(\n obj: unknown,\n): asserts obj is ExternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsExternalScopeString(scopeString);\n assertIsExternalScopeObject(scopeObject);\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsInternalScopeObject(\n obj: unknown,\n): asserts obj is InternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopeObject must be an object');\n }\n\n if (\n !hasProperty(obj, 'accounts') ||\n !Array.isArray(obj.accounts) ||\n !obj.accounts.every(isCaipAccountId)\n ) {\n throw new Error(\n 'InternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n}\n\n/**\n * Asserts that a scope string is a valid InternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nexport function assertIsInternalScopeString(\n scopeString: unknown,\n): asserts scopeString is InternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n // `InternalScopeString` is defined as either `KnownCaipNamespace.Wallet` or\n // `CaipChainId`, so our conditions intentionally match the type.\n (scopeString !== KnownCaipNamespace.Wallet && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid InternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsInternalScopesObject(\n obj: unknown,\n): asserts obj is InternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsInternalScopeString(scopeString);\n assertIsInternalScopeObject(scopeObject);\n }\n}\n"]}
1
+ {"version":3,"file":"assert.cjs","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":";;;AAAA,2CASyB;AAEzB,yCAAwC;AACxC,+CAIqB;AAYrB;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAAG,CAClC,WAAmB,EACnB,WAAkC,EAClC,EACE,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAK1B,EACD,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,WAAW,CAAC;IAC/C,IACE,CAAC,IAAA,kCAAsB,EAAC,WAAW,EAAE;QACnC,qBAAqB;QACrB,sBAAsB;KACvB,CAAC,EACF,CAAC;QACD,MAAM,qBAAY,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nownCaipNamespace,\n type Hex,\n} from '@metamask/utils';\n\nimport { Caip25Errors } from './errors';\nimport {\n isSupportedMethod,\n isSupportedNotification,\n isSupportedScopeString,\n} from './supported';\nimport type {\n ExternalScopeObject,\n ExternalScopesObject,\n ExternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Asserts that a scope string and its associated scope object are supported.\n *\n * @param scopeString - The scope string against which to assert support.\n * @param scopeObject - The scope object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopeSupported = (\n scopeString: string,\n scopeObject: NormalizedScopeObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n if (\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n })\n ) {\n throw Caip25Errors.requestedChainsNotSupportedError();\n }\n\n const allMethodsSupported = methods.every((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n if (!allMethodsSupported) {\n throw Caip25Errors.requestedMethodsNotSupportedError();\n }\n\n if (\n notifications &&\n !notifications.every((notification) =>\n isSupportedNotification(scopeString, notification),\n )\n ) {\n throw Caip25Errors.requestedNotificationsNotSupportedError();\n }\n};\n\n/**\n * Asserts that all scope strings and their associated scope objects are supported.\n *\n * @param scopes - The scopes object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopesSupported = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n }\n};\n/**\n * Asserts that an object is a valid ExternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsExternalScopeObject(\n obj: unknown,\n): asserts obj is ExternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopeObject must be an object');\n }\n\n if (hasProperty(obj, 'references')) {\n if (\n !Array.isArray(obj.references) ||\n !obj.references.every(isCaipReference)\n ) {\n throw new Error(\n 'ExternalScopeObject.references must be an array of CaipReference',\n );\n }\n }\n\n if (hasProperty(obj, 'accounts')) {\n if (!Array.isArray(obj.accounts) || !obj.accounts.every(isCaipAccountId)) {\n throw new Error(\n 'ExternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n }\n\n if (hasProperty(obj, 'methods')) {\n if (\n !Array.isArray(obj.methods) ||\n !obj.methods.every((method) => typeof method === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.methods must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'notifications')) {\n if (\n !Array.isArray(obj.notifications) ||\n !obj.notifications.every(\n (notification) => typeof notification === 'string',\n )\n ) {\n throw new Error(\n 'ExternalScopeObject.notifications must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcDocuments')) {\n if (\n !Array.isArray(obj.rpcDocuments) ||\n !obj.rpcDocuments.every((doc) => typeof doc === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcDocuments must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcEndpoints')) {\n if (\n !Array.isArray(obj.rpcEndpoints) ||\n !obj.rpcEndpoints.every((endpoint) => typeof endpoint === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcEndpoints must be an array of strings',\n );\n }\n }\n}\n\n/**\n * Asserts that a scope string is a valid ExternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nfunction assertIsExternalScopeString(\n scopeString: unknown,\n): asserts scopeString is ExternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n (!isCaipNamespace(scopeString) && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid ExternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid ExternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsExternalScopesObject(\n obj: unknown,\n): asserts obj is ExternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsExternalScopeString(scopeString);\n assertIsExternalScopeObject(scopeObject);\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsInternalScopeObject(\n obj: unknown,\n): asserts obj is InternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopeObject must be an object');\n }\n\n if (\n !hasProperty(obj, 'accounts') ||\n !Array.isArray(obj.accounts) ||\n !obj.accounts.every(isCaipAccountId)\n ) {\n throw new Error(\n 'InternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n}\n\n/**\n * Asserts that a scope string is a valid InternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nexport function assertIsInternalScopeString(\n scopeString: unknown,\n): asserts scopeString is InternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n // `InternalScopeString` is defined as either `KnownCaipNamespace.Wallet` or\n // `CaipChainId`, so our conditions intentionally match the type.\n (scopeString !== KnownCaipNamespace.Wallet && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid InternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsInternalScopesObject(\n obj: unknown,\n): asserts obj is InternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsInternalScopeString(scopeString);\n assertIsInternalScopeObject(scopeObject);\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { CaipChainId, Hex } from "@metamask/utils";
1
+ import { type CaipChainId, type Hex } from "@metamask/utils";
2
2
  import type { ExternalScopesObject, InternalScopesObject, InternalScopeString, NormalizedScopeObject, NormalizedScopesObject } from "./types.cjs";
3
3
  /**
4
4
  * Asserts that a scope string and its associated scope object are supported.
@@ -1 +1 @@
1
- {"version":3,"file":"assert.d.cts","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAQxD,OAAO,KAAK,EAEV,oBAAoB,EAGpB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,gBAClB,MAAM,eACN,qBAAqB;qCAMC,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UA6B9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,WACxB,sBAAsB;qCAMK,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UAU9D,CAAC;AA+FF;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC;AAyBD;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,WAAW,IAAI,mBAAmB,CAS5C;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC"}
1
+ {"version":3,"file":"assert.d.cts","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAOhB,KAAK,GAAG,EACT,wBAAwB;AAQzB,OAAO,KAAK,EAEV,oBAAoB,EAGpB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,gBAClB,MAAM,eACN,qBAAqB;qCAMC,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UA6B9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,WACxB,sBAAsB;qCAMK,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UAU9D,CAAC;AA+FF;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC;AAyBD;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,WAAW,IAAI,mBAAmB,CAS5C;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC"}
@@ -1,4 +1,4 @@
1
- import type { CaipChainId, Hex } from "@metamask/utils";
1
+ import { type CaipChainId, type Hex } from "@metamask/utils";
2
2
  import type { ExternalScopesObject, InternalScopesObject, InternalScopeString, NormalizedScopeObject, NormalizedScopesObject } from "./types.mjs";
3
3
  /**
4
4
  * Asserts that a scope string and its associated scope object are supported.
@@ -1 +1 @@
1
- {"version":3,"file":"assert.d.mts","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAQxD,OAAO,KAAK,EAEV,oBAAoB,EAGpB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,gBAClB,MAAM,eACN,qBAAqB;qCAMC,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UA6B9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,WACxB,sBAAsB;qCAMK,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UAU9D,CAAC;AA+FF;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC;AAyBD;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,WAAW,IAAI,mBAAmB,CAS5C;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC"}
1
+ {"version":3,"file":"assert.d.mts","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAOhB,KAAK,GAAG,EACT,wBAAwB;AAQzB,OAAO,KAAK,EAEV,oBAAoB,EAGpB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,gBAClB,MAAM,eACN,qBAAqB;qCAMC,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UA6B9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,WACxB,sBAAsB;qCAMK,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UAU9D,CAAC;AA+FF;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC;AAyBD;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,WAAW,IAAI,mBAAmB,CAS5C;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"assert.mjs","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EAAE,YAAY,EAAE,qBAAiB;AACxC,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACvB,wBAAoB;AAYrB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,WAAmB,EACnB,WAAkC,EAClC,EACE,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAK1B,EACD,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,WAAW,CA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;IAEZ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED,IACE,CAAC,WAAW,CAAC,GAAG,EAAE,UAAU,CAAC;QAC7B,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC5B,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,EACpC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CACzC,WAAoB;IAEpB,IACE,OAAO,WAAW,KAAK,QAAQ;QAC/B,4EAA4E;QAC5E,iEAAiE;QACjE,CAAC,WAAW,KAAK,kBAAkB,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,EAC1E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAC1C,GAAY;IAEZ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7D,2BAA2B,CAAC,WAAW,CAAC,CAAC;QACzC,2BAA2B,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC","sourcesContent":["import {\n hasProperty,\n isCaipAccountId,\n isCaipChainId,\n isCaipNamespace,\n isCaipReference,\n KnownCaipNamespace,\n} from '@metamask/utils';\nimport type { CaipChainId, Hex } from '@metamask/utils';\n\nimport { Caip25Errors } from './errors';\nimport {\n isSupportedMethod,\n isSupportedNotification,\n isSupportedScopeString,\n} from './supported';\nimport type {\n ExternalScopeObject,\n ExternalScopesObject,\n ExternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Asserts that a scope string and its associated scope object are supported.\n *\n * @param scopeString - The scope string against which to assert support.\n * @param scopeObject - The scope object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopeSupported = (\n scopeString: string,\n scopeObject: NormalizedScopeObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n if (\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n })\n ) {\n throw Caip25Errors.requestedChainsNotSupportedError();\n }\n\n const allMethodsSupported = methods.every((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n if (!allMethodsSupported) {\n throw Caip25Errors.requestedMethodsNotSupportedError();\n }\n\n if (\n notifications &&\n !notifications.every((notification) =>\n isSupportedNotification(scopeString, notification),\n )\n ) {\n throw Caip25Errors.requestedNotificationsNotSupportedError();\n }\n};\n\n/**\n * Asserts that all scope strings and their associated scope objects are supported.\n *\n * @param scopes - The scopes object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopesSupported = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n }\n};\n/**\n * Asserts that an object is a valid ExternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsExternalScopeObject(\n obj: unknown,\n): asserts obj is ExternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopeObject must be an object');\n }\n\n if (hasProperty(obj, 'references')) {\n if (\n !Array.isArray(obj.references) ||\n !obj.references.every(isCaipReference)\n ) {\n throw new Error(\n 'ExternalScopeObject.references must be an array of CaipReference',\n );\n }\n }\n\n if (hasProperty(obj, 'accounts')) {\n if (!Array.isArray(obj.accounts) || !obj.accounts.every(isCaipAccountId)) {\n throw new Error(\n 'ExternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n }\n\n if (hasProperty(obj, 'methods')) {\n if (\n !Array.isArray(obj.methods) ||\n !obj.methods.every((method) => typeof method === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.methods must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'notifications')) {\n if (\n !Array.isArray(obj.notifications) ||\n !obj.notifications.every(\n (notification) => typeof notification === 'string',\n )\n ) {\n throw new Error(\n 'ExternalScopeObject.notifications must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcDocuments')) {\n if (\n !Array.isArray(obj.rpcDocuments) ||\n !obj.rpcDocuments.every((doc) => typeof doc === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcDocuments must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcEndpoints')) {\n if (\n !Array.isArray(obj.rpcEndpoints) ||\n !obj.rpcEndpoints.every((endpoint) => typeof endpoint === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcEndpoints must be an array of strings',\n );\n }\n }\n}\n\n/**\n * Asserts that a scope string is a valid ExternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nfunction assertIsExternalScopeString(\n scopeString: unknown,\n): asserts scopeString is ExternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n (!isCaipNamespace(scopeString) && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid ExternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid ExternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsExternalScopesObject(\n obj: unknown,\n): asserts obj is ExternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsExternalScopeString(scopeString);\n assertIsExternalScopeObject(scopeObject);\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsInternalScopeObject(\n obj: unknown,\n): asserts obj is InternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopeObject must be an object');\n }\n\n if (\n !hasProperty(obj, 'accounts') ||\n !Array.isArray(obj.accounts) ||\n !obj.accounts.every(isCaipAccountId)\n ) {\n throw new Error(\n 'InternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n}\n\n/**\n * Asserts that a scope string is a valid InternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nexport function assertIsInternalScopeString(\n scopeString: unknown,\n): asserts scopeString is InternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n // `InternalScopeString` is defined as either `KnownCaipNamespace.Wallet` or\n // `CaipChainId`, so our conditions intentionally match the type.\n (scopeString !== KnownCaipNamespace.Wallet && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid InternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsInternalScopesObject(\n obj: unknown,\n): asserts obj is InternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsInternalScopeString(scopeString);\n assertIsInternalScopeObject(scopeObject);\n }\n}\n"]}
1
+ {"version":3,"file":"assert.mjs","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EAEnB,wBAAwB;AAEzB,OAAO,EAAE,YAAY,EAAE,qBAAiB;AACxC,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACvB,wBAAoB;AAYrB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,WAAmB,EACnB,WAAkC,EAClC,EACE,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAK1B,EACD,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,WAAW,CAAC;IAC/C,IACE,CAAC,sBAAsB,CAAC,WAAW,EAAE;QACnC,qBAAqB;QACrB,sBAAsB;KACvB,CAAC,EACF,CAAC;QACD,MAAM,YAAY,CAAC,gCAAgC,EAAE,CAAC;IACxD,CAAC;IAED,MAAM,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CACnD,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,yBAAyB,EAAE,CAAC,CACtE,CAAC;IAEF,IAAI,CAAC,mBAAmB,EAAE,CAAC;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K,CACb,gEAAgE,CACjE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CACzC,WAAoB;IAEpB,IACE,OAAO,WAAW,KAAK,QAAQ;QAC/B,4EAA4E;QAC5E,iEAAiE;QACjE,CAAC,WAAW,KAAK,kBAAkB,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,EAC1E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAC1C,GAAY;IAEZ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7D,2BAA2B,CAAC,WAAW,CAAC,CAAC;QACzC,2BAA2B,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC","sourcesContent":["import {\n type CaipChainId,\n hasProperty,\n isCaipAccountId,\n isCaipChainId,\n isCaipNamespace,\n isCaipReference,\n KnownCaipNamespace,\n type Hex,\n} from '@metamask/utils';\n\nimport { Caip25Errors } from './errors';\nimport {\n isSupportedMethod,\n isSupportedNotification,\n isSupportedScopeString,\n} from './supported';\nimport type {\n ExternalScopeObject,\n ExternalScopesObject,\n ExternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Asserts that a scope string and its associated scope object are supported.\n *\n * @param scopeString - The scope string against which to assert support.\n * @param scopeObject - The scope object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopeSupported = (\n scopeString: string,\n scopeObject: NormalizedScopeObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n if (\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n })\n ) {\n throw Caip25Errors.requestedChainsNotSupportedError();\n }\n\n const allMethodsSupported = methods.every((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n if (!allMethodsSupported) {\n throw Caip25Errors.requestedMethodsNotSupportedError();\n }\n\n if (\n notifications &&\n !notifications.every((notification) =>\n isSupportedNotification(scopeString, notification),\n )\n ) {\n throw Caip25Errors.requestedNotificationsNotSupportedError();\n }\n};\n\n/**\n * Asserts that all scope strings and their associated scope objects are supported.\n *\n * @param scopes - The scopes object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopesSupported = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n }\n};\n/**\n * Asserts that an object is a valid ExternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsExternalScopeObject(\n obj: unknown,\n): asserts obj is ExternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopeObject must be an object');\n }\n\n if (hasProperty(obj, 'references')) {\n if (\n !Array.isArray(obj.references) ||\n !obj.references.every(isCaipReference)\n ) {\n throw new Error(\n 'ExternalScopeObject.references must be an array of CaipReference',\n );\n }\n }\n\n if (hasProperty(obj, 'accounts')) {\n if (!Array.isArray(obj.accounts) || !obj.accounts.every(isCaipAccountId)) {\n throw new Error(\n 'ExternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n }\n\n if (hasProperty(obj, 'methods')) {\n if (\n !Array.isArray(obj.methods) ||\n !obj.methods.every((method) => typeof method === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.methods must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'notifications')) {\n if (\n !Array.isArray(obj.notifications) ||\n !obj.notifications.every(\n (notification) => typeof notification === 'string',\n )\n ) {\n throw new Error(\n 'ExternalScopeObject.notifications must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcDocuments')) {\n if (\n !Array.isArray(obj.rpcDocuments) ||\n !obj.rpcDocuments.every((doc) => typeof doc === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcDocuments must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcEndpoints')) {\n if (\n !Array.isArray(obj.rpcEndpoints) ||\n !obj.rpcEndpoints.every((endpoint) => typeof endpoint === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcEndpoints must be an array of strings',\n );\n }\n }\n}\n\n/**\n * Asserts that a scope string is a valid ExternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nfunction assertIsExternalScopeString(\n scopeString: unknown,\n): asserts scopeString is ExternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n (!isCaipNamespace(scopeString) && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid ExternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid ExternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsExternalScopesObject(\n obj: unknown,\n): asserts obj is ExternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsExternalScopeString(scopeString);\n assertIsExternalScopeObject(scopeObject);\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsInternalScopeObject(\n obj: unknown,\n): asserts obj is InternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopeObject must be an object');\n }\n\n if (\n !hasProperty(obj, 'accounts') ||\n !Array.isArray(obj.accounts) ||\n !obj.accounts.every(isCaipAccountId)\n ) {\n throw new Error(\n 'InternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n}\n\n/**\n * Asserts that a scope string is a valid InternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nexport function assertIsInternalScopeString(\n scopeString: unknown,\n): asserts scopeString is InternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n // `InternalScopeString` is defined as either `KnownCaipNamespace.Wallet` or\n // `CaipChainId`, so our conditions intentionally match the type.\n (scopeString !== KnownCaipNamespace.Wallet && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid InternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsInternalScopesObject(\n obj: unknown,\n): asserts obj is InternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsInternalScopeString(scopeString);\n assertIsInternalScopeObject(scopeObject);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/chain-agnostic-permission",
3
- "version": "1.2.2-preview-5c1b2b1",
3
+ "version": "1.2.2-preview-7cfbb337",
4
4
  "description": "Defines a CAIP-25 based endowment permission and helpers for interfacing with it",
5
5
  "keywords": [
6
6
  "MetaMask",