@metamask-previews/chain-agnostic-permission 0.4.0-preview-4f38c5b → 0.4.0-preview-514219da
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/adapters/caip-permission-adapter-accounts.cjs +143 -26
- package/dist/adapters/caip-permission-adapter-accounts.cjs.map +1 -1
- package/dist/adapters/caip-permission-adapter-accounts.d.cts +46 -1
- package/dist/adapters/caip-permission-adapter-accounts.d.cts.map +1 -1
- package/dist/adapters/caip-permission-adapter-accounts.d.mts +46 -1
- package/dist/adapters/caip-permission-adapter-accounts.d.mts.map +1 -1
- package/dist/adapters/caip-permission-adapter-accounts.mjs +137 -24
- package/dist/adapters/caip-permission-adapter-accounts.mjs.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.cjs +125 -31
- package/dist/adapters/caip-permission-adapter-permittedChains.cjs.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.d.cts +45 -4
- package/dist/adapters/caip-permission-adapter-permittedChains.d.cts.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.d.mts +45 -4
- package/dist/adapters/caip-permission-adapter-permittedChains.d.mts.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.mjs +118 -28
- package/dist/adapters/caip-permission-adapter-permittedChains.mjs.map +1 -1
- package/dist/caip25Permission.cjs +14 -3
- package/dist/caip25Permission.cjs.map +1 -1
- package/dist/caip25Permission.d.cts +16 -0
- package/dist/caip25Permission.d.cts.map +1 -1
- package/dist/caip25Permission.d.mts +16 -0
- package/dist/caip25Permission.d.mts.map +1 -1
- package/dist/caip25Permission.mjs +14 -4
- package/dist/caip25Permission.mjs.map +1 -1
- package/dist/index.cjs +15 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6 -7
- package/dist/index.mjs.map +1 -1
- package/dist/scope/authorization.cjs +16 -1
- package/dist/scope/authorization.cjs.map +1 -1
- package/dist/scope/authorization.d.cts +9 -1
- package/dist/scope/authorization.d.cts.map +1 -1
- package/dist/scope/authorization.d.mts +9 -1
- package/dist/scope/authorization.d.mts.map +1 -1
- package/dist/scope/authorization.mjs +14 -0
- package/dist/scope/authorization.mjs.map +1 -1
- package/dist/scope/constants.cjs +11 -1
- package/dist/scope/constants.cjs.map +1 -1
- package/dist/scope/constants.d.cts +7 -0
- package/dist/scope/constants.d.cts.map +1 -1
- package/dist/scope/constants.d.mts +7 -0
- package/dist/scope/constants.d.mts.map +1 -1
- package/dist/scope/constants.mjs +9 -0
- package/dist/scope/constants.mjs.map +1 -1
- package/dist/scope/filter.cjs +1 -29
- package/dist/scope/filter.cjs.map +1 -1
- package/dist/scope/filter.d.cts +2 -18
- package/dist/scope/filter.d.cts.map +1 -1
- package/dist/scope/filter.d.mts +2 -18
- package/dist/scope/filter.d.mts.map +1 -1
- package/dist/scope/filter.mjs +0 -26
- package/dist/scope/filter.mjs.map +1 -1
- package/dist/scope/validation.cjs +1 -12
- package/dist/scope/validation.cjs.map +1 -1
- package/dist/scope/validation.d.cts +0 -8
- package/dist/scope/validation.d.cts.map +1 -1
- package/dist/scope/validation.d.mts +0 -8
- package/dist/scope/validation.d.mts.map +1 -1
- package/dist/scope/validation.mjs +0 -10
- package/dist/scope/validation.mjs.map +1 -1
- package/package.json +2 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"caip25Permission.mjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AASA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;AAEzC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EAGT,wBAAwB;;;AAGzB,OAAO,EAAE,oBAAoB,EAAE,wDAAoD;AACnF,OAAO,EAAE,oBAAoB,EAAE,+DAA2D;AAC1F,OAA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kB;SAC1B,CAAC;KACH;IAED,OAAO;QACL,SAAS,EAAE,sBAAsB,CAAC,gBAAgB;KACnD,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,iBAAoC,EACpC,gBAAiC,EACjC,QAAuB,EAKvB,EAAE;IACF,MAAM,qBAAqB,GAAG,oBAAoB,CAChD,iBAAiB,EACjB,QAAQ,CACT,CAAC;IAEF,MAAM,uBAAuB,GAAG,oBAAoB,CAClD,qBAAqB,EACrB,gBAAgB,CACjB,CAAC;IAEF,OAAO;QACL,CAAC,6BAA6B,CAAC,EAAE;YAC/B,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,uBAAuB;iBAC/B;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport type { CaipAccountId, CaipChainId, Json } from '@metamask/utils';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n isObject,\n type Hex,\n type NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual } from 'lodash';\n\nimport { setPermittedAccounts } from './adapters/caip-permission-adapter-accounts';\nimport { setPermittedChainIds } from './adapters/caip-permission-adapter-permittedChains';\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport {\n isSupportedAccount,\n isSupportedScopeString,\n isSupportedSessionProperty,\n} from './scope/supported';\nimport { mergeInternalScopes } from './scope/transform';\nimport {\n parseScopeString,\n type ExternalScopeString,\n type InternalScopeObject,\n type InternalScopesObject,\n} from './scope/types';\n\n/**\n * The CAIP-25 permission caveat value.\n * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.\n * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.\n */\nexport type Caip25CaveatValue = {\n requiredScopes: InternalScopesObject;\n optionalScopes: InternalScopesObject;\n sessionProperties: Record<string, Json>;\n isMultichainOrigin: boolean;\n};\n\n/**\n * The name of the CAIP-25 permission caveat.\n */\nexport const Caip25CaveatType = 'authorizedScopes';\n\n/**\n * The target name of the CAIP-25 endowment permission.\n */\nexport const Caip25EndowmentPermissionName = 'endowment:caip25';\n\n/**\n * Creates a CAIP-25 permission caveat.\n *\n * @param value - The CAIP-25 permission caveat value.\n * @returns The CAIP-25 permission caveat (now including the type).\n */\nexport const createCaip25Caveat = (value: Caip25CaveatValue) => {\n return {\n type: Caip25CaveatType,\n value,\n };\n};\n\ntype Caip25EndowmentCaveatSpecificationBuilderOptions = {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;\n listAccounts: () => { type: string; address: Hex }[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n};\n\n/**\n * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.\n *\n * @param originalValue - The existing CAIP-25 permission caveat value.\n * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.\n * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.\n * @returns The difference between original and merged CAIP-25 permission caveat values.\n */\nexport function diffScopesForCaip25CaveatValue(\n originalValue: Caip25CaveatValue,\n mergedValue: Caip25CaveatValue,\n scopeToDiff: 'optionalScopes' | 'requiredScopes',\n): Caip25CaveatValue {\n const diff = cloneDeep(originalValue);\n\n const mergedScopeToDiff = mergedValue[scopeToDiff];\n for (const [scopeString, mergedScopeObject] of Object.entries(\n mergedScopeToDiff,\n )) {\n const internalScopeString = scopeString as keyof typeof mergedScopeToDiff;\n const originalScopeObject = diff[scopeToDiff][internalScopeString];\n\n if (originalScopeObject) {\n const newAccounts = mergedScopeObject.accounts.filter(\n (account) => !originalScopeObject?.accounts.includes(account),\n );\n if (newAccounts.length > 0) {\n diff[scopeToDiff][internalScopeString] = {\n accounts: newAccounts,\n };\n continue;\n }\n delete diff[scopeToDiff][internalScopeString];\n } else {\n diff[scopeToDiff][internalScopeString] = mergedScopeObject;\n }\n }\n\n return diff;\n}\n\n/**\n * Checks if every account in the given scopes object is supported.\n *\n * @param scopesObject - The scopes object to iterate over.\n * @param listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * addresses.\n * @returns True if every account in the scopes object is supported, false otherwise.\n */\nfunction isEveryAccountInScopesObjectSupported(\n scopesObject: InternalScopesObject,\n listAccounts: () => { type: string; address: Hex }[],\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[],\n) {\n return Object.values(scopesObject).every((scopeObject) =>\n scopeObject.accounts.every((account) =>\n isSupportedAccount(account, {\n getEvmInternalAccounts: listAccounts,\n getNonEvmAccountAddresses,\n }),\n ),\n );\n}\n\n/**\n * Helper that returns a `authorizedScopes` CAIP-25 caveat specification\n * that can be passed into the PermissionController constructor.\n *\n * @param options - The specification builder options.\n * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.\n * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.\n * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns The specification for the `caip25` caveat.\n */\nexport const caip25CaveatBuilder = ({\n findNetworkClientIdByChainId,\n listAccounts,\n isNonEvmScopeSupported,\n getNonEvmAccountAddresses,\n}: Caip25EndowmentCaveatSpecificationBuilderOptions): EndowmentCaveatSpecificationConstraint &\n Required<\n Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>\n > => {\n return {\n type: Caip25CaveatType,\n validator: (\n caveat: { type: typeof Caip25CaveatType; value: unknown },\n _origin?: string,\n _target?: string,\n ) => {\n if (\n !caveat.value ||\n !hasProperty(caveat.value, 'requiredScopes') ||\n !hasProperty(caveat.value, 'optionalScopes') ||\n !hasProperty(caveat.value, 'isMultichainOrigin') ||\n !hasProperty(caveat.value, 'sessionProperties') ||\n typeof caveat.value.isMultichainOrigin !== 'boolean' ||\n !isObject(caveat.value.sessionProperties)\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received invalid value for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const { requiredScopes, optionalScopes, sessionProperties } =\n caveat.value;\n\n const allSessionPropertiesSupported = Object.keys(\n sessionProperties,\n ).every((sessionProperty) => isSupportedSessionProperty(sessionProperty));\n\n if (!allSessionPropertiesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received unknown session property(s) for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n if (\n Object.keys(requiredScopes).length === 0 &&\n Object.keys(optionalScopes).length === 0\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received no scopes for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedSessionProperties = {\n ...leftValue.sessionProperties,\n ...rightValue.sessionProperties,\n };\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\n sessionProperties: mergedSessionProperties,\n isMultichainOrigin: leftValue.isMultichainOrigin,\n };\n\n const partialDiff = diffScopesForCaip25CaveatValue(\n leftValue,\n mergedValue,\n 'requiredScopes',\n );\n\n const diff = diffScopesForCaip25CaveatValue(\n partialDiff,\n mergedValue,\n 'optionalScopes',\n );\n\n return [mergedValue, diff];\n },\n };\n};\n\ntype Caip25EndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof Caip25EndowmentPermissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => null;\n validator: PermissionValidatorConstraint;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * Helper that returns a `endowment:caip25` specification that\n * can be passed into the PermissionController constructor.\n *\n * @returns The specification for the `caip25` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n Record<never, never>,\n Caip25EndowmentSpecification\n> = () => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: Caip25EndowmentPermissionName,\n allowedCaveats: [Caip25CaveatType],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => null,\n validator: (permission: PermissionConstraint) => {\n if (\n permission.caveats?.length !== 1 ||\n permission.caveats?.[0]?.type !== Caip25CaveatType\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Invalid caveats. There must be a single caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n },\n };\n};\n\n/**\n * The `caip25` endowment specification builder. Passed to the\n * `PermissionController` for constructing and validating the\n * `endowment:caip25` permission.\n */\nexport const caip25EndowmentBuilder = Object.freeze({\n targetName: Caip25EndowmentPermissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Factories that construct caveat mutator functions that are passed to\n * PermissionController.updatePermissionsByCaveat.\n */\nexport const Caip25CaveatMutators = {\n [Caip25CaveatType]: {\n removeScope,\n removeAccount,\n },\n};\n\n/**\n * Removes the account from the scope object.\n *\n * @param targetAddress - The address to remove from the scope object.\n * @returns A function that removes the account from the scope object.\n */\nfunction removeAccountFilterFn(targetAddress: string) {\n return (account: CaipAccountId) => {\n const parsed = parseCaipAccountId(account);\n return parsed.address !== targetAddress;\n };\n}\n\n/**\n * Removes the account from the scope object.\n *\n * @param scopeObject - The scope object to remove the account from.\n * @param targetAddress - The address to remove from the scope object.\n */\nfunction removeAccountFromScopeObject(\n scopeObject: InternalScopeObject,\n targetAddress: string,\n) {\n if (scopeObject.accounts) {\n scopeObject.accounts = scopeObject.accounts.filter(\n removeAccountFilterFn(targetAddress),\n );\n }\n}\n\n/**\n * Removes the target account from the scope object.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).\n * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.\n * @returns The updated scope object.\n */\nfunction removeAccount(\n caip25CaveatValue: Caip25CaveatValue,\n targetAddress: Hex,\n) {\n const updatedCaveatValue = cloneDeep(caip25CaveatValue);\n\n [\n updatedCaveatValue.requiredScopes,\n updatedCaveatValue.optionalScopes,\n ].forEach((scopes) => {\n Object.entries(scopes).forEach(([, scopeObject]) => {\n removeAccountFromScopeObject(scopeObject, targetAddress);\n });\n });\n\n const noChange = isEqual(updatedCaveatValue, caip25CaveatValue);\n\n if (noChange) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const hasAccounts = [\n ...Object.values(updatedCaveatValue.requiredScopes),\n ...Object.values(updatedCaveatValue.optionalScopes),\n ].some(({ accounts }) => accounts.length > 0);\n\n if (hasAccounts) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Removes the target scope from the value arrays of the given\n * `endowment:caip25` caveat. No-ops if the target scopeString is not in\n * the existing scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.\n * @param targetScopeString - The scope that is being removed.\n * @returns The updated CAIP-25 permission caveat value.\n */\nfunction removeScope(\n caip25CaveatValue: Caip25CaveatValue,\n targetScopeString: ExternalScopeString,\n) {\n const newRequiredScopes = Object.entries(\n caip25CaveatValue.requiredScopes,\n ).filter(([scope]) => scope !== targetScopeString);\n const newOptionalScopes = Object.entries(\n caip25CaveatValue.optionalScopes,\n ).filter(([scope]) => {\n return scope !== targetScopeString;\n });\n\n const requiredScopesRemoved =\n newRequiredScopes.length !==\n Object.keys(caip25CaveatValue.requiredScopes).length;\n const optionalScopesRemoved =\n newOptionalScopes.length !==\n Object.keys(caip25CaveatValue.optionalScopes).length;\n\n if (!requiredScopesRemoved && !optionalScopesRemoved) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const updatedCaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: Object.fromEntries(newRequiredScopes),\n optionalScopes: Object.fromEntries(newOptionalScopes),\n };\n\n const hasNonWalletScopes = [...newRequiredScopes, ...newOptionalScopes].some(\n ([scopeString]) => {\n const { namespace } = parseScopeString(scopeString);\n return namespace !== KnownCaipNamespace.Wallet;\n },\n );\n\n if (hasNonWalletScopes) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Modifies the requested CAIP-25 permissions object after UI confirmation.\n *\n * @param caip25CaveatValue - The requested CAIP-25 caveat value to modify.\n * @param accountAddresses - The list of permitted eth addresses.\n * @param chainIds - The list of permitted eth chainIds.\n * @returns The updated CAIP-25 caveat value with the permitted accounts and chainIds set.\n */\nexport const generateCaip25Caveat = (\n caip25CaveatValue: Caip25CaveatValue,\n accountAddresses: CaipAccountId[],\n chainIds: CaipChainId[],\n): {\n [Caip25EndowmentPermissionName]: {\n caveats: [{ type: string; value: Caip25CaveatValue }];\n };\n} => {\n const caveatValueWithChains = setPermittedChainIds(\n caip25CaveatValue,\n chainIds,\n );\n\n const caveatValueWithAccounts = setPermittedAccounts(\n caveatValueWithChains,\n accountAddresses,\n );\n\n return {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithAccounts,\n },\n ],\n },\n };\n};\n"]}
|
1
|
+
{"version":3,"file":"caip25Permission.mjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AASA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;AAEzC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,QAAQ,EAGT,wBAAwB;;;AAGzB,OAAO,EAAE,0CAA0C,EAAE,wDAAoD;AACzG,OAAO,EAAE,wCAAwC,EAAE,+DAA2D;AAC9G,OAAO,EAAE,4BAA4B,EAAE,2BAAuB;AAC9D,OAAO,EACL,kBAAkB,E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AAC,gBAAgB;KACnD,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,iBAAoC,EACpC,gBAAiC,EACjC,QAAuB,EAKvB,EAAE;IACF,MAAM,qBAAqB,GAAG,wCAAwC,CACpE,iBAAiB,EACjB,QAAQ,CACT,CAAC;IAEF,MAAM,uBAAuB,GAAG,0CAA0C,CACxE,qBAAqB,EACrB,gBAAgB,CACjB,CAAC;IAEF,OAAO;QACL,CAAC,6BAA6B,CAAC,EAAE;YAC/B,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,uBAAuB;iBAC/B;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,gBAK7C;IAMC,OAAO,gBAAgB,EAAE,OAAO,CAAC,IAAI,CACnC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,gBAAgB,CAC7C,CAAC;AACJ,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport type { CaipAccountId, CaipChainId, Json } from '@metamask/utils';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n isObject,\n type Hex,\n type NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual } from 'lodash';\n\nimport { setNonSCACaipAccountIdsInCaip25CaveatValue } from './adapters/caip-permission-adapter-accounts';\nimport { overwriteCaipChainIdsInCaip25CaveatValue } from './adapters/caip-permission-adapter-permittedChains';\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport {\n isSupportedAccount,\n isSupportedScopeString,\n isSupportedSessionProperty,\n} from './scope/supported';\nimport { mergeInternalScopes } from './scope/transform';\nimport {\n parseScopeString,\n type ExternalScopeString,\n type InternalScopeObject,\n type InternalScopesObject,\n} from './scope/types';\n\n/**\n * The CAIP-25 permission caveat value.\n * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.\n * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.\n */\nexport type Caip25CaveatValue = {\n requiredScopes: InternalScopesObject;\n optionalScopes: InternalScopesObject;\n sessionProperties: Record<string, Json>;\n isMultichainOrigin: boolean;\n};\n\n/**\n * The name of the CAIP-25 permission caveat.\n */\nexport const Caip25CaveatType = 'authorizedScopes';\n\n/**\n * The target name of the CAIP-25 endowment permission.\n */\nexport const Caip25EndowmentPermissionName = 'endowment:caip25';\n\n/**\n * Creates a CAIP-25 permission caveat.\n *\n * @param value - The CAIP-25 permission caveat value.\n * @returns The CAIP-25 permission caveat (now including the type).\n */\nexport const createCaip25Caveat = (value: Caip25CaveatValue) => {\n return {\n type: Caip25CaveatType,\n value,\n };\n};\n\ntype Caip25EndowmentCaveatSpecificationBuilderOptions = {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;\n listAccounts: () => { type: string; address: Hex }[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n};\n\n/**\n * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.\n *\n * @param originalValue - The existing CAIP-25 permission caveat value.\n * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.\n * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.\n * @returns The difference between original and merged CAIP-25 permission caveat values.\n */\nexport function diffScopesForCaip25CaveatValue(\n originalValue: Caip25CaveatValue,\n mergedValue: Caip25CaveatValue,\n scopeToDiff: 'optionalScopes' | 'requiredScopes',\n): Caip25CaveatValue {\n const diff = cloneDeep(originalValue);\n\n const mergedScopeToDiff = mergedValue[scopeToDiff];\n for (const [scopeString, mergedScopeObject] of Object.entries(\n mergedScopeToDiff,\n )) {\n const internalScopeString = scopeString as keyof typeof mergedScopeToDiff;\n const originalScopeObject = diff[scopeToDiff][internalScopeString];\n\n if (originalScopeObject) {\n const newAccounts = mergedScopeObject.accounts.filter(\n (account) => !originalScopeObject?.accounts.includes(account),\n );\n if (newAccounts.length > 0) {\n diff[scopeToDiff][internalScopeString] = {\n accounts: newAccounts,\n };\n continue;\n }\n delete diff[scopeToDiff][internalScopeString];\n } else {\n diff[scopeToDiff][internalScopeString] = mergedScopeObject;\n }\n }\n\n return diff;\n}\n\n/**\n * Checks if every account in the given scopes object is supported.\n *\n * @param scopesObject - The scopes object to iterate over.\n * @param listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * addresses.\n * @returns True if every account in the scopes object is supported, false otherwise.\n */\nfunction isEveryAccountInScopesObjectSupported(\n scopesObject: InternalScopesObject,\n listAccounts: () => { type: string; address: Hex }[],\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[],\n) {\n return Object.values(scopesObject).every((scopeObject) =>\n scopeObject.accounts.every((account) =>\n isSupportedAccount(account, {\n getEvmInternalAccounts: listAccounts,\n getNonEvmAccountAddresses,\n }),\n ),\n );\n}\n\n/**\n * Helper that returns a `authorizedScopes` CAIP-25 caveat specification\n * that can be passed into the PermissionController constructor.\n *\n * @param options - The specification builder options.\n * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.\n * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.\n * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns The specification for the `caip25` caveat.\n */\nexport const caip25CaveatBuilder = ({\n findNetworkClientIdByChainId,\n listAccounts,\n isNonEvmScopeSupported,\n getNonEvmAccountAddresses,\n}: Caip25EndowmentCaveatSpecificationBuilderOptions): EndowmentCaveatSpecificationConstraint &\n Required<\n Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>\n > => {\n return {\n type: Caip25CaveatType,\n validator: (\n caveat: { type: typeof Caip25CaveatType; value: unknown },\n _origin?: string,\n _target?: string,\n ) => {\n if (\n !caveat.value ||\n !hasProperty(caveat.value, 'requiredScopes') ||\n !hasProperty(caveat.value, 'optionalScopes') ||\n !hasProperty(caveat.value, 'isMultichainOrigin') ||\n !hasProperty(caveat.value, 'sessionProperties') ||\n typeof caveat.value.isMultichainOrigin !== 'boolean' ||\n !isObject(caveat.value.sessionProperties)\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received invalid value for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const { requiredScopes, optionalScopes, sessionProperties } =\n caveat.value;\n\n const allSessionPropertiesSupported = Object.keys(\n sessionProperties,\n ).every((sessionProperty) => isSupportedSessionProperty(sessionProperty));\n\n if (!allSessionPropertiesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received unknown session property(s) for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n if (\n Object.keys(requiredScopes).length === 0 &&\n Object.keys(optionalScopes).length === 0\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received no scopes for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedSessionProperties = {\n ...leftValue.sessionProperties,\n ...rightValue.sessionProperties,\n };\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\n sessionProperties: mergedSessionProperties,\n isMultichainOrigin: leftValue.isMultichainOrigin,\n };\n\n const partialDiff = diffScopesForCaip25CaveatValue(\n leftValue,\n mergedValue,\n 'requiredScopes',\n );\n\n const diff = diffScopesForCaip25CaveatValue(\n partialDiff,\n mergedValue,\n 'optionalScopes',\n );\n\n return [mergedValue, diff];\n },\n };\n};\n\ntype Caip25EndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof Caip25EndowmentPermissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => null;\n validator: PermissionValidatorConstraint;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * Helper that returns a `endowment:caip25` specification that\n * can be passed into the PermissionController constructor.\n *\n * @returns The specification for the `caip25` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n Record<never, never>,\n Caip25EndowmentSpecification\n> = () => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: Caip25EndowmentPermissionName,\n allowedCaveats: [Caip25CaveatType],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => null,\n validator: (permission: PermissionConstraint) => {\n if (\n permission.caveats?.length !== 1 ||\n permission.caveats?.[0]?.type !== Caip25CaveatType\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Invalid caveats. There must be a single caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n },\n };\n};\n\n/**\n * The `caip25` endowment specification builder. Passed to the\n * `PermissionController` for constructing and validating the\n * `endowment:caip25` permission.\n */\nexport const caip25EndowmentBuilder = Object.freeze({\n targetName: Caip25EndowmentPermissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Factories that construct caveat mutator functions that are passed to\n * PermissionController.updatePermissionsByCaveat.\n */\nexport const Caip25CaveatMutators = {\n [Caip25CaveatType]: {\n removeScope,\n removeAccount,\n },\n};\n\n/**\n * Removes the account from the scope object.\n *\n * @param targetAddress - The address to remove from the scope object.\n * @returns A function that removes the account from the scope object.\n */\nfunction removeAccountFilterFn(targetAddress: string) {\n return (account: CaipAccountId) => {\n const parsed = parseCaipAccountId(account);\n return parsed.address !== targetAddress;\n };\n}\n\n/**\n * Removes the account from the scope object.\n *\n * @param scopeObject - The scope object to remove the account from.\n * @param targetAddress - The address to remove from the scope object.\n */\nfunction removeAccountFromScopeObject(\n scopeObject: InternalScopeObject,\n targetAddress: string,\n) {\n if (scopeObject.accounts) {\n scopeObject.accounts = scopeObject.accounts.filter(\n removeAccountFilterFn(targetAddress),\n );\n }\n}\n\n/**\n * Removes the target account from the scope object.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).\n * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.\n * @returns The updated scope object.\n */\nfunction removeAccount(\n caip25CaveatValue: Caip25CaveatValue,\n targetAddress: Hex,\n) {\n const updatedCaveatValue = cloneDeep(caip25CaveatValue);\n\n [\n updatedCaveatValue.requiredScopes,\n updatedCaveatValue.optionalScopes,\n ].forEach((scopes) => {\n Object.entries(scopes).forEach(([, scopeObject]) => {\n removeAccountFromScopeObject(scopeObject, targetAddress);\n });\n });\n\n const noChange = isEqual(updatedCaveatValue, caip25CaveatValue);\n\n if (noChange) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const hasAccounts = [\n ...Object.values(updatedCaveatValue.requiredScopes),\n ...Object.values(updatedCaveatValue.optionalScopes),\n ].some(({ accounts }) => accounts.length > 0);\n\n if (hasAccounts) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Removes the target scope from the value arrays of the given\n * `endowment:caip25` caveat. No-ops if the target scopeString is not in\n * the existing scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.\n * @param targetScopeString - The scope that is being removed.\n * @returns The updated CAIP-25 permission caveat value.\n */\nfunction removeScope(\n caip25CaveatValue: Caip25CaveatValue,\n targetScopeString: ExternalScopeString,\n) {\n const newRequiredScopes = Object.entries(\n caip25CaveatValue.requiredScopes,\n ).filter(([scope]) => scope !== targetScopeString);\n const newOptionalScopes = Object.entries(\n caip25CaveatValue.optionalScopes,\n ).filter(([scope]) => {\n return scope !== targetScopeString;\n });\n\n const requiredScopesRemoved =\n newRequiredScopes.length !==\n Object.keys(caip25CaveatValue.requiredScopes).length;\n const optionalScopesRemoved =\n newOptionalScopes.length !==\n Object.keys(caip25CaveatValue.optionalScopes).length;\n\n if (!requiredScopesRemoved && !optionalScopesRemoved) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const updatedCaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: Object.fromEntries(newRequiredScopes),\n optionalScopes: Object.fromEntries(newOptionalScopes),\n };\n\n const hasNonWalletScopes = [...newRequiredScopes, ...newOptionalScopes].some(\n ([scopeString]) => {\n const { namespace } = parseScopeString(scopeString);\n return namespace !== KnownCaipNamespace.Wallet;\n },\n );\n\n if (hasNonWalletScopes) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Modifies the requested CAIP-25 permissions object after UI confirmation.\n *\n * @param caip25CaveatValue - The requested CAIP-25 caveat value to modify.\n * @param accountAddresses - The list of permitted eth addresses.\n * @param chainIds - The list of permitted eth chainIds.\n * @returns The updated CAIP-25 caveat value with the permitted accounts and chainIds set.\n */\nexport const generateCaip25Caveat = (\n caip25CaveatValue: Caip25CaveatValue,\n accountAddresses: CaipAccountId[],\n chainIds: CaipChainId[],\n): {\n [Caip25EndowmentPermissionName]: {\n caveats: [{ type: string; value: Caip25CaveatValue }];\n };\n} => {\n const caveatValueWithChains = overwriteCaipChainIdsInCaip25CaveatValue(\n caip25CaveatValue,\n chainIds,\n );\n\n const caveatValueWithAccounts = setNonSCACaipAccountIdsInCaip25CaveatValue(\n caveatValueWithChains,\n accountAddresses,\n );\n\n return {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: caveatValueWithAccounts,\n },\n ],\n },\n };\n};\n\n/**\n * Helper to get the CAIP-25 caveat from a permission\n *\n * @param [caip25Permission] - The CAIP-25 permission object\n * @param caip25Permission.caveats - The caveats of the CAIP-25 permission\n * @returns The CAIP-25 caveat or undefined if not found\n */\nexport function getCaip25CaveatFromPermission(caip25Permission?: {\n caveats: {\n type: string;\n value: Caip25CaveatValue;\n }[];\n}):\n | {\n type: string;\n value: Caip25CaveatValue;\n }\n | undefined {\n return caip25Permission?.caveats.find(\n (caveat) => caveat.type === Caip25CaveatType,\n );\n}\n"]}
|
package/dist/index.cjs
CHANGED
@@ -1,25 +1,32 @@
|
|
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.
|
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.getAllScopesFromScopesObjects = 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
|
-
Object.defineProperty(exports, "
|
7
|
+
Object.defineProperty(exports, "setNonSCACaipAccountIdsInCaip25CaveatValue", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.setNonSCACaipAccountIdsInCaip25CaveatValue; } });
|
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; } });
|
10
|
+
Object.defineProperty(exports, "isInternalAccountInPermittedAccountIds", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.isInternalAccountInPermittedAccountIds; } });
|
11
|
+
Object.defineProperty(exports, "isCaipAccountIdInPermittedAccountIds", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.isCaipAccountIdInPermittedAccountIds; } });
|
8
12
|
var caip_permission_adapter_permittedChains_1 = require("./adapters/caip-permission-adapter-permittedChains.cjs");
|
9
13
|
Object.defineProperty(exports, "getPermittedEthChainIds", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.getPermittedEthChainIds; } });
|
10
14
|
Object.defineProperty(exports, "addPermittedEthChainId", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.addPermittedEthChainId; } });
|
11
15
|
Object.defineProperty(exports, "setPermittedEthChainIds", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.setPermittedEthChainIds; } });
|
12
|
-
Object.defineProperty(exports, "
|
13
|
-
Object.defineProperty(exports, "
|
16
|
+
Object.defineProperty(exports, "overwriteCaipChainIdsInCaip25CaveatValue", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.overwriteCaipChainIdsInCaip25CaveatValue; } });
|
17
|
+
Object.defineProperty(exports, "addCaipChainIdInCaip25CaveatValue", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.addCaipChainIdInCaip25CaveatValue; } });
|
18
|
+
Object.defineProperty(exports, "getAllNonWalletNamespacesFromCaip25CaveatValue", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.getAllNonWalletNamespacesFromCaip25CaveatValue; } });
|
19
|
+
Object.defineProperty(exports, "getAllScopesFromPermission", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.getAllScopesFromPermission; } });
|
20
|
+
Object.defineProperty(exports, "getAllScopesFromCaip25CaveatValue", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.getAllScopesFromCaip25CaveatValue; } });
|
21
|
+
Object.defineProperty(exports, "getAllScopesFromScopesObjects", { enumerable: true, get: function () { return caip_permission_adapter_permittedChains_1.getAllScopesFromScopesObjects; } });
|
14
22
|
var caip_permission_adapter_session_scopes_1 = require("./adapters/caip-permission-adapter-session-scopes.cjs");
|
15
23
|
Object.defineProperty(exports, "getInternalScopesObject", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getInternalScopesObject; } });
|
16
24
|
Object.defineProperty(exports, "getSessionScopes", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getSessionScopes; } });
|
17
25
|
Object.defineProperty(exports, "getPermittedAccountsForScopes", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getPermittedAccountsForScopes; } });
|
18
|
-
var validation_1 = require("./scope/validation.cjs");
|
19
|
-
Object.defineProperty(exports, "isKnownSessionPropertyValue", { enumerable: true, get: function () { return validation_1.isKnownSessionPropertyValue; } });
|
20
26
|
var authorization_1 = require("./scope/authorization.cjs");
|
21
27
|
Object.defineProperty(exports, "validateAndNormalizeScopes", { enumerable: true, get: function () { return authorization_1.validateAndNormalizeScopes; } });
|
22
28
|
Object.defineProperty(exports, "bucketScopes", { enumerable: true, get: function () { return authorization_1.bucketScopes; } });
|
29
|
+
Object.defineProperty(exports, "isNamespaceInScopesObject", { enumerable: true, get: function () { return authorization_1.isNamespaceInScopesObject; } });
|
23
30
|
var assert_1 = require("./scope/assert.cjs");
|
24
31
|
Object.defineProperty(exports, "assertIsInternalScopeString", { enumerable: true, get: function () { return assert_1.assertIsInternalScopeString; } });
|
25
32
|
var constants_1 = require("./scope/constants.cjs");
|
@@ -28,10 +35,9 @@ Object.defineProperty(exports, "KnownRpcMethods", { enumerable: true, get: funct
|
|
28
35
|
Object.defineProperty(exports, "KnownWalletNamespaceRpcMethods", { enumerable: true, get: function () { return constants_1.KnownWalletNamespaceRpcMethods; } });
|
29
36
|
Object.defineProperty(exports, "KnownNotifications", { enumerable: true, get: function () { return constants_1.KnownNotifications; } });
|
30
37
|
Object.defineProperty(exports, "KnownWalletScopeString", { enumerable: true, get: function () { return constants_1.KnownWalletScopeString; } });
|
38
|
+
Object.defineProperty(exports, "isKnownSessionPropertyValue", { enumerable: true, get: function () { return constants_1.isKnownSessionPropertyValue; } });
|
31
39
|
var filter_1 = require("./scope/filter.cjs");
|
32
40
|
Object.defineProperty(exports, "getSupportedScopeObjects", { enumerable: true, get: function () { return filter_1.getSupportedScopeObjects; } });
|
33
|
-
Object.defineProperty(exports, "getCaipAccountIdsFromScopesObjects", { enumerable: true, get: function () { return filter_1.getCaipAccountIdsFromScopesObjects; } });
|
34
|
-
Object.defineProperty(exports, "getAllScopesFromScopesObjects", { enumerable: true, get: function () { return filter_1.getAllScopesFromScopesObjects; } });
|
35
41
|
var types_1 = require("./scope/types.cjs");
|
36
42
|
Object.defineProperty(exports, "parseScopeString", { enumerable: true, get: function () { return types_1.parseScopeString; } });
|
37
43
|
var transform_1 = require("./scope/transform.cjs");
|
@@ -49,6 +55,7 @@ Object.defineProperty(exports, "Caip25EndowmentPermissionName", { enumerable: tr
|
|
49
55
|
Object.defineProperty(exports, "caip25EndowmentBuilder", { enumerable: true, get: function () { return caip25Permission_1.caip25EndowmentBuilder; } });
|
50
56
|
Object.defineProperty(exports, "Caip25CaveatMutators", { enumerable: true, get: function () { return caip25Permission_1.Caip25CaveatMutators; } });
|
51
57
|
Object.defineProperty(exports, "generateCaip25Caveat", { enumerable: true, get: function () { return caip25Permission_1.generateCaip25Caveat; } });
|
58
|
+
Object.defineProperty(exports, "getCaip25CaveatFromPermission", { enumerable: true, get: function () { return caip25Permission_1.getCaip25CaveatFromPermission; } });
|
52
59
|
var constants_2 = require("./scope/constants.cjs");
|
53
60
|
Object.defineProperty(exports, "KnownSessionProperties", { enumerable: true, get: function () { return constants_2.KnownSessionProperties; } });
|
54
61
|
var errors_1 = require("./scope/errors.cjs");
|
package/dist/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oGAQqD;AAPnD,kIAAA,cAAc,OAAA;AACd,kIAAA,cAAc,OAAA;AACd,8JAAA,0CAA0C,OAAA;AAC1C,sJAAA,kCAAkC,OAAA;AAClC,0JAAA,sCAAsC,OAAA;AACtC,0JAAA,sCAAsC,OAAA;AACtC,wJAAA,oCAAoC,OAAA;AAEtC,kHAU4D;AAT1D,kJAAA,uBAAuB,OAAA;AACvB,iJAAA,sBAAsB,OAAA;AACtB,k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ts,\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 getAllScopesFromScopesObjects,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\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 {\n getSupportedScopeObjects,\n} 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,17 +1,16 @@
|
|
1
|
-
export { getEthAccounts, setEthAccounts,
|
2
|
-
export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds,
|
1
|
+
export { getEthAccounts, setEthAccounts, setNonSCACaipAccountIdsInCaip25CaveatValue, getCaipAccountIdsFromScopesObjects, getCaipAccountIdsFromCaip25CaveatValue, isInternalAccountInPermittedAccountIds, isCaipAccountIdInPermittedAccountIds, } from "./adapters/caip-permission-adapter-accounts.cjs";
|
2
|
+
export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, overwriteCaipChainIdsInCaip25CaveatValue, addCaipChainIdInCaip25CaveatValue, getAllNonWalletNamespacesFromCaip25CaveatValue, getAllScopesFromPermission, getAllScopesFromCaip25CaveatValue, getAllScopesFromScopesObjects, } from "./adapters/caip-permission-adapter-permittedChains.cjs";
|
3
3
|
export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes, } from "./adapters/caip-permission-adapter-session-scopes.cjs";
|
4
|
-
export { isKnownSessionPropertyValue } from "./scope/validation.cjs";
|
5
4
|
export type { Caip25Authorization } from "./scope/authorization.cjs";
|
6
|
-
export { validateAndNormalizeScopes, bucketScopes, } from "./scope/authorization.cjs";
|
5
|
+
export { validateAndNormalizeScopes, bucketScopes, isNamespaceInScopesObject, } from "./scope/authorization.cjs";
|
7
6
|
export { assertIsInternalScopeString } from "./scope/assert.cjs";
|
8
|
-
export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownNotifications, KnownWalletScopeString, } from "./scope/constants.cjs";
|
9
|
-
export { getSupportedScopeObjects,
|
7
|
+
export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownNotifications, KnownWalletScopeString, isKnownSessionPropertyValue, } from "./scope/constants.cjs";
|
8
|
+
export { getSupportedScopeObjects, } from "./scope/filter.cjs";
|
10
9
|
export type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject, InternalScopeString, InternalScopeObject, InternalScopesObject, NormalizedScopeObject, NormalizedScopesObject, ScopedProperties, NonWalletKnownCaipNamespace, } from "./scope/types.cjs";
|
11
10
|
export { parseScopeString } from "./scope/types.cjs";
|
12
11
|
export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes, } from "./scope/transform.cjs";
|
13
12
|
export type { Caip25CaveatValue } from "./caip25Permission.cjs";
|
14
|
-
export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, } from "./caip25Permission.cjs";
|
13
|
+
export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, getCaip25CaveatFromPermission, } from "./caip25Permission.cjs";
|
15
14
|
export { KnownSessionProperties } from "./scope/constants.cjs";
|
16
15
|
export { Caip25Errors } from "./scope/errors.cjs";
|
17
16
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,
|
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,sCAAsC,EACtC,oCAAoC,GACrC,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,wCAAwC,EACxC,iCAAiC,EACjC,8CAA8C,EAC9C,0BAA0B,EAC1B,iCAAiC,EACjC,6BAA6B,GAC9B,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAC3D,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,EACL,wBAAwB,GACzB,2BAAuB;AACxB,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.d.mts
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
export { getEthAccounts, setEthAccounts,
|
2
|
-
export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds,
|
1
|
+
export { getEthAccounts, setEthAccounts, setNonSCACaipAccountIdsInCaip25CaveatValue, getCaipAccountIdsFromScopesObjects, getCaipAccountIdsFromCaip25CaveatValue, isInternalAccountInPermittedAccountIds, isCaipAccountIdInPermittedAccountIds, } from "./adapters/caip-permission-adapter-accounts.mjs";
|
2
|
+
export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, overwriteCaipChainIdsInCaip25CaveatValue, addCaipChainIdInCaip25CaveatValue, getAllNonWalletNamespacesFromCaip25CaveatValue, getAllScopesFromPermission, getAllScopesFromCaip25CaveatValue, getAllScopesFromScopesObjects, } from "./adapters/caip-permission-adapter-permittedChains.mjs";
|
3
3
|
export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes, } from "./adapters/caip-permission-adapter-session-scopes.mjs";
|
4
|
-
export { isKnownSessionPropertyValue } from "./scope/validation.mjs";
|
5
4
|
export type { Caip25Authorization } from "./scope/authorization.mjs";
|
6
|
-
export { validateAndNormalizeScopes, bucketScopes, } from "./scope/authorization.mjs";
|
5
|
+
export { validateAndNormalizeScopes, bucketScopes, isNamespaceInScopesObject, } from "./scope/authorization.mjs";
|
7
6
|
export { assertIsInternalScopeString } from "./scope/assert.mjs";
|
8
|
-
export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownNotifications, KnownWalletScopeString, } from "./scope/constants.mjs";
|
9
|
-
export { getSupportedScopeObjects,
|
7
|
+
export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownNotifications, KnownWalletScopeString, isKnownSessionPropertyValue, } from "./scope/constants.mjs";
|
8
|
+
export { getSupportedScopeObjects, } from "./scope/filter.mjs";
|
10
9
|
export type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject, InternalScopeString, InternalScopeObject, InternalScopesObject, NormalizedScopeObject, NormalizedScopesObject, ScopedProperties, NonWalletKnownCaipNamespace, } from "./scope/types.mjs";
|
11
10
|
export { parseScopeString } from "./scope/types.mjs";
|
12
11
|
export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes, } from "./scope/transform.mjs";
|
13
12
|
export type { Caip25CaveatValue } from "./caip25Permission.mjs";
|
14
|
-
export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, } from "./caip25Permission.mjs";
|
13
|
+
export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, getCaip25CaveatFromPermission, } from "./caip25Permission.mjs";
|
15
14
|
export { KnownSessionProperties } from "./scope/constants.mjs";
|
16
15
|
export { Caip25Errors } from "./scope/errors.mjs";
|
17
16
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,
|
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,EACjC,6BAA6B,GAC9B,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAC3D,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,EACL,wBAAwB,GACzB,2BAAuB;AACxB,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,14 +1,13 @@
|
|
1
|
-
export { getEthAccounts, setEthAccounts,
|
2
|
-
export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds,
|
1
|
+
export { getEthAccounts, setEthAccounts, setNonSCACaipAccountIdsInCaip25CaveatValue, getCaipAccountIdsFromScopesObjects, getCaipAccountIdsFromCaip25CaveatValue, isInternalAccountInPermittedAccountIds, isCaipAccountIdInPermittedAccountIds } from "./adapters/caip-permission-adapter-accounts.mjs";
|
2
|
+
export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, overwriteCaipChainIdsInCaip25CaveatValue, addCaipChainIdInCaip25CaveatValue, getAllNonWalletNamespacesFromCaip25CaveatValue, getAllScopesFromPermission, getAllScopesFromCaip25CaveatValue, getAllScopesFromScopesObjects } from "./adapters/caip-permission-adapter-permittedChains.mjs";
|
3
3
|
export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes } from "./adapters/caip-permission-adapter-session-scopes.mjs";
|
4
|
-
export {
|
5
|
-
export { validateAndNormalizeScopes, bucketScopes } from "./scope/authorization.mjs";
|
4
|
+
export { validateAndNormalizeScopes, bucketScopes, isNamespaceInScopesObject } from "./scope/authorization.mjs";
|
6
5
|
export { assertIsInternalScopeString } from "./scope/assert.mjs";
|
7
|
-
export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownNotifications, KnownWalletScopeString } from "./scope/constants.mjs";
|
8
|
-
export { getSupportedScopeObjects
|
6
|
+
export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownNotifications, KnownWalletScopeString, isKnownSessionPropertyValue } from "./scope/constants.mjs";
|
7
|
+
export { getSupportedScopeObjects } from "./scope/filter.mjs";
|
9
8
|
export { parseScopeString } from "./scope/types.mjs";
|
10
9
|
export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes } from "./scope/transform.mjs";
|
11
|
-
export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat } from "./caip25Permission.mjs";
|
10
|
+
export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat, getCaip25CaveatFromPermission } from "./caip25Permission.mjs";
|
12
11
|
export { KnownSessionProperties } from "./scope/constants.mjs";
|
13
12
|
export { Caip25Errors } from "./scope/errors.mjs";
|
14
13
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,
|
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,EACjC,6BAA6B,EAC9B,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,EAC9B,8DAA0D;AAE3D,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,EACL,wBAAwB,EACzB,2BAAuB;AAaxB,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 getAllScopesFromScopesObjects,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\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 {\n getSupportedScopeObjects,\n} 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"]}
|
@@ -1,8 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.bucketScopes = exports.validateAndNormalizeScopes = void 0;
|
3
|
+
exports.isNamespaceInScopesObject = exports.bucketScopes = exports.validateAndNormalizeScopes = void 0;
|
4
4
|
const filter_1 = require("./filter.cjs");
|
5
5
|
const transform_1 = require("./transform.cjs");
|
6
|
+
const types_1 = require("./types.cjs");
|
6
7
|
const validation_1 = require("./validation.cjs");
|
7
8
|
/**
|
8
9
|
* Validates and normalizes a set of scopes according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.
|
@@ -48,4 +49,18 @@ const bucketScopes = (scopes, { isEvmChainIdSupported, isEvmChainIdSupportable,
|
|
48
49
|
return { supportedScopes, supportableScopes, unsupportableScopes };
|
49
50
|
};
|
50
51
|
exports.bucketScopes = bucketScopes;
|
52
|
+
/**
|
53
|
+
* Checks if a given CAIP namespace is present in a NormalizedScopesObject.
|
54
|
+
*
|
55
|
+
* @param scopesObject - The NormalizedScopesObject to check.
|
56
|
+
* @param caipNamespace - The CAIP namespace to check for.
|
57
|
+
* @returns true if the CAIP namespace is present in the NormalizedScopesObject, false otherwise.
|
58
|
+
*/
|
59
|
+
function isNamespaceInScopesObject(scopesObject, caipNamespace) {
|
60
|
+
return Object.keys(scopesObject).some((scope) => {
|
61
|
+
const { namespace } = (0, types_1.parseScopeString)(scope);
|
62
|
+
return namespace === caipNamespace;
|
63
|
+
});
|
64
|
+
}
|
65
|
+
exports.isNamespaceInScopesObject = isNamespaceInScopesObject;
|
51
66
|
//# sourceMappingURL=authorization.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"authorization.cjs","sourceRoot":"","sources":["../../src/scope/authorization.ts"],"names":[],"mappings":";;;AAEA,yCAAiD;AACjD,+CAAsD;AAMtD,iDAA8C;
|
1
|
+
{"version":3,"file":"authorization.cjs","sourceRoot":"","sources":["../../src/scope/authorization.ts"],"names":[],"mappings":";;;AAE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,EAAE,EAAE;QAC9C,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,KAAK,CAAC,CAAC;QAC9C,OAAO,SAAS,KAAK,aAAa,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC;AARD,8DAQC","sourcesContent":["import type { CaipChainId, CaipNamespace, Hex, Json } from '@metamask/utils';\n\nimport { bucketScopesBySupport } from './filter';\nimport { normalizeAndMergeScopes } from './transform';\nimport type {\n ExternalScopesObject,\n ExternalScopeString,\n NormalizedScopesObject,\n} from './types';\nimport { parseScopeString } from './types';\nimport { getValidScopes } from './validation';\n/**\n * Represents the parameters of a [CAIP-25](https://chainagnostic.org/CAIPs/caip-25) request.\n */\nexport type Caip25Authorization = (\n | {\n requiredScopes: ExternalScopesObject;\n optionalScopes?: ExternalScopesObject;\n }\n | {\n requiredScopes?: ExternalScopesObject;\n optionalScopes: ExternalScopesObject;\n }\n) & {\n sessionProperties?: Record<string, Json>;\n scopedProperties?: Record<ExternalScopeString, Json>;\n};\n\n/**\n * Validates and normalizes a set of scopes according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n *\n * @param requiredScopes - The required scopes to validate and normalize.\n * @param optionalScopes - The optional scopes to validate and normalize.\n * @returns An object containing the normalized required scopes and normalized optional scopes.\n */\nexport const validateAndNormalizeScopes = (\n requiredScopes: ExternalScopesObject,\n optionalScopes: ExternalScopesObject,\n): {\n normalizedRequiredScopes: NormalizedScopesObject;\n normalizedOptionalScopes: NormalizedScopesObject;\n} => {\n const { validRequiredScopes, validOptionalScopes } = getValidScopes(\n requiredScopes,\n optionalScopes,\n );\n\n const normalizedRequiredScopes = normalizeAndMergeScopes(validRequiredScopes);\n const normalizedOptionalScopes = normalizeAndMergeScopes(validOptionalScopes);\n\n return {\n normalizedRequiredScopes,\n normalizedOptionalScopes,\n };\n};\n\n/**\n * Groups a NormalizedScopesObject into three separate\n * NormalizedScopesObjects for supported scopes,\n * supportable scopes, and unsupportable scopes.\n *\n * @param scopes - The NormalizedScopesObject to group.\n * @param hooks - The hooks.\n * @param hooks.isEvmChainIdSupported - A helper that returns true if an eth chainId is currently supported by the wallet.\n * @param hooks.isEvmChainIdSupportable - A helper that returns true if an eth chainId could be supported by the wallet.\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 * @returns an object with three NormalizedScopesObjects separated by support.\n */\nexport const bucketScopes = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isEvmChainIdSupportable,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isEvmChainIdSupportable: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n): {\n supportedScopes: NormalizedScopesObject;\n supportableScopes: NormalizedScopesObject;\n unsupportableScopes: NormalizedScopesObject;\n} => {\n const { supportedScopes, unsupportedScopes: maybeSupportableScopes } =\n bucketScopesBySupport(scopes, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n\n const {\n supportedScopes: supportableScopes,\n unsupportedScopes: unsupportableScopes,\n } = bucketScopesBySupport(maybeSupportableScopes, {\n isEvmChainIdSupported: isEvmChainIdSupportable,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n\n return { supportedScopes, supportableScopes, unsupportableScopes };\n};\n\n/**\n * Checks if a given CAIP namespace is present in a NormalizedScopesObject.\n *\n * @param scopesObject - The NormalizedScopesObject to check.\n * @param caipNamespace - The CAIP namespace to check for.\n * @returns true if the CAIP namespace is present in the NormalizedScopesObject, false otherwise.\n */\nexport function isNamespaceInScopesObject(\n scopesObject: NormalizedScopesObject,\n caipNamespace: CaipNamespace,\n) {\n return Object.keys(scopesObject).some((scope) => {\n const { namespace } = parseScopeString(scope);\n return namespace === caipNamespace;\n });\n}\n"]}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { CaipChainId, Hex, Json } from "@metamask/utils";
|
1
|
+
import type { CaipChainId, CaipNamespace, Hex, Json } from "@metamask/utils";
|
2
2
|
import type { ExternalScopesObject, ExternalScopeString, NormalizedScopesObject } from "./types.cjs";
|
3
3
|
/**
|
4
4
|
* Represents the parameters of a [CAIP-25](https://chainagnostic.org/CAIPs/caip-25) request.
|
@@ -47,4 +47,12 @@ export declare const bucketScopes: (scopes: NormalizedScopesObject, { isEvmChain
|
|
47
47
|
supportableScopes: NormalizedScopesObject;
|
48
48
|
unsupportableScopes: NormalizedScopesObject;
|
49
49
|
};
|
50
|
+
/**
|
51
|
+
* Checks if a given CAIP namespace is present in a NormalizedScopesObject.
|
52
|
+
*
|
53
|
+
* @param scopesObject - The NormalizedScopesObject to check.
|
54
|
+
* @param caipNamespace - The CAIP namespace to check for.
|
55
|
+
* @returns true if the CAIP namespace is present in the NormalizedScopesObject, false otherwise.
|
56
|
+
*/
|
57
|
+
export declare function isNamespaceInScopesObject(scopesObject: NormalizedScopesObject, caipNamespace: CaipNamespace): boolean;
|
50
58
|
//# sourceMappingURL=authorization.d.cts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"authorization.d.cts","sourceRoot":"","sources":["../../src/scope/authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB;
|
1
|
+
{"version":3,"file":"authorization.d.cts","sourceRoot":"","sources":["../../src/scope/authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB;AAI7E,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACvB,oBAAgB;AAGjB;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAC9B;IACE,cAAc,EAAE,oBAAoB,CAAC;IACrC,cAAc,CAAC,EAAE,oBAAoB,CAAC;CACvC,GACD;IACE,cAAc,CAAC,EAAE,oBAAoB,CAAC;IACtC,cAAc,EAAE,oBAAoB,CAAC;CACtC,CACJ,GAAG;IACF,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,mBACrB,oBAAoB,kBACpB,oBAAoB;8BAEV,sBAAsB;8BACtB,sBAAsB;CAcjD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,WACf,sBAAsB;qCAOK,GAAG,KAAK,OAAO;uCACb,GAAG,KAAK,OAAO;oCAClB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;;qBAG5C,sBAAsB;uBACpB,sBAAsB;yBACpB,sBAAsB;CAmB5C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,sBAAsB,EACpC,aAAa,EAAE,aAAa,WAM7B"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { CaipChainId, Hex, Json } from "@metamask/utils";
|
1
|
+
import type { CaipChainId, CaipNamespace, Hex, Json } from "@metamask/utils";
|
2
2
|
import type { ExternalScopesObject, ExternalScopeString, NormalizedScopesObject } from "./types.mjs";
|
3
3
|
/**
|
4
4
|
* Represents the parameters of a [CAIP-25](https://chainagnostic.org/CAIPs/caip-25) request.
|
@@ -47,4 +47,12 @@ export declare const bucketScopes: (scopes: NormalizedScopesObject, { isEvmChain
|
|
47
47
|
supportableScopes: NormalizedScopesObject;
|
48
48
|
unsupportableScopes: NormalizedScopesObject;
|
49
49
|
};
|
50
|
+
/**
|
51
|
+
* Checks if a given CAIP namespace is present in a NormalizedScopesObject.
|
52
|
+
*
|
53
|
+
* @param scopesObject - The NormalizedScopesObject to check.
|
54
|
+
* @param caipNamespace - The CAIP namespace to check for.
|
55
|
+
* @returns true if the CAIP namespace is present in the NormalizedScopesObject, false otherwise.
|
56
|
+
*/
|
57
|
+
export declare function isNamespaceInScopesObject(scopesObject: NormalizedScopesObject, caipNamespace: CaipNamespace): boolean;
|
50
58
|
//# sourceMappingURL=authorization.d.mts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"authorization.d.mts","sourceRoot":"","sources":["../../src/scope/authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB;
|
1
|
+
{"version":3,"file":"authorization.d.mts","sourceRoot":"","sources":["../../src/scope/authorization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB;AAI7E,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACvB,oBAAgB;AAGjB;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAC9B;IACE,cAAc,EAAE,oBAAoB,CAAC;IACrC,cAAc,CAAC,EAAE,oBAAoB,CAAC;CACvC,GACD;IACE,cAAc,CAAC,EAAE,oBAAoB,CAAC;IACtC,cAAc,EAAE,oBAAoB,CAAC;CACtC,CACJ,GAAG;IACF,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,mBACrB,oBAAoB,kBACpB,oBAAoB;8BAEV,sBAAsB;8BACtB,sBAAsB;CAcjD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,WACf,sBAAsB;qCAOK,GAAG,KAAK,OAAO;uCACb,GAAG,KAAK,OAAO;oCAClB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;;qBAG5C,sBAAsB;uBACpB,sBAAsB;yBACpB,sBAAsB;CAmB5C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,sBAAsB,EACpC,aAAa,EAAE,aAAa,WAM7B"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { bucketScopesBySupport } from "./filter.mjs";
|
2
2
|
import { normalizeAndMergeScopes } from "./transform.mjs";
|
3
|
+
import { parseScopeString } from "./types.mjs";
|
3
4
|
import { getValidScopes } from "./validation.mjs";
|
4
5
|
/**
|
5
6
|
* Validates and normalizes a set of scopes according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.
|
@@ -43,4 +44,17 @@ export const bucketScopes = (scopes, { isEvmChainIdSupported, isEvmChainIdSuppor
|
|
43
44
|
});
|
44
45
|
return { supportedScopes, supportableScopes, unsupportableScopes };
|
45
46
|
};
|
47
|
+
/**
|
48
|
+
* Checks if a given CAIP namespace is present in a NormalizedScopesObject.
|
49
|
+
*
|
50
|
+
* @param scopesObject - The NormalizedScopesObject to check.
|
51
|
+
* @param caipNamespace - The CAIP namespace to check for.
|
52
|
+
* @returns true if the CAIP namespace is present in the NormalizedScopesObject, false otherwise.
|
53
|
+
*/
|
54
|
+
export function isNamespaceInScopesObject(scopesObject, caipNamespace) {
|
55
|
+
return Object.keys(scopesObject).some((scope) => {
|
56
|
+
const { namespace } = parseScopeString(scope);
|
57
|
+
return namespace === caipNamespace;
|
58
|
+
});
|
59
|
+
}
|
46
60
|
//# sourceMappingURL=authorization.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"authorization.mjs","sourceRoot":"","sources":["../../src/scope/authorization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AACjD,OAAO,EAAE,uBAAuB,EAAE,wBAAoB;AAMtD,OAAO,EA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AAEF;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,YAAoC,EACpC,aAA4B;IAE5B,OAAO,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;QAC9C,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;QAC9C,OAAO,SAAS,KAAK,aAAa,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { CaipChainId, CaipNamespace, Hex, Json } from '@metamask/utils';\n\nimport { bucketScopesBySupport } from './filter';\nimport { normalizeAndMergeScopes } from './transform';\nimport type {\n ExternalScopesObject,\n ExternalScopeString,\n NormalizedScopesObject,\n} from './types';\nimport { parseScopeString } from './types';\nimport { getValidScopes } from './validation';\n/**\n * Represents the parameters of a [CAIP-25](https://chainagnostic.org/CAIPs/caip-25) request.\n */\nexport type Caip25Authorization = (\n | {\n requiredScopes: ExternalScopesObject;\n optionalScopes?: ExternalScopesObject;\n }\n | {\n requiredScopes?: ExternalScopesObject;\n optionalScopes: ExternalScopesObject;\n }\n) & {\n sessionProperties?: Record<string, Json>;\n scopedProperties?: Record<ExternalScopeString, Json>;\n};\n\n/**\n * Validates and normalizes a set of scopes according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n *\n * @param requiredScopes - The required scopes to validate and normalize.\n * @param optionalScopes - The optional scopes to validate and normalize.\n * @returns An object containing the normalized required scopes and normalized optional scopes.\n */\nexport const validateAndNormalizeScopes = (\n requiredScopes: ExternalScopesObject,\n optionalScopes: ExternalScopesObject,\n): {\n normalizedRequiredScopes: NormalizedScopesObject;\n normalizedOptionalScopes: NormalizedScopesObject;\n} => {\n const { validRequiredScopes, validOptionalScopes } = getValidScopes(\n requiredScopes,\n optionalScopes,\n );\n\n const normalizedRequiredScopes = normalizeAndMergeScopes(validRequiredScopes);\n const normalizedOptionalScopes = normalizeAndMergeScopes(validOptionalScopes);\n\n return {\n normalizedRequiredScopes,\n normalizedOptionalScopes,\n };\n};\n\n/**\n * Groups a NormalizedScopesObject into three separate\n * NormalizedScopesObjects for supported scopes,\n * supportable scopes, and unsupportable scopes.\n *\n * @param scopes - The NormalizedScopesObject to group.\n * @param hooks - The hooks.\n * @param hooks.isEvmChainIdSupported - A helper that returns true if an eth chainId is currently supported by the wallet.\n * @param hooks.isEvmChainIdSupportable - A helper that returns true if an eth chainId could be supported by the wallet.\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 * @returns an object with three NormalizedScopesObjects separated by support.\n */\nexport const bucketScopes = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isEvmChainIdSupportable,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isEvmChainIdSupportable: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n): {\n supportedScopes: NormalizedScopesObject;\n supportableScopes: NormalizedScopesObject;\n unsupportableScopes: NormalizedScopesObject;\n} => {\n const { supportedScopes, unsupportedScopes: maybeSupportableScopes } =\n bucketScopesBySupport(scopes, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n\n const {\n supportedScopes: supportableScopes,\n unsupportedScopes: unsupportableScopes,\n } = bucketScopesBySupport(maybeSupportableScopes, {\n isEvmChainIdSupported: isEvmChainIdSupportable,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n\n return { supportedScopes, supportableScopes, unsupportableScopes };\n};\n\n/**\n * Checks if a given CAIP namespace is present in a NormalizedScopesObject.\n *\n * @param scopesObject - The NormalizedScopesObject to check.\n * @param caipNamespace - The CAIP namespace to check for.\n * @returns true if the CAIP namespace is present in the NormalizedScopesObject, false otherwise.\n */\nexport function isNamespaceInScopesObject(\n scopesObject: NormalizedScopesObject,\n caipNamespace: CaipNamespace,\n) {\n return Object.keys(scopesObject).some((scope) => {\n const { namespace } = parseScopeString(scope);\n return namespace === caipNamespace;\n });\n}\n"]}
|
package/dist/scope/constants.cjs
CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.KnownSessionProperties = exports.KnownNotifications = exports.KnownWalletNamespaceRpcMethods = exports.KnownRpcMethods = exports.Eip1193OnlyMethods = exports.KnownWalletRpcMethods = exports.CaipReferenceRegexes = exports.KnownWalletScopeString = void 0;
|
6
|
+
exports.isKnownSessionPropertyValue = exports.KnownSessionProperties = exports.KnownNotifications = exports.KnownWalletNamespaceRpcMethods = exports.KnownRpcMethods = exports.Eip1193OnlyMethods = exports.KnownWalletRpcMethods = exports.CaipReferenceRegexes = exports.KnownWalletScopeString = void 0;
|
7
7
|
const api_specs_1 = __importDefault(require("@metamask/api-specs"));
|
8
8
|
/**
|
9
9
|
* ScopeStrings for offchain methods that are not specific to a chainId but are specific to a CAIP namespace.
|
@@ -87,4 +87,14 @@ var KnownSessionProperties;
|
|
87
87
|
(function (KnownSessionProperties) {
|
88
88
|
KnownSessionProperties["SolanaAccountChangedNotifications"] = "solana_accountChanged_notifications";
|
89
89
|
})(KnownSessionProperties || (exports.KnownSessionProperties = KnownSessionProperties = {}));
|
90
|
+
/**
|
91
|
+
* Checks if a given value is a known session property.
|
92
|
+
*
|
93
|
+
* @param value - The value to check.
|
94
|
+
* @returns `true` if the value is a known session property, otherwise `false`.
|
95
|
+
*/
|
96
|
+
function isKnownSessionPropertyValue(value) {
|
97
|
+
return Object.values(KnownSessionProperties).includes(value);
|
98
|
+
}
|
99
|
+
exports.isKnownSessionPropertyValue = isKnownSessionPropertyValue;
|
90
100
|
//# sourceMappingURL=constants.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../src/scope/constants.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA0D;AAI1D;;GAEG;AACH,IAAY,sBAEX;AAFD,WAAY,sBAAsB;IAChC,kDAAwB,CAAA;AAC1B,CAAC,EAFW,sBAAsB,sCAAtB,sBAAsB,QAEjC;AAED;;GAEG;AACU,QAAA,oBAAoB,GAC/B;IACE,MAAM,EAAE,oBAAoB;IAC5B,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,KAAK;CACd,CAAC;AAEJ;;GAEG;AACU,QAAA,qBAAqB,GAAa;IAC7C,2BAA2B;IAC3B,mBAAmB;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAExD;;GAEG;AACU,QAAA,kBAAkB,GAAG;IAChC,4BAA4B;IAC5B,uBAAuB;IACvB,2BAA2B;IAC3B,0BAA0B;IAC1B,qBAAqB;IACrB,cAAc;IACd,cAAc;IACd,aAAa;IACb,2BAA2B;IAC3B,2BAA2B;IAC3B,6BAA6B;IAC7B,2BAA2B;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,aAAa,GAAG,mBAAuB,CAAC,OAAO;KAClD,GAAG,CAAC,CAAC,EAAE,IAAI,EAAoB,EAAE,EAAE,CAAC,IAAI,CAAC;KACzC,MAAM,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,mBAAmB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;KACjE,MAAM,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,6BAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;KACnE,MAAM,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,0BAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpE;;GAEG;AACU,QAAA,eAAe,GAAkD;IAC5E,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACX,CAAC;AAEF;;GAEG;AACU,QAAA,8BAA8B,GAGvC;IACF,MAAM,EAAE,mBAAmB;IAC3B,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACX,CAAC;AAEF;;GAEG;AACU,QAAA,kBAAkB,GAC7B;IACE,MAAM,EAAE,CAAC,kBAAkB,CAAC;IAC5B,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACX,CAAC;AAEJ;;GAEG;AACH,IAAY,sBAEX;AAFD,WAAY,sBAAsB;IAChC,mGAAyE,CAAA;AAC3E,CAAC,EAFW,sBAAsB,sCAAtB,sBAAsB,QAEjC","sourcesContent":["import MetaMaskOpenRPCDocument from '@metamask/api-specs';\n\nimport type { NonWalletKnownCaipNamespace } from './types';\n\n/**\n * ScopeStrings for offchain methods that are not specific to a chainId but are specific to a CAIP namespace.\n */\nexport enum KnownWalletScopeString {\n Eip155 = 'wallet:eip155',\n}\n\n/**\n * Regexes defining how references must be formed for non-wallet known CAIP namespaces\n */\nexport const CaipReferenceRegexes: Record<NonWalletKnownCaipNamespace, RegExp> =\n {\n eip155: /^(0|[1-9][0-9]*)$/u,\n bip122: /.*/u,\n solana: /.*/u,\n };\n\n/**\n * Methods that do not belong exclusively to any CAIP namespace.\n */\nexport const KnownWalletRpcMethods: string[] = [\n 'wallet_registerOnboarding',\n 'wallet_scanQRCode',\n];\n\n/**\n * Methods that belong to the `wallet:eip155` scope.\n */\nconst WalletEip155Methods = ['wallet_addEthereumChain'];\n\n/**\n * Methods that are only supported via the EIP-1193 API.\n */\nexport const Eip1193OnlyMethods = [\n 'wallet_switchEthereumChain',\n 'wallet_getPermissions',\n 'wallet_requestPermissions',\n 'wallet_revokePermissions',\n 'eth_requestAccounts',\n 'eth_accounts',\n 'eth_coinbase',\n 'net_version',\n 'metamask_logWeb3ShimUsage',\n 'metamask_getProviderState',\n 'metamask_sendDomainMetadata',\n 'wallet_registerOnboarding',\n];\n\n/**\n * All MetaMask methods, except for ones we have specified in the constants above.\n */\nconst Eip155Methods = MetaMaskOpenRPCDocument.methods\n .map(({ name }: { name: string }) => name)\n .filter((method: string) => !WalletEip155Methods.includes(method))\n .filter((method: string) => !KnownWalletRpcMethods.includes(method))\n .filter((method: string) => !Eip1193OnlyMethods.includes(method));\n\n/**\n * Methods by ecosystem that are chain specific.\n */\nexport const KnownRpcMethods: Record<NonWalletKnownCaipNamespace, string[]> = {\n eip155: Eip155Methods,\n bip122: [],\n solana: [],\n};\n\n/**\n * Methods for CAIP namespaces that aren't chain specific.\n */\nexport const KnownWalletNamespaceRpcMethods: Record<\n NonWalletKnownCaipNamespace,\n string[]\n> = {\n eip155: WalletEip155Methods,\n bip122: [],\n solana: [],\n};\n\n/**\n * Notifications for known CAIP namespaces.\n */\nexport const KnownNotifications: Record<NonWalletKnownCaipNamespace, string[]> =\n {\n eip155: ['eth_subscription'],\n bip122: [],\n solana: [],\n };\n\n/**\n * Session properties for known CAIP namespaces.\n */\nexport enum KnownSessionProperties {\n SolanaAccountChangedNotifications = 'solana_accountChanged_notifications',\n}\n"]}
|
1
|
+
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../src/scope/constants.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA0D;AAI1D;;GAEG;AACH,IAAY,sBAEX;AAFD,WAAY,sBAAsB;IAChC,kDAAwB,CAAA;AAC1B,CAAC,EAFW,sBAAsB,sCAAtB,sBAAsB,QAEjC;AAED;;GAEG;AACU,QAAA,oBAAoB,GAC/B;IACE,MAAM,EAAE,oBAAoB;IAC5B,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,KAAK;CACd,CAAC;AAEJ;;GAEG;AACU,QAAA,qBAAqB,GAAa;IAC7C,2BAA2B;IAC3B,mBAAmB;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAExD;;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M,CAAC,sBAAsB,CAAC,CAAC,QAAQ,CACnD,KAA+B,CAChC,CAAC;AACJ,CAAC;AAND,kEAMC","sourcesContent":["import MetaMaskOpenRPCDocument from '@metamask/api-specs';\n\nimport type { NonWalletKnownCaipNamespace } from './types';\n\n/**\n * ScopeStrings for offchain methods that are not specific to a chainId but are specific to a CAIP namespace.\n */\nexport enum KnownWalletScopeString {\n Eip155 = 'wallet:eip155',\n}\n\n/**\n * Regexes defining how references must be formed for non-wallet known CAIP namespaces\n */\nexport const CaipReferenceRegexes: Record<NonWalletKnownCaipNamespace, RegExp> =\n {\n eip155: /^(0|[1-9][0-9]*)$/u,\n bip122: /.*/u,\n solana: /.*/u,\n };\n\n/**\n * Methods that do not belong exclusively to any CAIP namespace.\n */\nexport const KnownWalletRpcMethods: string[] = [\n 'wallet_registerOnboarding',\n 'wallet_scanQRCode',\n];\n\n/**\n * Methods that belong to the `wallet:eip155` scope.\n */\nconst WalletEip155Methods = ['wallet_addEthereumChain'];\n\n/**\n * Methods that are only supported via the EIP-1193 API.\n */\nexport const Eip1193OnlyMethods = [\n 'wallet_switchEthereumChain',\n 'wallet_getPermissions',\n 'wallet_requestPermissions',\n 'wallet_revokePermissions',\n 'eth_requestAccounts',\n 'eth_accounts',\n 'eth_coinbase',\n 'net_version',\n 'metamask_logWeb3ShimUsage',\n 'metamask_getProviderState',\n 'metamask_sendDomainMetadata',\n 'wallet_registerOnboarding',\n];\n\n/**\n * All MetaMask methods, except for ones we have specified in the constants above.\n */\nconst Eip155Methods = MetaMaskOpenRPCDocument.methods\n .map(({ name }: { name: string }) => name)\n .filter((method: string) => !WalletEip155Methods.includes(method))\n .filter((method: string) => !KnownWalletRpcMethods.includes(method))\n .filter((method: string) => !Eip1193OnlyMethods.includes(method));\n\n/**\n * Methods by ecosystem that are chain specific.\n */\nexport const KnownRpcMethods: Record<NonWalletKnownCaipNamespace, string[]> = {\n eip155: Eip155Methods,\n bip122: [],\n solana: [],\n};\n\n/**\n * Methods for CAIP namespaces that aren't chain specific.\n */\nexport const KnownWalletNamespaceRpcMethods: Record<\n NonWalletKnownCaipNamespace,\n string[]\n> = {\n eip155: WalletEip155Methods,\n bip122: [],\n solana: [],\n};\n\n/**\n * Notifications for known CAIP namespaces.\n */\nexport const KnownNotifications: Record<NonWalletKnownCaipNamespace, string[]> =\n {\n eip155: ['eth_subscription'],\n bip122: [],\n solana: [],\n };\n\n/**\n * Session properties for known CAIP namespaces.\n */\nexport enum KnownSessionProperties {\n SolanaAccountChangedNotifications = 'solana_accountChanged_notifications',\n}\n\n/**\n * Checks if a given value is a known session property.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a known session property, otherwise `false`.\n */\nexport function isKnownSessionPropertyValue(\n value: string,\n): value is KnownSessionProperties {\n return Object.values(KnownSessionProperties).includes(\n value as KnownSessionProperties,\n );\n}\n"]}
|
@@ -35,4 +35,11 @@ export declare const KnownNotifications: Record<NonWalletKnownCaipNamespace, str
|
|
35
35
|
export declare enum KnownSessionProperties {
|
36
36
|
SolanaAccountChangedNotifications = "solana_accountChanged_notifications"
|
37
37
|
}
|
38
|
+
/**
|
39
|
+
* Checks if a given value is a known session property.
|
40
|
+
*
|
41
|
+
* @param value - The value to check.
|
42
|
+
* @returns `true` if the value is a known session property, otherwise `false`.
|
43
|
+
*/
|
44
|
+
export declare function isKnownSessionPropertyValue(value: string): value is KnownSessionProperties;
|
38
45
|
//# sourceMappingURL=constants.d.cts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../src/scope/constants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAgB;AAE3D;;GAEG;AACH,oBAAY,sBAAsB;IAChC,MAAM,kBAAkB;CACzB;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,2BAA2B,EAAE,MAAM,CAK1E,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,M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