@aarmos/avar-core 1.0.0-rc.3 → 1.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 +190 -21
- package/NOTICE +14 -0
- package/README.md +26 -4
- package/dist/index.d.ts +77 -1
- package/dist/index.js +163 -0
- package/package.json +13 -4
package/LICENSE
CHANGED
|
@@ -1,21 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept and charge a
|
|
167
|
+
fee for accepting support, warranty, indemnity, or other liability
|
|
168
|
+
obligations and/or rights consistent with this License. However,
|
|
169
|
+
in accepting such obligations, You may act only on Your own behalf
|
|
170
|
+
and on Your sole responsibility, not on behalf of any other
|
|
171
|
+
Contributor, and only if You agree to indemnify, defend, and hold
|
|
172
|
+
each Contributor harmless for any liability incurred by, or claims
|
|
173
|
+
asserted against, such Contributor by reason of your accepting any
|
|
174
|
+
such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Aarmatix LLC
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
189
|
+
implied. See the License for the specific language governing
|
|
190
|
+
permissions and limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
@aarmos/avar-core — Reference implementation of the AVAR specification
|
|
2
|
+
Copyright 2026 Aarmatix LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
5
|
+
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
This package is the JavaScript reference implementation for the AVAR
|
|
8
|
+
(Aarmos Verifiable Action Record) specification. The spec and this
|
|
9
|
+
implementation are co-located at:
|
|
10
|
+
|
|
11
|
+
https://github.com/Aarmatix/avar-spec
|
|
12
|
+
|
|
13
|
+
Third-party implementations of avar/1.x are welcome under the same
|
|
14
|
+
license and governance model. See GOVERNANCE.md.
|
package/README.md
CHANGED
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
# @aarmos/avar-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Source of truth:** [`Aarmatix/avar-spec/reference/js`](https://github.com/Aarmatix/avar-spec/tree/main/reference/js).
|
|
4
|
+
> This directory in the Aarmos product monorepo is a working copy kept in
|
|
5
|
+
> lockstep with the spec repo. Bug reports, PRs, and RFCs go to
|
|
6
|
+
> [`Aarmatix/avar-spec`](https://github.com/Aarmatix/avar-spec) — see
|
|
7
|
+
> [`SYNC.md`](./SYNC.md).
|
|
8
|
+
|
|
9
|
+
Reference implementation of the [AVAR specification](https://github.com/Aarmatix/avar-spec/blob/main/SPEC.md) — canonical JSON, Ed25519 signature verification, hash-chain math, and bundle verification.
|
|
4
10
|
|
|
5
11
|
**Pure.** No DOM references, no Node built-ins, no external dependencies. Runs identically in browsers (WebCrypto) and Node.js 20+ (`globalThis.crypto.subtle`).
|
|
6
12
|
|
|
7
13
|
**Normative.** Consumed by:
|
|
8
14
|
- The Aarmos PWA at [`/trust/verify`](https://www.aarmos.io/trust/verify) (browser drop-zone).
|
|
9
|
-
- The `aarmos verify` CLI in [`@aarmos/
|
|
15
|
+
- The `aarmos verify` CLI in [`@aarmos/cli`](https://www.npmjs.com/package/@aarmos/cli).
|
|
10
16
|
- The internal recorder in `src/lib/avar/` (chain + signature production).
|
|
11
17
|
|
|
12
18
|
All three call the same `verifyBundle()`. Divergence between them is guarded by the golden fixtures in [`test/fixtures/`](./test/fixtures/) — see spec §9.
|
|
13
19
|
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npm i @aarmos/avar-core
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or verify a bundle without installing anything:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npx -p @aarmos/cli aarmos verify path/to/bundle.avar.zip
|
|
30
|
+
```
|
|
31
|
+
|
|
14
32
|
## API
|
|
15
33
|
|
|
16
34
|
```ts
|
|
@@ -26,9 +44,13 @@ import {
|
|
|
26
44
|
verifySignature, computeDeviceFingerprint,
|
|
27
45
|
// Verification (top-level)
|
|
28
46
|
verifyBundle,
|
|
29
|
-
} from "@avar
|
|
47
|
+
} from "@aarmos/avar-core";
|
|
30
48
|
```
|
|
31
49
|
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
Apache-2.0. See [`LICENSE`](./LICENSE) and [`NOTICE`](./NOTICE).
|
|
53
|
+
|
|
32
54
|
## Spec revision
|
|
33
55
|
|
|
34
|
-
Tracks `avar/1` spec revision `1.0
|
|
56
|
+
Tracks `avar/1` spec revision `1.0`. See the [AVAR spec](https://github.com/Aarmatix/avar-spec/blob/main/SPEC.md) for the current revision and changelog.
|
package/dist/index.d.ts
CHANGED
|
@@ -194,4 +194,80 @@ declare function signedBodyOf(entry: AvarEntry): Omit<AvarEntry, "signature" | "
|
|
|
194
194
|
|
|
195
195
|
declare function verifyBundle(bundle: AvarBundle): Promise<VerificationReport>;
|
|
196
196
|
|
|
197
|
-
|
|
197
|
+
type DiffOp = {
|
|
198
|
+
op: "add";
|
|
199
|
+
path: string;
|
|
200
|
+
value: unknown;
|
|
201
|
+
} | {
|
|
202
|
+
op: "remove";
|
|
203
|
+
path: string;
|
|
204
|
+
oldValue: unknown;
|
|
205
|
+
} | {
|
|
206
|
+
op: "replace";
|
|
207
|
+
path: string;
|
|
208
|
+
oldValue: unknown;
|
|
209
|
+
value: unknown;
|
|
210
|
+
};
|
|
211
|
+
type CanonicalDiff = {
|
|
212
|
+
equal: boolean;
|
|
213
|
+
ops: DiffOp[];
|
|
214
|
+
};
|
|
215
|
+
/** Structural, canonical diff of two JSON values. */
|
|
216
|
+
declare function diffCanonical(a: unknown, b: unknown): CanonicalDiff;
|
|
217
|
+
type ReceiptEntryChange = {
|
|
218
|
+
id: string;
|
|
219
|
+
indexA: number;
|
|
220
|
+
indexB: number;
|
|
221
|
+
ops: DiffOp[];
|
|
222
|
+
signatureChanged: boolean;
|
|
223
|
+
entryHashChanged: boolean;
|
|
224
|
+
stepsChanged: boolean;
|
|
225
|
+
};
|
|
226
|
+
type ReceiptDiff = {
|
|
227
|
+
equal: boolean;
|
|
228
|
+
kind: "bundle" | "entry";
|
|
229
|
+
specVersion: {
|
|
230
|
+
from: string;
|
|
231
|
+
to: string;
|
|
232
|
+
} | null;
|
|
233
|
+
chainHead: {
|
|
234
|
+
from: {
|
|
235
|
+
entryHash: string;
|
|
236
|
+
index: number;
|
|
237
|
+
};
|
|
238
|
+
to: {
|
|
239
|
+
entryHash: string;
|
|
240
|
+
index: number;
|
|
241
|
+
};
|
|
242
|
+
extended: boolean;
|
|
243
|
+
} | null;
|
|
244
|
+
devicePublicKeys: {
|
|
245
|
+
added: string[];
|
|
246
|
+
removed: string[];
|
|
247
|
+
};
|
|
248
|
+
entries: {
|
|
249
|
+
added: Array<{
|
|
250
|
+
id: string;
|
|
251
|
+
index: number;
|
|
252
|
+
}>;
|
|
253
|
+
removed: Array<{
|
|
254
|
+
id: string;
|
|
255
|
+
index: number;
|
|
256
|
+
}>;
|
|
257
|
+
modified: ReceiptEntryChange[];
|
|
258
|
+
unchanged: number;
|
|
259
|
+
};
|
|
260
|
+
/** Raw canonical diff of manifest + pubkeys (entries handled above). */
|
|
261
|
+
ops: DiffOp[];
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* Compare two AVAR receipts. Accepts full bundles OR single entries.
|
|
265
|
+
* Entries are matched by `id`, not by index — reordering is not a diff.
|
|
266
|
+
*/
|
|
267
|
+
declare function diffReceipts(a: unknown, b: unknown): ReceiptDiff;
|
|
268
|
+
/** Canonical diff of two policy documents. Schema-agnostic. */
|
|
269
|
+
declare function diffPolicies(a: unknown, b: unknown): CanonicalDiff;
|
|
270
|
+
/** Canonical diff of two tool manifests. Schema-agnostic. */
|
|
271
|
+
declare function diffToolManifests(a: unknown, b: unknown): CanonicalDiff;
|
|
272
|
+
|
|
273
|
+
export { type AvarBundle, type AvarEntry, type BundleManifest, type BundlePubKeys, type CanonicalDiff, type DecisionStep, type DiffOp, GENESIS_PREV_HASH, GENESIS_PREV_STEP_HASH, type PolicyHit, type ReceiptDiff, type ReceiptEntryChange, type TextStep, type ToolStep, type TraceStep, type VerificationIssue, type VerificationReport, canonicalize, computeDeviceFingerprint, computeEntryHash, computeStepHash, diffCanonical, diffPolicies, diffReceipts, diffToolManifests, sha256Hex, signedBodyOf, utf8, verifyBundle, verifySignature };
|
package/dist/index.js
CHANGED
|
@@ -294,6 +294,165 @@ function computeChainHead(entries) {
|
|
|
294
294
|
}
|
|
295
295
|
return { entryHash: "", index: -1 };
|
|
296
296
|
}
|
|
297
|
+
|
|
298
|
+
// src/diff.ts
|
|
299
|
+
function isPlainObject(v) {
|
|
300
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
301
|
+
}
|
|
302
|
+
function escapePointer(seg) {
|
|
303
|
+
return seg.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
304
|
+
}
|
|
305
|
+
function join(base, seg) {
|
|
306
|
+
return `${base}/${typeof seg === "number" ? seg : escapePointer(seg)}`;
|
|
307
|
+
}
|
|
308
|
+
function diffCanonical(a, b) {
|
|
309
|
+
const ops = [];
|
|
310
|
+
walk(a, b, "", ops);
|
|
311
|
+
return { equal: ops.length === 0, ops };
|
|
312
|
+
}
|
|
313
|
+
function walk(a, b, path, ops) {
|
|
314
|
+
if (a === b) return;
|
|
315
|
+
if ((a === null || typeof a !== "object") && (b === null || typeof b !== "object")) {
|
|
316
|
+
if (canonicalize(a) !== canonicalize(b)) {
|
|
317
|
+
ops.push({ op: "replace", path: path || "/", oldValue: a, value: b });
|
|
318
|
+
}
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
322
|
+
const min = Math.min(a.length, b.length);
|
|
323
|
+
for (let i = 0; i < min; i++) walk(a[i], b[i], join(path, i), ops);
|
|
324
|
+
if (b.length > a.length) {
|
|
325
|
+
for (let i = a.length; i < b.length; i++) {
|
|
326
|
+
ops.push({ op: "add", path: join(path, i), value: b[i] });
|
|
327
|
+
}
|
|
328
|
+
} else if (a.length > b.length) {
|
|
329
|
+
for (let i = b.length; i < a.length; i++) {
|
|
330
|
+
ops.push({ op: "remove", path: join(path, i), oldValue: a[i] });
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
336
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
337
|
+
const sorted = [...keys].sort();
|
|
338
|
+
for (const k of sorted) {
|
|
339
|
+
const inA = Object.prototype.hasOwnProperty.call(a, k);
|
|
340
|
+
const inB = Object.prototype.hasOwnProperty.call(b, k);
|
|
341
|
+
if (inA && !inB) ops.push({ op: "remove", path: join(path, k), oldValue: a[k] });
|
|
342
|
+
else if (!inA && inB) ops.push({ op: "add", path: join(path, k), value: b[k] });
|
|
343
|
+
else walk(a[k], b[k], join(path, k), ops);
|
|
344
|
+
}
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
ops.push({ op: "replace", path: path || "/", oldValue: a, value: b });
|
|
348
|
+
}
|
|
349
|
+
function isBundle(v) {
|
|
350
|
+
return isPlainObject(v) && typeof v.specVersion === "string" && isPlainObject(v.manifest) && Array.isArray(v.entries);
|
|
351
|
+
}
|
|
352
|
+
function isEntry(v) {
|
|
353
|
+
return isPlainObject(v) && typeof v.id === "string" && Array.isArray(v.steps);
|
|
354
|
+
}
|
|
355
|
+
function diffEntryPair(a, b, indexA, indexB) {
|
|
356
|
+
const { entriesNdjsonBytes: _skip1, ...aClean } = a;
|
|
357
|
+
const { entriesNdjsonBytes: _skip2, ...bClean } = b;
|
|
358
|
+
void _skip1;
|
|
359
|
+
void _skip2;
|
|
360
|
+
const { ops } = diffCanonical(aClean, bClean);
|
|
361
|
+
const signatureChanged = ops.some((o) => o.path === "/signature" || o.path.startsWith("/signature/"));
|
|
362
|
+
const entryHashChanged = ops.some((o) => o.path === "/entryHash");
|
|
363
|
+
const stepsChanged = ops.some((o) => o.path === "/steps" || o.path.startsWith("/steps/"));
|
|
364
|
+
return {
|
|
365
|
+
id: a.id,
|
|
366
|
+
indexA,
|
|
367
|
+
indexB,
|
|
368
|
+
ops,
|
|
369
|
+
signatureChanged,
|
|
370
|
+
entryHashChanged,
|
|
371
|
+
stepsChanged
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function diffReceipts(a, b) {
|
|
375
|
+
if (isEntry(a) && isEntry(b)) {
|
|
376
|
+
const change = diffEntryPair(a, b, 0, 0);
|
|
377
|
+
return {
|
|
378
|
+
equal: change.ops.length === 0,
|
|
379
|
+
kind: "entry",
|
|
380
|
+
specVersion: null,
|
|
381
|
+
chainHead: null,
|
|
382
|
+
devicePublicKeys: { added: [], removed: [] },
|
|
383
|
+
entries: {
|
|
384
|
+
added: [],
|
|
385
|
+
removed: [],
|
|
386
|
+
modified: change.ops.length === 0 ? [] : [change],
|
|
387
|
+
unchanged: change.ops.length === 0 ? 1 : 0
|
|
388
|
+
},
|
|
389
|
+
ops: change.ops
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
if (!isBundle(a) || !isBundle(b)) {
|
|
393
|
+
throw new Error("diffReceipts: inputs must be AvarBundle or AvarEntry values.");
|
|
394
|
+
}
|
|
395
|
+
const specVersion = a.specVersion === b.specVersion ? null : { from: a.specVersion, to: b.specVersion };
|
|
396
|
+
const headA = a.manifest.chainHead;
|
|
397
|
+
const headB = b.manifest.chainHead;
|
|
398
|
+
const chainHead = headA.entryHash === headB.entryHash && headA.index === headB.index ? null : {
|
|
399
|
+
from: headA,
|
|
400
|
+
to: headB,
|
|
401
|
+
extended: headB.index > headA.index
|
|
402
|
+
};
|
|
403
|
+
const keysA = new Set(a.manifest.devicePublicKeys ?? []);
|
|
404
|
+
const keysB = new Set(b.manifest.devicePublicKeys ?? []);
|
|
405
|
+
const devicePublicKeys = {
|
|
406
|
+
added: [...keysB].filter((k) => !keysA.has(k)).sort(),
|
|
407
|
+
removed: [...keysA].filter((k) => !keysB.has(k)).sort()
|
|
408
|
+
};
|
|
409
|
+
const byIdA = /* @__PURE__ */ new Map();
|
|
410
|
+
a.entries.forEach((e, i) => byIdA.set(e.id, { entry: e, index: i }));
|
|
411
|
+
const byIdB = /* @__PURE__ */ new Map();
|
|
412
|
+
b.entries.forEach((e, i) => byIdB.set(e.id, { entry: e, index: i }));
|
|
413
|
+
const added = [];
|
|
414
|
+
const removed = [];
|
|
415
|
+
const modified = [];
|
|
416
|
+
let unchanged = 0;
|
|
417
|
+
for (const [id, { entry, index }] of byIdB) {
|
|
418
|
+
const prior = byIdA.get(id);
|
|
419
|
+
if (!prior) {
|
|
420
|
+
added.push({ id, index });
|
|
421
|
+
continue;
|
|
422
|
+
}
|
|
423
|
+
const change = diffEntryPair(prior.entry, entry, prior.index, index);
|
|
424
|
+
if (change.ops.length === 0) unchanged++;
|
|
425
|
+
else modified.push(change);
|
|
426
|
+
}
|
|
427
|
+
for (const [id, { index }] of byIdA) {
|
|
428
|
+
if (!byIdB.has(id)) removed.push({ id, index });
|
|
429
|
+
}
|
|
430
|
+
added.sort((x, y) => x.index - y.index);
|
|
431
|
+
removed.sort((x, y) => x.index - y.index);
|
|
432
|
+
modified.sort((x, y) => x.indexA - y.indexA);
|
|
433
|
+
const strip = (bundle) => ({
|
|
434
|
+
specVersion: bundle.specVersion,
|
|
435
|
+
manifest: bundle.manifest,
|
|
436
|
+
pubkeys: bundle.pubkeys
|
|
437
|
+
});
|
|
438
|
+
const headerDiff = diffCanonical(strip(a), strip(b));
|
|
439
|
+
const equal = added.length === 0 && removed.length === 0 && modified.length === 0 && headerDiff.equal;
|
|
440
|
+
return {
|
|
441
|
+
equal,
|
|
442
|
+
kind: "bundle",
|
|
443
|
+
specVersion,
|
|
444
|
+
chainHead,
|
|
445
|
+
devicePublicKeys,
|
|
446
|
+
entries: { added, removed, modified, unchanged },
|
|
447
|
+
ops: headerDiff.ops
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
function diffPolicies(a, b) {
|
|
451
|
+
return diffCanonical(a, b);
|
|
452
|
+
}
|
|
453
|
+
function diffToolManifests(a, b) {
|
|
454
|
+
return diffCanonical(a, b);
|
|
455
|
+
}
|
|
297
456
|
export {
|
|
298
457
|
GENESIS_PREV_HASH,
|
|
299
458
|
GENESIS_PREV_STEP_HASH,
|
|
@@ -301,6 +460,10 @@ export {
|
|
|
301
460
|
computeDeviceFingerprint,
|
|
302
461
|
computeEntryHash,
|
|
303
462
|
computeStepHash,
|
|
463
|
+
diffCanonical,
|
|
464
|
+
diffPolicies,
|
|
465
|
+
diffReceipts,
|
|
466
|
+
diffToolManifests,
|
|
304
467
|
sha256Hex,
|
|
305
468
|
signedBodyOf,
|
|
306
469
|
utf8,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aarmos/avar-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Reference implementation of the AVAR (Aarmos Verifiable Action Record) spec — canonical JSON, Ed25519 signature verification, hash-chain math, and bundle verification. Pure, zero-dep, browser + Node.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
17
|
"README.md",
|
|
18
|
-
"LICENSE"
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"NOTICE"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
|
21
22
|
"build": "tsup",
|
|
@@ -29,9 +30,17 @@
|
|
|
29
30
|
"ed25519",
|
|
30
31
|
"verifier"
|
|
31
32
|
],
|
|
32
|
-
"license": "
|
|
33
|
+
"license": "Apache-2.0",
|
|
33
34
|
"author": "Aarmatix LLC",
|
|
34
|
-
"homepage": "https://
|
|
35
|
+
"homepage": "https://github.com/Aarmatix/avar-spec/tree/main/reference/js",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/Aarmatix/avar-spec.git",
|
|
39
|
+
"directory": "reference/js"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/Aarmatix/avar-spec/issues"
|
|
43
|
+
},
|
|
35
44
|
"publishConfig": {
|
|
36
45
|
"access": "public"
|
|
37
46
|
},
|