@metamask-previews/chain-agnostic-permission 0.1.0-preview-8f23873 → 0.1.0-preview-9d51a80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/adapters/caip-permission-adapter-session-scopes.cjs +1 -23
  2. package/dist/adapters/caip-permission-adapter-session-scopes.cjs.map +1 -1
  3. package/dist/adapters/caip-permission-adapter-session-scopes.d.cts +1 -9
  4. package/dist/adapters/caip-permission-adapter-session-scopes.d.cts.map +1 -1
  5. package/dist/adapters/caip-permission-adapter-session-scopes.d.mts +1 -9
  6. package/dist/adapters/caip-permission-adapter-session-scopes.d.mts.map +1 -1
  7. package/dist/adapters/caip-permission-adapter-session-scopes.mjs +0 -21
  8. package/dist/adapters/caip-permission-adapter-session-scopes.mjs.map +1 -1
  9. package/dist/caip25Permission.cjs +2 -14
  10. package/dist/caip25Permission.cjs.map +1 -1
  11. package/dist/caip25Permission.d.cts +2 -2
  12. package/dist/caip25Permission.d.cts.map +1 -1
  13. package/dist/caip25Permission.d.mts +2 -2
  14. package/dist/caip25Permission.d.mts.map +1 -1
  15. package/dist/caip25Permission.mjs +3 -15
  16. package/dist/caip25Permission.mjs.map +1 -1
  17. package/dist/index.cjs +1 -2
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.cts.map +1 -1
  21. package/dist/index.d.mts +1 -1
  22. package/dist/index.d.mts.map +1 -1
  23. package/dist/index.mjs +1 -1
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/scope/constants.cjs +1 -8
  26. package/dist/scope/constants.cjs.map +1 -1
  27. package/dist/scope/constants.d.cts +0 -6
  28. package/dist/scope/constants.d.cts.map +1 -1
  29. package/dist/scope/constants.d.mts +0 -6
  30. package/dist/scope/constants.d.mts.map +1 -1
  31. package/dist/scope/constants.mjs +0 -7
  32. package/dist/scope/constants.mjs.map +1 -1
  33. package/dist/scope/supported.cjs +1 -11
  34. package/dist/scope/supported.cjs.map +1 -1
  35. package/dist/scope/supported.d.cts +0 -7
  36. package/dist/scope/supported.d.cts.map +1 -1
  37. package/dist/scope/supported.d.mts +0 -7
  38. package/dist/scope/supported.d.mts.map +1 -1
  39. package/dist/scope/supported.mjs +1 -10
  40. package/dist/scope/supported.mjs.map +1 -1
  41. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPermittedAccountsForScopes = exports.getSessionScopes = exports.getInternalScopesObject = void 0;
3
+ exports.getSessionScopes = exports.getInternalScopesObject = void 0;
4
4
  const utils_1 = require("@metamask/utils");
5
5
  const constants_1 = require("../scope/constants.cjs");
6
6
  const transform_1 = require("../scope/transform.cjs");
@@ -82,26 +82,4 @@ const getSessionScopes = (caip25CaveatValue, { getNonEvmSupportedMethods, }) =>
82
82
  }));
83
83
  };
84
84
  exports.getSessionScopes = getSessionScopes;
85
- /**
86
- * Get the permitted accounts for a given scope.
87
- *
88
- * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for
89
- * @param scopes - The scopes to get the permitted accounts for
90
- * @returns An array of permitted accounts
91
- */
92
- const getPermittedAccountsForScopes = (caip25CaveatValue, scopes) => {
93
- const scopeAccounts = [];
94
- scopes.forEach((scope) => {
95
- const requiredScope = caip25CaveatValue.requiredScopes[scope];
96
- const optionalScope = caip25CaveatValue.optionalScopes[scope];
97
- if (requiredScope) {
98
- scopeAccounts.push(...requiredScope.accounts);
99
- }
100
- if (optionalScope) {
101
- scopeAccounts.push(...optionalScope.accounts);
102
- }
103
- });
104
- return scopeAccounts;
105
- };
106
- exports.getPermittedAccountsForScopes = getPermittedAccountsForScopes;
107
85
  //# sourceMappingURL=caip-permission-adapter-session-scopes.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-adapter-session-scopes.cjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-session-scopes.ts"],"names":[],"mappings":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IAAI,aAAa,EAAE;YACjB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;SAC/C;IACH,CAAC,CAAC,CAAC;IACH,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AArBW,QAAA,6BAA6B,iCAqBxC","sourcesContent":["import {\n type CaipAccountId,\n type CaipChainId,\n isCaipChainId,\n KnownCaipNamespace,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n\n/**\n * Get the permitted accounts for a given scope.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for\n * @param scopes - The scopes to get the permitted accounts for\n * @returns An array of permitted accounts\n */\nexport const getPermittedAccountsForScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n scopes: CaipChainId[],\n): CaipAccountId[] => {\n const scopeAccounts: CaipAccountId[] = [];\n\n scopes.forEach((scope) => {\n const requiredScope = caip25CaveatValue.requiredScopes[scope];\n const optionalScope = caip25CaveatValue.optionalScopes[scope];\n if (requiredScope) {\n scopeAccounts.push(...requiredScope.accounts);\n }\n\n if (optionalScope) {\n scopeAccounts.push(...optionalScope.accounts);\n }\n });\n return scopeAccounts;\n};\n"]}
1
+ {"version":3,"file":"caip-permission-adapter-session-scopes.cjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-session-scopes.ts"],"names":[],"mappings":";;;AAAA,2CAIyB;AAGzB,sDAK4B;AAC5B,sDAA2D;AAK3D,8CAAkD;AAElD;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,sBAA8C,EAC9C,EAAE;IACF,MAAM,cAAc,GAAyB,EAAE,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAC5C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAmD,CAAC;QAExE,cAAc,CAAC,WAAW,CAAC,GAAG;YAC5B,QAAQ;SACT,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAhBW,QAAA,uBAAuB,2BAgBlC;AAEF;;;;;;;GAOG;AACH,MAAM,yBAAyB,GAAG,CAChC,oBAA0C,EAC1C,EACE,yBAAyB,GAG1B,EACD,EAAE;IACF,MAAM,gBAAgB,GAA2B,EAAE,CAAC;IAEpD,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAC1C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAiD,CAAC;QACtE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QA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n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { type CaipAccountId, type CaipChainId } from "@metamask/utils";
1
+ import { type CaipChainId } from "@metamask/utils";
2
2
  import type { Caip25CaveatValue } from "../caip25Permission.cjs";
3
3
  import type { InternalScopesObject, NormalizedScopesObject } from "../scope/types.cjs";
4
4
  /**
@@ -20,12 +20,4 @@ export declare const getInternalScopesObject: (normalizedScopesObject: Normalize
20
20
  export declare const getSessionScopes: (caip25CaveatValue: Pick<Caip25CaveatValue, 'requiredScopes' | 'optionalScopes'>, { getNonEvmSupportedMethods, }: {
21
21
  getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
22
22
  }) => NormalizedScopesObject;
23
- /**
24
- * Get the permitted accounts for a given scope.
25
- *
26
- * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for
27
- * @param scopes - The scopes to get the permitted accounts for
28
- * @returns An array of permitted accounts
29
- */
30
- export declare const getPermittedAccountsForScopes: (caip25CaveatValue: Pick<Caip25CaveatValue, 'requiredScopes' | 'optionalScopes'>, scopes: CaipChainId[]) => CaipAccountId[];
31
23
  //# sourceMappingURL=caip-permission-adapter-session-scopes.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-adapter-session-scopes.d.cts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAGjB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,sBACrB,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,UACO,WAAW,EAAE,KACpB,aAAa,EAef,CAAC"}
1
+ {"version":3,"file":"caip-permission-adapter-session-scopes.d.cts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAGjB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type CaipAccountId, type CaipChainId } from "@metamask/utils";
1
+ import { type CaipChainId } from "@metamask/utils";
2
2
  import type { Caip25CaveatValue } from "../caip25Permission.mjs";
3
3
  import type { InternalScopesObject, NormalizedScopesObject } from "../scope/types.mjs";
4
4
  /**
@@ -20,12 +20,4 @@ export declare const getInternalScopesObject: (normalizedScopesObject: Normalize
20
20
  export declare const getSessionScopes: (caip25CaveatValue: Pick<Caip25CaveatValue, 'requiredScopes' | 'optionalScopes'>, { getNonEvmSupportedMethods, }: {
21
21
  getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
22
22
  }) => NormalizedScopesObject;
23
- /**
24
- * Get the permitted accounts for a given scope.
25
- *
26
- * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for
27
- * @param scopes - The scopes to get the permitted accounts for
28
- * @returns An array of permitted accounts
29
- */
30
- export declare const getPermittedAccountsForScopes: (caip25CaveatValue: Pick<Caip25CaveatValue, 'requiredScopes' | 'optionalScopes'>, scopes: CaipChainId[]) => CaipAccountId[];
31
23
  //# sourceMappingURL=caip-permission-adapter-session-scopes.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-adapter-session-scopes.d.mts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAGjB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B,sBACrB,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,UACO,WAAW,EAAE,KACpB,aAAa,EAef,CAAC"}
1
+ {"version":3,"file":"caip-permission-adapter-session-scopes.d.mts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAGjB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAQ7D,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,2BAAuB;AAGxB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,2BACV,sBAAsB,yBAe/C,CAAC;AAyDF;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,sBACR,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC;uCAIoC,WAAW,KAAK,MAAM,EAAE;4BAW9D,CAAC"}
@@ -77,25 +77,4 @@ export const getSessionScopes = (caip25CaveatValue, { getNonEvmSupportedMethods,
77
77
  getNonEvmSupportedMethods,
78
78
  }));
79
79
  };
80
- /**
81
- * Get the permitted accounts for a given scope.
82
- *
83
- * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for
84
- * @param scopes - The scopes to get the permitted accounts for
85
- * @returns An array of permitted accounts
86
- */
87
- export const getPermittedAccountsForScopes = (caip25CaveatValue, scopes) => {
88
- const scopeAccounts = [];
89
- scopes.forEach((scope) => {
90
- const requiredScope = caip25CaveatValue.requiredScopes[scope];
91
- const optionalScope = caip25CaveatValue.optionalScopes[scope];
92
- if (requiredScope) {
93
- scopeAccounts.push(...requiredScope.accounts);
94
- }
95
- if (optionalScope) {
96
- scopeAccounts.push(...optionalScope.accounts);
97
- }
98
- });
99
- return scopeAccounts;
100
- };
101
80
  //# sourceMappingURL=caip-permission-adapter-session-scopes.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"caip-permission-adapter-session-scopes.mjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACb,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,8BAA8B,EAC9B,qBAAqB,EACtB,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,+BAA2B;AAK3D,OAAO,EAAE,gBAAgB,EAAE,2BAAuB;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,sBAA8C,EAC9C,EAAE;IACF,MAAM,cAAc,GAAyB,EAAE,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAC5C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAmD,CAAC;QAExE,cAAc,CAAC,WAAW,CAAC,GAAG;YAC5B,QAAQ;SACT,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,yBAAyB,GAAG,CAChC,oBAA0C,EAC1C,EACE,yBAAyB,GAG1B,EACD,EAAE;IACF,MAAM,gBAAgB,GAA2B,EAAE,CAAC;IAEpD,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAC1C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAiD,CAAC;QACtE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,OAAO,GAAa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,CAAC;IAE1C,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,aAAa,GAAG,iBAAiB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC9D,IAAI,aAAa,EAAE;YACjB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;SAC/C;QAED,IAAI,aAAa,EAAE;YACjB,aAAa,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;SAC/C;IACH,CAAC,CAAC,CAAC;IACH,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC","sourcesContent":["import {\n type CaipAccountId,\n type CaipChainId,\n isCaipChainId,\n KnownCaipNamespace,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n\n/**\n * Get the permitted accounts for a given scope.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to get the permitted accounts for\n * @param scopes - The scopes to get the permitted accounts for\n * @returns An array of permitted accounts\n */\nexport const getPermittedAccountsForScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n scopes: CaipChainId[],\n): CaipAccountId[] => {\n const scopeAccounts: CaipAccountId[] = [];\n\n scopes.forEach((scope) => {\n const requiredScope = caip25CaveatValue.requiredScopes[scope];\n const optionalScope = caip25CaveatValue.optionalScopes[scope];\n if (requiredScope) {\n scopeAccounts.push(...requiredScope.accounts);\n }\n\n if (optionalScope) {\n scopeAccounts.push(...optionalScope.accounts);\n }\n });\n return scopeAccounts;\n};\n"]}
1
+ {"version":3,"file":"caip-permission-adapter-session-scopes.mjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-session-scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,8BAA8B,EAC9B,qBAAqB,EACtB,+BAA2B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,+BAA2B;AAK3D,OAAO,EAAE,gBAAgB,EAAE,2BAAuB;AAElD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,sBAA8C,EAC9C,EAAE;IACF,MAAM,cAAc,GAAyB,EAAE,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,OAAO,CAC5C,CAAC,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,YAAmD,CAAC;QAExE,cAAc,CAAC,WAAW,CAAC,GAAG;YAC5B,QAAQ;SACT,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,OAAO,cAAc,CAA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;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,iBAGC,EACD,EACE,yBAAyB,GAG1B,EACD,EAAE;IACF,OAAO,qBAAqB,CAC1B,yBAAyB,CAAC,iBAAiB,CAAC,cAAc,EAAE;QAC1D,yBAAyB;KAC1B,CAAC,EACF,yBAAyB,CAAC,iBAAiB,CAAC,cAAc,EAAE;QAC1D,yBAAyB;KAC1B,CAAC,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n type CaipChainId,\n isCaipChainId,\n KnownCaipNamespace,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport {\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from '../scope/constants';\nimport { mergeNormalizedScopes } from '../scope/transform';\nimport type {\n InternalScopesObject,\n NormalizedScopesObject,\n} from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Converts an NormalizedScopesObject to a InternalScopesObject.\n *\n * @param normalizedScopesObject - The NormalizedScopesObject to convert.\n * @returns An InternalScopesObject.\n */\nexport const getInternalScopesObject = (\n normalizedScopesObject: NormalizedScopesObject,\n) => {\n const internalScopes: InternalScopesObject = {};\n\n Object.entries(normalizedScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof normalizedScopesObject;\n\n internalScopes[scopeString] = {\n accounts,\n };\n },\n );\n\n return internalScopes;\n};\n\n/**\n * Converts an InternalScopesObject to a NormalizedScopesObject.\n *\n * @param internalScopesObject - The InternalScopesObject to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nconst getNormalizedScopesObject = (\n internalScopesObject: InternalScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const normalizedScopes: NormalizedScopesObject = {};\n\n Object.entries(internalScopesObject).forEach(\n ([_scopeString, { accounts }]) => {\n const scopeString = _scopeString as keyof typeof internalScopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n let methods: string[] = [];\n let notifications: string[] = [];\n\n if (\n scopeString === KnownCaipNamespace.Wallet ||\n namespace === KnownCaipNamespace.Wallet\n ) {\n if (reference === KnownCaipNamespace.Eip155) {\n methods = KnownWalletNamespaceRpcMethods[reference];\n } else if (isCaipChainId(scopeString)) {\n methods = getNonEvmSupportedMethods(scopeString);\n } else {\n methods = KnownWalletRpcMethods;\n }\n } else if (namespace === KnownCaipNamespace.Eip155) {\n methods = KnownRpcMethods[namespace];\n notifications = KnownNotifications[namespace];\n } else {\n methods = getNonEvmSupportedMethods(scopeString);\n notifications = [];\n }\n\n normalizedScopes[scopeString] = {\n methods,\n notifications,\n accounts,\n };\n },\n );\n\n return normalizedScopes;\n};\n\n/**\n * Takes the scopes from an endowment:caip25 permission caveat value,\n * hydrates them with supported methods and notifications, and returns a NormalizedScopesObject.\n *\n * @param caip25CaveatValue - The CAIP-25 CaveatValue to convert.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A NormalizedScopesObject.\n */\nexport const getSessionScopes = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n return mergeNormalizedScopes(\n getNormalizedScopesObject(caip25CaveatValue.requiredScopes, {\n getNonEvmSupportedMethods,\n }),\n getNormalizedScopesObject(caip25CaveatValue.optionalScopes, {\n getNonEvmSupportedMethods,\n }),\n );\n};\n"]}
@@ -94,17 +94,10 @@ const caip25CaveatBuilder = ({ findNetworkClientIdByChainId, listAccounts, isNon
94
94
  !(0, utils_1.hasProperty)(caveat.value, 'requiredScopes') ||
95
95
  !(0, utils_1.hasProperty)(caveat.value, 'optionalScopes') ||
96
96
  !(0, utils_1.hasProperty)(caveat.value, 'isMultichainOrigin') ||
97
- !(0, utils_1.hasProperty)(caveat.value, 'sessionProperties') ||
98
- typeof caveat.value.isMultichainOrigin !== 'boolean' ||
99
- typeof caveat.value.sessionProperties !== 'object' ||
100
- caveat.value.sessionProperties === null) {
97
+ typeof caveat.value.isMultichainOrigin !== 'boolean') {
101
98
  throw new Error(`${exports.Caip25EndowmentPermissionName} error: Received invalid value for caveat of type "${exports.Caip25CaveatType}".`);
102
99
  }
103
- const { requiredScopes, optionalScopes, sessionProperties } = caveat.value;
104
- const unknownSessionProperties = Object.keys(sessionProperties).filter((key) => !(0, supported_1.isSupportedSessionProperty)(key));
105
- if (unknownSessionProperties.length > 0) {
106
- throw new Error(`${exports.Caip25EndowmentPermissionName} error: Received unknown session property(s) for caveat of type "${exports.Caip25CaveatType}".`);
107
- }
100
+ const { requiredScopes, optionalScopes } = caveat.value;
108
101
  (0, assert_1.assertIsInternalScopesObject)(requiredScopes);
109
102
  (0, assert_1.assertIsInternalScopesObject)(optionalScopes);
110
103
  const isEvmChainIdSupported = (chainId) => {
@@ -136,14 +129,9 @@ const caip25CaveatBuilder = ({ findNetworkClientIdByChainId, listAccounts, isNon
136
129
  merger: (leftValue, rightValue) => {
137
130
  const mergedRequiredScopes = (0, transform_1.mergeInternalScopes)(leftValue.requiredScopes, rightValue.requiredScopes);
138
131
  const mergedOptionalScopes = (0, transform_1.mergeInternalScopes)(leftValue.optionalScopes, rightValue.optionalScopes);
139
- const mergedSessionProperties = {
140
- ...leftValue.sessionProperties,
141
- ...rightValue.sessionProperties,
142
- };
143
132
  const mergedValue = {
144
133
  requiredScopes: mergedRequiredScopes,
145
134
  optionalScopes: mergedOptionalScopes,
146
- sessionProperties: mergedSessionProperties,
147
135
  isMultichainOrigin: leftValue.isMultichainOrigin,
148
136
  };
149
137
  const partialDiff = diffScopesForCaip25CaveatValue(leftValue, mergedValue, 'requiredScopes');
@@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AS,EAAE,8CAAsB,CAAC,gBAAgB;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport type { CaipAccountId, CaipChainId, Json } from '@metamask/utils';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n type Hex,\n type NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual } from 'lodash';\n\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport {\n isSupportedAccount,\n isSupportedScopeString,\n isSupportedSessionProperty,\n} from './scope/supported';\nimport { mergeInternalScopes } from './scope/transform';\nimport {\n parseScopeString,\n type ExternalScopeString,\n type InternalScopeObject,\n type InternalScopesObject,\n} from './scope/types';\n\n/**\n * The CAIP-25 permission caveat value.\n * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.\n * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.\n */\nexport type Caip25CaveatValue = {\n requiredScopes: InternalScopesObject;\n optionalScopes: InternalScopesObject;\n sessionProperties: Record<string, Json>;\n isMultichainOrigin: boolean;\n};\n\n/**\n * The name of the CAIP-25 permission caveat.\n */\nexport const Caip25CaveatType = 'authorizedScopes';\n\n/**\n * The target name of the CAIP-25 endowment permission.\n */\nexport const Caip25EndowmentPermissionName = 'endowment:caip25';\n\n/**\n * Creates a CAIP-25 permission caveat.\n *\n * @param value - The CAIP-25 permission caveat value.\n * @returns The CAIP-25 permission caveat (now including the type).\n */\nexport const createCaip25Caveat = (value: Caip25CaveatValue) => {\n return {\n type: Caip25CaveatType,\n value,\n };\n};\n\ntype Caip25EndowmentCaveatSpecificationBuilderOptions = {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;\n listAccounts: () => { type: string; address: Hex }[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n};\n\n/**\n * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.\n *\n * @param originalValue - The existing CAIP-25 permission caveat value.\n * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.\n * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.\n * @returns The difference between original and merged CAIP-25 permission caveat values.\n */\nexport function diffScopesForCaip25CaveatValue(\n originalValue: Caip25CaveatValue,\n mergedValue: Caip25CaveatValue,\n scopeToDiff: 'optionalScopes' | 'requiredScopes',\n): Caip25CaveatValue {\n const diff = cloneDeep(originalValue);\n\n const mergedScopeToDiff = mergedValue[scopeToDiff];\n for (const [scopeString, mergedScopeObject] of Object.entries(\n mergedScopeToDiff,\n )) {\n const internalScopeString = scopeString as keyof typeof mergedScopeToDiff;\n const originalScopeObject = diff[scopeToDiff][internalScopeString];\n\n if (originalScopeObject) {\n const newAccounts = mergedScopeObject.accounts.filter(\n (account) => !originalScopeObject?.accounts.includes(account),\n );\n if (newAccounts.length > 0) {\n diff[scopeToDiff][internalScopeString] = {\n accounts: newAccounts,\n };\n continue;\n }\n delete diff[scopeToDiff][internalScopeString];\n } else {\n diff[scopeToDiff][internalScopeString] = mergedScopeObject;\n }\n }\n\n return diff;\n}\n\n/**\n * Checks if every account in the given scopes object is supported.\n *\n * @param scopesObject - The scopes object to iterate over.\n * @param listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * addresses.\n * @returns True if every account in the scopes object is supported, false otherwise.\n */\nfunction isEveryAccountInScopesObjectSupported(\n scopesObject: InternalScopesObject,\n listAccounts: () => { type: string; address: Hex }[],\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[],\n) {\n return Object.values(scopesObject).every((scopeObject) =>\n scopeObject.accounts.every((account) =>\n isSupportedAccount(account, {\n getEvmInternalAccounts: listAccounts,\n getNonEvmAccountAddresses,\n }),\n ),\n );\n}\n\n/**\n * Helper that returns a `authorizedScopes` CAIP-25 caveat specification\n * that can be passed into the PermissionController constructor.\n *\n * @param options - The specification builder options.\n * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.\n * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.\n * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns The specification for the `caip25` caveat.\n */\nexport const caip25CaveatBuilder = ({\n findNetworkClientIdByChainId,\n listAccounts,\n isNonEvmScopeSupported,\n getNonEvmAccountAddresses,\n}: Caip25EndowmentCaveatSpecificationBuilderOptions): EndowmentCaveatSpecificationConstraint &\n Required<\n Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>\n > => {\n return {\n type: Caip25CaveatType,\n validator: (\n caveat: { type: typeof Caip25CaveatType; value: unknown },\n _origin?: string,\n _target?: string,\n ) => {\n if (\n !caveat.value ||\n !hasProperty(caveat.value, 'requiredScopes') ||\n !hasProperty(caveat.value, 'optionalScopes') ||\n !hasProperty(caveat.value, 'isMultichainOrigin') ||\n !hasProperty(caveat.value, 'sessionProperties') ||\n typeof caveat.value.isMultichainOrigin !== 'boolean' ||\n typeof caveat.value.sessionProperties !== 'object' ||\n caveat.value.sessionProperties === null\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 unknownSessionProperties = Object.keys(sessionProperties).filter(\n (key) => !isSupportedSessionProperty(key),\n );\n\n if (unknownSessionProperties.length > 0) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received unknown session property(s) for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedSessionProperties = {\n ...leftValue.sessionProperties,\n ...rightValue.sessionProperties,\n };\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\n sessionProperties: mergedSessionProperties,\n isMultichainOrigin: leftValue.isMultichainOrigin,\n };\n\n const partialDiff = diffScopesForCaip25CaveatValue(\n leftValue,\n mergedValue,\n 'requiredScopes',\n );\n\n const diff = diffScopesForCaip25CaveatValue(\n partialDiff,\n mergedValue,\n 'optionalScopes',\n );\n\n return [mergedValue, diff];\n },\n };\n};\n\ntype Caip25EndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof Caip25EndowmentPermissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => null;\n validator: PermissionValidatorConstraint;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * Helper that returns a `endowment:caip25` specification that\n * can be passed into the PermissionController constructor.\n *\n * @returns The specification for the `caip25` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n Record<never, never>,\n Caip25EndowmentSpecification\n> = () => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: Caip25EndowmentPermissionName,\n allowedCaveats: [Caip25CaveatType],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => null,\n validator: (permission: PermissionConstraint) => {\n if (\n permission.caveats?.length !== 1 ||\n permission.caveats?.[0]?.type !== Caip25CaveatType\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Invalid caveats. There must be a single caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n },\n };\n};\n\n/**\n * The `caip25` endowment specification builder. Passed to the\n * `PermissionController` for constructing and validating the\n * `endowment:caip25` permission.\n */\nexport const caip25EndowmentBuilder = Object.freeze({\n targetName: Caip25EndowmentPermissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Factories that construct caveat mutator functions that are passed to\n * PermissionController.updatePermissionsByCaveat.\n */\nexport const Caip25CaveatMutators = {\n [Caip25CaveatType]: {\n removeScope,\n removeAccount,\n },\n};\n\n/**\n * Removes the account from the scope object.\n *\n * @param targetAddress - The address to remove from the scope object.\n * @returns A function that removes the account from the scope object.\n */\nfunction removeAccountFilterFn(targetAddress: string) {\n return (account: CaipAccountId) => {\n const parsed = parseCaipAccountId(account);\n return parsed.address !== targetAddress;\n };\n}\n\n/**\n * Removes the account from the scope object.\n *\n * @param scopeObject - The scope object to remove the account from.\n * @param targetAddress - The address to remove from the scope object.\n */\nfunction removeAccountFromScopeObject(\n scopeObject: InternalScopeObject,\n targetAddress: string,\n) {\n if (scopeObject.accounts) {\n scopeObject.accounts = scopeObject.accounts.filter(\n removeAccountFilterFn(targetAddress),\n );\n }\n}\n\n/**\n * Removes the target account from the scope object.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).\n * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.\n * @returns The updated scope object.\n */\nfunction removeAccount(\n caip25CaveatValue: Caip25CaveatValue,\n targetAddress: Hex,\n) {\n const updatedCaveatValue = cloneDeep(caip25CaveatValue);\n\n [\n updatedCaveatValue.requiredScopes,\n updatedCaveatValue.optionalScopes,\n ].forEach((scopes) => {\n Object.entries(scopes).forEach(([, scopeObject]) => {\n removeAccountFromScopeObject(scopeObject, targetAddress);\n });\n });\n\n const noChange = isEqual(updatedCaveatValue, caip25CaveatValue);\n\n if (noChange) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const hasAccounts = [\n ...Object.values(updatedCaveatValue.requiredScopes),\n ...Object.values(updatedCaveatValue.optionalScopes),\n ].some(({ accounts }) => accounts.length > 0);\n\n if (hasAccounts) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Removes the target scope from the value arrays of the given\n * `endowment:caip25` caveat. No-ops if the target scopeString is not in\n * the existing scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.\n * @param targetScopeString - The scope that is being removed.\n * @returns The updated CAIP-25 permission caveat value.\n */\nfunction removeScope(\n caip25CaveatValue: Caip25CaveatValue,\n targetScopeString: ExternalScopeString,\n) {\n const newRequiredScopes = Object.entries(\n caip25CaveatValue.requiredScopes,\n ).filter(([scope]) => scope !== targetScopeString);\n const newOptionalScopes = Object.entries(\n caip25CaveatValue.optionalScopes,\n ).filter(([scope]) => {\n return scope !== targetScopeString;\n });\n\n const requiredScopesRemoved =\n newRequiredScopes.length !==\n Object.keys(caip25CaveatValue.requiredScopes).length;\n const optionalScopesRemoved =\n newOptionalScopes.length !==\n Object.keys(caip25CaveatValue.optionalScopes).length;\n\n if (!requiredScopesRemoved && !optionalScopesRemoved) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const updatedCaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: Object.fromEntries(newRequiredScopes),\n optionalScopes: Object.fromEntries(newOptionalScopes),\n };\n\n const hasNonWalletScopes = [...newRequiredScopes, ...newOptionalScopes].some(\n ([scopeString]) => {\n const { namespace } = parseScopeString(scopeString);\n return namespace !== KnownCaipNamespace.Wallet;\n },\n );\n\n if (hasNonWalletScopes) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n"]}
1
+ {"version":3,"file":"caip25Permission.cjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":";;;AASA,2EAGyC;AAEzC,2CAMyB;AACzB,mCAA4C;AAE5C,+CAA8D;AAC9D,qDAA+E;AAC/E,qDAAwD;AACxD,6CAKuB;AAcvB;;GAEG;AACU,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;GAEG;AACU,QAAA,6BAA6B,GAAG,kBAAkB,CAAC;AAEhE;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC7D,OAAO;QACL,IAA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AO,SAAS,KAAK,0BAAkB,CAAC,MAAM,CAAC;IACjD,CAAC,CACF,CAAC;IAEF,IAAI,kBAAkB,EAAE;QACtB,OAAO;YACL,SAAS,EAAE,8CAAsB,CAAC,WAAW;YAC7C,KAAK,EAAE,kBAAkB;SAC1B,CAAC;KACH;IAED,OAAO;QACL,SAAS,EAAE,8CAAsB,CAAC,gBAAgB;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport type { CaipAccountId, CaipChainId, Json } from '@metamask/utils';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n type Hex,\n type NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual } from 'lodash';\n\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport { isSupportedAccount, isSupportedScopeString } 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 typeof caveat.value.isMultichainOrigin !== 'boolean'\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received invalid value for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const { requiredScopes, optionalScopes } = caveat.value;\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\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"]}
@@ -12,7 +12,7 @@ import { type ExternalScopeString, type InternalScopeObject, type InternalScopes
12
12
  export type Caip25CaveatValue = {
13
13
  requiredScopes: InternalScopesObject;
14
14
  optionalScopes: InternalScopesObject;
15
- sessionProperties: Record<string, Json>;
15
+ sessionProperties?: Record<string, Json>;
16
16
  isMultichainOrigin: boolean;
17
17
  };
18
18
  /**
@@ -123,7 +123,7 @@ declare function removeScope(caip25CaveatValue: Caip25CaveatValue, targetScopeSt
123
123
  optionalScopes: {
124
124
  [k: string]: InternalScopeObject;
125
125
  };
126
- sessionProperties: Record<string, Json>;
126
+ sessionProperties?: Record<string, Json> | undefined;
127
127
  isMultichainOrigin: boolean;
128
128
  };
129
129
  };
@@ -1 +1 @@
1
- {"version":3,"file":"caip25Permission.d.cts","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAA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MG;AACH,iBAAS,aAAa,CACpB,iBAAiB,EAAE,iBAAiB,EACpC,aAAa,EAAE,GAAG;;;;;;EAoCnB;AAED;;;;;;;;GAQG;AACH,iBAAS,WAAW,CAClB,iBAAiB,EAAE,iBAAiB,EACpC,iBAAiB,EAAE,mBAAmB;;;;;;;;;;;;;;;EA+CvC"}
@@ -12,7 +12,7 @@ import { type ExternalScopeString, type InternalScopeObject, type InternalScopes
12
12
  export type Caip25CaveatValue = {
13
13
  requiredScopes: InternalScopesObject;
14
14
  optionalScopes: InternalScopesObject;
15
- sessionProperties: Record<string, Json>;
15
+ sessionProperties?: Record<string, Json>;
16
16
  isMultichainOrigin: boolean;
17
17
  };
18
18
  /**
@@ -123,7 +123,7 @@ declare function removeScope(caip25CaveatValue: Caip25CaveatValue, targetScopeSt
123
123
  optionalScopes: {
124
124
  [k: string]: InternalScopeObject;
125
125
  };
126
- sessionProperties: Record<string, Json>;
126
+ sessionProperties?: Record<string, Json> | undefined;
127
127
  isMultichainOrigin: boolean;
128
128
  };
129
129
  };
@@ -1 +1 @@
1
- {"version":3,"file":"caip25Permission.d.mts","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EACV,8BAA8B,EAC9B,qBAAqB,EAErB,6BAA6B,EAE7B,sCAAsC,EACvC,wCAAwC;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;AACzC,OAAO,KAAK,EAAiB,WAAW,EAAE,IAAI,EAAE,wBAAwB;AACxE,OAAO,EAIL,KAAK,GAAG,EACR,KAAK,aAAa,EACnB,wBAAwB;AAUzB,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EAC1B,0BAAsB;AAEvB;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,oBAAoB,CAAC;IACrC,cAAc,EAAE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AAO,EAAE,GAAG,CAAA;KAAE,EAAE,CAAC;IACrD,sBAAsB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IACxD,yBAAyB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,EAAE,CAAC;CAC7D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAC5C,aAAa,EAAE,iBAAiB,EAChC,WAAW,EAAE,iBAAiB,EAC9B,WAAW,EAAE,gBAAgB,GAAG,gBAAgB,GAC/C,iBAAiB,CA2BnB;AA0BD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,uGAK7B,gDAAgD,KAAG,sCAAsC,GAC1F,SACE,KAAK,sCAAsC,EAAE,WAAW,GAAG,QAAQ,CAAC,CA2GvE,CAAC;AAuCF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;;;wBAzCjB,eAAe,SAAS;oBAC5B,oCAAoC;qCACnB,qBAAqB,KAAK,IAAI;mBAChD,6BAA6B;wBACxB,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;EAwC7C,CAAC;AAEZ;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKhC,CAAC;AAgCF;;;;;;GAMG;AACH,iBAAS,aAAa,CACpB,iBAAiB,EAAE,iBAAiB,EACpC,aAAa,EAAE,GAAG;;;;;;EAoCnB;AAED;;;;;;;;GAQG;AACH,iBAAS,WAAW,CAClB,iBAAiB,EAAE,iBAAiB,EACpC,iBAAiB,EAAE,mBAAmB;;;;;;;;;;;;;;;EA+CvC"}
@@ -3,7 +3,7 @@ import { hasProperty, KnownCaipNamespace, parseCaipAccountId } from "@metamask/u
3
3
  import $lodash from "lodash";
4
4
  const { cloneDeep, isEqual } = $lodash;
5
5
  import { assertIsInternalScopesObject } from "./scope/assert.mjs";
6
- import { isSupportedAccount, isSupportedScopeString, isSupportedSessionProperty } from "./scope/supported.mjs";
6
+ import { isSupportedAccount, isSupportedScopeString } from "./scope/supported.mjs";
7
7
  import { mergeInternalScopes } from "./scope/transform.mjs";
8
8
  import { parseScopeString } from "./scope/types.mjs";
9
9
  /**
@@ -90,17 +90,10 @@ export const caip25CaveatBuilder = ({ findNetworkClientIdByChainId, listAccounts
90
90
  !hasProperty(caveat.value, 'requiredScopes') ||
91
91
  !hasProperty(caveat.value, 'optionalScopes') ||
92
92
  !hasProperty(caveat.value, 'isMultichainOrigin') ||
93
- !hasProperty(caveat.value, 'sessionProperties') ||
94
- typeof caveat.value.isMultichainOrigin !== 'boolean' ||
95
- typeof caveat.value.sessionProperties !== 'object' ||
96
- caveat.value.sessionProperties === null) {
93
+ typeof caveat.value.isMultichainOrigin !== 'boolean') {
97
94
  throw new Error(`${Caip25EndowmentPermissionName} error: Received invalid value for caveat of type "${Caip25CaveatType}".`);
98
95
  }
99
- const { requiredScopes, optionalScopes, sessionProperties } = caveat.value;
100
- const unknownSessionProperties = Object.keys(sessionProperties).filter((key) => !isSupportedSessionProperty(key));
101
- if (unknownSessionProperties.length > 0) {
102
- throw new Error(`${Caip25EndowmentPermissionName} error: Received unknown session property(s) for caveat of type "${Caip25CaveatType}".`);
103
- }
96
+ const { requiredScopes, optionalScopes } = caveat.value;
104
97
  assertIsInternalScopesObject(requiredScopes);
105
98
  assertIsInternalScopesObject(optionalScopes);
106
99
  const isEvmChainIdSupported = (chainId) => {
@@ -132,14 +125,9 @@ export const caip25CaveatBuilder = ({ findNetworkClientIdByChainId, listAccounts
132
125
  merger: (leftValue, rightValue) => {
133
126
  const mergedRequiredScopes = mergeInternalScopes(leftValue.requiredScopes, rightValue.requiredScopes);
134
127
  const mergedOptionalScopes = mergeInternalScopes(leftValue.optionalScopes, rightValue.optionalScopes);
135
- const mergedSessionProperties = {
136
- ...leftValue.sessionProperties,
137
- ...rightValue.sessionProperties,
138
- };
139
128
  const mergedValue = {
140
129
  requiredScopes: mergedRequiredScopes,
141
130
  optionalScopes: mergedOptionalScopes,
142
- sessionProperties: mergedSessionProperties,
143
131
  isMultichainOrigin: leftValue.isMultichainOrigin,
144
132
  };
145
133
  const partialDiff = diffScopesForCaip25CaveatValue(leftValue, mergedValue, 'requiredScopes');
@@ -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,EAGnB,wBAAwB;;;AAGzB,OAAO,EAAE,4BAA4B,EAAE,2BAAuB;AAC9D,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,0BAA0B,EAC3B,8BAA0B;AAC3B,OAAO,EAAE,mBAAmB,EAAE,8BAA0B;AACxD,OAAO,EACL,gBAAgB,EAIjB,0BAAsB;AAcvB;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,kBAAkB,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC7D,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AASF;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAC5C,aAAgC,EAChC,WAA8B,EAC9B,WAAgD;IAEhD,MAAM,IAAI,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;IAEtC,MAAM,iBAAiB,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IACnD,KAAK,MAAM,CAAC,WAAW,EAAE,iBAAiB,CAAC,IAAI,MAAM,CAAC,OAAO,CAC3D,iBAAiB,CAClB,EAAE;QACD,MAAM,mBAAmB,GAAG,WAA6C,CAAC;QAC1E,MAAM,mBAAmB,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;QAEnE,IAAI,mBAA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SAAS,KAAK,kBAAkB,CAAC,MAAM,CAAC;IACjD,CAAC,CACF,CAAC;IAEF,IAAI,kBAAkB,EAAE;QACtB,OAAO;YACL,SAAS,EAAE,sBAAsB,CAAC,WAAW;YAC7C,KAAK,EAAE,kBAAkB;SAC1B,CAAC;KACH;IAED,OAAO;QACL,SAAS,EAAE,sBAAsB,CAAC,gBAAgB;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport type { CaipAccountId, CaipChainId, Json } from '@metamask/utils';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n type Hex,\n type NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual } from 'lodash';\n\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport {\n isSupportedAccount,\n isSupportedScopeString,\n isSupportedSessionProperty,\n} from './scope/supported';\nimport { mergeInternalScopes } from './scope/transform';\nimport {\n parseScopeString,\n type ExternalScopeString,\n type InternalScopeObject,\n type InternalScopesObject,\n} from './scope/types';\n\n/**\n * The CAIP-25 permission caveat value.\n * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.\n * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.\n */\nexport type Caip25CaveatValue = {\n requiredScopes: InternalScopesObject;\n optionalScopes: InternalScopesObject;\n sessionProperties: Record<string, Json>;\n isMultichainOrigin: boolean;\n};\n\n/**\n * The name of the CAIP-25 permission caveat.\n */\nexport const Caip25CaveatType = 'authorizedScopes';\n\n/**\n * The target name of the CAIP-25 endowment permission.\n */\nexport const Caip25EndowmentPermissionName = 'endowment:caip25';\n\n/**\n * Creates a CAIP-25 permission caveat.\n *\n * @param value - The CAIP-25 permission caveat value.\n * @returns The CAIP-25 permission caveat (now including the type).\n */\nexport const createCaip25Caveat = (value: Caip25CaveatValue) => {\n return {\n type: Caip25CaveatType,\n value,\n };\n};\n\ntype Caip25EndowmentCaveatSpecificationBuilderOptions = {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;\n listAccounts: () => { type: string; address: Hex }[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n};\n\n/**\n * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.\n *\n * @param originalValue - The existing CAIP-25 permission caveat value.\n * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.\n * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.\n * @returns The difference between original and merged CAIP-25 permission caveat values.\n */\nexport function diffScopesForCaip25CaveatValue(\n originalValue: Caip25CaveatValue,\n mergedValue: Caip25CaveatValue,\n scopeToDiff: 'optionalScopes' | 'requiredScopes',\n): Caip25CaveatValue {\n const diff = cloneDeep(originalValue);\n\n const mergedScopeToDiff = mergedValue[scopeToDiff];\n for (const [scopeString, mergedScopeObject] of Object.entries(\n mergedScopeToDiff,\n )) {\n const internalScopeString = scopeString as keyof typeof mergedScopeToDiff;\n const originalScopeObject = diff[scopeToDiff][internalScopeString];\n\n if (originalScopeObject) {\n const newAccounts = mergedScopeObject.accounts.filter(\n (account) => !originalScopeObject?.accounts.includes(account),\n );\n if (newAccounts.length > 0) {\n diff[scopeToDiff][internalScopeString] = {\n accounts: newAccounts,\n };\n continue;\n }\n delete diff[scopeToDiff][internalScopeString];\n } else {\n diff[scopeToDiff][internalScopeString] = mergedScopeObject;\n }\n }\n\n return diff;\n}\n\n/**\n * Checks if every account in the given scopes object is supported.\n *\n * @param scopesObject - The scopes object to iterate over.\n * @param listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * addresses.\n * @returns True if every account in the scopes object is supported, false otherwise.\n */\nfunction isEveryAccountInScopesObjectSupported(\n scopesObject: InternalScopesObject,\n listAccounts: () => { type: string; address: Hex }[],\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[],\n) {\n return Object.values(scopesObject).every((scopeObject) =>\n scopeObject.accounts.every((account) =>\n isSupportedAccount(account, {\n getEvmInternalAccounts: listAccounts,\n getNonEvmAccountAddresses,\n }),\n ),\n );\n}\n\n/**\n * Helper that returns a `authorizedScopes` CAIP-25 caveat specification\n * that can be passed into the PermissionController constructor.\n *\n * @param options - The specification builder options.\n * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.\n * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.\n * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns The specification for the `caip25` caveat.\n */\nexport const caip25CaveatBuilder = ({\n findNetworkClientIdByChainId,\n listAccounts,\n isNonEvmScopeSupported,\n getNonEvmAccountAddresses,\n}: Caip25EndowmentCaveatSpecificationBuilderOptions): EndowmentCaveatSpecificationConstraint &\n Required<\n Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>\n > => {\n return {\n type: Caip25CaveatType,\n validator: (\n caveat: { type: typeof Caip25CaveatType; value: unknown },\n _origin?: string,\n _target?: string,\n ) => {\n if (\n !caveat.value ||\n !hasProperty(caveat.value, 'requiredScopes') ||\n !hasProperty(caveat.value, 'optionalScopes') ||\n !hasProperty(caveat.value, 'isMultichainOrigin') ||\n !hasProperty(caveat.value, 'sessionProperties') ||\n typeof caveat.value.isMultichainOrigin !== 'boolean' ||\n typeof caveat.value.sessionProperties !== 'object' ||\n caveat.value.sessionProperties === null\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 unknownSessionProperties = Object.keys(sessionProperties).filter(\n (key) => !isSupportedSessionProperty(key),\n );\n\n if (unknownSessionProperties.length > 0) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received unknown session property(s) for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedSessionProperties = {\n ...leftValue.sessionProperties,\n ...rightValue.sessionProperties,\n };\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\n sessionProperties: mergedSessionProperties,\n isMultichainOrigin: leftValue.isMultichainOrigin,\n };\n\n const partialDiff = diffScopesForCaip25CaveatValue(\n leftValue,\n mergedValue,\n 'requiredScopes',\n );\n\n const diff = diffScopesForCaip25CaveatValue(\n partialDiff,\n mergedValue,\n 'optionalScopes',\n );\n\n return [mergedValue, diff];\n },\n };\n};\n\ntype Caip25EndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof Caip25EndowmentPermissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => null;\n validator: PermissionValidatorConstraint;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * Helper that returns a `endowment:caip25` specification that\n * can be passed into the PermissionController constructor.\n *\n * @returns The specification for the `caip25` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n Record<never, never>,\n Caip25EndowmentSpecification\n> = () => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: Caip25EndowmentPermissionName,\n allowedCaveats: [Caip25CaveatType],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => null,\n validator: (permission: PermissionConstraint) => {\n if (\n permission.caveats?.length !== 1 ||\n permission.caveats?.[0]?.type !== Caip25CaveatType\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Invalid caveats. There must be a single caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n },\n };\n};\n\n/**\n * The `caip25` endowment specification builder. Passed to the\n * `PermissionController` for constructing and validating the\n * `endowment:caip25` permission.\n */\nexport const caip25EndowmentBuilder = Object.freeze({\n targetName: Caip25EndowmentPermissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Factories that construct caveat mutator functions that are passed to\n * PermissionController.updatePermissionsByCaveat.\n */\nexport const Caip25CaveatMutators = {\n [Caip25CaveatType]: {\n removeScope,\n removeAccount,\n },\n};\n\n/**\n * Removes the account from the scope object.\n *\n * @param targetAddress - The address to remove from the scope object.\n * @returns A function that removes the account from the scope object.\n */\nfunction removeAccountFilterFn(targetAddress: string) {\n return (account: CaipAccountId) => {\n const parsed = parseCaipAccountId(account);\n return parsed.address !== targetAddress;\n };\n}\n\n/**\n * Removes the account from the scope object.\n *\n * @param scopeObject - The scope object to remove the account from.\n * @param targetAddress - The address to remove from the scope object.\n */\nfunction removeAccountFromScopeObject(\n scopeObject: InternalScopeObject,\n targetAddress: string,\n) {\n if (scopeObject.accounts) {\n scopeObject.accounts = scopeObject.accounts.filter(\n removeAccountFilterFn(targetAddress),\n );\n }\n}\n\n/**\n * Removes the target account from the scope object.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).\n * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.\n * @returns The updated scope object.\n */\nfunction removeAccount(\n caip25CaveatValue: Caip25CaveatValue,\n targetAddress: Hex,\n) {\n const updatedCaveatValue = cloneDeep(caip25CaveatValue);\n\n [\n updatedCaveatValue.requiredScopes,\n updatedCaveatValue.optionalScopes,\n ].forEach((scopes) => {\n Object.entries(scopes).forEach(([, scopeObject]) => {\n removeAccountFromScopeObject(scopeObject, targetAddress);\n });\n });\n\n const noChange = isEqual(updatedCaveatValue, caip25CaveatValue);\n\n if (noChange) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const hasAccounts = [\n ...Object.values(updatedCaveatValue.requiredScopes),\n ...Object.values(updatedCaveatValue.optionalScopes),\n ].some(({ accounts }) => accounts.length > 0);\n\n if (hasAccounts) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Removes the target scope from the value arrays of the given\n * `endowment:caip25` caveat. No-ops if the target scopeString is not in\n * the existing scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.\n * @param targetScopeString - The scope that is being removed.\n * @returns The updated CAIP-25 permission caveat value.\n */\nfunction removeScope(\n caip25CaveatValue: Caip25CaveatValue,\n targetScopeString: ExternalScopeString,\n) {\n const newRequiredScopes = Object.entries(\n caip25CaveatValue.requiredScopes,\n ).filter(([scope]) => scope !== targetScopeString);\n const newOptionalScopes = Object.entries(\n caip25CaveatValue.optionalScopes,\n ).filter(([scope]) => {\n return scope !== targetScopeString;\n });\n\n const requiredScopesRemoved =\n newRequiredScopes.length !==\n Object.keys(caip25CaveatValue.requiredScopes).length;\n const optionalScopesRemoved =\n newOptionalScopes.length !==\n Object.keys(caip25CaveatValue.optionalScopes).length;\n\n if (!requiredScopesRemoved && !optionalScopesRemoved) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const updatedCaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: Object.fromEntries(newRequiredScopes),\n optionalScopes: Object.fromEntries(newOptionalScopes),\n };\n\n const hasNonWalletScopes = [...newRequiredScopes, ...newOptionalScopes].some(\n ([scopeString]) => {\n const { namespace } = parseScopeString(scopeString);\n return namespace !== KnownCaipNamespace.Wallet;\n },\n );\n\n if (hasNonWalletScopes) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n"]}
1
+ {"version":3,"file":"caip25Permission.mjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AASA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;AAEzC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAG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AW,CAAC,iBAAiB,CAAC;QACrD,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;KACtD,CAAC;IAEF,MAAM,kBAAkB,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,iBAAiB,CAAC,CAAC,IAAI,CAC1E,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE;QAChB,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACpD,OAAO,SAAS,KAAK,kBAAkB,CAAC,MAAM,CAAC;IACjD,CAAC,CACF,CAAC;IAEF,IAAI,kBAAkB,EAAE;QACtB,OAAO;YACL,SAAS,EAAE,sBAAsB,CAAC,WAAW;YAC7C,KAAK,EAAE,kBAAkB;SAC1B,CAAC;KACH;IAED,OAAO;QACL,SAAS,EAAE,sBAAsB,CAAC,gBAAgB;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport type { CaipAccountId, CaipChainId, Json } from '@metamask/utils';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n type Hex,\n type NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual } from 'lodash';\n\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport { isSupportedAccount, isSupportedScopeString } 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 typeof caveat.value.isMultichainOrigin !== 'boolean'\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received invalid value for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const { requiredScopes, optionalScopes } = caveat.value;\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\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"]}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Caip25CaveatMutators = exports.caip25EndowmentBuilder = exports.Caip25EndowmentPermissionName = exports.createCaip25Caveat = exports.Caip25CaveatType = exports.caip25CaveatBuilder = exports.normalizeAndMergeScopes = exports.mergeInternalScopes = exports.mergeNormalizedScopes = exports.mergeScopeObject = exports.normalizeScope = exports.getUniqueArrayItems = exports.parseScopeString = exports.getSupportedScopeObjects = exports.KnownWalletScopeString = exports.KnownNotifications = exports.KnownWalletNamespaceRpcMethods = exports.KnownRpcMethods = exports.KnownWalletRpcMethods = exports.assertIsInternalScopeString = exports.bucketScopes = exports.validateAndNormalizeScopes = exports.getPermittedAccountsForScopes = exports.getSessionScopes = exports.getInternalScopesObject = exports.setPermittedEthChainIds = exports.addPermittedEthChainId = exports.getPermittedEthChainIds = exports.setEthAccounts = exports.getEthAccounts = void 0;
3
+ exports.Caip25CaveatMutators = exports.caip25EndowmentBuilder = exports.Caip25EndowmentPermissionName = exports.createCaip25Caveat = exports.Caip25CaveatType = exports.caip25CaveatBuilder = exports.normalizeAndMergeScopes = exports.mergeInternalScopes = exports.mergeNormalizedScopes = exports.mergeScopeObject = exports.normalizeScope = exports.getUniqueArrayItems = exports.parseScopeString = exports.getSupportedScopeObjects = exports.KnownWalletScopeString = exports.KnownNotifications = exports.KnownWalletNamespaceRpcMethods = exports.KnownRpcMethods = exports.KnownWalletRpcMethods = exports.assertIsInternalScopeString = exports.bucketScopes = exports.validateAndNormalizeScopes = exports.getSessionScopes = exports.getInternalScopesObject = exports.setPermittedEthChainIds = exports.addPermittedEthChainId = exports.getPermittedEthChainIds = exports.setEthAccounts = exports.getEthAccounts = void 0;
4
4
  var caip_permission_adapter_eth_accounts_1 = require("./adapters/caip-permission-adapter-eth-accounts.cjs");
5
5
  Object.defineProperty(exports, "getEthAccounts", { enumerable: true, get: function () { return caip_permission_adapter_eth_accounts_1.getEthAccounts; } });
6
6
  Object.defineProperty(exports, "setEthAccounts", { enumerable: true, get: function () { return caip_permission_adapter_eth_accounts_1.setEthAccounts; } });
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "setPermittedEthChainIds", { enumerable: true, ge
11
11
  var caip_permission_adapter_session_scopes_1 = require("./adapters/caip-permission-adapter-session-scopes.cjs");
12
12
  Object.defineProperty(exports, "getInternalScopesObject", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getInternalScopesObject; } });
13
13
  Object.defineProperty(exports, "getSessionScopes", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getSessionScopes; } });
14
- Object.defineProperty(exports, "getPermittedAccountsForScopes", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getPermittedAccountsForScopes; } });
15
14
  var authorization_1 = require("./scope/authorization.cjs");
16
15
  Object.defineProperty(exports, "validateAndNormalizeScopes", { enumerable: true, get: function () { return authorization_1.validateAndNormalizeScopes; } });
17
16
  Object.defineProperty(exports, "bucketScopes", { enumerable: true, get: function () { return authorization_1.bucketScopes; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4GAGyD;AAFvD,sIAAA,cAAc,OAAA;AACd,sIAAA,cAAc,OAAA;AAEhB,kHAI4D;AAH1D,kJAAA,uBAAuB,OAAA;AACvB,iJAAA,sBAAsB,OAAA;AACtB,kJAAA,uBAAuB,OAAA;AAEzB,gHAI2D;AAHzD,iJAAA,uBAAuB,OAAA;AACvB,0IAAA,gBAAgB,OAAA;AAChB,uJAAA,6BAA6B,OAAA;AAI/B,2DAG+B;AAF7B,2HAAA,0BAA0B,OAAA;AAC1B,6GAAA,YAAY,OAAA;AAEd,6CAA6D;AAApD,qHAAA,2BAA2B,OAAA;AACpC,mDAM2B;AALzB,kHAAA,qBAAqB,OAAA;AACrB,4GAAA,eAAe,OAAA;AACf,2HAAA,8BAA8B,OAAA;AAC9B,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AAExB,6CAA0D;AAAjD,kHAAA,wBAAwB,OAAA;AAajC,2CAAiD;AAAxC,yGAAA,gBAAgB,OAAA;AACzB,mDAO2B;AANzB,gHAAA,mBAAmB,OAAA;AACnB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,kHAAA,qBAAqB,OAAA;AACrB,gHAAA,mBAAmB,OAAA;AACnB,oHAAA,uBAAuB,OAAA;AAIzB,2DAO4B;AAN1B,uHAAA,mBAAmB,OAAA;AACnB,oHAAA,gBAAgB,OAAA;AAChB,sHAAA,kBAAkB,OAAA;AAClB,iIAAA,6BAA6B,OAAA;AAC7B,0HAAA,sBAAsB,OAAA;AACtB,wHAAA,oBAAoB,OAAA","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n} from './adapters/caip-permission-adapter-eth-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n} from './caip25Permission';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4GAGyD;AAFvD,sIAAA,cAAc,OAAA;AACd,sIAAA,cAAc,OAAA;AAEhB,kHAI4D;AAH1D,kJAAA,uBAAuB,OAAA;AACvB,iJAAA,sBAAsB,OAAA;AACtB,kJAAA,uBAAuB,OAAA;AAEzB,gHAG2D;AAFzD,iJAAA,uBAAuB,OAAA;AACvB,0IAAA,gBAAgB,OAAA;AAIlB,2DAG+B;AAF7B,2HAAA,0BAA0B,OAAA;AAC1B,6GAAA,YAAY,OAAA;AAEd,6CAA6D;AAApD,qHAAA,2BAA2B,OAAA;AACpC,mDAM2B;AALzB,kHAAA,qBAAqB,OAAA;AACrB,4GAAA,eAAe,OAAA;AACf,2HAAA,8BAA8B,OAAA;AAC9B,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AAExB,6CAA0D;AAAjD,kHAAA,wBAAwB,OAAA;AAajC,2CAAiD;AAAxC,yGAAA,gBAAgB,OAAA;AACzB,mDAO2B;AANzB,gHAAA,mBAAmB,OAAA;AACnB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,kHAAA,qBAAqB,OAAA;AACrB,gHAAA,mBAAmB,OAAA;AACnB,oHAAA,uBAAuB,OAAA;AAIzB,2DAO4B;AAN1B,uHAAA,mBAAmB,OAAA;AACnB,oHAAA,gBAAgB,OAAA;AAChB,sHAAA,kBAAkB,OAAA;AAClB,iIAAA,6BAA6B,OAAA;AAC7B,0HAAA,sBAAsB,OAAA;AACtB,wHAAA,oBAAoB,OAAA","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n} from './adapters/caip-permission-adapter-eth-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n} from './caip25Permission';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { getEthAccounts, setEthAccounts, } from "./adapters/caip-permission-adapter-eth-accounts.cjs";
2
2
  export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, } from "./adapters/caip-permission-adapter-permittedChains.cjs";
3
- export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes, } from "./adapters/caip-permission-adapter-session-scopes.cjs";
3
+ export { getInternalScopesObject, getSessionScopes, } from "./adapters/caip-permission-adapter-session-scopes.cjs";
4
4
  export type { Caip25Authorization } from "./scope/authorization.cjs";
5
5
  export { validateAndNormalizeScopes, bucketScopes, } from "./scope/authorization.cjs";
6
6
  export { assertIsInternalScopeString } from "./scope/assert.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,GACf,4DAAwD;AACzD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,GACxB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,GACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,GACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,GACrB,+BAA2B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,GACf,4DAAwD;AACzD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,GACxB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,GACjB,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,GACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,GACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,GACrB,+BAA2B"}
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { getEthAccounts, setEthAccounts, } from "./adapters/caip-permission-adapter-eth-accounts.mjs";
2
2
  export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, } from "./adapters/caip-permission-adapter-permittedChains.mjs";
3
- export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes, } from "./adapters/caip-permission-adapter-session-scopes.mjs";
3
+ export { getInternalScopesObject, getSessionScopes, } from "./adapters/caip-permission-adapter-session-scopes.mjs";
4
4
  export type { Caip25Authorization } from "./scope/authorization.mjs";
5
5
  export { validateAndNormalizeScopes, bucketScopes, } from "./scope/authorization.mjs";
6
6
  export { assertIsInternalScopeString } from "./scope/assert.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,GACf,4DAAwD;AACzD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,GACxB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,GACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,GACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,GACrB,+BAA2B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,GACf,4DAAwD;AACzD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,GACxB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,GACjB,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,GACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,GACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,GACrB,+BAA2B"}
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  export { getEthAccounts, setEthAccounts } from "./adapters/caip-permission-adapter-eth-accounts.mjs";
2
2
  export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds } from "./adapters/caip-permission-adapter-permittedChains.mjs";
3
- export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes } from "./adapters/caip-permission-adapter-session-scopes.mjs";
3
+ export { getInternalScopesObject, getSessionScopes } from "./adapters/caip-permission-adapter-session-scopes.mjs";
4
4
  export { validateAndNormalizeScopes, bucketScopes } from "./scope/authorization.mjs";
5
5
  export { assertIsInternalScopeString } from "./scope/assert.mjs";
6
6
  export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownNotifications, KnownWalletScopeString } from "./scope/constants.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACf,4DAAwD;AACzD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACxB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,EAC9B,8DAA0D;AAG3D,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,EACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAa1D,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACxB,8BAA0B;AAG3B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACrB,+BAA2B","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n} from './adapters/caip-permission-adapter-eth-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n} from './caip25Permission';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACf,4DAAwD;AACzD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACxB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EACjB,8DAA0D;AAG3D,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,EACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAa1D,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACxB,8BAA0B;AAG3B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACrB,+BAA2B","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n} from './adapters/caip-permission-adapter-eth-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n} from './caip25Permission';\n"]}
@@ -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.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.
@@ -80,11 +80,4 @@ exports.KnownNotifications = {
80
80
  bip122: [],
81
81
  solana: [],
82
82
  };
83
- /**
84
- * Session properties for known CAIP namespaces.
85
- */
86
- var KnownSessionProperties;
87
- (function (KnownSessionProperties) {
88
- KnownSessionProperties["SolanaAccountChangedNotifications"] = "solana_accountChanged_notifications";
89
- })(KnownSessionProperties || (exports.KnownSessionProperties = KnownSessionProperties = {}));
90
83
  //# 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,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AAE,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","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"]}
@@ -29,10 +29,4 @@ export declare const KnownWalletNamespaceRpcMethods: Record<NonWalletKnownCaipNa
29
29
  * Notifications for known CAIP namespaces.
30
30
  */
31
31
  export declare const KnownNotifications: Record<NonWalletKnownCaipNamespace, string[]>;
32
- /**
33
- * Session properties for known CAIP namespaces.
34
- */
35
- export declare enum KnownSessionProperties {
36
- SolanaAccountChangedNotifications = "solana_accountChanged_notifications"
37
- }
38
32
  //# 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,MAAM,EAGzC,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,kBAAkB,UAa9B,CAAC;AAWF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,2BAA2B,EAAE,MAAM,EAAE,CAIzE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAAM,CACjD,2BAA2B,EAC3B,MAAM,EAAE,CAKT,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,2BAA2B,EAAE,MAAM,EAAE,CAK1E,CAAC;AAEJ;;GAEG;AACH,oBAAY,sBAAsB;IAChC,iCAAiC,wCAAwC;CAC1E"}
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,MAAM,EAGzC,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,kBAAkB,UAa9B,CAAC;AAWF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,2BAA2B,EAAE,MAAM,EAAE,CAIzE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAAM,CACjD,2BAA2B,EAC3B,MAAM,EAAE,CAKT,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,2BAA2B,EAAE,MAAM,EAAE,CAK1E,CAAC"}
@@ -29,10 +29,4 @@ export declare const KnownWalletNamespaceRpcMethods: Record<NonWalletKnownCaipNa
29
29
  * Notifications for known CAIP namespaces.
30
30
  */
31
31
  export declare const KnownNotifications: Record<NonWalletKnownCaipNamespace, string[]>;
32
- /**
33
- * Session properties for known CAIP namespaces.
34
- */
35
- export declare enum KnownSessionProperties {
36
- SolanaAccountChangedNotifications = "solana_accountChanged_notifications"
37
- }
38
32
  //# sourceMappingURL=constants.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../src/scope/constants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAgB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AkB,EAAE,MAAM,CAAC,2BAA2B,EAAE,MAAM,EAAE,CAK1E,CAAC"}
@@ -81,11 +81,4 @@ export const KnownNotifications = {
81
81
  bip122: [],
82
82
  solana: [],
83
83
  };
84
- /**
85
- * Session properties for known CAIP namespaces.
86
- */
87
- export var KnownSessionProperties;
88
- (function (KnownSessionProperties) {
89
- KnownSessionProperties["SolanaAccountChangedNotifications"] = "solana_accountChanged_notifications";
90
- })(KnownSessionProperties || (KnownSessionProperties = {}));
91
84
  //# sourceMappingURL=constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../src/scope/constants.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,wBAAuB,4BAA4B;;AAI1D;;GAEG;AACH,MAAM,CAAN,IAAY,sBAEX;AAFD,WAAY,sBAAsB;IAChC,kDAAwB,CAAA;AAC1B,CAAC,EAFW,sBAAsB,KAAtB,sBAAsB,QAEjC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAC/B;IACE,MAAM,EAAE,oBAAoB;IAC5B,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,KAAK;CACd,CAAC;AAEJ;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAa;IAC7C,2BAA2B;IAC3B,mBAAmB;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAExD;;GAEG;AACH,MAAM,CAAC,MAAM,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,uBAAuB,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,qBAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;KACnE,MAAM,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAkD;IAC5E,MAAM,EAAE,aAAa;IACrB,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACX,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAGvC;IACF,MAAM,EAAE,mBAAmB;IAC3B,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACX,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B;IACE,MAAM,EAAE,CAAC,kBAAkB,CAAC;IAC5B,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACX,CAAC;AAEJ;;GAEG;AACH,MAAM,CAAN,IAAY,sBAEX;AAFD,WAAY,sBAAsB;IAChC,mGAAyE,CAAA;AAC3E,CAAC,EAFW,sBAAsB,KAAtB,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.mjs","sourceRoot":"","sources":["../../src/scope/constants.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,wBAA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AE;CACX,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAGvC;IACF,MAAM,EAAE,mBAAmB;IAC3B,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACX,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B;IACE,MAAM,EAAE,CAAC,kBAAkB,CAAC;IAC5B,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACX,CAAC","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"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSupportedSessionProperty = exports.isSupportedNotification = exports.isSupportedMethod = exports.isSupportedAccount = exports.isSupportedScopeString = void 0;
3
+ exports.isSupportedNotification = exports.isSupportedMethod = exports.isSupportedAccount = exports.isSupportedScopeString = void 0;
4
4
  const controller_utils_1 = require("@metamask/controller-utils");
5
5
  const utils_1 = require("@metamask/utils");
6
6
  const constants_1 = require("./constants.cjs");
@@ -113,14 +113,4 @@ const isSupportedNotification = (scopeString, notification) => {
113
113
  return false;
114
114
  };
115
115
  exports.isSupportedNotification = isSupportedNotification;
116
- /**
117
- * Determines if a session property is supported by the wallet.
118
- *
119
- * @param property - The property to check.
120
- * @returns A boolean indicating if the property is supported by the wallet.
121
- */
122
- const isSupportedSessionProperty = (property) => {
123
- return Object.values(constants_1.KnownSessionProperties).includes(property);
124
- };
125
- exports.isSupportedSessionProperty = isSupportedSessionProperty;
126
116
  //# sourceMappingURL=supported.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"supported.cjs","sourceRoot":"","sources":["../../src/scope/supported.ts"],"names":[],"mappings":";;;AAAA,iEAA2E;AAE3E,2CAIyB;AAEzB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CAA8B,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SACnE;QAED,OAAO,uBAAuB,EAAE,CAAC;KAClC;IAED,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,EAAE;QAC3C,OAAO,2BAAe,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;KACpD;IACD,gEAAgE;IAEhE,OAAO,uBAAuB,EAAE,CAAC;AACnC,CAAC,CAAC;AAvCW,QAAA,iBAAiB,qBAuC5B;AAEF;;;;;;GAMG;AACI,MAAM,uBAAuB,GAAG,CACrC,WAAgC,EAChC,YAAoB,EACX,EAAE;IACX,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAEpD,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,EAAE;QAC3C,OAAO,8BAAkB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;KAC7D;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAXW,QAAA,uBAAuB,2BAWlC;AAEF;;;;;GAKG;AACI,MAAM,0BAA0B,GAAG,CAAC,QAAgB,EAAW,EAAE;IACtE,OAAO,MAAM,CAAC,MAAM,CAAC,kCAAsB,CAAC,CAAC,QAAQ,CACnD,QAAkC,CACnC,CAAC;AACJ,CAAC,CAAC;AAJW,QAAA,0BAA0B,8BAIrC","sourcesContent":["import { toHex, isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type { CaipAccountId, CaipChainId, Hex } from '@metamask/utils';\nimport {\n isCaipChainId,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport {\n CaipReferenceRegexes,\n KnownNotifications,\n KnownRpcMethods,\n KnownSessionProperties,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from './constants';\nimport type { ExternalScopeString } from './types';\nimport { parseScopeString } from './types';\n\n/**\n * Determines if a scope string is supported.\n *\n * @param scopeString - The scope string to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @returns A boolean indicating if the scope string is supported.\n */\nexport const isSupportedScopeString = (\n scopeString: string,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n },\n) => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n switch (namespace) {\n case KnownCaipNamespace.Wallet:\n if (\n isCaipChainId(scopeString) &&\n reference !== KnownCaipNamespace.Eip155\n ) {\n return isNonEvmScopeSupported(scopeString);\n }\n return true;\n case KnownCaipNamespace.Eip155:\n return (\n !reference ||\n (CaipReferenceRegexes.eip155.test(reference) &&\n isEvmChainIdSupported(toHex(reference)))\n );\n default:\n return isCaipChainId(scopeString)\n ? isNonEvmScopeSupported(scopeString)\n : false;\n }\n};\n\n/**\n * Determines if an account is supported by the wallet (i.e. on a keyring known to the wallet).\n *\n * @param account - The CAIP account ID to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.getEvmInternalAccounts - A function that returns the EVM internal accounts.\n * @param hooks.getNonEvmAccountAddresses - A function that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns A boolean indicating if the account is supported by the wallet.\n */\nexport const isSupportedAccount = (\n account: CaipAccountId,\n {\n getEvmInternalAccounts,\n getNonEvmAccountAddresses,\n }: {\n getEvmInternalAccounts: () => { type: string; address: Hex }[];\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n },\n) => {\n const {\n address,\n chainId,\n chain: { namespace, reference },\n } = parseCaipAccountId(account);\n\n const isSupportedEip155Account = () =>\n getEvmInternalAccounts().some(\n (internalAccount) =>\n ['eip155:eoa', 'eip155:erc4337'].includes(internalAccount.type) &&\n isEqualCaseInsensitive(address, internalAccount.address),\n );\n\n const isSupportedNonEvmAccount = () =>\n getNonEvmAccountAddresses(chainId).includes(account);\n\n // We are trying to discern the type of `namespace`.\n /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n switch (namespace) {\n case KnownCaipNamespace.Wallet:\n if (reference === KnownCaipNamespace.Eip155) {\n return isSupportedEip155Account();\n }\n return isSupportedNonEvmAccount();\n case KnownCaipNamespace.Eip155:\n return isSupportedEip155Account();\n default:\n return isSupportedNonEvmAccount();\n }\n /* eslint-enable @typescript-eslint/no-unsafe-enum-comparison */\n};\n\n/**\n * Determines if a method is supported by the wallet.\n *\n * @param scopeString - The scope string to check.\n * @param method - The method to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A boolean indicating if the method is supported by the wallet.\n */\nexport const isSupportedMethod = (\n scopeString: ExternalScopeString,\n method: string,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n): boolean => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n if (!namespace) {\n return false;\n }\n\n const isSupportedNonEvmMethod = () =>\n isCaipChainId(scopeString) &&\n getNonEvmSupportedMethods(scopeString).includes(method);\n\n // We are trying to discern the type of `namespace`.\n /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n if (namespace === KnownCaipNamespace.Wallet) {\n if (!reference) {\n return KnownWalletRpcMethods.includes(method);\n }\n\n if (reference === KnownCaipNamespace.Eip155) {\n return KnownWalletNamespaceRpcMethods[reference].includes(method);\n }\n\n return isSupportedNonEvmMethod();\n }\n\n if (namespace === KnownCaipNamespace.Eip155) {\n return KnownRpcMethods[namespace].includes(method);\n }\n /* eslint-enable @typescript-eslint/no-unsafe-enum-comparison */\n\n return isSupportedNonEvmMethod();\n};\n\n/**\n * Determines if a notification is supported by the wallet.\n *\n * @param scopeString - The scope string to check.\n * @param notification - The notification to check.\n * @returns A boolean indicating if the notification is supported by the wallet.\n */\nexport const isSupportedNotification = (\n scopeString: ExternalScopeString,\n notification: string,\n): boolean => {\n const { namespace } = parseScopeString(scopeString);\n\n if (namespace === KnownCaipNamespace.Eip155) {\n return KnownNotifications[namespace].includes(notification);\n }\n\n return false;\n};\n\n/**\n * Determines if a session property is supported by the wallet.\n *\n * @param property - The property to check.\n * @returns A boolean indicating if the property is supported by the wallet.\n */\nexport const isSupportedSessionProperty = (property: string): boolean => {\n return Object.values(KnownSessionProperties).includes(\n property as KnownSessionProperties,\n );\n};\n"]}
1
+ {"version":3,"file":"supported.cjs","sourceRoot":"","sources":["../../src/scope/supported.ts"],"names":[],"mappings":";;;AAAA,iEAA2E;AAE3E,2CAIyB;AAEzB,+CAMqB;AAErB,uCAA2C;AAE3C;;;;;;;;GAQG;AACI,MAAM,sBAAsB,GAAG,CACpC,WAAmB,EACnB,EACE,qBAAqB,EACrB,sBAAsB,GAIvB,EACD,EAAE;IACF,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAE/D,QAAQ,SAAS,EAAE;QACjB,KAAK,0BAAkB,CAAC,MAAM;YAC5B,IACE,IAAA,qBAAa,EAAC,WAAW,CAAC;gBAC1B,SAAS,KAAK,0BAAkB,CAAC,MAAM,EACvC;gBACA,OAAO,sBAAsB,CAAC,WAAW,CAAC,CAAC;aAC5C;YACD,OAAO,IAAI,CAAC;QACd,KAAK,0BAAkB,CAAC,MAAM;YAC5B,OAAO,CACL,CAAC,SAAS;gBACV,CAAC,gCAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;oBAC1C,qBAAqB,CAAC,IAAA,wBAAK,EAAC,SAAS,CAAC,CAAC,CAAC,CAC3C,CAAC;QACJ;YACE,OAAO,IAAA,qBAAa,EAAC,WAAW,CAAC;gBAC/B,CAAC,CAAC,sBAAsB,CAAC,WAAW,CAAC;gBACrC,CAAC,CAAC,KAAK,CAAC;KACb;AACH,CAAC,CAAC;AA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I,CAAC,SAAS,EAAE;QACd,OAAO,KAAK,CAAC;KACd;IAED,MAAM,uBAAuB,GAAG,GAAG,EAAE,CACnC,IAAA,qBAAa,EAAC,WAAW,CAAC;QAC1B,yBAAyB,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE1D,oDAAoD;IACpD,iEAAiE;IACjE,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,EAAE;QAC3C,IAAI,CAAC,SAAS,EAAE;YACd,OAAO,iCAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SAC/C;QAED,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,EAAE;YAC3C,OAAO,0CAA8B,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SACnE;QAED,OAAO,uBAAuB,EAAE,CAAC;KAClC;IAED,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,EAAE;QAC3C,OAAO,2BAAe,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;KACpD;IACD,gEAAgE;IAEhE,OAAO,uBAAuB,EAAE,CAAC;AACnC,CAAC,CAAC;AAvCW,QAAA,iBAAiB,qBAuC5B;AAEF;;;;;;GAMG;AACI,MAAM,uBAAuB,GAAG,CACrC,WAAgC,EAChC,YAAoB,EACX,EAAE;IACX,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAEpD,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,EAAE;QAC3C,OAAO,8BAAkB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;KAC7D;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAXW,QAAA,uBAAuB,2BAWlC","sourcesContent":["import { toHex, isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type { CaipAccountId, CaipChainId, Hex } from '@metamask/utils';\nimport {\n isCaipChainId,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport {\n CaipReferenceRegexes,\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from './constants';\nimport type { ExternalScopeString } from './types';\nimport { parseScopeString } from './types';\n\n/**\n * Determines if a scope string is supported.\n *\n * @param scopeString - The scope string to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @returns A boolean indicating if the scope string is supported.\n */\nexport const isSupportedScopeString = (\n scopeString: string,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n },\n) => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n switch (namespace) {\n case KnownCaipNamespace.Wallet:\n if (\n isCaipChainId(scopeString) &&\n reference !== KnownCaipNamespace.Eip155\n ) {\n return isNonEvmScopeSupported(scopeString);\n }\n return true;\n case KnownCaipNamespace.Eip155:\n return (\n !reference ||\n (CaipReferenceRegexes.eip155.test(reference) &&\n isEvmChainIdSupported(toHex(reference)))\n );\n default:\n return isCaipChainId(scopeString)\n ? isNonEvmScopeSupported(scopeString)\n : false;\n }\n};\n\n/**\n * Determines if an account is supported by the wallet (i.e. on a keyring known to the wallet).\n *\n * @param account - The CAIP account ID to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.getEvmInternalAccounts - A function that returns the EVM internal accounts.\n * @param hooks.getNonEvmAccountAddresses - A function that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns A boolean indicating if the account is supported by the wallet.\n */\nexport const isSupportedAccount = (\n account: CaipAccountId,\n {\n getEvmInternalAccounts,\n getNonEvmAccountAddresses,\n }: {\n getEvmInternalAccounts: () => { type: string; address: Hex }[];\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n },\n) => {\n const {\n address,\n chainId,\n chain: { namespace, reference },\n } = parseCaipAccountId(account);\n\n const isSupportedEip155Account = () =>\n getEvmInternalAccounts().some(\n (internalAccount) =>\n ['eip155:eoa', 'eip155:erc4337'].includes(internalAccount.type) &&\n isEqualCaseInsensitive(address, internalAccount.address),\n );\n\n const isSupportedNonEvmAccount = () =>\n getNonEvmAccountAddresses(chainId).includes(account);\n\n // We are trying to discern the type of `namespace`.\n /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n switch (namespace) {\n case KnownCaipNamespace.Wallet:\n if (reference === KnownCaipNamespace.Eip155) {\n return isSupportedEip155Account();\n }\n return isSupportedNonEvmAccount();\n case KnownCaipNamespace.Eip155:\n return isSupportedEip155Account();\n default:\n return isSupportedNonEvmAccount();\n }\n /* eslint-enable @typescript-eslint/no-unsafe-enum-comparison */\n};\n\n/**\n * Determines if a method is supported by the wallet.\n *\n * @param scopeString - The scope string to check.\n * @param method - The method to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A boolean indicating if the method is supported by the wallet.\n */\nexport const isSupportedMethod = (\n scopeString: ExternalScopeString,\n method: string,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n): boolean => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n if (!namespace) {\n return false;\n }\n\n const isSupportedNonEvmMethod = () =>\n isCaipChainId(scopeString) &&\n getNonEvmSupportedMethods(scopeString).includes(method);\n\n // We are trying to discern the type of `namespace`.\n /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n if (namespace === KnownCaipNamespace.Wallet) {\n if (!reference) {\n return KnownWalletRpcMethods.includes(method);\n }\n\n if (reference === KnownCaipNamespace.Eip155) {\n return KnownWalletNamespaceRpcMethods[reference].includes(method);\n }\n\n return isSupportedNonEvmMethod();\n }\n\n if (namespace === KnownCaipNamespace.Eip155) {\n return KnownRpcMethods[namespace].includes(method);\n }\n /* eslint-enable @typescript-eslint/no-unsafe-enum-comparison */\n\n return isSupportedNonEvmMethod();\n};\n\n/**\n * Determines if a notification is supported by the wallet.\n *\n * @param scopeString - The scope string to check.\n * @param notification - The notification to check.\n * @returns A boolean indicating if the notification is supported by the wallet.\n */\nexport const isSupportedNotification = (\n scopeString: ExternalScopeString,\n notification: string,\n): boolean => {\n const { namespace } = parseScopeString(scopeString);\n\n if (namespace === KnownCaipNamespace.Eip155) {\n return KnownNotifications[namespace].includes(notification);\n }\n\n return false;\n};\n"]}
@@ -49,11 +49,4 @@ export declare const isSupportedMethod: (scopeString: ExternalScopeString, metho
49
49
  * @returns A boolean indicating if the notification is supported by the wallet.
50
50
  */
51
51
  export declare const isSupportedNotification: (scopeString: ExternalScopeString, notification: string) => boolean;
52
- /**
53
- * Determines if a session property is supported by the wallet.
54
- *
55
- * @param property - The property to check.
56
- * @returns A boolean indicating if the property is supported by the wallet.
57
- */
58
- export declare const isSupportedSessionProperty: (property: string) => boolean;
59
52
  //# sourceMappingURL=supported.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"supported.d.cts","sourceRoot":"","sources":["../../src/scope/supported.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAevE,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAgB;AAGnD;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,gBACpB,MAAM;qCAKgB,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;aAyB1D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,YACpB,aAAa;4BAKI,MAAM;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,EAAE;uCAC3B,WAAW,KAAK,MAAM,EAAE;aAiC9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,gBACf,mBAAmB,UACxB,MAAM;uCAIuB,WAAW,KAAK,MAAM,EAAE;MAE5D,OA+BF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gBACrB,mBAAmB,gBAClB,MAAM,KACnB,OAQF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,aAAc,MAAM,KAAG,OAI7D,CAAC"}
1
+ {"version":3,"file":"supported.d.cts","sourceRoot":"","sources":["../../src/scope/supported.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAcvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAgB;AAGnD;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,gBACpB,MAAM;qCAKgB,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;aAyB1D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,YACpB,aAAa;4BAKI,MAAM;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,EAAE;uCAC3B,WAAW,KAAK,MAAM,EAAE;aAiC9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,gBACf,mBAAmB,UACxB,MAAM;uCAIuB,WAAW,KAAK,MAAM,EAAE;MAE5D,OA+BF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gBACrB,mBAAmB,gBAClB,MAAM,KACnB,OAQF,CAAC"}
@@ -49,11 +49,4 @@ export declare const isSupportedMethod: (scopeString: ExternalScopeString, metho
49
49
  * @returns A boolean indicating if the notification is supported by the wallet.
50
50
  */
51
51
  export declare const isSupportedNotification: (scopeString: ExternalScopeString, notification: string) => boolean;
52
- /**
53
- * Determines if a session property is supported by the wallet.
54
- *
55
- * @param property - The property to check.
56
- * @returns A boolean indicating if the property is supported by the wallet.
57
- */
58
- export declare const isSupportedSessionProperty: (property: string) => boolean;
59
52
  //# sourceMappingURL=supported.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"supported.d.mts","sourceRoot":"","sources":["../../src/scope/supported.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAevE,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAgB;AAGnD;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,gBACpB,MAAM;qCAKgB,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;aAyB1D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,YACpB,aAAa;4BAKI,MAAM;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,EAAE;uCAC3B,WAAW,KAAK,MAAM,EAAE;aAiC9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,gBACf,mBAAmB,UACxB,MAAM;uCAIuB,WAAW,KAAK,MAAM,EAAE;MAE5D,OA+BF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gBACrB,mBAAmB,gBAClB,MAAM,KACnB,OAQF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,aAAc,MAAM,KAAG,OAI7D,CAAC"}
1
+ {"version":3,"file":"supported.d.mts","sourceRoot":"","sources":["../../src/scope/supported.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAcvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAgB;AAGnD;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,gBACpB,MAAM;qCAKgB,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;aAyB1D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,YACpB,aAAa;4BAKI,MAAM;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,EAAE;uCAC3B,WAAW,KAAK,MAAM,EAAE;aAiC9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,gBACf,mBAAmB,UACxB,MAAM;uCAIuB,WAAW,KAAK,MAAM,EAAE;MAE5D,OA+BF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gBACrB,mBAAmB,gBAClB,MAAM,KACnB,OAQF,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { toHex, isEqualCaseInsensitive } from "@metamask/controller-utils";
2
2
  import { isCaipChainId, KnownCaipNamespace, parseCaipAccountId } from "@metamask/utils";
3
- import { CaipReferenceRegexes, KnownNotifications, KnownRpcMethods, KnownSessionProperties, KnownWalletNamespaceRpcMethods, KnownWalletRpcMethods } from "./constants.mjs";
3
+ import { CaipReferenceRegexes, KnownNotifications, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownWalletRpcMethods } from "./constants.mjs";
4
4
  import { parseScopeString } from "./types.mjs";
5
5
  /**
6
6
  * Determines if a scope string is supported.
@@ -106,13 +106,4 @@ export const isSupportedNotification = (scopeString, notification) => {
106
106
  }
107
107
  return false;
108
108
  };
109
- /**
110
- * Determines if a session property is supported by the wallet.
111
- *
112
- * @param property - The property to check.
113
- * @returns A boolean indicating if the property is supported by the wallet.
114
- */
115
- export const isSupportedSessionProperty = (property) => {
116
- return Object.values(KnownSessionProperties).includes(property);
117
- };
118
109
  //# sourceMappingURL=supported.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"supported.mjs","sourceRoot":"","sources":["../../src/scope/supported.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,sBAAsB,EAAE,mCAAmC;AAE3E,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AAEzB,OAAO,EACL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AAC,MAAM,EAAE;YAC3C,OAAO,8BAA8B,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SACnE;QAED,OAAO,uBAAuB,EAAE,CAAC;KAClC;IAED,IAAI,SAAS,KAAK,kBAAkB,CAAC,MAAM,EAAE;QAC3C,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;KACpD;IACD,gEAAgE;IAEhE,OAAO,uBAAuB,EAAE,CAAC;AACnC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,WAAgC,EAChC,YAAoB,EACX,EAAE;IACX,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAEpD,IAAI,SAAS,KAAK,kBAAkB,CAAC,MAAM,EAAE;QAC3C,OAAO,kBAAkB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;KAC7D;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,QAAgB,EAAW,EAAE;IACtE,OAAO,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,QAAQ,CACnD,QAAkC,CACnC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { toHex, isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type { CaipAccountId, CaipChainId, Hex } from '@metamask/utils';\nimport {\n isCaipChainId,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport {\n CaipReferenceRegexes,\n KnownNotifications,\n KnownRpcMethods,\n KnownSessionProperties,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from './constants';\nimport type { ExternalScopeString } from './types';\nimport { parseScopeString } from './types';\n\n/**\n * Determines if a scope string is supported.\n *\n * @param scopeString - The scope string to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @returns A boolean indicating if the scope string is supported.\n */\nexport const isSupportedScopeString = (\n scopeString: string,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n },\n) => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n switch (namespace) {\n case KnownCaipNamespace.Wallet:\n if (\n isCaipChainId(scopeString) &&\n reference !== KnownCaipNamespace.Eip155\n ) {\n return isNonEvmScopeSupported(scopeString);\n }\n return true;\n case KnownCaipNamespace.Eip155:\n return (\n !reference ||\n (CaipReferenceRegexes.eip155.test(reference) &&\n isEvmChainIdSupported(toHex(reference)))\n );\n default:\n return isCaipChainId(scopeString)\n ? isNonEvmScopeSupported(scopeString)\n : false;\n }\n};\n\n/**\n * Determines if an account is supported by the wallet (i.e. on a keyring known to the wallet).\n *\n * @param account - The CAIP account ID to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.getEvmInternalAccounts - A function that returns the EVM internal accounts.\n * @param hooks.getNonEvmAccountAddresses - A function that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns A boolean indicating if the account is supported by the wallet.\n */\nexport const isSupportedAccount = (\n account: CaipAccountId,\n {\n getEvmInternalAccounts,\n getNonEvmAccountAddresses,\n }: {\n getEvmInternalAccounts: () => { type: string; address: Hex }[];\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n },\n) => {\n const {\n address,\n chainId,\n chain: { namespace, reference },\n } = parseCaipAccountId(account);\n\n const isSupportedEip155Account = () =>\n getEvmInternalAccounts().some(\n (internalAccount) =>\n ['eip155:eoa', 'eip155:erc4337'].includes(internalAccount.type) &&\n isEqualCaseInsensitive(address, internalAccount.address),\n );\n\n const isSupportedNonEvmAccount = () =>\n getNonEvmAccountAddresses(chainId).includes(account);\n\n // We are trying to discern the type of `namespace`.\n /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n switch (namespace) {\n case KnownCaipNamespace.Wallet:\n if (reference === KnownCaipNamespace.Eip155) {\n return isSupportedEip155Account();\n }\n return isSupportedNonEvmAccount();\n case KnownCaipNamespace.Eip155:\n return isSupportedEip155Account();\n default:\n return isSupportedNonEvmAccount();\n }\n /* eslint-enable @typescript-eslint/no-unsafe-enum-comparison */\n};\n\n/**\n * Determines if a method is supported by the wallet.\n *\n * @param scopeString - The scope string to check.\n * @param method - The method to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A boolean indicating if the method is supported by the wallet.\n */\nexport const isSupportedMethod = (\n scopeString: ExternalScopeString,\n method: string,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n): boolean => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n if (!namespace) {\n return false;\n }\n\n const isSupportedNonEvmMethod = () =>\n isCaipChainId(scopeString) &&\n getNonEvmSupportedMethods(scopeString).includes(method);\n\n // We are trying to discern the type of `namespace`.\n /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n if (namespace === KnownCaipNamespace.Wallet) {\n if (!reference) {\n return KnownWalletRpcMethods.includes(method);\n }\n\n if (reference === KnownCaipNamespace.Eip155) {\n return KnownWalletNamespaceRpcMethods[reference].includes(method);\n }\n\n return isSupportedNonEvmMethod();\n }\n\n if (namespace === KnownCaipNamespace.Eip155) {\n return KnownRpcMethods[namespace].includes(method);\n }\n /* eslint-enable @typescript-eslint/no-unsafe-enum-comparison */\n\n return isSupportedNonEvmMethod();\n};\n\n/**\n * Determines if a notification is supported by the wallet.\n *\n * @param scopeString - The scope string to check.\n * @param notification - The notification to check.\n * @returns A boolean indicating if the notification is supported by the wallet.\n */\nexport const isSupportedNotification = (\n scopeString: ExternalScopeString,\n notification: string,\n): boolean => {\n const { namespace } = parseScopeString(scopeString);\n\n if (namespace === KnownCaipNamespace.Eip155) {\n return KnownNotifications[namespace].includes(notification);\n }\n\n return false;\n};\n\n/**\n * Determines if a session property is supported by the wallet.\n *\n * @param property - The property to check.\n * @returns A boolean indicating if the property is supported by the wallet.\n */\nexport const isSupportedSessionProperty = (property: string): boolean => {\n return Object.values(KnownSessionProperties).includes(\n property as KnownSessionProperties,\n );\n};\n"]}
1
+ {"version":3,"file":"supported.mjs","sourceRoot":"","sources":["../../src/scope/supported.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,sBAAsB,EAAE,mCAAmC;AAE3E,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AAEzB,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,8BAA8B,EAC9B,qBAAqB,EACtB,wBAAoB;AAErB,OAAO,EAAE,gBAAgB,EAAE,oBAAgB;AAE3C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,WAAmB,EACnB,EACE,qBAAqB,EACrB,sBAAsB,GAIvB,EACD,EAAE;IACF,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAE/D,QAAQ,SAAS,EAAE;QACjB,KAAK,kBAAkB,CAAC,MAAM;YAC5B,IACE,aAAa,CAAC,WAAW,CAAC;gBAC1B,SAAS,KAAK,kBAAkB,CAAC,MAAM,EACvC;gBACA,OAAO,sBAAsB,CAAC,WAAW,CAAC,CAAC;aAC5C;YACD,OAAO,IAAI,CAAC;QACd,KAAK,kBAAkB,CAAC,MAAM;YAC5B,OAAO,CACL,CAAC,SAAS;gBACV,CAAC,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;oBAC1C,qBAAqB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAC3C,CAAC;QACJ;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,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAE/D,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,KAAK,CAAC;KACd;IAED,MAAM,uBAAuB,GAAG,GAAG,EAAE,CACnC,aAAa,CAAC,WAAW,CAAC;QAC1B,yBAAyB,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE1D,oDAAoD;IACpD,iEAAiE;IACjE,IAAI,SAAS,KAAK,kBAAkB,CAAC,MAAM,EAAE;QAC3C,IAAI,CAAC,SAAS,EAAE;YACd,OAAO,qBAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SAC/C;QAED,IAAI,SAAS,KAAK,kBAAkB,CAAC,MAAM,EAAE;YAC3C,OAAO,8BAA8B,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SACnE;QAED,OAAO,uBAAuB,EAAE,CAAC;KAClC;IAED,IAAI,SAAS,KAAK,kBAAkB,CAAC,MAAM,EAAE;QAC3C,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;KACpD;IACD,gEAAgE;IAEhE,OAAO,uBAAuB,EAAE,CAAC;AACnC,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,WAAgC,EAChC,YAAoB,EACX,EAAE;IACX,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAEpD,IAAI,SAAS,KAAK,kBAAkB,CAAC,MAAM,EAAE;QAC3C,OAAO,kBAAkB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;KAC7D;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import { toHex, isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type { CaipAccountId, CaipChainId, Hex } from '@metamask/utils';\nimport {\n isCaipChainId,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport {\n CaipReferenceRegexes,\n KnownNotifications,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownWalletRpcMethods,\n} from './constants';\nimport type { ExternalScopeString } from './types';\nimport { parseScopeString } from './types';\n\n/**\n * Determines if a scope string is supported.\n *\n * @param scopeString - The scope string to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @returns A boolean indicating if the scope string is supported.\n */\nexport const isSupportedScopeString = (\n scopeString: string,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n },\n) => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n switch (namespace) {\n case KnownCaipNamespace.Wallet:\n if (\n isCaipChainId(scopeString) &&\n reference !== KnownCaipNamespace.Eip155\n ) {\n return isNonEvmScopeSupported(scopeString);\n }\n return true;\n case KnownCaipNamespace.Eip155:\n return (\n !reference ||\n (CaipReferenceRegexes.eip155.test(reference) &&\n isEvmChainIdSupported(toHex(reference)))\n );\n default:\n return isCaipChainId(scopeString)\n ? isNonEvmScopeSupported(scopeString)\n : false;\n }\n};\n\n/**\n * Determines if an account is supported by the wallet (i.e. on a keyring known to the wallet).\n *\n * @param account - The CAIP account ID to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.getEvmInternalAccounts - A function that returns the EVM internal accounts.\n * @param hooks.getNonEvmAccountAddresses - A function that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns A boolean indicating if the account is supported by the wallet.\n */\nexport const isSupportedAccount = (\n account: CaipAccountId,\n {\n getEvmInternalAccounts,\n getNonEvmAccountAddresses,\n }: {\n getEvmInternalAccounts: () => { type: string; address: Hex }[];\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n },\n) => {\n const {\n address,\n chainId,\n chain: { namespace, reference },\n } = parseCaipAccountId(account);\n\n const isSupportedEip155Account = () =>\n getEvmInternalAccounts().some(\n (internalAccount) =>\n ['eip155:eoa', 'eip155:erc4337'].includes(internalAccount.type) &&\n isEqualCaseInsensitive(address, internalAccount.address),\n );\n\n const isSupportedNonEvmAccount = () =>\n getNonEvmAccountAddresses(chainId).includes(account);\n\n // We are trying to discern the type of `namespace`.\n /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n switch (namespace) {\n case KnownCaipNamespace.Wallet:\n if (reference === KnownCaipNamespace.Eip155) {\n return isSupportedEip155Account();\n }\n return isSupportedNonEvmAccount();\n case KnownCaipNamespace.Eip155:\n return isSupportedEip155Account();\n default:\n return isSupportedNonEvmAccount();\n }\n /* eslint-enable @typescript-eslint/no-unsafe-enum-comparison */\n};\n\n/**\n * Determines if a method is supported by the wallet.\n *\n * @param scopeString - The scope string to check.\n * @param method - The method to check.\n * @param hooks - An object containing the following properties:\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns A boolean indicating if the method is supported by the wallet.\n */\nexport const isSupportedMethod = (\n scopeString: ExternalScopeString,\n method: string,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n): boolean => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n if (!namespace) {\n return false;\n }\n\n const isSupportedNonEvmMethod = () =>\n isCaipChainId(scopeString) &&\n getNonEvmSupportedMethods(scopeString).includes(method);\n\n // We are trying to discern the type of `namespace`.\n /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */\n if (namespace === KnownCaipNamespace.Wallet) {\n if (!reference) {\n return KnownWalletRpcMethods.includes(method);\n }\n\n if (reference === KnownCaipNamespace.Eip155) {\n return KnownWalletNamespaceRpcMethods[reference].includes(method);\n }\n\n return isSupportedNonEvmMethod();\n }\n\n if (namespace === KnownCaipNamespace.Eip155) {\n return KnownRpcMethods[namespace].includes(method);\n }\n /* eslint-enable @typescript-eslint/no-unsafe-enum-comparison */\n\n return isSupportedNonEvmMethod();\n};\n\n/**\n * Determines if a notification is supported by the wallet.\n *\n * @param scopeString - The scope string to check.\n * @param notification - The notification to check.\n * @returns A boolean indicating if the notification is supported by the wallet.\n */\nexport const isSupportedNotification = (\n scopeString: ExternalScopeString,\n notification: string,\n): boolean => {\n const { namespace } = parseScopeString(scopeString);\n\n if (namespace === KnownCaipNamespace.Eip155) {\n return KnownNotifications[namespace].includes(notification);\n }\n\n return false;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/chain-agnostic-permission",
3
- "version": "0.1.0-preview-8f23873",
3
+ "version": "0.1.0-preview-9d51a80",
4
4
  "description": "Defines a CAIP-25 based endowment permission and helpers for interfacing with it",
5
5
  "keywords": [
6
6
  "MetaMask",