@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. 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.0",
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",
@@ -18,22 +18,26 @@ export function parseScope(scope) {
18
18
 
19
19
  /**
20
20
  * Check whether a granted scope matches a required scope.
21
- * Supports wildcard (`*`) matching at any level.
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 = parseScope(granted);
29
- const r = parseScope(required);
30
-
31
- const matches = (grantedPart, requiredPart) =>
32
- grantedPart === '*' || grantedPart === requiredPart;
33
-
34
- return matches(g.namespace, r.namespace) &&
35
- matches(g.resource, r.resource) &&
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
  /**