Commit 680c862
Volodymyr Shvets
perf(schema): sign GeoJSON geometry as @JSON literal to fix pathological VC canonicalization
Signing a VC that embeds a GeoJSON geometry is dominated by JSON-LD
canonicalization. The generated schema context never activates the geojson
`@list` scoped context for the geometry field, so `coordinates` falls through to
the default `@vocab` and every coordinate is expanded per-value into RDF, which
is super-linear (~O(n^2)). A large MultiPolygon takes tens of seconds and
tens-to-hundreds of MB to sign; concurrent signings stack the cost.
Fix: when a schema context contains `#GeoJSON`, map the root `coordinates`/`bbox`
terms to `@type: @json` so the geometry is signed as a single opaque JCS literal
instead of exploded into RDF lists (root-level term -> applies at every nesting
depth). Cuts canonicalization from ~22s to ~1.5s on a large real schema.
Gated by `geoJsonCoordinatesAsJson`, passed by schema-publish-helper as
`entity !== EVC`: EVC schemas keep the old context because BBS+ selective-
disclosure derive flattens nested arrays inside an @JSON literal, corrupting the
revealed geometry.
`@type: @json` changes only JSON-LD canonicalization, not the stored JSON
document, so consumers reading the geometry as JSON are unaffected. The change
applies to newly published schema contexts; existing credentials keep verifying
against their own published context.1 parent 1a88b4b commit 680c862
2 files changed
Lines changed: 26 additions & 2 deletions
File tree
- common/src/helpers
- guardian-service/src/helpers/import-helpers/schema
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
35 | 51 | | |
36 | 52 | | |
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
56 | 61 | | |
57 | 62 | | |
58 | 63 | | |
| |||
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
99 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
100 | 108 | | |
101 | 109 | | |
102 | 110 | | |
| |||
0 commit comments