@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.
Files changed (33) hide show
  1. package/dist/adapters/caip-permission-adapter-accounts.cjs +32 -4
  2. package/dist/adapters/caip-permission-adapter-accounts.cjs.map +1 -1
  3. package/dist/adapters/caip-permission-adapter-accounts.d.cts +11 -0
  4. package/dist/adapters/caip-permission-adapter-accounts.d.cts.map +1 -1
  5. package/dist/adapters/caip-permission-adapter-accounts.d.mts +11 -0
  6. package/dist/adapters/caip-permission-adapter-accounts.d.mts.map +1 -1
  7. package/dist/adapters/caip-permission-adapter-accounts.mjs +31 -3
  8. package/dist/adapters/caip-permission-adapter-accounts.mjs.map +1 -1
  9. package/dist/adapters/caip-permission-adapter-permittedChains.cjs +37 -34
  10. package/dist/adapters/caip-permission-adapter-permittedChains.cjs.map +1 -1
  11. package/dist/adapters/caip-permission-adapter-permittedChains.d.cts +9 -7
  12. package/dist/adapters/caip-permission-adapter-permittedChains.d.cts.map +1 -1
  13. package/dist/adapters/caip-permission-adapter-permittedChains.d.mts +9 -7
  14. package/dist/adapters/caip-permission-adapter-permittedChains.d.mts.map +1 -1
  15. package/dist/adapters/caip-permission-adapter-permittedChains.mjs +35 -32
  16. package/dist/adapters/caip-permission-adapter-permittedChains.mjs.map +1 -1
  17. package/dist/caip25Permission.cjs +13 -8
  18. package/dist/caip25Permission.cjs.map +1 -1
  19. package/dist/caip25Permission.d.cts +7 -6
  20. package/dist/caip25Permission.d.cts.map +1 -1
  21. package/dist/caip25Permission.d.mts +7 -6
  22. package/dist/caip25Permission.d.mts.map +1 -1
  23. package/dist/caip25Permission.mjs +13 -8
  24. package/dist/caip25Permission.mjs.map +1 -1
  25. package/dist/scope/types.cjs +1 -0
  26. package/dist/scope/types.cjs.map +1 -1
  27. package/dist/scope/types.d.cts +1 -0
  28. package/dist/scope/types.d.cts.map +1 -1
  29. package/dist/scope/types.d.mts +1 -0
  30. package/dist/scope/types.d.mts.map +1 -1
  31. package/dist/scope/types.mjs +1 -0
  32. package/dist/scope/types.mjs.map +1 -1
  33. package/package.json +1 -1
@@ -81,6 +81,7 @@ export declare const parseScopeString: (scopeString: string) => {
81
81
  export type NonWalletKnownCaipNamespace = Exclude<KnownCaipNamespace, KnownCaipNamespace.Wallet>;
82
82
  /**
83
83
  * Checks if a scope string is either a 'wallet' scope or a 'wallet:*' scope.
84
+ *
84
85
  * @param scopeString - The scope string to check.
85
86
  * @returns True if the scope string is a wallet scope, false otherwise.
86
87
  */
@@ -1 +1 @@
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,GAAG,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,WAAW,EAAE,mBAAmB,CAAC,GAAG;IAC5E,CAAC,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AkB,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,gBACd,MAAM,KAClB;IACD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,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"}
@@ -81,6 +81,7 @@ export declare const parseScopeString: (scopeString: string) => {
81
81
  export type NonWalletKnownCaipNamespace = Exclude<KnownCaipNamespace, KnownCaipNamespace.Wallet>;
82
82
  /**
83
83
  * Checks if a scope string is either a 'wallet' scope or a 'wallet:*' scope.
84
+ *
84
85
  * @param scopeString - The scope string to check.
85
86
  * @returns True if the scope string is a wallet scope, false otherwise.
86
87
  */
@@ -1 +1 @@
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;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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;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,CACzC,WAAW,EACX,qBAAqB,CACtB,GAAG;IACF,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,EAAE,qBAAqB,CAAC;CACrD,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,GAAG;IACzE,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,gBACd,MAAM,KAClB;IACD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,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"}
@@ -18,6 +18,7 @@ export const parseScopeString = (scopeString) => {
18
18
  };
19
19
  /**
20
20
  * Checks if a scope string is either a 'wallet' scope or a 'wallet:*' scope.
21
+ *
21
22
  * @param scopeString - The scope string to check.
22
23
  * @returns True if the scope string is a wallet scope, false otherwise.
23
24
  */
@@ -1 +1 @@
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;;;;GAIG;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 * @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"]}
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.2.0-preview-8c3b89c",
3
+ "version": "0.2.0-preview-62c1e797",
4
4
  "description": "Defines a CAIP-25 based endowment permission and helpers for interfacing with it",
5
5
  "keywords": [
6
6
  "MetaMask",