@metamask-previews/chain-agnostic-permission 0.4.0-preview-ddbcf048 → 0.4.0-preview-514219da
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/adapters/caip-permission-adapter-accounts.cjs +143 -26
- package/dist/adapters/caip-permission-adapter-accounts.cjs.map +1 -1
- package/dist/adapters/caip-permission-adapter-accounts.d.cts +46 -1
- package/dist/adapters/caip-permission-adapter-accounts.d.cts.map +1 -1
- package/dist/adapters/caip-permission-adapter-accounts.d.mts +46 -1
- package/dist/adapters/caip-permission-adapter-accounts.d.mts.map +1 -1
- package/dist/adapters/caip-permission-adapter-accounts.mjs +137 -24
- package/dist/adapters/caip-permission-adapter-accounts.mjs.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.cjs +125 -31
- package/dist/adapters/caip-permission-adapter-permittedChains.cjs.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.d.cts +45 -4
- package/dist/adapters/caip-permission-adapter-permittedChains.d.cts.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.d.mts +45 -4
- package/dist/adapters/caip-permission-adapter-permittedChains.d.mts.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.mjs +118 -28
- package/dist/adapters/caip-permission-adapter-permittedChains.mjs.map +1 -1
- package/dist/caip25Permission.cjs +14 -3
- package/dist/caip25Permission.cjs.map +1 -1
- package/dist/caip25Permission.d.cts +16 -0
- package/dist/caip25Permission.d.cts.map +1 -1
- package/dist/caip25Permission.d.mts +16 -0
- package/dist/caip25Permission.d.mts.map +1 -1
- package/dist/caip25Permission.mjs +14 -4
- package/dist/caip25Permission.mjs.map +1 -1
- package/dist/index.cjs +15 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6 -7
- package/dist/index.mjs.map +1 -1
- package/dist/scope/authorization.cjs +16 -1
- package/dist/scope/authorization.cjs.map +1 -1
- package/dist/scope/authorization.d.cts +9 -1
- package/dist/scope/authorization.d.cts.map +1 -1
- package/dist/scope/authorization.d.mts +9 -1
- package/dist/scope/authorization.d.mts.map +1 -1
- package/dist/scope/authorization.mjs +14 -0
- package/dist/scope/authorization.mjs.map +1 -1
- package/dist/scope/constants.cjs +11 -1
- package/dist/scope/constants.cjs.map +1 -1
- package/dist/scope/constants.d.cts +7 -0
- package/dist/scope/constants.d.cts.map +1 -1
- package/dist/scope/constants.d.mts +7 -0
- package/dist/scope/constants.d.mts.map +1 -1
- package/dist/scope/constants.mjs +9 -0
- package/dist/scope/constants.mjs.map +1 -1
- package/dist/scope/filter.cjs +1 -29
- package/dist/scope/filter.cjs.map +1 -1
- package/dist/scope/filter.d.cts +2 -18
- package/dist/scope/filter.d.cts.map +1 -1
- package/dist/scope/filter.d.mts +2 -18
- package/dist/scope/filter.d.mts.map +1 -1
- package/dist/scope/filter.mjs +0 -26
- package/dist/scope/filter.mjs.map +1 -1
- package/dist/scope/validation.cjs +1 -12
- package/dist/scope/validation.cjs.map +1 -1
- package/dist/scope/validation.d.cts +0 -8
- package/dist/scope/validation.d.cts.map +1 -1
- package/dist/scope/validation.d.mts +0 -8
- package/dist/scope/validation.d.mts.map +1 -1
- package/dist/scope/validation.mjs +0 -10
- package/dist/scope/validation.mjs.map +1 -1
- package/package.json +2 -1
@@ -35,4 +35,11 @@ export declare const KnownNotifications: Record<NonWalletKnownCaipNamespace, str
|
|
35
35
|
export declare enum KnownSessionProperties {
|
36
36
|
SolanaAccountChangedNotifications = "solana_accountChanged_notifications"
|
37
37
|
}
|
38
|
+
/**
|
39
|
+
* Checks if a given value is a known session property.
|
40
|
+
*
|
41
|
+
* @param value - The value to check.
|
42
|
+
* @returns `true` if the value is a known session property, otherwise `false`.
|
43
|
+
*/
|
44
|
+
export declare function isKnownSessionPropertyValue(value: string): value is KnownSessionProperties;
|
38
45
|
//# sourceMappingURL=constants.d.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;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.mts","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;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,GACZ,KAAK,IAAI,sBAAsB,CAIjC"}
|
package/dist/scope/constants.mjs
CHANGED
@@ -88,4 +88,13 @@ export var KnownSessionProperties;
|
|
88
88
|
(function (KnownSessionProperties) {
|
89
89
|
KnownSessionProperties["SolanaAccountChangedNotifications"] = "solana_accountChanged_notifications";
|
90
90
|
})(KnownSessionProperties || (KnownSessionProperties = {}));
|
91
|
+
/**
|
92
|
+
* Checks if a given value is a known session property.
|
93
|
+
*
|
94
|
+
* @param value - The value to check.
|
95
|
+
* @returns `true` if the value is a known session property, otherwise `false`.
|
96
|
+
*/
|
97
|
+
export function isKnownSessionPropertyValue(value) {
|
98
|
+
return Object.values(KnownSessionProperties).includes(value);
|
99
|
+
}
|
91
100
|
//# 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,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AE;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,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;AAED;;;;;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 MetaMaskOpenRPCDocument from '@metamask/api-specs';\n\nimport type { NonWalletKnownCaipNamespace } from './types';\n\n/**\n * ScopeStrings for offchain methods that are not specific to a chainId but are specific to a CAIP namespace.\n */\nexport enum KnownWalletScopeString {\n Eip155 = 'wallet:eip155',\n}\n\n/**\n * Regexes defining how references must be formed for non-wallet known CAIP namespaces\n */\nexport const CaipReferenceRegexes: Record<NonWalletKnownCaipNamespace, RegExp> =\n {\n eip155: /^(0|[1-9][0-9]*)$/u,\n bip122: /.*/u,\n solana: /.*/u,\n };\n\n/**\n * Methods that do not belong exclusively to any CAIP namespace.\n */\nexport const KnownWalletRpcMethods: string[] = [\n 'wallet_registerOnboarding',\n 'wallet_scanQRCode',\n];\n\n/**\n * Methods that belong to the `wallet:eip155` scope.\n */\nconst WalletEip155Methods = ['wallet_addEthereumChain'];\n\n/**\n * Methods that are only supported via the EIP-1193 API.\n */\nexport const Eip1193OnlyMethods = [\n 'wallet_switchEthereumChain',\n 'wallet_getPermissions',\n 'wallet_requestPermissions',\n 'wallet_revokePermissions',\n 'eth_requestAccounts',\n 'eth_accounts',\n 'eth_coinbase',\n 'net_version',\n 'metamask_logWeb3ShimUsage',\n 'metamask_getProviderState',\n 'metamask_sendDomainMetadata',\n 'wallet_registerOnboarding',\n];\n\n/**\n * All MetaMask methods, except for ones we have specified in the constants above.\n */\nconst Eip155Methods = MetaMaskOpenRPCDocument.methods\n .map(({ name }: { name: string }) => name)\n .filter((method: string) => !WalletEip155Methods.includes(method))\n .filter((method: string) => !KnownWalletRpcMethods.includes(method))\n .filter((method: string) => !Eip1193OnlyMethods.includes(method));\n\n/**\n * Methods by ecosystem that are chain specific.\n */\nexport const KnownRpcMethods: Record<NonWalletKnownCaipNamespace, string[]> = {\n eip155: Eip155Methods,\n bip122: [],\n solana: [],\n};\n\n/**\n * Methods for CAIP namespaces that aren't chain specific.\n */\nexport const KnownWalletNamespaceRpcMethods: Record<\n NonWalletKnownCaipNamespace,\n string[]\n> = {\n eip155: WalletEip155Methods,\n bip122: [],\n solana: [],\n};\n\n/**\n * Notifications for known CAIP namespaces.\n */\nexport const KnownNotifications: Record<NonWalletKnownCaipNamespace, string[]> =\n {\n eip155: ['eth_subscription'],\n bip122: [],\n solana: [],\n };\n\n/**\n * Session properties for known CAIP namespaces.\n */\nexport enum KnownSessionProperties {\n SolanaAccountChangedNotifications = 'solana_accountChanged_notifications',\n}\n\n/**\n * Checks if a given value is a known session property.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a known session property, otherwise `false`.\n */\nexport function isKnownSessionPropertyValue(\n value: string,\n): value is KnownSessionProperties {\n return Object.values(KnownSessionProperties).includes(\n value as KnownSessionProperties,\n );\n}\n"]}
|
package/dist/scope/filter.cjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
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,32 +73,4 @@ 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;
|
104
76
|
//# sourceMappingURL=filter.cjs.map
|
@@ -1 +1 @@
|
|
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,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,WAAk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AAE;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 { 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"]}
|
package/dist/scope/filter.d.cts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
1
|
+
import type { CaipChainId, Hex } from "@metamask/utils";
|
2
|
+
import type { NormalizedScopesObject } from "./types.cjs";
|
3
3
|
/**
|
4
4
|
* Groups a NormalizedScopesObject into two separate
|
5
5
|
* NormalizedScopesObject with supported scopes in one
|
@@ -32,20 +32,4 @@ 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[];
|
51
35
|
//# 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,
|
1
|
+
{"version":3,"file":"filter.d.cts","sourceRoot":"","sources":["../../src/scope/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAIV,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"}
|
package/dist/scope/filter.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
1
|
+
import type { CaipChainId, Hex } from "@metamask/utils";
|
2
|
+
import type { NormalizedScopesObject } from "./types.mjs";
|
3
3
|
/**
|
4
4
|
* Groups a NormalizedScopesObject into two separate
|
5
5
|
* NormalizedScopesObject with supported scopes in one
|
@@ -32,20 +32,4 @@ 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[];
|
51
35
|
//# 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,
|
1
|
+
{"version":3,"file":"filter.d.mts","sourceRoot":"","sources":["../../src/scope/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,WAAW,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAIV,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"}
|
package/dist/scope/filter.mjs
CHANGED
@@ -68,30 +68,4 @@ 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
|
-
}
|
97
71
|
//# 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;AAQzE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,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,2BAA2B,CAAC,WAAW,CAAC,CAAC;QACzC,IAAI;YACF,oBAAoB,CAAC,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;AAEF;;;;;;;;;GASG;AACH,MAAM,uBAAuB,GAAG,CAC9B,WAAgC,EAChC,WAAkC,EAClC,EACE,yBAAyB,G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AAM,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 { 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"]}
|
@@ -1,8 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.getValidScopes = exports.isValidScope = void 0;
|
4
4
|
const utils_1 = require("@metamask/utils");
|
5
|
-
const constants_1 = require("./constants.cjs");
|
6
5
|
const types_1 = require("./types.cjs");
|
7
6
|
/**
|
8
7
|
* Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.
|
@@ -85,14 +84,4 @@ const getValidScopes = (requiredScopes, optionalScopes) => {
|
|
85
84
|
};
|
86
85
|
};
|
87
86
|
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;
|
98
87
|
//# sourceMappingURL=validation.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":";;;AAAA,2CAAkD;
|
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,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,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AAc,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,4 +1,3 @@
|
|
1
|
-
import { KnownSessionProperties } from "./constants.cjs";
|
2
1
|
import type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject } from "./types.cjs";
|
3
2
|
/**
|
4
3
|
* Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.
|
@@ -19,11 +18,4 @@ export declare const getValidScopes: (requiredScopes?: ExternalScopesObject, opt
|
|
19
18
|
validRequiredScopes: ExternalScopesObject;
|
20
19
|
validOptionalScopes: ExternalScopesObject;
|
21
20
|
};
|
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;
|
29
21
|
//# sourceMappingURL=validation.d.cts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":"AAEA,OAAO,
|
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,4 +1,3 @@
|
|
1
|
-
import { KnownSessionProperties } from "./constants.mjs";
|
2
1
|
import type { ExternalScopeString, ExternalScopeObject, ExternalScopesObject } from "./types.mjs";
|
3
2
|
/**
|
4
3
|
* Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.
|
@@ -19,11 +18,4 @@ export declare const getValidScopes: (requiredScopes?: ExternalScopesObject, opt
|
|
19
18
|
validRequiredScopes: ExternalScopesObject;
|
20
19
|
validOptionalScopes: ExternalScopesObject;
|
21
20
|
};
|
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;
|
29
21
|
//# sourceMappingURL=validation.d.mts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validation.d.mts","sourceRoot":"","sources":["../../src/scope/validation.ts"],"names":[],"mappings":"AAEA,OAAO,
|
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,5 +1,4 @@
|
|
1
1
|
import { isCaipReference } from "@metamask/utils";
|
2
|
-
import { KnownSessionProperties } from "./constants.mjs";
|
3
2
|
import { parseScopeString } from "./types.mjs";
|
4
3
|
/**
|
5
4
|
* Validates a scope object according to the [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) spec.
|
@@ -80,13 +79,4 @@ export const getValidScopes = (requiredScopes, optionalScopes) => {
|
|
80
79
|
validOptionalScopes,
|
81
80
|
};
|
82
81
|
};
|
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
|
-
}
|
92
82
|
//# 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;
|
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,CAAC,kBAAkB,EAAE;YACvB,OAAO,KAAK,CAAC;SACd;KACF;I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AG;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"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask-previews/chain-agnostic-permission",
|
3
|
-
"version": "0.4.0-preview-
|
3
|
+
"version": "0.4.0-preview-514219da",
|
4
4
|
"description": "Defines a CAIP-25 based endowment permission and helpers for interfacing with it",
|
5
5
|
"keywords": [
|
6
6
|
"MetaMask",
|
@@ -57,6 +57,7 @@
|
|
57
57
|
},
|
58
58
|
"devDependencies": {
|
59
59
|
"@metamask/auto-changelog": "^3.4.4",
|
60
|
+
"@metamask/keyring-internal-api": "^6.0.1",
|
60
61
|
"@types/jest": "^27.4.1",
|
61
62
|
"deepmerge": "^4.2.2",
|
62
63
|
"jest": "^27.5.1",
|