@metamask-previews/chain-agnostic-permission 0.1.0-preview-b69c669

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 (116) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +20 -0
  3. package/README.md +15 -0
  4. package/dist/adapters/caip-permission-adapter-eth-accounts.cjs +103 -0
  5. package/dist/adapters/caip-permission-adapter-eth-accounts.cjs.map +1 -0
  6. package/dist/adapters/caip-permission-adapter-eth-accounts.d.cts +20 -0
  7. package/dist/adapters/caip-permission-adapter-eth-accounts.d.cts.map +1 -0
  8. package/dist/adapters/caip-permission-adapter-eth-accounts.d.mts +20 -0
  9. package/dist/adapters/caip-permission-adapter-eth-accounts.d.mts.map +1 -0
  10. package/dist/adapters/caip-permission-adapter-eth-accounts.mjs +98 -0
  11. package/dist/adapters/caip-permission-adapter-eth-accounts.mjs.map +1 -0
  12. package/dist/adapters/caip-permission-adapter-permittedChains.cjs +115 -0
  13. package/dist/adapters/caip-permission-adapter-permittedChains.cjs.map +1 -0
  14. package/dist/adapters/caip-permission-adapter-permittedChains.d.cts +27 -0
  15. package/dist/adapters/caip-permission-adapter-permittedChains.d.cts.map +1 -0
  16. package/dist/adapters/caip-permission-adapter-permittedChains.d.mts +27 -0
  17. package/dist/adapters/caip-permission-adapter-permittedChains.d.mts.map +1 -0
  18. package/dist/adapters/caip-permission-adapter-permittedChains.mjs +109 -0
  19. package/dist/adapters/caip-permission-adapter-permittedChains.mjs.map +1 -0
  20. package/dist/adapters/caip-permission-adapter-session-scopes.cjs +85 -0
  21. package/dist/adapters/caip-permission-adapter-session-scopes.cjs.map +1 -0
  22. package/dist/adapters/caip-permission-adapter-session-scopes.d.cts +23 -0
  23. package/dist/adapters/caip-permission-adapter-session-scopes.d.cts.map +1 -0
  24. package/dist/adapters/caip-permission-adapter-session-scopes.d.mts +23 -0
  25. package/dist/adapters/caip-permission-adapter-session-scopes.d.mts.map +1 -0
  26. package/dist/adapters/caip-permission-adapter-session-scopes.mjs +80 -0
  27. package/dist/adapters/caip-permission-adapter-session-scopes.mjs.map +1 -0
  28. package/dist/caip25Permission.cjs +285 -0
  29. package/dist/caip25Permission.cjs.map +1 -0
  30. package/dist/caip25Permission.d.cts +131 -0
  31. package/dist/caip25Permission.d.cts.map +1 -0
  32. package/dist/caip25Permission.d.mts +131 -0
  33. package/dist/caip25Permission.d.mts.map +1 -0
  34. package/dist/caip25Permission.mjs +280 -0
  35. package/dist/caip25Permission.mjs.map +1 -0
  36. package/dist/index.cjs +43 -0
  37. package/dist/index.cjs.map +1 -0
  38. package/dist/index.d.cts +14 -0
  39. package/dist/index.d.cts.map +1 -0
  40. package/dist/index.d.mts +14 -0
  41. package/dist/index.d.mts.map +1 -0
  42. package/dist/index.mjs +11 -0
  43. package/dist/index.mjs.map +1 -0
  44. package/dist/scope/assert.cjs +170 -0
  45. package/dist/scope/assert.cjs.map +1 -0
  46. package/dist/scope/assert.d.cts +50 -0
  47. package/dist/scope/assert.d.cts.map +1 -0
  48. package/dist/scope/assert.d.mts +50 -0
  49. package/dist/scope/assert.d.mts.map +1 -0
  50. package/dist/scope/assert.mjs +162 -0
  51. package/dist/scope/assert.mjs.map +1 -0
  52. package/dist/scope/authorization.cjs +51 -0
  53. package/dist/scope/authorization.cjs.map +1 -0
  54. package/dist/scope/authorization.d.cts +50 -0
  55. package/dist/scope/authorization.d.cts.map +1 -0
  56. package/dist/scope/authorization.d.mts +50 -0
  57. package/dist/scope/authorization.d.mts.map +1 -0
  58. package/dist/scope/authorization.mjs +46 -0
  59. package/dist/scope/authorization.mjs.map +1 -0
  60. package/dist/scope/constants.cjs +83 -0
  61. package/dist/scope/constants.cjs.map +1 -0
  62. package/dist/scope/constants.d.cts +32 -0
  63. package/dist/scope/constants.d.cts.map +1 -0
  64. package/dist/scope/constants.d.mts +32 -0
  65. package/dist/scope/constants.d.mts.map +1 -0
  66. package/dist/scope/constants.mjs +84 -0
  67. package/dist/scope/constants.mjs.map +1 -0
  68. package/dist/scope/errors.cjs +47 -0
  69. package/dist/scope/errors.cjs.map +1 -0
  70. package/dist/scope/errors.d.cts +44 -0
  71. package/dist/scope/errors.d.cts.map +1 -0
  72. package/dist/scope/errors.d.mts +44 -0
  73. package/dist/scope/errors.d.mts.map +1 -0
  74. package/dist/scope/errors.mjs +44 -0
  75. package/dist/scope/errors.mjs.map +1 -0
  76. package/dist/scope/filter.cjs +76 -0
  77. package/dist/scope/filter.cjs.map +1 -0
  78. package/dist/scope/filter.d.cts +35 -0
  79. package/dist/scope/filter.d.cts.map +1 -0
  80. package/dist/scope/filter.d.mts +35 -0
  81. package/dist/scope/filter.d.mts.map +1 -0
  82. package/dist/scope/filter.mjs +71 -0
  83. package/dist/scope/filter.mjs.map +1 -0
  84. package/dist/scope/supported.cjs +116 -0
  85. package/dist/scope/supported.cjs.map +1 -0
  86. package/dist/scope/supported.d.cts +52 -0
  87. package/dist/scope/supported.d.cts.map +1 -0
  88. package/dist/scope/supported.d.mts +52 -0
  89. package/dist/scope/supported.d.mts.map +1 -0
  90. package/dist/scope/supported.mjs +109 -0
  91. package/dist/scope/supported.mjs.map +1 -0
  92. package/dist/scope/transform.cjs +152 -0
  93. package/dist/scope/transform.cjs.map +1 -0
  94. package/dist/scope/transform.d.cts +50 -0
  95. package/dist/scope/transform.d.cts.map +1 -0
  96. package/dist/scope/transform.d.mts +50 -0
  97. package/dist/scope/transform.d.mts.map +1 -0
  98. package/dist/scope/transform.mjs +144 -0
  99. package/dist/scope/transform.mjs.map +1 -0
  100. package/dist/scope/types.cjs +23 -0
  101. package/dist/scope/types.cjs.map +1 -0
  102. package/dist/scope/types.d.cts +81 -0
  103. package/dist/scope/types.d.cts.map +1 -0
  104. package/dist/scope/types.d.mts +81 -0
  105. package/dist/scope/types.d.mts.map +1 -0
  106. package/dist/scope/types.mjs +19 -0
  107. package/dist/scope/types.mjs.map +1 -0
  108. package/dist/scope/validation.cjs +87 -0
  109. package/dist/scope/validation.cjs.map +1 -0
  110. package/dist/scope/validation.d.cts +21 -0
  111. package/dist/scope/validation.d.cts.map +1 -0
  112. package/dist/scope/validation.d.mts +21 -0
  113. package/dist/scope/validation.d.mts.map +1 -0
  114. package/dist/scope/validation.mjs +82 -0
  115. package/dist/scope/validation.mjs.map +1 -0
  116. package/package.json +75 -0
@@ -0,0 +1,285 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Caip25CaveatMutators = exports.caip25EndowmentBuilder = exports.caip25CaveatBuilder = exports.diffScopesForCaip25CaveatValue = exports.createCaip25Caveat = exports.Caip25EndowmentPermissionName = exports.Caip25CaveatType = void 0;
4
+ const permission_controller_1 = require("@metamask/permission-controller");
5
+ const utils_1 = require("@metamask/utils");
6
+ const lodash_1 = require("lodash");
7
+ const assert_1 = require("./scope/assert.cjs");
8
+ const supported_1 = require("./scope/supported.cjs");
9
+ const transform_1 = require("./scope/transform.cjs");
10
+ const types_1 = require("./scope/types.cjs");
11
+ /**
12
+ * The name of the CAIP-25 permission caveat.
13
+ */
14
+ exports.Caip25CaveatType = 'authorizedScopes';
15
+ /**
16
+ * The target name of the CAIP-25 endowment permission.
17
+ */
18
+ exports.Caip25EndowmentPermissionName = 'endowment:caip25';
19
+ /**
20
+ * Creates a CAIP-25 permission caveat.
21
+ *
22
+ * @param value - The CAIP-25 permission caveat value.
23
+ * @returns The CAIP-25 permission caveat (now including the type).
24
+ */
25
+ const createCaip25Caveat = (value) => {
26
+ return {
27
+ type: exports.Caip25CaveatType,
28
+ value,
29
+ };
30
+ };
31
+ exports.createCaip25Caveat = createCaip25Caveat;
32
+ /**
33
+ * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.
34
+ *
35
+ * @param originalValue - The existing CAIP-25 permission caveat value.
36
+ * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.
37
+ * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.
38
+ * @returns The difference between original and merged CAIP-25 permission caveat values.
39
+ */
40
+ function diffScopesForCaip25CaveatValue(originalValue, mergedValue, scopeToDiff) {
41
+ const diff = (0, lodash_1.cloneDeep)(originalValue);
42
+ const mergedScopeToDiff = mergedValue[scopeToDiff];
43
+ for (const [scopeString, mergedScopeObject] of Object.entries(mergedScopeToDiff)) {
44
+ const internalScopeString = scopeString;
45
+ const originalScopeObject = diff[scopeToDiff][internalScopeString];
46
+ if (originalScopeObject) {
47
+ const newAccounts = mergedScopeObject.accounts.filter((account) => !originalScopeObject?.accounts.includes(account));
48
+ if (newAccounts.length > 0) {
49
+ diff[scopeToDiff][internalScopeString] = {
50
+ accounts: newAccounts,
51
+ };
52
+ continue;
53
+ }
54
+ delete diff[scopeToDiff][internalScopeString];
55
+ }
56
+ else {
57
+ diff[scopeToDiff][internalScopeString] = mergedScopeObject;
58
+ }
59
+ }
60
+ return diff;
61
+ }
62
+ exports.diffScopesForCaip25CaveatValue = diffScopesForCaip25CaveatValue;
63
+ /**
64
+ * Checks if every account in the given scopes object is supported.
65
+ *
66
+ * @param scopesObject - The scopes object to iterate over.
67
+ * @param listAccounts - The hook for getting internalAccount objects for all evm accounts.
68
+ * @param getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.
69
+ * addresses.
70
+ * @returns True if every account in the scopes object is supported, false otherwise.
71
+ */
72
+ function isEveryAccountInScopesObjectSupported(scopesObject, listAccounts, getNonEvmAccountAddresses) {
73
+ return Object.values(scopesObject).every((scopeObject) => scopeObject.accounts.every((account) => (0, supported_1.isSupportedAccount)(account, {
74
+ getEvmInternalAccounts: listAccounts,
75
+ getNonEvmAccountAddresses,
76
+ })));
77
+ }
78
+ /**
79
+ * Helper that returns a `authorizedScopes` CAIP-25 caveat specification
80
+ * that can be passed into the PermissionController constructor.
81
+ *
82
+ * @param options - The specification builder options.
83
+ * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.
84
+ * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.
85
+ * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.
86
+ * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.
87
+ * @returns The specification for the `caip25` caveat.
88
+ */
89
+ const caip25CaveatBuilder = ({ findNetworkClientIdByChainId, listAccounts, isNonEvmScopeSupported, getNonEvmAccountAddresses, }) => {
90
+ return {
91
+ type: exports.Caip25CaveatType,
92
+ validator: (caveat, _origin, _target) => {
93
+ if (!caveat.value ||
94
+ !(0, utils_1.hasProperty)(caveat.value, 'requiredScopes') ||
95
+ !(0, utils_1.hasProperty)(caveat.value, 'optionalScopes') ||
96
+ !(0, utils_1.hasProperty)(caveat.value, 'isMultichainOrigin') ||
97
+ typeof caveat.value.isMultichainOrigin !== 'boolean') {
98
+ throw new Error(`${exports.Caip25EndowmentPermissionName} error: Received invalid value for caveat of type "${exports.Caip25CaveatType}".`);
99
+ }
100
+ const { requiredScopes, optionalScopes } = caveat.value;
101
+ (0, assert_1.assertIsInternalScopesObject)(requiredScopes);
102
+ (0, assert_1.assertIsInternalScopesObject)(optionalScopes);
103
+ const isEvmChainIdSupported = (chainId) => {
104
+ try {
105
+ findNetworkClientIdByChainId(chainId);
106
+ return true;
107
+ }
108
+ catch {
109
+ return false;
110
+ }
111
+ };
112
+ const allRequiredScopesSupported = Object.keys(requiredScopes).every((scopeString) => (0, supported_1.isSupportedScopeString)(scopeString, {
113
+ isEvmChainIdSupported,
114
+ isNonEvmScopeSupported,
115
+ }));
116
+ const allOptionalScopesSupported = Object.keys(optionalScopes).every((scopeString) => (0, supported_1.isSupportedScopeString)(scopeString, {
117
+ isEvmChainIdSupported,
118
+ isNonEvmScopeSupported,
119
+ }));
120
+ if (!allRequiredScopesSupported || !allOptionalScopesSupported) {
121
+ throw new Error(`${exports.Caip25EndowmentPermissionName} error: Received scopeString value(s) for caveat of type "${exports.Caip25CaveatType}" that are not supported by the wallet.`);
122
+ }
123
+ const allRequiredAccountsSupported = isEveryAccountInScopesObjectSupported(requiredScopes, listAccounts, getNonEvmAccountAddresses);
124
+ const allOptionalAccountsSupported = isEveryAccountInScopesObjectSupported(optionalScopes, listAccounts, getNonEvmAccountAddresses);
125
+ if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {
126
+ throw new Error(`${exports.Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type "${exports.Caip25CaveatType}" that are not supported by the wallet.`);
127
+ }
128
+ },
129
+ merger: (leftValue, rightValue) => {
130
+ const mergedRequiredScopes = (0, transform_1.mergeInternalScopes)(leftValue.requiredScopes, rightValue.requiredScopes);
131
+ const mergedOptionalScopes = (0, transform_1.mergeInternalScopes)(leftValue.optionalScopes, rightValue.optionalScopes);
132
+ const mergedValue = {
133
+ requiredScopes: mergedRequiredScopes,
134
+ optionalScopes: mergedOptionalScopes,
135
+ isMultichainOrigin: leftValue.isMultichainOrigin,
136
+ };
137
+ const partialDiff = diffScopesForCaip25CaveatValue(leftValue, mergedValue, 'requiredScopes');
138
+ const diff = diffScopesForCaip25CaveatValue(partialDiff, mergedValue, 'optionalScopes');
139
+ return [mergedValue, diff];
140
+ },
141
+ };
142
+ };
143
+ exports.caip25CaveatBuilder = caip25CaveatBuilder;
144
+ /**
145
+ * Helper that returns a `endowment:caip25` specification that
146
+ * can be passed into the PermissionController constructor.
147
+ *
148
+ * @returns The specification for the `caip25` endowment.
149
+ */
150
+ const specificationBuilder = () => {
151
+ return {
152
+ permissionType: permission_controller_1.PermissionType.Endowment,
153
+ targetName: exports.Caip25EndowmentPermissionName,
154
+ allowedCaveats: [exports.Caip25CaveatType],
155
+ endowmentGetter: (_getterOptions) => null,
156
+ validator: (permission) => {
157
+ if (permission.caveats?.length !== 1 ||
158
+ permission.caveats?.[0]?.type !== exports.Caip25CaveatType) {
159
+ throw new Error(`${exports.Caip25EndowmentPermissionName} error: Invalid caveats. There must be a single caveat of type "${exports.Caip25CaveatType}".`);
160
+ }
161
+ },
162
+ };
163
+ };
164
+ /**
165
+ * The `caip25` endowment specification builder. Passed to the
166
+ * `PermissionController` for constructing and validating the
167
+ * `endowment:caip25` permission.
168
+ */
169
+ exports.caip25EndowmentBuilder = Object.freeze({
170
+ targetName: exports.Caip25EndowmentPermissionName,
171
+ specificationBuilder,
172
+ });
173
+ /**
174
+ * Factories that construct caveat mutator functions that are passed to
175
+ * PermissionController.updatePermissionsByCaveat.
176
+ */
177
+ exports.Caip25CaveatMutators = {
178
+ [exports.Caip25CaveatType]: {
179
+ removeScope,
180
+ removeAccount,
181
+ },
182
+ };
183
+ /**
184
+ * Removes the account from the scope object.
185
+ *
186
+ * @param targetAddress - The address to remove from the scope object.
187
+ * @returns A function that removes the account from the scope object.
188
+ */
189
+ function removeAccountFilterFn(targetAddress) {
190
+ return (account) => {
191
+ const parsed = (0, utils_1.parseCaipAccountId)(account);
192
+ return parsed.address !== targetAddress;
193
+ };
194
+ }
195
+ /**
196
+ * Removes the account from the scope object.
197
+ *
198
+ * @param scopeObject - The scope object to remove the account from.
199
+ * @param targetAddress - The address to remove from the scope object.
200
+ */
201
+ function removeAccountFromScopeObject(scopeObject, targetAddress) {
202
+ if (scopeObject.accounts) {
203
+ scopeObject.accounts = scopeObject.accounts.filter(removeAccountFilterFn(targetAddress));
204
+ }
205
+ }
206
+ /**
207
+ * Removes the target account from the scope object.
208
+ *
209
+ * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).
210
+ * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.
211
+ * @returns The updated scope object.
212
+ */
213
+ function removeAccount(caip25CaveatValue, targetAddress) {
214
+ const updatedCaveatValue = (0, lodash_1.cloneDeep)(caip25CaveatValue);
215
+ [
216
+ updatedCaveatValue.requiredScopes,
217
+ updatedCaveatValue.optionalScopes,
218
+ ].forEach((scopes) => {
219
+ Object.entries(scopes).forEach(([, scopeObject]) => {
220
+ removeAccountFromScopeObject(scopeObject, targetAddress);
221
+ });
222
+ });
223
+ const noChange = (0, lodash_1.isEqual)(updatedCaveatValue, caip25CaveatValue);
224
+ if (noChange) {
225
+ return {
226
+ operation: permission_controller_1.CaveatMutatorOperation.Noop,
227
+ };
228
+ }
229
+ const hasAccounts = [
230
+ ...Object.values(updatedCaveatValue.requiredScopes),
231
+ ...Object.values(updatedCaveatValue.optionalScopes),
232
+ ].some(({ accounts }) => accounts.length > 0);
233
+ if (hasAccounts) {
234
+ return {
235
+ operation: permission_controller_1.CaveatMutatorOperation.UpdateValue,
236
+ value: updatedCaveatValue,
237
+ };
238
+ }
239
+ return {
240
+ operation: permission_controller_1.CaveatMutatorOperation.RevokePermission,
241
+ };
242
+ }
243
+ /**
244
+ * Removes the target scope from the value arrays of the given
245
+ * `endowment:caip25` caveat. No-ops if the target scopeString is not in
246
+ * the existing scopes.
247
+ *
248
+ * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.
249
+ * @param targetScopeString - The scope that is being removed.
250
+ * @returns The updated CAIP-25 permission caveat value.
251
+ */
252
+ function removeScope(caip25CaveatValue, targetScopeString) {
253
+ const newRequiredScopes = Object.entries(caip25CaveatValue.requiredScopes).filter(([scope]) => scope !== targetScopeString);
254
+ const newOptionalScopes = Object.entries(caip25CaveatValue.optionalScopes).filter(([scope]) => {
255
+ return scope !== targetScopeString;
256
+ });
257
+ const requiredScopesRemoved = newRequiredScopes.length !==
258
+ Object.keys(caip25CaveatValue.requiredScopes).length;
259
+ const optionalScopesRemoved = newOptionalScopes.length !==
260
+ Object.keys(caip25CaveatValue.optionalScopes).length;
261
+ if (!requiredScopesRemoved && !optionalScopesRemoved) {
262
+ return {
263
+ operation: permission_controller_1.CaveatMutatorOperation.Noop,
264
+ };
265
+ }
266
+ const updatedCaveatValue = {
267
+ ...caip25CaveatValue,
268
+ requiredScopes: Object.fromEntries(newRequiredScopes),
269
+ optionalScopes: Object.fromEntries(newOptionalScopes),
270
+ };
271
+ const hasNonWalletScopes = [...newRequiredScopes, ...newOptionalScopes].some(([scopeString]) => {
272
+ const { namespace } = (0, types_1.parseScopeString)(scopeString);
273
+ return namespace !== utils_1.KnownCaipNamespace.Wallet;
274
+ });
275
+ if (hasNonWalletScopes) {
276
+ return {
277
+ operation: permission_controller_1.CaveatMutatorOperation.UpdateValue,
278
+ value: updatedCaveatValue,
279
+ };
280
+ }
281
+ return {
282
+ operation: permission_controller_1.CaveatMutatorOperation.RevokePermission,
283
+ };
284
+ }
285
+ //# sourceMappingURL=caip25Permission.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip25Permission.cjs","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":";;;AASA,2EAGyC;AAEzC,2CAMyB;AACzB,mCAA4C;AAE5C,+CAA8D;AAC9D,qDAA+E;AAC/E,qDAAwD;AACxD,6CAKuB;AAcvB;;GAEG;AACU,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAEnD;;GAEG;AACU,QAAA,6BAA6B,GAAG,kBAAkB,CAAC;AAEhE;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC7D,OAAO;QACL,IAAI,EAAE,wBAAgB;QACtB,KAAK;KACN,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,kBAAkB,sBAK7B;AASF;;;;;;;GAOG;AACH,SAAgB,8BAA8B,CAC5C,aAAgC,EAChC,WAA8B,EAC9B,WAAgD;IAEhD,MAAM,IAAI,GAAG,IAAA,kBAAS,EAAC,aAAa,CAAC,CAAC;IAEtC,MAAM,iBAAiB,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC;IACnD,KAAK,MAAM,CAAC,WAAW,EAAE,iBAAiB,CAAC,IAAI,MAAM,CAAC,OAAO,CAC3D,iBAAiB,CAClB,EAAE;QACD,MAAM,mBAAmB,GAAG,WAA6C,CAAC;QAC1E,MAAM,mBAAmB,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC,mBAAmB,CAAC,CAAC;Q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GACzB,iBAAiB,CAAC,MAAM;QACxB,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC;IACvD,MAAM,qBAAqB,GACzB,iBAAiB,CAAC,MAAM;QACxB,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC;IAEvD,IAAI,CAAC,qBAAqB,IAAI,CAAC,qBAAqB,EAAE;QACpD,OAAO;YACL,SAAS,EAAE,8CAAsB,CAAC,IAAI;SACvC,CAAC;KACH;IAED,MAAM,kBAAkB,GAAG;QACzB,GAAG,iBAAiB;QACpB,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;QACrD,cAAc,EAAE,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC;KACtD,CAAC;IAEF,MAAM,kBAAkB,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,iBAAiB,CAAC,CAAC,IAAI,CAC1E,CAAC,CAAC,WAAW,CAAC,EAAE,EAAE;QAChB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;QACpD,OAAO,SAAS,KAAK,0BAAkB,CAAC,MAAM,CAAC;IACjD,CAAC,CACF,CAAC;IAEF,IAAI,kBAAkB,EAAE;QACtB,OAAO;YACL,SAAS,EAAE,8CAAsB,CAAC,WAAW;YAC7C,KAAK,EAAE,kBAAkB;SAC1B,CAAC;KACH;IAED,OAAO;QACL,SAAS,EAAE,8CAAsB,CAAC,gBAAgB;KACnD,CAAC;AACJ,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n PermissionSpecificationBuilder,\n EndowmentGetterParams,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionConstraint,\n EndowmentCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n CaveatMutatorOperation,\n PermissionType,\n} from '@metamask/permission-controller';\nimport type { CaipAccountId, CaipChainId, Json } from '@metamask/utils';\nimport {\n hasProperty,\n KnownCaipNamespace,\n parseCaipAccountId,\n type Hex,\n type NonEmptyArray,\n} from '@metamask/utils';\nimport { cloneDeep, isEqual } from 'lodash';\n\nimport { assertIsInternalScopesObject } from './scope/assert';\nimport { isSupportedAccount, isSupportedScopeString } from './scope/supported';\nimport { mergeInternalScopes } from './scope/transform';\nimport {\n parseScopeString,\n type ExternalScopeString,\n type InternalScopeObject,\n type InternalScopesObject,\n} from './scope/types';\n\n/**\n * The CAIP-25 permission caveat value.\n * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.\n * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.\n */\nexport type Caip25CaveatValue = {\n requiredScopes: InternalScopesObject;\n optionalScopes: InternalScopesObject;\n sessionProperties?: Record<string, Json>;\n isMultichainOrigin: boolean;\n};\n\n/**\n * The name of the CAIP-25 permission caveat.\n */\nexport const Caip25CaveatType = 'authorizedScopes';\n\n/**\n * The target name of the CAIP-25 endowment permission.\n */\nexport const Caip25EndowmentPermissionName = 'endowment:caip25';\n\n/**\n * Creates a CAIP-25 permission caveat.\n *\n * @param value - The CAIP-25 permission caveat value.\n * @returns The CAIP-25 permission caveat (now including the type).\n */\nexport const createCaip25Caveat = (value: Caip25CaveatValue) => {\n return {\n type: Caip25CaveatType,\n value,\n };\n};\n\ntype Caip25EndowmentCaveatSpecificationBuilderOptions = {\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;\n listAccounts: () => { type: string; address: Hex }[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[];\n};\n\n/**\n * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.\n *\n * @param originalValue - The existing CAIP-25 permission caveat value.\n * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.\n * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.\n * @returns The difference between original and merged CAIP-25 permission caveat values.\n */\nexport function diffScopesForCaip25CaveatValue(\n originalValue: Caip25CaveatValue,\n mergedValue: Caip25CaveatValue,\n scopeToDiff: 'optionalScopes' | 'requiredScopes',\n): Caip25CaveatValue {\n const diff = cloneDeep(originalValue);\n\n const mergedScopeToDiff = mergedValue[scopeToDiff];\n for (const [scopeString, mergedScopeObject] of Object.entries(\n mergedScopeToDiff,\n )) {\n const internalScopeString = scopeString as keyof typeof mergedScopeToDiff;\n const originalScopeObject = diff[scopeToDiff][internalScopeString];\n\n if (originalScopeObject) {\n const newAccounts = mergedScopeObject.accounts.filter(\n (account) => !originalScopeObject?.accounts.includes(account),\n );\n if (newAccounts.length > 0) {\n diff[scopeToDiff][internalScopeString] = {\n accounts: newAccounts,\n };\n continue;\n }\n delete diff[scopeToDiff][internalScopeString];\n } else {\n diff[scopeToDiff][internalScopeString] = mergedScopeObject;\n }\n }\n\n return diff;\n}\n\n/**\n * Checks if every account in the given scopes object is supported.\n *\n * @param scopesObject - The scopes object to iterate over.\n * @param listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * addresses.\n * @returns True if every account in the scopes object is supported, false otherwise.\n */\nfunction isEveryAccountInScopesObjectSupported(\n scopesObject: InternalScopesObject,\n listAccounts: () => { type: string; address: Hex }[],\n getNonEvmAccountAddresses: (scope: CaipChainId) => string[],\n) {\n return Object.values(scopesObject).every((scopeObject) =>\n scopeObject.accounts.every((account) =>\n isSupportedAccount(account, {\n getEvmInternalAccounts: listAccounts,\n getNonEvmAccountAddresses,\n }),\n ),\n );\n}\n\n/**\n * Helper that returns a `authorizedScopes` CAIP-25 caveat specification\n * that can be passed into the PermissionController constructor.\n *\n * @param options - The specification builder options.\n * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.\n * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.\n * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.\n * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.\n * @returns The specification for the `caip25` caveat.\n */\nexport const caip25CaveatBuilder = ({\n findNetworkClientIdByChainId,\n listAccounts,\n isNonEvmScopeSupported,\n getNonEvmAccountAddresses,\n}: Caip25EndowmentCaveatSpecificationBuilderOptions): EndowmentCaveatSpecificationConstraint &\n Required<\n Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>\n > => {\n return {\n type: Caip25CaveatType,\n validator: (\n caveat: { type: typeof Caip25CaveatType; value: unknown },\n _origin?: string,\n _target?: string,\n ) => {\n if (\n !caveat.value ||\n !hasProperty(caveat.value, 'requiredScopes') ||\n !hasProperty(caveat.value, 'optionalScopes') ||\n !hasProperty(caveat.value, 'isMultichainOrigin') ||\n typeof caveat.value.isMultichainOrigin !== 'boolean'\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received invalid value for caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n\n const { requiredScopes, optionalScopes } = caveat.value;\n\n assertIsInternalScopesObject(requiredScopes);\n assertIsInternalScopesObject(optionalScopes);\n\n const isEvmChainIdSupported = (chainId: Hex) => {\n try {\n findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n const allRequiredScopesSupported = Object.keys(requiredScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n const allOptionalScopesSupported = Object.keys(optionalScopes).every(\n (scopeString) =>\n isSupportedScopeString(scopeString, {\n isEvmChainIdSupported,\n isNonEvmScopeSupported,\n }),\n );\n if (!allRequiredScopesSupported || !allOptionalScopesSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received scopeString value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n\n const allRequiredAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n requiredScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n const allOptionalAccountsSupported =\n isEveryAccountInScopesObjectSupported(\n optionalScopes,\n listAccounts,\n getNonEvmAccountAddresses,\n );\n if (!allRequiredAccountsSupported || !allOptionalAccountsSupported) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Received account value(s) for caveat of type \"${Caip25CaveatType}\" that are not supported by the wallet.`,\n );\n }\n },\n merger: (\n leftValue: Caip25CaveatValue,\n rightValue: Caip25CaveatValue,\n ): [Caip25CaveatValue, Caip25CaveatValue] => {\n const mergedRequiredScopes = mergeInternalScopes(\n leftValue.requiredScopes,\n rightValue.requiredScopes,\n );\n const mergedOptionalScopes = mergeInternalScopes(\n leftValue.optionalScopes,\n rightValue.optionalScopes,\n );\n\n const mergedValue: Caip25CaveatValue = {\n requiredScopes: mergedRequiredScopes,\n optionalScopes: mergedOptionalScopes,\n isMultichainOrigin: leftValue.isMultichainOrigin,\n };\n\n const partialDiff = diffScopesForCaip25CaveatValue(\n leftValue,\n mergedValue,\n 'requiredScopes',\n );\n\n const diff = diffScopesForCaip25CaveatValue(\n partialDiff,\n mergedValue,\n 'optionalScopes',\n );\n\n return [mergedValue, diff];\n },\n };\n};\n\ntype Caip25EndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof Caip25EndowmentPermissionName;\n endowmentGetter: (_options?: EndowmentGetterParams) => null;\n validator: PermissionValidatorConstraint;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * Helper that returns a `endowment:caip25` specification that\n * can be passed into the PermissionController constructor.\n *\n * @returns The specification for the `caip25` endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n Record<never, never>,\n Caip25EndowmentSpecification\n> = () => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: Caip25EndowmentPermissionName,\n allowedCaveats: [Caip25CaveatType],\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => null,\n validator: (permission: PermissionConstraint) => {\n if (\n permission.caveats?.length !== 1 ||\n permission.caveats?.[0]?.type !== Caip25CaveatType\n ) {\n throw new Error(\n `${Caip25EndowmentPermissionName} error: Invalid caveats. There must be a single caveat of type \"${Caip25CaveatType}\".`,\n );\n }\n },\n };\n};\n\n/**\n * The `caip25` endowment specification builder. Passed to the\n * `PermissionController` for constructing and validating the\n * `endowment:caip25` permission.\n */\nexport const caip25EndowmentBuilder = Object.freeze({\n targetName: Caip25EndowmentPermissionName,\n specificationBuilder,\n} as const);\n\n/**\n * Factories that construct caveat mutator functions that are passed to\n * PermissionController.updatePermissionsByCaveat.\n */\nexport const Caip25CaveatMutators = {\n [Caip25CaveatType]: {\n removeScope,\n removeAccount,\n },\n};\n\n/**\n * Removes the account from the scope object.\n *\n * @param targetAddress - The address to remove from the scope object.\n * @returns A function that removes the account from the scope object.\n */\nfunction removeAccountFilterFn(targetAddress: string) {\n return (account: CaipAccountId) => {\n const parsed = parseCaipAccountId(account);\n return parsed.address !== targetAddress;\n };\n}\n\n/**\n * Removes the account from the scope object.\n *\n * @param scopeObject - The scope object to remove the account from.\n * @param targetAddress - The address to remove from the scope object.\n */\nfunction removeAccountFromScopeObject(\n scopeObject: InternalScopeObject,\n targetAddress: string,\n) {\n if (scopeObject.accounts) {\n scopeObject.accounts = scopeObject.accounts.filter(\n removeAccountFilterFn(targetAddress),\n );\n }\n}\n\n/**\n * Removes the target account from the scope object.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).\n * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.\n * @returns The updated scope object.\n */\nfunction removeAccount(\n caip25CaveatValue: Caip25CaveatValue,\n targetAddress: Hex,\n) {\n const updatedCaveatValue = cloneDeep(caip25CaveatValue);\n\n [\n updatedCaveatValue.requiredScopes,\n updatedCaveatValue.optionalScopes,\n ].forEach((scopes) => {\n Object.entries(scopes).forEach(([, scopeObject]) => {\n removeAccountFromScopeObject(scopeObject, targetAddress);\n });\n });\n\n const noChange = isEqual(updatedCaveatValue, caip25CaveatValue);\n\n if (noChange) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const hasAccounts = [\n ...Object.values(updatedCaveatValue.requiredScopes),\n ...Object.values(updatedCaveatValue.optionalScopes),\n ].some(({ accounts }) => accounts.length > 0);\n\n if (hasAccounts) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n\n/**\n * Removes the target scope from the value arrays of the given\n * `endowment:caip25` caveat. No-ops if the target scopeString is not in\n * the existing scopes.\n *\n * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.\n * @param targetScopeString - The scope that is being removed.\n * @returns The updated CAIP-25 permission caveat value.\n */\nfunction removeScope(\n caip25CaveatValue: Caip25CaveatValue,\n targetScopeString: ExternalScopeString,\n) {\n const newRequiredScopes = Object.entries(\n caip25CaveatValue.requiredScopes,\n ).filter(([scope]) => scope !== targetScopeString);\n const newOptionalScopes = Object.entries(\n caip25CaveatValue.optionalScopes,\n ).filter(([scope]) => {\n return scope !== targetScopeString;\n });\n\n const requiredScopesRemoved =\n newRequiredScopes.length !==\n Object.keys(caip25CaveatValue.requiredScopes).length;\n const optionalScopesRemoved =\n newOptionalScopes.length !==\n Object.keys(caip25CaveatValue.optionalScopes).length;\n\n if (!requiredScopesRemoved && !optionalScopesRemoved) {\n return {\n operation: CaveatMutatorOperation.Noop,\n };\n }\n\n const updatedCaveatValue = {\n ...caip25CaveatValue,\n requiredScopes: Object.fromEntries(newRequiredScopes),\n optionalScopes: Object.fromEntries(newOptionalScopes),\n };\n\n const hasNonWalletScopes = [...newRequiredScopes, ...newOptionalScopes].some(\n ([scopeString]) => {\n const { namespace } = parseScopeString(scopeString);\n return namespace !== KnownCaipNamespace.Wallet;\n },\n );\n\n if (hasNonWalletScopes) {\n return {\n operation: CaveatMutatorOperation.UpdateValue,\n value: updatedCaveatValue,\n };\n }\n\n return {\n operation: CaveatMutatorOperation.RevokePermission,\n };\n}\n"]}
@@ -0,0 +1,131 @@
1
+ import type { NetworkClientId } from "@metamask/network-controller";
2
+ import type { PermissionSpecificationBuilder, EndowmentGetterParams, PermissionValidatorConstraint, EndowmentCaveatSpecificationConstraint } from "@metamask/permission-controller";
3
+ import { CaveatMutatorOperation, PermissionType } from "@metamask/permission-controller";
4
+ import type { CaipChainId, Json } from "@metamask/utils";
5
+ import { type Hex, type NonEmptyArray } from "@metamask/utils";
6
+ import { type ExternalScopeString, type InternalScopeObject, type InternalScopesObject } from "./scope/types.cjs";
7
+ /**
8
+ * The CAIP-25 permission caveat value.
9
+ * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.
10
+ * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.
11
+ */
12
+ export type Caip25CaveatValue = {
13
+ requiredScopes: InternalScopesObject;
14
+ optionalScopes: InternalScopesObject;
15
+ sessionProperties?: Record<string, Json>;
16
+ isMultichainOrigin: boolean;
17
+ };
18
+ /**
19
+ * The name of the CAIP-25 permission caveat.
20
+ */
21
+ export declare const Caip25CaveatType = "authorizedScopes";
22
+ /**
23
+ * The target name of the CAIP-25 endowment permission.
24
+ */
25
+ export declare const Caip25EndowmentPermissionName = "endowment:caip25";
26
+ /**
27
+ * Creates a CAIP-25 permission caveat.
28
+ *
29
+ * @param value - The CAIP-25 permission caveat value.
30
+ * @returns The CAIP-25 permission caveat (now including the type).
31
+ */
32
+ export declare const createCaip25Caveat: (value: Caip25CaveatValue) => {
33
+ type: string;
34
+ value: Caip25CaveatValue;
35
+ };
36
+ type Caip25EndowmentCaveatSpecificationBuilderOptions = {
37
+ findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;
38
+ listAccounts: () => {
39
+ type: string;
40
+ address: Hex;
41
+ }[];
42
+ isNonEvmScopeSupported: (scope: CaipChainId) => boolean;
43
+ getNonEvmAccountAddresses: (scope: CaipChainId) => string[];
44
+ };
45
+ /**
46
+ * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.
47
+ *
48
+ * @param originalValue - The existing CAIP-25 permission caveat value.
49
+ * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.
50
+ * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.
51
+ * @returns The difference between original and merged CAIP-25 permission caveat values.
52
+ */
53
+ export declare function diffScopesForCaip25CaveatValue(originalValue: Caip25CaveatValue, mergedValue: Caip25CaveatValue, scopeToDiff: 'optionalScopes' | 'requiredScopes'): Caip25CaveatValue;
54
+ /**
55
+ * Helper that returns a `authorizedScopes` CAIP-25 caveat specification
56
+ * that can be passed into the PermissionController constructor.
57
+ *
58
+ * @param options - The specification builder options.
59
+ * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.
60
+ * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.
61
+ * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.
62
+ * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.
63
+ * @returns The specification for the `caip25` caveat.
64
+ */
65
+ export declare const caip25CaveatBuilder: ({ findNetworkClientIdByChainId, listAccounts, isNonEvmScopeSupported, getNonEvmAccountAddresses, }: Caip25EndowmentCaveatSpecificationBuilderOptions) => EndowmentCaveatSpecificationConstraint & Required<Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>>;
66
+ /**
67
+ * The `caip25` endowment specification builder. Passed to the
68
+ * `PermissionController` for constructing and validating the
69
+ * `endowment:caip25` permission.
70
+ */
71
+ export declare const caip25EndowmentBuilder: Readonly<{
72
+ readonly targetName: "endowment:caip25";
73
+ readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.Endowment, Record<never, never>, {
74
+ permissionType: PermissionType.Endowment;
75
+ targetName: typeof Caip25EndowmentPermissionName;
76
+ endowmentGetter: (_options?: EndowmentGetterParams) => null;
77
+ validator: PermissionValidatorConstraint;
78
+ allowedCaveats: Readonly<NonEmptyArray<string>> | null;
79
+ }>;
80
+ }>;
81
+ /**
82
+ * Factories that construct caveat mutator functions that are passed to
83
+ * PermissionController.updatePermissionsByCaveat.
84
+ */
85
+ export declare const Caip25CaveatMutators: {
86
+ authorizedScopes: {
87
+ removeScope: typeof removeScope;
88
+ removeAccount: typeof removeAccount;
89
+ };
90
+ };
91
+ /**
92
+ * Removes the target account from the scope object.
93
+ *
94
+ * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).
95
+ * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.
96
+ * @returns The updated scope object.
97
+ */
98
+ declare function removeAccount(caip25CaveatValue: Caip25CaveatValue, targetAddress: Hex): {
99
+ operation: CaveatMutatorOperation;
100
+ value?: undefined;
101
+ } | {
102
+ operation: CaveatMutatorOperation;
103
+ value: Caip25CaveatValue;
104
+ };
105
+ /**
106
+ * Removes the target scope from the value arrays of the given
107
+ * `endowment:caip25` caveat. No-ops if the target scopeString is not in
108
+ * the existing scopes.
109
+ *
110
+ * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.
111
+ * @param targetScopeString - The scope that is being removed.
112
+ * @returns The updated CAIP-25 permission caveat value.
113
+ */
114
+ declare function removeScope(caip25CaveatValue: Caip25CaveatValue, targetScopeString: ExternalScopeString): {
115
+ operation: CaveatMutatorOperation;
116
+ value?: undefined;
117
+ } | {
118
+ operation: CaveatMutatorOperation;
119
+ value: {
120
+ requiredScopes: {
121
+ [k: string]: InternalScopeObject;
122
+ };
123
+ optionalScopes: {
124
+ [k: string]: InternalScopeObject;
125
+ };
126
+ sessionProperties?: Record<string, Json> | undefined;
127
+ isMultichainOrigin: boolean;
128
+ };
129
+ };
130
+ export {};
131
+ //# sourceMappingURL=caip25Permission.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip25Permission.d.cts","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EACV,8BAA8B,EAC9B,qBAAqB,EAErB,6BAA6B,EAE7B,sCAAsC,EACvC,wCAAwC;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;AACzC,OAAO,KAAK,EAAiB,WAAW,EAAE,IAAI,EAAE,wBAAwB;AACxE,OAAO,EAIL,KAAK,GAAG,EACR,KAAK,aAAa,EACnB,wBAAwB;AAMzB,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EAC1B,0BAAsB;AAEvB;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,oBAAoB,CAAC;IACrC,cAAc,EAAE,oBAAoB,CAAC;IACrC,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACzC,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,6BAA6B,qBAAqB,CAAC;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,UAAW,iBAAiB;;;CAK1D,CAAC;AAEF,KAAK,gDAAgD,GAAG;IACtD,4BAA4B,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,eAAe,CAAC;IAChE,YAAY,EAAE,MAAM;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,EAAE,CAAC;IACrD,sBAAsB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IACxD,yBAAyB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,EAAE,CAAC;CAC7D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAC5C,aAAa,EAAE,iBAAiB,EAChC,WAAW,EAAE,iBAAiB,EAC9B,WAAW,EAAE,gBAAgB,GAAG,gBAAgB,GAC/C,iBAAiB,CA2BnB;AA0BD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,uGAK7B,gDAAgD,KAAG,sCAAsC,GAC1F,SACE,KAAK,sCAAsC,EAAE,WAAW,GAAG,QAAQ,CAAC,CA2GvE,CAAC;AAuCF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;;;wBAzCjB,eAAe,SAAS;oBAC5B,oCAAoC;qCACnB,qBAAqB,KAAK,IAAI;mBAChD,6BAA6B;wBACxB,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;;EAwC7C,CAAC;AAEZ;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKhC,CAAC;AAgCF;;;;;;GAMG;AACH,iBAAS,aAAa,CACpB,iBAAiB,EAAE,iBAAiB,EACpC,aAAa,EAAE,GAAG;;;;;;EAoCnB;AAED;;;;;;;;GAQG;AACH,iBAAS,WAAW,CAClB,iBAAiB,EAAE,iBAAiB,EACpC,iBAAiB,EAAE,mBAAmB;;;;;;;;;;;;;;;EA+CvC"}
@@ -0,0 +1,131 @@
1
+ import type { NetworkClientId } from "@metamask/network-controller";
2
+ import type { PermissionSpecificationBuilder, EndowmentGetterParams, PermissionValidatorConstraint, EndowmentCaveatSpecificationConstraint } from "@metamask/permission-controller";
3
+ import { CaveatMutatorOperation, PermissionType } from "@metamask/permission-controller";
4
+ import type { CaipChainId, Json } from "@metamask/utils";
5
+ import { type Hex, type NonEmptyArray } from "@metamask/utils";
6
+ import { type ExternalScopeString, type InternalScopeObject, type InternalScopesObject } from "./scope/types.mjs";
7
+ /**
8
+ * The CAIP-25 permission caveat value.
9
+ * This permission contains the required and optional scopes and session properties from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request that initiated the permission session.
10
+ * It also contains a boolean (isMultichainOrigin) indicating if the permission session is multichain, which may be needed to determine implicit permissioning.
11
+ */
12
+ export type Caip25CaveatValue = {
13
+ requiredScopes: InternalScopesObject;
14
+ optionalScopes: InternalScopesObject;
15
+ sessionProperties?: Record<string, Json>;
16
+ isMultichainOrigin: boolean;
17
+ };
18
+ /**
19
+ * The name of the CAIP-25 permission caveat.
20
+ */
21
+ export declare const Caip25CaveatType = "authorizedScopes";
22
+ /**
23
+ * The target name of the CAIP-25 endowment permission.
24
+ */
25
+ export declare const Caip25EndowmentPermissionName = "endowment:caip25";
26
+ /**
27
+ * Creates a CAIP-25 permission caveat.
28
+ *
29
+ * @param value - The CAIP-25 permission caveat value.
30
+ * @returns The CAIP-25 permission caveat (now including the type).
31
+ */
32
+ export declare const createCaip25Caveat: (value: Caip25CaveatValue) => {
33
+ type: string;
34
+ value: Caip25CaveatValue;
35
+ };
36
+ type Caip25EndowmentCaveatSpecificationBuilderOptions = {
37
+ findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId;
38
+ listAccounts: () => {
39
+ type: string;
40
+ address: Hex;
41
+ }[];
42
+ isNonEvmScopeSupported: (scope: CaipChainId) => boolean;
43
+ getNonEvmAccountAddresses: (scope: CaipChainId) => string[];
44
+ };
45
+ /**
46
+ * Calculates the difference between two provided CAIP-25 permission caveat values, but only considering a single scope property at a time.
47
+ *
48
+ * @param originalValue - The existing CAIP-25 permission caveat value.
49
+ * @param mergedValue - The result from merging existing and incoming CAIP-25 permission caveat values.
50
+ * @param scopeToDiff - The required or optional scopes from the [CAIP-25](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-25.md) request.
51
+ * @returns The difference between original and merged CAIP-25 permission caveat values.
52
+ */
53
+ export declare function diffScopesForCaip25CaveatValue(originalValue: Caip25CaveatValue, mergedValue: Caip25CaveatValue, scopeToDiff: 'optionalScopes' | 'requiredScopes'): Caip25CaveatValue;
54
+ /**
55
+ * Helper that returns a `authorizedScopes` CAIP-25 caveat specification
56
+ * that can be passed into the PermissionController constructor.
57
+ *
58
+ * @param options - The specification builder options.
59
+ * @param options.findNetworkClientIdByChainId - The hook for getting the networkClientId that serves a chainId.
60
+ * @param options.listAccounts - The hook for getting internalAccount objects for all evm accounts.
61
+ * @param options.isNonEvmScopeSupported - The hook that determines if an non EVM scopeString is supported.
62
+ * @param options.getNonEvmAccountAddresses - The hook that returns the supported CAIP-10 account addresses for a non EVM scope.
63
+ * @returns The specification for the `caip25` caveat.
64
+ */
65
+ export declare const caip25CaveatBuilder: ({ findNetworkClientIdByChainId, listAccounts, isNonEvmScopeSupported, getNonEvmAccountAddresses, }: Caip25EndowmentCaveatSpecificationBuilderOptions) => EndowmentCaveatSpecificationConstraint & Required<Pick<EndowmentCaveatSpecificationConstraint, 'validator' | 'merger'>>;
66
+ /**
67
+ * The `caip25` endowment specification builder. Passed to the
68
+ * `PermissionController` for constructing and validating the
69
+ * `endowment:caip25` permission.
70
+ */
71
+ export declare const caip25EndowmentBuilder: Readonly<{
72
+ readonly targetName: "endowment:caip25";
73
+ readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.Endowment, Record<never, never>, {
74
+ permissionType: PermissionType.Endowment;
75
+ targetName: typeof Caip25EndowmentPermissionName;
76
+ endowmentGetter: (_options?: EndowmentGetterParams) => null;
77
+ validator: PermissionValidatorConstraint;
78
+ allowedCaveats: Readonly<NonEmptyArray<string>> | null;
79
+ }>;
80
+ }>;
81
+ /**
82
+ * Factories that construct caveat mutator functions that are passed to
83
+ * PermissionController.updatePermissionsByCaveat.
84
+ */
85
+ export declare const Caip25CaveatMutators: {
86
+ authorizedScopes: {
87
+ removeScope: typeof removeScope;
88
+ removeAccount: typeof removeAccount;
89
+ };
90
+ };
91
+ /**
92
+ * Removes the target account from the scope object.
93
+ *
94
+ * @param caip25CaveatValue - The CAIP-25 permission caveat value from which to remove the account (across all chain scopes).
95
+ * @param targetAddress - The address to remove from the scope object. Not a CAIP-10 formatted address because it will be removed across each chain scope.
96
+ * @returns The updated scope object.
97
+ */
98
+ declare function removeAccount(caip25CaveatValue: Caip25CaveatValue, targetAddress: Hex): {
99
+ operation: CaveatMutatorOperation;
100
+ value?: undefined;
101
+ } | {
102
+ operation: CaveatMutatorOperation;
103
+ value: Caip25CaveatValue;
104
+ };
105
+ /**
106
+ * Removes the target scope from the value arrays of the given
107
+ * `endowment:caip25` caveat. No-ops if the target scopeString is not in
108
+ * the existing scopes.
109
+ *
110
+ * @param caip25CaveatValue - The CAIP-25 permission caveat value to remove the scope from.
111
+ * @param targetScopeString - The scope that is being removed.
112
+ * @returns The updated CAIP-25 permission caveat value.
113
+ */
114
+ declare function removeScope(caip25CaveatValue: Caip25CaveatValue, targetScopeString: ExternalScopeString): {
115
+ operation: CaveatMutatorOperation;
116
+ value?: undefined;
117
+ } | {
118
+ operation: CaveatMutatorOperation;
119
+ value: {
120
+ requiredScopes: {
121
+ [k: string]: InternalScopeObject;
122
+ };
123
+ optionalScopes: {
124
+ [k: string]: InternalScopeObject;
125
+ };
126
+ sessionProperties?: Record<string, Json> | undefined;
127
+ isMultichainOrigin: boolean;
128
+ };
129
+ };
130
+ export {};
131
+ //# sourceMappingURL=caip25Permission.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip25Permission.d.mts","sourceRoot":"","sources":["../src/caip25Permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EACV,8BAA8B,EAC9B,qBAAqB,EAErB,6BAA6B,EAE7B,sCAAsC,EACvC,wCAAwC;AACzC,OAAO,EACL,sBAAsB,EACtB,cAAc,EACf,wCAAwC;AACzC,OAAO,KAAK,EAAiB,WAAW,EAAE,IAAI,EAAE,wBAAw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