๐Ÿ“„ src/web3/registry/sidecar-sources.ts
D-OPEN SOVEREIGN

Documentation & Insights

registry_v2 โ†’ SidecarUrls resolver (migration_models_v2.md ยง4.3).

Maps the v2 manifest data block (`layoutVersion` + `forwarding` + `objects`)
into the `SidecarUrls[]` contract that `@the_library/public/models`'s worker
`initialLoad` consumes. Kept structural (no models_v2 dependency) so this
low-level package stays at the bottom of the SDK layering.
`objects[objectType][lang][tier] = [txid, โ€ฆ]` (tier arrays allow sharding).
Structurally compatible with models_v2 `SidecarUrls`.
Resolves a v2 manifest data block to `SidecarUrls[]` for one language.
Uses shard 0 of each tier (single-shard corpus โ€” ยง2.4); multi-shard loading
is deferred to Step 4, at which point this returns an array of shard URLs.
1/*
2 * Copyright (c) 2026 Pond Enterprise Pty Ltd. (ACN 694 747 987)
3 * All Rights Reserved. Proprietary & Confidential.
4 * Unauthorised use is strictly prohibited.
5 */
6
7/**
8 * registry_v2 โ†’ SidecarUrls resolver (migration_models_v2.md ยง4.3).
9 *
10 * Maps the v2 manifest data block (`layoutVersion` + `forwarding` + `objects`)
11 * into the `SidecarUrls[]` contract that `@the_library/public/models`'s worker
12 * `initialLoad` consumes. Kept structural (no models_v2 dependency) so this
13 * low-level package stays at the bottom of the SDK layering.
14 */
15
16/** `objects[objectType][lang][tier] = [txid, โ€ฆ]` (tier arrays allow sharding). */
17export interface SidecarObjectPointers {
18    [lang: string]: { slim?: string[]; extended?: string[]; prov?: string[] };
19}
20
21export interface V2DataBlock {
22    layoutVersion?: number | null;
23    forwarding?: Record<string, Record<string, number>>;
24    objects?: Record<string, SidecarObjectPointers>;
25}
26
27/** Structurally compatible with models_v2 `SidecarUrls`. */
28export interface ResolvedSidecarUrls {
29    objectType: number;
30    slimUrl?: string;
31    extendedUrl?: string;
32    provUrl?: string;
33}
34
35const DEFAULT_GATEWAY = 'https://arweave.net';
36const txUrl = (gateway: string, txid?: string): string | undefined =>
37    txid ? `${gateway.replace(/\/+$/, '')}/${txid}` : undefined;
38
39/**
40 * Resolves a v2 manifest data block to `SidecarUrls[]` for one language.
41 * Uses shard 0 of each tier (single-shard corpus โ€” ยง2.4); multi-shard loading
42 * is deferred to Step 4, at which point this returns an array of shard URLs.
43 */
44export function sidecarUrlsFromManifest(
45    data: V2DataBlock,
46    lang: string,
47    gateway: string = DEFAULT_GATEWAY,
48): ResolvedSidecarUrls[] {
49    const out: ResolvedSidecarUrls[] = [];
50    for (const [objectType, byLang] of Object.entries(data.objects ?? {})) {
51        const tiers = byLang[lang];
52        if (!tiers) continue;
53        out.push({
54            objectType: Number(objectType),
55            slimUrl: txUrl(gateway, tiers.slim?.[0]),
56            extendedUrl: txUrl(gateway, tiers.extended?.[0]),
57            provUrl: txUrl(gateway, tiers.prov?.[0]),
58        });
59    }
60    return out;
61}
62