@metamask-previews/chain-agnostic-permission 0.2.0-preview-8c3b89c → 0.2.0-preview-62c1e797
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/dist/adapters/caip-permission-adapter-accounts.cjs +32 -4
- package/dist/adapters/caip-permission-adapter-accounts.cjs.map +1 -1
- package/dist/adapters/caip-permission-adapter-accounts.d.cts +11 -0
- package/dist/adapters/caip-permission-adapter-accounts.d.cts.map +1 -1
- package/dist/adapters/caip-permission-adapter-accounts.d.mts +11 -0
- package/dist/adapters/caip-permission-adapter-accounts.d.mts.map +1 -1
- package/dist/adapters/caip-permission-adapter-accounts.mjs +31 -3
- package/dist/adapters/caip-permission-adapter-accounts.mjs.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.cjs +37 -34
- package/dist/adapters/caip-permission-adapter-permittedChains.cjs.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.d.cts +9 -7
- package/dist/adapters/caip-permission-adapter-permittedChains.d.cts.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.d.mts +9 -7
- package/dist/adapters/caip-permission-adapter-permittedChains.d.mts.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.mjs +35 -32
- package/dist/adapters/caip-permission-adapter-permittedChains.mjs.map +1 -1
- package/dist/caip25Permission.cjs +13 -8
- package/dist/caip25Permission.cjs.map +1 -1
- package/dist/caip25Permission.d.cts +7 -6
- package/dist/caip25Permission.d.cts.map +1 -1
- package/dist/caip25Permission.d.mts +7 -6
- package/dist/caip25Permission.d.mts.map +1 -1
- package/dist/caip25Permission.mjs +13 -8
- package/dist/caip25Permission.mjs.map +1 -1
- package/dist/scope/types.cjs +1 -0
- package/dist/scope/types.cjs.map +1 -1
- package/dist/scope/types.d.cts +1 -0
- package/dist/scope/types.d.cts.map +1 -1
- package/dist/scope/types.d.mts +1 -0
- package/dist/scope/types.d.mts.map +1 -1
- package/dist/scope/types.mjs +1 -0
- package/dist/scope/types.mjs.map +1 -1
- package/package.json +1 -1
@@ -1,10 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.setPermittedAccounts = exports.setEthAccounts = exports.getEthAccounts = void 0;
|
3
|
+
exports.getAllAccountsFromCaip25Caveat = exports.setPermittedAccounts = exports.setEthAccounts = exports.getEthAccounts = void 0;
|
4
4
|
const utils_1 = require("@metamask/utils");
|
5
5
|
const constants_1 = require("../scope/constants.cjs");
|
6
6
|
const transform_1 = require("../scope/transform.cjs");
|
7
7
|
const types_1 = require("../scope/types.cjs");
|
8
|
+
const lodash_1 = require("lodash");
|
8
9
|
/**
|
9
10
|
* Checks if a scope string is either an EIP155 or wallet namespaced scope string.
|
10
11
|
*
|
@@ -102,6 +103,7 @@ const setEthAccounts = (caip25CaveatValue, accounts) => {
|
|
102
103
|
exports.setEthAccounts = setEthAccounts;
|
103
104
|
/**
|
104
105
|
* Sets the permitted accounts for the given scopes object.
|
106
|
+
*
|
105
107
|
* @param scopesObject - The scopes object to set the permitted accounts for.
|
106
108
|
* @param accounts - The permitted accounts to add to the appropriate scopes.
|
107
109
|
* @returns The updated scopes object with the permitted accounts set.
|
@@ -115,21 +117,25 @@ const setPermittedAccountsForScopesObject = (scopesObject, accounts) => {
|
|
115
117
|
let caipAccounts = [];
|
116
118
|
if (namespace && reference) {
|
117
119
|
caipAccounts = accounts.reduce((acc, account) => {
|
118
|
-
|
119
|
-
|
120
|
+
const { chain: { namespace: accountNamespace }, address: accountAddress, } = (0, utils_1.parseCaipAccountId)(account);
|
121
|
+
// If the account namespace is the same as the scope namespace, add the account to the scope
|
122
|
+
// This will, for example, distribute all EIP155 accounts, regardless of reference, to all EIP155 scopes
|
123
|
+
if (namespace === accountNamespace) {
|
124
|
+
acc.push(`${namespace}:${reference}:${accountAddress}`);
|
120
125
|
}
|
121
126
|
return acc;
|
122
127
|
}, []);
|
123
128
|
}
|
124
129
|
updatedScopesObject[scopeString] = {
|
125
130
|
...scopeObject,
|
126
|
-
accounts: caipAccounts,
|
131
|
+
accounts: (0, lodash_1.uniq)(caipAccounts),
|
127
132
|
};
|
128
133
|
});
|
129
134
|
return updatedScopesObject;
|
130
135
|
};
|
131
136
|
/**
|
132
137
|
* Sets the permitted accounts for the given CAIP-25 caveat value.
|
138
|
+
*
|
133
139
|
* @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.
|
134
140
|
* @param accounts - The permitted accounts to add to the appropriate scopes.
|
135
141
|
* @returns The updated CAIP-25 caveat value with the permitted accounts set.
|
@@ -142,4 +148,26 @@ const setPermittedAccounts = (caip25CaveatValue, accounts) => {
|
|
142
148
|
};
|
143
149
|
};
|
144
150
|
exports.setPermittedAccounts = setPermittedAccounts;
|
151
|
+
/**
|
152
|
+
* Gets the requested accounts from the given CAIP-25 caveat value.
|
153
|
+
*
|
154
|
+
* @param requestedCaip25CaveatValue - CAIP-25 request values.
|
155
|
+
* @returns Accounts available for requesting.
|
156
|
+
*/
|
157
|
+
function getAllAccountsFromCaip25Caveat(requestedCaip25CaveatValue) {
|
158
|
+
const requiredAccounts = Object.values(requestedCaip25CaveatValue.requiredScopes)
|
159
|
+
.flatMap((scope) => scope.accounts)
|
160
|
+
.map((account) => ({
|
161
|
+
address: (0, utils_1.parseCaipAccountId)(account).address,
|
162
|
+
chainId: (0, utils_1.parseCaipAccountId)(account).chainId,
|
163
|
+
}));
|
164
|
+
const optionalAccounts = Object.values(requestedCaip25CaveatValue.optionalScopes)
|
165
|
+
.flatMap((scope) => scope.accounts)
|
166
|
+
.map((account) => ({
|
167
|
+
address: (0, utils_1.parseCaipAccountId)(account).address,
|
168
|
+
chainId: (0, utils_1.parseCaipAccountId)(account).chainId,
|
169
|
+
}));
|
170
|
+
return [...requiredAccounts, ...optionalAccounts];
|
171
|
+
}
|
172
|
+
exports.getAllAccountsFromCaip25Caveat = getAllAccountsFromCaip25Caveat;
|
145
173
|
//# sourceMappingURL=caip-permission-adapter-accounts.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-accounts.cjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":";;;AAAA,2CAMyB;AAGzB,sDAA4D;AAC5D,sDAAyD;AAEzD,8CAAkD;AAElD;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,CAAC,WAAgC,EAAE,EAAE;IAC/D,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAEpD,OAAO,CACL,SAAS,KAAK,0BAAkB,CAAC,MAAM;QACvC,sDAAsD;QACtD,wEAAwE;QACxE,WAAW,KAAK,kCAAsB,CAAC,MAAM,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,MAA4B,EAAE,EAAE;IAChE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE;QACnD,QAAQ,EAAE,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC5B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;YAEzD,IAAI,mBAAmB,CAAC,OAAO,CAAC,EAAE;gBAChC,2DAA2D;gBAC3D,kCAAkC;gBAClC,IAAA,+BAAuB,EAAC,OAAO,CAAC,CAAC;gBACjC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aAC3B;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;GAKG;AACI,MAAM,cAAc,GAAG,CAC5B,iBAGC,EACM,EAAE;IACT,MAAM,EAAE,cAAc,EAAE,cA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AAO;QACL,GAAG,iBAAiB;QACpB,cAAc,EAAE,mCAAmC,CACjD,iBAAiB,CAAC,cAAc,EAChC,QAAQ,CACT;QACD,cAAc,EAAE,mCAAmC,CACjD,iBAAiB,CAAC,cAAc,EAChC,QAAQ,CACT;KACF,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,oBAAoB,wBAe/B","sourcesContent":["import {\n assertIsStrictHexString,\n type CaipAccountId,\n type Hex,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { KnownWalletScopeString } from '../scope/constants';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopeString, InternalScopesObject } from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Checks if a scope string is either an EIP155 or wallet namespaced scope string.\n *\n * @param scopeString - The scope string to check.\n * @returns True if the scope string is an EIP155 or wallet namespaced scope string, false otherwise.\n */\nconst isEip155ScopeString = (scopeString: InternalScopeString) => {\n const { namespace } = parseScopeString(scopeString);\n\n return (\n namespace === KnownCaipNamespace.Eip155 ||\n // We are trying to discern the type of `scopeString`.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n scopeString === KnownWalletScopeString.Eip155\n );\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum accounts.\n * @returns An array of Ethereum accounts.\n */\nconst getEthAccountsFromScopes = (scopes: InternalScopesObject) => {\n const ethAccounts: Hex[] = [];\n\n Object.entries(scopes).forEach(([_, { accounts }]) => {\n accounts?.forEach((account) => {\n const { address, chainId } = parseCaipAccountId(account);\n\n if (isEip155ScopeString(chainId)) {\n // This address should always be a valid Hex string because\n // it's an EIP155/Ethereum account\n assertIsStrictHexString(address);\n ethAccounts.push(address);\n }\n });\n });\n\n return ethAccounts;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to get the Ethereum accounts from.\n * @returns An array of Ethereum accounts.\n */\nexport const getEthAccounts = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n): Hex[] => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethAccounts: Hex[] = [\n ...getEthAccountsFromScopes(requiredScopes),\n ...getEthAccountsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethAccounts);\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given scopes object.\n *\n * @param scopesObject - The scopes object to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated scopes object with the Ethereum accounts set.\n */\nconst setEthAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: Hex[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const isWalletNamespace = scopeString === KnownCaipNamespace.Wallet;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!isEip155ScopeString(scopeString) && !isWalletNamespace) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.map<CaipAccountId>(\n (account) => `${namespace}:${reference}:${account}`,\n );\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: caipAccounts,\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given CAIP-25 caveat value.\n * We set the same accounts for all the scopes that are EIP155 or Wallet namespaced because\n * we do not provide UI/UX flows for selecting different accounts across different chains.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated CAIP-25 caveat value with the Ethereum accounts set.\n */\nexport const setEthAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: Hex[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n\n/**\n * Sets the permitted accounts for the given scopes object.\n * @param scopesObject - The scopes object to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated scopes object with the permitted accounts set.\n */\nconst setPermittedAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: CaipAccountId[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.reduce<CaipAccountId[]>(\n (acc, account) => {\n if (account.startsWith(`${namespace}:${reference}`)) {\n acc.push(account);\n }\n return acc;\n },\n [],\n );\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: caipAccounts,\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted accounts for the given CAIP-25 caveat value.\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated CAIP-25 caveat value with the permitted accounts set.\n */\nexport const setPermittedAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: CaipAccountId[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setPermittedAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setPermittedAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n"]}
|
1
|
+
{"version":3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D,wEAsBC","sourcesContent":["import {\n assertIsStrictHexString,\n type CaipAccountId,\n type Hex,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { KnownWalletScopeString } from '../scope/constants';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopeString, InternalScopesObject } from '../scope/types';\nimport { parseScopeString } from '../scope/types';\nimport { uniq } from 'lodash';\n\n/**\n * Checks if a scope string is either an EIP155 or wallet namespaced scope string.\n *\n * @param scopeString - The scope string to check.\n * @returns True if the scope string is an EIP155 or wallet namespaced scope string, false otherwise.\n */\nconst isEip155ScopeString = (scopeString: InternalScopeString) => {\n const { namespace } = parseScopeString(scopeString);\n\n return (\n namespace === KnownCaipNamespace.Eip155 ||\n // We are trying to discern the type of `scopeString`.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n scopeString === KnownWalletScopeString.Eip155\n );\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum accounts.\n * @returns An array of Ethereum accounts.\n */\nconst getEthAccountsFromScopes = (scopes: InternalScopesObject) => {\n const ethAccounts: Hex[] = [];\n\n Object.entries(scopes).forEach(([_, { accounts }]) => {\n accounts?.forEach((account) => {\n const { address, chainId } = parseCaipAccountId(account);\n\n if (isEip155ScopeString(chainId)) {\n // This address should always be a valid Hex string because\n // it's an EIP155/Ethereum account\n assertIsStrictHexString(address);\n ethAccounts.push(address);\n }\n });\n });\n\n return ethAccounts;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to get the Ethereum accounts from.\n * @returns An array of Ethereum accounts.\n */\nexport const getEthAccounts = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n): Hex[] => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethAccounts: Hex[] = [\n ...getEthAccountsFromScopes(requiredScopes),\n ...getEthAccountsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethAccounts);\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given scopes object.\n *\n * @param scopesObject - The scopes object to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated scopes object with the Ethereum accounts set.\n */\nconst setEthAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: Hex[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const isWalletNamespace = scopeString === KnownCaipNamespace.Wallet;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!isEip155ScopeString(scopeString) && !isWalletNamespace) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.map<CaipAccountId>(\n (account) => `${namespace}:${reference}:${account}`,\n );\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: caipAccounts,\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given CAIP-25 caveat value.\n * We set the same accounts for all the scopes that are EIP155 or Wallet namespaced because\n * we do not provide UI/UX flows for selecting different accounts across different chains.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated CAIP-25 caveat value with the Ethereum accounts set.\n */\nexport const setEthAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: Hex[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/**\n * Sets the permitted accounts for the given scopes object.\n *\n * @param scopesObject - The scopes object to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated scopes object with the permitted accounts set.\n */\nconst setPermittedAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: CaipAccountId[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.reduce<CaipAccountId[]>((acc, account) => {\n const {\n chain: { namespace: accountNamespace },\n address: accountAddress,\n } = parseCaipAccountId(account);\n // If the account namespace is the same as the scope namespace, add the account to the scope\n // This will, for example, distribute all EIP155 accounts, regardless of reference, to all EIP155 scopes\n if (namespace === accountNamespace) {\n acc.push(`${namespace}:${reference}:${accountAddress}`);\n }\n return acc;\n }, []);\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: uniq(caipAccounts),\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted accounts for the given CAIP-25 caveat value.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated CAIP-25 caveat value with the permitted accounts set.\n */\nexport const setPermittedAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: CaipAccountId[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setPermittedAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setPermittedAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/**\n * Gets the requested accounts from the given CAIP-25 caveat value.\n *\n * @param requestedCaip25CaveatValue - CAIP-25 request values.\n * @returns Accounts available for requesting.\n */\nexport function getAllAccountsFromCaip25Caveat(\n requestedCaip25CaveatValue: Caip25CaveatValue,\n) {\n const requiredAccounts = Object.values(\n requestedCaip25CaveatValue.requiredScopes,\n )\n .flatMap((scope) => scope.accounts)\n .map((account) => ({\n address: parseCaipAccountId(account).address,\n chainId: parseCaipAccountId(account).chainId,\n }));\n\n const optionalAccounts = Object.values(\n requestedCaip25CaveatValue.optionalScopes,\n )\n .flatMap((scope) => scope.accounts)\n .map((account) => ({\n address: parseCaipAccountId(account).address,\n chainId: parseCaipAccountId(account).chainId,\n }));\n\n return [...requiredAccounts, ...optionalAccounts];\n}\n"]}
|
@@ -19,9 +19,20 @@ export declare const getEthAccounts: (caip25CaveatValue: Pick<Caip25CaveatValue,
|
|
19
19
|
export declare const setEthAccounts: (caip25CaveatValue: Caip25CaveatValue, accounts: Hex[]) => Caip25CaveatValue;
|
20
20
|
/**
|
21
21
|
* Sets the permitted accounts for the given CAIP-25 caveat value.
|
22
|
+
*
|
22
23
|
* @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.
|
23
24
|
* @param accounts - The permitted accounts to add to the appropriate scopes.
|
24
25
|
* @returns The updated CAIP-25 caveat value with the permitted accounts set.
|
25
26
|
*/
|
26
27
|
export declare const setPermittedAccounts: (caip25CaveatValue: Caip25CaveatValue, accounts: CaipAccountId[]) => Caip25CaveatValue;
|
28
|
+
/**
|
29
|
+
* Gets the requested accounts from the given CAIP-25 caveat value.
|
30
|
+
*
|
31
|
+
* @param requestedCaip25CaveatValue - CAIP-25 request values.
|
32
|
+
* @returns Accounts available for requesting.
|
33
|
+
*/
|
34
|
+
export declare function getAllAccountsFromCaip25Caveat(requestedCaip25CaveatValue: Caip25CaveatValue): {
|
35
|
+
address: string;
|
36
|
+
chainId: `${string}:${string}`;
|
37
|
+
}[];
|
27
38
|
//# sourceMappingURL=caip-permission-adapter-accounts.d.cts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-accounts.d.cts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,GAAG,EAGT,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;
|
1
|
+
{"version":3,"file":"caip-permission-adapter-accounts.d.cts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,GAAG,EAGT,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAiD7D;;;;;GAKG;AACH,eAAO,MAAM,cAAc,sBACN,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,KACA,GAAG,EASL,CAAC;AAwCF;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,sBACN,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAYF,CAAC;AA4CF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,sBACZ,iBAAiB,YAC1B,aAAa,EAAE,KACxB,iBAYF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,0BAA0B,EAAE,iBAAiB;;;IAqB9C"}
|
@@ -19,9 +19,20 @@ export declare const getEthAccounts: (caip25CaveatValue: Pick<Caip25CaveatValue,
|
|
19
19
|
export declare const setEthAccounts: (caip25CaveatValue: Caip25CaveatValue, accounts: Hex[]) => Caip25CaveatValue;
|
20
20
|
/**
|
21
21
|
* Sets the permitted accounts for the given CAIP-25 caveat value.
|
22
|
+
*
|
22
23
|
* @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.
|
23
24
|
* @param accounts - The permitted accounts to add to the appropriate scopes.
|
24
25
|
* @returns The updated CAIP-25 caveat value with the permitted accounts set.
|
25
26
|
*/
|
26
27
|
export declare const setPermittedAccounts: (caip25CaveatValue: Caip25CaveatValue, accounts: CaipAccountId[]) => Caip25CaveatValue;
|
28
|
+
/**
|
29
|
+
* Gets the requested accounts from the given CAIP-25 caveat value.
|
30
|
+
*
|
31
|
+
* @param requestedCaip25CaveatValue - CAIP-25 request values.
|
32
|
+
* @returns Accounts available for requesting.
|
33
|
+
*/
|
34
|
+
export declare function getAllAccountsFromCaip25Caveat(requestedCaip25CaveatValue: Caip25CaveatValue): {
|
35
|
+
address: string;
|
36
|
+
chainId: `${string}:${string}`;
|
37
|
+
}[];
|
27
38
|
//# sourceMappingURL=caip-permission-adapter-accounts.d.mts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-accounts.d.mts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,GAAG,EAGT,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;
|
1
|
+
{"version":3,"file":"caip-permission-adapter-accounts.d.mts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,GAAG,EAGT,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAiD7D;;;;;GAKG;AACH,eAAO,MAAM,cAAc,sBACN,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,KACA,GAAG,EASL,CAAC;AAwCF;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,sBACN,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAYF,CAAC;AA4CF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,sBACZ,iBAAiB,YAC1B,aAAa,EAAE,KACxB,iBAYF,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC5C,0BAA0B,EAAE,iBAAiB;;;IAqB9C"}
|
@@ -2,6 +2,8 @@ import { assertIsStrictHexString, KnownCaipNamespace, parseCaipAccountId } from
|
|
2
2
|
import { KnownWalletScopeString } from "../scope/constants.mjs";
|
3
3
|
import { getUniqueArrayItems } from "../scope/transform.mjs";
|
4
4
|
import { parseScopeString } from "../scope/types.mjs";
|
5
|
+
import $lodash from "lodash";
|
6
|
+
const { uniq } = $lodash;
|
5
7
|
/**
|
6
8
|
* Checks if a scope string is either an EIP155 or wallet namespaced scope string.
|
7
9
|
*
|
@@ -97,6 +99,7 @@ export const setEthAccounts = (caip25CaveatValue, accounts) => {
|
|
97
99
|
};
|
98
100
|
/**
|
99
101
|
* Sets the permitted accounts for the given scopes object.
|
102
|
+
*
|
100
103
|
* @param scopesObject - The scopes object to set the permitted accounts for.
|
101
104
|
* @param accounts - The permitted accounts to add to the appropriate scopes.
|
102
105
|
* @returns The updated scopes object with the permitted accounts set.
|
@@ -110,21 +113,25 @@ const setPermittedAccountsForScopesObject = (scopesObject, accounts) => {
|
|
110
113
|
let caipAccounts = [];
|
111
114
|
if (namespace && reference) {
|
112
115
|
caipAccounts = accounts.reduce((acc, account) => {
|
113
|
-
|
114
|
-
|
116
|
+
const { chain: { namespace: accountNamespace }, address: accountAddress, } = parseCaipAccountId(account);
|
117
|
+
// If the account namespace is the same as the scope namespace, add the account to the scope
|
118
|
+
// This will, for example, distribute all EIP155 accounts, regardless of reference, to all EIP155 scopes
|
119
|
+
if (namespace === accountNamespace) {
|
120
|
+
acc.push(`${namespace}:${reference}:${accountAddress}`);
|
115
121
|
}
|
116
122
|
return acc;
|
117
123
|
}, []);
|
118
124
|
}
|
119
125
|
updatedScopesObject[scopeString] = {
|
120
126
|
...scopeObject,
|
121
|
-
accounts: caipAccounts,
|
127
|
+
accounts: uniq(caipAccounts),
|
122
128
|
};
|
123
129
|
});
|
124
130
|
return updatedScopesObject;
|
125
131
|
};
|
126
132
|
/**
|
127
133
|
* Sets the permitted accounts for the given CAIP-25 caveat value.
|
134
|
+
*
|
128
135
|
* @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.
|
129
136
|
* @param accounts - The permitted accounts to add to the appropriate scopes.
|
130
137
|
* @returns The updated CAIP-25 caveat value with the permitted accounts set.
|
@@ -136,4 +143,25 @@ export const setPermittedAccounts = (caip25CaveatValue, accounts) => {
|
|
136
143
|
optionalScopes: setPermittedAccountsForScopesObject(caip25CaveatValue.optionalScopes, accounts),
|
137
144
|
};
|
138
145
|
};
|
146
|
+
/**
|
147
|
+
* Gets the requested accounts from the given CAIP-25 caveat value.
|
148
|
+
*
|
149
|
+
* @param requestedCaip25CaveatValue - CAIP-25 request values.
|
150
|
+
* @returns Accounts available for requesting.
|
151
|
+
*/
|
152
|
+
export function getAllAccountsFromCaip25Caveat(requestedCaip25CaveatValue) {
|
153
|
+
const requiredAccounts = Object.values(requestedCaip25CaveatValue.requiredScopes)
|
154
|
+
.flatMap((scope) => scope.accounts)
|
155
|
+
.map((account) => ({
|
156
|
+
address: parseCaipAccountId(account).address,
|
157
|
+
chainId: parseCaipAccountId(account).chainId,
|
158
|
+
}));
|
159
|
+
const optionalAccounts = Object.values(requestedCaip25CaveatValue.optionalScopes)
|
160
|
+
.flatMap((scope) => scope.accounts)
|
161
|
+
.map((account) => ({
|
162
|
+
address: parseCaipAccountId(account).address,
|
163
|
+
chainId: parseCaipAccountId(account).chainId,
|
164
|
+
}));
|
165
|
+
return [...requiredAccounts, ...optionalAccounts];
|
166
|
+
}
|
139
167
|
//# sourceMappingURL=caip-permission-adapter-accounts.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-accounts.mjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAGvB,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EAAE,sBAAsB,EAAE,+BAA2B;AAC5D,OAAO,EAAE,mBAAmB,EAAE,+BAA2B;AAEzD,OAAO,EAAE,gBAAgB,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,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { KnownWalletScopeString } from '../scope/constants';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopeString, InternalScopesObject } from '../scope/types';\nimport { parseScopeString } from '../scope/types';\n\n/**\n * Checks if a scope string is either an EIP155 or wallet namespaced scope string.\n *\n * @param scopeString - The scope string to check.\n * @returns True if the scope string is an EIP155 or wallet namespaced scope string, false otherwise.\n */\nconst isEip155ScopeString = (scopeString: InternalScopeString) => {\n const { namespace } = parseScopeString(scopeString);\n\n return (\n namespace === KnownCaipNamespace.Eip155 ||\n // We are trying to discern the type of `scopeString`.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n scopeString === KnownWalletScopeString.Eip155\n );\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum accounts.\n * @returns An array of Ethereum accounts.\n */\nconst getEthAccountsFromScopes = (scopes: InternalScopesObject) => {\n const ethAccounts: Hex[] = [];\n\n Object.entries(scopes).forEach(([_, { accounts }]) => {\n accounts?.forEach((account) => {\n const { address, chainId } = parseCaipAccountId(account);\n\n if (isEip155ScopeString(chainId)) {\n // This address should always be a valid Hex string because\n // it's an EIP155/Ethereum account\n assertIsStrictHexString(address);\n ethAccounts.push(address);\n }\n });\n });\n\n return ethAccounts;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to get the Ethereum accounts from.\n * @returns An array of Ethereum accounts.\n */\nexport const getEthAccounts = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n): Hex[] => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethAccounts: Hex[] = [\n ...getEthAccountsFromScopes(requiredScopes),\n ...getEthAccountsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethAccounts);\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given scopes object.\n *\n * @param scopesObject - The scopes object to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated scopes object with the Ethereum accounts set.\n */\nconst setEthAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: Hex[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const isWalletNamespace = scopeString === KnownCaipNamespace.Wallet;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!isEip155ScopeString(scopeString) && !isWalletNamespace) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.map<CaipAccountId>(\n (account) => `${namespace}:${reference}:${account}`,\n );\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: caipAccounts,\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given CAIP-25 caveat value.\n * We set the same accounts for all the scopes that are EIP155 or Wallet namespaced because\n * we do not provide UI/UX flows for selecting different accounts across different chains.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated CAIP-25 caveat value with the Ethereum accounts set.\n */\nexport const setEthAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: Hex[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n\n/**\n * Sets the permitted accounts for the given scopes object.\n * @param scopesObject - The scopes object to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated scopes object with the permitted accounts set.\n */\nconst setPermittedAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: CaipAccountId[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.reduce<CaipAccountId[]>(\n (acc, account) => {\n if (account.startsWith(`${namespace}:${reference}`)) {\n acc.push(account);\n }\n return acc;\n },\n [],\n );\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: caipAccounts,\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted accounts for the given CAIP-25 caveat value.\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated CAIP-25 caveat value with the permitted accounts set.\n */\nexport const setPermittedAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: CaipAccountId[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setPermittedAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setPermittedAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n"]}
|
1
|
+
{"version":3,"file":"caip-permission-adapter-accounts.mjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAGvB,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EAAE,sBAAsB,EAAE,+BAA2B;AAC5D,OAAO,EAAE,mBAAmB,EAAE,+BAA2B;AAEzD,OAAO,EAAE,gBAAgB,E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ACjD,iBAAiB,CAAC,cAAc,EAChC,QAAQ,CACT;QACD,cAAc,EAAE,mCAAmC,CACjD,iBAAiB,CAAC,cAAc,EAChC,QAAQ,CACT;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAC5C,0BAA6C;IAE7C,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CACpC,0BAA0B,CAAC,cAAc,CAC1C;SACE,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC;SAClC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACjB,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC,OAAO;QAC5C,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC,OAAO;KAC7C,CAAC,CAAC,CAAC;IAEN,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CACpC,0BAA0B,CAAC,cAAc,CAC1C;SACE,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC;SAClC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACjB,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC,OAAO;QAC5C,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC,OAAO;KAC7C,CAAC,CAAC,CAAC;IAEN,OAAO,CAAC,GAAG,gBAAgB,EAAE,GAAG,gBAAgB,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import {\n assertIsStrictHexString,\n type CaipAccountId,\n type Hex,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { KnownWalletScopeString } from '../scope/constants';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopeString, InternalScopesObject } from '../scope/types';\nimport { parseScopeString } from '../scope/types';\nimport { uniq } from 'lodash';\n\n/**\n * Checks if a scope string is either an EIP155 or wallet namespaced scope string.\n *\n * @param scopeString - The scope string to check.\n * @returns True if the scope string is an EIP155 or wallet namespaced scope string, false otherwise.\n */\nconst isEip155ScopeString = (scopeString: InternalScopeString) => {\n const { namespace } = parseScopeString(scopeString);\n\n return (\n namespace === KnownCaipNamespace.Eip155 ||\n // We are trying to discern the type of `scopeString`.\n // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n scopeString === KnownWalletScopeString.Eip155\n );\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum accounts.\n * @returns An array of Ethereum accounts.\n */\nconst getEthAccountsFromScopes = (scopes: InternalScopesObject) => {\n const ethAccounts: Hex[] = [];\n\n Object.entries(scopes).forEach(([_, { accounts }]) => {\n accounts?.forEach((account) => {\n const { address, chainId } = parseCaipAccountId(account);\n\n if (isEip155ScopeString(chainId)) {\n // This address should always be a valid Hex string because\n // it's an EIP155/Ethereum account\n assertIsStrictHexString(address);\n ethAccounts.push(address);\n }\n });\n });\n\n return ethAccounts;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) accounts from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to get the Ethereum accounts from.\n * @returns An array of Ethereum accounts.\n */\nexport const getEthAccounts = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n): Hex[] => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethAccounts: Hex[] = [\n ...getEthAccountsFromScopes(requiredScopes),\n ...getEthAccountsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethAccounts);\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given scopes object.\n *\n * @param scopesObject - The scopes object to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated scopes object with the Ethereum accounts set.\n */\nconst setEthAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: Hex[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const isWalletNamespace = scopeString === KnownCaipNamespace.Wallet;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!isEip155ScopeString(scopeString) && !isWalletNamespace) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.map<CaipAccountId>(\n (account) => `${namespace}:${reference}:${account}`,\n );\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: caipAccounts,\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the Ethereum (EIP155 namespaced) accounts for the given CAIP-25 caveat value.\n * We set the same accounts for all the scopes that are EIP155 or Wallet namespaced because\n * we do not provide UI/UX flows for selecting different accounts across different chains.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the Ethereum accounts for.\n * @param accounts - The Ethereum accounts to set.\n * @returns The updated CAIP-25 caveat value with the Ethereum accounts set.\n */\nexport const setEthAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: Hex[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setEthAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/**\n * Sets the permitted accounts for the given scopes object.\n *\n * @param scopesObject - The scopes object to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated scopes object with the permitted accounts set.\n */\nconst setPermittedAccountsForScopesObject = (\n scopesObject: InternalScopesObject,\n accounts: CaipAccountId[],\n) => {\n const updatedScopesObject: InternalScopesObject = {};\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n\n let caipAccounts: CaipAccountId[] = [];\n if (namespace && reference) {\n caipAccounts = accounts.reduce<CaipAccountId[]>((acc, account) => {\n const {\n chain: { namespace: accountNamespace },\n address: accountAddress,\n } = parseCaipAccountId(account);\n // If the account namespace is the same as the scope namespace, add the account to the scope\n // This will, for example, distribute all EIP155 accounts, regardless of reference, to all EIP155 scopes\n if (namespace === accountNamespace) {\n acc.push(`${namespace}:${reference}:${accountAddress}`);\n }\n return acc;\n }, []);\n }\n\n updatedScopesObject[scopeString] = {\n ...scopeObject,\n accounts: uniq(caipAccounts),\n };\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted accounts for the given CAIP-25 caveat value.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted accounts for.\n * @param accounts - The permitted accounts to add to the appropriate scopes.\n * @returns The updated CAIP-25 caveat value with the permitted accounts set.\n */\nexport const setPermittedAccounts = (\n caip25CaveatValue: Caip25CaveatValue,\n accounts: CaipAccountId[],\n): Caip25CaveatValue => {\n return {\n ...caip25CaveatValue,\n requiredScopes: setPermittedAccountsForScopesObject(\n caip25CaveatValue.requiredScopes,\n accounts,\n ),\n optionalScopes: setPermittedAccountsForScopesObject(\n caip25CaveatValue.optionalScopes,\n accounts,\n ),\n };\n};\n\n/**\n * Gets the requested accounts from the given CAIP-25 caveat value.\n *\n * @param requestedCaip25CaveatValue - CAIP-25 request values.\n * @returns Accounts available for requesting.\n */\nexport function getAllAccountsFromCaip25Caveat(\n requestedCaip25CaveatValue: Caip25CaveatValue,\n) {\n const requiredAccounts = Object.values(\n requestedCaip25CaveatValue.requiredScopes,\n )\n .flatMap((scope) => scope.accounts)\n .map((account) => ({\n address: parseCaipAccountId(account).address,\n chainId: parseCaipAccountId(account).chainId,\n }));\n\n const optionalAccounts = Object.values(\n requestedCaip25CaveatValue.optionalScopes,\n )\n .flatMap((scope) => scope.accounts)\n .map((account) => ({\n address: parseCaipAccountId(account).address,\n chainId: parseCaipAccountId(account).chainId,\n }));\n\n return [...requiredAccounts, ...optionalAccounts];\n}\n"]}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.setPermittedChainIds = exports.addPermittedChainId = exports.setPermittedEthChainIds = exports.addPermittedEthChainId = exports.getPermittedEthChainIds = void 0;
|
4
4
|
const controller_utils_1 = require("@metamask/controller-utils");
|
5
5
|
const utils_1 = require("@metamask/utils");
|
6
6
|
const transform_1 = require("../scope/transform.cjs");
|
@@ -113,26 +113,33 @@ const setPermittedEthChainIds = (caip25CaveatValue, chainIds) => {
|
|
113
113
|
};
|
114
114
|
exports.setPermittedEthChainIds = setPermittedEthChainIds;
|
115
115
|
/**
|
116
|
-
*
|
117
|
-
*
|
118
|
-
*
|
119
|
-
*
|
116
|
+
* Filters the scopes object to only include:
|
117
|
+
* - Scopes without references (e.g. "wallet:")
|
118
|
+
* - CAIP-2 ChainId scopes for the given chainIDs
|
119
|
+
*
|
120
|
+
* @param scopesObject - The scopes object to filter.
|
121
|
+
* @param chainIds - The CAIP-2 chainIDs to filter for.
|
122
|
+
* @returns The filtered scopes object.
|
120
123
|
*/
|
121
|
-
const
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
124
|
+
const filterChainScopesObjectByChainId = (scopesObject, chainIds) => {
|
125
|
+
const updatedScopesObject = {};
|
126
|
+
Object.entries(scopesObject).forEach(([key, scopeObject]) => {
|
127
|
+
// Cast needed because index type is returned as `string` by `Object.entries`
|
128
|
+
const scopeString = key;
|
129
|
+
// If its a wallet scope or a wallet:* scope we don't filter it
|
130
|
+
if ((0, types_1.isWalletScope)(scopeString)) {
|
131
|
+
updatedScopesObject[scopeString] = scopeObject;
|
132
|
+
}
|
133
|
+
else if (chainIds.includes(scopeString)) {
|
134
|
+
updatedScopesObject[scopeString] = scopeObject;
|
135
|
+
}
|
129
136
|
});
|
130
|
-
return
|
137
|
+
return updatedScopesObject;
|
131
138
|
};
|
132
|
-
exports.setPermittedChainIds = setPermittedChainIds;
|
133
139
|
/**
|
134
140
|
* Adds a chainID to the optional scopes if it is not already present
|
135
141
|
* in either the pre-existing required or optional scopes.
|
142
|
+
*
|
136
143
|
* @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.
|
137
144
|
* @param chainId - The chainID to add.
|
138
145
|
* @returns The updated CAIP-25 caveat value with the added chainID.
|
@@ -154,26 +161,22 @@ const addPermittedChainId = (caip25CaveatValue, chainId) => {
|
|
154
161
|
};
|
155
162
|
exports.addPermittedChainId = addPermittedChainId;
|
156
163
|
/**
|
157
|
-
*
|
158
|
-
*
|
159
|
-
* - CAIP-
|
160
|
-
* @param
|
161
|
-
* @
|
162
|
-
* @returns The filtered scopes object.
|
164
|
+
* Sets the permitted CAIP-2 chainIDs for the required and optional scopes.
|
165
|
+
*
|
166
|
+
* @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.
|
167
|
+
* @param chainIds - The CAIP-2 chainIDs to set as permitted.
|
168
|
+
* @returns The updated CAIP-25 caveat value with the permitted CAIP-2 chainIDs.
|
163
169
|
*/
|
164
|
-
const
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
}
|
173
|
-
else if (chainIds.includes(scopeString)) {
|
174
|
-
updatedScopesObject[scopeString] = scopeObject;
|
175
|
-
}
|
170
|
+
const setPermittedChainIds = (caip25CaveatValue, chainIds) => {
|
171
|
+
let updatedCaveatValue = {
|
172
|
+
...caip25CaveatValue,
|
173
|
+
requiredScopes: filterChainScopesObjectByChainId(caip25CaveatValue.requiredScopes, chainIds),
|
174
|
+
optionalScopes: filterChainScopesObjectByChainId(caip25CaveatValue.optionalScopes, chainIds),
|
175
|
+
};
|
176
|
+
chainIds.forEach((chainId) => {
|
177
|
+
updatedCaveatValue = (0, exports.addPermittedChainId)(updatedCaveatValue, chainId);
|
176
178
|
});
|
177
|
-
return
|
179
|
+
return updatedCaveatValue;
|
178
180
|
};
|
181
|
+
exports.setPermittedChainIds = setPermittedChainIds;
|
179
182
|
//# sourceMappingURL=caip-permission-adapter-permittedChains.cjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-permittedChains.cjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-permittedChains.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AAEnD,2CAAkE;AAGlE,sDAAyD;AAEzD,8CAAiE;AAEjE;;;;;GAKG;AACH,MAAM,iCAAiC,GAAG,CAAC,MAA4B,EAAE,EAAE;IACzE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,IAAI,SAAS,EAAE;YACxD,WAAW,CAAC,IAAI,CAAC,IAAA,wBAAK,EAAC,SAAS,CAAC,CAAC,CAAC;SACpC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,iBAGC,EACD,EAAE;IACF,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,iBAAiB,CAAC;IAE7D,MAAM,WAAW,GAAU;QACzB,GAAG,iCAAiC,CAAC,cAAc,CAAC;QACpD,GAAG,iCAAiC,CAAC,cAAc,CAAC;KACrD,CAAC;IAEF,OAAO,IAAA,+BAAmB,EAAC,WAAW,CAAC,CAAC;AAC1C,CAAC,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AC,CAAC;AArBW,QAAA,oBAAoB,wBAqB/B;AAEF;;;;;;GAMG;AACI,MAAM,mBAAmB,GAAG,CACjC,iBAAoC,EACpC,OAAoB,EACD,EAAE;IACrB,IACE,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC/D,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAC/D;QACA,OAAO,iBAAiB,CAAC;KAC1B;IAED,OAAO;QACL,GAAG,iBAAiB;QACpB,cAAc,EAAE;YACd,GAAG,iBAAiB,CAAC,cAAc;YACnC,CAAC,OAAO,CAAC,EAAE;gBACT,QAAQ,EAAE,EAAE;aACb;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AApBW,QAAA,mBAAmB,uBAoB9B;AAEF;;;;;;;GAOG;AACH,MAAM,gCAAgC,GAAG,CACvC,YAAkC,EAClC,QAAuB,EACD,EAAE;IACxB,MAAM,mBAAmB,GAAyB,EAAE,CAAC;IAErD,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,EAAE,EAAE;QAC1D,6EAA6E;QAC7E,MAAM,WAAW,GAAG,GAAgC,CAAC;QACrD,+DAA+D;QAC/D,IAAI,IAAA,qBAAa,EAAC,WAAW,CAAC,EAAE;YAC9B,mBAAmB,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;SAChD;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;YACzC,mBAAmB,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;SAChD;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex, CaipChainId } from '@metamask/utils';\nimport { hexToBigInt, KnownCaipNamespace } from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopesObject } from '../scope/types';\nimport { isWalletScope, parseScopeString } from '../scope/types';\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nconst getPermittedEthChainIdsFromScopes = (scopes: InternalScopesObject) => {\n const ethChainIds: Hex[] = [];\n\n Object.keys(scopes).forEach((scopeString) => {\n const { namespace, reference } = parseScopeString(scopeString);\n if (namespace === KnownCaipNamespace.Eip155 && reference) {\n ethChainIds.push(toHex(reference));\n }\n });\n\n return ethChainIds;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nexport const getPermittedEthChainIds = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n) => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethChainIds: Hex[] = [\n ...getPermittedEthChainIdsFromScopes(requiredScopes),\n ...getPermittedEthChainIdsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethChainIds);\n};\n\n/**\n * Adds an Ethereum (EIP155 namespaced) chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.\n * @param chainId - The Ethereum chainID to add.\n * @returns The updated CAIP-25 caveat value with the added Ethereum chainID.\n */\nexport const addPermittedEthChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: Hex,\n): Caip25CaveatValue => {\n const scopeString = `eip155:${hexToBigInt(chainId).toString(10)}`;\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(scopeString) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(scopeString)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [scopeString]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - EIP155 scopes for the given chainIDs\n * - Non EIP155 scopes (e.g. \"bip122:\" or any other non ethereum namespaces)\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The chainIDs to filter EIP155 scopes by.\n * @returns The filtered scopes object.\n */\nconst filterEthScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: Hex[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!reference) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n if (namespace === KnownCaipNamespace.Eip155) {\n const chainId = toHex(reference);\n if (chainIds.includes(chainId)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n } else {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.\n * @param chainIds - The Ethereum chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.\n */\nexport const setPermittedEthChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: Hex[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedEthChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\n};\n\n/**\n * Sets the permitted CAIP-2 chainIDs for the required and optional scopes.\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.\n * @param chainIds - The CAIP-2 chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted CAIP-2 chainIDs.\n */\nexport const setPermittedChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: CaipChainId[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterChainScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterChainScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\n};\n\n/**\n * Adds a chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.\n * @param chainId - The chainID to add.\n * @returns The updated CAIP-25 caveat value with the added chainID.\n */\nexport const addPermittedChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: CaipChainId,\n): Caip25CaveatValue => {\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(chainId) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(chainId)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [chainId]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - CAIP-2 ChainId scopes for the given chainIDs\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The CAIP-2 chainIDs to filter for.\n * @returns The filtered scopes object.\n */\nconst filterChainScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: CaipChainId[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n // If its a wallet scope or a wallet:* scope we don't filter it\n if (isWalletScope(scopeString)) {\n updatedScopesObject[scopeString] = scopeObject;\n } else if (chainIds.includes(scopeString)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n"]}
|
1
|
+
{"version":3,"file":"caip-permission-adapter-permittedChains.cjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-permittedChains.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AAEnD,2CAAkE;AAGlE,sDAAyD;AAEzD,8CAAiE;AAEjE;;;;;GAKG;AACH,MAAM,iCAAiC,GAAG,CAAC,MAA4B,EAAE,EAAE;IACzE,MAAM,WAAW,GAAU,EAAE,CAAC;IAE9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;QAC1C,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,SAAS,KAAK,0BAAkB,CAAC,MAAM,IAAI,SAAS,EAAE;YACxD,WAAW,CAAC,IAAI,CAAC,IAAA,wBAAK,EAAC,SAAS,CAAC,CAAC,CAAC;SACpC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,iBAGC,EACD,EAAE;IACF,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,iBAAiB,CAAC;IAE7D,MAAM,WAAW,GAAU;QACzB,GAAG,iCAAiC,CAAC,cAA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ArBW,QAAA,oBAAoB,wBAqB/B","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport type { Hex, CaipChainId } from '@metamask/utils';\nimport { hexToBigInt, KnownCaipNamespace } from '@metamask/utils';\n\nimport type { Caip25CaveatValue } from '../caip25Permission';\nimport { getUniqueArrayItems } from '../scope/transform';\nimport type { InternalScopesObject } from '../scope/types';\nimport { isWalletScope, parseScopeString } from '../scope/types';\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from internal scopes.\n *\n * @param scopes - The internal scopes from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nconst getPermittedEthChainIdsFromScopes = (scopes: InternalScopesObject) => {\n const ethChainIds: Hex[] = [];\n\n Object.keys(scopes).forEach((scopeString) => {\n const { namespace, reference } = parseScopeString(scopeString);\n if (namespace === KnownCaipNamespace.Eip155 && reference) {\n ethChainIds.push(toHex(reference));\n }\n });\n\n return ethChainIds;\n};\n\n/**\n * Gets the Ethereum (EIP155 namespaced) chainIDs from the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value from which to get the Ethereum chainIDs.\n * @returns An array of Ethereum chainIDs.\n */\nexport const getPermittedEthChainIds = (\n caip25CaveatValue: Pick<\n Caip25CaveatValue,\n 'requiredScopes' | 'optionalScopes'\n >,\n) => {\n const { requiredScopes, optionalScopes } = caip25CaveatValue;\n\n const ethChainIds: Hex[] = [\n ...getPermittedEthChainIdsFromScopes(requiredScopes),\n ...getPermittedEthChainIdsFromScopes(optionalScopes),\n ];\n\n return getUniqueArrayItems(ethChainIds);\n};\n\n/**\n * Adds an Ethereum (EIP155 namespaced) chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the Ethereum chainID to.\n * @param chainId - The Ethereum chainID to add.\n * @returns The updated CAIP-25 caveat value with the added Ethereum chainID.\n */\nexport const addPermittedEthChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: Hex,\n): Caip25CaveatValue => {\n const scopeString = `eip155:${hexToBigInt(chainId).toString(10)}`;\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(scopeString) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(scopeString)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [scopeString]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - EIP155 scopes for the given chainIDs\n * - Non EIP155 scopes (e.g. \"bip122:\" or any other non ethereum namespaces)\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The chainIDs to filter EIP155 scopes by.\n * @returns The filtered scopes object.\n */\nconst filterEthScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: Hex[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n const { namespace, reference } = parseScopeString(scopeString);\n if (!reference) {\n updatedScopesObject[scopeString] = scopeObject;\n return;\n }\n if (namespace === KnownCaipNamespace.Eip155) {\n const chainId = toHex(reference);\n if (chainIds.includes(chainId)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n } else {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Sets the permitted Ethereum (EIP155 namespaced) chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted Ethereum chainIDs for.\n * @param chainIds - The Ethereum chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.\n */\nexport const setPermittedEthChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: Hex[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterEthScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedEthChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\n};\n\n/**\n * Filters the scopes object to only include:\n * - Scopes without references (e.g. \"wallet:\")\n * - CAIP-2 ChainId scopes for the given chainIDs\n *\n * @param scopesObject - The scopes object to filter.\n * @param chainIds - The CAIP-2 chainIDs to filter for.\n * @returns The filtered scopes object.\n */\nconst filterChainScopesObjectByChainId = (\n scopesObject: InternalScopesObject,\n chainIds: CaipChainId[],\n): InternalScopesObject => {\n const updatedScopesObject: InternalScopesObject = {};\n\n Object.entries(scopesObject).forEach(([key, scopeObject]) => {\n // Cast needed because index type is returned as `string` by `Object.entries`\n const scopeString = key as keyof typeof scopesObject;\n // If its a wallet scope or a wallet:* scope we don't filter it\n if (isWalletScope(scopeString)) {\n updatedScopesObject[scopeString] = scopeObject;\n } else if (chainIds.includes(scopeString)) {\n updatedScopesObject[scopeString] = scopeObject;\n }\n });\n\n return updatedScopesObject;\n};\n\n/**\n * Adds a chainID to the optional scopes if it is not already present\n * in either the pre-existing required or optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.\n * @param chainId - The chainID to add.\n * @returns The updated CAIP-25 caveat value with the added chainID.\n */\nexport const addPermittedChainId = (\n caip25CaveatValue: Caip25CaveatValue,\n chainId: CaipChainId,\n): Caip25CaveatValue => {\n if (\n Object.keys(caip25CaveatValue.requiredScopes).includes(chainId) ||\n Object.keys(caip25CaveatValue.optionalScopes).includes(chainId)\n ) {\n return caip25CaveatValue;\n }\n\n return {\n ...caip25CaveatValue,\n optionalScopes: {\n ...caip25CaveatValue.optionalScopes,\n [chainId]: {\n accounts: [],\n },\n },\n };\n};\n\n/**\n * Sets the permitted CAIP-2 chainIDs for the required and optional scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.\n * @param chainIds - The CAIP-2 chainIDs to set as permitted.\n * @returns The updated CAIP-25 caveat value with the permitted CAIP-2 chainIDs.\n */\nexport const setPermittedChainIds = (\n caip25CaveatValue: Caip25CaveatValue,\n chainIds: CaipChainId[],\n): Caip25CaveatValue => {\n let updatedCaveatValue: Caip25CaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: filterChainScopesObjectByChainId(\n caip25CaveatValue.requiredScopes,\n chainIds,\n ),\n optionalScopes: filterChainScopesObjectByChainId(\n caip25CaveatValue.optionalScopes,\n chainIds,\n ),\n };\n\n chainIds.forEach((chainId) => {\n updatedCaveatValue = addPermittedChainId(updatedCaveatValue, chainId);\n });\n\n return updatedCaveatValue;\n};\n"]}
|
@@ -24,19 +24,21 @@ export declare const addPermittedEthChainId: (caip25CaveatValue: Caip25CaveatVal
|
|
24
24
|
* @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.
|
25
25
|
*/
|
26
26
|
export declare const setPermittedEthChainIds: (caip25CaveatValue: Caip25CaveatValue, chainIds: Hex[]) => Caip25CaveatValue;
|
27
|
-
/**
|
28
|
-
* Sets the permitted CAIP-2 chainIDs for the required and optional scopes.
|
29
|
-
* @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.
|
30
|
-
* @param chainIds - The CAIP-2 chainIDs to set as permitted.
|
31
|
-
* @returns The updated CAIP-25 caveat value with the permitted CAIP-2 chainIDs.
|
32
|
-
*/
|
33
|
-
export declare const setPermittedChainIds: (caip25CaveatValue: Caip25CaveatValue, chainIds: CaipChainId[]) => Caip25CaveatValue;
|
34
27
|
/**
|
35
28
|
* Adds a chainID to the optional scopes if it is not already present
|
36
29
|
* in either the pre-existing required or optional scopes.
|
30
|
+
*
|
37
31
|
* @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.
|
38
32
|
* @param chainId - The chainID to add.
|
39
33
|
* @returns The updated CAIP-25 caveat value with the added chainID.
|
40
34
|
*/
|
41
35
|
export declare const addPermittedChainId: (caip25CaveatValue: Caip25CaveatValue, chainId: CaipChainId) => Caip25CaveatValue;
|
36
|
+
/**
|
37
|
+
* Sets the permitted CAIP-2 chainIDs for the required and optional scopes.
|
38
|
+
*
|
39
|
+
* @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.
|
40
|
+
* @param chainIds - The CAIP-2 chainIDs to set as permitted.
|
41
|
+
* @returns The updated CAIP-25 caveat value with the permitted CAIP-2 chainIDs.
|
42
|
+
*/
|
43
|
+
export declare const setPermittedChainIds: (caip25CaveatValue: Caip25CaveatValue, chainIds: CaipChainId[]) => Caip25CaveatValue;
|
42
44
|
//# sourceMappingURL=caip-permission-adapter-permittedChains.d.cts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-permittedChains.d.cts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,wBAAwB;AAGxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAwB7D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;
|
1
|
+
{"version":3,"file":"caip-permission-adapter-permittedChains.d.cts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,wBAAwB;AAGxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAwB7D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;AA+BF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,sBACX,iBAAiB,WAC3B,WAAW,KACnB,iBAiBF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,sBACZ,iBAAiB,YAC1B,WAAW,EAAE,KACtB,iBAkBF,CAAC"}
|
@@ -24,19 +24,21 @@ export declare const addPermittedEthChainId: (caip25CaveatValue: Caip25CaveatVal
|
|
24
24
|
* @returns The updated CAIP-25 caveat value with the permitted Ethereum chainIDs.
|
25
25
|
*/
|
26
26
|
export declare const setPermittedEthChainIds: (caip25CaveatValue: Caip25CaveatValue, chainIds: Hex[]) => Caip25CaveatValue;
|
27
|
-
/**
|
28
|
-
* Sets the permitted CAIP-2 chainIDs for the required and optional scopes.
|
29
|
-
* @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.
|
30
|
-
* @param chainIds - The CAIP-2 chainIDs to set as permitted.
|
31
|
-
* @returns The updated CAIP-25 caveat value with the permitted CAIP-2 chainIDs.
|
32
|
-
*/
|
33
|
-
export declare const setPermittedChainIds: (caip25CaveatValue: Caip25CaveatValue, chainIds: CaipChainId[]) => Caip25CaveatValue;
|
34
27
|
/**
|
35
28
|
* Adds a chainID to the optional scopes if it is not already present
|
36
29
|
* in either the pre-existing required or optional scopes.
|
30
|
+
*
|
37
31
|
* @param caip25CaveatValue - The CAIP-25 caveat value to add the chainID to.
|
38
32
|
* @param chainId - The chainID to add.
|
39
33
|
* @returns The updated CAIP-25 caveat value with the added chainID.
|
40
34
|
*/
|
41
35
|
export declare const addPermittedChainId: (caip25CaveatValue: Caip25CaveatValue, chainId: CaipChainId) => Caip25CaveatValue;
|
36
|
+
/**
|
37
|
+
* Sets the permitted CAIP-2 chainIDs for the required and optional scopes.
|
38
|
+
*
|
39
|
+
* @param caip25CaveatValue - The CAIP-25 caveat value to set the permitted CAIP-2 chainIDs for.
|
40
|
+
* @param chainIds - The CAIP-2 chainIDs to set as permitted.
|
41
|
+
* @returns The updated CAIP-25 caveat value with the permitted CAIP-2 chainIDs.
|
42
|
+
*/
|
43
|
+
export declare const setPermittedChainIds: (caip25CaveatValue: Caip25CaveatValue, chainIds: CaipChainId[]) => Caip25CaveatValue;
|
42
44
|
//# sourceMappingURL=caip-permission-adapter-permittedChains.d.mts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-permittedChains.d.mts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,wBAAwB;AAGxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAwB7D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;
|
1
|
+
{"version":3,"file":"caip-permission-adapter-permittedChains.d.mts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-permittedChains.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,wBAAwB;AAGxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAwB7D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,sBACf,KACjB,iBAAiB,EACjB,gBAAgB,GAAG,gBAAgB,CACpC,oBAUF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,sBACd,iBAAiB,WAC3B,GAAG,KACX,iBAkBF,CAAC;AAuCF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,sBACf,iBAAiB,YAC1B,GAAG,EAAE,KACd,iBAkBF,CAAC;AA+BF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,sBACX,iBAAiB,WAC3B,WAAW,KACnB,iBAiBF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,sBACZ,iBAAiB,YAC1B,WAAW,EAAE,KACtB,iBAkBF,CAAC"}
|