@metamask-previews/chain-agnostic-permission 0.3.0-preview-ca400074 → 0.4.0-preview-d11c4815

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0]
11
+
12
+ ### Added
13
+
14
+ - Add and Export `isKnownSessionPropertyValue` validation utility function ([#5647](https://github.com/MetaMask/core/pull/5647))
15
+ - Add and Export `getCaipAccountIdsFromScopesObjects` filtering utility function ([#5647](https://github.com/MetaMask/core/pull/5647))
16
+ - Add and Export `getAllScopesFromScopesObjects` filtering utility function ([#5647](https://github.com/MetaMask/core/pull/5647))
17
+ - Add and Export `getSupportedScopeObjects` filtering utility function ([#5647](https://github.com/MetaMask/core/pull/5647))
18
+
10
19
  ### Changed
11
20
 
12
21
  - Bump `@metamask/controller-utils` to `^11.7.0` ([#5583](https://github.com/MetaMask/core/pull/5583))
@@ -48,7 +57,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
48
57
 
49
58
  - Initial release
50
59
 
51
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/chain-agnostic-permission@0.3.0...HEAD
60
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/chain-agnostic-permission@0.4.0...HEAD
61
+ [0.4.0]: https://github.com/MetaMask/core/compare/@metamask/chain-agnostic-permission@0.3.0...@metamask/chain-agnostic-permission@0.4.0
52
62
  [0.3.0]: https://github.com/MetaMask/core/compare/@metamask/chain-agnostic-permission@0.2.0...@metamask/chain-agnostic-permission@0.3.0
53
63
  [0.2.0]: https://github.com/MetaMask/core/compare/@metamask/chain-agnostic-permission@0.1.0...@metamask/chain-agnostic-permission@0.2.0
54
64
  [0.1.0]: https://github.com/MetaMask/core/releases/tag/@metamask/chain-agnostic-permission@0.1.0
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Caip25Errors = exports.KnownSessionProperties = exports.generateCaip25Caveat = exports.Caip25CaveatMutators = exports.caip25EndowmentBuilder = exports.Caip25EndowmentPermissionName = exports.createCaip25Caveat = exports.Caip25CaveatType = exports.caip25CaveatBuilder = exports.normalizeAndMergeScopes = exports.mergeInternalScopes = exports.mergeNormalizedScopes = exports.mergeScopeObject = exports.normalizeScope = exports.getUniqueArrayItems = exports.parseScopeString = exports.getSupportedScopeObjects = exports.KnownWalletScopeString = exports.KnownNotifications = exports.KnownWalletNamespaceRpcMethods = exports.KnownRpcMethods = exports.KnownWalletRpcMethods = exports.assertIsInternalScopeString = exports.bucketScopes = exports.validateAndNormalizeScopes = exports.getPermittedAccountsForScopes = exports.getSessionScopes = exports.getInternalScopesObject = exports.addPermittedChainId = exports.setPermittedChainIds = exports.setPermittedEthChainIds = exports.addPermittedEthChainId = exports.getPermittedEthChainIds = exports.setPermittedAccounts = exports.setEthAccounts = exports.getEthAccounts = void 0;
3
+ exports.Caip25Errors = exports.KnownSessionProperties = exports.generateCaip25Caveat = exports.Caip25CaveatMutators = exports.caip25EndowmentBuilder = exports.Caip25EndowmentPermissionName = exports.createCaip25Caveat = exports.Caip25CaveatType = exports.caip25CaveatBuilder = exports.normalizeAndMergeScopes = exports.mergeInternalScopes = exports.mergeNormalizedScopes = exports.mergeScopeObject = exports.normalizeScope = exports.getUniqueArrayItems = exports.parseScopeString = exports.getAllScopesFromScopesObjects = exports.getCaipAccountIdsFromScopesObjects = exports.getSupportedScopeObjects = exports.KnownWalletScopeString = exports.KnownNotifications = exports.KnownWalletNamespaceRpcMethods = exports.KnownRpcMethods = exports.KnownWalletRpcMethods = exports.assertIsInternalScopeString = exports.bucketScopes = exports.validateAndNormalizeScopes = exports.isKnownSessionPropertyValue = exports.getPermittedAccountsForScopes = exports.getSessionScopes = exports.getInternalScopesObject = exports.addPermittedChainId = exports.setPermittedChainIds = exports.setPermittedEthChainIds = exports.addPermittedEthChainId = exports.getPermittedEthChainIds = exports.setPermittedAccounts = exports.setEthAccounts = exports.getEthAccounts = void 0;
4
4
  var caip_permission_adapter_accounts_1 = require("./adapters/caip-permission-adapter-accounts.cjs");
5
5
  Object.defineProperty(exports, "getEthAccounts", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.getEthAccounts; } });
6
6
  Object.defineProperty(exports, "setEthAccounts", { enumerable: true, get: function () { return caip_permission_adapter_accounts_1.setEthAccounts; } });
@@ -15,6 +15,8 @@ var caip_permission_adapter_session_scopes_1 = require("./adapters/caip-permissi
15
15
  Object.defineProperty(exports, "getInternalScopesObject", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getInternalScopesObject; } });
16
16
  Object.defineProperty(exports, "getSessionScopes", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getSessionScopes; } });
17
17
  Object.defineProperty(exports, "getPermittedAccountsForScopes", { enumerable: true, get: function () { return caip_permission_adapter_session_scopes_1.getPermittedAccountsForScopes; } });
18
+ var validation_1 = require("./scope/validation.cjs");
19
+ Object.defineProperty(exports, "isKnownSessionPropertyValue", { enumerable: true, get: function () { return validation_1.isKnownSessionPropertyValue; } });
18
20
  var authorization_1 = require("./scope/authorization.cjs");
19
21
  Object.defineProperty(exports, "validateAndNormalizeScopes", { enumerable: true, get: function () { return authorization_1.validateAndNormalizeScopes; } });
20
22
  Object.defineProperty(exports, "bucketScopes", { enumerable: true, get: function () { return authorization_1.bucketScopes; } });
@@ -28,6 +30,8 @@ Object.defineProperty(exports, "KnownNotifications", { enumerable: true, get: fu
28
30
  Object.defineProperty(exports, "KnownWalletScopeString", { enumerable: true, get: function () { return constants_1.KnownWalletScopeString; } });
29
31
  var filter_1 = require("./scope/filter.cjs");
30
32
  Object.defineProperty(exports, "getSupportedScopeObjects", { enumerable: true, get: function () { return filter_1.getSupportedScopeObjects; } });
33
+ Object.defineProperty(exports, "getCaipAccountIdsFromScopesObjects", { enumerable: true, get: function () { return filter_1.getCaipAccountIdsFromScopesObjects; } });
34
+ Object.defineProperty(exports, "getAllScopesFromScopesObjects", { enumerable: true, get: function () { return filter_1.getAllScopesFromScopesObjects; } });
31
35
  var types_1 = require("./scope/types.cjs");
32
36
  Object.defineProperty(exports, "parseScopeString", { enumerable: true, get: function () { return types_1.parseScopeString; } });
33
37
  var transform_1 = require("./scope/transform.cjs");
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oGAIqD;AAHnD,kIAAA,cAAc,OAAA;AACd,kIAAA,cAAc,OAAA;AACd,wIAAA,oBAAoB,OAAA;AAEtB,kHAM4D;AAL1D,kJAAA,uBAAuB,OAAA;AACvB,iJAAA,sBAAsB,OAAA;AACtB,kJAAA,uBAAuB,OAAA;AACvB,+IAAA,oBAAoB,OAAA;AACpB,8IAAA,mBAAmB,OAAA;AAErB,gHAI2D;AAHzD,iJAAA,uBAAuB,OAAA;AACvB,0IAAA,gBAAgB,OAAA;AAChB,uJAAA,6BAA6B,OAAA;AAI/B,2DAG+B;AAF7B,2HAAA,0BAA0B,OAAA;AAC1B,6GAAA,YAAY,OAAA;AAEd,6CAA6D;AAApD,qHAAA,2BAA2B,OAAA;AACpC,mDAM2B;AALzB,kHAAA,qBAAqB,OAAA;AACrB,4GAAA,eAAe,OAAA;AACf,2HAAA,8BAA8B,OAAA;AAC9B,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AAExB,6CAA0D;AAAjD,kHAAA,wBAAwB,OAAA;AAajC,2CAAiD;AAAxC,yGAAA,gBAAgB,OAAA;AACzB,mDAO2B;AANzB,gHAAA,mBAAmB,OAAA;AACnB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,kHAAA,qBAAqB,OAAA;AACrB,gHAAA,mBAAmB,OAAA;AACnB,oHAAA,uBAAuB,OAAA;AAIzB,2DAQ4B;AAP1B,uHAAA,mBAAmB,OAAA;AACnB,oHAAA,gBAAgB,OAAA;AAChB,sHAAA,kBAAkB,OAAA;AAClB,iIAAA,6BAA6B,OAAA;AAC7B,0HAAA,sBAAsB,OAAA;AACtB,wHAAA,oBAAoB,OAAA;AACpB,wHAAA,oBAAoB,OAAA;AAEtB,mDAA2D;AAAlD,mHAAA,sBAAsB,OAAA;AAC/B,6CAA8C;AAArC,sGAAA,YAAY,OAAA","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n setPermittedAccounts,\n} from './adapters/caip-permission-adapter-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n setPermittedChainIds,\n addPermittedChainId,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n generateCaip25Caveat,\n} from './caip25Permission';\nexport { KnownSessionProperties } from './scope/constants';\nexport { Caip25Errors } from './scope/errors';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oGAIqD;AAHnD,kIAAA,cAAc,OAAA;AACd,kIAAA,cAAc,OAAA;AACd,wIAAA,oBAAoB,OAAA;AAEtB,kHAM4D;AAL1D,kJAAA,uBAAuB,OAAA;AACvB,iJAAA,sBAAsB,OAAA;AACtB,kJAAA,uBAAuB,OAAA;AACvB,+IAAA,oBAAoB,OAAA;AACpB,8IAAA,mBAAmB,OAAA;AAErB,gHAI2D;AAHzD,iJAAA,uBAAuB,OAAA;AACvB,0IAAA,gBAAgB,OAAA;AAChB,uJAAA,6BAA6B,OAAA;AAE/B,qDAAiE;AAAxD,yHAAA,2BAA2B,OAAA;AAEpC,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,6CAIwB;AAHtB,kHAAA,wBAAwB,OAAA;AACxB,4HAAA,kCAAkC,OAAA;AAClC,uHAAA,6BAA6B,OAAA;AAc/B,2CAAiD;AAAxC,yGAAA,gBAAgB,OAAA;AACzB,mDAO2B;AANzB,gHAAA,mBAAmB,OAAA;AACnB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,kHAAA,qBAAqB,OAAA;AACrB,gHAAA,mBAAmB,OAAA;AACnB,oHAAA,uBAAuB,OAAA;AAIzB,2DAQ4B;AAP1B,uHAAA,mBAAmB,OAAA;AACnB,oHAAA,gBAAgB,OAAA;AAChB,sHAAA,kBAAkB,OAAA;AAClB,iIAAA,6BAA6B,OAAA;AAC7B,0HAAA,sBAAsB,OAAA;AACtB,wHAAA,oBAAoB,OAAA;AACpB,wHAAA,oBAAoB,OAAA;AAEtB,mDAA2D;AAAlD,mHAAA,sBAAsB,OAAA;AAC/B,6CAA8C;AAArC,sGAAA,YAAY,OAAA","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n setPermittedAccounts,\n} from './adapters/caip-permission-adapter-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n setPermittedChainIds,\n addPermittedChainId,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\nexport { isKnownSessionPropertyValue } from './scope/validation';\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 {\n getSupportedScopeObjects,\n getCaipAccountIdsFromScopesObjects,\n getAllScopesFromScopesObjects,\n} from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n generateCaip25Caveat,\n} from './caip25Permission';\nexport { KnownSessionProperties } from './scope/constants';\nexport { Caip25Errors } from './scope/errors';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,11 +1,12 @@
1
1
  export { getEthAccounts, setEthAccounts, setPermittedAccounts, } from "./adapters/caip-permission-adapter-accounts.cjs";
2
2
  export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, setPermittedChainIds, addPermittedChainId, } from "./adapters/caip-permission-adapter-permittedChains.cjs";
3
3
  export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes, } from "./adapters/caip-permission-adapter-session-scopes.cjs";
4
+ export { isKnownSessionPropertyValue } from "./scope/validation.cjs";
4
5
  export type { Caip25Authorization } from "./scope/authorization.cjs";
5
6
  export { validateAndNormalizeScopes, bucketScopes, } from "./scope/authorization.cjs";
6
7
  export { assertIsInternalScopeString } from "./scope/assert.cjs";
7
8
  export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownNotifications, KnownWalletScopeString, } from "./scope/constants.cjs";
8
- export { getSupportedScopeObjects } from "./scope/filter.cjs";
9
+ export { getSupportedScopeObjects, getCaipAccountIdsFromScopesObjects, getAllScopesFromScopesObjects, } from "./scope/filter.cjs";
9
10
  export type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject, InternalScopeString, InternalScopeObject, InternalScopesObject, NormalizedScopeObject, NormalizedScopesObject, ScopedProperties, NonWalletKnownCaipNamespace, } from "./scope/types.cjs";
10
11
  export { parseScopeString } from "./scope/types.cjs";
11
12
  export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes, } from "./scope/transform.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,GACpB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,GACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,GACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,GACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,GACpB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAC3D,OAAO,EAAE,2BAA2B,EAAE,+BAA2B;AACjE,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,EACL,wBAAwB,EACxB,kCAAkC,EAClC,6BAA6B,GAC9B,2BAAuB;AACxB,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,GACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB"}
package/dist/index.d.mts CHANGED
@@ -1,11 +1,12 @@
1
1
  export { getEthAccounts, setEthAccounts, setPermittedAccounts, } from "./adapters/caip-permission-adapter-accounts.mjs";
2
2
  export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, setPermittedChainIds, addPermittedChainId, } from "./adapters/caip-permission-adapter-permittedChains.mjs";
3
3
  export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes, } from "./adapters/caip-permission-adapter-session-scopes.mjs";
4
+ export { isKnownSessionPropertyValue } from "./scope/validation.mjs";
4
5
  export type { Caip25Authorization } from "./scope/authorization.mjs";
5
6
  export { validateAndNormalizeScopes, bucketScopes, } from "./scope/authorization.mjs";
6
7
  export { assertIsInternalScopeString } from "./scope/assert.mjs";
7
8
  export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownNotifications, KnownWalletScopeString, } from "./scope/constants.mjs";
8
- export { getSupportedScopeObjects } from "./scope/filter.mjs";
9
+ export { getSupportedScopeObjects, getCaipAccountIdsFromScopesObjects, getAllScopesFromScopesObjects, } from "./scope/filter.mjs";
9
10
  export type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject, InternalScopeString, InternalScopeObject, InternalScopesObject, NormalizedScopeObject, NormalizedScopesObject, ScopedProperties, NonWalletKnownCaipNamespace, } from "./scope/types.mjs";
10
11
  export { parseScopeString } from "./scope/types.mjs";
11
12
  export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes, } from "./scope/transform.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,GACpB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAE3D,YAAY,EAAE,mBAAmB,EAAE,kCAA8B;AACjE,OAAO,EACL,0BAA0B,EAC1B,YAAY,GACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,GACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAC1D,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,GACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,GACrB,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,GACpB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,GAC9B,8DAA0D;AAC3D,OAAO,EAAE,2BAA2B,EAAE,+BAA2B;AACjE,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,EACL,wBAAwB,EACxB,kCAAkC,EAClC,6BAA6B,GAC9B,2BAAuB;AACxB,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,2BAA2B,GAC5B,0BAAsB;AACvB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,8BAA0B;AAE3B,YAAY,EAAE,iBAAiB,EAAE,+BAA2B;AAC5D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,GACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB"}
package/dist/index.mjs CHANGED
@@ -1,10 +1,11 @@
1
1
  export { getEthAccounts, setEthAccounts, setPermittedAccounts } from "./adapters/caip-permission-adapter-accounts.mjs";
2
2
  export { getPermittedEthChainIds, addPermittedEthChainId, setPermittedEthChainIds, setPermittedChainIds, addPermittedChainId } from "./adapters/caip-permission-adapter-permittedChains.mjs";
3
3
  export { getInternalScopesObject, getSessionScopes, getPermittedAccountsForScopes } from "./adapters/caip-permission-adapter-session-scopes.mjs";
4
+ export { isKnownSessionPropertyValue } from "./scope/validation.mjs";
4
5
  export { validateAndNormalizeScopes, bucketScopes } from "./scope/authorization.mjs";
5
6
  export { assertIsInternalScopeString } from "./scope/assert.mjs";
6
7
  export { KnownWalletRpcMethods, KnownRpcMethods, KnownWalletNamespaceRpcMethods, KnownNotifications, KnownWalletScopeString } from "./scope/constants.mjs";
7
- export { getSupportedScopeObjects } from "./scope/filter.mjs";
8
+ export { getSupportedScopeObjects, getCaipAccountIdsFromScopesObjects, getAllScopesFromScopesObjects } from "./scope/filter.mjs";
8
9
  export { parseScopeString } from "./scope/types.mjs";
9
10
  export { getUniqueArrayItems, normalizeScope, mergeScopeObject, mergeNormalizedScopes, mergeInternalScopes, normalizeAndMergeScopes } from "./scope/transform.mjs";
10
11
  export { caip25CaveatBuilder, Caip25CaveatType, createCaip25Caveat, Caip25EndowmentPermissionName, caip25EndowmentBuilder, Caip25CaveatMutators, generateCaip25Caveat } from "./caip25Permission.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACrB,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACpB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,EAC9B,8DAA0D;AAG3D,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,kCAA8B;AAC/B,OAAO,EAAE,2BAA2B,EAAE,2BAAuB;AAC7D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,8BAA8B,EAC9B,kBAAkB,EAClB,sBAAsB,EACvB,8BAA0B;AAC3B,OAAO,EAAE,wBAAwB,EAAE,2BAAuB;AAa1D,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACxB,8BAA0B;AAG3B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n setPermittedAccounts,\n} from './adapters/caip-permission-adapter-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n setPermittedChainIds,\n addPermittedChainId,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\n\nexport type { Caip25Authorization } from './scope/authorization';\nexport {\n validateAndNormalizeScopes,\n bucketScopes,\n} from './scope/authorization';\nexport { assertIsInternalScopeString } from './scope/assert';\nexport {\n KnownWalletRpcMethods,\n KnownRpcMethods,\n KnownWalletNamespaceRpcMethods,\n KnownNotifications,\n KnownWalletScopeString,\n} from './scope/constants';\nexport { getSupportedScopeObjects } from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n generateCaip25Caveat,\n} from './caip25Permission';\nexport { KnownSessionProperties } from './scope/constants';\nexport { Caip25Errors } from './scope/errors';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACrB,wDAAoD;AACrD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACpB,+DAA2D;AAC5D,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,6BAA6B,EAC9B,8DAA0D;AAC3D,OAAO,EAAE,2BAA2B,EAAE,+BAA2B;AAEjE,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,EACL,wBAAwB,EACxB,kCAAkC,EAClC,6BAA6B,EAC9B,2BAAuB;AAaxB,OAAO,EAAE,gBAAgB,EAAE,0BAAsB;AACjD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACxB,8BAA0B;AAG3B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,6BAA6B,EAC7B,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACrB,+BAA2B;AAC5B,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,YAAY,EAAE,2BAAuB","sourcesContent":["export {\n getEthAccounts,\n setEthAccounts,\n setPermittedAccounts,\n} from './adapters/caip-permission-adapter-accounts';\nexport {\n getPermittedEthChainIds,\n addPermittedEthChainId,\n setPermittedEthChainIds,\n setPermittedChainIds,\n addPermittedChainId,\n} from './adapters/caip-permission-adapter-permittedChains';\nexport {\n getInternalScopesObject,\n getSessionScopes,\n getPermittedAccountsForScopes,\n} from './adapters/caip-permission-adapter-session-scopes';\nexport { isKnownSessionPropertyValue } from './scope/validation';\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 {\n getSupportedScopeObjects,\n getCaipAccountIdsFromScopesObjects,\n getAllScopesFromScopesObjects,\n} from './scope/filter';\nexport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n InternalScopeString,\n InternalScopeObject,\n InternalScopesObject,\n NormalizedScopeObject,\n NormalizedScopesObject,\n ScopedProperties,\n NonWalletKnownCaipNamespace,\n} from './scope/types';\nexport { parseScopeString } from './scope/types';\nexport {\n getUniqueArrayItems,\n normalizeScope,\n mergeScopeObject,\n mergeNormalizedScopes,\n mergeInternalScopes,\n normalizeAndMergeScopes,\n} from './scope/transform';\n\nexport type { Caip25CaveatValue } from './caip25Permission';\nexport {\n caip25CaveatBuilder,\n Caip25CaveatType,\n createCaip25Caveat,\n Caip25EndowmentPermissionName,\n caip25EndowmentBuilder,\n Caip25CaveatMutators,\n generateCaip25Caveat,\n} from './caip25Permission';\nexport { KnownSessionProperties } from './scope/constants';\nexport { Caip25Errors } from './scope/errors';\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSupportedScopeObjects = exports.bucketScopesBySupport = void 0;
3
+ exports.getAllScopesFromScopesObjects = exports.getCaipAccountIdsFromScopesObjects = exports.getSupportedScopeObjects = exports.bucketScopesBySupport = void 0;
4
4
  const assert_1 = require("./assert.cjs");
5
5
  const supported_1 = require("./supported.cjs");
6
6
  /**
@@ -73,4 +73,32 @@ const getSupportedScopeObjects = (scopes, { getNonEvmSupportedMethods, }) => {
73
73
  return filteredScopesObject;
74
74
  };
75
75
  exports.getSupportedScopeObjects = getSupportedScopeObjects;
76
+ /**
77
+ * Gets all accounts from an array of scopes objects
78
+ * This extracts all account IDs from both required and optional scopes
79
+ * and returns a unique set.
80
+ *
81
+ * @param scopesObjects - The scopes objects to extract accounts from
82
+ * @returns Array of unique account IDs
83
+ */
84
+ function getCaipAccountIdsFromScopesObjects(scopesObjects) {
85
+ if (!scopesObjects.length) {
86
+ return [];
87
+ }
88
+ return Array.from(new Set(scopesObjects.flatMap((scopeObject) => Object.values(scopeObject).flatMap(({ accounts }) => accounts))));
89
+ }
90
+ exports.getCaipAccountIdsFromScopesObjects = getCaipAccountIdsFromScopesObjects;
91
+ /**
92
+ * Gets all scopes from a CAIP-25 caveat value
93
+ *
94
+ * @param scopesObjects - The scopes objects to get the scopes from.
95
+ * @returns An array of InternalScopeStrings.
96
+ */
97
+ function getAllScopesFromScopesObjects(scopesObjects) {
98
+ if (!scopesObjects.length) {
99
+ return [];
100
+ }
101
+ return Array.from(new Set(scopesObjects.flatMap((scopeObject) => Object.keys(scopeObject))));
102
+ }
103
+ exports.getAllScopesFromScopesObjects = getAllScopesFromScopesObjects;
76
104
  //# sourceMappingURL=filter.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"filter.cjs","sourceRoot":"","sources":["../../src/scope/filter.ts"],"names":[],"mappings":";;;AAEA,yCAA6E;AAC7E,+CAAyE;AAOzE;;;;;;;;;;;GAWG;AACI,MAAM,qBAAqB,GAAG,CACnC,MAA8B,EAC9B,EACE,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAK1B,EACD,EAAE;IACF,MAAM,eAAe,GAA2B,EAAE,CAAC;IACnD,MAAM,iBAAiB,GAA2B,EAAE,CAAC;IAErD,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC/D,IAAA,oCAA2B,EAAC,WAAW,CAAC,CAAC;QACzC,IAAI;YACF,IAAA,6BAAoB,EAAC,WAAW,EAAE,WAAW,EAAE;gBAC7C,qBAAqB;gBACrB,sBAAsB;gBACtB,yBAAyB;aAC1B,CAAC,CAAC;YACH,eAAe,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;SAC5C;QAAC,MAAM;YACN,iBAAiB,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;SAC9C;KACF;IAED,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,CAAC;AAChD,CAAC,CAAC;AA9BW,QAAA,qBAAqB,yBA8BhC;AAEF;;;;;;;;;GASG;AACH,MAAM,uBAAuB,GAAG,CAC9B,WAAgC,EAChC,WAAkC,EAClC,EACE,yBAAyB,GAG1B,EACD,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,WAAW,CAAC;IAE/C,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CACjD,IAAA,6BAAiB,EAAC,WAAW,EAAE,MAAM,EAAE,EAAE,yBAAyB,EAAE,CAAC,CACtE,CAAC;IAEF,MAAM,sBAAsB,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CACnE,IAAA,mCAAuB,EAAC,WAAW,EAAE,YAAY,CAAC,CACnD,CAAC;IAEF,OAAO;QACL,GAAG,WAAW;QACd,OAAO,EAAE,gBAAgB;QACzB,aAAa,EAAE,sBAAsB;KACtC,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,wBAAwB,GAAG,CACtC,MAA8B,EAC9B,EACE,yBAAyB,GAG1B,EACD,EAAE;IACF,MAAM,oBAAoB,GAA2B,EAAE,CAAC;IAExD,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC/D,IAAA,oCAA2B,EAAC,WAAW,CAAC,CAAC;QACzC,oBAAoB,CAAC,WAAW,CAAC,GAAG,uBAAuB,CACzD,WAAW,EACX,WAAW,EACX,EAAE,yBAAyB,EAAE,CAC9B,CAAC;KACH;IAED,OAAO,oBAAoB,CAAC;AAC9B,CAAC,CAAC;AApBW,QAAA,wBAAwB,4BAoBnC","sourcesContent":["import type { CaipChainId, Hex } from '@metamask/utils';\n\nimport { assertIsInternalScopeString, assertScopeSupported } from './assert';\nimport { isSupportedMethod, isSupportedNotification } from './supported';\nimport type {\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Groups a NormalizedScopesObject into two separate\n * NormalizedScopesObject with supported scopes in one\n * and unsupported scopes in the other.\n *\n * @param scopes - The NormalizedScopesObject to group.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns The supported and unsupported scopes.\n */\nexport const bucketScopesBySupport = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const supportedScopes: NormalizedScopesObject = {};\n const unsupportedScopes: NormalizedScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertIsInternalScopeString(scopeString);\n try {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n supportedScopes[scopeString] = scopeObject;\n } catch {\n unsupportedScopes[scopeString] = scopeObject;\n }\n }\n\n return { supportedScopes, unsupportedScopes };\n};\n\n/**\n * Returns a NormalizedScopeObject with\n * unsupported methods and notifications removed.\n *\n * @param scopeString - The InternalScopeString for the scopeObject.\n * @param scopeObject - The NormalizedScopeObject to filter.\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 NormalizedScopeObject with only methods and notifications that are currently supported.\n */\nconst getSupportedScopeObject = (\n scopeString: InternalScopeString,\n scopeObject: NormalizedScopeObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n\n const supportedMethods = methods.filter((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n const supportedNotifications = notifications.filter((notification) =>\n isSupportedNotification(scopeString, notification),\n );\n\n return {\n ...scopeObject,\n methods: supportedMethods,\n notifications: supportedNotifications,\n };\n};\n\n/**\n * Returns a NormalizedScopesObject with\n * unsupported methods and notifications removed from scopeObjects.\n *\n * @param scopes - The NormalizedScopesObject to filter.\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 with only methods, and notifications that are currently supported.\n */\nexport const getSupportedScopeObjects = (\n scopes: NormalizedScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const filteredScopesObject: NormalizedScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertIsInternalScopeString(scopeString);\n filteredScopesObject[scopeString] = getSupportedScopeObject(\n scopeString,\n scopeObject,\n { getNonEvmSupportedMethods },\n );\n }\n\n return filteredScopesObject;\n};\n"]}
1
+ {"version":3,"file":"filter.cjs","sourceRoot":"","sources":["../../src/scope/filter.ts"],"names":[],"mappings":";;;AAEA,yCAA6E;AAC7E,+CAAyE;AAQzE;;;;;;;;;;;GAWG;AACI,MAAM,qBAAqB,GAAG,CACnC,MAA8B,EAC9B,EACE,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,GAK1B,EACD,EAAE;IACF,MAAM,eAAe,GAA2B,EAAE,CAAC;IACnD,MAAM,iBAAiB,GAA2B,EAAE,CAAC;IAErD,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC/D,IAAA,oCAA2B,EAAC,WAAW,CAAC,CAAC;QACzC,IA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,CAAC,GAAG,uBAAuB,CACzD,WAAW,EACX,WAAW,EACX,EAAE,yBAAyB,EAAE,CAC9B,CAAC;KACH;IAED,OAAO,oBAAoB,CAAC;AAC9B,CAAC,CAAC;AApBW,QAAA,wBAAwB,4BAoBnC;AAEF;;;;;;;GAOG;AACH,SAAgB,kCAAkC,CAChD,aAAqC;IAErC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE;QACzB,OAAO,EAAE,CAAC;KACX;IACD,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,GAAG,CACL,aAAa,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CACpC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,CAC/D,CACF,CACF,CAAC;AACJ,CAAC;AAbD,gFAaC;AAED;;;;;GAKG;AACH,SAAgB,6BAA6B,CAC3C,aAAqC;IAErC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE;QACzB,OAAO,EAAE,CAAC;KACX;IACD,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,GAAG,CACL,aAAa,CAAC,OAAO,CACnB,CAAC,WAAW,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAA0B,CACnE,CACF,CACF,CAAC;AACJ,CAAC;AAbD,sEAaC","sourcesContent":["import type { CaipAccountId, CaipChainId, Hex } from '@metamask/utils';\n\nimport { assertIsInternalScopeString, assertScopeSupported } from './assert';\nimport { isSupportedMethod, isSupportedNotification } from './supported';\nimport type {\n InternalScopesObject,\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Groups a NormalizedScopesObject into two separate\n * NormalizedScopesObject with supported scopes in one\n * and unsupported scopes in the other.\n *\n * @param scopes - The NormalizedScopesObject to group.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns The supported and unsupported scopes.\n */\nexport const bucketScopesBySupport = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const supportedScopes: NormalizedScopesObject = {};\n const unsupportedScopes: NormalizedScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertIsInternalScopeString(scopeString);\n try {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n supportedScopes[scopeString] = scopeObject;\n } catch {\n unsupportedScopes[scopeString] = scopeObject;\n }\n }\n\n return { supportedScopes, unsupportedScopes };\n};\n\n/**\n * Returns a NormalizedScopeObject with\n * unsupported methods and notifications removed.\n *\n * @param scopeString - The InternalScopeString for the scopeObject.\n * @param scopeObject - The NormalizedScopeObject to filter.\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 NormalizedScopeObject with only methods and notifications that are currently supported.\n */\nconst getSupportedScopeObject = (\n scopeString: InternalScopeString,\n scopeObject: NormalizedScopeObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n\n const supportedMethods = methods.filter((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n const supportedNotifications = notifications.filter((notification) =>\n isSupportedNotification(scopeString, notification),\n );\n\n return {\n ...scopeObject,\n methods: supportedMethods,\n notifications: supportedNotifications,\n };\n};\n\n/**\n * Returns a NormalizedScopesObject with\n * unsupported methods and notifications removed from scopeObjects.\n *\n * @param scopes - The NormalizedScopesObject to filter.\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 with only methods, and notifications that are currently supported.\n */\nexport const getSupportedScopeObjects = (\n scopes: NormalizedScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const filteredScopesObject: NormalizedScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertIsInternalScopeString(scopeString);\n filteredScopesObject[scopeString] = getSupportedScopeObject(\n scopeString,\n scopeObject,\n { getNonEvmSupportedMethods },\n );\n }\n\n return filteredScopesObject;\n};\n\n/**\n * Gets all accounts from an array of scopes objects\n * This extracts all account IDs from both required and optional scopes\n * and returns a unique set.\n *\n * @param scopesObjects - The scopes objects to extract accounts from\n * @returns Array of unique account IDs\n */\nexport function getCaipAccountIdsFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): CaipAccountId[] {\n if (!scopesObjects.length) {\n return [];\n }\n return Array.from(\n new Set(\n scopesObjects.flatMap((scopeObject) =>\n Object.values(scopeObject).flatMap(({ accounts }) => accounts),\n ),\n ),\n );\n}\n\n/**\n * Gets all scopes from a CAIP-25 caveat value\n *\n * @param scopesObjects - The scopes objects to get the scopes from.\n * @returns An array of InternalScopeStrings.\n */\nexport function getAllScopesFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): InternalScopeString[] {\n if (!scopesObjects.length) {\n return [];\n }\n return Array.from(\n new Set(\n scopesObjects.flatMap(\n (scopeObject) => Object.keys(scopeObject) as InternalScopeString[],\n ),\n ),\n );\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { CaipChainId, Hex } from "@metamask/utils";
2
- import type { NormalizedScopesObject } from "./types.cjs";
1
+ import type { CaipAccountId, CaipChainId, Hex } from "@metamask/utils";
2
+ import type { InternalScopesObject, InternalScopeString, NormalizedScopesObject } from "./types.cjs";
3
3
  /**
4
4
  * Groups a NormalizedScopesObject into two separate
5
5
  * NormalizedScopesObject with supported scopes in one
@@ -32,4 +32,20 @@ export declare const bucketScopesBySupport: (scopes: NormalizedScopesObject, { i
32
32
  export declare const getSupportedScopeObjects: (scopes: NormalizedScopesObject, { getNonEvmSupportedMethods, }: {
33
33
  getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
34
34
  }) => NormalizedScopesObject;
35
+ /**
36
+ * Gets all accounts from an array of scopes objects
37
+ * This extracts all account IDs from both required and optional scopes
38
+ * and returns a unique set.
39
+ *
40
+ * @param scopesObjects - The scopes objects to extract accounts from
41
+ * @returns Array of unique account IDs
42
+ */
43
+ export declare function getCaipAccountIdsFromScopesObjects(scopesObjects: InternalScopesObject[]): CaipAccountId[];
44
+ /**
45
+ * Gets all scopes from a CAIP-25 caveat value
46
+ *
47
+ * @param scopesObjects - The scopes objects to get the scopes from.
48
+ * @returns An array of InternalScopeStrings.
49
+ */
50
+ export declare function getAllScopesFromScopesObjects(scopesObjects: InternalScopesObject[]): InternalScopeString[];
35
51
  //# sourceMappingURL=filter.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filter.d.cts","sourceRoot":"","sources":["../../src/scope/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAIxD,OAAO,KAAK,EAGV,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,WACxB,sBAAsB;qCAMK,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;;;;CAqB9D,CAAC;AAsCF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,WAC3B,sBAAsB;uCAIO,WAAW,KAAK,MAAM,EAAE;4BAe9D,CAAC"}
1
+ {"version":3,"file":"filter.d.cts","sourceRoot":"","sources":["../../src/scope/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EAEnB,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,WACxB,sBAAsB;qCAMK,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;;;;CAqB9D,CAAC;AAsCF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,WAC3B,sBAAsB;uCAIO,WAAW,KAAK,MAAM,EAAE;4BAe9D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CAChD,aAAa,EAAE,oBAAoB,EAAE,GACpC,aAAa,EAAE,CAWjB;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,oBAAoB,EAAE,GACpC,mBAAmB,EAAE,CAWvB"}
@@ -1,5 +1,5 @@
1
- import type { CaipChainId, Hex } from "@metamask/utils";
2
- import type { NormalizedScopesObject } from "./types.mjs";
1
+ import type { CaipAccountId, CaipChainId, Hex } from "@metamask/utils";
2
+ import type { InternalScopesObject, InternalScopeString, NormalizedScopesObject } from "./types.mjs";
3
3
  /**
4
4
  * Groups a NormalizedScopesObject into two separate
5
5
  * NormalizedScopesObject with supported scopes in one
@@ -32,4 +32,20 @@ export declare const bucketScopesBySupport: (scopes: NormalizedScopesObject, { i
32
32
  export declare const getSupportedScopeObjects: (scopes: NormalizedScopesObject, { getNonEvmSupportedMethods, }: {
33
33
  getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
34
34
  }) => NormalizedScopesObject;
35
+ /**
36
+ * Gets all accounts from an array of scopes objects
37
+ * This extracts all account IDs from both required and optional scopes
38
+ * and returns a unique set.
39
+ *
40
+ * @param scopesObjects - The scopes objects to extract accounts from
41
+ * @returns Array of unique account IDs
42
+ */
43
+ export declare function getCaipAccountIdsFromScopesObjects(scopesObjects: InternalScopesObject[]): CaipAccountId[];
44
+ /**
45
+ * Gets all scopes from a CAIP-25 caveat value
46
+ *
47
+ * @param scopesObjects - The scopes objects to get the scopes from.
48
+ * @returns An array of InternalScopeStrings.
49
+ */
50
+ export declare function getAllScopesFromScopesObjects(scopesObjects: InternalScopesObject[]): InternalScopeString[];
35
51
  //# sourceMappingURL=filter.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filter.d.mts","sourceRoot":"","sources":["../../src/scope/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAIxD,OAAO,KAAK,EAGV,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,WACxB,sBAAsB;qCAMK,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;;;;CAqB9D,CAAC;AAsCF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,WAC3B,sBAAsB;uCAIO,WAAW,KAAK,MAAM,EAAE;4BAe9D,CAAC"}
1
+ {"version":3,"file":"filter.d.mts","sourceRoot":"","sources":["../../src/scope/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EAEnB,sBAAsB,EACvB,oBAAgB;AAEjB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,WACxB,sBAAsB;qCAMK,GAAG,KAAK,OAAO;oCAChB,WAAW,KAAK,OAAO;uCACpB,WAAW,KAAK,MAAM,EAAE;;;;CAqB9D,CAAC;AAsCF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,WAC3B,sBAAsB;uCAIO,WAAW,KAAK,MAAM,EAAE;4BAe9D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CAChD,aAAa,EAAE,oBAAoB,EAAE,GACpC,aAAa,EAAE,CAWjB;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,aAAa,EAAE,oBAAoB,EAAE,GACpC,mBAAmB,EAAE,CAWvB"}
@@ -68,4 +68,30 @@ export const getSupportedScopeObjects = (scopes, { getNonEvmSupportedMethods, })
68
68
  }
69
69
  return filteredScopesObject;
70
70
  };
71
+ /**
72
+ * Gets all accounts from an array of scopes objects
73
+ * This extracts all account IDs from both required and optional scopes
74
+ * and returns a unique set.
75
+ *
76
+ * @param scopesObjects - The scopes objects to extract accounts from
77
+ * @returns Array of unique account IDs
78
+ */
79
+ export function getCaipAccountIdsFromScopesObjects(scopesObjects) {
80
+ if (!scopesObjects.length) {
81
+ return [];
82
+ }
83
+ return Array.from(new Set(scopesObjects.flatMap((scopeObject) => Object.values(scopeObject).flatMap(({ accounts }) => accounts))));
84
+ }
85
+ /**
86
+ * Gets all scopes from a CAIP-25 caveat value
87
+ *
88
+ * @param scopesObjects - The scopes objects to get the scopes from.
89
+ * @returns An array of InternalScopeStrings.
90
+ */
91
+ export function getAllScopesFromScopesObjects(scopesObjects) {
92
+ if (!scopesObjects.length) {
93
+ return [];
94
+ }
95
+ return Array.from(new Set(scopesObjects.flatMap((scopeObject) => Object.keys(scopeObject))));
96
+ }
71
97
  //# sourceMappingURL=filter.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"filter.mjs","sourceRoot":"","sources":["../../src/scope/filter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,qBAAiB;AAC7E,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,wBAAoB;AAOzE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,MAA8B,EAC9B,EACE,qBAAqB,EACrB,sB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G1B,EACD,EAAE;IACF,MAAM,oBAAoB,GAA2B,EAAE,CAAC;IAExD,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC/D,2BAA2B,CAAC,WAAW,CAAC,CAAC;QACzC,oBAAoB,CAAC,WAAW,CAAC,GAAG,uBAAuB,CACzD,WAAW,EACX,WAAW,EACX,EAAE,yBAAyB,EAAE,CAC9B,CAAC;KACH;IAED,OAAO,oBAAoB,CAAC;AAC9B,CAAC,CAAC","sourcesContent":["import type { CaipChainId, Hex } from '@metamask/utils';\n\nimport { assertIsInternalScopeString, assertScopeSupported } from './assert';\nimport { isSupportedMethod, isSupportedNotification } from './supported';\nimport type {\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Groups a NormalizedScopesObject into two separate\n * NormalizedScopesObject with supported scopes in one\n * and unsupported scopes in the other.\n *\n * @param scopes - The NormalizedScopesObject to group.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns The supported and unsupported scopes.\n */\nexport const bucketScopesBySupport = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const supportedScopes: NormalizedScopesObject = {};\n const unsupportedScopes: NormalizedScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertIsInternalScopeString(scopeString);\n try {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n supportedScopes[scopeString] = scopeObject;\n } catch {\n unsupportedScopes[scopeString] = scopeObject;\n }\n }\n\n return { supportedScopes, unsupportedScopes };\n};\n\n/**\n * Returns a NormalizedScopeObject with\n * unsupported methods and notifications removed.\n *\n * @param scopeString - The InternalScopeString for the scopeObject.\n * @param scopeObject - The NormalizedScopeObject to filter.\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 NormalizedScopeObject with only methods and notifications that are currently supported.\n */\nconst getSupportedScopeObject = (\n scopeString: InternalScopeString,\n scopeObject: NormalizedScopeObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n\n const supportedMethods = methods.filter((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n const supportedNotifications = notifications.filter((notification) =>\n isSupportedNotification(scopeString, notification),\n );\n\n return {\n ...scopeObject,\n methods: supportedMethods,\n notifications: supportedNotifications,\n };\n};\n\n/**\n * Returns a NormalizedScopesObject with\n * unsupported methods and notifications removed from scopeObjects.\n *\n * @param scopes - The NormalizedScopesObject to filter.\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 with only methods, and notifications that are currently supported.\n */\nexport const getSupportedScopeObjects = (\n scopes: NormalizedScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const filteredScopesObject: NormalizedScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertIsInternalScopeString(scopeString);\n filteredScopesObject[scopeString] = getSupportedScopeObject(\n scopeString,\n scopeObject,\n { getNonEvmSupportedMethods },\n );\n }\n\n return filteredScopesObject;\n};\n"]}
1
+ {"version":3,"file":"filter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CAAC,IAAI,CAAC,WAAW,CAA0B,CACnE,CACF,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type { CaipAccountId, CaipChainId, Hex } from '@metamask/utils';\n\nimport { assertIsInternalScopeString, assertScopeSupported } from './assert';\nimport { isSupportedMethod, isSupportedNotification } from './supported';\nimport type {\n InternalScopesObject,\n InternalScopeString,\n NormalizedScopeObject,\n NormalizedScopesObject,\n} from './types';\n\n/**\n * Groups a NormalizedScopesObject into two separate\n * NormalizedScopesObject with supported scopes in one\n * and unsupported scopes in the other.\n *\n * @param scopes - The NormalizedScopesObject to group.\n * @param hooks - An object containing the following properties:\n * @param hooks.isEvmChainIdSupported - A predicate that determines if an EVM chainID is supported.\n * @param hooks.isNonEvmScopeSupported - A predicate that determines if an non EVM scopeString is supported.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @returns The supported and unsupported scopes.\n */\nexport const bucketScopesBySupport = (\n scopes: NormalizedScopesObject,\n {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n }: {\n isEvmChainIdSupported: (chainId: Hex) => boolean;\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const supportedScopes: NormalizedScopesObject = {};\n const unsupportedScopes: NormalizedScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertIsInternalScopeString(scopeString);\n try {\n assertScopeSupported(scopeString, scopeObject, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n getNonEvmSupportedMethods,\n });\n supportedScopes[scopeString] = scopeObject;\n } catch {\n unsupportedScopes[scopeString] = scopeObject;\n }\n }\n\n return { supportedScopes, unsupportedScopes };\n};\n\n/**\n * Returns a NormalizedScopeObject with\n * unsupported methods and notifications removed.\n *\n * @param scopeString - The InternalScopeString for the scopeObject.\n * @param scopeObject - The NormalizedScopeObject to filter.\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 NormalizedScopeObject with only methods and notifications that are currently supported.\n */\nconst getSupportedScopeObject = (\n scopeString: InternalScopeString,\n scopeObject: NormalizedScopeObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const { methods, notifications } = scopeObject;\n\n const supportedMethods = methods.filter((method) =>\n isSupportedMethod(scopeString, method, { getNonEvmSupportedMethods }),\n );\n\n const supportedNotifications = notifications.filter((notification) =>\n isSupportedNotification(scopeString, notification),\n );\n\n return {\n ...scopeObject,\n methods: supportedMethods,\n notifications: supportedNotifications,\n };\n};\n\n/**\n * Returns a NormalizedScopesObject with\n * unsupported methods and notifications removed from scopeObjects.\n *\n * @param scopes - The NormalizedScopesObject to filter.\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 with only methods, and notifications that are currently supported.\n */\nexport const getSupportedScopeObjects = (\n scopes: NormalizedScopesObject,\n {\n getNonEvmSupportedMethods,\n }: {\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n },\n) => {\n const filteredScopesObject: NormalizedScopesObject = {};\n\n for (const [scopeString, scopeObject] of Object.entries(scopes)) {\n assertIsInternalScopeString(scopeString);\n filteredScopesObject[scopeString] = getSupportedScopeObject(\n scopeString,\n scopeObject,\n { getNonEvmSupportedMethods },\n );\n }\n\n return filteredScopesObject;\n};\n\n/**\n * Gets all accounts from an array of scopes objects\n * This extracts all account IDs from both required and optional scopes\n * and returns a unique set.\n *\n * @param scopesObjects - The scopes objects to extract accounts from\n * @returns Array of unique account IDs\n */\nexport function getCaipAccountIdsFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): CaipAccountId[] {\n if (!scopesObjects.length) {\n return [];\n }\n return Array.from(\n new Set(\n scopesObjects.flatMap((scopeObject) =>\n Object.values(scopeObject).flatMap(({ accounts }) => accounts),\n ),\n ),\n );\n}\n\n/**\n * Gets all scopes from a CAIP-25 caveat value\n *\n * @param scopesObjects - The scopes objects to get the scopes from.\n * @returns An array of InternalScopeStrings.\n */\nexport function getAllScopesFromScopesObjects(\n scopesObjects: InternalScopesObject[],\n): InternalScopeString[] {\n if (!scopesObjects.length) {\n return [];\n }\n return Array.from(\n new Set(\n scopesObjects.flatMap(\n (scopeObject) => Object.keys(scopeObject) as InternalScopeString[],\n ),\n ),\n );\n}\n"]}
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getValidScopes = exports.isValidScope = void 0;
3
+ exports.isKnownSessionPropertyValue = exports.getValidScopes = exports.isValidScope = void 0;
4
4
  const utils_1 = require("@metamask/utils");
5
+ const constants_1 = require("./constants.cjs");
5
6
  const types_1 = require("./types.cjs");
6
7
  /**
7
8
  * Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.
@@ -84,4 +85,14 @@ const getValidScopes = (requiredScopes, optionalScopes) => {
84
85
  };
85
86
  };
86
87
  exports.getValidScopes = getValidScopes;
88
+ /**
89
+ * Checks if a given value is a known session property.
90
+ *
91
+ * @param value - The value to check.
92
+ * @returns `true` if the value is a known session property, otherwise `false`.
93
+ */
94
+ function isKnownSessionPropertyValue(value) {
95
+ return Object.values(constants_1.KnownSessionProperties).includes(value);
96
+ }
97
+ exports.isKnownSessionPropertyValue = isKnownSessionPropertyValue;
87
98
  //# sourceMappingURL=validation.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":";;;AAAA,2CAAkD;AAOlD,uCAA2C;AAE3C;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAC1B,WAAgC,EAChC,WAAgC,EACvB,EAAE;IACX,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,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CAAC,MAAM,GAAG,CAAC,EAAE;QAC3C,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAzEW,QAAA,YAAY,gBAyEvB;AAEF;;;;;;GAMG;AACI,MAAM,cAAc,GAAG,CAC5B,cAAqC,EACrC,cAAqC,EACrC,EAAE;IACF,MAAM,mBAAmB,GAAyB,EAAE,CAAC;IACrD,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CACrD,cAAc,IAAI,EAAE,CACrB,EAAE;QACD,IAAI,IAAA,oBAAY,EAAC,WAAW,EAAE,WAAW,CAAC,EAAE;YAC1C,mBAAmB,CAAC,WAAW,CAAC,GAAG;gBACjC,QAAQ,EAAE,EAAE;gBACZ,GAAG,WAAW;aACf,CAAC;SACH;KACF;IAED,MAAM,mBAAmB,GAAyB,EAAE,CAAC;IACrD,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CACrD,cAAc,IAAI,EAAE,CACrB,EAAE;QACD,IAAI,IAAA,oBAAY,EAAC,WAAW,EAAE,WAAW,CAAC,EAAE;YAC1C,mBAAmB,CAAC,WAAW,CAAC,GAAG;gBACjC,QAAQ,EAAE,EAAE;gBACZ,GAAG,WAAW;aACf,CAAC;SACH;KACF;IAED,OAAO;QACL,mBAAmB;QACnB,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC;AAhCW,QAAA,cAAc,kBAgCzB","sourcesContent":["import { isCaipReference } from '@metamask/utils';\n\nimport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n} from './types';\nimport { parseScopeString } from './types';\n\n/**\n * Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n *\n * @param scopeString - The scope string to validate.\n * @param scopeObject - The scope object to validate.\n * @returns A boolean indicating if the scope object is valid according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n */\nexport const isValidScope = (\n scopeString: ExternalScopeString,\n scopeObject: ExternalScopeObject,\n): boolean => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n // Namespace is required\n if (!namespace) {\n return false;\n }\n\n const {\n references,\n methods,\n notifications,\n accounts,\n rpcDocuments,\n rpcEndpoints,\n ...extraProperties\n } = scopeObject;\n\n // Methods and notifications are required\n if (!methods || !notifications) {\n return false;\n }\n\n // For namespaces other than 'wallet', either reference or non-empty references array must be present\n if (\n namespace !== 'wallet' &&\n !reference &&\n (!references || references.length === 0)\n ) {\n return false;\n }\n\n // If references are present, reference must be absent and all references must be valid\n if (references) {\n if (reference) {\n return false;\n }\n\n const areReferencesValid = references.every((nestedReference) =>\n isCaipReference(nestedReference),\n );\n\n if (!areReferencesValid) {\n return false;\n }\n }\n\n const areMethodsValid = methods.every(\n (method) => typeof method === 'string' && method.trim() !== '',\n );\n\n if (!areMethodsValid) {\n return false;\n }\n\n const areNotificationsValid = notifications.every(\n (notification) =>\n typeof notification === 'string' && notification.trim() !== '',\n );\n\n if (!areNotificationsValid) {\n return false;\n }\n\n // Ensure no unexpected properties are present in the scope object\n if (Object.keys(extraProperties).length > 0) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Filters out invalid scopes and returns valid sets of required and optional scopes according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n *\n * @param requiredScopes - The required scopes to validate.\n * @param optionalScopes - The optional scopes to validate.\n * @returns An object containing valid required scopes and optional scopes.\n */\nexport const getValidScopes = (\n requiredScopes?: ExternalScopesObject,\n optionalScopes?: ExternalScopesObject,\n) => {\n const validRequiredScopes: ExternalScopesObject = {};\n for (const [scopeString, scopeObject] of Object.entries(\n requiredScopes || {},\n )) {\n if (isValidScope(scopeString, scopeObject)) {\n validRequiredScopes[scopeString] = {\n accounts: [],\n ...scopeObject,\n };\n }\n }\n\n const validOptionalScopes: ExternalScopesObject = {};\n for (const [scopeString, scopeObject] of Object.entries(\n optionalScopes || {},\n )) {\n if (isValidScope(scopeString, scopeObject)) {\n validOptionalScopes[scopeString] = {\n accounts: [],\n ...scopeObject,\n };\n }\n }\n\n return {\n validRequiredScopes,\n validOptionalScopes,\n };\n};\n"]}
1
+ {"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":";;;AAAA,2CAAkD;AAElD,+CAAqD;AAMrD,uCAA2C;AAE3C;;;;;;GAMG;AACI,MAAM,YAAY,GAAG,CAC1B,WAAgC,EAChC,WAAgC,EACvB,EAAE;IACX,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAE/D,wBAAwB;IACxB,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,KAAK,CAAC;KACd;IAED,MAAM,EACJ,UAAU,EACV,OAAO,EACP,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,GAAG,eAAe,EACnB,GAAG,WAAW,CAAC;IAEhB,yCAAyC;IACzC,IAAI,CAAC,OAAO,IAAI,CAAC,aAAa,EAAE;QAC9B,OAAO,KAAK,CAAC;KACd;IAED,qGAAqG;IACrG,IACE,SAAS,KAAK,QAAQ;QACtB,CAAC,SAAS;QACV,CAAC,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,EACxC;QACA,OAAO,KAAK,CAAC;KACd;IAED,uFAAuF;IACvF,IAAI,UAAU,EAAE;QACd,IAAI,SAAS,EAAE;YACb,OAAO,KAAK,CAAC;SACd;QAED,MAAM,kBAAkB,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,eAAe,EAAE,EAAE,CAC9D,IAAA,uBAAe,EAAC,eAAe,CAAC,CACjC,CAAC;QAEF,IAAI,CAAC,kBAAkB,EAAE;YACvB,OAAO,KAAK,CAAC;SACd;KACF;IAED,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CACnC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,MAAM,KAAK,QAAQ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;IAED,OAAO;QACL,mBAAmB;QACnB,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC;AAhCW,QAAA,cAAc,kBAgCzB;AAEF;;;;;GAKG;AACH,SAAgB,2BAA2B,CACzC,KAAa;IAEb,OAAO,MAAM,CAAC,MAAM,CAAC,kCAAsB,CAAC,CAAC,QAAQ,CACnD,KAA+B,CAChC,CAAC;AACJ,CAAC;AAND,kEAMC","sourcesContent":["import { isCaipReference } from '@metamask/utils';\n\nimport { KnownSessionProperties } from './constants';\nimport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n} from './types';\nimport { parseScopeString } from './types';\n\n/**\n * Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n *\n * @param scopeString - The scope string to validate.\n * @param scopeObject - The scope object to validate.\n * @returns A boolean indicating if the scope object is valid according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n */\nexport const isValidScope = (\n scopeString: ExternalScopeString,\n scopeObject: ExternalScopeObject,\n): boolean => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n // Namespace is required\n if (!namespace) {\n return false;\n }\n\n const {\n references,\n methods,\n notifications,\n accounts,\n rpcDocuments,\n rpcEndpoints,\n ...extraProperties\n } = scopeObject;\n\n // Methods and notifications are required\n if (!methods || !notifications) {\n return false;\n }\n\n // For namespaces other than 'wallet', either reference or non-empty references array must be present\n if (\n namespace !== 'wallet' &&\n !reference &&\n (!references || references.length === 0)\n ) {\n return false;\n }\n\n // If references are present, reference must be absent and all references must be valid\n if (references) {\n if (reference) {\n return false;\n }\n\n const areReferencesValid = references.every((nestedReference) =>\n isCaipReference(nestedReference),\n );\n\n if (!areReferencesValid) {\n return false;\n }\n }\n\n const areMethodsValid = methods.every(\n (method) => typeof method === 'string' && method.trim() !== '',\n );\n\n if (!areMethodsValid) {\n return false;\n }\n\n const areNotificationsValid = notifications.every(\n (notification) =>\n typeof notification === 'string' && notification.trim() !== '',\n );\n\n if (!areNotificationsValid) {\n return false;\n }\n\n // Ensure no unexpected properties are present in the scope object\n if (Object.keys(extraProperties).length > 0) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Filters out invalid scopes and returns valid sets of required and optional scopes according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n *\n * @param requiredScopes - The required scopes to validate.\n * @param optionalScopes - The optional scopes to validate.\n * @returns An object containing valid required scopes and optional scopes.\n */\nexport const getValidScopes = (\n requiredScopes?: ExternalScopesObject,\n optionalScopes?: ExternalScopesObject,\n) => {\n const validRequiredScopes: ExternalScopesObject = {};\n for (const [scopeString, scopeObject] of Object.entries(\n requiredScopes || {},\n )) {\n if (isValidScope(scopeString, scopeObject)) {\n validRequiredScopes[scopeString] = {\n accounts: [],\n ...scopeObject,\n };\n }\n }\n\n const validOptionalScopes: ExternalScopesObject = {};\n for (const [scopeString, scopeObject] of Object.entries(\n optionalScopes || {},\n )) {\n if (isValidScope(scopeString, scopeObject)) {\n validOptionalScopes[scopeString] = {\n accounts: [],\n ...scopeObject,\n };\n }\n }\n\n return {\n validRequiredScopes,\n validOptionalScopes,\n };\n};\n\n/**\n * Checks if a given value is a known session property.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a known session property, otherwise `false`.\n */\nexport function isKnownSessionPropertyValue(\n value: string,\n): value is KnownSessionProperties {\n return Object.values(KnownSessionProperties).includes(\n value as KnownSessionProperties,\n );\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { KnownSessionProperties } from "./constants.cjs";
1
2
  import type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject } from "./types.cjs";
2
3
  /**
3
4
  * Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.
@@ -18,4 +19,11 @@ export declare const getValidScopes: (requiredScopes?: ExternalScopesObject, opt
18
19
  validRequiredScopes: ExternalScopesObject;
19
20
  validOptionalScopes: ExternalScopesObject;
20
21
  };
22
+ /**
23
+ * Checks if a given value is a known session property.
24
+ *
25
+ * @param value - The value to check.
26
+ * @returns `true` if the value is a known session property, otherwise `false`.
27
+ */
28
+ export declare function isKnownSessionPropertyValue(value: string): value is KnownSessionProperties;
21
29
  //# sourceMappingURL=validation.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACrB,oBAAgB;AAGjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,gBACV,mBAAmB,eACnB,mBAAmB,KAC/B,OAsEF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,oBACR,oBAAoB,mBACpB,oBAAoB;;;CA8BtC,CAAC"}
1
+ {"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,wBAAoB;AACrD,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACrB,oBAAgB;AAGjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,gBACV,mBAAmB,eACnB,mBAAmB,KAC/B,OAsEF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,oBACR,oBAAoB,mBACpB,oBAAoB;;;CA8BtC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,GACZ,KAAK,IAAI,sBAAsB,CAIjC"}
@@ -1,3 +1,4 @@
1
+ import { KnownSessionProperties } from "./constants.mjs";
1
2
  import type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject } from "./types.mjs";
2
3
  /**
3
4
  * Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.
@@ -18,4 +19,11 @@ export declare const getValidScopes: (requiredScopes?: ExternalScopesObject, opt
18
19
  validRequiredScopes: ExternalScopesObject;
19
20
  validOptionalScopes: ExternalScopesObject;
20
21
  };
22
+ /**
23
+ * Checks if a given value is a known session property.
24
+ *
25
+ * @param value - The value to check.
26
+ * @returns `true` if the value is a known session property, otherwise `false`.
27
+ */
28
+ export declare function isKnownSessionPropertyValue(value: string): value is KnownSessionProperties;
21
29
  //# sourceMappingURL=validation.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACrB,oBAAgB;AAGjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,gBACV,mBAAmB,eACnB,mBAAmB,KAC/B,OAsEF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,oBACR,oBAAoB,mBACpB,oBAAoB;;;CA8BtC,CAAC"}
1
+ {"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,wBAAoB;AACrD,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACrB,oBAAgB;AAGjB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,gBACV,mBAAmB,eACnB,mBAAmB,KAC/B,OAsEF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,oBACR,oBAAoB,mBACpB,oBAAoB;;;CA8BtC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,GACZ,KAAK,IAAI,sBAAsB,CAIjC"}
@@ -1,4 +1,5 @@
1
1
  import { isCaipReference } from "@metamask/utils";
2
+ import { KnownSessionProperties } from "./constants.mjs";
2
3
  import { parseScopeString } from "./types.mjs";
3
4
  /**
4
5
  * Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.
@@ -79,4 +80,13 @@ export const getValidScopes = (requiredScopes, optionalScopes) => {
79
80
  validOptionalScopes,
80
81
  };
81
82
  };
83
+ /**
84
+ * Checks if a given value is a known session property.
85
+ *
86
+ * @param value - The value to check.
87
+ * @returns `true` if the value is a known session property, otherwise `false`.
88
+ */
89
+ export function isKnownSessionPropertyValue(value) {
90
+ return Object.values(KnownSessionProperties).includes(value);
91
+ }
82
92
  //# sourceMappingURL=validation.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,wBAAwB;AAOlD,OAAO,EAAE,gBAAgB,EAAE,oBAAgB;AAE3C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,WAAgC,EAChC,WAAgC,EACvB,EAAE;IACX,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAE/D,wBAAwB;IACxB,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,KAAK,CAAC;KACd;IAED,MAAM,EACJ,UAAU,EACV,OAAO,EACP,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,GAAG,eAAe,EACnB,GAAG,WAAW,CAAC;IAEhB,yCAAyC;IACzC,IAAI,CAAC,OAAO,IAAI,CAAC,aAAa,EAAE;QAC9B,OAAO,KAAK,CAAC;KACd;IAED,qGAAqG;IACrG,IACE,SAAS,KAAK,QAAQ;QACtB,CAAC,SAAS;QACV,CAAC,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,EACxC;QACA,OAAO,KAAK,CAAC;KACd;IAED,uFAAuF;IACvF,IAAI,UAAU,EAAE;QACd,IAAI,SAAS,EAAE;YACb,OAAO,KAAK,CAAC;SACd;QAED,MAAM,kBAAkB,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,eAAe,EAAE,EAAE,CAC9D,eAAe,CAAC,eAAe,CAAC,CACjC,CAAC;QAEF,IAAI,C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WAAW,CAAC,EAAE;YAC1C,mBAAmB,CAAC,WAAW,CAAC,GAAG;gBACjC,QAAQ,EAAE,EAAE;gBACZ,GAAG,WAAW;aACf,CAAC;SACH;KACF;IAED,OAAO;QACL,mBAAmB;QACnB,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { isCaipReference } from '@metamask/utils';\n\nimport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n} from './types';\nimport { parseScopeString } from './types';\n\n/**\n * Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n *\n * @param scopeString - The scope string to validate.\n * @param scopeObject - The scope object to validate.\n * @returns A boolean indicating if the scope object is valid according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n */\nexport const isValidScope = (\n scopeString: ExternalScopeString,\n scopeObject: ExternalScopeObject,\n): boolean => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n // Namespace is required\n if (!namespace) {\n return false;\n }\n\n const {\n references,\n methods,\n notifications,\n accounts,\n rpcDocuments,\n rpcEndpoints,\n ...extraProperties\n } = scopeObject;\n\n // Methods and notifications are required\n if (!methods || !notifications) {\n return false;\n }\n\n // For namespaces other than 'wallet', either reference or non-empty references array must be present\n if (\n namespace !== 'wallet' &&\n !reference &&\n (!references || references.length === 0)\n ) {\n return false;\n }\n\n // If references are present, reference must be absent and all references must be valid\n if (references) {\n if (reference) {\n return false;\n }\n\n const areReferencesValid = references.every((nestedReference) =>\n isCaipReference(nestedReference),\n );\n\n if (!areReferencesValid) {\n return false;\n }\n }\n\n const areMethodsValid = methods.every(\n (method) => typeof method === 'string' && method.trim() !== '',\n );\n\n if (!areMethodsValid) {\n return false;\n }\n\n const areNotificationsValid = notifications.every(\n (notification) =>\n typeof notification === 'string' && notification.trim() !== '',\n );\n\n if (!areNotificationsValid) {\n return false;\n }\n\n // Ensure no unexpected properties are present in the scope object\n if (Object.keys(extraProperties).length > 0) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Filters out invalid scopes and returns valid sets of required and optional scopes according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n *\n * @param requiredScopes - The required scopes to validate.\n * @param optionalScopes - The optional scopes to validate.\n * @returns An object containing valid required scopes and optional scopes.\n */\nexport const getValidScopes = (\n requiredScopes?: ExternalScopesObject,\n optionalScopes?: ExternalScopesObject,\n) => {\n const validRequiredScopes: ExternalScopesObject = {};\n for (const [scopeString, scopeObject] of Object.entries(\n requiredScopes || {},\n )) {\n if (isValidScope(scopeString, scopeObject)) {\n validRequiredScopes[scopeString] = {\n accounts: [],\n ...scopeObject,\n };\n }\n }\n\n const validOptionalScopes: ExternalScopesObject = {};\n for (const [scopeString, scopeObject] of Object.entries(\n optionalScopes || {},\n )) {\n if (isValidScope(scopeString, scopeObject)) {\n validOptionalScopes[scopeString] = {\n accounts: [],\n ...scopeObject,\n };\n }\n }\n\n return {\n validRequiredScopes,\n validOptionalScopes,\n };\n};\n"]}
1
+ {"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,wBAAwB;AAElD,OAAO,EAAE,sBAAsB,EAAE,wBAAoB;AAMrD,OAAO,EAAE,gBAAgB,EAAE,oBAAgB;AAE3C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,WAAgC,EAChC,WAAgC,EACvB,EAAE;IACX,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAE/D,wBAAwB;IACxB,IAAI,CAAC,SAAS,EAAE;QACd,OAAO,KAAK,CAAC;KACd;IAED,MAAM,EACJ,UAAU,EACV,OAAO,EACP,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,GAAG,eAAe,EACnB,GAAG,WAAW,CAAC;IAEhB,yCAAyC;IACzC,IAAI,CAAC,OAAO,IAAI,CAAC,aAAa,EA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AAW,CAAC,IAAI,MAAM,CAAC,OAAO,CACrD,cAAc,IAAI,EAAE,CACrB,EAAE;QACD,IAAI,YAAY,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE;YAC1C,mBAAmB,CAAC,WAAW,CAAC,GAAG;gBACjC,QAAQ,EAAE,EAAE;gBACZ,GAAG,WAAW;aACf,CAAC;SACH;KACF;IAED,MAAM,mBAAmB,GAAyB,EAAE,CAAC;IACrD,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CACrD,cAAc,IAAI,EAAE,CACrB,EAAE;QACD,IAAI,YAAY,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE;YAC1C,mBAAmB,CAAC,WAAW,CAAC,GAAG;gBACjC,QAAQ,EAAE,EAAE;gBACZ,GAAG,WAAW;aACf,CAAC;SACH;KACF;IAED,OAAO;QACL,mBAAmB;QACnB,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,KAAa;IAEb,OAAO,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,QAAQ,CACnD,KAA+B,CAChC,CAAC;AACJ,CAAC","sourcesContent":["import { isCaipReference } from '@metamask/utils';\n\nimport { KnownSessionProperties } from './constants';\nimport type {\n ExternalScopeString,\n ExternalScopeObject,\n ExternalScopesObject,\n} from './types';\nimport { parseScopeString } from './types';\n\n/**\n * Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n *\n * @param scopeString - The scope string to validate.\n * @param scopeObject - The scope object to validate.\n * @returns A boolean indicating if the scope object is valid according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n */\nexport const isValidScope = (\n scopeString: ExternalScopeString,\n scopeObject: ExternalScopeObject,\n): boolean => {\n const { namespace, reference } = parseScopeString(scopeString);\n\n // Namespace is required\n if (!namespace) {\n return false;\n }\n\n const {\n references,\n methods,\n notifications,\n accounts,\n rpcDocuments,\n rpcEndpoints,\n ...extraProperties\n } = scopeObject;\n\n // Methods and notifications are required\n if (!methods || !notifications) {\n return false;\n }\n\n // For namespaces other than 'wallet', either reference or non-empty references array must be present\n if (\n namespace !== 'wallet' &&\n !reference &&\n (!references || references.length === 0)\n ) {\n return false;\n }\n\n // If references are present, reference must be absent and all references must be valid\n if (references) {\n if (reference) {\n return false;\n }\n\n const areReferencesValid = references.every((nestedReference) =>\n isCaipReference(nestedReference),\n );\n\n if (!areReferencesValid) {\n return false;\n }\n }\n\n const areMethodsValid = methods.every(\n (method) => typeof method === 'string' && method.trim() !== '',\n );\n\n if (!areMethodsValid) {\n return false;\n }\n\n const areNotificationsValid = notifications.every(\n (notification) =>\n typeof notification === 'string' && notification.trim() !== '',\n );\n\n if (!areNotificationsValid) {\n return false;\n }\n\n // Ensure no unexpected properties are present in the scope object\n if (Object.keys(extraProperties).length > 0) {\n return false;\n }\n\n return true;\n};\n\n/**\n * Filters out invalid scopes and returns valid sets of required and optional scopes according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.\n *\n * @param requiredScopes - The required scopes to validate.\n * @param optionalScopes - The optional scopes to validate.\n * @returns An object containing valid required scopes and optional scopes.\n */\nexport const getValidScopes = (\n requiredScopes?: ExternalScopesObject,\n optionalScopes?: ExternalScopesObject,\n) => {\n const validRequiredScopes: ExternalScopesObject = {};\n for (const [scopeString, scopeObject] of Object.entries(\n requiredScopes || {},\n )) {\n if (isValidScope(scopeString, scopeObject)) {\n validRequiredScopes[scopeString] = {\n accounts: [],\n ...scopeObject,\n };\n }\n }\n\n const validOptionalScopes: ExternalScopesObject = {};\n for (const [scopeString, scopeObject] of Object.entries(\n optionalScopes || {},\n )) {\n if (isValidScope(scopeString, scopeObject)) {\n validOptionalScopes[scopeString] = {\n accounts: [],\n ...scopeObject,\n };\n }\n }\n\n return {\n validRequiredScopes,\n validOptionalScopes,\n };\n};\n\n/**\n * Checks if a given value is a known session property.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a known session property, otherwise `false`.\n */\nexport function isKnownSessionPropertyValue(\n value: string,\n): value is KnownSessionProperties {\n return Object.values(KnownSessionProperties).includes(\n value as KnownSessionProperties,\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/chain-agnostic-permission",
3
- "version": "0.3.0-preview-ca400074",
3
+ "version": "0.4.0-preview-d11c4815",
4
4
  "description": "Defines a CAIP-25 based endowment permission and helpers for interfacing with it",
5
5
  "keywords": [
6
6
  "MetaMask",