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

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 (40) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/caip25Permission.cjs.map +1 -1
  3. package/dist/caip25Permission.d.cts +2 -3
  4. package/dist/caip25Permission.d.cts.map +1 -1
  5. package/dist/caip25Permission.d.mts +2 -3
  6. package/dist/caip25Permission.d.mts.map +1 -1
  7. package/dist/caip25Permission.mjs.map +1 -1
  8. package/dist/operators/caip-permission-operator-accounts.cjs.map +1 -1
  9. package/dist/operators/caip-permission-operator-accounts.d.cts +1 -1
  10. package/dist/operators/caip-permission-operator-accounts.d.cts.map +1 -1
  11. package/dist/operators/caip-permission-operator-accounts.d.mts +1 -1
  12. package/dist/operators/caip-permission-operator-accounts.d.mts.map +1 -1
  13. package/dist/operators/caip-permission-operator-accounts.mjs.map +1 -1
  14. package/dist/operators/caip-permission-operator-permittedChains.cjs.map +1 -1
  15. package/dist/operators/caip-permission-operator-permittedChains.d.cts +1 -1
  16. package/dist/operators/caip-permission-operator-permittedChains.d.cts.map +1 -1
  17. package/dist/operators/caip-permission-operator-permittedChains.d.mts +1 -1
  18. package/dist/operators/caip-permission-operator-permittedChains.d.mts.map +1 -1
  19. package/dist/operators/caip-permission-operator-permittedChains.mjs.map +1 -1
  20. package/dist/operators/caip-permission-operator-session-scopes.cjs.map +1 -1
  21. package/dist/operators/caip-permission-operator-session-scopes.d.cts +1 -1
  22. package/dist/operators/caip-permission-operator-session-scopes.d.cts.map +1 -1
  23. package/dist/operators/caip-permission-operator-session-scopes.d.mts +1 -1
  24. package/dist/operators/caip-permission-operator-session-scopes.d.mts.map +1 -1
  25. package/dist/operators/caip-permission-operator-session-scopes.mjs.map +1 -1
  26. package/dist/scope/assert.cjs.map +1 -1
  27. package/dist/scope/assert.d.cts +1 -1
  28. package/dist/scope/assert.d.cts.map +1 -1
  29. package/dist/scope/assert.d.mts +1 -1
  30. package/dist/scope/assert.d.mts.map +1 -1
  31. package/dist/scope/assert.mjs.map +1 -1
  32. package/dist/scope/constants.cjs +1 -0
  33. package/dist/scope/constants.cjs.map +1 -1
  34. package/dist/scope/constants.d.cts +2 -1
  35. package/dist/scope/constants.d.cts.map +1 -1
  36. package/dist/scope/constants.d.mts +2 -1
  37. package/dist/scope/constants.d.mts.map +1 -1
  38. package/dist/scope/constants.mjs +1 -0
  39. package/dist/scope/constants.mjs.map +1 -1
  40. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-accounts.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,mCAAmC;AAEpE,OAAO,EACL,uBAAuB,EAMvB,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EAAE,sBAAsB,EAAE,+BAA2B;AAC5D,OAAO,EAAE,mBAAmB,EAAE,+BAA2B;AAEzD,OAAO,EAAE,gBAAgB,EAAE,2BAAuB;AAElD;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,CAAC,WAAgC,EAAE,EAAE;IAC/D,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAEpD,OAAO,CACL,SAAS,KAAK,kBAAkB,CAAC,MAAM;QACvC,WAAW,KAAK,sBAAsB,CAAC,MAAM,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,MAA4B,EAAE,EAAE;IAChE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QACnD,QAAQ,EAAE,OAA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,CAClD,SAAwB,EACxB,iBAAkC;IAElC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAEzD,OAAO,8CAA8C,CACnD,OAAO,EACP,CAAC,KAAK,CAAC,EACP,iBAAiB,CAClB,CAAC;AACJ,CAAC","sourcesContent":["import { isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport {\n assertIsStrictHexString,\n type CaipAccountAddress,\n type CaipAccountId,\n type CaipNamespace,\n type CaipReference,\n type Hex,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { KnownWalletScopeString } from '../scope/constants';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopeString, InternalScopesObject } from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n *\n * Checks if a scope string is either an EIP155 or wallet namespaced scope string.\n *\n * @param scopeString - The scope string to check.\n * @returns True if the scope string is an EIP155 or wallet namespaced scope string, false otherwise.\n */\nconst isEip155ScopeString = (scopeString: InternalScopeString) => {\n const { namespace } = parseScopeString(scopeString);\n\n return (\n namespace === KnownCaipNamespace.Eip155 ||\n scopeString === KnownWalletScopeString.Eip155\n );\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum accounts.\n * @returns An array of Ethereum accounts.\n */\nconst getEthAccountsFromScopes = (scopes: InternalScopesObject) => {\n const ethAccounts: Hex[] = [];\n\n Object.entries(scopes).forEach(([_, { accounts }]) => {\n accounts?.forEach((account) => {\n const { address, chainId } = parseCaipAccountId(account);\n\n if (isEip155ScopeString(chainId)) {\n // This address should always be a valid Hex string because\n // it's an EIP155/Ethereum account\n assertIsStrictHexString(address);\n ethAccounts.push(address);\n }\n });\n });\n\n return ethAccounts;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to get the Ethereum accounts from.\n * @returns An array of Ethereum accounts.\n */\nexport const getEthAccounts = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n): Hex[] => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethAccounts: Hex[] = [\n ...getEthAccountsFromScopes(requiredScopes),\n ...getEthAccountsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethAccounts);\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given scopes object.\n *\n * @param scopesObject - The scopes object to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated scopes object with the Ethereum accounts set.\n */\nconst setEthAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: Hex[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const isWalletNamespace = scopeString === KnownCaipNamespace.Wallet;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!isEip155ScopeString(scopeString) && !isWalletNamespace) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.map<CaipAccountId>(\n (account) => `${namespace}:${reference}:${account}`,\n );\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: caipAccounts,\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given CAIP-25 caveat value.\n * We set the same accounts for all the scopes that are EIP155 or Wallet namespaced because\n * we do not provide UI/UX flows for selecting different accounts across different chains.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated CAIP-25 caveat value with the Ethereum accounts set.\n */\nexport const setEthAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: Hex[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/*\n *\n *\n * GENERALIZED GETTERS AND SETTERS\n *\n *\n */\n\n/**\n *\n * Getters\n *\n */\n\n/**\n * Gets all accounts from an array of scopes objects\n * This extracts all account IDs from both required and optional scopes\n * and returns a unique set.\n *\n * @param scopesObjects - The scopes objects to extract accounts from\n * @returns Array of unique account IDs\n */\nexport function getCaipAccountIdsFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): CaipAccountId[] {\n const allAccounts = new Set<CaipAccountId>();\n\n for (const scopeObject of scopesObjects) {\n for (const { accounts } of Object.values(scopeObject)) {\n for (const account of accounts) {\n allAccounts.add(account);\n }\n }\n }\n\n return Array.from(allAccounts);\n}\n\n/**\n * Gets all permitted accounts from a CAIP-25 caveat\n * This extracts all account IDs from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract accounts from\n * @returns Array of unique account IDs\n */\nexport function getCaipAccountIdsFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipAccountId[] {\n return getCaipAccountIdsFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]);\n}\n\n/**\n *\n * Setters\n *\n */\n\n/**\n * Sets the CAIP account IDs to scopes with matching namespaces in the given scopes object.\n * This function should not be used with Smart Contract Accounts (SCA) because\n * it adds the same account ID to all the scopes that have the same namespace.\n *\n * @param scopesObject - The scopes object to set the CAIP account IDs for.\n * @param accounts - The CAIP account IDs to add to the appropriate scopes.\n * @returns The updated scopes object with the CAIP account IDs set.\n */\nconst setNonSCACaipAccountIdsInScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: CaipAccountId[],\n) => {\n const accountsByNamespace = new Map<string, Set<string>>();\n\n for (const account of accounts) {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(account);\n\n if (!accountsByNamespace.has(namespace)) {\n accountsByNamespace.set(namespace, new Set());\n }\n\n accountsByNamespace.get(namespace)?.add(address);\n }\n\n const updatedScopesObject: InternalScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopesObject)) {\n const { namespace, reference } = parseScopeString(scopeString);\n\n let caipAccounts: CaipAccountId[] = [];\n\n if (namespace && reference && accountsByNamespace.has(namespace)) {\n const addressSet = accountsByNamespace.get(namespace);\n if (addressSet) {\n caipAccounts = Array.from(addressSet).map(\n (address) => `${namespace}:${reference}:${address}` as const,\n );\n }\n }\n\n updatedScopesObject[scopeString as keyof typeof scopesObject] = {\n ...scopeObject,\n accounts: getUniqueArrayItems(caipAccounts),\n };\n }\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted accounts to scopes with matching namespaces in the given CAIP-25 caveat value.\n * This function should not be used with Smart Contract Accounts (SCA) because\n * it adds the same account ID to all scopes that have the same namespace as the account.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated CAIP-25 caveat value with the permitted accounts set.\n */\nexport const setNonSCACaipAccountIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: CaipAccountId[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setNonSCACaipAccountIdsInScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setNonSCACaipAccountIdsInScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/**\n * Checks if an address and list of parsed scopes are connected to any of\n * the permitted accounts based on scope matching\n *\n * @param address - The CAIP account address to check against permitted accounts\n * @param parsedAccountScopes - The list of parsed CAIP chain ID to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the address and any account scope is connected to any permitted account\n */\nfunction isAddressWithParsedScopesInPermittedAccountIds(\n address: CaipAccountAddress,\n parsedAccountScopes: {\n namespace?: CaipNamespace;\n reference?: CaipReference;\n }[],\n permittedAccounts: CaipAccountId[],\n) {\n if (!address || !parsedAccountScopes.length || !permittedAccounts.length) {\n return false;\n }\n\n return permittedAccounts.some((account) => {\n const parsedPermittedAccount = parseCaipAccountId(account);\n\n return parsedAccountScopes.some(({ namespace, reference }) => {\n if (\n namespace !== parsedPermittedAccount.chain.namespace &&\n parsedPermittedAccount.chain.namespace !== KnownCaipNamespace.Wallet\n ) {\n return false;\n }\n\n // handle wallet:<namespace>:<address> case where namespaces are mismatched but addresses match\n // i.e. wallet:notSolana:12389812309123 and solana:0:12389812309123\n if (\n parsedPermittedAccount.chain.namespace === KnownCaipNamespace.Wallet &&\n namespace !== parsedPermittedAccount.chain.reference\n ) {\n return false;\n }\n\n // handle eip155:0 case and insensitive evm address comparison\n if (namespace === KnownCaipNamespace.Eip155) {\n return (\n (reference === '0' ||\n reference === parsedPermittedAccount.chain.reference) &&\n isEqualCaseInsensitive(address, parsedPermittedAccount.address)\n );\n }\n\n // handle wallet:<namespace>:<address> case\n if (\n parsedPermittedAccount.chain.namespace === KnownCaipNamespace.Wallet\n ) {\n return address === parsedPermittedAccount.address;\n }\n\n return (\n reference === parsedPermittedAccount.chain.reference &&\n address === parsedPermittedAccount.address\n );\n });\n });\n}\n\n/**\n * Checks if an internal account is connected to any of the permitted accounts\n * based on scope matching\n *\n * @param internalAccount - The internal account to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the account is connected to any permitted account\n */\nexport function isInternalAccountInPermittedAccountIds(\n internalAccount: InternalAccount,\n permittedAccounts: CaipAccountId[],\n): boolean {\n // temporary fix for the issue where the internal account has no scopes and or scopes is undefined\n // TODO: remove this once the bug is fixed (tracked here: https://github.com/MetaMask/accounts-planning/issues/941)\n // there is currently a bug where an account associated with a snap can fail to add scopes to the internal account in time\n // before we attempt to access this state\n if (!internalAccount?.scopes?.length) {\n return false;\n }\n\n const parsedInteralAccountScopes = internalAccount.scopes.map((scope) => {\n return parseScopeString(scope);\n });\n\n return isAddressWithParsedScopesInPermittedAccountIds(\n internalAccount.address,\n parsedInteralAccountScopes,\n permittedAccounts,\n );\n}\n\n/**\n * Checks if an CAIP account ID is connected to any of the permitted accounts\n * based on scope matching\n *\n * @param accountId - The CAIP account ID to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the account is connected to any permitted account\n */\nexport function isCaipAccountIdInPermittedAccountIds(\n accountId: CaipAccountId,\n permittedAccounts: CaipAccountId[],\n): boolean {\n const { address, chain } = parseCaipAccountId(accountId);\n\n return isAddressWithParsedScopesInPermittedAccountIds(\n address,\n [chain],\n permittedAccounts,\n );\n}\n"]}
1
+ {"version":3,"file":"caip-permission-operator-accounts.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,mCAAmC;AAEpE,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AAUzB,OAAO,EAAE,sBAAsB,EAAE,+BAA2B;AAC5D,OAAO,EAAE,mBAAmB,EAAE,+BAA2B;AAEzD,OAAO,EAAE,gBAAgB,EAAE,2BAAuB;AAElD;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,CAAC,WAAgC,EAAE,EAAE;IAC/D,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAEpD,OAAO,CACL,SAAS,KAAK,kBAAkB,CAAC,MAAM;QACvC,WAAW,KAAK,sBAAsB,CAAC,MAAM,CAC9C,CA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,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACtE,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,OAAO,8CAA8C,CACnD,eAAe,CAAC,OAAO,EACvB,0BAA0B,EAC1B,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oCAAoC,CAClD,SAAwB,EACxB,iBAAkC;IAElC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAEzD,OAAO,8CAA8C,CACnD,OAAO,EACP,CAAC,KAAK,CAAC,EACP,iBAAiB,CAClB,CAAC;AACJ,CAAC","sourcesContent":["import { isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport {\n assertIsStrictHexString,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type {\n CaipAccountAddress,\n CaipAccountId,\n CaipNamespace,\n CaipReference,\n Hex,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { KnownWalletScopeString } from '../scope/constants';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopeString, InternalScopesObject } from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n *\n * Checks if a scope string is either an EIP155 or wallet namespaced scope string.\n *\n * @param scopeString - The scope string to check.\n * @returns True if the scope string is an EIP155 or wallet namespaced scope string, false otherwise.\n */\nconst isEip155ScopeString = (scopeString: InternalScopeString) => {\n const { namespace } = parseScopeString(scopeString);\n\n return (\n namespace === KnownCaipNamespace.Eip155 ||\n scopeString === KnownWalletScopeString.Eip155\n );\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum accounts.\n * @returns An array of Ethereum accounts.\n */\nconst getEthAccountsFromScopes = (scopes: InternalScopesObject) => {\n const ethAccounts: Hex[] = [];\n\n Object.entries(scopes).forEach(([_, { accounts }]) => {\n accounts?.forEach((account) => {\n const { address, chainId } = parseCaipAccountId(account);\n\n if (isEip155ScopeString(chainId)) {\n // This address should always be a valid Hex string because\n // it's an EIP155/Ethereum account\n assertIsStrictHexString(address);\n ethAccounts.push(address);\n }\n });\n });\n\n return ethAccounts;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to get the Ethereum accounts from.\n * @returns An array of Ethereum accounts.\n */\nexport const getEthAccounts = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n): Hex[] => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethAccounts: Hex[] = [\n ...getEthAccountsFromScopes(requiredScopes),\n ...getEthAccountsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethAccounts);\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given scopes object.\n *\n * @param scopesObject - The scopes object to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated scopes object with the Ethereum accounts set.\n */\nconst setEthAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: Hex[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const isWalletNamespace = scopeString === KnownCaipNamespace.Wallet;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!isEip155ScopeString(scopeString) && !isWalletNamespace) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.map<CaipAccountId>(\n (account) => `${namespace}:${reference}:${account}`,\n );\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: caipAccounts,\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given CAIP-25 caveat value.\n * We set the same accounts for all the scopes that are EIP155 or Wallet namespaced because\n * we do not provide UI/UX flows for selecting different accounts across different chains.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated CAIP-25 caveat value with the Ethereum accounts set.\n */\nexport const setEthAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: Hex[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/*\n *\n *\n * GENERALIZED GETTERS AND SETTERS\n *\n *\n */\n\n/**\n *\n * Getters\n *\n */\n\n/**\n * Gets all accounts from an array of scopes objects\n * This extracts all account IDs from both required and optional scopes\n * and returns a unique set.\n *\n * @param scopesObjects - The scopes objects to extract accounts from\n * @returns Array of unique account IDs\n */\nexport function getCaipAccountIdsFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): CaipAccountId[] {\n const allAccounts = new Set<CaipAccountId>();\n\n for (const scopeObject of scopesObjects) {\n for (const { accounts } of Object.values(scopeObject)) {\n for (const account of accounts) {\n allAccounts.add(account);\n }\n }\n }\n\n return Array.from(allAccounts);\n}\n\n/**\n * Gets all permitted accounts from a CAIP-25 caveat\n * This extracts all account IDs from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract accounts from\n * @returns Array of unique account IDs\n */\nexport function getCaipAccountIdsFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipAccountId[] {\n return getCaipAccountIdsFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]);\n}\n\n/**\n *\n * Setters\n *\n */\n\n/**\n * Sets the CAIP account IDs to scopes with matching namespaces in the given scopes object.\n * This function should not be used with Smart Contract Accounts (SCA) because\n * it adds the same account ID to all the scopes that have the same namespace.\n *\n * @param scopesObject - The scopes object to set the CAIP account IDs for.\n * @param accounts - The CAIP account IDs to add to the appropriate scopes.\n * @returns The updated scopes object with the CAIP account IDs set.\n */\nconst setNonSCACaipAccountIdsInScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: CaipAccountId[],\n) => {\n const accountsByNamespace = new Map<string, Set<string>>();\n\n for (const account of accounts) {\n const {\n chain: { namespace },\n address,\n } = parseCaipAccountId(account);\n\n if (!accountsByNamespace.has(namespace)) {\n accountsByNamespace.set(namespace, new Set());\n }\n\n accountsByNamespace.get(namespace)?.add(address);\n }\n\n const updatedScopesObject: InternalScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopesObject)) {\n const { namespace, reference } = parseScopeString(scopeString);\n\n let caipAccounts: CaipAccountId[] = [];\n\n if (namespace && reference && accountsByNamespace.has(namespace)) {\n const addressSet = accountsByNamespace.get(namespace);\n if (addressSet) {\n caipAccounts = Array.from(addressSet).map(\n (address) => `${namespace}:${reference}:${address}` as const,\n );\n }\n }\n\n updatedScopesObject[scopeString as keyof typeof scopesObject] = {\n ...scopeObject,\n accounts: getUniqueArrayItems(caipAccounts),\n };\n }\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted accounts to scopes with matching namespaces in the given CAIP-25 caveat value.\n * This function should not be used with Smart Contract Accounts (SCA) because\n * it adds the same account ID to all scopes that have the same namespace as the account.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated CAIP-25 caveat value with the permitted accounts set.\n */\nexport const setNonSCACaipAccountIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: CaipAccountId[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setNonSCACaipAccountIdsInScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setNonSCACaipAccountIdsInScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/**\n * Checks if an address and list of parsed scopes are connected to any of\n * the permitted accounts based on scope matching\n *\n * @param address - The CAIP account address to check against permitted accounts\n * @param parsedAccountScopes - The list of parsed CAIP chain ID to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the address and any account scope is connected to any permitted account\n */\nfunction isAddressWithParsedScopesInPermittedAccountIds(\n address: CaipAccountAddress,\n parsedAccountScopes: {\n namespace?: CaipNamespace;\n reference?: CaipReference;\n }[],\n permittedAccounts: CaipAccountId[],\n) {\n if (!address || !parsedAccountScopes.length || !permittedAccounts.length) {\n return false;\n }\n\n return permittedAccounts.some((account) => {\n const parsedPermittedAccount = parseCaipAccountId(account);\n\n return parsedAccountScopes.some(({ namespace, reference }) => {\n if (\n namespace !== parsedPermittedAccount.chain.namespace &&\n parsedPermittedAccount.chain.namespace !== KnownCaipNamespace.Wallet\n ) {\n return false;\n }\n\n // handle wallet:<namespace>:<address> case where namespaces are mismatched but addresses match\n // i.e. wallet:notSolana:12389812309123 and solana:0:12389812309123\n if (\n parsedPermittedAccount.chain.namespace === KnownCaipNamespace.Wallet &&\n namespace !== parsedPermittedAccount.chain.reference\n ) {\n return false;\n }\n\n // handle eip155:0 case and insensitive evm address comparison\n if (namespace === KnownCaipNamespace.Eip155) {\n return (\n (reference === '0' ||\n reference === parsedPermittedAccount.chain.reference) &&\n isEqualCaseInsensitive(address, parsedPermittedAccount.address)\n );\n }\n\n // handle wallet:<namespace>:<address> case\n if (\n parsedPermittedAccount.chain.namespace === KnownCaipNamespace.Wallet\n ) {\n return address === parsedPermittedAccount.address;\n }\n\n return (\n reference === parsedPermittedAccount.chain.reference &&\n address === parsedPermittedAccount.address\n );\n });\n });\n}\n\n/**\n * Checks if an internal account is connected to any of the permitted accounts\n * based on scope matching\n *\n * @param internalAccount - The internal account to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the account is connected to any permitted account\n */\nexport function isInternalAccountInPermittedAccountIds(\n internalAccount: InternalAccount,\n permittedAccounts: CaipAccountId[],\n): boolean {\n // temporary fix for the issue where the internal account has no scopes and or scopes is undefined\n // TODO: remove this once the bug is fixed (tracked here: https://github.com/MetaMask/accounts-planning/issues/941)\n // there is currently a bug where an account associated with a snap can fail to add scopes to the internal account in time\n // before we attempt to access this state\n if (!internalAccount?.scopes?.length) {\n return false;\n }\n\n const parsedInteralAccountScopes = internalAccount.scopes.map((scope) => {\n return parseScopeString(scope);\n });\n\n return isAddressWithParsedScopesInPermittedAccountIds(\n internalAccount.address,\n parsedInteralAccountScopes,\n permittedAccounts,\n );\n}\n\n/**\n * Checks if an CAIP account ID is connected to any of the permitted accounts\n * based on scope matching\n *\n * @param accountId - The CAIP account ID to check against permitted accounts\n * @param permittedAccounts - Array of CAIP account IDs that are permitted\n * @returns True if the account is connected to any permitted account\n */\nexport function isCaipAccountIdInPermittedAccountIds(\n accountId: CaipAccountId,\n permittedAccounts: CaipAccountId[],\n): boolean {\n const { address, chain } = parseCaipAccountId(accountId);\n\n return isAddressWithParsedScopesInPermittedAccountIds(\n address,\n [chain],\n permittedAccounts,\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-permittedChains.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AAEnD,2CAAkE;AAElE,8DAA+E;AAC/E,sDAAyD;AAEzD,8CAAiE;AAEjE;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,iCAAiC,GAAG,CAAC,MAA4B,EAAE,EAAE;IACzE,MAAM,WAAW,GAA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Namespace } from '@metamask/utils';\nimport { hexToBigInt, KnownCaipNamespace } from '@metamask/utils';\n\nimport { Caip25CaveatType, type Caip25CaveatValue } from '../caip25Permission';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopesObject, InternalScopeString } from '../scope/types';\nimport { isWalletScope, parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nconst getPermittedEthChainIdsFromScopes = (scopes: InternalScopesObject) => {\n const ethChainIds: Hex[] = [];\n\n Object.keys(scopes).forEach((scopeString) => {\n const { namespace, reference } = parseScopeString(scopeString);\n if (namespace === KnownCaipNamespace.Eip155 && reference) {\n ethChainIds.push(toHex(reference));\n }\n });\n\n return ethChainIds;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nexport const getPermittedEthChainIds = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n) => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethChainIds: Hex[] = [\n ...getPermittedEthChainIdsFromScopes(requiredScopes),\n ...getPermittedEthChainIdsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethChainIds);\n};\n\n/**\n * Adds an Ethereum (EIP155 namespaced) chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.\n * @param chainId - The Ethereum chainID to add.\n * @returns The updated CAIP-25 caveat value with the added Ethereum chainID.\n */\nexport const addPermittedEthChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: Hex,\n): Caip25CaveatValue => {\n const scopeString = `eip155:${hexToBigInt(chainId).toString(10)}`;\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(scopeString) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(scopeString)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [scopeString]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - EIP155 scopes for the given chainIDs\n * - Non EIP155 scopes (e.g. \"bip122:\" or any other non ethereum namespaces)\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The chainIDs to filter EIP155 scopes by.\n * @returns The filtered scopes object.\n */\nconst filterEthScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: Hex[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!reference) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n if (namespace === KnownCaipNamespace.Eip155) {\n const chainId = toHex(reference);\n if (chainIds.includes(chainId)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n } else {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.\n * @param chainIds - The Ethereum chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.\n */\nexport const setPermittedEthChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: Hex[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedEthChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\n};\n\n/*\n *\n *\n * GENERALIZED GETTERS AND SETTERS\n *\n *\n */\n\n/*\n *\n * GETTERS\n *\n */\n\n/**\n * Gets all scopes from a CAIP-25 caveat value\n *\n * @param scopesObjects - The scopes objects to get the scopes from.\n * @returns An array of InternalScopeStrings.\n */\nexport function getAllScopesFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): InternalScopeString[] {\n const scopeSet = new Set<InternalScopeString>();\n\n for (const scopeObject of scopesObjects) {\n for (const key of Object.keys(scopeObject)) {\n scopeSet.add(key as InternalScopeString);\n }\n }\n\n return Array.from(scopeSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 caveat\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract scopes from\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipChainId[] {\n return getAllScopesFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]) as CaipChainId[];\n}\n\n/**\n * Gets all non-wallet namespaces from a CAIP-25 caveat value\n * This extracts all namespaces from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract namespaces from\n * @returns Array of unique namespace strings\n */\nexport function getAllNamespacesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipNamespace[] {\n const allScopes = getAllScopesFromCaip25CaveatValue(caip25CaveatValue);\n const namespaceSet = new Set<CaipNamespace>();\n\n for (const scope of allScopes) {\n const { namespace, reference } = parseScopeString(scope);\n if (namespace === KnownCaipNamespace.Wallet) {\n namespaceSet.add(reference ?? namespace);\n } else if (namespace) {\n namespaceSet.add(namespace);\n }\n }\n\n return Array.from(namespaceSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 permission\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25Permission - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromPermission(caip25Permission: {\n caveats: {\n type: string;\n value: Caip25CaveatValue;\n }[];\n}): CaipChainId[] {\n const caip25Caveat = caip25Permission.caveats.find(\n (caveat) => caveat.type === Caip25CaveatType,\n );\n if (!caip25Caveat) {\n return [];\n }\n\n return getAllScopesFromCaip25CaveatValue(caip25Caveat.value);\n}\n\n/*\n *\n * SETTERS\n *\n */\n\n/**\n * Adds a chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.\n * @param chainId - The chainID to add.\n * @returns The updated CAIP-25 caveat value with the added chainID.\n */\nexport const addCaipChainIdInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: CaipChainId,\n): Caip25CaveatValue => {\n if (\n caip25CaveatValue.requiredScopes[chainId] ||\n caip25CaveatValue.optionalScopes[chainId]\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [chainId]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Sets the CAIP-2 chainIds for the required and optional scopes.\n * If the caip25CaveatValue contains chainIds not in the chainIds array arg they are filtered out\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.\n * @param chainIds - The CAIP-2 chainIDs to set.\n * @returns The updated CAIP-25 caveat value with the CAIP-2 chainIDs.\n */\nexport const setChainIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: CaipChainId[],\n): Caip25CaveatValue => {\n const chainIdSet = new Set(chainIds);\n const result: Caip25CaveatValue = {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: caip25CaveatValue.sessionProperties,\n isMultichainOrigin: caip25CaveatValue.isMultichainOrigin,\n };\n\n for (const [key, value] of Object.entries(caip25CaveatValue.requiredScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.requiredScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.requiredScopes[scopeString] = value;\n }\n }\n\n for (const [key, value] of Object.entries(caip25CaveatValue.optionalScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.optionalScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.optionalScopes[scopeString] = value;\n }\n }\n\n for (const chainId of chainIds) {\n if (!result.requiredScopes[chainId] && !result.optionalScopes[chainId]) {\n result.optionalScopes[chainId] = { accounts: [] };\n }\n }\n\n return result;\n};\n"]}
1
+ {"version":3,"file":"caip-permission-operator-permittedChains.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AAEnD,2CAAkE;AAElE,8DAAuD;AAEvD,sDAAyD;AAEzD,8CAAiE;AAEjE;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,iCAAiC,GAAG,CAAC,MAA4B,EAAE,EAAE;IACzE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YACzD,WAAW,CAAC,IAAI,CAAC,IAA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,GAAG,GAAoD,CAAC;QACzE,IAAI,IAAA,qBAAa,EAAC,WAAW,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,EAAE,CAAC;QAC5E,MAAM,WAAW,GAAG,GAAoD,CAAC;QACzE,IAAI,IAAA,qBAAa,EAAC,WAAW,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YACvE,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAjCW,QAAA,8BAA8B,kCAiCzC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex, CaipChainId, CaipNamespace } from '@metamask/utils';\nimport { hexToBigInt, KnownCaipNamespace } from '@metamask/utils';\n\nimport { Caip25CaveatType } from '../caip25Permission';\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopesObject, InternalScopeString } from '../scope/types';\nimport { isWalletScope, parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nconst getPermittedEthChainIdsFromScopes = (scopes: InternalScopesObject) => {\n const ethChainIds: Hex[] = [];\n\n Object.keys(scopes).forEach((scopeString) => {\n const { namespace, reference } = parseScopeString(scopeString);\n if (namespace === KnownCaipNamespace.Eip155 && reference) {\n ethChainIds.push(toHex(reference));\n }\n });\n\n return ethChainIds;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nexport const getPermittedEthChainIds = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n) => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethChainIds: Hex[] = [\n ...getPermittedEthChainIdsFromScopes(requiredScopes),\n ...getPermittedEthChainIdsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethChainIds);\n};\n\n/**\n * Adds an Ethereum (EIP155 namespaced) chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.\n * @param chainId - The Ethereum chainID to add.\n * @returns The updated CAIP-25 caveat value with the added Ethereum chainID.\n */\nexport const addPermittedEthChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: Hex,\n): Caip25CaveatValue => {\n const scopeString = `eip155:${hexToBigInt(chainId).toString(10)}`;\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(scopeString) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(scopeString)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [scopeString]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - EIP155 scopes for the given chainIDs\n * - Non EIP155 scopes (e.g. \"bip122:\" or any other non ethereum namespaces)\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The chainIDs to filter EIP155 scopes by.\n * @returns The filtered scopes object.\n */\nconst filterEthScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: Hex[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!reference) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n if (namespace === KnownCaipNamespace.Eip155) {\n const chainId = toHex(reference);\n if (chainIds.includes(chainId)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n } else {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.\n * @param chainIds - The Ethereum chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.\n */\nexport const setPermittedEthChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: Hex[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedEthChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\n};\n\n/*\n *\n *\n * GENERALIZED GETTERS AND SETTERS\n *\n *\n */\n\n/*\n *\n * GETTERS\n *\n */\n\n/**\n * Gets all scopes from a CAIP-25 caveat value\n *\n * @param scopesObjects - The scopes objects to get the scopes from.\n * @returns An array of InternalScopeStrings.\n */\nexport function getAllScopesFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): InternalScopeString[] {\n const scopeSet = new Set<InternalScopeString>();\n\n for (const scopeObject of scopesObjects) {\n for (const key of Object.keys(scopeObject)) {\n scopeSet.add(key as InternalScopeString);\n }\n }\n\n return Array.from(scopeSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 caveat\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract scopes from\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipChainId[] {\n return getAllScopesFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]) as CaipChainId[];\n}\n\n/**\n * Gets all non-wallet namespaces from a CAIP-25 caveat value\n * This extracts all namespaces from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract namespaces from\n * @returns Array of unique namespace strings\n */\nexport function getAllNamespacesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipNamespace[] {\n const allScopes = getAllScopesFromCaip25CaveatValue(caip25CaveatValue);\n const namespaceSet = new Set<CaipNamespace>();\n\n for (const scope of allScopes) {\n const { namespace, reference } = parseScopeString(scope);\n if (namespace === KnownCaipNamespace.Wallet) {\n namespaceSet.add(reference ?? namespace);\n } else if (namespace) {\n namespaceSet.add(namespace);\n }\n }\n\n return Array.from(namespaceSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 permission\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25Permission - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromPermission(caip25Permission: {\n caveats: {\n type: string;\n value: Caip25CaveatValue;\n }[];\n}): CaipChainId[] {\n const caip25Caveat = caip25Permission.caveats.find(\n (caveat) => caveat.type === Caip25CaveatType,\n );\n if (!caip25Caveat) {\n return [];\n }\n\n return getAllScopesFromCaip25CaveatValue(caip25Caveat.value);\n}\n\n/*\n *\n * SETTERS\n *\n */\n\n/**\n * Adds a chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.\n * @param chainId - The chainID to add.\n * @returns The updated CAIP-25 caveat value with the added chainID.\n */\nexport const addCaipChainIdInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: CaipChainId,\n): Caip25CaveatValue => {\n if (\n caip25CaveatValue.requiredScopes[chainId] ||\n caip25CaveatValue.optionalScopes[chainId]\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [chainId]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Sets the CAIP-2 chainIds for the required and optional scopes.\n * If the caip25CaveatValue contains chainIds not in the chainIds array arg they are filtered out\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.\n * @param chainIds - The CAIP-2 chainIDs to set.\n * @returns The updated CAIP-25 caveat value with the CAIP-2 chainIDs.\n */\nexport const setChainIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: CaipChainId[],\n): Caip25CaveatValue => {\n const chainIdSet = new Set(chainIds);\n const result: Caip25CaveatValue = {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: caip25CaveatValue.sessionProperties,\n isMultichainOrigin: caip25CaveatValue.isMultichainOrigin,\n };\n\n for (const [key, value] of Object.entries(caip25CaveatValue.requiredScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.requiredScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.requiredScopes[scopeString] = value;\n }\n }\n\n for (const [key, value] of Object.entries(caip25CaveatValue.optionalScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.optionalScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.optionalScopes[scopeString] = value;\n }\n }\n\n for (const chainId of chainIds) {\n if (!result.requiredScopes[chainId] && !result.optionalScopes[chainId]) {\n result.optionalScopes[chainId] = { accounts: [] };\n }\n }\n\n return result;\n};\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { Hex, CaipChainId, CaipNamespace } from "@metamask/utils";
2
- import { type Caip25CaveatValue } from "../caip25Permission.cjs";
2
+ import type { Caip25CaveatValue } from "../caip25Permission.cjs";
3
3
  import type { InternalScopesObject, InternalScopeString } from "../scope/types.cjs";
4
4
  /**
5
5
  * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-permittedChains.d.cts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AAGvE,OAAO,EAAoB,KAAK,iBAAiB,EAAE,gCAA4B;AAE/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,2BAAuB;AA8BhF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,oBAAoB,EAAE,GACpC,mBAAmB,EAAE,CAUvB;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,iBAAiB,EAAE,iBAAiB,GACnC,WAAW,EAAE,CAKf;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACnD,iBAAiB,EAAE,iBAAiB,GACnC,aAAa,EAAE,CAcjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE;IAC3D,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,iBAAiB,CAAC;KAC1B,EAAE,CAAC;CACL,GAAG,WAAW,EAAE,CAShB;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,sBACzB,iBAAiB,WAC3B,WAAW,KACnB,iBAiBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,sBACtB,iBAAiB,YAC1B,WAAW,EAAE,KACtB,iBA8BF,CAAC"}
1
+ {"version":3,"file":"caip-permission-operator-permittedChains.d.cts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAE7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,2BAAuB;AA8BhF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,oBAAoB,EAAE,GACpC,mBAAmB,EAAE,CAUvB;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,iBAAiB,EAAE,iBAAiB,GACnC,WAAW,EAAE,CAKf;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACnD,iBAAiB,EAAE,iBAAiB,GACnC,aAAa,EAAE,CAcjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE;IAC3D,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,iBAAiB,CAAC;KAC1B,EAAE,CAAC;CACL,GAAG,WAAW,EAAE,CAShB;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,sBACzB,iBAAiB,WAC3B,WAAW,KACnB,iBAiBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,sBACtB,iBAAiB,YAC1B,WAAW,EAAE,KACtB,iBA8BF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { Hex, CaipChainId, CaipNamespace } from "@metamask/utils";
2
- import { type Caip25CaveatValue } from "../caip25Permission.mjs";
2
+ import type { Caip25CaveatValue } from "../caip25Permission.mjs";
3
3
  import type { InternalScopesObject, InternalScopeString } from "../scope/types.mjs";
4
4
  /**
5
5
  * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-permittedChains.d.mts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AAGvE,OAAO,EAAoB,KAAK,iBAAiB,EAAE,gCAA4B;AAE/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,2BAAuB;AA8BhF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,oBAAoB,EAAE,GACpC,mBAAmB,EAAE,CAUvB;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,iBAAiB,EAAE,iBAAiB,GACnC,WAAW,EAAE,CAKf;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACnD,iBAAiB,EAAE,iBAAiB,GACnC,aAAa,EAAE,CAcjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE;IAC3D,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,iBAAiB,CAAC;KAC1B,EAAE,CAAC;CACL,GAAG,WAAW,EAAE,CAShB;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,sBACzB,iBAAiB,WAC3B,WAAW,KACnB,iBAiBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,sBACtB,iBAAiB,YAC1B,WAAW,EAAE,KACtB,iBA8BF,CAAC"}
1
+ {"version":3,"file":"caip-permission-operator-permittedChains.d.mts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAE7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,2BAAuB;AA8BhF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;AAgBF;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,oBAAoB,EAAE,GACpC,mBAAmB,EAAE,CAUvB;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,iBAAiB,EAAE,iBAAiB,GACnC,WAAW,EAAE,CAKf;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACnD,iBAAiB,EAAE,iBAAiB,GACnC,aAAa,EAAE,CAcjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE;IAC3D,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,iBAAiB,CAAC;KAC1B,EAAE,CAAC;CACL,GAAG,WAAW,EAAE,CAShB;AAQD;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,sBACzB,iBAAiB,WAC3B,WAAW,KACnB,iBAiBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,sBACtB,iBAAiB,YAC1B,WAAW,EAAE,KACtB,iBA8BF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-permittedChains.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAEnD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,wBAAwB;AAElE,OAAO,EAAE,gBAAgB,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-utils';\nimport type { Hex, CaipChainId, CaipNamespace } from '@metamask/utils';\nimport { hexToBigInt, KnownCaipNamespace } from '@metamask/utils';\n\nimport { Caip25CaveatType, type Caip25CaveatValue } from '../caip25Permission';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopesObject, InternalScopeString } from '../scope/types';\nimport { isWalletScope, parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nconst getPermittedEthChainIdsFromScopes = (scopes: InternalScopesObject) => {\n const ethChainIds: Hex[] = [];\n\n Object.keys(scopes).forEach((scopeString) => {\n const { namespace, reference } = parseScopeString(scopeString);\n if (namespace === KnownCaipNamespace.Eip155 && reference) {\n ethChainIds.push(toHex(reference));\n }\n });\n\n return ethChainIds;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nexport const getPermittedEthChainIds = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n) => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethChainIds: Hex[] = [\n ...getPermittedEthChainIdsFromScopes(requiredScopes),\n ...getPermittedEthChainIdsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethChainIds);\n};\n\n/**\n * Adds an Ethereum (EIP155 namespaced) chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.\n * @param chainId - The Ethereum chainID to add.\n * @returns The updated CAIP-25 caveat value with the added Ethereum chainID.\n */\nexport const addPermittedEthChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: Hex,\n): Caip25CaveatValue => {\n const scopeString = `eip155:${hexToBigInt(chainId).toString(10)}`;\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(scopeString) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(scopeString)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [scopeString]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - EIP155 scopes for the given chainIDs\n * - Non EIP155 scopes (e.g. \"bip122:\" or any other non ethereum namespaces)\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The chainIDs to filter EIP155 scopes by.\n * @returns The filtered scopes object.\n */\nconst filterEthScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: Hex[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!reference) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n if (namespace === KnownCaipNamespace.Eip155) {\n const chainId = toHex(reference);\n if (chainIds.includes(chainId)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n } else {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.\n * @param chainIds - The Ethereum chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.\n */\nexport const setPermittedEthChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: Hex[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedEthChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\n};\n\n/*\n *\n *\n * GENERALIZED GETTERS AND SETTERS\n *\n *\n */\n\n/*\n *\n * GETTERS\n *\n */\n\n/**\n * Gets all scopes from a CAIP-25 caveat value\n *\n * @param scopesObjects - The scopes objects to get the scopes from.\n * @returns An array of InternalScopeStrings.\n */\nexport function getAllScopesFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): InternalScopeString[] {\n const scopeSet = new Set<InternalScopeString>();\n\n for (const scopeObject of scopesObjects) {\n for (const key of Object.keys(scopeObject)) {\n scopeSet.add(key as InternalScopeString);\n }\n }\n\n return Array.from(scopeSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 caveat\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract scopes from\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipChainId[] {\n return getAllScopesFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]) as CaipChainId[];\n}\n\n/**\n * Gets all non-wallet namespaces from a CAIP-25 caveat value\n * This extracts all namespaces from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract namespaces from\n * @returns Array of unique namespace strings\n */\nexport function getAllNamespacesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipNamespace[] {\n const allScopes = getAllScopesFromCaip25CaveatValue(caip25CaveatValue);\n const namespaceSet = new Set<CaipNamespace>();\n\n for (const scope of allScopes) {\n const { namespace, reference } = parseScopeString(scope);\n if (namespace === KnownCaipNamespace.Wallet) {\n namespaceSet.add(reference ?? namespace);\n } else if (namespace) {\n namespaceSet.add(namespace);\n }\n }\n\n return Array.from(namespaceSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 permission\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25Permission - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromPermission(caip25Permission: {\n caveats: {\n type: string;\n value: Caip25CaveatValue;\n }[];\n}): CaipChainId[] {\n const caip25Caveat = caip25Permission.caveats.find(\n (caveat) => caveat.type === Caip25CaveatType,\n );\n if (!caip25Caveat) {\n return [];\n }\n\n return getAllScopesFromCaip25CaveatValue(caip25Caveat.value);\n}\n\n/*\n *\n * SETTERS\n *\n */\n\n/**\n * Adds a chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.\n * @param chainId - The chainID to add.\n * @returns The updated CAIP-25 caveat value with the added chainID.\n */\nexport const addCaipChainIdInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: CaipChainId,\n): Caip25CaveatValue => {\n if (\n caip25CaveatValue.requiredScopes[chainId] ||\n caip25CaveatValue.optionalScopes[chainId]\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [chainId]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Sets the CAIP-2 chainIds for the required and optional scopes.\n * If the caip25CaveatValue contains chainIds not in the chainIds array arg they are filtered out\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.\n * @param chainIds - The CAIP-2 chainIDs to set.\n * @returns The updated CAIP-25 caveat value with the CAIP-2 chainIDs.\n */\nexport const setChainIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: CaipChainId[],\n): Caip25CaveatValue => {\n const chainIdSet = new Set(chainIds);\n const result: Caip25CaveatValue = {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: caip25CaveatValue.sessionProperties,\n isMultichainOrigin: caip25CaveatValue.isMultichainOrigin,\n };\n\n for (const [key, value] of Object.entries(caip25CaveatValue.requiredScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.requiredScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.requiredScopes[scopeString] = value;\n }\n }\n\n for (const [key, value] of Object.entries(caip25CaveatValue.optionalScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.optionalScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.optionalScopes[scopeString] = value;\n }\n }\n\n for (const chainId of chainIds) {\n if (!result.requiredScopes[chainId] && !result.optionalScopes[chainId]) {\n result.optionalScopes[chainId] = { accounts: [] };\n }\n }\n\n return result;\n};\n"]}
1
+ {"version":3,"file":"caip-permission-operator-permittedChains.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-permittedChains.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAEnD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,wBAAwB;AAElE,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD,OAAO,EAAE,mBAAmB,EAAE,+BAA2B;AAEzD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,2BAAuB;AAEjE;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,iCAAiC,GAAG,CAAC,MAA4B,EAAE,EAAE;IACzE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QAC1C,MAA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AAC,EAAE,CAAC;QAC5E,MAAM,WAAW,GAAG,GAAoD,CAAC;QACzE,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,EAAE,CAAC;QAC5E,MAAM,WAAW,GAAG,GAAoD,CAAC;QACzE,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YACvE,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex, CaipChainId, CaipNamespace } from '@metamask/utils';\nimport { hexToBigInt, KnownCaipNamespace } from '@metamask/utils';\n\nimport { Caip25CaveatType } from '../caip25Permission';\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopesObject, InternalScopeString } from '../scope/types';\nimport { isWalletScope, parseScopeString } from '../scope/types';\n\n/*\n *\n *\n * EVM SPECIFIC GETTERS AND SETTERS\n *\n *\n */\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nconst getPermittedEthChainIdsFromScopes = (scopes: InternalScopesObject) => {\n const ethChainIds: Hex[] = [];\n\n Object.keys(scopes).forEach((scopeString) => {\n const { namespace, reference } = parseScopeString(scopeString);\n if (namespace === KnownCaipNamespace.Eip155 && reference) {\n ethChainIds.push(toHex(reference));\n }\n });\n\n return ethChainIds;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nexport const getPermittedEthChainIds = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n) => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethChainIds: Hex[] = [\n ...getPermittedEthChainIdsFromScopes(requiredScopes),\n ...getPermittedEthChainIdsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethChainIds);\n};\n\n/**\n * Adds an Ethereum (EIP155 namespaced) chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.\n * @param chainId - The Ethereum chainID to add.\n * @returns The updated CAIP-25 caveat value with the added Ethereum chainID.\n */\nexport const addPermittedEthChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: Hex,\n): Caip25CaveatValue => {\n const scopeString = `eip155:${hexToBigInt(chainId).toString(10)}`;\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(scopeString) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(scopeString)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [scopeString]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - EIP155 scopes for the given chainIDs\n * - Non EIP155 scopes (e.g. \"bip122:\" or any other non ethereum namespaces)\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The chainIDs to filter EIP155 scopes by.\n * @returns The filtered scopes object.\n */\nconst filterEthScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: Hex[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!reference) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n if (namespace === KnownCaipNamespace.Eip155) {\n const chainId = toHex(reference);\n if (chainIds.includes(chainId)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n } else {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.\n * @param chainIds - The Ethereum chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.\n */\nexport const setPermittedEthChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: Hex[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedEthChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\n};\n\n/*\n *\n *\n * GENERALIZED GETTERS AND SETTERS\n *\n *\n */\n\n/*\n *\n * GETTERS\n *\n */\n\n/**\n * Gets all scopes from a CAIP-25 caveat value\n *\n * @param scopesObjects - The scopes objects to get the scopes from.\n * @returns An array of InternalScopeStrings.\n */\nexport function getAllScopesFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): InternalScopeString[] {\n const scopeSet = new Set<InternalScopeString>();\n\n for (const scopeObject of scopesObjects) {\n for (const key of Object.keys(scopeObject)) {\n scopeSet.add(key as InternalScopeString);\n }\n }\n\n return Array.from(scopeSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 caveat\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract scopes from\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipChainId[] {\n return getAllScopesFromScopesObjects([\n caip25CaveatValue.requiredScopes,\n caip25CaveatValue.optionalScopes,\n ]) as CaipChainId[];\n}\n\n/**\n * Gets all non-wallet namespaces from a CAIP-25 caveat value\n * This extracts all namespaces from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to extract namespaces from\n * @returns Array of unique namespace strings\n */\nexport function getAllNamespacesFromCaip25CaveatValue(\n caip25CaveatValue: Caip25CaveatValue,\n): CaipNamespace[] {\n const allScopes = getAllScopesFromCaip25CaveatValue(caip25CaveatValue);\n const namespaceSet = new Set<CaipNamespace>();\n\n for (const scope of allScopes) {\n const { namespace, reference } = parseScopeString(scope);\n if (namespace === KnownCaipNamespace.Wallet) {\n namespaceSet.add(reference ?? namespace);\n } else if (namespace) {\n namespaceSet.add(namespace);\n }\n }\n\n return Array.from(namespaceSet);\n}\n\n/**\n * Gets all scopes (chain IDs) from a CAIP-25 permission\n * This extracts all scopes from both required and optional scopes\n * and returns a unique set.\n *\n * @param caip25Permission - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns Array of unique scope strings (chain IDs)\n */\nexport function getAllScopesFromPermission(caip25Permission: {\n caveats: {\n type: string;\n value: Caip25CaveatValue;\n }[];\n}): CaipChainId[] {\n const caip25Caveat = caip25Permission.caveats.find(\n (caveat) => caveat.type === Caip25CaveatType,\n );\n if (!caip25Caveat) {\n return [];\n }\n\n return getAllScopesFromCaip25CaveatValue(caip25Caveat.value);\n}\n\n/*\n *\n * SETTERS\n *\n */\n\n/**\n * Adds a chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.\n * @param chainId - The chainID to add.\n * @returns The updated CAIP-25 caveat value with the added chainID.\n */\nexport const addCaipChainIdInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: CaipChainId,\n): Caip25CaveatValue => {\n if (\n caip25CaveatValue.requiredScopes[chainId] ||\n caip25CaveatValue.optionalScopes[chainId]\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [chainId]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Sets the CAIP-2 chainIds for the required and optional scopes.\n * If the caip25CaveatValue contains chainIds not in the chainIds array arg they are filtered out\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.\n * @param chainIds - The CAIP-2 chainIDs to set.\n * @returns The updated CAIP-25 caveat value with the CAIP-2 chainIDs.\n */\nexport const setChainIdsInCaip25CaveatValue = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: CaipChainId[],\n): Caip25CaveatValue => {\n const chainIdSet = new Set(chainIds);\n const result: Caip25CaveatValue = {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: caip25CaveatValue.sessionProperties,\n isMultichainOrigin: caip25CaveatValue.isMultichainOrigin,\n };\n\n for (const [key, value] of Object.entries(caip25CaveatValue.requiredScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.requiredScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.requiredScopes[scopeString] = value;\n }\n }\n\n for (const [key, value] of Object.entries(caip25CaveatValue.optionalScopes)) {\n const scopeString = key as keyof typeof caip25CaveatValue.optionalScopes;\n if (isWalletScope(scopeString) || chainIdSet.has(scopeString)) {\n result.optionalScopes[scopeString] = value;\n }\n }\n\n for (const chainId of chainIds) {\n if (!result.requiredScopes[chainId] && !result.optionalScopes[chainId]) {\n result.optionalScopes[chainId] = { accounts: [] };\n }\n }\n\n return result;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-session-scopes.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":";;;AAAA,2CAKyB;AAGzB,sDAK4B;AAC5B,sDAA2D;AAK3D,8CAAkD;AAElD;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,sBAA8C,EAC9C,EAAE;IACF,MAAM,cAAc,GAAyB,EAAE,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAC5C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAmD,CAAC;QAExE,cAAc,CAAC,WAAW,CAAC,GAAG;YAC5B,QAAQ;SACT,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAhBW,QAAA,uBAAuB,2BAgBlC;AAEF;;;;;;;GAOG;AACH,MAAM,yBAAyB,GAAG,CAChC,oBAA0C,EAC1C,EACE,yBAAyB,GAG1B,EACD,EAAE;IACF,MAAM,gBAAgB,GAA2B,EAAE,CAAC;IAEpD,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAC1C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,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,EACF,yBAAyB,CAAC,iBAAiB,CAAC,cAAc,EAAE;QAC1D,yBAAyB;KAC1B,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,gBAAgB,oBAmB3B;AAEF;;;;;;GAMG;AACI,MAAM,6BAA6B,GAAG,CAC3C,iBAGC,EACD,MAAqB,EACJ,EAAE;IACnB,MAAM,aAAa,GAAoB,EAAE,CAAC;IAE1C,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;AACrC,CAAC,CAAC;AArBW,QAAA,6BAA6B,iCAqBxC","sourcesContent":["import {\n type CaipAccountId,\n type CaipChainId,\n isCaipChainId,\n KnownCaipNamespace,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n\n/**\n * Get the permitted accounts for the given scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for\n * @param scopes - The scopes to get the permitted accounts for\n * @returns An array of permitted accounts\n */\nexport const getPermittedAccountsForScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n scopes: CaipChainId[],\n): CaipAccountId[] => {\n const scopeAccounts: CaipAccountId[] = [];\n\n scopes.forEach((scope) => {\n const requiredScope = caip25CaveatValue.requiredScopes[scope];\n const optionalScope = caip25CaveatValue.optionalScopes[scope];\n if (requiredScope) {\n scopeAccounts.push(...requiredScope.accounts);\n }\n\n if (optionalScope) {\n scopeAccounts.push(...optionalScope.accounts);\n }\n });\n return [...new Set(scopeAccounts)];\n};\n"]}
1
+ {"version":3,"file":"caip-permission-operator-session-scopes.cjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":";;;AAAA,2CAAoE;AAIpE,sDAK4B;AAC5B,sDAA2D;AAK3D,8CAAkD;AAElD;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,sBAA8C,EAC9C,EAAE;IACF,MAAM,cAAc,GAAyB,EAAE,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAC5C,CAAC,CAAC,YAAY,EAAE,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,CAAC,CAAC;AACrC,CAAC,CAAC;AArBW,QAAA,6BAA6B,iCAqBxC","sourcesContent":["import { isCaipChainId, KnownCaipNamespace } from '@metamask/utils';\nimport type { CaipAccountId, CaipChainId } from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n\n/**\n * Get the permitted accounts for the given scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for\n * @param scopes - The scopes to get the permitted accounts for\n * @returns An array of permitted accounts\n */\nexport const getPermittedAccountsForScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n scopes: CaipChainId[],\n): CaipAccountId[] => {\n const scopeAccounts: CaipAccountId[] = [];\n\n scopes.forEach((scope) => {\n const requiredScope = caip25CaveatValue.requiredScopes[scope];\n const optionalScope = caip25CaveatValue.optionalScopes[scope];\n if (requiredScope) {\n scopeAccounts.push(...requiredScope.accounts);\n }\n\n if (optionalScope) {\n scopeAccounts.push(...optionalScope.accounts);\n }\n });\n return [...new Set(scopeAccounts)];\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { type CaipAccountId, type CaipChainId } from "@metamask/utils";
1
+ import type { CaipAccountId, CaipChainId } from "@metamask/utils";
2
2
  import type { Caip25CaveatValue } from "../caip25Permission.cjs";
3
3
  import type { InternalScopesObject, NormalizedScopesObject } from "../scope/types.cjs";
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-session-scopes.d.cts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAGjB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,sBACrB,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,UACO,WAAW,EAAE,KACpB,aAAa,EAef,CAAC"}
1
+ {"version":3,"file":"caip-permission-operator-session-scopes.d.cts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,wBAAwB;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,sBACrB,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,UACO,WAAW,EAAE,KACpB,aAAa,EAef,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type CaipAccountId, type CaipChainId } from "@metamask/utils";
1
+ import type { CaipAccountId, CaipChainId } from "@metamask/utils";
2
2
  import type { Caip25CaveatValue } from "../caip25Permission.mjs";
3
3
  import type { InternalScopesObject, NormalizedScopesObject } from "../scope/types.mjs";
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-session-scopes.d.mts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAGjB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,sBACrB,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,UACO,WAAW,EAAE,KACpB,aAAa,EAef,CAAC"}
1
+ {"version":3,"file":"caip-permission-operator-session-scopes.d.mts","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,wBAAwB;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,sBACrB,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,UACO,WAAW,EAAE,KACpB,aAAa,EAef,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-operator-session-scopes.mjs","sourceRoot":"","sources":["../../src/operators/caip-permission-operator-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACb,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,8BAA8B,EAC9B,qBAAqB,EACtB,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,+BAA2B;AAK3D,OAAO,EAAE,gBAAgB,EAAE,2BAAuB;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,sBAA8C,EAC9C,EAAE;IACF,MAAM,cAAc,GAAyB,EAAE,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAC5C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAA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25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n\n/**\n * Get the permitted accounts for the given scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for\n * @param scopes - The scopes to get the permitted accounts for\n * @returns An array of permitted accounts\n */\nexport const getPermittedAccountsForScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n scopes: CaipChainId[],\n): CaipAccountId[] => {\n const scopeAccounts: CaipAccountId[] = [];\n\n scopes.forEach((scope) => {\n const requiredScope = caip25CaveatValue.requiredScopes[scope];\n const optionalScope = caip25CaveatValue.optionalScopes[scope];\n if (requiredScope) {\n scopeAccounts.push(...requiredScope.accounts);\n }\n\n if (optionalScope) {\n scopeAccounts.push(...optionalScope.accounts);\n }\n });\n return [...new Set(scopeAccounts)];\n};\n"]}
1
+ {"version":3,"file":"caip-permission-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AAE,EAAE;QACvB,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;AACrC,CAAC,CAAC","sourcesContent":["import { isCaipChainId, KnownCaipNamespace } from '@metamask/utils';\nimport type { CaipAccountId, CaipChainId } from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n\n/**\n * Get the permitted accounts for the given scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for\n * @param scopes - The scopes to get the permitted accounts for\n * @returns An array of permitted accounts\n */\nexport const getPermittedAccountsForScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n scopes: CaipChainId[],\n): CaipAccountId[] => {\n const scopeAccounts: CaipAccountId[] = [];\n\n scopes.forEach((scope) => {\n const requiredScope = caip25CaveatValue.requiredScopes[scope];\n const optionalScope = caip25CaveatValue.optionalScopes[scope];\n if (requiredScope) {\n scopeAccounts.push(...requiredScope.accounts);\n }\n\n if (optionalScope) {\n scopeAccounts.push(...optionalScope.accounts);\n }\n });\n return [...new Set(scopeAccounts)];\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"assert.cjs","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":";;;AAAA,2CASyB;AAEzB,yCAAwC;AACxC,+CAIqB;AAYrB;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAAG,CAClC,WAAmB,EACnB,WAAkC,EAClC,EACE,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAK1B,EACD,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,WAAW,CAAC;IAC/C,IACE,CAAC,IAAA,kCAAsB,EAAC,WAAW,EAAE;QACnC,qBAAqB;QACrB,sBAAsB;KACvB,CAAC,EACF,CAAC;QACD,MAAM,qBAAY,CAAC,gCAAgC,EAAE,CAAC;IACxD,CAAC;IAED,MAAM,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CACnD,IAAA,6BAAiB,EAAC,WAAW,EAAE,MAAM,EAAE,EAAE,yBAAyB,EAAE,CAAC,CACtE,CAAC;IAEF,IAAI,CAAC,mBAAmB,EAAE,CA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KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC5B,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,uBAAe,CAAC,EACpC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,gEAAgE,CACjE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,2BAA2B,CACzC,WAAoB;IAEpB,IACE,OAAO,WAAW,KAAK,QAAQ;QAC/B,4EAA4E;QAC5E,iEAAiE;QACjE,CAAC,WAAW,KAAK,0BAAkB,CAAC,MAAM,IAAI,CAAC,IAAA,qBAAa,EAAC,WAAW,CAAC,CAAC,EAC1E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAXD,kEAWC;AAED;;;;GAIG;AACH,SAAgB,4BAA4B,CAC1C,GAAY;IAEZ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7D,2BAA2B,CAAC,WAAW,CAAC,CAAC;QACzC,2BAA2B,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAXD,oEAWC","sourcesContent":["import {\n type CaipChainId,\n hasProperty,\n isCaipAccountId,\n isCaipChainId,\n isCaipNamespace,\n isCaipReference,\n KnownCaipNamespace,\n type Hex,\n} from '@metamask/utils';\n\nimport { Caip25Errors } from './errors';\nimport {\n isSupportedMethod,\n isSupportedNotification,\n isSupportedScopeString,\n} from './supported';\nimport type {\n ExternalScopeObject,\n ExternalScopesObject,\n ExternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Asserts that a scope string and its associated scope object are supported.\n *\n * @param scopeString - The scope string against which to assert support.\n * @param scopeObject - The scope object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopeSupported = (\n scopeString: string,\n scopeObject: NormalizedScopeObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n if (\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n })\n ) {\n throw Caip25Errors.requestedChainsNotSupportedError();\n }\n\n const allMethodsSupported = methods.every((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n if (!allMethodsSupported) {\n throw Caip25Errors.requestedMethodsNotSupportedError();\n }\n\n if (\n notifications &&\n !notifications.every((notification) =>\n isSupportedNotification(scopeString, notification),\n )\n ) {\n throw Caip25Errors.requestedNotificationsNotSupportedError();\n }\n};\n\n/**\n * Asserts that all scope strings and their associated scope objects are supported.\n *\n * @param scopes - The scopes object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopesSupported = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n }\n};\n/**\n * Asserts that an object is a valid ExternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsExternalScopeObject(\n obj: unknown,\n): asserts obj is ExternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopeObject must be an object');\n }\n\n if (hasProperty(obj, 'references')) {\n if (\n !Array.isArray(obj.references) ||\n !obj.references.every(isCaipReference)\n ) {\n throw new Error(\n 'ExternalScopeObject.references must be an array of CaipReference',\n );\n }\n }\n\n if (hasProperty(obj, 'accounts')) {\n if (!Array.isArray(obj.accounts) || !obj.accounts.every(isCaipAccountId)) {\n throw new Error(\n 'ExternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n }\n\n if (hasProperty(obj, 'methods')) {\n if (\n !Array.isArray(obj.methods) ||\n !obj.methods.every((method) => typeof method === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.methods must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'notifications')) {\n if (\n !Array.isArray(obj.notifications) ||\n !obj.notifications.every(\n (notification) => typeof notification === 'string',\n )\n ) {\n throw new Error(\n 'ExternalScopeObject.notifications must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcDocuments')) {\n if (\n !Array.isArray(obj.rpcDocuments) ||\n !obj.rpcDocuments.every((doc) => typeof doc === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcDocuments must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcEndpoints')) {\n if (\n !Array.isArray(obj.rpcEndpoints) ||\n !obj.rpcEndpoints.every((endpoint) => typeof endpoint === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcEndpoints must be an array of strings',\n );\n }\n }\n}\n\n/**\n * Asserts that a scope string is a valid ExternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nfunction assertIsExternalScopeString(\n scopeString: unknown,\n): asserts scopeString is ExternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n (!isCaipNamespace(scopeString) && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid ExternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid ExternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsExternalScopesObject(\n obj: unknown,\n): asserts obj is ExternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsExternalScopeString(scopeString);\n assertIsExternalScopeObject(scopeObject);\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsInternalScopeObject(\n obj: unknown,\n): asserts obj is InternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopeObject must be an object');\n }\n\n if (\n !hasProperty(obj, 'accounts') ||\n !Array.isArray(obj.accounts) ||\n !obj.accounts.every(isCaipAccountId)\n ) {\n throw new Error(\n 'InternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n}\n\n/**\n * Asserts that a scope string is a valid InternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nexport function assertIsInternalScopeString(\n scopeString: unknown,\n): asserts scopeString is InternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n // `InternalScopeString` is defined as either `KnownCaipNamespace.Wallet` or\n // `CaipChainId`, so our conditions intentionally match the type.\n (scopeString !== KnownCaipNamespace.Wallet && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid InternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsInternalScopesObject(\n obj: unknown,\n): asserts obj is InternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsInternalScopeString(scopeString);\n assertIsInternalScopeObject(scopeObject);\n }\n}\n"]}
1
+ {"version":3,"file":"assert.cjs","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":";;;AAAA,2CAOyB;AAGzB,yCAAwC;AACxC,+CAIqB;AAYrB;;;;;;;;;GASG;AACI,MAAM,oBAAoB,GAAG,CAClC,WAAmB,EACnB,WAAkC,EAClC,EACE,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAK1B,EACD,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,WAAW,CAAC;IAC/C,IACE,CAAC,IAAA,kCAAsB,EAAC,WAAW,EAAE;QACnC,qBAAqB;QACrB,sBAAsB;KACvB,CAAC,EACF,CAAC;QACD,MAAM,qBAAY,CAAC,gCAAgC,EAAE,CAAC;IACxD,CAAC;IAED,MAAM,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CACnD,IAAA,6BAAiB,EAAC,WAAW,EAAE,MAAM,EAAE,EAAE,yBAAyB,EAAE,CAAC,CACtE,CAAC;IAEF,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,MAAM,qBAAY,CAAC,iCAAiC,EAAE,CAAC;IACzD,CAAC;IAED,IACE,aAAa;QACb,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE,EAAE,CACpC,IAAA,mCAAuB,EAAC,WAAW,EAAE,YAAY,CAAC,CACnD,EACD,CAAC;QACD,MAAM,qBAAY,CAAC,uCAAuC,EAAE,CAAC;IAC/D,CAAC;AACH,CAAC,CAAC;AAvCW,QAAA,oBAAoB,wBAuC/B;AAEF;;;;;;;;GAQG;AACI,MAAM,qBAAqB,GAA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AAM,IAAI,CAAC,IAAA,qBAAa,EAAC,WAAW,CAAC,CAAC,EAC1E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAXD,kEAWC;AAED;;;;GAIG;AACH,SAAgB,4BAA4B,CAC1C,GAAY;IAEZ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7D,2BAA2B,CAAC,WAAW,CAAC,CAAC;QACzC,2BAA2B,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAXD,oEAWC","sourcesContent":["import {\n hasProperty,\n isCaipAccountId,\n isCaipChainId,\n isCaipNamespace,\n isCaipReference,\n KnownCaipNamespace,\n} from '@metamask/utils';\nimport type { CaipChainId, Hex } from '@metamask/utils';\n\nimport { Caip25Errors } from './errors';\nimport {\n isSupportedMethod,\n isSupportedNotification,\n isSupportedScopeString,\n} from './supported';\nimport type {\n ExternalScopeObject,\n ExternalScopesObject,\n ExternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Asserts that a scope string and its associated scope object are supported.\n *\n * @param scopeString - The scope string against which to assert support.\n * @param scopeObject - The scope object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopeSupported = (\n scopeString: string,\n scopeObject: NormalizedScopeObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n if (\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n })\n ) {\n throw Caip25Errors.requestedChainsNotSupportedError();\n }\n\n const allMethodsSupported = methods.every((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n if (!allMethodsSupported) {\n throw Caip25Errors.requestedMethodsNotSupportedError();\n }\n\n if (\n notifications &&\n !notifications.every((notification) =>\n isSupportedNotification(scopeString, notification),\n )\n ) {\n throw Caip25Errors.requestedNotificationsNotSupportedError();\n }\n};\n\n/**\n * Asserts that all scope strings and their associated scope objects are supported.\n *\n * @param scopes - The scopes object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopesSupported = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n }\n};\n/**\n * Asserts that an object is a valid ExternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsExternalScopeObject(\n obj: unknown,\n): asserts obj is ExternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopeObject must be an object');\n }\n\n if (hasProperty(obj, 'references')) {\n if (\n !Array.isArray(obj.references) ||\n !obj.references.every(isCaipReference)\n ) {\n throw new Error(\n 'ExternalScopeObject.references must be an array of CaipReference',\n );\n }\n }\n\n if (hasProperty(obj, 'accounts')) {\n if (!Array.isArray(obj.accounts) || !obj.accounts.every(isCaipAccountId)) {\n throw new Error(\n 'ExternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n }\n\n if (hasProperty(obj, 'methods')) {\n if (\n !Array.isArray(obj.methods) ||\n !obj.methods.every((method) => typeof method === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.methods must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'notifications')) {\n if (\n !Array.isArray(obj.notifications) ||\n !obj.notifications.every(\n (notification) => typeof notification === 'string',\n )\n ) {\n throw new Error(\n 'ExternalScopeObject.notifications must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcDocuments')) {\n if (\n !Array.isArray(obj.rpcDocuments) ||\n !obj.rpcDocuments.every((doc) => typeof doc === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcDocuments must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcEndpoints')) {\n if (\n !Array.isArray(obj.rpcEndpoints) ||\n !obj.rpcEndpoints.every((endpoint) => typeof endpoint === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcEndpoints must be an array of strings',\n );\n }\n }\n}\n\n/**\n * Asserts that a scope string is a valid ExternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nfunction assertIsExternalScopeString(\n scopeString: unknown,\n): asserts scopeString is ExternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n (!isCaipNamespace(scopeString) && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid ExternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid ExternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsExternalScopesObject(\n obj: unknown,\n): asserts obj is ExternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsExternalScopeString(scopeString);\n assertIsExternalScopeObject(scopeObject);\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsInternalScopeObject(\n obj: unknown,\n): asserts obj is InternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopeObject must be an object');\n }\n\n if (\n !hasProperty(obj, 'accounts') ||\n !Array.isArray(obj.accounts) ||\n !obj.accounts.every(isCaipAccountId)\n ) {\n throw new Error(\n 'InternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n}\n\n/**\n * Asserts that a scope string is a valid InternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nexport function assertIsInternalScopeString(\n scopeString: unknown,\n): asserts scopeString is InternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n // `InternalScopeString` is defined as either `KnownCaipNamespace.Wallet` or\n // `CaipChainId`, so our conditions intentionally match the type.\n (scopeString !== KnownCaipNamespace.Wallet && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid InternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsInternalScopesObject(\n obj: unknown,\n): asserts obj is InternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsInternalScopeString(scopeString);\n assertIsInternalScopeObject(scopeObject);\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { type CaipChainId, type Hex } from "@metamask/utils";
1
+ import type { CaipChainId, Hex } from "@metamask/utils";
2
2
  import type { ExternalScopesObject, InternalScopesObject, InternalScopeString, NormalizedScopeObject, NormalizedScopesObject } from "./types.cjs";
3
3
  /**
4
4
  * Asserts that a scope string and its associated scope object are supported.
@@ -1 +1 @@
1
- {"version":3,"file":"assert.d.cts","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAOhB,KAAK,GAAG,EACT,wBAAwB;AAQzB,OAAO,KAAK,EAEV,oBAAoB,EAGpB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,gBAClB,MAAM,eACN,qBAAqB;qCAMC,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UA6B9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,WACxB,sBAAsB;qCAMK,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UAU9D,CAAC;AA+FF;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC;AAyBD;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,WAAW,IAAI,mBAAmB,CAS5C;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC"}
1
+ {"version":3,"file":"assert.d.cts","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAQxD,OAAO,KAAK,EAEV,oBAAoB,EAGpB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,gBAClB,MAAM,eACN,qBAAqB;qCAMC,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UA6B9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,WACxB,sBAAsB;qCAMK,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;UAU9D,CAAC;AA+FF;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC;AAyBD;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,WAAW,IAAI,mBAAmB,CAS5C;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,GACX,OAAO,CAAC,GAAG,IAAI,oBAAoB,CASrC"}
@@ -1,4 +1,4 @@
1
- import { type CaipChainId, type Hex } from "@metamask/utils";
1
+ import type { CaipChainId, Hex } from "@metamask/utils";
2
2
  import type { ExternalScopesObject, InternalScopesObject, InternalScopeString, NormalizedScopeObject, NormalizedScopesObject } from "./types.mjs";
3
3
  /**
4
4
  * Asserts that a scope string and its associated scope object are supported.
@@ -1 +1 @@
1
- {"version":3,"file":"assert.d.mts","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAOhB,KAAK,GAAG,EACT,wBAAwB;AAQzB,OAAO,KAAK,EAEV,oBAAoB,EAGpB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,gBAClB,MAAM,eACN,qBAAqB;qCAMC,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW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AAC,aAAa,CAAC,WAAW,CAAC,CAAC,EAC1E,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAC1C,GAAY;IAEZ,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7D,2BAA2B,CAAC,WAAW,CAAC,CAAC;QACzC,2BAA2B,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC","sourcesContent":["import {\n type CaipChainId,\n hasProperty,\n isCaipAccountId,\n isCaipChainId,\n isCaipNamespace,\n isCaipReference,\n KnownCaipNamespace,\n type Hex,\n} from '@metamask/utils';\n\nimport { Caip25Errors } from './errors';\nimport {\n isSupportedMethod,\n isSupportedNotification,\n isSupportedScopeString,\n} from './supported';\nimport type {\n ExternalScopeObject,\n ExternalScopesObject,\n ExternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Asserts that a scope string and its associated scope object are supported.\n *\n * @param scopeString - The scope string against which to assert support.\n * @param scopeObject - The scope object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopeSupported = (\n scopeString: string,\n scopeObject: NormalizedScopeObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n if (\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n })\n ) {\n throw Caip25Errors.requestedChainsNotSupportedError();\n }\n\n const allMethodsSupported = methods.every((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n if (!allMethodsSupported) {\n throw Caip25Errors.requestedMethodsNotSupportedError();\n }\n\n if (\n notifications &&\n !notifications.every((notification) =>\n isSupportedNotification(scopeString, notification),\n )\n ) {\n throw Caip25Errors.requestedNotificationsNotSupportedError();\n }\n};\n\n/**\n * Asserts that all scope strings and their associated scope objects are supported.\n *\n * @param scopes - The scopes object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopesSupported = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n }\n};\n/**\n * Asserts that an object is a valid ExternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsExternalScopeObject(\n obj: unknown,\n): asserts obj is ExternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopeObject must be an object');\n }\n\n if (hasProperty(obj, 'references')) {\n if (\n !Array.isArray(obj.references) ||\n !obj.references.every(isCaipReference)\n ) {\n throw new Error(\n 'ExternalScopeObject.references must be an array of CaipReference',\n );\n }\n }\n\n if (hasProperty(obj, 'accounts')) {\n if (!Array.isArray(obj.accounts) || !obj.accounts.every(isCaipAccountId)) {\n throw new Error(\n 'ExternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n }\n\n if (hasProperty(obj, 'methods')) {\n if (\n !Array.isArray(obj.methods) ||\n !obj.methods.every((method) => typeof method === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.methods must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'notifications')) {\n if (\n !Array.isArray(obj.notifications) ||\n !obj.notifications.every(\n (notification) => typeof notification === 'string',\n )\n ) {\n throw new Error(\n 'ExternalScopeObject.notifications must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcDocuments')) {\n if (\n !Array.isArray(obj.rpcDocuments) ||\n !obj.rpcDocuments.every((doc) => typeof doc === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcDocuments must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcEndpoints')) {\n if (\n !Array.isArray(obj.rpcEndpoints) ||\n !obj.rpcEndpoints.every((endpoint) => typeof endpoint === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcEndpoints must be an array of strings',\n );\n }\n }\n}\n\n/**\n * Asserts that a scope string is a valid ExternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nfunction assertIsExternalScopeString(\n scopeString: unknown,\n): asserts scopeString is ExternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n (!isCaipNamespace(scopeString) && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid ExternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid ExternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsExternalScopesObject(\n obj: unknown,\n): asserts obj is ExternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsExternalScopeString(scopeString);\n assertIsExternalScopeObject(scopeObject);\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsInternalScopeObject(\n obj: unknown,\n): asserts obj is InternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopeObject must be an object');\n }\n\n if (\n !hasProperty(obj, 'accounts') ||\n !Array.isArray(obj.accounts) ||\n !obj.accounts.every(isCaipAccountId)\n ) {\n throw new Error(\n 'InternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n}\n\n/**\n * Asserts that a scope string is a valid InternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nexport function assertIsInternalScopeString(\n scopeString: unknown,\n): asserts scopeString is InternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n // `InternalScopeString` is defined as either `KnownCaipNamespace.Wallet` or\n // `CaipChainId`, so our conditions intentionally match the type.\n (scopeString !== KnownCaipNamespace.Wallet && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid InternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsInternalScopesObject(\n obj: unknown,\n): asserts obj is InternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsInternalScopeString(scopeString);\n assertIsInternalScopeObject(scopeObject);\n }\n}\n"]}
1
+ {"version":3,"file":"assert.mjs","sourceRoot":"","sources":["../../src/scope/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EAAE,YA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,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7D,2BAA2B,CAAC,WAAW,CAAC,CAAC;QACzC,2BAA2B,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC","sourcesContent":["import {\n hasProperty,\n isCaipAccountId,\n isCaipChainId,\n isCaipNamespace,\n isCaipReference,\n KnownCaipNamespace,\n} from '@metamask/utils';\nimport type { CaipChainId, Hex } from '@metamask/utils';\n\nimport { Caip25Errors } from './errors';\nimport {\n isSupportedMethod,\n isSupportedNotification,\n isSupportedScopeString,\n} from './supported';\nimport type {\n ExternalScopeObject,\n ExternalScopesObject,\n ExternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Asserts that a scope string and its associated scope object are supported.\n *\n * @param scopeString - The scope string against which to assert support.\n * @param scopeObject - The scope object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopeSupported = (\n scopeString: string,\n scopeObject: NormalizedScopeObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n if (\n !isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n })\n ) {\n throw Caip25Errors.requestedChainsNotSupportedError();\n }\n\n const allMethodsSupported = methods.every((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n if (!allMethodsSupported) {\n throw Caip25Errors.requestedMethodsNotSupportedError();\n }\n\n if (\n notifications &&\n !notifications.every((notification) =>\n isSupportedNotification(scopeString, notification),\n )\n ) {\n throw Caip25Errors.requestedNotificationsNotSupportedError();\n }\n};\n\n/**\n * Asserts that all scope strings and their associated scope objects are supported.\n *\n * @param scopes - The scopes object against which to assert support.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n */\nexport const assertScopesSupported = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n }\n};\n/**\n * Asserts that an object is a valid ExternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsExternalScopeObject(\n obj: unknown,\n): asserts obj is ExternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopeObject must be an object');\n }\n\n if (hasProperty(obj, 'references')) {\n if (\n !Array.isArray(obj.references) ||\n !obj.references.every(isCaipReference)\n ) {\n throw new Error(\n 'ExternalScopeObject.references must be an array of CaipReference',\n );\n }\n }\n\n if (hasProperty(obj, 'accounts')) {\n if (!Array.isArray(obj.accounts) || !obj.accounts.every(isCaipAccountId)) {\n throw new Error(\n 'ExternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n }\n\n if (hasProperty(obj, 'methods')) {\n if (\n !Array.isArray(obj.methods) ||\n !obj.methods.every((method) => typeof method === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.methods must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'notifications')) {\n if (\n !Array.isArray(obj.notifications) ||\n !obj.notifications.every(\n (notification) => typeof notification === 'string',\n )\n ) {\n throw new Error(\n 'ExternalScopeObject.notifications must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcDocuments')) {\n if (\n !Array.isArray(obj.rpcDocuments) ||\n !obj.rpcDocuments.every((doc) => typeof doc === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcDocuments must be an array of strings',\n );\n }\n }\n\n if (hasProperty(obj, 'rpcEndpoints')) {\n if (\n !Array.isArray(obj.rpcEndpoints) ||\n !obj.rpcEndpoints.every((endpoint) => typeof endpoint === 'string')\n ) {\n throw new Error(\n 'ExternalScopeObject.rpcEndpoints must be an array of strings',\n );\n }\n }\n}\n\n/**\n * Asserts that a scope string is a valid ExternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nfunction assertIsExternalScopeString(\n scopeString: unknown,\n): asserts scopeString is ExternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n (!isCaipNamespace(scopeString) && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid ExternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid ExternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsExternalScopesObject(\n obj: unknown,\n): asserts obj is ExternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('ExternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsExternalScopeString(scopeString);\n assertIsExternalScopeObject(scopeObject);\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopeObject.\n *\n * @param obj - The object to assert.\n */\nfunction assertIsInternalScopeObject(\n obj: unknown,\n): asserts obj is InternalScopeObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopeObject must be an object');\n }\n\n if (\n !hasProperty(obj, 'accounts') ||\n !Array.isArray(obj.accounts) ||\n !obj.accounts.every(isCaipAccountId)\n ) {\n throw new Error(\n 'InternalScopeObject.accounts must be an array of CaipAccountId',\n );\n }\n}\n\n/**\n * Asserts that a scope string is a valid InternalScopeString.\n *\n * @param scopeString - The scope string to assert.\n */\nexport function assertIsInternalScopeString(\n scopeString: unknown,\n): asserts scopeString is InternalScopeString {\n if (\n typeof scopeString !== 'string' ||\n // `InternalScopeString` is defined as either `KnownCaipNamespace.Wallet` or\n // `CaipChainId`, so our conditions intentionally match the type.\n (scopeString !== KnownCaipNamespace.Wallet && !isCaipChainId(scopeString))\n ) {\n throw new Error('scopeString is not a valid InternalScopeString');\n }\n}\n\n/**\n * Asserts that an object is a valid InternalScopesObject.\n *\n * @param obj - The object to assert.\n */\nexport function assertIsInternalScopesObject(\n obj: unknown,\n): asserts obj is InternalScopesObject {\n if (typeof obj !== 'object' || obj === null) {\n throw new Error('InternalScopesObject must be an object');\n }\n\n for (const [scopeString, scopeObject] of Object.entries(obj)) {\n assertIsInternalScopeString(scopeString);\n assertIsInternalScopeObject(scopeObject);\n }\n}\n"]}
@@ -90,6 +90,7 @@ exports.KnownNotifications = {
90
90
  var KnownSessionProperties;
91
91
  (function (KnownSessionProperties) {
92
92
  KnownSessionProperties["SolanaAccountChangedNotifications"] = "solana_accountChanged_notifications";
93
+ KnownSessionProperties["TronAccountChangedNotifications"] = "tron_accountChanged_notifications";
93
94
  })(KnownSessionProperties || (exports.KnownSessionProperties = KnownSessionProperties = {}));
94
95
  /**
95
96
  * Checks if a given value is a known session property.