Skip to content

Commit cb33c7e

Browse files
authored
Merge pull request #330 from ChainAgnostic/caip25/clarify-scope-restructuring-best-practice--non-normative
Provide more guidance on restructuring scopes to disambiguate double-requests
2 parents 439bd19 + 723ad0d commit cb33c7e

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

CAIPs/caip-25.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ e.g., one or more specific failure states MAY be sent (see [#### failure states]
8282

8383
After parsing and authorizing separately all the networks and capabilities within each, a respondent establishes a connection by returning a success response that organizes all authorized features of each authorized scope in a single unified object of `scopeObject`s called `sessionScopes`.
8484
In the case of identically-keyed `scopeObject`s appearing in both top-level objects in the request (`requestedScopes` and `optionalScopes`), the identically-scoped objects MUST be merged in the response, since `sessionScopes` MUST NOT contain redundant keys (see examples below).
85-
However, respondents MUST NOT restructure scopes (e.g., by folding properties from a [CAIP-2][]-keyed, chain-specific scope object into a [CAIP-104][]-keyed, namespace-wide scope object) as this may introduce ambiguities (See Security Considerations below).
85+
86+
However, respondents SHOULD exercise caution when restructuring scopes.
87+
Folding properties from a [CAIP-2][]-keyed, chain-specific scope object into a [CAIP-104][]-keyed, namespace-wide scope object, for example, may introduce ambiguities or violate the law of Least Privilege;
88+
it is safer, in such cases, to restructure in the opposite direction, i.e. from compact [CAIP-104] scopes into more verbose single-chain [CAIP-2] requests. (See Security Considerations below).
8689

8790
### Request
8891

@@ -296,6 +299,9 @@ Regardless of caller trust level, the following error responses can reduce frict
296299
- When provider does not recognize one or more requested notification(s)
297300
- code = 5202
298301
- message = "Unknown notification(s) requested"
302+
- When a badly-formed request includes a network reference invalid in that scope
303+
- code = 5203
304+
- message = "Chain reference invalid for given scope"
299305
- When a badly-formed request defines one `chainId` two ways
300306
- code = 5204
301307
- message = "ChainId defined in two different scopes"
@@ -327,6 +333,55 @@ translate this object into other structures, preserving it in the CAIP-25
327333
interface is crucial to the unambiguous communication between caller and
328334
respondent about what exact authorization is granted.
329335
336+
### Ambiguity Between Different Types of Scopes
337+
338+
In the examples given above, there is no overlap between the two `eip155` chains authorized identically in compact form (1, 137) and the three additional chains identified in free-standing scopes (10, 42161, 0).
339+
340+
In cases where a given chain appears in both, it can be ambiguous what the intended behavior was.
341+
Depending on the security posture of the respondent, the ambiguity MAY be rejected using error code 5204, or the respondent MAY err on the side of [Postel's Law permissiveness][postel], returning a disambiguated response with all authorizations for a given chain moved into a single scope to confirm the intention.
342+
343+
For example, the request
344+
345+
```json
346+
//...
347+
"requiredScopes": {
348+
"eip155": {
349+
"references": ["1", "10", "137"],
350+
"methods": ["eth_sendTransaction", "eth_signTransaction", "get_balance", "eth_sign"],
351+
"notifications": ["accountsChanged", "chainChanged"],
352+
"accounts": ["eip155:10:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb", "eip155:137:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb"]
353+
},
354+
"eip155:10": {
355+
"methods": ["personal_sign"],
356+
"notifications": ["accountsChanged"],
357+
"accounts:" []
358+
},
359+
//...
360+
```
361+
362+
Can be returned as
363+
364+
```json
365+
//...
366+
"sessionScopes": {
367+
"eip155": {
368+
"references": ["1", "137"],
369+
"methods": ["eth_sendTransaction", "eth_signTransaction", "get_balance", "eth_sign"]
370+
"notifications": ["accountsChanged", "chainChanged"],
371+
"accounts": ["eip155:137:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb"]
372+
},
373+
"eip155:10": {
374+
"methods": ["eth_sendTransaction", "eth_signTransaction", "get_balance", "eth_sign", "personal_sign"]
375+
"notifications": ["accountsChanged", "chainChanged"],
376+
"accounts": ["eip155:10:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb"]
377+
},
378+
//...
379+
```
380+
381+
Note that the reference "10" has been moved out of the compact multi-reference scope, and that the union of all methods and notifications authorized to chainId reference `10` in both requested scopes has been granted to it in the latter.
382+
Also note that the `accounts` array of both scope objects has been updated, as the `eip155:10` account is no longer valid in the compact scope after the removal of `10` from the `references` array; likewise, the union of the compact scope's array and the empty array of the requested `eip155:10` scope, minus the invalid terms, leaves an array with only one member, an `eip155:10` account.
383+
384+
330385
## Privacy Considerations
331386
332387
One major risk in browser-based or HTTP-based communications is "fingerprinting
@@ -401,6 +456,7 @@ was in violation of policy).
401456
[CAIP-316]: https://chainagnostic.org/CAIPs/caip-316
402457
[namespaces]: https://namespaces.chainagnostic.org
403458
[RFC3339]: https://datatracker.ietf.org/doc/html/rfc3339#section-5.6
459+
[postel]: https://www.rfc-editor.org/rfc/rfc760#section-3.2
404460
405461
## Copyright
406462

0 commit comments

Comments
 (0)