@metamask-previews/chain-agnostic-permission 0.3.0-preview-c76a33e4 → 0.3.0-preview-363db98c

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.
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-adapter-accounts.cjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":";;;AACA,2CASyB;AAGzB,sDAA4D;AAC5D,sDAAyD;AAEzD,8CAAkD;AAElD;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,CAAC,WAAgC,EAAE,EAAE;IAC/D,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAEpD,OAAO,CACL,SAAS,KAAK,0BAAkB,CAAC,MAAM;QACvC,sDAAsD;QACtD,wEAAwE;QACxE,WAAW,KAAK,kCAAsB,CAAC,MAAM,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,MAA4B,EAAE,EAAE;IAChE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QACnD,QAAQ,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;YAEzD,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE;gBAChC,2DAA2D;gBAC3D,kCAAkC;gBAClC,IAAA,+BAAuB,EAAC,OAAO,CAAC,CAAC;gBACjC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aAC3B;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,O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;;;;;GAOG;AACH,SAAgB,oCAAoC,CAClD,SAAwB,EACxB,iBAAkC;IAElC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAA,0BAAkB,EAAC,SAAS,CAAC,CAAC;IAEzD,OAAO,8CAA8C,CACnD,OAAO,EACP,CAAC,KAAK,CAAC,EACP,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,oFAWC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\nimport {\n assertIsStrictHexString,\n CaipAccountAddress,\n type CaipAccountId,\n CaipNamespace,\n 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 // We are trying to discern the type of `scopeString`.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\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 as string);\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 CaipAccountId,\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 address !== parsedPermittedAccount.address\n ) {\n return false;\n }\n\n return (\n reference === '0' ||\n reference === parsedPermittedAccount.chain.reference\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 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-adapter-accounts.cjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":";;;AACA,2CASyB;AAGzB,sDAA4D;AAC5D,sDAAyD;AAEzD,8CAAkD;AAElD;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,CAAC,WAAgC,EAAE,EAAE;IAC/D,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAEpD,OAAO,CACL,SAAS,KAAK,0BAAkB,CAAC,MAAM;QACvC,sDAAsD;QACtD,wEAAwE;QACxE,WAAW,KAAK,kCAAsB,CAAC,MAAM,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,MAA4B,EAAE,EAAE;IAChE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QACnD,QAAQ,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;YAEzD,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE;gBAChC,2DAA2D;gBAC3D,kCAAkC;gBAClC,IAAA,+BAAuB,EAAC,OAAO,CAAC,CAAC;gBACjC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aAC3B;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;GAKG;AACI,MAAM,cAAc,GAAG,C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E,OAAO,EAAE,KAAK,EAAE,GAAG,IAAA,0BAAkB,EAAC,SAAS,CAAC,CAAC;IAEzD,OAAO,8CAA8C,CACnD,OAAO,EACP,CAAC,KAAK,CAAC,EACP,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAXD,oFAWC","sourcesContent":["import 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 // We are trying to discern the type of `scopeString`.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\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 as string);\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 CaipAccountId,\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 address !== parsedPermittedAccount.address\n ) {\n return false;\n }\n\n return (\n reference === '0' ||\n reference === parsedPermittedAccount.chain.reference\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 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,4 +1,4 @@
1
- import { assertIsStrictHexString, CaipAccountAddress, CaipNamespace, CaipReference, KnownCaipNamespace, parseCaipAccountId } from "@metamask/utils";
1
+ import { assertIsStrictHexString, KnownCaipNamespace, parseCaipAccountId } from "@metamask/utils";
2
2
  import { KnownWalletScopeString } from "../scope/constants.mjs";
3
3
  import { getUniqueArrayItems } from "../scope/transform.mjs";
4
4
  import { parseScopeString } from "../scope/types.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-adapter-accounts.mjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAElB,aAAa,EACb,aAAa,EAEb,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,sDAAsD;QACtD,wEAAwE;QACxE,WAAW,KAAK,sBAAsB,CAAC,MAAM,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,MAA4B,EAAE,EAAE;IAChE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QACnD,QAAQ,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,MAAM,EAAE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E,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 type { InternalAccount } from '@metamask/keyring-internal-api';\nimport {\n assertIsStrictHexString,\n CaipAccountAddress,\n type CaipAccountId,\n CaipNamespace,\n 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 // We are trying to discern the type of `scopeString`.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\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 as string);\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 CaipAccountId,\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 address !== parsedPermittedAccount.address\n ) {\n return false;\n }\n\n return (\n reference === '0' ||\n reference === parsedPermittedAccount.chain.reference\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 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-adapter-accounts.mjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":"AACA,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,sDAAsD;QACtD,wEAAwE;QACxE,WAAW,KAAK,sBAAsB,CAAC,MAAM,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,MAA4B,EAAE,EAAE;IAChE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QACnD,QAAQ,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;YAEzD,IAAI,mBAAmB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AAO,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 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 // We are trying to discern the type of `scopeString`.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\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 as string);\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 CaipAccountId,\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 address !== parsedPermittedAccount.address\n ) {\n return false;\n }\n\n return (\n reference === '0' ||\n reference === parsedPermittedAccount.chain.reference\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 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"]}
package/dist/index.cjs CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Caip25Errors = exports.KnownSessionProperties = exports.generateCaip25Caveat = exports.Caip25CaveatMutators = exports.caip25EndowmentBuilder = exports.Caip25EndowmentPermissionName = exports.createCaip25Caveat = exports.Caip25CaveatType = exports.caip25CaveatBuilder = exports.normalizeAndMergeScopes = exports.mergeInternalScopes = exports.mergeNormalizedScopes = exports.mergeScopeObject = exports.normalizeScope = exports.getUniqueArrayItems = exports.parseScopeString = exports.getSupportedScopeObjects = exports.isKnownSessionPropertyValue = exports.KnownWalletScopeString = exports.KnownNotifications = exports.KnownWalletNamespaceRpcMethods = exports.KnownRpcMethods = exports.KnownWalletRpcMethods = exports.assertIsInternalScopeString = exports.isNamespaceInScopesObject = exports.bucketScopes = exports.validateAndNormalizeScopes = exports.getPermittedAccountsForScopes = exports.getSessionScopes = exports.getInternalScopesObject = exports.getAllScopesFromCaip25CaveatValue = exports.getAllScopesFromPermission = exports.getAllNonWalletNamespacesFromCaip25CaveatValue = exports.addCaipChainIdInCaip25CaveatValue = exports.overwriteCaipChainIdsInCaip25CaveatValue = exports.setPermittedEthChainIds = exports.addPermittedEthChainId = exports.getPermittedEthChainIds = exports.isCaipAccountIdInPermittedAccountIds = exports.isInternalAccountInPermittedAccountIds = exports.getCaipAccountIdsFromScopesObjects = exports.setNonSCACaipAccountIdsInCaip25CaveatValue = exports.setEthAccounts = exports.getEthAccounts = void 0;
3
+ exports.Caip25Errors = exports.KnownSessionProperties = exports.getCaip25CaveatFromPermission = exports.generateCaip25Caveat = exports.Caip25CaveatMutators = exports.caip25EndowmentBuilder = exports.Caip25EndowmentPermissionName = exports.createCaip25Caveat = exports.Caip25CaveatType = exports.caip25CaveatBuilder = exports.normalizeAndMergeScopes = exports.mergeInternalScopes = exports.mergeNormalizedScopes = exports.mergeScopeObject = exports.normalizeScope = exports.getUniqueArrayItems = exports.parseScopeString = exports.getSupportedScopeObjects = exports.isKnownSessionPropertyValue = exports.KnownWalletScopeString = exports.KnownNotifications = exports.KnownWalletNamespaceRpcMethods = exports.KnownRpcMethods = exports.KnownWalletRpcMethods = exports.assertIsInternalScopeString = exports.isNamespaceInScopesObject = exports.bucketScopes = exports.validateAndNormalizeScopes = exports.getPermittedAccountsForScopes = exports.getSessionScopes = exports.getInternalScopesObject = exports.getAllScopesFromCaip25CaveatValue = exports.getAllScopesFromPermission = exports.getAllNonWalletNamespacesFromCaip25CaveatValue = exports.addCaipChainIdInCaip25CaveatValue = exports.overwriteCaipChainIdsInCaip25CaveatValue = exports.setPermittedEthChainIds = exports.addPermittedEthChainId = exports.getPermittedEthChainIds = exports.isCaipAccountIdInPermittedAccountIds = exports.isInternalAccountInPermittedAccountIds = exports.getCaipAccountIdsFromCaip25CaveatValue = exports.getCaipAccountIdsFromScopesObjects = exports.setNonSCACaipAccountIdsInCaip25CaveatValue = exports.setEthAccounts = exports.getEthAccounts = void 0;
4
4
  var caip_permission_adapter_accounts_1 = require("./adapters/caip-permission-adapter-accounts.cjs");
5
5
  Object.defineProperty(exports, "getEthAccounts", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.getEthAccounts; } });
6
6
  Object.defineProperty(exports, "setEthAccounts", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.setEthAccounts; } });
7
7
  Object.defineProperty(exports, "setNonSCACaipAccountIdsInCaip25CaveatValue", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.setNonSCACaipAccountIdsInCaip25CaveatValue; } });
8
8
  Object.defineProperty(exports, "getCaipAccountIdsFromScopesObjects", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.getCaipAccountIdsFromScopesObjects; } });
9
+ Object.defineProperty(exports, "getCaipAccountIdsFromCaip25CaveatValue", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.getCaipAccountIdsFromCaip25CaveatValue; } });
9
10
  Object.defineProperty(exports, "isInternalAccountInPermittedAccountIds", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.isInternalAccountInPermittedAccountIds; } });
10
11
  Object.defineProperty(exports, "isCaipAccountIdInPermittedAccountIds", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.isCaipAccountIdInPermittedAccountIds; } });
11
12
  var caip_permission_adapter_permittedChains_1 = require("./adapters/caip-permission-adapter-permittedChains.cjs");
@@ -53,6 +54,7 @@ Object.defineProperty(exports, "Caip25EndowmentPermissionName", { enumerable: tr
53
54
  Object.defineProperty(exports, "caip25EndowmentBuilder", { enumerable: true, get: function () { return caip25Permission_1.caip25EndowmentBuilder; } });
54
55
  Object.defineProperty(exports, "Caip25CaveatMutators", { enumerable: true, get: function () { return caip25Permission_1.Caip25CaveatMutators; } });
55
56
  Object.defineProperty(exports, "generateCaip25Caveat", { enumerable: true, get: function () { return caip25Permission_1.generateCaip25Caveat; } });
57
+ Object.defineProperty(exports, "getCaip25CaveatFromPermission", { enumerable: true, get: function () { return caip25Permission_1.getCaip25CaveatFromPermission; } });
56
58
  var constants_2 = require("./scope/constants.cjs");
57
59
  Object.defineProperty(exports, "KnownSessionProperties", { enumerable: true, get: function () { return constants_2.KnownSessionProperties; } });
58
60
  var errors_1 = require("./scope/errors.cjs");
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oGAOqD;AANnD,kIAAA,cAAc,OAAA;AACd,kIAAA,cAAc,OAAA;AACd,8JAAA,0CAA0C,OAAA;AAC1C,sJAAA,kCAAkC,OAAA;AAClC,0JAAA,sCAAsC,OAAA;AACtC,wJAAA,oCAAoC,OAAA;AAEtC,kHAS4D;AAR1D,kJAAA,uBAAuB,OAAA;AACvB,iJ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CaveatValue,\n getCaipAccountIdsFromScopesObjects,\n isInternalAccountInPermittedAccountIds,\n isCaipAccountIdInPermittedAccountIds,\n} from './adapters/caip-permission-adapter-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n overwriteCaipChainIdsInCaip25CaveatValue,\n addCaipChainIdInCaip25CaveatValue,\n getAllNonWalletNamespacesFromCaip25CaveatValue,\n getAllScopesFromPermission,\n getAllScopesFromCaip25CaveatValue,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n isNamespaceInScopesObject,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n isKnownSessionPropertyValue,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n generateCaip25Caveat,\n} from './caip25Permission';\nexport { KnownSessionProperties } from './scope/constants';\nexport { Caip25Errors } from './scope/errors';\n"]}
1
+ {"version":3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B,oHAAA,gBAAgB,OAAA;AAChB,sHAAA,kBAAkB,OAAA;AAClB,iIAAA,6BAA6B,OAAA;AAC7B,0HAAA,sBAAsB,OAAA;AACtB,wHAAA,oBAAoB,OAAA;AACpB,wHAAA,oBAAoB,OAAA;AACpB,iIAAA,6BAA6B,OAAA;AAE/B,mDAA2D;AAAlD,mHAAA,sBAAsB,OAAA;AAC/B,6CAA8C;AAArC,sGAAA,YAAY,OAAA","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n setNonSCACaipAccountIdsInCaip25CaveatValue,\n getCaipAccountIdsFromScopesObjects,\n getCaipAccountIdsFromCaip25CaveatValue,\n isInternalAccountInPermittedAccountIds,\n isCaipAccountIdInPermittedAccountIds,\n} from './adapters/caip-permission-adapter-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n overwriteCaipChainIdsInCaip25CaveatValue,\n addCaipChainIdInCaip25CaveatValue,\n getAllNonWalletNamespacesFromCaip25CaveatValue,\n getAllScopesFromPermission,\n getAllScopesFromCaip25CaveatValue,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n isNamespaceInScopesObject,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n isKnownSessionPropertyValue,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n generateCaip25Caveat,\n getCaip25CaveatFromPermission,\n} from './caip25Permission';\nexport { KnownSessionProperties } from './scope/constants';\nexport { Caip25Errors } from './scope/errors';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { getEthAccounts, setEthAccounts, setNonSCACaipAccountIdsInCaip25CaveatValue, getCaipAccountIdsFromScopesObjects, isInternalAccountInPermittedAccountIds, isCaipAccountIdInPermittedAccountIds, } from "./adapters/caip-permission-adapter-accounts.cjs";
1
+ export { getEthAccounts, setEthAccounts, setNonSCACaipAccountIdsInCaip25CaveatValue, getCaipAccountIdsFromScopesObjects, getCaipAccountIdsFromCaip25CaveatValue, isInternalAccountInPermittedAccountIds, isCaipAccountIdInPermittedAccountIds, } from "./adapters/caip-permission-adapter-accounts.cjs";
2
2
  export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, overwriteCaipChainIdsInCaip25CaveatValue, addCaipChainIdInCaip25CaveatValue, getAllNonWalletNamespacesFromCaip25CaveatValue, getAllScopesFromPermission, getAllScopesFromCaip25CaveatValue, } from "./adapters/caip-permission-adapter-permittedChains.cjs";
3
3
  export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes, } from "./adapters/caip-permission-adapter-session-scopes.cjs";
4
4
  export type { Caip25Authorization } from "./scope/authorization.cjs";
@@ -10,7 +10,7 @@ export type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject, In
10
10
  export { parseScopeString } from "./scope/types.cjs";
11
11
  export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes, } from "./scope/transform.cjs";
12
12
  export type { Caip25CaveatValue } from "./caip25Permission.cjs";
13
- export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, } from "./caip25Permission.cjs";
13
+ export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, getCaip25CaveatFromPermission, } from "./caip25Permission.cjs";
14
14
  export { KnownSessionProperties } from "./scope/constants.cjs";
15
15
  export { Caip25Errors } from "./scope/errors.cjs";
16
16
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,0CAA0C,EAC1C,kCAAkC,EAClC,sCAAsC,EACtC,oCAAoC,GACrC,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,wCAAwC,EACxC,iCAAiC,EACjC,8CAA8C,EAC9C,0BAA0B,EAC1B,iCAAiC,GAClC,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACZ,yBAAyB,GAC1B,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,EACtB,2BAA2B,GAC5B,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mB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EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,6BAA6B,GAC9B,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { getEthAccounts, setEthAccounts, setNonSCACaipAccountIdsInCaip25CaveatValue, getCaipAccountIdsFromScopesObjects, isInternalAccountInPermittedAccountIds, isCaipAccountIdInPermittedAccountIds, } from "./adapters/caip-permission-adapter-accounts.mjs";
1
+ export { getEthAccounts, setEthAccounts, setNonSCACaipAccountIdsInCaip25CaveatValue, getCaipAccountIdsFromScopesObjects, getCaipAccountIdsFromCaip25CaveatValue, isInternalAccountInPermittedAccountIds, isCaipAccountIdInPermittedAccountIds, } from "./adapters/caip-permission-adapter-accounts.mjs";
2
2
  export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, overwriteCaipChainIdsInCaip25CaveatValue, addCaipChainIdInCaip25CaveatValue, getAllNonWalletNamespacesFromCaip25CaveatValue, getAllScopesFromPermission, getAllScopesFromCaip25CaveatValue, } from "./adapters/caip-permission-adapter-permittedChains.mjs";
3
3
  export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes, } from "./adapters/caip-permission-adapter-session-scopes.mjs";
4
4
  export type { Caip25Authorization } from "./scope/authorization.mjs";
@@ -10,7 +10,7 @@ export type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject, In
10
10
  export { parseScopeString } from "./scope/types.mjs";
11
11
  export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes, } from "./scope/transform.mjs";
12
12
  export type { Caip25CaveatValue } from "./caip25Permission.mjs";
13
- export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, } from "./caip25Permission.mjs";
13
+ export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, getCaip25CaveatFromPermission, } from "./caip25Permission.mjs";
14
14
  export { KnownSessionProperties } from "./scope/constants.mjs";
15
15
  export { Caip25Errors } from "./scope/errors.mjs";
16
16
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,0CAA0C,EAC1C,kCAAkC,EAClC,sCAAsC,EACtC,oCAAoC,GACrC,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,wCAAwC,EACxC,iCAAiC,EACjC,8CAA8C,EAC9C,0BAA0B,EAC1B,iCAAiC,GAClC,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACZ,yBAAyB,GAC1B,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,EACtB,2BAA2B,GAC5B,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,GACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,0CAA0C,EAC1C,kCAAkC,EAClC,sCAAsC,EACtC,sCAAsC,EACtC,oCAAoC,GACrC,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,wCAAwC,EACxC,iCAAiC,EACjC,8CAA8C,EAC9C,0BAA0B,EAC1B,iCAAiC,GAClC,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACZ,yBAAyB,GAC1B,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,EACtB,2BAA2B,GAC5B,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,6BAA6B,GAC9B,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { getEthAccounts, setEthAccounts, setNonSCACaipAccountIdsInCaip25CaveatValue, getCaipAccountIdsFromScopesObjects, isInternalAccountInPermittedAccountIds, isCaipAccountIdInPermittedAccountIds } from "./adapters/caip-permission-adapter-accounts.mjs";
1
+ export { getEthAccounts, setEthAccounts, setNonSCACaipAccountIdsInCaip25CaveatValue, getCaipAccountIdsFromScopesObjects, getCaipAccountIdsFromCaip25CaveatValue, isInternalAccountInPermittedAccountIds, isCaipAccountIdInPermittedAccountIds } from "./adapters/caip-permission-adapter-accounts.mjs";
2
2
  export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, overwriteCaipChainIdsInCaip25CaveatValue, addCaipChainIdInCaip25CaveatValue, getAllNonWalletNamespacesFromCaip25CaveatValue, getAllScopesFromPermission, getAllScopesFromCaip25CaveatValue } from "./adapters/caip-permission-adapter-permittedChains.mjs";
3
3
  export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes } from "./adapters/caip-permission-adapter-session-scopes.mjs";
4
4
  export { validateAndNormalizeScopes, bucketScopes, isNamespaceInScopesObject } from "./scope/authorization.mjs";
@@ -7,7 +7,7 @@ export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods,
7
7
  export { getSupportedScopeObjects } from "./scope/filter.mjs";
8
8
  export { parseScopeString } from "./scope/types.mjs";
9
9
  export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes } from "./scope/transform.mjs";
10
- export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat } from "./caip25Permission.mjs";
10
+ export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, getCaip25CaveatFromPermission } from "./caip25Permission.mjs";
11
11
  export { KnownSessionProperties } from "./scope/constants.mjs";
12
12
  export { Caip25Errors } from "./scope/errors.mjs";
13
13
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,0CAA0C,EAC1C,kCAAkC,EAClC,sCAAsC,EACtC,oCAAoC,EACrC,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,wCAAwC,EACxC,iCAAiC,EACjC,8CAA8C,EAC9C,0BAA0B,EAC1B,iCAAiC,EAClC,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,EAC9B,8DAA0D;AAG3D,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACZ,yBAAyB,EAC1B,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,EACtB,2BAA2B,EAC5B,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAa1D,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACxB,8BAA0B;AAG3B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n setNonSCACaipAccountIdsInCaip25CaveatValue,\n getCaipAccountIdsFromScopesObjects,\n isInternalAccountInPermittedAccountIds,\n isCaipAccountIdInPermittedAccountIds,\n} from './adapters/caip-permission-adapter-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n overwriteCaipChainIdsInCaip25CaveatValue,\n addCaipChainIdInCaip25CaveatValue,\n getAllNonWalletNamespacesFromCaip25CaveatValue,\n getAllScopesFromPermission,\n getAllScopesFromCaip25CaveatValue,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n isNamespaceInScopesObject,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n isKnownSessionPropertyValue,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n generateCaip25Caveat,\n} from './caip25Permission';\nexport { KnownSessionProperties } from './scope/constants';\nexport { Caip25Errors } from './scope/errors';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,0CAA0C,EAC1C,kCAAkC,EAClC,sCAAsC,EACtC,sCAAsC,EACtC,oCAAoC,EACrC,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,wCAAwC,EACxC,iCAAiC,EACjC,8CAA8C,EAC9C,0BAA0B,EAC1B,iCAAiC,EAClC,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,EAC9B,8DAA0D;AAG3D,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACZ,yBAAyB,EAC1B,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,EACtB,2BAA2B,EAC5B,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAa1D,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACxB,8BAA0B;AAG3B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,6BAA6B,EAC9B,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n setNonSCACaipAccountIdsInCaip25CaveatValue,\n getCaipAccountIdsFromScopesObjects,\n getCaipAccountIdsFromCaip25CaveatValue,\n isInternalAccountInPermittedAccountIds,\n isCaipAccountIdInPermittedAccountIds,\n} from './adapters/caip-permission-adapter-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n overwriteCaipChainIdsInCaip25CaveatValue,\n addCaipChainIdInCaip25CaveatValue,\n getAllNonWalletNamespacesFromCaip25CaveatValue,\n getAllScopesFromPermission,\n getAllScopesFromCaip25CaveatValue,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n isNamespaceInScopesObject,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n isKnownSessionPropertyValue,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n generateCaip25Caveat,\n getCaip25CaveatFromPermission,\n} from './caip25Permission';\nexport { KnownSessionProperties } from './scope/constants';\nexport { Caip25Errors } from './scope/errors';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/chain-agnostic-permission",
3
- "version": "0.3.0-preview-c76a33e4",
3
+ "version": "0.3.0-preview-363db98c",
4
4
  "description": "Defines a CAIP-25 based endowment permission and helpers for interfacing with it",
5
5
  "keywords": [
6
6
  "MetaMask",