@johnhenry/browsermesh-primitives 0.4.0 → 0.4.1
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/package.json +1 -1
- package/src/capability.mjs +14 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnhenry/browsermesh-primitives",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Shared primitives for browser mesh networking — wire format, identity (Ed25519), CRDTs, capabilities, trust model, and ACL engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.mjs",
|
package/src/capability.mjs
CHANGED
|
@@ -18,22 +18,26 @@ export function parseScope(scope) {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Check whether a granted scope matches a required scope.
|
|
21
|
-
*
|
|
21
|
+
*
|
|
22
|
+
* Both are split on `:` and compared segment by segment, for any number of
|
|
23
|
+
* segments: a granted segment covers a required one if it is `*` or equal. A
|
|
24
|
+
* missing or empty segment counts as `*` (so a shorter grant covers what is
|
|
25
|
+
* beneath it, and at least three segments are always compared). A grant never
|
|
26
|
+
* covers a required scope that differs from it in a segment beyond the third.
|
|
22
27
|
*
|
|
23
28
|
* @param {string} granted - The scope that was granted
|
|
24
29
|
* @param {string} required - The scope being checked against
|
|
25
30
|
* @returns {boolean} True if granted covers required
|
|
26
31
|
*/
|
|
27
32
|
export function matchScope(granted, required) {
|
|
28
|
-
const g =
|
|
29
|
-
const r =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
grantedPart
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
matches(g.action, r.action);
|
|
33
|
+
const g = granted.split(':');
|
|
34
|
+
const r = required.split(':');
|
|
35
|
+
const length = Math.max(g.length, r.length, 3);
|
|
36
|
+
for (let i = 0; i < length; i++) {
|
|
37
|
+
const grantedPart = g[i] || '*';
|
|
38
|
+
if (grantedPart !== '*' && grantedPart !== (r[i] || '*')) return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
/**
|