@metamask-previews/chain-agnostic-permission 0.2.0-preview-57dc1075 → 0.3.0-preview-b0b2930

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 (46) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/adapters/{caip-permission-adapter-eth-accounts.cjs → caip-permission-adapter-accounts.cjs} +50 -2
  3. package/dist/adapters/caip-permission-adapter-accounts.cjs.map +1 -0
  4. package/dist/adapters/{caip-permission-adapter-eth-accounts.d.cts → caip-permission-adapter-accounts.d.cts} +10 -2
  5. package/dist/adapters/caip-permission-adapter-accounts.d.cts.map +1 -0
  6. package/dist/adapters/{caip-permission-adapter-eth-accounts.d.mts → caip-permission-adapter-accounts.d.mts} +10 -2
  7. package/dist/adapters/caip-permission-adapter-accounts.d.mts.map +1 -0
  8. package/dist/adapters/{caip-permission-adapter-eth-accounts.mjs → caip-permission-adapter-accounts.mjs} +48 -1
  9. package/dist/adapters/caip-permission-adapter-accounts.mjs.map +1 -0
  10. package/dist/adapters/caip-permission-adapter-permittedChains.cjs +64 -1
  11. package/dist/adapters/caip-permission-adapter-permittedChains.cjs.map +1 -1
  12. package/dist/adapters/caip-permission-adapter-permittedChains.d.cts +18 -1
  13. package/dist/adapters/caip-permission-adapter-permittedChains.d.cts.map +1 -1
  14. package/dist/adapters/caip-permission-adapter-permittedChains.d.mts +18 -1
  15. package/dist/adapters/caip-permission-adapter-permittedChains.d.mts.map +1 -1
  16. package/dist/adapters/caip-permission-adapter-permittedChains.mjs +62 -1
  17. package/dist/adapters/caip-permission-adapter-permittedChains.mjs.map +1 -1
  18. package/dist/caip25Permission.cjs +30 -1
  19. package/dist/caip25Permission.cjs.map +1 -1
  20. package/dist/caip25Permission.d.cts +17 -1
  21. package/dist/caip25Permission.d.cts.map +1 -1
  22. package/dist/caip25Permission.d.mts +17 -1
  23. package/dist/caip25Permission.d.mts.map +1 -1
  24. package/dist/caip25Permission.mjs +28 -0
  25. package/dist/caip25Permission.mjs.map +1 -1
  26. package/dist/index.cjs +10 -4
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +4 -3
  29. package/dist/index.d.cts.map +1 -1
  30. package/dist/index.d.mts +4 -3
  31. package/dist/index.d.mts.map +1 -1
  32. package/dist/index.mjs +4 -3
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/scope/types.cjs +12 -1
  35. package/dist/scope/types.cjs.map +1 -1
  36. package/dist/scope/types.d.cts +9 -1
  37. package/dist/scope/types.d.cts.map +1 -1
  38. package/dist/scope/types.d.mts +9 -1
  39. package/dist/scope/types.d.mts.map +1 -1
  40. package/dist/scope/types.mjs +11 -1
  41. package/dist/scope/types.mjs.map +1 -1
  42. package/package.json +1 -1
  43. package/dist/adapters/caip-permission-adapter-eth-accounts.cjs.map +0 -1
  44. package/dist/adapters/caip-permission-adapter-eth-accounts.d.cts.map +0 -1
  45. package/dist/adapters/caip-permission-adapter-eth-accounts.d.mts.map +0 -1
  46. package/dist/adapters/caip-permission-adapter-eth-accounts.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"caip25Permission.cjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":";;;AASA,2EAGyC;AAEzC,2CAOyB;AACzB,mCAA4C;AAE5C,+CAA8D;AAC9D,qDAI2B;AAC3B,qDAAwD;AACxD,6CAKuB;AAcvB;;GAEG;AACU,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;GAEG;AACU,QAAA,6BAA6B,GAAG,kBAAkB,CAAC;AAEhE;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC7D,OAAO;QACL,IAAI,EAAE,wBAAgB;QACtB,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,kBAAkB,sBAK7B;AASF;;;;;;;GAOG;AACH,SAAgB,8BAA8B,CAC5C,aAAgC,EAChC,WAA8B,EAC9B,WAAgD;IAEhD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;SACvC,CAAC;KACH;IAED,MAAM,kBAAkB,GAAG;QACzB,GAAG,iBAAiB;QACpB,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;QACrD,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;KACtD,CAAC;IAEF,MAAM,kBAAkB,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,iBAAiB,CAAC,CAAC,IAAI,CAC1E,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE;QAChB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QACpD,OAAO,SAAS,KAAK,0BAAkB,CAAC,MAAM,CAAC;IACjD,CAAC,CACF,CAAC;IAEF,IAAI,kBAAkB,EAAE;QACtB,OAAO;YACL,SAAS,EAAE,8CAAsB,CAAC,WAAW;YAC7C,KAAK,EAAE,kBAAkB;SAC1B,CAAC;KACH;IAED,OAAO;QACL,SAAS,EAAE,8CAAsB,CAAC,gBAAgB;KACnD,CAAC;AACJ,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 } from 'lodash';\n\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 const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) 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"]}
1
+ {"version":3,"file":"caip25Permission.cjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":";;;AASA,2EAGyC;AAEzC,2CAOyB;AACzB,mCAA4C;AAE5C,sGAAmF;AACnF,oHAA0F;AAC1F,+CAA8D;AAC9D,qDAI2B;AAC3B,qDAAwD;AACxD,6CAKuB;AAcvB;;GAEG;AACU,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;GAEG;AACU,QAAA,6BAA6B,GAAG,kBAAkB,CAAC;AAEhE;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC7D,OAAO;QACL,IAAI,EAAE,wBAAgB;QACtB,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,kBAAkB,sBAK7B;AASF;;;;;;;GAOG;AACH,SAAgB,8BAA8B,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;QACD,MAAM,mBAAmB,GAAG,WAA6C,CAAC;QAC1E,MAAM,mBAAmB,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;QAEnE,IAAI,mBAAmB,EAAE;YACvB,MAAM,WAAW,GAAG,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CACnD,CAAC,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AAkB,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,iBAAiB,CAAC,CAAC,IAAI,CAC1E,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE;QAChB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QACpD,OAAO,SAAS,KAAK,0BAAkB,CAAC,MAAM,CAAC;IACjD,CAAC,CACF,CAAC;IAEF,IAAI,kBAAkB,EAAE;QACtB,OAAO;YACL,SAAS,EAAE,8CAAsB,CAAC,WAAW;YAC7C,KAAK,EAAE,kBAAkB;SAC1B,CAAC;KACH;IAED,OAAO;QACL,SAAS,EAAE,8CAAsB,CAAC,gBAAgB;KACnD,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACI,MAAM,oBAAoB,GAAG,CAClC,iBAAoC,EACpC,gBAAiC,EACjC,QAAuB,EAKvB,EAAE;IACF,MAAM,qBAAqB,GAAG,IAAA,8DAAoB,EAChD,iBAAiB,EACjB,QAAQ,CACT,CAAC;IAEF,MAAM,uBAAuB,GAAG,IAAA,uDAAoB,EAClD,qBAAqB,EACrB,gBAAgB,CACjB,CAAC;IAEF,OAAO;QACL,CAAC,qCAA6B,CAAC,EAAE;YAC/B,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,wBAAgB;oBACtB,KAAK,EAAE,uBAAuB;iBAC/B;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,oBAAoB,wBA6B/B","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 } from 'lodash';\n\nimport { setPermittedAccounts } from './adapters/caip-permission-adapter-accounts';\nimport { setPermittedChainIds } from './adapters/caip-permission-adapter-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 allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) 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 = setPermittedChainIds(\n caip25CaveatValue,\n chainIds,\n );\n\n const caveatValueWithAccounts = setPermittedAccounts(\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"]}
@@ -1,7 +1,7 @@
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 { CaipChainId, Json } from "@metamask/utils";
4
+ import type { CaipAccountId, CaipChainId, Json } from "@metamask/utils";
5
5
  import { type Hex, type NonEmptyArray } from "@metamask/utils";
6
6
  import { type ExternalScopeString, type InternalScopeObject, type InternalScopesObject } from "./scope/types.cjs";
7
7
  /**
@@ -127,5 +127,21 @@ declare function removeScope(caip25CaveatValue: Caip25CaveatValue, targetScopeSt
127
127
  isMultichainOrigin: boolean;
128
128
  };
129
129
  };
130
+ /**
131
+ * Modifies the requested CAIP-25 permissions object after UI confirmation.
132
+ *
133
+ * @param caip25CaveatValue - The requested CAIP-25 caveat value to modify.
134
+ * @param accountAddresses - The list of permitted eth addresses.
135
+ * @param chainIds - The list of permitted eth chainIds.
136
+ * @returns The updated CAIP-25 caveat value with the permitted accounts and chainIds set.
137
+ */
138
+ export declare const generateCaip25Caveat: (caip25CaveatValue: Caip25CaveatValue, accountAddresses: CaipAccountId[], chainIds: CaipChainId[]) => {
139
+ [Caip25EndowmentPermissionName]: {
140
+ caveats: [{
141
+ type: string;
142
+ value: Caip25CaveatValue;
143
+ }];
144
+ };
145
+ };
130
146
  export {};
131
147
  //# sourceMappingURL=caip25Permission.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"caip25Permission.d.cts","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EACV,8BAA8B,EAC9B,qBAAqB,EAErB,6BAA6B,EAE7B,sCAAsC,EACvC,wCAAwC;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wC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BAAiB,EACpC,iBAAiB,EAAE,mBAAmB;;;;;;;;;;;;;;;EA+CvC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,sBACZ,iBAAiB,oBAClB,aAAa,EAAE,YACvB,WAAW,EAAE,KACtB;IACD,+BAA+B,EAAE;QAC/B,OAAO,EAAE,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,iBAAiB,CAAA;SAAE,CAAC,CAAC;KACvD,CAAC;CAsBH,CAAC"}
@@ -1,7 +1,7 @@
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 { CaipChainId, Json } from "@metamask/utils";
4
+ import type { CaipAccountId, CaipChainId, Json } from "@metamask/utils";
5
5
  import { type Hex, type NonEmptyArray } from "@metamask/utils";
6
6
  import { type ExternalScopeString, type InternalScopeObject, type InternalScopesObject } from "./scope/types.mjs";
7
7
  /**
@@ -127,5 +127,21 @@ declare function removeScope(caip25CaveatValue: Caip25CaveatValue, targetScopeSt
127
127
  isMultichainOrigin: boolean;
128
128
  };
129
129
  };
130
+ /**
131
+ * Modifies the requested CAIP-25 permissions object after UI confirmation.
132
+ *
133
+ * @param caip25CaveatValue - The requested CAIP-25 caveat value to modify.
134
+ * @param accountAddresses - The list of permitted eth addresses.
135
+ * @param chainIds - The list of permitted eth chainIds.
136
+ * @returns The updated CAIP-25 caveat value with the permitted accounts and chainIds set.
137
+ */
138
+ export declare const generateCaip25Caveat: (caip25CaveatValue: Caip25CaveatValue, accountAddresses: CaipAccountId[], chainIds: CaipChainId[]) => {
139
+ [Caip25EndowmentPermissionName]: {
140
+ caveats: [{
141
+ type: string;
142
+ value: Caip25CaveatValue;
143
+ }];
144
+ };
145
+ };
130
146
  export {};
131
147
  //# sourceMappingURL=caip25Permission.d.mts.map
@@ -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;AACzC,OAAO,KAAK,EAAiB,WAAW,EAAE,IAAI,EAAE,wBAAwB;AACxE,OAAO,EAKL,KAAK,GAAG,EACR,KAAK,aAAa,EACnB,wBAAwB;AAUzB,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EAC1B,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,KAAK,eAAe,CAAC;IAChE,YAAY,EAAE,MAAM;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,EAAE,CAAC;IACrD,sBAAsB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IACxD,yBAAyB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,EAAE,CAAC;CAC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wBACxB,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;EAwC7C,CAAC;AAEZ;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKhC,CAAC;AAgCF;;;;;;GAMG;AACH,iBAAS,aAAa,CACpB,iBAAiB,EAAE,iBAAiB,EACpC,aAAa,EAAE,GAAG;;;;;;EAoCnB;AAED;;;;;;;;GAQG;AACH,iBAAS,WAAW,CAClB,iBAAiB,EAAE,iBAAiB,EACpC,iBAAiB,EAAE,mBAAmB;;;;;;;;;;;;;;;EA+CvC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,sBACZ,iBAAiB,oBAClB,aAAa,EAAE,YACvB,WAAW,EAAE,KACtB;IACD,+BAA+B,EAAE;QAC/B,OAAO,EAAE,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,iBAAiB,CAAA;SAAE,CAAC,CAAC;KACvD,CAAC;CAsBH,CAAC"}
@@ -2,6 +2,8 @@ import { CaveatMutatorOperation, PermissionType } from "@metamask/permission-con
2
2
  import { hasProperty, KnownCaipNamespace, parseCaipAccountId, isObject } from "@metamask/utils";
3
3
  import $lodash from "lodash";
4
4
  const { cloneDeep, isEqual } = $lodash;
5
+ import { setPermittedAccounts } from "./adapters/caip-permission-adapter-accounts.mjs";
6
+ import { setPermittedChainIds } from "./adapters/caip-permission-adapter-permittedChains.mjs";
5
7
  import { assertIsInternalScopesObject } from "./scope/assert.mjs";
6
8
  import { isSupportedAccount, isSupportedScopeString, isSupportedSessionProperty } from "./scope/supported.mjs";
7
9
  import { mergeInternalScopes } from "./scope/transform.mjs";
@@ -102,6 +104,10 @@ export const caip25CaveatBuilder = ({ findNetworkClientIdByChainId, listAccounts
102
104
  }
103
105
  assertIsInternalScopesObject(requiredScopes);
104
106
  assertIsInternalScopesObject(optionalScopes);
107
+ if (Object.keys(requiredScopes).length === 0 &&
108
+ Object.keys(optionalScopes).length === 0) {
109
+ throw new Error(`${Caip25EndowmentPermissionName} error: Received no scopes for caveat of type "${Caip25CaveatType}".`);
110
+ }
105
111
  const isEvmChainIdSupported = (chainId) => {
106
112
  try {
107
113
  findNetworkClientIdByChainId(chainId);
@@ -288,4 +294,26 @@ function removeScope(caip25CaveatValue, targetScopeString) {
288
294
  operation: CaveatMutatorOperation.RevokePermission,
289
295
  };
290
296
  }
297
+ /**
298
+ * Modifies the requested CAIP-25 permissions object after UI confirmation.
299
+ *
300
+ * @param caip25CaveatValue - The requested CAIP-25 caveat value to modify.
301
+ * @param accountAddresses - The list of permitted eth addresses.
302
+ * @param chainIds - The list of permitted eth chainIds.
303
+ * @returns The updated CAIP-25 caveat value with the permitted accounts and chainIds set.
304
+ */
305
+ export const generateCaip25Caveat = (caip25CaveatValue, accountAddresses, chainIds) => {
306
+ const caveatValueWithChains = setPermittedChainIds(caip25CaveatValue, chainIds);
307
+ const caveatValueWithAccounts = setPermittedAccounts(caveatValueWithChains, accountAddresses);
308
+ return {
309
+ [Caip25EndowmentPermissionName]: {
310
+ caveats: [
311
+ {
312
+ type: Caip25CaveatType,
313
+ value: caveatValueWithAccounts,
314
+ },
315
+ ],
316
+ },
317
+ };
318
+ };
291
319
  //# sourceMappingURL=caip25Permission.mjs.map
@@ -1 +1 @@
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,4BAA4B,EAAE,2BAAuB;AAC9D,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC3B,8BAA0B;AAC3B,OAAO,EAAE,mBAAmB,EAAE,8BAA0B;AACxD,OAAO,EACL,gBAAgB,EAIjB,0BAAsB;AAcvB;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA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qBAAqB,GACzB,iBAAiB,CAAC,MAAM;QACxB,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC;IAEvD,IAAI,CAAC,qBAAqB,IAAI,CAAC,qBAAqB,EAAE;QACpD,OAAO;YACL,SAAS,EAAE,sBAAsB,CAAC,IAAI;SACvC,CAAC;KACH;IAED,MAAM,kBAAkB,GAAG;QACzB,GAAG,iBAAiB;QACpB,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;QACrD,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;KACtD,CAAC;IAEF,MAAM,kBAAkB,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,iBAAiB,CAAC,CAAC,IAAI,CAC1E,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE;QAChB,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACpD,OAAO,SAAS,KAAK,kBAAkB,CAAC,MAAM,CAAC;IACjD,CAAC,CACF,CAAC;IAEF,IAAI,kBAAkB,EAAE;QACtB,OAAO;YACL,SAAS,EAAE,sBAAsB,CAAC,WAAW;YAC7C,KAAK,EAAE,kBAAkB;SAC1B,CAAC;KACH;IAED,OAAO;QACL,SAAS,EAAE,sBAAsB,CAAC,gBAAgB;KACnD,CAAC;AACJ,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 } from 'lodash';\n\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 const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) 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"]}
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,oBAAoB,EAAE,wDAAoD;AACnF,OAAO,EAAE,oBAAoB,EAAE,+DAA2D;AAC1F,OAAO,EAAE,4BAA4B,EAAE,2BAAuB;AAC9D,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC3B,8BAA0B;AAC3B,OAAO,EAAE,mBAAmB,EAAE,8BAA0B;AACxD,OAAO,EACL,gBAAgB,EAIjB,0BAAsB;AAcvB;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,kBAAkB,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC7D,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AASF;;;;;;;GAOG;AACH,MAAM,U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ACJ,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 } from 'lodash';\n\nimport { setPermittedAccounts } from './adapters/caip-permission-adapter-accounts';\nimport { setPermittedChainIds } from './adapters/caip-permission-adapter-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 allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) 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 = setPermittedChainIds(\n caip25CaveatValue,\n chainIds,\n );\n\n const caveatValueWithAccounts = setPermittedAccounts(\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"]}
package/dist/index.cjs CHANGED
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Caip25CaveatMutators = exports.caip25EndowmentBuilder = exports.Caip25EndowmentPermissionName = exports.createCaip25Caveat = exports.Caip25CaveatType = exports.caip25CaveatBuilder = exports.normalizeAndMergeScopes = exports.mergeInternalScopes = exports.mergeNormalizedScopes = exports.mergeScopeObject = exports.normalizeScope = exports.getUniqueArrayItems = exports.parseScopeString = exports.getSupportedScopeObjects = exports.KnownWalletScopeString = exports.KnownNotifications = exports.KnownWalletNamespaceRpcMethods = exports.KnownRpcMethods = exports.KnownWalletRpcMethods = exports.assertIsInternalScopeString = exports.bucketScopes = exports.validateAndNormalizeScopes = exports.getPermittedAccountsForScopes = exports.getSessionScopes = exports.getInternalScopesObject = exports.setPermittedEthChainIds = exports.addPermittedEthChainId = exports.getPermittedEthChainIds = exports.setEthAccounts = exports.getEthAccounts = void 0;
4
- var caip_permission_adapter_eth_accounts_1 = require("./adapters/caip-permission-adapter-eth-accounts.cjs");
5
- Object.defineProperty(exports, "getEthAccounts", { enumerable: true, get: function () { return caip_permission_adapter_eth_accounts_1.getEthAccounts; } });
6
- Object.defineProperty(exports, "setEthAccounts", { enumerable: true, get: function () { return caip_permission_adapter_eth_accounts_1.setEthAccounts; } });
3
+ exports.KnownSessionProperties = exports.generateCaip25Caveat = exports.Caip25CaveatMutators = exports.caip25EndowmentBuilder = exports.Caip25EndowmentPermissionName = exports.createCaip25Caveat = exports.Caip25CaveatType = exports.caip25CaveatBuilder = exports.normalizeAndMergeScopes = exports.mergeInternalScopes = exports.mergeNormalizedScopes = exports.mergeScopeObject = exports.normalizeScope = exports.getUniqueArrayItems = exports.parseScopeString = exports.getSupportedScopeObjects = exports.KnownWalletScopeString = exports.KnownNotifications = exports.KnownWalletNamespaceRpcMethods = exports.KnownRpcMethods = exports.KnownWalletRpcMethods = exports.assertIsInternalScopeString = exports.bucketScopes = exports.validateAndNormalizeScopes = exports.getPermittedAccountsForScopes = exports.getSessionScopes = exports.getInternalScopesObject = exports.addPermittedChainId = exports.setPermittedChainIds = exports.setPermittedEthChainIds = exports.addPermittedEthChainId = exports.getPermittedEthChainIds = exports.setPermittedAccounts = exports.setEthAccounts = exports.getEthAccounts = void 0;
4
+ var caip_permission_adapter_accounts_1 = require("./adapters/caip-permission-adapter-accounts.cjs");
5
+ Object.defineProperty(exports, "getEthAccounts", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.getEthAccounts; } });
6
+ Object.defineProperty(exports, "setEthAccounts", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.setEthAccounts; } });
7
+ Object.defineProperty(exports, "setPermittedAccounts", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.setPermittedAccounts; } });
7
8
  var caip_permission_adapter_permittedChains_1 = require("./adapters/caip-permission-adapter-permittedChains.cjs");
8
9
  Object.defineProperty(exports, "getPermittedEthChainIds", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.getPermittedEthChainIds; } });
9
10
  Object.defineProperty(exports, "addPermittedEthChainId", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.addPermittedEthChainId; } });
10
11
  Object.defineProperty(exports, "setPermittedEthChainIds", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.setPermittedEthChainIds; } });
12
+ Object.defineProperty(exports, "setPermittedChainIds", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.setPermittedChainIds; } });
13
+ Object.defineProperty(exports, "addPermittedChainId", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.addPermittedChainId; } });
11
14
  var caip_permission_adapter_session_scopes_1 = require("./adapters/caip-permission-adapter-session-scopes.cjs");
12
15
  Object.defineProperty(exports, "getInternalScopesObject", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getInternalScopesObject; } });
13
16
  Object.defineProperty(exports, "getSessionScopes", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getSessionScopes; } });
@@ -41,4 +44,7 @@ Object.defineProperty(exports, "createCaip25Caveat", { enumerable: true, get: fu
41
44
  Object.defineProperty(exports, "Caip25EndowmentPermissionName", { enumerable: true, get: function () { return caip25Permission_1.Caip25EndowmentPermissionName; } });
42
45
  Object.defineProperty(exports, "caip25EndowmentBuilder", { enumerable: true, get: function () { return caip25Permission_1.caip25EndowmentBuilder; } });
43
46
  Object.defineProperty(exports, "Caip25CaveatMutators", { enumerable: true, get: function () { return caip25Permission_1.Caip25CaveatMutators; } });
47
+ Object.defineProperty(exports, "generateCaip25Caveat", { enumerable: true, get: function () { return caip25Permission_1.generateCaip25Caveat; } });
48
+ var constants_2 = require("./scope/constants.cjs");
49
+ Object.defineProperty(exports, "KnownSessionProperties", { enumerable: true, get: function () { return constants_2.KnownSessionProperties; } });
44
50
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4GAGyD;AAFvD,sIAAA,cAAc,OAAA;AACd,sIAAA,cAAc,OAAA;AAEhB,kHAI4D;AAH1D,kJAAA,uBAAuB,OAAA;AACvB,iJAAA,sBAAsB,OAAA;AACtB,kJAAA,uBAAuB,OAAA;AAEzB,gHAI2D;AAHzD,iJAAA,uBAAuB,OAAA;AACvB,0IAAA,gBAAgB,OAAA;AAChB,uJAAA,6BAA6B,OAAA;AAI/B,2DAG+B;AAF7B,2HAAA,0BAA0B,OAAA;AAC1B,6GAAA,YAAY,OAAA;AAEd,6CAA6D;AAApD,qHAAA,2BAA2B,OAAA;AACpC,mDAM2B;AALzB,kHAAA,qBAAqB,OAAA;AACrB,4GAAA,eAAe,OAAA;AACf,2HAAA,8BAA8B,OAAA;AAC9B,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AAExB,6CAA0D;AAAjD,kHAAA,wBAAwB,OAAA;AAajC,2CAAiD;AAAxC,yGAAA,gBAAgB,OAAA;AACzB,mDAO2B;AANzB,gHAAA,mBAAmB,OAAA;AACnB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,kHAAA,qBAAqB,OAAA;AACrB,gHAAA,mBAAmB,OAAA;AACnB,oHAAA,uBAAuB,OAAA;AAIzB,2DAO4B;AAN1B,uHAAA,mBAAmB,OAAA;AACnB,oHAAA,gBAAgB,OAAA;AAChB,sHAAA,kBAAkB,OAAA;AAClB,iIAAA,6BAA6B,OAAA;AAC7B,0HAAA,sBAAsB,OAAA;AACtB,wHAAA,oBAAoB,OAAA","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n} from './adapters/caip-permission-adapter-eth-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n} from './caip25Permission';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oGAIqD;AAHnD,kIAAA,cAAc,OAAA;AACd,kIAAA,cAAc,OAAA;AACd,wIAAA,oBAAoB,OAAA;AAEtB,kHAM4D;AAL1D,kJAAA,uBAAuB,OAAA;AACvB,iJAAA,sBAAsB,OAAA;AACtB,kJAAA,uBAAuB,OAAA;AACvB,+IAAA,oBAAoB,OAAA;AACpB,8IAAA,mBAAmB,OAAA;AAErB,gHAI2D;AAHzD,iJAAA,uBAAuB,OAAA;AACvB,0IAAA,gBAAgB,OAAA;AAChB,uJAAA,6BAA6B,OAAA;AAI/B,2DAG+B;AAF7B,2HAAA,0BAA0B,OAAA;AAC1B,6GAAA,YAAY,OAAA;AAEd,6CAA6D;AAApD,qHAAA,2BAA2B,OAAA;AACpC,mDAM2B;AALzB,kHAAA,qBAAqB,OAAA;AACrB,4GAAA,eAAe,OAAA;AACf,2HAAA,8BAA8B,OAAA;AAC9B,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AAExB,6CAA0D;AAAjD,kHAAA,wBAAwB,OAAA;AAajC,2CAAiD;AAAxC,yGAAA,gBAAgB,OAAA;AACzB,mDAO2B;AANzB,gHAAA,mBAAmB,OAAA;AACnB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,kHAAA,qBAAqB,OAAA;AACrB,gHAAA,mBAAmB,OAAA;AACnB,oHAAA,uBAAuB,OAAA;AAIzB,2DAQ4B;AAP1B,uHAAA,mBAAmB,OAAA;AACnB,oHAAA,gBAAgB,OAAA;AAChB,sHAAA,kBAAkB,OAAA;AAClB,iIAAA,6BAA6B,OAAA;AAC7B,0HAAA,sBAAsB,OAAA;AACtB,wHAAA,oBAAoB,OAAA;AACpB,wHAAA,oBAAoB,OAAA;AAEtB,mDAA2D;AAAlD,mHAAA,sBAAsB,OAAA","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n setPermittedAccounts,\n} from './adapters/caip-permission-adapter-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n setPermittedChainIds,\n addPermittedChainId,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n generateCaip25Caveat,\n} from './caip25Permission';\nexport { KnownSessionProperties } from './scope/constants';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- export { getEthAccounts, setEthAccounts, } from "./adapters/caip-permission-adapter-eth-accounts.cjs";
2
- export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, } from "./adapters/caip-permission-adapter-permittedChains.cjs";
1
+ export { getEthAccounts, setEthAccounts, setPermittedAccounts, } from "./adapters/caip-permission-adapter-accounts.cjs";
2
+ export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, setPermittedChainIds, addPermittedChainId, } from "./adapters/caip-permission-adapter-permittedChains.cjs";
3
3
  export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes, } from "./adapters/caip-permission-adapter-session-scopes.cjs";
4
4
  export type { Caip25Authorization } from "./scope/authorization.cjs";
5
5
  export { validateAndNormalizeScopes, bucketScopes, } from "./scope/authorization.cjs";
@@ -10,5 +10,6 @@ export type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject, In
10
10
  export { parseScopeString } from "./scope/types.cjs";
11
11
  export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes, } from "./scope/transform.cjs";
12
12
  export type { Caip25CaveatValue } from "./caip25Permission.cjs";
13
- export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, } from "./caip25Permission.cjs";
13
+ export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, } from "./caip25Permission.cjs";
14
+ export { KnownSessionProperties } from "./scope/constants.cjs";
14
15
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,GACf,4DAAwD;AACzD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,GACxB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,GACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,GACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,GACrB,+BAA2B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,GACpB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,GACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,GACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,GACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B"}
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- export { getEthAccounts, setEthAccounts, } from "./adapters/caip-permission-adapter-eth-accounts.mjs";
2
- export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, } from "./adapters/caip-permission-adapter-permittedChains.mjs";
1
+ export { getEthAccounts, setEthAccounts, setPermittedAccounts, } from "./adapters/caip-permission-adapter-accounts.mjs";
2
+ export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, setPermittedChainIds, addPermittedChainId, } from "./adapters/caip-permission-adapter-permittedChains.mjs";
3
3
  export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes, } from "./adapters/caip-permission-adapter-session-scopes.mjs";
4
4
  export type { Caip25Authorization } from "./scope/authorization.mjs";
5
5
  export { validateAndNormalizeScopes, bucketScopes, } from "./scope/authorization.mjs";
@@ -10,5 +10,6 @@ export type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject, In
10
10
  export { parseScopeString } from "./scope/types.mjs";
11
11
  export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes, } from "./scope/transform.mjs";
12
12
  export type { Caip25CaveatValue } from "./caip25Permission.mjs";
13
- export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, } from "./caip25Permission.mjs";
13
+ export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, } from "./caip25Permission.mjs";
14
+ export { KnownSessionProperties } from "./scope/constants.mjs";
14
15
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,GACf,4DAAwD;AACzD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,GACxB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,GACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,GACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,GACrB,+BAA2B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,GACpB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,GACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,GACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,GACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- export { getEthAccounts, setEthAccounts } from "./adapters/caip-permission-adapter-eth-accounts.mjs";
2
- export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds } from "./adapters/caip-permission-adapter-permittedChains.mjs";
1
+ export { getEthAccounts, setEthAccounts, setPermittedAccounts } from "./adapters/caip-permission-adapter-accounts.mjs";
2
+ export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, setPermittedChainIds, addPermittedChainId } from "./adapters/caip-permission-adapter-permittedChains.mjs";
3
3
  export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes } from "./adapters/caip-permission-adapter-session-scopes.mjs";
4
4
  export { validateAndNormalizeScopes, bucketScopes } from "./scope/authorization.mjs";
5
5
  export { assertIsInternalScopeString } from "./scope/assert.mjs";
@@ -7,5 +7,6 @@ export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods,
7
7
  export { getSupportedScopeObjects } from "./scope/filter.mjs";
8
8
  export { parseScopeString } from "./scope/types.mjs";
9
9
  export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes } from "./scope/transform.mjs";
10
- export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators } from "./caip25Permission.mjs";
10
+ export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat } from "./caip25Permission.mjs";
11
+ export { KnownSessionProperties } from "./scope/constants.mjs";
11
12
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACf,4DAAwD;AACzD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACxB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,EAC9B,8DAA0D;AAG3D,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,EACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAa1D,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACxB,8BAA0B;AAG3B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACrB,+BAA2B","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n} from './adapters/caip-permission-adapter-eth-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n} from './caip25Permission';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACrB,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACpB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,EAC9B,8DAA0D;AAG3D,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,EACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAa1D,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACxB,8BAA0B;AAG3B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n setPermittedAccounts,\n} from './adapters/caip-permission-adapter-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n setPermittedChainIds,\n addPermittedChainId,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n generateCaip25Caveat,\n} from './caip25Permission';\nexport { KnownSessionProperties } from './scope/constants';\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseScopeString = void 0;
3
+ exports.isWalletScope = exports.parseScopeString = void 0;
4
4
  const utils_1 = require("@metamask/utils");
5
5
  /**
6
6
  * Parses a scope string into a namespace and reference.
@@ -20,4 +20,15 @@ const parseScopeString = (scopeString) => {
20
20
  return {};
21
21
  };
22
22
  exports.parseScopeString = parseScopeString;
23
+ /**
24
+ * Checks if a scope string is either a 'wallet' scope or a 'wallet:*' scope.
25
+ *
26
+ * @param scopeString - The scope string to check.
27
+ * @returns True if the scope string is a wallet scope, false otherwise.
28
+ */
29
+ const isWalletScope = (scopeString) => {
30
+ const { namespace } = (0, exports.parseScopeString)(scopeString);
31
+ return namespace === utils_1.KnownCaipNamespace.Wallet;
32
+ };
33
+ exports.isWalletScope = isWalletScope;
23
34
  //# sourceMappingURL=types.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/scope/types.ts"],"names":[],"mappings":";;;AAAA,2CAIyB;AAuFzB;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAC9B,WAAmB,EAInB,EAAE;IACF,IAAI,IAAA,uBAAe,EAAC,WAAW,CAAC,EAAE;QAChC,OAAO;YACL,SAAS,EAAE,WAAW;SACvB,CAAC;KACH;IACD,IAAI,IAAA,qBAAa,EAAC,WAAW,CAAC,EAAE;QAC9B,OAAO,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;KACtC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAhBW,QAAA,gBAAgB,oBAgB3B","sourcesContent":["import {\n isCaipNamespace,\n isCaipChainId,\n parseCaipChainId,\n} from '@metamask/utils';\nimport type {\n CaipChainId,\n CaipReference,\n CaipAccountId,\n KnownCaipNamespace,\n CaipNamespace,\n Json,\n} from '@metamask/utils';\n\n/**\n * Represents a `scopeString` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).\n */\nexport type ExternalScopeString = CaipChainId | CaipNamespace;\n/**\n * Represents a `scopeObject` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).\n */\nexport type ExternalScopeObject = Omit<NormalizedScopeObject, 'accounts'> & {\n references?: CaipReference[];\n accounts?: CaipAccountId[];\n};\n/**\n * Represents a `scope` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).\n * TODO update the language in CAIP-217 to use \"scope\" instead of \"scopeObject\" for this full record type.\n */\nexport type ExternalScopesObject = Record<\n ExternalScopeString,\n ExternalScopeObject\n>;\n\n/**\n * Represents a `scopeString` as defined in\n * [CAIP-217](https://chainagnostic.org/CAIPs/caip-217), with the exception that\n * CAIP namespaces without a reference (aside from \"wallet\") are disallowed for our internal representations of CAIP-25 session scopes\n */\nexport type InternalScopeString = CaipChainId | KnownCaipNamespace.Wallet;\n\n/**\n * A trimmed down version of a [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) defined scopeObject that is stored in a `endowment:caip25` permission.\n * The only property from the original CAIP-25 scopeObject that we use for permissioning is `accounts`.\n */\nexport type InternalScopeObject = {\n accounts: CaipAccountId[];\n};\n\n/**\n * A trimmed down version of a [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) scope that is stored in a `endowment:caip25` permission.\n * Accounts arrays are mapped to CAIP-2 chainIds. These are currently the only properties used by the permission system.\n */\nexport type InternalScopesObject = Record<CaipChainId, InternalScopeObject> & {\n [KnownCaipNamespace.Wallet]?: InternalScopeObject;\n};\n\n/**\n * Represents a `scopeObject` as defined in\n * [CAIP-217](https://chainagnostic.org/CAIPs/caip-217), with the exception that\n * we resolve the `references` property into a scopeObject per reference and\n * assign an empty array to the `accounts` property if not already defined\n * to more easily perform support checks for `wallet_createSession` requests.\n * Also used as the return type for `wallet_createSession` and `wallet_sessionChanged`.\n */\nexport type NormalizedScopeObject = {\n methods: string[];\n notifications: string[];\n accounts: CaipAccountId[];\n rpcDocuments?: string[];\n rpcEndpoints?: string[];\n};\n/**\n * Represents a keyed `scopeObject` as defined in\n * [CAIP-217](https://chainagnostic.org/CAIPs/caip-217), with the exception that\n * we resolve the `references` property into a scopeObject per reference and\n * assign an empty array to the `accounts` property if not already defined\n * to more easily perform support checks for `wallet_createSession` requests.\n * Also used as the return type for `wallet_createSession` and `wallet_sessionChanged`.\n */\nexport type NormalizedScopesObject = Record<\n CaipChainId,\n NormalizedScopeObject\n> & {\n [KnownCaipNamespace.Wallet]?: NormalizedScopeObject;\n};\n\nexport type ScopedProperties = Record<CaipChainId, Record<string, Json>> & {\n [KnownCaipNamespace.Wallet]?: Record<string, Json>;\n};\n\n/**\n * Parses a scope string into a namespace and reference.\n *\n * @param scopeString - The scope string to parse.\n * @returns An object containing the namespace and reference.\n */\nexport const parseScopeString = (\n scopeString: string,\n): {\n namespace?: string;\n reference?: string;\n} => {\n if (isCaipNamespace(scopeString)) {\n return {\n namespace: scopeString,\n };\n }\n if (isCaipChainId(scopeString)) {\n return parseCaipChainId(scopeString);\n }\n\n return {};\n};\n\n/**\n * CAIP namespaces excluding \"wallet\" currently supported by/known to the wallet.\n */\nexport type NonWalletKnownCaipNamespace = Exclude<\n KnownCaipNamespace,\n KnownCaipNamespace.Wallet\n>;\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/scope/types.ts"],"names":[],"mappings":";;;AAAA,2CAKyB;AAsFzB;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAC9B,WAAmB,EAInB,EAAE;IACF,IAAI,IAAA,uBAAe,EAAC,WAAW,CAAC,EAAE;QAChC,OAAO;YACL,SAAS,EAAE,WAAW;SACvB,CAAC;KACH;IACD,IAAI,IAAA,qBAAa,EAAC,WAAW,CAAC,EAAE;QAC9B,OAAO,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;KACtC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAhBW,QAAA,gBAAgB,oBAgB3B;AAUF;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAC3B,WAAmB,EAGwB,EAAE;IAC7C,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IACpD,OAAO,SAAS,KAAK,0BAAkB,CAAC,MAAM,CAAC;AACjD,CAAC,CAAC;AAPW,QAAA,aAAa,iBAOxB","sourcesContent":["import {\n isCaipNamespace,\n isCaipChainId,\n parseCaipChainId,\n KnownCaipNamespace,\n} from '@metamask/utils';\nimport type {\n CaipChainId,\n CaipReference,\n CaipAccountId,\n CaipNamespace,\n Json,\n} from '@metamask/utils';\n\n/**\n * Represents a `scopeString` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).\n */\nexport type ExternalScopeString = CaipChainId | CaipNamespace;\n/**\n * Represents a `scopeObject` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).\n */\nexport type ExternalScopeObject = Omit<NormalizedScopeObject, 'accounts'> & {\n references?: CaipReference[];\n accounts?: CaipAccountId[];\n};\n/**\n * Represents a `scope` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).\n * TODO update the language in CAIP-217 to use \"scope\" instead of \"scopeObject\" for this full record type.\n */\nexport type ExternalScopesObject = Record<\n ExternalScopeString,\n ExternalScopeObject\n>;\n\n/**\n * Represents a `scopeString` as defined in\n * [CAIP-217](https://chainagnostic.org/CAIPs/caip-217), with the exception that\n * CAIP namespaces without a reference (aside from \"wallet\") are disallowed for our internal representations of CAIP-25 session scopes\n */\nexport type InternalScopeString = CaipChainId | KnownCaipNamespace.Wallet;\n\n/**\n * A trimmed down version of a [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) defined scopeObject that is stored in a `endowment:caip25` permission.\n * The only property from the original CAIP-25 scopeObject that we use for permissioning is `accounts`.\n */\nexport type InternalScopeObject = {\n accounts: CaipAccountId[];\n};\n\n/**\n * A trimmed down version of a [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) scope that is stored in a `endowment:caip25` permission.\n * Accounts arrays are mapped to CAIP-2 chainIds. These are currently the only properties used by the permission system.\n */\nexport type InternalScopesObject = Record<CaipChainId, InternalScopeObject> & {\n [KnownCaipNamespace.Wallet]?: InternalScopeObject;\n};\n\n/**\n * Represents a `scopeObject` as defined in\n * [CAIP-217](https://chainagnostic.org/CAIPs/caip-217), with the exception that\n * we resolve the `references` property into a scopeObject per reference and\n * assign an empty array to the `accounts` property if not already defined\n * to more easily perform support checks for `wallet_createSession` requests.\n * Also used as the return type for `wallet_createSession` and `wallet_sessionChanged`.\n */\nexport type NormalizedScopeObject = {\n methods: string[];\n notifications: string[];\n accounts: CaipAccountId[];\n rpcDocuments?: string[];\n rpcEndpoints?: string[];\n};\n/**\n * Represents a keyed `scopeObject` as defined in\n * [CAIP-217](https://chainagnostic.org/CAIPs/caip-217), with the exception that\n * we resolve the `references` property into a scopeObject per reference and\n * assign an empty array to the `accounts` property if not already defined\n * to more easily perform support checks for `wallet_createSession` requests.\n * Also used as the return type for `wallet_createSession` and `wallet_sessionChanged`.\n */\nexport type NormalizedScopesObject = Record<\n CaipChainId,\n NormalizedScopeObject\n> & {\n [KnownCaipNamespace.Wallet]?: NormalizedScopeObject;\n};\n\nexport type ScopedProperties = Record<CaipChainId, Record<string, Json>> & {\n [KnownCaipNamespace.Wallet]?: Record<string, Json>;\n};\n\n/**\n * Parses a scope string into a namespace and reference.\n *\n * @param scopeString - The scope string to parse.\n * @returns An object containing the namespace and reference.\n */\nexport const parseScopeString = (\n scopeString: string,\n): {\n namespace?: string;\n reference?: string;\n} => {\n if (isCaipNamespace(scopeString)) {\n return {\n namespace: scopeString,\n };\n }\n if (isCaipChainId(scopeString)) {\n return parseCaipChainId(scopeString);\n }\n\n return {};\n};\n\n/**\n * CAIP namespaces excluding \"wallet\" currently supported by/known to the wallet.\n */\nexport type NonWalletKnownCaipNamespace = Exclude<\n KnownCaipNamespace,\n KnownCaipNamespace.Wallet\n>;\n\n/**\n * Checks if a scope string is either a 'wallet' scope or a 'wallet:*' scope.\n *\n * @param scopeString - The scope string to check.\n * @returns True if the scope string is a wallet scope, false otherwise.\n */\nexport const isWalletScope = (\n scopeString: string,\n): scopeString is\n | KnownCaipNamespace.Wallet\n | `${KnownCaipNamespace.Wallet}:${string}` => {\n const { namespace } = parseScopeString(scopeString);\n return namespace === KnownCaipNamespace.Wallet;\n};\n"]}
@@ -1,4 +1,5 @@
1
- import type { CaipChainId, CaipReference, CaipAccountId, KnownCaipNamespace, CaipNamespace, Json } from "@metamask/utils";
1
+ import { KnownCaipNamespace } from "@metamask/utils";
2
+ import type { CaipChainId, CaipReference, CaipAccountId, CaipNamespace, Json } from "@metamask/utils";
2
3
  /**
3
4
  * Represents a `scopeString` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).
4
5
  */
@@ -78,4 +79,11 @@ export declare const parseScopeString: (scopeString: string) => {
78
79
  * CAIP namespaces excluding "wallet" currently supported by/known to the wallet.
79
80
  */
80
81
  export type NonWalletKnownCaipNamespace = Exclude<KnownCaipNamespace, KnownCaipNamespace.Wallet>;
82
+ /**
83
+ * Checks if a scope string is either a 'wallet' scope or a 'wallet:*' scope.
84
+ *
85
+ * @param scopeString - The scope string to check.
86
+ * @returns True if the scope string is a wallet scope, false otherwise.
87
+ */
88
+ export declare const isWalletScope: (scopeString: string) => scopeString is KnownCaipNamespace.Wallet | `wallet:${string}`;
81
89
  //# sourceMappingURL=types.d.cts.map