@aithorized/core 0.1.0 → 0.1.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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 The aithorized authors
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The aithorized authors
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 CHANGED
@@ -1,30 +1,30 @@
1
- # @aithorized/core
2
-
3
- The deterministic core of [aithorized](https://aithorized.dev): what the SDK, the MCP proxy and the hooks use to decide whether a tool call may run. No network and no state. Node 20 or later.
4
-
5
- ```bash
6
- npm install @aithorized/core
7
- ```
8
-
9
- Most integrations want [`@aithorized/sdk`](https://www.npmjs.com/package/@aithorized/sdk) instead. Use this package to verify decisions yourself, or to port the protocol to another language.
10
-
11
- ## What is in it
12
-
13
- - **Canonical JSON and hashing**: RFC 8785 (JCS) and the SHA-256 payload hash every signature commits to.
14
- - **Signatures**: ECDSA P-256 for device decisions and Ed25519 for policy bundles, with domain-separated signing inputs.
15
- - **Policy**: loading, matching, evaluation, and a merge that can only make a policy stricter.
16
- - **Verification**: `verifyDecisionBundle` checks a signed decision against the payload that is about to run.
17
- - **Lifecycle helpers**: the local deadline and the redaction of previews.
18
-
19
- | Import | |
20
- |---|---|
21
- | `@aithorized/core` | Everything above |
22
- | `@aithorized/core/policy` | Policy evaluation only, safe for browsers |
23
- | `@aithorized/core/kill-switch` | Local pause helpers |
24
- | `@aithorized/core/vectors` | Loaders for the test vectors |
25
-
26
- ## Test vectors
27
-
28
- `test-vectors/` ships with the package: canonical JSON, payload hashes, signing inputs, policy evaluation and bundle verification, as JSON. An implementation in another language is correct when it reproduces them byte for byte.
29
-
30
- MIT.
1
+ # @aithorized/core
2
+
3
+ The deterministic core of [aithorized](https://aithorized.dev): what the SDK, the MCP proxy and the hooks use to decide whether a tool call may run. No network and no state. Node 20 or later.
4
+
5
+ ```bash
6
+ npm install @aithorized/core
7
+ ```
8
+
9
+ Most integrations want [`@aithorized/sdk`](https://www.npmjs.com/package/@aithorized/sdk) instead. Use this package to verify decisions yourself, or to port the protocol to another language.
10
+
11
+ ## What is in it
12
+
13
+ - **Canonical JSON and hashing**: RFC 8785 (JCS) and the SHA-256 payload hash every signature commits to.
14
+ - **Signatures**: ECDSA P-256 for device decisions and Ed25519 for policy bundles, with domain-separated signing inputs.
15
+ - **Policy**: loading, matching, evaluation, and a merge that can only make a policy stricter.
16
+ - **Verification**: `verifyDecisionBundle` checks a signed decision against the payload that is about to run.
17
+ - **Lifecycle helpers**: the local deadline and the redaction of previews.
18
+
19
+ | Import | |
20
+ |---|---|
21
+ | `@aithorized/core` | Everything above |
22
+ | `@aithorized/core/policy` | Policy evaluation only, safe for browsers |
23
+ | `@aithorized/core/kill-switch` | Local pause helpers |
24
+ | `@aithorized/core/vectors` | Loaders for the test vectors |
25
+
26
+ ## Test vectors
27
+
28
+ `test-vectors/` ships with the package: canonical JSON, payload hashes, signing inputs, policy evaluation and bundle verification, as JSON. An implementation in another language is correct when it reproduces them byte for byte.
29
+
30
+ MIT.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aithorized/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Deterministic crypto core and policy engine for aithorized (JCS RFC 8785, payload hashing, domain-separated ECDSA/Ed25519 signatures, fail-closed policy evaluation).",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,25 +1,25 @@
1
- # Shared test vectors (`aithorized/test-vector/v1`)
2
-
3
- Cross-language gate for **checklist C-03** (docs/05-threat-model.md): the
4
- TypeScript SDK, the NestJS backend and the mobile app MUST each run these
5
- files in their CI and assert **byte-identical** results.
6
-
7
- | File | Contract |
8
- |---|---|
9
- | `jcs.json` | RFC 8785 canonicalization: `input` (parsed JSON value) -> `expected` (canonical string). Includes the official RFC sort sample, the primitives sample and the Appendix B number table. |
10
- | `payload-hash.json` | `payloadHash(payload) == "sha256:" + base64url(SHA-256(UTF8(JCS(payload))))` (docs/03 section 1.5). `key-order-invariance` must hash identically to `stripe-refund`. |
11
- | `signing.json` | ECDSA P-256, base64url(DER), domain-separated signing inputs (`AITHORIZED-DECISION-V1`, `-ACTION-`, `-HTTP-`, `-WS-`, `-ENROLL-`, docs/03 sections 1.3-1.4). `negatives` pin the rejection behaviour: high-S (C-05), trailing DER bytes, cross-domain replay, tampered objects. |
12
- | `policy-eval.json` | Deterministic evaluation order (docs/02 section 3.4): kill switch -> breaker -> DENY -> auto-rules -> REQUIRE_APPROVAL -> OBSERVE -> default. |
13
- | `bundle-verify.json` | Ed25519 policy-bundle signature over `JCS(bundle without "signature")` (C-06), plus stale/invalid scenarios. |
14
-
15
- ## Regeneration
16
-
17
- Vectors are generated deterministically by:
18
-
19
- ```sh
20
- pnpm --filter @aithorized/core vectors
21
- ```
22
-
23
- The embedded keys are **TEST-ONLY fixture keys** (marked in each file).
24
- Never use them in production, and never replace them silently: downstream
25
- CI in other components depends on the committed values.
1
+ # Shared test vectors (`aithorized/test-vector/v1`)
2
+
3
+ Cross-language gate for **checklist C-03** (docs/05-threat-model.md): the
4
+ TypeScript SDK, the NestJS backend and the mobile app MUST each run these
5
+ files in their CI and assert **byte-identical** results.
6
+
7
+ | File | Contract |
8
+ |---|---|
9
+ | `jcs.json` | RFC 8785 canonicalization: `input` (parsed JSON value) -> `expected` (canonical string). Includes the official RFC sort sample, the primitives sample and the Appendix B number table. |
10
+ | `payload-hash.json` | `payloadHash(payload) == "sha256:" + base64url(SHA-256(UTF8(JCS(payload))))` (docs/03 section 1.5). `key-order-invariance` must hash identically to `stripe-refund`. |
11
+ | `signing.json` | ECDSA P-256, base64url(DER), domain-separated signing inputs (`AITHORIZED-DECISION-V1`, `-ACTION-`, `-HTTP-`, `-WS-`, `-ENROLL-`, docs/03 sections 1.3-1.4). `negatives` pin the rejection behaviour: high-S (C-05), trailing DER bytes, cross-domain replay, tampered objects. |
12
+ | `policy-eval.json` | Deterministic evaluation order (docs/02 section 3.4): kill switch -> breaker -> DENY -> auto-rules -> REQUIRE_APPROVAL -> OBSERVE -> default. |
13
+ | `bundle-verify.json` | Ed25519 policy-bundle signature over `JCS(bundle without "signature")` (C-06), plus stale/invalid scenarios. |
14
+
15
+ ## Regeneration
16
+
17
+ Vectors are generated deterministically by:
18
+
19
+ ```sh
20
+ pnpm --filter @aithorized/core vectors
21
+ ```
22
+
23
+ The embedded keys are **TEST-ONLY fixture keys** (marked in each file).
24
+ Never use them in production, and never replace them silently: downstream
25
+ CI in other components depends on the committed values.
@@ -1,173 +1,173 @@
1
- {
2
- "$schema": "aithorized/test-vector/v1",
3
- "name": "bundle-verify",
4
- "description": "Ed25519 policy bundle verification (checklist C-06). Signature over JCS(bundle without \"signature\").",
5
- "key": {
6
- "note": "TEST-ONLY fixture key. Never use in production or with real keys.",
7
- "keyId": "aithorized-policy-2026",
8
- "privateJwk": {
9
- "kty": "OKP",
10
- "crv": "Ed25519",
11
- "x": "PKuKyLAdhe711wpmrNFLQ3JqJ3aCZ-WwgJhjOStHeEc",
12
- "d": "t-jaWfW9DGW3tFgAKKUEBqp3Bw6sHKgpB2abXnoqUoY"
13
- },
14
- "publicJwk": {
15
- "kty": "OKP",
16
- "crv": "Ed25519",
17
- "x": "PKuKyLAdhe711wpmrNFLQ3JqJ3aCZ-WwgJhjOStHeEc"
18
- }
19
- },
20
- "nowMs": 1795780800000,
21
- "vectors": [
22
- {
23
- "name": "valid",
24
- "bundle": {
25
- "version": 14,
26
- "keyId": "aithorized-policy-2026",
27
- "defaults": {
28
- "unmatched": "OBSERVE",
29
- "ttlSeconds": 300
30
- },
31
- "rules": [
32
- {
33
- "id": "stripe-refund-large",
34
- "match": {
35
- "tool": "stripe.refund",
36
- "args": {
37
- "amount": {
38
- "gt": 10000
39
- }
40
- }
41
- },
42
- "effect": "REQUIRE_APPROVAL",
43
- "riskLevel": "HIGH"
44
- }
45
- ],
46
- "autoRules": [],
47
- "signature": "akO1o8shtnj0ZW6pSlDQXRp4zTqundN6FcLbFs1ly4iHTCfg5opHho2282bdyAAjGKZcGOaLN4NA_8JXmEi6Bg"
48
- },
49
- "lastRefreshMs": 1795780800000,
50
- "expected": "ok"
51
- },
52
- {
53
- "name": "stale-25h",
54
- "bundle": {
55
- "version": 14,
56
- "keyId": "aithorized-policy-2026",
57
- "defaults": {
58
- "unmatched": "OBSERVE",
59
- "ttlSeconds": 300
60
- },
61
- "rules": [
62
- {
63
- "id": "stripe-refund-large",
64
- "match": {
65
- "tool": "stripe.refund",
66
- "args": {
67
- "amount": {
68
- "gt": 10000
69
- }
70
- }
71
- },
72
- "effect": "REQUIRE_APPROVAL",
73
- "riskLevel": "HIGH"
74
- }
75
- ],
76
- "autoRules": [],
77
- "signature": "akO1o8shtnj0ZW6pSlDQXRp4zTqundN6FcLbFs1ly4iHTCfg5opHho2282bdyAAjGKZcGOaLN4NA_8JXmEi6Bg"
78
- },
79
- "lastRefreshMs": 1795690800000,
80
- "expected": "stale"
81
- },
82
- {
83
- "name": "fresh-boundary-23h",
84
- "bundle": {
85
- "version": 14,
86
- "keyId": "aithorized-policy-2026",
87
- "defaults": {
88
- "unmatched": "OBSERVE",
89
- "ttlSeconds": 300
90
- },
91
- "rules": [
92
- {
93
- "id": "stripe-refund-large",
94
- "match": {
95
- "tool": "stripe.refund",
96
- "args": {
97
- "amount": {
98
- "gt": 10000
99
- }
100
- }
101
- },
102
- "effect": "REQUIRE_APPROVAL",
103
- "riskLevel": "HIGH"
104
- }
105
- ],
106
- "autoRules": [],
107
- "signature": "akO1o8shtnj0ZW6pSlDQXRp4zTqundN6FcLbFs1ly4iHTCfg5opHho2282bdyAAjGKZcGOaLN4NA_8JXmEi6Bg"
108
- },
109
- "lastRefreshMs": 1795698000000,
110
- "expected": "ok"
111
- },
112
- {
113
- "name": "tampered-rule",
114
- "bundle": {
115
- "version": 14,
116
- "keyId": "aithorized-policy-2026",
117
- "defaults": {
118
- "unmatched": "OBSERVE",
119
- "ttlSeconds": 300
120
- },
121
- "rules": [
122
- {
123
- "id": "stripe-refund-large",
124
- "match": {
125
- "tool": "stripe.refund",
126
- "args": {
127
- "amount": {
128
- "gt": 10000
129
- }
130
- }
131
- },
132
- "effect": "REQUIRE_APPROVAL",
133
- "riskLevel": "LOW"
134
- }
135
- ],
136
- "autoRules": [],
137
- "signature": "akO1o8shtnj0ZW6pSlDQXRp4zTqundN6FcLbFs1ly4iHTCfg5opHho2282bdyAAjGKZcGOaLN4NA_8JXmEi6Bg"
138
- },
139
- "lastRefreshMs": 1795780800000,
140
- "expected": "invalid"
141
- },
142
- {
143
- "name": "wrong-key-id",
144
- "bundle": {
145
- "version": 14,
146
- "keyId": "other-policy-key",
147
- "defaults": {
148
- "unmatched": "OBSERVE",
149
- "ttlSeconds": 300
150
- },
151
- "rules": [
152
- {
153
- "id": "stripe-refund-large",
154
- "match": {
155
- "tool": "stripe.refund",
156
- "args": {
157
- "amount": {
158
- "gt": 10000
159
- }
160
- }
161
- },
162
- "effect": "REQUIRE_APPROVAL",
163
- "riskLevel": "HIGH"
164
- }
165
- ],
166
- "autoRules": [],
167
- "signature": "akO1o8shtnj0ZW6pSlDQXRp4zTqundN6FcLbFs1ly4iHTCfg5opHho2282bdyAAjGKZcGOaLN4NA_8JXmEi6Bg"
168
- },
169
- "lastRefreshMs": 1795780800000,
170
- "expected": "invalid"
171
- }
172
- ]
173
- }
1
+ {
2
+ "$schema": "aithorized/test-vector/v1",
3
+ "name": "bundle-verify",
4
+ "description": "Ed25519 policy bundle verification (checklist C-06). Signature over JCS(bundle without \"signature\").",
5
+ "key": {
6
+ "note": "TEST-ONLY fixture key. Never use in production or with real keys.",
7
+ "keyId": "aithorized-policy-2026",
8
+ "privateJwk": {
9
+ "kty": "OKP",
10
+ "crv": "Ed25519",
11
+ "x": "PKuKyLAdhe711wpmrNFLQ3JqJ3aCZ-WwgJhjOStHeEc",
12
+ "d": "t-jaWfW9DGW3tFgAKKUEBqp3Bw6sHKgpB2abXnoqUoY"
13
+ },
14
+ "publicJwk": {
15
+ "kty": "OKP",
16
+ "crv": "Ed25519",
17
+ "x": "PKuKyLAdhe711wpmrNFLQ3JqJ3aCZ-WwgJhjOStHeEc"
18
+ }
19
+ },
20
+ "nowMs": 1795780800000,
21
+ "vectors": [
22
+ {
23
+ "name": "valid",
24
+ "bundle": {
25
+ "version": 14,
26
+ "keyId": "aithorized-policy-2026",
27
+ "defaults": {
28
+ "unmatched": "OBSERVE",
29
+ "ttlSeconds": 300
30
+ },
31
+ "rules": [
32
+ {
33
+ "id": "stripe-refund-large",
34
+ "match": {
35
+ "tool": "stripe.refund",
36
+ "args": {
37
+ "amount": {
38
+ "gt": 10000
39
+ }
40
+ }
41
+ },
42
+ "effect": "REQUIRE_APPROVAL",
43
+ "riskLevel": "HIGH"
44
+ }
45
+ ],
46
+ "autoRules": [],
47
+ "signature": "akO1o8shtnj0ZW6pSlDQXRp4zTqundN6FcLbFs1ly4iHTCfg5opHho2282bdyAAjGKZcGOaLN4NA_8JXmEi6Bg"
48
+ },
49
+ "lastRefreshMs": 1795780800000,
50
+ "expected": "ok"
51
+ },
52
+ {
53
+ "name": "stale-25h",
54
+ "bundle": {
55
+ "version": 14,
56
+ "keyId": "aithorized-policy-2026",
57
+ "defaults": {
58
+ "unmatched": "OBSERVE",
59
+ "ttlSeconds": 300
60
+ },
61
+ "rules": [
62
+ {
63
+ "id": "stripe-refund-large",
64
+ "match": {
65
+ "tool": "stripe.refund",
66
+ "args": {
67
+ "amount": {
68
+ "gt": 10000
69
+ }
70
+ }
71
+ },
72
+ "effect": "REQUIRE_APPROVAL",
73
+ "riskLevel": "HIGH"
74
+ }
75
+ ],
76
+ "autoRules": [],
77
+ "signature": "akO1o8shtnj0ZW6pSlDQXRp4zTqundN6FcLbFs1ly4iHTCfg5opHho2282bdyAAjGKZcGOaLN4NA_8JXmEi6Bg"
78
+ },
79
+ "lastRefreshMs": 1795690800000,
80
+ "expected": "stale"
81
+ },
82
+ {
83
+ "name": "fresh-boundary-23h",
84
+ "bundle": {
85
+ "version": 14,
86
+ "keyId": "aithorized-policy-2026",
87
+ "defaults": {
88
+ "unmatched": "OBSERVE",
89
+ "ttlSeconds": 300
90
+ },
91
+ "rules": [
92
+ {
93
+ "id": "stripe-refund-large",
94
+ "match": {
95
+ "tool": "stripe.refund",
96
+ "args": {
97
+ "amount": {
98
+ "gt": 10000
99
+ }
100
+ }
101
+ },
102
+ "effect": "REQUIRE_APPROVAL",
103
+ "riskLevel": "HIGH"
104
+ }
105
+ ],
106
+ "autoRules": [],
107
+ "signature": "akO1o8shtnj0ZW6pSlDQXRp4zTqundN6FcLbFs1ly4iHTCfg5opHho2282bdyAAjGKZcGOaLN4NA_8JXmEi6Bg"
108
+ },
109
+ "lastRefreshMs": 1795698000000,
110
+ "expected": "ok"
111
+ },
112
+ {
113
+ "name": "tampered-rule",
114
+ "bundle": {
115
+ "version": 14,
116
+ "keyId": "aithorized-policy-2026",
117
+ "defaults": {
118
+ "unmatched": "OBSERVE",
119
+ "ttlSeconds": 300
120
+ },
121
+ "rules": [
122
+ {
123
+ "id": "stripe-refund-large",
124
+ "match": {
125
+ "tool": "stripe.refund",
126
+ "args": {
127
+ "amount": {
128
+ "gt": 10000
129
+ }
130
+ }
131
+ },
132
+ "effect": "REQUIRE_APPROVAL",
133
+ "riskLevel": "LOW"
134
+ }
135
+ ],
136
+ "autoRules": [],
137
+ "signature": "akO1o8shtnj0ZW6pSlDQXRp4zTqundN6FcLbFs1ly4iHTCfg5opHho2282bdyAAjGKZcGOaLN4NA_8JXmEi6Bg"
138
+ },
139
+ "lastRefreshMs": 1795780800000,
140
+ "expected": "invalid"
141
+ },
142
+ {
143
+ "name": "wrong-key-id",
144
+ "bundle": {
145
+ "version": 14,
146
+ "keyId": "other-policy-key",
147
+ "defaults": {
148
+ "unmatched": "OBSERVE",
149
+ "ttlSeconds": 300
150
+ },
151
+ "rules": [
152
+ {
153
+ "id": "stripe-refund-large",
154
+ "match": {
155
+ "tool": "stripe.refund",
156
+ "args": {
157
+ "amount": {
158
+ "gt": 10000
159
+ }
160
+ }
161
+ },
162
+ "effect": "REQUIRE_APPROVAL",
163
+ "riskLevel": "HIGH"
164
+ }
165
+ ],
166
+ "autoRules": [],
167
+ "signature": "akO1o8shtnj0ZW6pSlDQXRp4zTqundN6FcLbFs1ly4iHTCfg5opHho2282bdyAAjGKZcGOaLN4NA_8JXmEi6Bg"
168
+ },
169
+ "lastRefreshMs": 1795780800000,
170
+ "expected": "invalid"
171
+ }
172
+ ]
173
+ }