@xnetjs/trust 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chris Smothers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # @xnetjs/trust
2
+
3
+ The shared provenance→trust-tier primitives for xNet's extensibility systems
4
+ (exploration 0194).
5
+
6
+ Trust follows **provenance** — where an extension came from — never anything the
7
+ code declares about itself. A `synced` extension always re-derives its tier
8
+ locally (sync is not consent).
9
+
10
+ ```ts
11
+ import { deriveTrustTier, requiresCapabilityReprompt, sandboxForTier } from '@xnetjs/trust'
12
+
13
+ deriveTrustTier('marketplace') // 'marketplace' → sandboxForTier → 'iframe'
14
+ deriveTrustTier('authored') // 'user' → 'ses-worker'
15
+ deriveTrustTier('builtin') // 'first-party' → 'host'
16
+ requiresCapabilityReprompt('synced') // true
17
+ ```
18
+
19
+ This package is the single source of truth consumed by `@xnetjs/plugins`
20
+ (ecosystem layer, 0192) and `@xnetjs/labs` (0180), which previously carried
21
+ byte-for-byte identical copies of this logic. It is intentionally zero-dependency
22
+ and policy-only (no runtime) so it never becomes a coupling magnet.
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @xnetjs/trust — the shared provenance→trust primitives for xNet extensibility
3
+ * (exploration 0194).
4
+ *
5
+ * The load-bearing invariant of the whole extensibility story: an extension's
6
+ * trust tier follows its PROVENANCE — where it came from — never anything the
7
+ * code declares about itself. Something you (or an AI you approved) authored
8
+ * locally installs at the `user` tier; something pulled from a marketplace
9
+ * installs at the `marketplace` tier (and runs in the iframe).
10
+ *
11
+ * Critically, when an extension node SYNCS to another device, the receiver must
12
+ * RE-DERIVE the tier from its own local install action — never trust a tier
13
+ * carried in the synced payload. {@link deriveTrustTier} is that single choke
14
+ * point.
15
+ *
16
+ * This package exists because `@xnetjs/labs` (0180) and `@xnetjs/plugins`'s
17
+ * ecosystem layer (0192) had *byte-for-byte identical* copies of this logic —
18
+ * 0192 mirrored it to avoid a `plugins → labs` dependency edge (labs already
19
+ * depends on plugins). A tiny zero-dep leaf both can depend on is the clean fix.
20
+ * Keep it policy-only (no runtime) so it never becomes a coupling magnet.
21
+ */
22
+ /** Where an extension came from — the only input to its trust tier. */
23
+ type InstallProvenance =
24
+ /** Bundled with the app. */
25
+ 'builtin'
26
+ /** Authored in this workspace by the user. */
27
+ | 'authored'
28
+ /** Generated by an AI agent and explicitly approved by the user. */
29
+ | 'ai-generated'
30
+ /** Imported from a file/manifest the user pasted or opened. */
31
+ | 'imported'
32
+ /** Installed from a public marketplace. */
33
+ | 'marketplace'
34
+ /** Arrived via P2P sync from another device/peer. */
35
+ | 'synced';
36
+ /** The execution trust tier an extension runs at. */
37
+ type TrustTier = 'first-party' | 'user' | 'marketplace';
38
+ /** The sandbox a tier maps to (mirrors the dashboard widget tiers). */
39
+ type SandboxKind = 'host' | 'ses-worker' | 'iframe';
40
+ /**
41
+ * Map install provenance to a trust tier. `synced` does NOT inherit any tier —
42
+ * it lands at `user` and the host must re-confirm capabilities locally before
43
+ * activating (sync is not consent). `authored`/`ai-generated`/`imported` also
44
+ * land at `user`; only `builtin` is first-party and only `marketplace` is
45
+ * marketplace.
46
+ */
47
+ declare function deriveTrustTier(provenance: InstallProvenance): TrustTier;
48
+ /**
49
+ * Whether installing from `provenance` must re-prompt the user for the
50
+ * extension's capabilities before activation. True for anything not authored on
51
+ * this device in this session — especially synced and marketplace nodes.
52
+ */
53
+ declare function requiresCapabilityReprompt(provenance: InstallProvenance): boolean;
54
+ /** Map a trust tier to the sandbox its code should run in. */
55
+ declare function sandboxForTier(tier: TrustTier): SandboxKind;
56
+
57
+ export { type InstallProvenance, type SandboxKind, type TrustTier, deriveTrustTier, requiresCapabilityReprompt, sandboxForTier };
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ // src/index.ts
2
+ function deriveTrustTier(provenance) {
3
+ if (provenance === "builtin") return "first-party";
4
+ if (provenance === "marketplace") return "marketplace";
5
+ return "user";
6
+ }
7
+ function requiresCapabilityReprompt(provenance) {
8
+ return provenance !== "builtin" && provenance !== "authored";
9
+ }
10
+ function sandboxForTier(tier) {
11
+ if (tier === "first-party") return "host";
12
+ if (tier === "marketplace") return "iframe";
13
+ return "ses-worker";
14
+ }
15
+ export {
16
+ deriveTrustTier,
17
+ requiresCapabilityReprompt,
18
+ sandboxForTier
19
+ };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@xnetjs/trust",
3
+ "version": "0.0.1",
4
+ "description": "Shared provenance→trust-tier primitives for xNet extensibility — the single source of truth consumed by @xnetjs/plugins and @xnetjs/labs.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "devDependencies": {
16
+ "@types/node": "^20.0.0",
17
+ "tsup": "^8.0.0",
18
+ "typescript": "^5.4.0",
19
+ "vitest": "^4.0.0"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/crs48/xNet"
32
+ },
33
+ "scripts": {
34
+ "build": "tsup src/index.ts --format esm --dts",
35
+ "test": "vitest run",
36
+ "test:watch": "vitest",
37
+ "typecheck": "tsc --noEmit",
38
+ "clean": "rm -rf dist"
39
+ }
40
+ }