@metamask-previews/chain-agnostic-permission 0.2.0-preview-57dc1075 → 0.3.0-preview-9838d8a5
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 +17 -1
- package/dist/adapters/{caip-permission-adapter-eth-accounts.cjs → caip-permission-adapter-accounts.cjs} +50 -2
- package/dist/adapters/caip-permission-adapter-accounts.cjs.map +1 -0
- package/dist/adapters/{caip-permission-adapter-eth-accounts.d.cts → caip-permission-adapter-accounts.d.cts} +10 -2
- package/dist/adapters/caip-permission-adapter-accounts.d.cts.map +1 -0
- package/dist/adapters/{caip-permission-adapter-eth-accounts.d.mts → caip-permission-adapter-accounts.d.mts} +10 -2
- package/dist/adapters/caip-permission-adapter-accounts.d.mts.map +1 -0
- package/dist/adapters/{caip-permission-adapter-eth-accounts.mjs → caip-permission-adapter-accounts.mjs} +48 -1
- package/dist/adapters/caip-permission-adapter-accounts.mjs.map +1 -0
- package/dist/adapters/caip-permission-adapter-permittedChains.cjs +64 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.cjs.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.d.cts +18 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.d.cts.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.d.mts +18 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.d.mts.map +1 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.mjs +62 -1
- package/dist/adapters/caip-permission-adapter-permittedChains.mjs.map +1 -1
- package/dist/caip25Permission.cjs +30 -1
- package/dist/caip25Permission.cjs.map +1 -1
- package/dist/caip25Permission.d.cts +17 -1
- package/dist/caip25Permission.d.cts.map +1 -1
- package/dist/caip25Permission.d.mts +17 -1
- package/dist/caip25Permission.d.mts.map +1 -1
- package/dist/caip25Permission.mjs +28 -0
- package/dist/caip25Permission.mjs.map +1 -1
- package/dist/index.cjs +10 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -3
- package/dist/index.mjs.map +1 -1
- package/dist/scope/types.cjs +12 -1
- package/dist/scope/types.cjs.map +1 -1
- package/dist/scope/types.d.cts +9 -1
- package/dist/scope/types.d.cts.map +1 -1
- package/dist/scope/types.d.mts +9 -1
- package/dist/scope/types.d.mts.map +1 -1
- package/dist/scope/types.mjs +11 -1
- package/dist/scope/types.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/adapters/caip-permission-adapter-eth-accounts.cjs.map +0 -1
- package/dist/adapters/caip-permission-adapter-eth-accounts.d.cts.map +0 -1
- package/dist/adapters/caip-permission-adapter-eth-accounts.d.mts.map +0 -1
- package/dist/adapters/caip-permission-adapter-eth-accounts.mjs.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/scope/types.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/scope/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EACnB,wBAAwB;AACzB,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,aAAa,EACb,aAAa,EACb,IAAI,EACL,wBAAwB;AAEzB;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,aAAa,CAAC;AAC9D;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,qBAAqB,EAAE,UAAU,CAAC,GAAG;IAC1E,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAC7B,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC;CAC5B,CAAC;AACF;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CACvC,mBAAmB,EACnB,mBAAmB,CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GA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,gBACX,MAAM,kEAMpB,CAAC"}
|
package/dist/scope/types.d.mts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import { KnownCaipNamespace } from "@metamask/utils";
|
2
|
+
import type { CaipChainId, CaipReference, CaipAccountId, CaipNamespace, Json } from "@metamask/utils";
|
2
3
|
/**
|
3
4
|
* Represents a `scopeString` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).
|
4
5
|
*/
|
@@ -78,4 +79,11 @@ export declare const parseScopeString: (scopeString: string) => {
|
|
78
79
|
* CAIP namespaces excluding "wallet" currently supported by/known to the wallet.
|
79
80
|
*/
|
80
81
|
export type NonWalletKnownCaipNamespace = Exclude<KnownCaipNamespace, KnownCaipNamespace.Wallet>;
|
82
|
+
/**
|
83
|
+
* Checks if a scope string is either a 'wallet' scope or a 'wallet:*' scope.
|
84
|
+
*
|
85
|
+
* @param scopeString - The scope string to check.
|
86
|
+
* @returns True if the scope string is a wallet scope, false otherwise.
|
87
|
+
*/
|
88
|
+
export declare const isWalletScope: (scopeString: string) => scopeString is KnownCaipNamespace.Wallet | `wallet:${string}`;
|
81
89
|
//# sourceMappingURL=types.d.mts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/scope/types.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/scope/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,kBAAkB,EACnB,wBAAwB;AACzB,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,aAAa,EACb,aAAa,EACb,IAAI,EACL,wBAAwB;AAEzB;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,aAAa,CAAC;AAC9D;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,qBAAqB,EAAE,UAAU,CAAC,GAAG;IAC1E,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;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ACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CAYpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,OAAO,CAC/C,kBAAkB,EAClB,kBAAkB,CAAC,MAAM,CAC1B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,gBACX,MAAM,kEAMpB,CAAC"}
|
package/dist/scope/types.mjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { isCaipNamespace, isCaipChainId, parseCaipChainId } from "@metamask/utils";
|
1
|
+
import { isCaipNamespace, isCaipChainId, parseCaipChainId, KnownCaipNamespace } from "@metamask/utils";
|
2
2
|
/**
|
3
3
|
* Parses a scope string into a namespace and reference.
|
4
4
|
*
|
@@ -16,4 +16,14 @@ export const parseScopeString = (scopeString) => {
|
|
16
16
|
}
|
17
17
|
return {};
|
18
18
|
};
|
19
|
+
/**
|
20
|
+
* Checks if a scope string is either a 'wallet' scope or a 'wallet:*' scope.
|
21
|
+
*
|
22
|
+
* @param scopeString - The scope string to check.
|
23
|
+
* @returns True if the scope string is a wallet scope, false otherwise.
|
24
|
+
*/
|
25
|
+
export const isWalletScope = (scopeString) => {
|
26
|
+
const { namespace } = parseScopeString(scopeString);
|
27
|
+
return namespace === KnownCaipNamespace.Wallet;
|
28
|
+
};
|
19
29
|
//# sourceMappingURL=types.mjs.map
|
package/dist/scope/types.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/scope/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,EACb,gBAAgB,
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/scope/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EACnB,wBAAwB;AAsFzB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,WAAmB,EAInB,EAAE;IACF,IAAI,eAAe,CAAC,WAAW,CAAC,EAAE;QAChC,OAAO;YACL,SAAS,EAAE,WAAW;SACvB,CAAC;KACH;IACD,IAAI,aAAa,CAAC,WAAW,CAAC,EAAE;QAC9B,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;KACtC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAUF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,WAAmB,EAGwB,EAAE;IAC7C,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACpD,OAAO,SAAS,KAAK,kBAAkB,CAAC,MAAM,CAAC;AACjD,CAAC,CAAC","sourcesContent":["import {\n isCaipNamespace,\n isCaipChainId,\n parseCaipChainId,\n KnownCaipNamespace,\n} from '@metamask/utils';\nimport type {\n CaipChainId,\n CaipReference,\n CaipAccountId,\n CaipNamespace,\n Json,\n} from '@metamask/utils';\n\n/**\n * Represents a `scopeString` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).\n */\nexport type ExternalScopeString = CaipChainId | CaipNamespace;\n/**\n * Represents a `scopeObject` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).\n */\nexport type ExternalScopeObject = Omit<NormalizedScopeObject, 'accounts'> & {\n references?: CaipReference[];\n accounts?: CaipAccountId[];\n};\n/**\n * Represents a `scope` as defined in [CAIP-217](https://chainagnostic.org/CAIPs/caip-217).\n * TODO update the language in CAIP-217 to use \"scope\" instead of \"scopeObject\" for this full record type.\n */\nexport type ExternalScopesObject = Record<\n ExternalScopeString,\n ExternalScopeObject\n>;\n\n/**\n * Represents a `scopeString` as defined in\n * [CAIP-217](https://chainagnostic.org/CAIPs/caip-217), with the exception that\n * CAIP namespaces without a reference (aside from \"wallet\") are disallowed for our internal representations of CAIP-25 session scopes\n */\nexport type InternalScopeString = CaipChainId | KnownCaipNamespace.Wallet;\n\n/**\n * A trimmed down version of a [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) defined scopeObject that is stored in a `endowment:caip25` permission.\n * The only property from the original CAIP-25 scopeObject that we use for permissioning is `accounts`.\n */\nexport type InternalScopeObject = {\n accounts: CaipAccountId[];\n};\n\n/**\n * A trimmed down version of a [CAIP-217](https://chainagnostic.org/CAIPs/caip-217) scope that is stored in a `endowment:caip25` permission.\n * Accounts arrays are mapped to CAIP-2 chainIds. These are currently the only properties used by the permission system.\n */\nexport type InternalScopesObject = Record<CaipChainId, InternalScopeObject> & {\n [KnownCaipNamespace.Wallet]?: InternalScopeObject;\n};\n\n/**\n * Represents a `scopeObject` as defined in\n * [CAIP-217](https://chainagnostic.org/CAIPs/caip-217), with the exception that\n * we resolve the `references` property into a scopeObject per reference and\n * assign an empty array to the `accounts` property if not already defined\n * to more easily perform support checks for `wallet_createSession` requests.\n * Also used as the return type for `wallet_createSession` and `wallet_sessionChanged`.\n */\nexport type NormalizedScopeObject = {\n methods: string[];\n notifications: string[];\n accounts: CaipAccountId[];\n rpcDocuments?: string[];\n rpcEndpoints?: string[];\n};\n/**\n * Represents a keyed `scopeObject` as defined in\n * [CAIP-217](https://chainagnostic.org/CAIPs/caip-217), with the exception that\n * we resolve the `references` property into a scopeObject per reference and\n * assign an empty array to the `accounts` property if not already defined\n * to more easily perform support checks for `wallet_createSession` requests.\n * Also used as the return type for `wallet_createSession` and `wallet_sessionChanged`.\n */\nexport type NormalizedScopesObject = Record<\n CaipChainId,\n NormalizedScopeObject\n> & {\n [KnownCaipNamespace.Wallet]?: NormalizedScopeObject;\n};\n\nexport type ScopedProperties = Record<CaipChainId, Record<string, Json>> & {\n [KnownCaipNamespace.Wallet]?: Record<string, Json>;\n};\n\n/**\n * Parses a scope string into a namespace and reference.\n *\n * @param scopeString - The scope string to parse.\n * @returns An object containing the namespace and reference.\n */\nexport const parseScopeString = (\n scopeString: string,\n): {\n namespace?: string;\n reference?: string;\n} => {\n if (isCaipNamespace(scopeString)) {\n return {\n namespace: scopeString,\n };\n }\n if (isCaipChainId(scopeString)) {\n return parseCaipChainId(scopeString);\n }\n\n return {};\n};\n\n/**\n * CAIP namespaces excluding \"wallet\" currently supported by/known to the wallet.\n */\nexport type NonWalletKnownCaipNamespace = Exclude<\n KnownCaipNamespace,\n KnownCaipNamespace.Wallet\n>;\n\n/**\n * Checks if a scope string is either a 'wallet' scope or a 'wallet:*' scope.\n *\n * @param scopeString - The scope string to check.\n * @returns True if the scope string is a wallet scope, false otherwise.\n */\nexport const isWalletScope = (\n scopeString: string,\n): scopeString is\n | KnownCaipNamespace.Wallet\n | `${KnownCaipNamespace.Wallet}:${string}` => {\n const { namespace } = parseScopeString(scopeString);\n return namespace === KnownCaipNamespace.Wallet;\n};\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask-previews/chain-agnostic-permission",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.3.0-preview-9838d8a5",
|
4
4
|
"description": "Defines a CAIP-25 based endowment permission and helpers for interfacing with it",
|
5
5
|
"keywords": [
|
6
6
|
"MetaMask",
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-eth-accounts.cjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-eth-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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K,0BAAkB,CAAC,MAAM,CAAC;QACpE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,EAAE;YAC3D,mBAAmB,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;YAC/C,OAAO;SACR;QAED,IAAI,YAAY,GAAoB,EAAE,CAAC;QACvC,IAAI,SAAS,IAAI,SAAS,EAAE;YAC1B,YAAY,GAAG,QAAQ,CAAC,GAAG,CACzB,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,SAAS,IAAI,SAAS,IAAI,OAAO,EAAE,CACpD,CAAC;SACH;QAED,mBAAmB,CAAC,WAAW,CAAC,GAAG;YACjC,GAAG,WAAW;YACd,QAAQ,EAAE,YAAY;SACvB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACI,MAAM,cAAc,GAAG,CAC5B,iBAAoC,EACpC,QAAe,EACI,EAAE;IACrB,OAAO;QACL,GAAG,iBAAiB;QACpB,cAAc,EAAE,6BAA6B,CAC3C,iBAAiB,CAAC,cAAc,EAChC,QAAQ,CACT;QACD,cAAc,EAAE,6BAA6B,CAC3C,iBAAiB,CAAC,cAAc,EAChC,QAAQ,CACT;KACF,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,cAAc,kBAezB","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"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-eth-accounts.d.cts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-eth-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,GAAG,EAGT,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAgD7D;;;;;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"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-eth-accounts.d.mts","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-eth-accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,GAAG,EAGT,wBAAwB;AAEzB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAgD7D;;;;;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"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"caip-permission-adapter-eth-accounts.mjs","sourceRoot":"","sources":["../../src/adapters/caip-permission-adapter-eth-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,EAAE,2BAAuB;AAElD;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,CAAC,WAAgC,EAAE,EAAE;IAC/D,MAAM,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAEpD,OAAO,CACL,SAAS,KAAK,kBAAkB,CAAC,MAAM;QACvC,sDAAsD;QACtD,wEAAwE;QACxE,WAAW,KAAK,sBAAsB,CAAC,MAAM,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MA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,KAAK,kBAAkB,CAAC,MAAM,CAAC;QACpE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,EAAE;YAC3D,mBAAmB,CAAC,WAAW,CAAC,GAAG,WAAW,CAAC;YAC/C,OAAO;SACR;QAED,IAAI,YAAY,GAAoB,EAAE,CAAC;QACvC,IAAI,SAAS,IAAI,SAAS,EAAE;YAC1B,YAAY,GAAG,QAAQ,CAAC,GAAG,CACzB,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,SAAS,IAAI,SAAS,IAAI,OAAO,EAAE,CACpD,CAAC;SACH;QAED,mBAAmB,CAAC,WAAW,CAAC,GAAG;YACjC,GAAG,WAAW;YACd,QAAQ,EAAE,YAAY;SACvB,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,mBAAmB,CAAC;AAC7B,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,iBAAoC,EACpC,QAAe,EACI,EAAE;IACrB,OAAO;QACL,GAAG,iBAAiB;QACpB,cAAc,EAAE,6BAA6B,CAC3C,iBAAiB,CAAC,cAAc,EAChC,QAAQ,CACT;QACD,cAAc,EAAE,6BAA6B,CAC3C,iBAAiB,CAAC,cAAc,EAChC,QAAQ,CACT;KACF,CAAC;AACJ,CAAC,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';\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"]}
|