@vorionsys/aurais-core 0.1.0

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,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,214 @@
1
+ # @vorionsys/aurais-core
2
+
3
+ Shared library for the Aurais ecosystem. Provides:
4
+
5
+ - **`ProofChain`** — Ed25519-signed, sha256-chained event log for bot actions
6
+ - **`deriveAgentIdentity`** — offline CAR-shaped identity derivation (deterministic ID, contextHash, tier ceiling)
7
+ - **`canonicalJSON` / `sha256`** — the canonical-JSON serializer + hash used by both, exported for callers that need to reproduce digests
8
+
9
+ License: Apache-2.0.
10
+
11
+ ---
12
+
13
+ ## Why this exists
14
+
15
+ The Aurais Next app and the five `aurais-mcp-*` packages each carried their
16
+ own copy of `proof-chain.ts` and `car-identity.ts`. The `proof-chain.ts`
17
+ copies were byte-identical across all five MCPs (sha256
18
+ `e17631fd…` × 5); the `car-identity.ts` copies differed only in the per-bot
19
+ `*_IDENTITY` constant pinned to the bottom. The MCP source headers said,
20
+ verbatim:
21
+
22
+ > Copied from apps/aurais/src/lib/proof-chain.ts for this standalone package.
23
+ > Future: extract to **@aurais/core** and have both packages import.
24
+
25
+ This is that extract.
26
+
27
+ We chose the npm name `@vorionsys/aurais-core` rather than `@aurais/core`
28
+ for scope continuity with the rest of the Vorion org packages
29
+ (`@vorionsys/basis-gate-spec`, `@vorionsys/car-client`, etc.) — registering
30
+ a fresh `@aurais` scope is admin friction we can defer. Renaming later if
31
+ the marketing surface ever requires it is a one-pass change.
32
+
33
+ ## Three-step consolidation — this is step 1
34
+
35
+ 1. **Step 1 (this repo):** extract the canonical lib into a standalone
36
+ package with tests + CI. Source: `voriongit/aurais` `src/lib/` at
37
+ `be55bf0fffc4254c4f77da03a99a272f5bb7cd5e`.
38
+ 2. **Step 2:** update `voriongit/aurais` and the five
39
+ `voriongit/vorion/packages/aurais-mcp-*` packages to consume from
40
+ `@vorionsys/aurais-core` instead of their local copies. Per-bot
41
+ `*_IDENTITY` constants stay in each MCP package — they're per-bot config,
42
+ not shared.
43
+ 3. **Step 3:** land the MCP packages in their final home (likely individual
44
+ polyrepos under `voriongit/`, decided in step-2 review).
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ npm install @vorionsys/aurais-core
50
+ ```
51
+
52
+ Requires Node 22+.
53
+
54
+ ## Usage
55
+
56
+ ### Proof chain
57
+
58
+ ```ts
59
+ import { ProofChain, hashText } from "@vorionsys/aurais-core";
60
+
61
+ const chain = new ProofChain();
62
+
63
+ const entry = "User wrote a journal entry…";
64
+ chain.append("session_started", {
65
+ bot: "aurais-journal-companion@0.1.0",
66
+ entry_hash: hashText(entry),
67
+ });
68
+
69
+ chain.append("commentary_generated", {
70
+ model: "claude-sonnet-4-5",
71
+ elapsed_ms: 423,
72
+ });
73
+
74
+ const events = chain.toJSON(); // ProofEvent[]
75
+ const tip = chain.tipHash(); // sha256 of the last canonical event
76
+ ```
77
+
78
+ Each event embeds the signer's pubkey (base64 SPKI) and the Ed25519
79
+ signature, so any consumer can verify chain integrity offline:
80
+
81
+ ```ts
82
+ import { createPublicKey, verify } from "node:crypto";
83
+ import { canonicalJSON } from "@vorionsys/aurais-core";
84
+
85
+ const evt = events[0];
86
+ // The signed object is everything in the event except `sig`.
87
+ // `pubkey` and `key_id` are part of what's signed — that binds the
88
+ // signer identity to the message.
89
+ const { sig, ...unsigned } = evt;
90
+ const ok = verify(
91
+ null,
92
+ Buffer.from(canonicalJSON(unsigned)),
93
+ createPublicKey({ key: Buffer.from(evt.pubkey, "base64"), format: "der", type: "spki" }),
94
+ Buffer.from(sig, "base64"),
95
+ );
96
+ ```
97
+
98
+ ### CAR identity
99
+
100
+ ```ts
101
+ import { deriveAgentIdentity } from "@vorionsys/aurais-core";
102
+
103
+ const id = deriveAgentIdentity({
104
+ slug: "aurais-journal-companion",
105
+ version: "0.1.0",
106
+ name: "Aurais Journal Companion",
107
+ tier: 3,
108
+ maxEarnableTier: 4,
109
+ capabilities: [
110
+ "tool:analyze_journal_entry",
111
+ "tool:generate_reflection",
112
+ "data:read:user:journal-entry-transient",
113
+ "api:post:api.anthropic.com",
114
+ "runtime:mcp-stdio",
115
+ ],
116
+ });
117
+
118
+ console.log(id.carId); // car-aurais-journal-companion-<12 hex>
119
+ console.log(id.contextHash); // sha256:<64 hex>
120
+ console.log(id.trustCeiling); // 600 (BLACK_BOX)
121
+ console.log(id.deploymentId); // resolved from env vars (see below)
122
+ ```
123
+
124
+ ### Signing key resolution
125
+
126
+ `ProofChain` looks for `AURAIS_SIGNING_KEY_PRIV` (base64 PKCS#8 DER of an
127
+ Ed25519 private key). If unset (or malformed), it generates an ephemeral
128
+ keypair scoped to the current process. The keypair is cached process-wide,
129
+ so warm serverless invocations reuse the same signer.
130
+
131
+ ### Deployment ID resolution
132
+
133
+ `deriveAgentIdentity` resolves `deploymentId` in this order:
134
+
135
+ 1. `AURAIS_DEPLOYMENT_ID` — explicit override (typical for MCP test/CI runs)
136
+ 2. `VERCEL_DEPLOYMENT_ID` — set by Vercel for the Next app
137
+ 3. `VERCEL_GIT_COMMIT_SHA` — first 12 chars
138
+ 4. `mcp-local-${process.platform}-${process.arch}` — local-dev fallback
139
+ 5. `"local-dev"` — last resort
140
+
141
+ This intentionally unions both consumers' resolution rules so neither
142
+ consumer changes behavior at step-2 fold-in.
143
+
144
+ ## API
145
+
146
+ ```ts
147
+ // Proof chain
148
+ class ProofChain {
149
+ constructor();
150
+ append(action: EventAction, payload: Record<string, unknown>): ProofEvent;
151
+ toJSON(): ProofEvent[];
152
+ tipHash(): string;
153
+ }
154
+ type EventAction =
155
+ | "session_started"
156
+ | "market_data_fetched"
157
+ | "indicators_computed"
158
+ | "commentary_generated"
159
+ | "briefing_assembled";
160
+ type ProofEvent = {
161
+ seq: number;
162
+ ts: string;
163
+ action: EventAction;
164
+ payload: Record<string, unknown>;
165
+ prev_hash: string;
166
+ pubkey: string;
167
+ key_id: string;
168
+ sig: string;
169
+ };
170
+ function hashText(s: string): string; // → "sha256:<64 hex>"
171
+ function hashJSON(v: unknown): string; // → "sha256:<64 hex>"
172
+
173
+ // CAR identity
174
+ function deriveAgentIdentity(input: DeriveInput): AgentIdentity;
175
+ const TIER_CEILING: Record<TrustTier, number>; // canonical.ts ceilings
176
+ const TIER_NAME: Record<TrustTier, string>;
177
+ type TrustTier = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
178
+
179
+ // Canonical JSON
180
+ function canonicalJSON(value: unknown): string; // sorted-keys, no whitespace
181
+ function sha256(text: string): string; // hex
182
+ ```
183
+
184
+ ## Known follow-ups (step 2 / step 3)
185
+
186
+ - **`EventAction` union is hardcoded** to the original five actions
187
+ (`session_started`, `market_data_fetched`, `indicators_computed`,
188
+ `commentary_generated`, `briefing_assembled`). The Meeting Distiller and
189
+ Journal Companion MCPs currently reuse `briefing_assembled` for what's
190
+ semantically a meeting summary or a reflection. Step 2 should decide
191
+ whether to widen the union, switch to a `string` typedef, or introduce a
192
+ per-bot extension point.
193
+ - **`AgentIdentity` shape matches the offline CAR spec** (the live
194
+ `@vorionsys/car-client` registers against the AgentAnchor backend); when
195
+ that backend lands the lib should grow a `registerAgent()` shim that
196
+ flips `registrationStatus` from `offline-attested` to `registered`.
197
+ - **No tests existed in `voriongit/aurais` for these files** before this
198
+ extraction — the test suite here is the first one. Step-2 fold-in should
199
+ add an integration test in each consumer that exercises a
200
+ round-trip-and-verify against this lib.
201
+
202
+ ## Provenance
203
+
204
+ | File | Source |
205
+ | --------------------- | -------------------------------------------------------------------------------------------- |
206
+ | `src/proof-chain.ts` | `voriongit/aurais` `src/lib/proof-chain.ts` @ `be55bf0fffc4254c4f77da03a99a272f5bb7cd5e` |
207
+ | `src/car-identity.ts` | `voriongit/aurais` `src/lib/car-identity.ts` @ `be55bf0fffc4254c4f77da03a99a272f5bb7cd5e` (+ widened `deploymentId` resolver) |
208
+ | `src/canonical-json.ts` | Extracted to dedupe within-package; same canonical-JSON algorithm used by both source files |
209
+ | `LICENSE` | `voriongit/basis-spec-docs` `LICENSE` (canonical Apache-2.0 text) |
210
+
211
+ ## Repo
212
+
213
+ [github.com/voriongit/aurais-core](https://github.com/voriongit/aurais-core)
214
+ — private during step-1 / step-2; visibility decision to be revisited at step 3.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Canonical JSON serializer + sha256 helper.
3
+ *
4
+ * Canonical JSON: keys sorted, no whitespace. Used as the input for both
5
+ * hashing and signing so independent verifiers can reproduce the digest
6
+ * byte-for-byte regardless of object key insertion order.
7
+ *
8
+ * This is intentionally tiny and dependency-free (node:crypto only).
9
+ * Both proof-chain and car-identity use it; extracted to avoid the
10
+ * within-package duplication that the source files carried before
11
+ * consolidation.
12
+ */
13
+ export declare function canonicalJSON(value: unknown): string;
14
+ export declare function sha256(text: string): string;
15
+ //# sourceMappingURL=canonical-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-json.d.ts","sourceRoot":"","sources":["../src/canonical-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASpD;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3C"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Canonical JSON serializer + sha256 helper.
3
+ *
4
+ * Canonical JSON: keys sorted, no whitespace. Used as the input for both
5
+ * hashing and signing so independent verifiers can reproduce the digest
6
+ * byte-for-byte regardless of object key insertion order.
7
+ *
8
+ * This is intentionally tiny and dependency-free (node:crypto only).
9
+ * Both proof-chain and car-identity use it; extracted to avoid the
10
+ * within-package duplication that the source files carried before
11
+ * consolidation.
12
+ */
13
+ import { createHash } from "node:crypto";
14
+ export function canonicalJSON(value) {
15
+ if (value === null || typeof value !== "object")
16
+ return JSON.stringify(value);
17
+ if (Array.isArray(value)) {
18
+ return "[" + value.map(canonicalJSON).join(",") + "]";
19
+ }
20
+ const obj = value;
21
+ const keys = Object.keys(obj).sort();
22
+ const parts = keys.map((k) => JSON.stringify(k) + ":" + canonicalJSON(obj[k]));
23
+ return "{" + parts.join(",") + "}";
24
+ }
25
+ export function sha256(text) {
26
+ return createHash("sha256").update(text).digest("hex");
27
+ }
28
+ //# sourceMappingURL=canonical-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-json.js","sourceRoot":"","sources":["../src/canonical-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9E,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACxD,CAAC;IACD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/E,OAAO,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Offline CAR identity derivation.
3
+ *
4
+ * The full @vorionsys/car-client library is a registry-backed SDK that expects
5
+ * a live backend (api.agentanchorai.com) for agent registration, role-gate
6
+ * evaluation, ceiling checks, and tier progression. Aurais consumers (the
7
+ * Next app + the five aurais-mcp-* packages) don't have that backend stood
8
+ * up yet, so they can't register bots live.
9
+ *
10
+ * What we CAN do offline:
11
+ * - Derive a deterministic CAR ID from (bot_slug, bot_version, manifest_hash)
12
+ * - Generate a fresh operationId per run
13
+ * - Compute a contextHash over the bot's declared capabilities + tier
14
+ * - Emit these fields in the proof chain, shape-matching the CAR spec
15
+ *
16
+ * When the backend lands, we add a registration step in the bot bootstrap
17
+ * flow that submits this same agent context and gets a signed registration
18
+ * record back. All the existing proof-chain events remain compatible.
19
+ *
20
+ * Source: extracted (with deploymentId resolver widened to cover both the
21
+ * Next app's Vercel env and the MCPs' stdio env) from voriongit/aurais
22
+ * src/lib/car-identity.ts @ be55bf0fffc4254c4f77da03a99a272f5bb7cd5e
23
+ * on 2026-04-25.
24
+ */
25
+ export type TrustTier = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
26
+ export declare const TIER_CEILING: Record<TrustTier, number>;
27
+ export declare const TIER_NAME: Record<TrustTier, string>;
28
+ export type AgentIdentity = {
29
+ /** CAR ID — deterministic, stable across runs of the same deployed version. */
30
+ carId: string;
31
+ /** Short human-readable: slug + short hash. */
32
+ agentId: string;
33
+ /** Per-run unique operation ID. */
34
+ operationId: string;
35
+ /** Org this agent is registered under. */
36
+ orgId: string;
37
+ /** Deployment identifier (Vercel env, AURAIS_DEPLOYMENT_ID, or local fallback). */
38
+ deploymentId: string;
39
+ /** sha256 of manifest-canonical fields. */
40
+ contextHash: string;
41
+ /** Parent registration hash. "" for root agents owned by Vorion LLC. */
42
+ parentHash: string;
43
+ /** Trust ceiling (score cap) this tier allows. */
44
+ trustCeiling: number;
45
+ /** Starting tier — per spec, all bots begin at T0 until onboarding. */
46
+ startingTier: TrustTier;
47
+ /** Max tier this bot is approved to reach. */
48
+ maxEarnableTier: TrustTier;
49
+ /** Tier this bot is currently operating at (for offline-attested bots, the required runtime tier). */
50
+ currentTier: TrustTier;
51
+ /** Capabilities declared in the manifest. */
52
+ capabilities: string[];
53
+ /** Status label for the UI — reflects that live registration is pending backend. */
54
+ registrationStatus: "offline-attested" | "registered" | "pending";
55
+ };
56
+ export type DeriveInput = {
57
+ slug: string;
58
+ version: string;
59
+ name: string;
60
+ tier: TrustTier;
61
+ maxEarnableTier?: TrustTier;
62
+ capabilities: string[];
63
+ orgId?: string;
64
+ };
65
+ /**
66
+ * Derive a deterministic CAR ID for a bot deployment.
67
+ * Safe to call on every request — same inputs → same ID.
68
+ */
69
+ export declare function deriveAgentIdentity(input: DeriveInput): AgentIdentity;
70
+ //# sourceMappingURL=car-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"car-identity.d.ts","sourceRoot":"","sources":["../src/car-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAGtD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CASlD,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAS/C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,mFAAmF;IACnF,YAAY,EAAE,MAAM,CAAC;IACrB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,YAAY,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,YAAY,EAAE,SAAS,CAAC;IACxB,8CAA8C;IAC9C,eAAe,EAAE,SAAS,CAAC;IAC3B,sGAAsG;IACtG,WAAW,EAAE,SAAS,CAAC;IACvB,6CAA6C;IAC7C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,oFAAoF;IACpF,kBAAkB,EAAE,kBAAkB,GAAG,YAAY,GAAG,SAAS,CAAC;CACnE,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAuBF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa,CA4CrE"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Offline CAR identity derivation.
3
+ *
4
+ * The full @vorionsys/car-client library is a registry-backed SDK that expects
5
+ * a live backend (api.agentanchorai.com) for agent registration, role-gate
6
+ * evaluation, ceiling checks, and tier progression. Aurais consumers (the
7
+ * Next app + the five aurais-mcp-* packages) don't have that backend stood
8
+ * up yet, so they can't register bots live.
9
+ *
10
+ * What we CAN do offline:
11
+ * - Derive a deterministic CAR ID from (bot_slug, bot_version, manifest_hash)
12
+ * - Generate a fresh operationId per run
13
+ * - Compute a contextHash over the bot's declared capabilities + tier
14
+ * - Emit these fields in the proof chain, shape-matching the CAR spec
15
+ *
16
+ * When the backend lands, we add a registration step in the bot bootstrap
17
+ * flow that submits this same agent context and gets a signed registration
18
+ * record back. All the existing proof-chain events remain compatible.
19
+ *
20
+ * Source: extracted (with deploymentId resolver widened to cover both the
21
+ * Next app's Vercel env and the MCPs' stdio env) from voriongit/aurais
22
+ * src/lib/car-identity.ts @ be55bf0fffc4254c4f77da03a99a272f5bb7cd5e
23
+ * on 2026-04-25.
24
+ */
25
+ import { canonicalJSON, sha256 } from "./canonical-json.js";
26
+ // Observation ceilings per canonical.ts (packages/basis/src/canonical.ts).
27
+ export const TIER_CEILING = {
28
+ 0: 200,
29
+ 1: 300,
30
+ 2: 450,
31
+ 3: 600, // BLACK_BOX
32
+ 4: 750, // GRAY_BOX
33
+ 5: 900, // WHITE_BOX
34
+ 6: 950, // ATTESTED_BOX
35
+ 7: 1000, // VERIFIED_BOX
36
+ };
37
+ export const TIER_NAME = {
38
+ 0: "PROVISIONING",
39
+ 1: "INITIATED",
40
+ 2: "OBSERVED",
41
+ 3: "BLACK_BOX",
42
+ 4: "GRAY_BOX",
43
+ 5: "WHITE_BOX",
44
+ 6: "ATTESTED_BOX",
45
+ 7: "VERIFIED_BOX",
46
+ };
47
+ /**
48
+ * Resolve the deployment ID across both Vercel-hosted (Next app) and
49
+ * stdio-hosted (MCP servers) environments. Priority:
50
+ * 1. AURAIS_DEPLOYMENT_ID — explicit override (used by MCPs in CI/tests)
51
+ * 2. VERCEL_DEPLOYMENT_ID — set by Vercel for the Next app
52
+ * 3. VERCEL_GIT_COMMIT_SHA — Vercel commit SHA, first 12 chars
53
+ * 4. mcp-local-${platform}-${arch} — MCP local-dev fallback
54
+ * 5. "local-dev" — last-resort
55
+ */
56
+ function resolveDeploymentId() {
57
+ if (process.env.AURAIS_DEPLOYMENT_ID)
58
+ return process.env.AURAIS_DEPLOYMENT_ID;
59
+ if (process.env.VERCEL_DEPLOYMENT_ID)
60
+ return process.env.VERCEL_DEPLOYMENT_ID;
61
+ const sha = process.env.VERCEL_GIT_COMMIT_SHA;
62
+ if (sha)
63
+ return sha.slice(0, 12);
64
+ // Process is always available in Node — both Vercel functions and stdio MCPs.
65
+ if (process.platform && process.arch) {
66
+ return `mcp-local-${process.platform}-${process.arch}`;
67
+ }
68
+ return "local-dev";
69
+ }
70
+ /**
71
+ * Derive a deterministic CAR ID for a bot deployment.
72
+ * Safe to call on every request — same inputs → same ID.
73
+ */
74
+ export function deriveAgentIdentity(input) {
75
+ const orgId = input.orgId ?? "vorion-llc";
76
+ const deploymentId = resolveDeploymentId();
77
+ // Canonical manifest digest (deterministic, version-pinned)
78
+ const manifestBlob = canonicalJSON({
79
+ slug: input.slug,
80
+ version: input.version,
81
+ name: input.name,
82
+ tier: input.tier,
83
+ capabilities: [...input.capabilities].sort(),
84
+ orgId,
85
+ });
86
+ const contextHash = "sha256:" + sha256(manifestBlob);
87
+ // CAR ID shape: car-<slug>-<12chars of context+org>
88
+ const carHashShort = sha256(contextHash + orgId).slice(0, 12);
89
+ const carId = `car-${input.slug}-${carHashShort}`;
90
+ // Short agent ID (for logs, badges)
91
+ const agentId = `${input.slug}@${input.version}`;
92
+ // Fresh op ID per call
93
+ const operationId = sha256(carId + Date.now() + Math.random()).slice(0, 16);
94
+ const trustCeiling = TIER_CEILING[input.tier];
95
+ const maxEarnableTier = input.maxEarnableTier ?? input.tier;
96
+ return {
97
+ carId,
98
+ agentId,
99
+ operationId,
100
+ orgId,
101
+ deploymentId,
102
+ contextHash,
103
+ parentHash: "", // root
104
+ trustCeiling,
105
+ startingTier: 0,
106
+ maxEarnableTier,
107
+ currentTier: input.tier,
108
+ capabilities: input.capabilities,
109
+ // Flip to "registered" once the backend lands and we call CARClient.registerAgent.
110
+ registrationStatus: "offline-attested",
111
+ };
112
+ }
113
+ //# sourceMappingURL=car-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"car-identity.js","sourceRoot":"","sources":["../src/car-identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAE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EAAE,CAAC;QACf,eAAe;QACf,WAAW,EAAE,KAAK,CAAC,IAAI;QACvB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,mFAAmF;QACnF,kBAAkB,EAAE,kBAAkB;KACvC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @vorionsys/aurais-core — shared library for the Aurais ecosystem.
3
+ *
4
+ * Public API surface:
5
+ * - Proof chain: ProofChain class, ProofEvent / EventAction types,
6
+ * hashText / hashJSON helpers
7
+ * - CAR identity: deriveAgentIdentity, AgentIdentity / DeriveInput / TrustTier
8
+ * types, TIER_CEILING / TIER_NAME tables
9
+ * - Canonical JSON: canonicalJSON serializer + sha256 helper (re-exported
10
+ * so callers can produce digests that match what the lib produces)
11
+ *
12
+ * Source: extracted from voriongit/aurais src/lib/{proof-chain,car-identity}.ts
13
+ * @ be55bf0fffc4254c4f77da03a99a272f5bb7cd5e — see README.md.
14
+ */
15
+ export { ProofChain, type ProofEvent, type EventAction, hashText, hashJSON, } from "./proof-chain.js";
16
+ export { deriveAgentIdentity, type AgentIdentity, type DeriveInput, type TrustTier, TIER_CEILING, TIER_NAME, } from "./car-identity.js";
17
+ export { canonicalJSON, sha256 } from "./canonical-json.js";
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,UAAU,EACV,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,QAAQ,EACR,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,YAAY,EACZ,SAAS,GACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @vorionsys/aurais-core — shared library for the Aurais ecosystem.
3
+ *
4
+ * Public API surface:
5
+ * - Proof chain: ProofChain class, ProofEvent / EventAction types,
6
+ * hashText / hashJSON helpers
7
+ * - CAR identity: deriveAgentIdentity, AgentIdentity / DeriveInput / TrustTier
8
+ * types, TIER_CEILING / TIER_NAME tables
9
+ * - Canonical JSON: canonicalJSON serializer + sha256 helper (re-exported
10
+ * so callers can produce digests that match what the lib produces)
11
+ *
12
+ * Source: extracted from voriongit/aurais src/lib/{proof-chain,car-identity}.ts
13
+ * @ be55bf0fffc4254c4f77da03a99a272f5bb7cd5e — see README.md.
14
+ */
15
+ export { ProofChain, hashText, hashJSON, } from "./proof-chain.js";
16
+ export { deriveAgentIdentity, TIER_CEILING, TIER_NAME, } from "./car-identity.js";
17
+ export { canonicalJSON, sha256 } from "./canonical-json.js";
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,UAAU,EAGV,QAAQ,EACR,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,mBAAmB,EAInB,YAAY,EACZ,SAAS,GACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Proof chain — signed + hash-chained event log for bot actions.
3
+ *
4
+ * Every event in a session carries:
5
+ * - timestamp (ISO)
6
+ * - action (short machine-readable code)
7
+ * - payload (action-specific data)
8
+ * - prev_hash (sha-256 of the previous event's canonical JSON, or "")
9
+ * - signature (ed25519 over canonical JSON of everything above)
10
+ * - pubkey (base64 SPKI of the signing key — for independent verification)
11
+ *
12
+ * Signing key lifecycle (v0):
13
+ * - If AURAIS_SIGNING_KEY_PRIV is set (base64 PKCS#8 DER), use it.
14
+ * - Otherwise generate a session-scoped keypair on first use. The keypair
15
+ * lives for the duration of the serverless / process instance (warm
16
+ * invocations reuse it). This is fine for the BYOK demo; production
17
+ * bots will load a managed key from a KMS-style secret store.
18
+ *
19
+ * Source: extracted unchanged from voriongit/aurais src/lib/proof-chain.ts
20
+ * @ be55bf0fffc4254c4f77da03a99a272f5bb7cd5e on 2026-04-25.
21
+ */
22
+ /**
23
+ * Test/internal helper — drop the cached keypair so the next ProofChain
24
+ * picks up a fresh AURAIS_SIGNING_KEY_PRIV. Not exported from index.ts.
25
+ */
26
+ export declare function _resetKeyCacheForTests(): void;
27
+ /**
28
+ * The event-action vocabulary used today across the Aurais Next app and the
29
+ * five aurais-mcp-* packages. Keeping the union frozen for step 1 to avoid
30
+ * breaking any consumer; widening / per-bot vocabularies will land in step 2.
31
+ */
32
+ export type EventAction = "session_started" | "market_data_fetched" | "indicators_computed" | "commentary_generated" | "briefing_assembled";
33
+ export type ProofEvent = {
34
+ seq: number;
35
+ ts: string;
36
+ action: EventAction;
37
+ payload: Record<string, unknown>;
38
+ prev_hash: string;
39
+ pubkey: string;
40
+ key_id: string;
41
+ sig: string;
42
+ };
43
+ export declare class ProofChain {
44
+ private events;
45
+ private keys;
46
+ constructor();
47
+ append(action: EventAction, payload: Record<string, unknown>): ProofEvent;
48
+ toJSON(): ProofEvent[];
49
+ /** Sha-256 of the canonical last event — the "tip" of the chain. */
50
+ tipHash(): string;
51
+ }
52
+ export declare function hashText(s: string): string;
53
+ export declare function hashJSON(v: unknown): string;
54
+ //# sourceMappingURL=proof-chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proof-chain.d.ts","sourceRoot":"","sources":["../src/proof-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAgDH;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAID;;;;GAIG;AACH,MAAM,MAAM,WAAW,GACnB,iBAAiB,GACjB,qBAAqB,GACrB,qBAAqB,GACrB,sBAAsB,GACtB,oBAAoB,CAAC;AAEzB,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,IAAI,CAAU;;IAMtB,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU;IAsBzE,MAAM,IAAI,UAAU,EAAE;IAItB,oEAAoE;IACpE,OAAO,IAAI,MAAM;CAIlB;AAID,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAE3C"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Proof chain — signed + hash-chained event log for bot actions.
3
+ *
4
+ * Every event in a session carries:
5
+ * - timestamp (ISO)
6
+ * - action (short machine-readable code)
7
+ * - payload (action-specific data)
8
+ * - prev_hash (sha-256 of the previous event's canonical JSON, or "")
9
+ * - signature (ed25519 over canonical JSON of everything above)
10
+ * - pubkey (base64 SPKI of the signing key — for independent verification)
11
+ *
12
+ * Signing key lifecycle (v0):
13
+ * - If AURAIS_SIGNING_KEY_PRIV is set (base64 PKCS#8 DER), use it.
14
+ * - Otherwise generate a session-scoped keypair on first use. The keypair
15
+ * lives for the duration of the serverless / process instance (warm
16
+ * invocations reuse it). This is fine for the BYOK demo; production
17
+ * bots will load a managed key from a KMS-style secret store.
18
+ *
19
+ * Source: extracted unchanged from voriongit/aurais src/lib/proof-chain.ts
20
+ * @ be55bf0fffc4254c4f77da03a99a272f5bb7cd5e on 2026-04-25.
21
+ */
22
+ import { generateKeyPairSync, sign as cryptoSign, createPrivateKey, createPublicKey, } from "node:crypto";
23
+ import { canonicalJSON, sha256 } from "./canonical-json.js";
24
+ let cachedKeys = null;
25
+ function ed25519KeyPair() {
26
+ if (cachedKeys)
27
+ return cachedKeys;
28
+ const envPriv = process.env.AURAIS_SIGNING_KEY_PRIV;
29
+ if (envPriv) {
30
+ try {
31
+ // Ed25519 private keys in PKCS#8 DER, base64
32
+ const der = Buffer.from(envPriv, "base64");
33
+ const priv = createPrivateKey({ key: der, format: "der", type: "pkcs8" });
34
+ const pub = createPublicKey(priv);
35
+ const pubB64 = pub.export({ format: "der", type: "spki" }).toString("base64");
36
+ const keyId = "ed25519:" + sha256(pubB64).slice(0, 12);
37
+ cachedKeys = { priv, pub, pubB64, keyId };
38
+ return cachedKeys;
39
+ }
40
+ catch {
41
+ // fall through to session-scoped generation if env var is malformed
42
+ }
43
+ }
44
+ const { privateKey, publicKey } = generateKeyPairSync("ed25519");
45
+ const pubB64 = publicKey.export({ format: "der", type: "spki" }).toString("base64");
46
+ const keyId = "ed25519-ephemeral:" + sha256(pubB64).slice(0, 12);
47
+ cachedKeys = { priv: privateKey, pub: publicKey, pubB64, keyId };
48
+ return cachedKeys;
49
+ }
50
+ /**
51
+ * Test/internal helper — drop the cached keypair so the next ProofChain
52
+ * picks up a fresh AURAIS_SIGNING_KEY_PRIV. Not exported from index.ts.
53
+ */
54
+ export function _resetKeyCacheForTests() {
55
+ cachedKeys = null;
56
+ }
57
+ export class ProofChain {
58
+ events = [];
59
+ keys;
60
+ constructor() {
61
+ this.keys = ed25519KeyPair();
62
+ }
63
+ append(action, payload) {
64
+ const seq = this.events.length;
65
+ const prev_hash = seq === 0 ? "" : sha256(canonicalJSON(this.events[seq - 1]));
66
+ const ts = new Date().toISOString();
67
+ const unsigned = {
68
+ seq,
69
+ ts,
70
+ action,
71
+ payload,
72
+ prev_hash,
73
+ pubkey: this.keys.pubB64,
74
+ key_id: this.keys.keyId,
75
+ };
76
+ const toSign = Buffer.from(canonicalJSON(unsigned));
77
+ const sig = cryptoSign(null, toSign, this.keys.priv).toString("base64");
78
+ const event = { ...unsigned, sig };
79
+ this.events.push(event);
80
+ return event;
81
+ }
82
+ toJSON() {
83
+ return this.events;
84
+ }
85
+ /** Sha-256 of the canonical last event — the "tip" of the chain. */
86
+ tipHash() {
87
+ if (this.events.length === 0)
88
+ return "";
89
+ return sha256(canonicalJSON(this.events[this.events.length - 1]));
90
+ }
91
+ }
92
+ // ---------- payload hashers (keep payloads small; commit to full content via hash) ----------
93
+ export function hashText(s) {
94
+ return "sha256:" + sha256(s);
95
+ }
96
+ export function hashJSON(v) {
97
+ return "sha256:" + sha256(canonicalJSON(v));
98
+ }
99
+ //# sourceMappingURL=proof-chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proof-chain.js","sourceRoot":"","sources":["../src/proof-chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACL,mBAAmB,EACnB,IAAI,IAAI,UAAU,EAElB,gBAAgB,EAChB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAW5D,IAAI,UAAU,GAAmB,IAAI,CAAC;AAEtC,SAAS,cAAc;IACrB,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC;IAElC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;IACpD,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,6CAA6C;YAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC3C,MAAM,IAAI,GAAG,gBAAgB,CAAC,EAAE,GAAG,EA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C;CACF;AAED,+FAA+F;AAE/F,MAAM,UAAU,QAAQ,CAAC,CAAS;IAChC,OAAO,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,CAAU;IACjC,OAAO,SAAS,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@vorionsys/aurais-core",
3
+ "version": "0.1.0",
4
+ "description": "Shared library for the Aurais ecosystem — proof-chain (Ed25519-signed, sha256-chained event log) and CAR identity helpers. Step 1 of 3 in the aurais-mcp-* consolidation.",
5
+ "license": "Apache-2.0",
6
+ "author": "Vorion LLC <team@vorion.org>",
7
+ "homepage": "https://github.com/voriongit/aurais-core",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/voriongit/aurais-core.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/voriongit/aurais-core/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ },
23
+ "./proof-chain": {
24
+ "types": "./dist/proof-chain.d.ts",
25
+ "import": "./dist/proof-chain.js"
26
+ },
27
+ "./car-identity": {
28
+ "types": "./dist/car-identity.d.ts",
29
+ "import": "./dist/car-identity.js"
30
+ },
31
+ "./canonical-json": {
32
+ "types": "./dist/canonical-json.d.ts",
33
+ "import": "./dist/canonical-json.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "src",
39
+ "README.md",
40
+ "LICENSE"
41
+ ],
42
+ "engines": {
43
+ "node": ">=22"
44
+ },
45
+ "scripts": {
46
+ "build": "tsc -p tsconfig.json",
47
+ "prepare": "npm run build",
48
+ "test": "vitest run",
49
+ "test:watch": "vitest",
50
+ "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^22.19.17",
54
+ "typescript": "^5.9.3",
55
+ "vitest": "^2.1.9"
56
+ }
57
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Canonical JSON serializer + sha256 helper.
3
+ *
4
+ * Canonical JSON: keys sorted, no whitespace. Used as the input for both
5
+ * hashing and signing so independent verifiers can reproduce the digest
6
+ * byte-for-byte regardless of object key insertion order.
7
+ *
8
+ * This is intentionally tiny and dependency-free (node:crypto only).
9
+ * Both proof-chain and car-identity use it; extracted to avoid the
10
+ * within-package duplication that the source files carried before
11
+ * consolidation.
12
+ */
13
+
14
+ import { createHash } from "node:crypto";
15
+
16
+ export function canonicalJSON(value: unknown): string {
17
+ if (value === null || typeof value !== "object") return JSON.stringify(value);
18
+ if (Array.isArray(value)) {
19
+ return "[" + value.map(canonicalJSON).join(",") + "]";
20
+ }
21
+ const obj = value as Record<string, unknown>;
22
+ const keys = Object.keys(obj).sort();
23
+ const parts = keys.map((k) => JSON.stringify(k) + ":" + canonicalJSON(obj[k]));
24
+ return "{" + parts.join(",") + "}";
25
+ }
26
+
27
+ export function sha256(text: string): string {
28
+ return createHash("sha256").update(text).digest("hex");
29
+ }
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Offline CAR identity derivation.
3
+ *
4
+ * The full @vorionsys/car-client library is a registry-backed SDK that expects
5
+ * a live backend (api.agentanchorai.com) for agent registration, role-gate
6
+ * evaluation, ceiling checks, and tier progression. Aurais consumers (the
7
+ * Next app + the five aurais-mcp-* packages) don't have that backend stood
8
+ * up yet, so they can't register bots live.
9
+ *
10
+ * What we CAN do offline:
11
+ * - Derive a deterministic CAR ID from (bot_slug, bot_version, manifest_hash)
12
+ * - Generate a fresh operationId per run
13
+ * - Compute a contextHash over the bot's declared capabilities + tier
14
+ * - Emit these fields in the proof chain, shape-matching the CAR spec
15
+ *
16
+ * When the backend lands, we add a registration step in the bot bootstrap
17
+ * flow that submits this same agent context and gets a signed registration
18
+ * record back. All the existing proof-chain events remain compatible.
19
+ *
20
+ * Source: extracted (with deploymentId resolver widened to cover both the
21
+ * Next app's Vercel env and the MCPs' stdio env) from voriongit/aurais
22
+ * src/lib/car-identity.ts @ be55bf0fffc4254c4f77da03a99a272f5bb7cd5e
23
+ * on 2026-04-25.
24
+ */
25
+
26
+ import { canonicalJSON, sha256 } from "./canonical-json.js";
27
+
28
+ export type TrustTier = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
29
+
30
+ // Observation ceilings per canonical.ts (packages/basis/src/canonical.ts).
31
+ export const TIER_CEILING: Record<TrustTier, number> = {
32
+ 0: 200,
33
+ 1: 300,
34
+ 2: 450,
35
+ 3: 600, // BLACK_BOX
36
+ 4: 750, // GRAY_BOX
37
+ 5: 900, // WHITE_BOX
38
+ 6: 950, // ATTESTED_BOX
39
+ 7: 1000, // VERIFIED_BOX
40
+ };
41
+
42
+ export const TIER_NAME: Record<TrustTier, string> = {
43
+ 0: "PROVISIONING",
44
+ 1: "INITIATED",
45
+ 2: "OBSERVED",
46
+ 3: "BLACK_BOX",
47
+ 4: "GRAY_BOX",
48
+ 5: "WHITE_BOX",
49
+ 6: "ATTESTED_BOX",
50
+ 7: "VERIFIED_BOX",
51
+ };
52
+
53
+ export type AgentIdentity = {
54
+ /** CAR ID — deterministic, stable across runs of the same deployed version. */
55
+ carId: string;
56
+ /** Short human-readable: slug + short hash. */
57
+ agentId: string;
58
+ /** Per-run unique operation ID. */
59
+ operationId: string;
60
+ /** Org this agent is registered under. */
61
+ orgId: string;
62
+ /** Deployment identifier (Vercel env, AURAIS_DEPLOYMENT_ID, or local fallback). */
63
+ deploymentId: string;
64
+ /** sha256 of manifest-canonical fields. */
65
+ contextHash: string;
66
+ /** Parent registration hash. "" for root agents owned by Vorion LLC. */
67
+ parentHash: string;
68
+ /** Trust ceiling (score cap) this tier allows. */
69
+ trustCeiling: number;
70
+ /** Starting tier — per spec, all bots begin at T0 until onboarding. */
71
+ startingTier: TrustTier;
72
+ /** Max tier this bot is approved to reach. */
73
+ maxEarnableTier: TrustTier;
74
+ /** Tier this bot is currently operating at (for offline-attested bots, the required runtime tier). */
75
+ currentTier: TrustTier;
76
+ /** Capabilities declared in the manifest. */
77
+ capabilities: string[];
78
+ /** Status label for the UI — reflects that live registration is pending backend. */
79
+ registrationStatus: "offline-attested" | "registered" | "pending";
80
+ };
81
+
82
+ export type DeriveInput = {
83
+ slug: string;
84
+ version: string;
85
+ name: string;
86
+ tier: TrustTier;
87
+ maxEarnableTier?: TrustTier;
88
+ capabilities: string[];
89
+ orgId?: string;
90
+ };
91
+
92
+ /**
93
+ * Resolve the deployment ID across both Vercel-hosted (Next app) and
94
+ * stdio-hosted (MCP servers) environments. Priority:
95
+ * 1. AURAIS_DEPLOYMENT_ID — explicit override (used by MCPs in CI/tests)
96
+ * 2. VERCEL_DEPLOYMENT_ID — set by Vercel for the Next app
97
+ * 3. VERCEL_GIT_COMMIT_SHA — Vercel commit SHA, first 12 chars
98
+ * 4. mcp-local-${platform}-${arch} — MCP local-dev fallback
99
+ * 5. "local-dev" — last-resort
100
+ */
101
+ function resolveDeploymentId(): string {
102
+ if (process.env.AURAIS_DEPLOYMENT_ID) return process.env.AURAIS_DEPLOYMENT_ID;
103
+ if (process.env.VERCEL_DEPLOYMENT_ID) return process.env.VERCEL_DEPLOYMENT_ID;
104
+ const sha = process.env.VERCEL_GIT_COMMIT_SHA;
105
+ if (sha) return sha.slice(0, 12);
106
+ // Process is always available in Node — both Vercel functions and stdio MCPs.
107
+ if (process.platform && process.arch) {
108
+ return `mcp-local-${process.platform}-${process.arch}`;
109
+ }
110
+ return "local-dev";
111
+ }
112
+
113
+ /**
114
+ * Derive a deterministic CAR ID for a bot deployment.
115
+ * Safe to call on every request — same inputs → same ID.
116
+ */
117
+ export function deriveAgentIdentity(input: DeriveInput): AgentIdentity {
118
+ const orgId = input.orgId ?? "vorion-llc";
119
+ const deploymentId = resolveDeploymentId();
120
+
121
+ // Canonical manifest digest (deterministic, version-pinned)
122
+ const manifestBlob = canonicalJSON({
123
+ slug: input.slug,
124
+ version: input.version,
125
+ name: input.name,
126
+ tier: input.tier,
127
+ capabilities: [...input.capabilities].sort(),
128
+ orgId,
129
+ });
130
+ const contextHash = "sha256:" + sha256(manifestBlob);
131
+
132
+ // CAR ID shape: car-<slug>-<12chars of context+org>
133
+ const carHashShort = sha256(contextHash + orgId).slice(0, 12);
134
+ const carId = `car-${input.slug}-${carHashShort}`;
135
+
136
+ // Short agent ID (for logs, badges)
137
+ const agentId = `${input.slug}@${input.version}`;
138
+
139
+ // Fresh op ID per call
140
+ const operationId = sha256(carId + Date.now() + Math.random()).slice(0, 16);
141
+
142
+ const trustCeiling = TIER_CEILING[input.tier];
143
+ const maxEarnableTier = input.maxEarnableTier ?? input.tier;
144
+
145
+ return {
146
+ carId,
147
+ agentId,
148
+ operationId,
149
+ orgId,
150
+ deploymentId,
151
+ contextHash,
152
+ parentHash: "", // root
153
+ trustCeiling,
154
+ startingTier: 0,
155
+ maxEarnableTier,
156
+ currentTier: input.tier,
157
+ capabilities: input.capabilities,
158
+ // Flip to "registered" once the backend lands and we call CARClient.registerAgent.
159
+ registrationStatus: "offline-attested",
160
+ };
161
+ }
package/src/index.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @vorionsys/aurais-core — shared library for the Aurais ecosystem.
3
+ *
4
+ * Public API surface:
5
+ * - Proof chain: ProofChain class, ProofEvent / EventAction types,
6
+ * hashText / hashJSON helpers
7
+ * - CAR identity: deriveAgentIdentity, AgentIdentity / DeriveInput / TrustTier
8
+ * types, TIER_CEILING / TIER_NAME tables
9
+ * - Canonical JSON: canonicalJSON serializer + sha256 helper (re-exported
10
+ * so callers can produce digests that match what the lib produces)
11
+ *
12
+ * Source: extracted from voriongit/aurais src/lib/{proof-chain,car-identity}.ts
13
+ * @ be55bf0fffc4254c4f77da03a99a272f5bb7cd5e — see README.md.
14
+ */
15
+
16
+ export {
17
+ ProofChain,
18
+ type ProofEvent,
19
+ type EventAction,
20
+ hashText,
21
+ hashJSON,
22
+ } from "./proof-chain.js";
23
+
24
+ export {
25
+ deriveAgentIdentity,
26
+ type AgentIdentity,
27
+ type DeriveInput,
28
+ type TrustTier,
29
+ TIER_CEILING,
30
+ TIER_NAME,
31
+ } from "./car-identity.js";
32
+
33
+ export { canonicalJSON, sha256 } from "./canonical-json.js";
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Proof chain — signed + hash-chained event log for bot actions.
3
+ *
4
+ * Every event in a session carries:
5
+ * - timestamp (ISO)
6
+ * - action (short machine-readable code)
7
+ * - payload (action-specific data)
8
+ * - prev_hash (sha-256 of the previous event's canonical JSON, or "")
9
+ * - signature (ed25519 over canonical JSON of everything above)
10
+ * - pubkey (base64 SPKI of the signing key — for independent verification)
11
+ *
12
+ * Signing key lifecycle (v0):
13
+ * - If AURAIS_SIGNING_KEY_PRIV is set (base64 PKCS#8 DER), use it.
14
+ * - Otherwise generate a session-scoped keypair on first use. The keypair
15
+ * lives for the duration of the serverless / process instance (warm
16
+ * invocations reuse it). This is fine for the BYOK demo; production
17
+ * bots will load a managed key from a KMS-style secret store.
18
+ *
19
+ * Source: extracted unchanged from voriongit/aurais src/lib/proof-chain.ts
20
+ * @ be55bf0fffc4254c4f77da03a99a272f5bb7cd5e on 2026-04-25.
21
+ */
22
+
23
+ import {
24
+ generateKeyPairSync,
25
+ sign as cryptoSign,
26
+ type KeyObject,
27
+ createPrivateKey,
28
+ createPublicKey,
29
+ } from "node:crypto";
30
+ import { canonicalJSON, sha256 } from "./canonical-json.js";
31
+
32
+ // ---------- key material ----------
33
+
34
+ type KeyPair = {
35
+ priv: KeyObject;
36
+ pub: KeyObject;
37
+ pubB64: string;
38
+ keyId: string; // short fingerprint prefix, for display
39
+ };
40
+
41
+ let cachedKeys: KeyPair | null = null;
42
+
43
+ function ed25519KeyPair(): KeyPair {
44
+ if (cachedKeys) return cachedKeys;
45
+
46
+ const envPriv = process.env.AURAIS_SIGNING_KEY_PRIV;
47
+ if (envPriv) {
48
+ try {
49
+ // Ed25519 private keys in PKCS#8 DER, base64
50
+ const der = Buffer.from(envPriv, "base64");
51
+ const priv = createPrivateKey({ key: der, format: "der", type: "pkcs8" });
52
+ const pub = createPublicKey(priv);
53
+ const pubB64 = pub.export({ format: "der", type: "spki" }).toString("base64");
54
+ const keyId = "ed25519:" + sha256(pubB64).slice(0, 12);
55
+ cachedKeys = { priv, pub, pubB64, keyId };
56
+ return cachedKeys;
57
+ } catch {
58
+ // fall through to session-scoped generation if env var is malformed
59
+ }
60
+ }
61
+
62
+ const { privateKey, publicKey } = generateKeyPairSync("ed25519");
63
+ const pubB64 = publicKey.export({ format: "der", type: "spki" }).toString("base64");
64
+ const keyId = "ed25519-ephemeral:" + sha256(pubB64).slice(0, 12);
65
+ cachedKeys = { priv: privateKey, pub: publicKey, pubB64, keyId };
66
+ return cachedKeys;
67
+ }
68
+
69
+ /**
70
+ * Test/internal helper — drop the cached keypair so the next ProofChain
71
+ * picks up a fresh AURAIS_SIGNING_KEY_PRIV. Not exported from index.ts.
72
+ */
73
+ export function _resetKeyCacheForTests(): void {
74
+ cachedKeys = null;
75
+ }
76
+
77
+ // ---------- events ----------
78
+
79
+ /**
80
+ * The event-action vocabulary used today across the Aurais Next app and the
81
+ * five aurais-mcp-* packages. Keeping the union frozen for step 1 to avoid
82
+ * breaking any consumer; widening / per-bot vocabularies will land in step 2.
83
+ */
84
+ export type EventAction =
85
+ | "session_started"
86
+ | "market_data_fetched"
87
+ | "indicators_computed"
88
+ | "commentary_generated"
89
+ | "briefing_assembled";
90
+
91
+ export type ProofEvent = {
92
+ seq: number;
93
+ ts: string; // ISO
94
+ action: EventAction;
95
+ payload: Record<string, unknown>;
96
+ prev_hash: string; // "" for seq=0
97
+ pubkey: string; // base64 SPKI of the signer
98
+ key_id: string; // short fingerprint
99
+ sig: string; // base64 Ed25519 signature over canonical JSON of the above
100
+ };
101
+
102
+ export class ProofChain {
103
+ private events: ProofEvent[] = [];
104
+ private keys: KeyPair;
105
+
106
+ constructor() {
107
+ this.keys = ed25519KeyPair();
108
+ }
109
+
110
+ append(action: EventAction, payload: Record<string, unknown>): ProofEvent {
111
+ const seq = this.events.length;
112
+ const prev_hash = seq === 0 ? "" : sha256(canonicalJSON(this.events[seq - 1]));
113
+ const ts = new Date().toISOString();
114
+
115
+ const unsigned = {
116
+ seq,
117
+ ts,
118
+ action,
119
+ payload,
120
+ prev_hash,
121
+ pubkey: this.keys.pubB64,
122
+ key_id: this.keys.keyId,
123
+ };
124
+ const toSign = Buffer.from(canonicalJSON(unsigned));
125
+ const sig = cryptoSign(null, toSign, this.keys.priv).toString("base64");
126
+
127
+ const event: ProofEvent = { ...unsigned, sig };
128
+ this.events.push(event);
129
+ return event;
130
+ }
131
+
132
+ toJSON(): ProofEvent[] {
133
+ return this.events;
134
+ }
135
+
136
+ /** Sha-256 of the canonical last event — the "tip" of the chain. */
137
+ tipHash(): string {
138
+ if (this.events.length === 0) return "";
139
+ return sha256(canonicalJSON(this.events[this.events.length - 1]));
140
+ }
141
+ }
142
+
143
+ // ---------- payload hashers (keep payloads small; commit to full content via hash) ----------
144
+
145
+ export function hashText(s: string): string {
146
+ return "sha256:" + sha256(s);
147
+ }
148
+
149
+ export function hashJSON(v: unknown): string {
150
+ return "sha256:" + sha256(canonicalJSON(v));
151
+ }