oculon 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +344 -2
- package/dist/agent.d.ts +47 -0
- package/dist/agent.js +104 -0
- package/dist/cases.d.ts +68 -0
- package/dist/cases.js +158 -0
- package/dist/cli/main.d.ts +12 -0
- package/dist/cli/main.js +1999 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +15 -0
- package/dist/core/context.d.ts +19 -0
- package/dist/core/context.js +19 -0
- package/dist/core/features.d.ts +22 -0
- package/dist/core/features.js +28 -0
- package/dist/core/graph.d.ts +38 -0
- package/dist/core/graph.js +81 -0
- package/dist/core/http.d.ts +42 -0
- package/dist/core/http.js +266 -0
- package/dist/core/keys.d.ts +8 -0
- package/dist/core/keys.js +22 -0
- package/dist/core/llm.d.ts +93 -0
- package/dist/core/llm.js +180 -0
- package/dist/core/merkle.d.ts +15 -0
- package/dist/core/merkle.js +46 -0
- package/dist/core/paths.d.ts +2 -0
- package/dist/core/paths.js +6 -0
- package/dist/core/png.d.ts +17 -0
- package/dist/core/png.js +101 -0
- package/dist/core/quota.d.ts +15 -0
- package/dist/core/quota.js +90 -0
- package/dist/core/stats.d.ts +24 -0
- package/dist/core/stats.js +67 -0
- package/dist/core/store.d.ts +20 -0
- package/dist/core/store.js +213 -0
- package/dist/core/text.d.ts +9 -0
- package/dist/core/text.js +30 -0
- package/dist/core/types.d.ts +38 -0
- package/dist/core/types.js +1 -0
- package/dist/index.d.ts +346 -0
- package/dist/index.js +503 -0
- package/dist/live.d.ts +53 -0
- package/dist/live.js +236 -0
- package/dist/mcp.d.ts +43 -0
- package/dist/mcp.js +651 -0
- package/dist/modules/airport.d.ts +60 -0
- package/dist/modules/airport.js +111 -0
- package/dist/modules/audit.d.ts +73 -0
- package/dist/modules/audit.js +211 -0
- package/dist/modules/bgp.d.ts +147 -0
- package/dist/modules/bgp.js +206 -0
- package/dist/modules/blackout.d.ts +41 -0
- package/dist/modules/blackout.js +98 -0
- package/dist/modules/brief.d.ts +26 -0
- package/dist/modules/brief.js +99 -0
- package/dist/modules/calendar.d.ts +27 -0
- package/dist/modules/calendar.js +145 -0
- package/dist/modules/calibrate.d.ts +46 -0
- package/dist/modules/calibrate.js +92 -0
- package/dist/modules/cloud.d.ts +32 -0
- package/dist/modules/cloud.js +94 -0
- package/dist/modules/condor.d.ts +66 -0
- package/dist/modules/condor.js +214 -0
- package/dist/modules/connect.d.ts +47 -0
- package/dist/modules/connect.js +114 -0
- package/dist/modules/contradictions.d.ts +27 -0
- package/dist/modules/contradictions.js +76 -0
- package/dist/modules/country.d.ts +82 -0
- package/dist/modules/country.js +136 -0
- package/dist/modules/cricket.d.ts +34 -0
- package/dist/modules/cricket.js +166 -0
- package/dist/modules/darkships.d.ts +219 -0
- package/dist/modules/darkships.js +400 -0
- package/dist/modules/defi.d.ts +237 -0
- package/dist/modules/defi.js +512 -0
- package/dist/modules/emailsec.d.ts +47 -0
- package/dist/modules/emailsec.js +146 -0
- package/dist/modules/exposure.d.ts +43 -0
- package/dist/modules/exposure.js +89 -0
- package/dist/modules/factcheck.d.ts +39 -0
- package/dist/modules/factcheck.js +127 -0
- package/dist/modules/falcon.d.ts +58 -0
- package/dist/modules/falcon.js +219 -0
- package/dist/modules/feedback.d.ts +24 -0
- package/dist/modules/feedback.js +37 -0
- package/dist/modules/fence.d.ts +52 -0
- package/dist/modules/fence.js +128 -0
- package/dist/modules/ferret.d.ts +47 -0
- package/dist/modules/ferret.js +220 -0
- package/dist/modules/filings.d.ts +86 -0
- package/dist/modules/filings.js +166 -0
- package/dist/modules/fires.d.ts +56 -0
- package/dist/modules/fires.js +150 -0
- package/dist/modules/hazards.d.ts +37 -0
- package/dist/modules/hazards.js +83 -0
- package/dist/modules/health.d.ts +24 -0
- package/dist/modules/health.js +82 -0
- package/dist/modules/heron.d.ts +68 -0
- package/dist/modules/heron.js +184 -0
- package/dist/modules/hound.d.ts +100 -0
- package/dist/modules/hound.js +301 -0
- package/dist/modules/impact.d.ts +39 -0
- package/dist/modules/impact.js +63 -0
- package/dist/modules/launches.d.ts +24 -0
- package/dist/modules/launches.js +61 -0
- package/dist/modules/listen.d.ts +48 -0
- package/dist/modules/listen.js +125 -0
- package/dist/modules/lynx.d.ts +43 -0
- package/dist/modules/lynx.js +127 -0
- package/dist/modules/magpie.d.ts +70 -0
- package/dist/modules/magpie.js +174 -0
- package/dist/modules/meerkat.d.ts +42 -0
- package/dist/modules/meerkat.js +293 -0
- package/dist/modules/monitor.d.ts +27 -0
- package/dist/modules/monitor.js +105 -0
- package/dist/modules/narratives.d.ts +33 -0
- package/dist/modules/narratives.js +136 -0
- package/dist/modules/owl.d.ts +71 -0
- package/dist/modules/owl.js +290 -0
- package/dist/modules/papers.d.ts +46 -0
- package/dist/modules/papers.js +135 -0
- package/dist/modules/personal.d.ts +54 -0
- package/dist/modules/personal.js +153 -0
- package/dist/modules/pulse.d.ts +19 -0
- package/dist/modules/pulse.js +59 -0
- package/dist/modules/raven.d.ts +80 -0
- package/dist/modules/raven.js +147 -0
- package/dist/modules/recall.d.ts +44 -0
- package/dist/modules/recall.js +123 -0
- package/dist/modules/regs.d.ts +88 -0
- package/dist/modules/regs.js +142 -0
- package/dist/modules/rewind.d.ts +22 -0
- package/dist/modules/rewind.js +68 -0
- package/dist/modules/sanctions.d.ts +62 -0
- package/dist/modules/sanctions.js +173 -0
- package/dist/modules/scam.d.ts +43 -0
- package/dist/modules/scam.js +149 -0
- package/dist/modules/scoop.d.ts +31 -0
- package/dist/modules/scoop.js +74 -0
- package/dist/modules/ships.d.ts +33 -0
- package/dist/modules/ships.js +113 -0
- package/dist/modules/sky.d.ts +47 -0
- package/dist/modules/sky.js +183 -0
- package/dist/modules/squawk.d.ts +46 -0
- package/dist/modules/squawk.js +106 -0
- package/dist/modules/tortoise.d.ts +59 -0
- package/dist/modules/tortoise.js +133 -0
- package/dist/modules/travel.d.ts +94 -0
- package/dist/modules/travel.js +241 -0
- package/dist/modules/urlcheck.d.ts +63 -0
- package/dist/modules/urlcheck.js +223 -0
- package/dist/modules/vulns.d.ts +142 -0
- package/dist/modules/vulns.js +276 -0
- package/dist/plugins.d.ts +41 -0
- package/dist/plugins.js +70 -0
- package/dist/report.d.ts +12 -0
- package/dist/report.js +90 -0
- package/dist/scheduler.d.ts +22 -0
- package/dist/scheduler.js +139 -0
- package/dist/sources/aircraft.d.ts +76 -0
- package/dist/sources/aircraft.js +107 -0
- package/dist/sources/airports.d.ts +28 -0
- package/dist/sources/airports.js +100 -0
- package/dist/sources/ais.d.ts +32 -0
- package/dist/sources/ais.js +111 -0
- package/dist/sources/apify.d.ts +28 -0
- package/dist/sources/apify.js +80 -0
- package/dist/sources/arxiv.d.ts +13 -0
- package/dist/sources/arxiv.js +27 -0
- package/dist/sources/certs.d.ts +12 -0
- package/dist/sources/certs.js +23 -0
- package/dist/sources/corp.d.ts +46 -0
- package/dist/sources/corp.js +60 -0
- package/dist/sources/earth.d.ts +39 -0
- package/dist/sources/earth.js +76 -0
- package/dist/sources/fda.d.ts +77 -0
- package/dist/sources/fda.js +121 -0
- package/dist/sources/finance.d.ts +181 -0
- package/dist/sources/finance.js +270 -0
- package/dist/sources/gdelt.d.ts +19 -0
- package/dist/sources/gdelt.js +33 -0
- package/dist/sources/github.d.ts +17 -0
- package/dist/sources/github.js +33 -0
- package/dist/sources/hackernews.d.ts +20 -0
- package/dist/sources/hackernews.js +37 -0
- package/dist/sources/labels.d.ts +21 -0
- package/dist/sources/labels.js +87 -0
- package/dist/sources/launch.d.ts +16 -0
- package/dist/sources/launch.js +41 -0
- package/dist/sources/ofac.d.ts +29 -0
- package/dist/sources/ofac.js +86 -0
- package/dist/sources/onchain.d.ts +77 -0
- package/dist/sources/onchain.js +189 -0
- package/dist/sources/opentimestamps.d.ts +49 -0
- package/dist/sources/opentimestamps.js +145 -0
- package/dist/sources/polymarket.d.ts +36 -0
- package/dist/sources/polymarket.js +70 -0
- package/dist/sources/predict.d.ts +18 -0
- package/dist/sources/predict.js +59 -0
- package/dist/sources/press.d.ts +30 -0
- package/dist/sources/press.js +111 -0
- package/dist/sources/resend.d.ts +14 -0
- package/dist/sources/resend.js +29 -0
- package/dist/sources/robinhood.d.ts +109 -0
- package/dist/sources/robinhood.js +129 -0
- package/dist/sources/sec.d.ts +67 -0
- package/dist/sources/sec.js +129 -0
- package/dist/sources/sentinel.d.ts +13 -0
- package/dist/sources/sentinel.js +63 -0
- package/dist/sources/signatures.d.ts +14 -0
- package/dist/sources/signatures.js +103 -0
- package/dist/sources/social.d.ts +22 -0
- package/dist/sources/social.js +56 -0
- package/dist/sources/space.d.ts +160 -0
- package/dist/sources/space.js +230 -0
- package/dist/sources/usgs.d.ts +17 -0
- package/dist/sources/usgs.js +24 -0
- package/dist/sources/wayback.d.ts +10 -0
- package/dist/sources/wayback.js +28 -0
- package/dist/sources/websec.d.ts +19 -0
- package/dist/sources/websec.js +40 -0
- package/dist/sources/wikidata.d.ts +11 -0
- package/dist/sources/wikidata.js +30 -0
- package/dist/sources/wikimedia.d.ts +28 -0
- package/dist/sources/wikimedia.js +52 -0
- package/dist/telegram.d.ts +104 -0
- package/dist/telegram.js +927 -0
- package/dist/web/assets/favicon-32.png +0 -0
- package/dist/web/assets/fx.js +178 -0
- package/dist/web/assets/icon-192.png +0 -0
- package/dist/web/assets/icon-512.png +0 -0
- package/dist/web/assets/icon-maskable-512.png +0 -0
- package/dist/web/assets/night-americas.jpg +0 -0
- package/dist/web/assets/night-emea.jpg +0 -0
- package/dist/web/assets/og.png +0 -0
- package/dist/web/assets/redsea-bm.jpg +0 -0
- package/dist/web/docs.html +281 -0
- package/dist/web/index.html +1828 -0
- package/dist/web/insights.d.ts +100 -0
- package/dist/web/insights.js +134 -0
- package/dist/web/landing.html +1144 -0
- package/dist/web/legal.html +176 -0
- package/dist/web/manifest.webmanifest +20 -0
- package/dist/web/mcp.html +104 -0
- package/dist/web/mcphttp.d.ts +10 -0
- package/dist/web/mcphttp.js +67 -0
- package/dist/web/openapi.d.ts +1 -0
- package/dist/web/openapi.js +51 -0
- package/dist/web/public.d.ts +45 -0
- package/dist/web/public.js +136 -0
- package/dist/web/server.d.ts +69 -0
- package/dist/web/server.js +764 -0
- package/dist/web/share.d.ts +35 -0
- package/dist/web/share.js +132 -0
- package/dist/web/sw.js +28 -0
- package/package.json +60 -4
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Squawk: aircraft currently transmitting a transponder emergency code, worldwide, from adsb.lol (keyless).
|
|
3
|
+
* 7500 unlawful interference (hijack), 7700 general emergency, 7600 radio failure.
|
|
4
|
+
* Each aircraft gets its registration and type (adsb.lol database, then hexdb.io when missing) and the nearest
|
|
5
|
+
* airport. Aircraft on the ground and stationary or long-stale positions are left out: those are mostly
|
|
6
|
+
* maintenance tests and transponders left on the wrong code at the gate.
|
|
7
|
+
*/
|
|
8
|
+
import type { Ctx } from '../core/context.js';
|
|
9
|
+
import type { ModuleResult } from '../core/types.js';
|
|
10
|
+
import { type AircraftState, type EmergencyCode } from '../sources/aircraft.js';
|
|
11
|
+
export interface SquawkAircraft {
|
|
12
|
+
code: EmergencyCode;
|
|
13
|
+
meaning: string;
|
|
14
|
+
hex: string;
|
|
15
|
+
callsign: string | null;
|
|
16
|
+
registration: string | null;
|
|
17
|
+
type: string | null;
|
|
18
|
+
owner: string | null;
|
|
19
|
+
lat: number | null;
|
|
20
|
+
lon: number | null;
|
|
21
|
+
altFt: number | null;
|
|
22
|
+
speedKt: number | null;
|
|
23
|
+
track: number | null;
|
|
24
|
+
/** adsb.lol `emergency` field (general, nordo, unlawful, minfuel...) when the transponder sets it. */
|
|
25
|
+
emergency: string | null;
|
|
26
|
+
seenSec: number | null;
|
|
27
|
+
nearestAirport: {
|
|
28
|
+
name: string;
|
|
29
|
+
ident: string;
|
|
30
|
+
km: number;
|
|
31
|
+
} | null;
|
|
32
|
+
url: string;
|
|
33
|
+
}
|
|
34
|
+
export interface Squawks {
|
|
35
|
+
total: number;
|
|
36
|
+
byCode: Record<EmergencyCode, number>;
|
|
37
|
+
aircraft: SquawkAircraft[];
|
|
38
|
+
/** Left out as ground tests, stationary or stale. */
|
|
39
|
+
ignored: number;
|
|
40
|
+
}
|
|
41
|
+
/** True for squawks that are almost certainly not a real airborne emergency. */
|
|
42
|
+
export declare function isGroundOrTest(a: AircraftState, maxSeenSec?: number): boolean;
|
|
43
|
+
export declare function squawks(ctx: Ctx, opts?: {
|
|
44
|
+
codes?: EmergencyCode[];
|
|
45
|
+
lookup?: boolean;
|
|
46
|
+
}): Promise<ModuleResult<Squawks>>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { signalId } from '../core/text.js';
|
|
2
|
+
import { aircraftInfo, bySquawk, EMERGENCY_CODES } from '../sources/aircraft.js';
|
|
3
|
+
import { airportLabel, airports, nearestAirport } from '../sources/airports.js';
|
|
4
|
+
const ORDER = ['7500', '7700', '7600'];
|
|
5
|
+
const BASE_SCORE = { '7500': 90, '7700': 70, '7600': 55 };
|
|
6
|
+
/** True for squawks that are almost certainly not a real airborne emergency. */
|
|
7
|
+
export function isGroundOrTest(a, maxSeenSec = 120) {
|
|
8
|
+
if (a.lat === null || a.lon === null)
|
|
9
|
+
return true;
|
|
10
|
+
if ((a.seenSec ?? 0) > maxSeenSec)
|
|
11
|
+
return true;
|
|
12
|
+
const slow = (a.speedKt ?? 0) < 40;
|
|
13
|
+
if (a.onGround && slow)
|
|
14
|
+
return true;
|
|
15
|
+
if ((a.altFt === null || a.altFt <= 0) && slow)
|
|
16
|
+
return true;
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
export async function squawks(ctx, opts = {}) {
|
|
20
|
+
const now = ctx.now().toISOString();
|
|
21
|
+
const codes = (opts.codes?.length ? opts.codes : ORDER).filter((c) => c in EMERGENCY_CODES);
|
|
22
|
+
const provenance = [];
|
|
23
|
+
const lists = await Promise.all(codes.map(async (code) => ({ code, r: await bySquawk(ctx, code) })));
|
|
24
|
+
const kept = [];
|
|
25
|
+
let ignored = 0;
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
for (const { code, r } of lists) {
|
|
28
|
+
provenance.push(r.prov);
|
|
29
|
+
for (const a of r.data ?? []) {
|
|
30
|
+
// The squawk endpoint matches on the current code; double-check in case of a stale cache entry.
|
|
31
|
+
if (a.squawk && a.squawk !== code)
|
|
32
|
+
continue;
|
|
33
|
+
if (seen.has(a.hex))
|
|
34
|
+
continue;
|
|
35
|
+
seen.add(a.hex);
|
|
36
|
+
if (isGroundOrTest(a))
|
|
37
|
+
ignored++;
|
|
38
|
+
else
|
|
39
|
+
kept.push({ code, a });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const ap = kept.length ? await airports(ctx) : null;
|
|
43
|
+
if (ap)
|
|
44
|
+
provenance.push(ap.prov);
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const { code, a } of kept) {
|
|
47
|
+
let registration = a.registration;
|
|
48
|
+
let type = a.type;
|
|
49
|
+
let owner = null;
|
|
50
|
+
if (opts.lookup !== false && (!registration || !type) && out.length < 15) {
|
|
51
|
+
const info = await aircraftInfo(ctx, a.hex);
|
|
52
|
+
if (info.data) {
|
|
53
|
+
registration ??= info.data.registration;
|
|
54
|
+
type ??= info.data.typeCode ?? info.data.type;
|
|
55
|
+
owner = info.data.owner;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const near = ap?.data && a.lat !== null && a.lon !== null ? nearestAirport(ap.data, a.lat, a.lon) : null;
|
|
59
|
+
out.push({
|
|
60
|
+
code,
|
|
61
|
+
meaning: EMERGENCY_CODES[code],
|
|
62
|
+
hex: a.hex,
|
|
63
|
+
callsign: a.callsign,
|
|
64
|
+
registration,
|
|
65
|
+
type,
|
|
66
|
+
owner,
|
|
67
|
+
lat: a.lat,
|
|
68
|
+
lon: a.lon,
|
|
69
|
+
altFt: a.altFt,
|
|
70
|
+
speedKt: a.speedKt,
|
|
71
|
+
track: a.track,
|
|
72
|
+
emergency: a.emergency && a.emergency !== 'none' ? a.emergency : null,
|
|
73
|
+
seenSec: a.seenSec,
|
|
74
|
+
nearestAirport: near ? { name: airportLabel(near.airport), ident: near.airport.ident, km: Math.round(near.km) } : null,
|
|
75
|
+
url: `https://globe.adsb.lol/?icao=${a.hex}`,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
out.sort((x, y) => ORDER.indexOf(x.code) - ORDER.indexOf(y.code));
|
|
79
|
+
const signals = out.map((x) => {
|
|
80
|
+
const who = [x.callsign, x.registration, x.type].filter(Boolean).join(' / ') || `hex ${x.hex}`;
|
|
81
|
+
const where = x.nearestAirport ? `${x.nearestAirport.km} km from ${x.nearestAirport.name}` : `${x.lat.toFixed(2)}, ${x.lon.toFixed(2)}`;
|
|
82
|
+
// A matching emergency flag from the transponder makes the code more credible than a fat-fingered squawk.
|
|
83
|
+
const confirmed = x.emergency !== null;
|
|
84
|
+
return {
|
|
85
|
+
id: signalId('squawk', x.hex, x.code, now.slice(0, 13)),
|
|
86
|
+
module: 'squawk',
|
|
87
|
+
title: `Squawk ${x.code} (${x.meaning}): ${who} ${where}`,
|
|
88
|
+
score: Math.min(98, BASE_SCORE[x.code] + (confirmed ? 5 : 0)),
|
|
89
|
+
entity: x.registration ?? x.hex,
|
|
90
|
+
evidence: [
|
|
91
|
+
{
|
|
92
|
+
source: 'adsb.lol',
|
|
93
|
+
text: `${who} squawking ${x.code} at ${x.altFt ?? '?'} ft, ${x.speedKt === null ? '?' : Math.round(x.speedKt)} kt, position ${x.lat.toFixed(3)}, ${x.lon.toFixed(3)}${confirmed ? `, emergency flag "${x.emergency}"` : ''}${x.seenSec !== null ? `, seen ${Math.round(x.seenSec)} s ago` : ''}`,
|
|
94
|
+
url: x.url,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
createdAt: now,
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
for (const s of signals)
|
|
101
|
+
ctx.graph.saveSignal(s);
|
|
102
|
+
const byCode = { '7500': 0, '7600': 0, '7700': 0 };
|
|
103
|
+
for (const x of out)
|
|
104
|
+
byCode[x.code]++;
|
|
105
|
+
return { module: 'squawk', input: codes.join(','), generatedAt: now, result: { total: out.length, byCode, aircraft: out, ignored }, signals, provenance };
|
|
106
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tortoise: tamper-evident proofs for Raven's forecasts.
|
|
3
|
+
* Open forecasts are batched into a Merkle tree; the root is timestamped on Bitcoin through OpenTimestamps
|
|
4
|
+
* (free, no wallet). Anyone can later recompute a forecast's hash, walk its Merkle path to the root, and
|
|
5
|
+
* check the root against a Bitcoin block's merkle root. Anchoring on Robinhood Chain is a later, opt-in step
|
|
6
|
+
* because it needs a funded wallet.
|
|
7
|
+
*/
|
|
8
|
+
import type { Ctx } from '../core/context.js';
|
|
9
|
+
import { type PathStep } from '../core/merkle.js';
|
|
10
|
+
import type { ModuleResult } from '../core/types.js';
|
|
11
|
+
import { type Receipt } from '../sources/opentimestamps.js';
|
|
12
|
+
import { predictionCore } from './raven.js';
|
|
13
|
+
/** Everything needed to check a forecast's proof without trusting this server. */
|
|
14
|
+
export interface ProofBundle {
|
|
15
|
+
forecast: ReturnType<typeof predictionCore>;
|
|
16
|
+
canonicalJson: string;
|
|
17
|
+
leaf: string;
|
|
18
|
+
merklePath: PathStep[];
|
|
19
|
+
root: string | null;
|
|
20
|
+
batchId: string | null;
|
|
21
|
+
bitcoin: {
|
|
22
|
+
height: number;
|
|
23
|
+
time: string;
|
|
24
|
+
} | null;
|
|
25
|
+
howToVerify: string[];
|
|
26
|
+
}
|
|
27
|
+
export declare function proofBundle(ctx: Ctx, predictionId: string): ProofBundle;
|
|
28
|
+
/** The forecast's batch root as a standard `.ots` file, or null when it has not been stamped yet. */
|
|
29
|
+
export declare function proofOts(ctx: Ctx, predictionId: string): Buffer | null;
|
|
30
|
+
export interface Batch {
|
|
31
|
+
id: string;
|
|
32
|
+
root: string;
|
|
33
|
+
size: number;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
receipts: Receipt[];
|
|
36
|
+
bitcoinHeight: number | null;
|
|
37
|
+
bitcoinTime: number | null;
|
|
38
|
+
}
|
|
39
|
+
export declare function getBatch(ctx: Ctx, id: string): Batch | null;
|
|
40
|
+
/** Batch every not-yet-stamped forecast and submit the Merkle root to the OpenTimestamps calendars. */
|
|
41
|
+
export declare function stamp(ctx: Ctx): Promise<ModuleResult<{
|
|
42
|
+
batch: Batch | null;
|
|
43
|
+
reason?: string;
|
|
44
|
+
}>>;
|
|
45
|
+
export type ProofStatus = 'VERIFIED' | 'PENDING' | 'NOT_STAMPED' | 'TAMPERED' | 'ERROR';
|
|
46
|
+
export interface Verification {
|
|
47
|
+
predictionId: string;
|
|
48
|
+
status: ProofStatus;
|
|
49
|
+
leaf: string;
|
|
50
|
+
root: string | null;
|
|
51
|
+
steps: string[];
|
|
52
|
+
bitcoin: {
|
|
53
|
+
height: number;
|
|
54
|
+
blockHash: string;
|
|
55
|
+
time: string;
|
|
56
|
+
} | null;
|
|
57
|
+
}
|
|
58
|
+
/** Recompute everything from the stored forecast and check it all the way down to Bitcoin. */
|
|
59
|
+
export declare function verify(ctx: Ctx, predictionId: string): Promise<ModuleResult<Verification>>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { applyPath, merkle } from '../core/merkle.js';
|
|
2
|
+
import { bitcoinBlock, matchesMerkleRoot, otsFile, parseTimestamp, submit, upgrade } from '../sources/opentimestamps.js';
|
|
3
|
+
import { canonicalJson } from '../core/merkle.js';
|
|
4
|
+
import { getPrediction, leafOf, predictionCore } from './raven.js';
|
|
5
|
+
export function proofBundle(ctx, predictionId) {
|
|
6
|
+
const p = getPrediction(ctx, predictionId);
|
|
7
|
+
if (!p)
|
|
8
|
+
throw new Error(`no prediction ${predictionId}`);
|
|
9
|
+
const forecast = predictionCore(p);
|
|
10
|
+
const row = ctx.store.db.prepare('SELECT merkle_path FROM predictions WHERE id = ?').get(p.id);
|
|
11
|
+
const batch = p.batchId ? getBatch(ctx, p.batchId) : null;
|
|
12
|
+
return {
|
|
13
|
+
forecast,
|
|
14
|
+
canonicalJson: canonicalJson(forecast),
|
|
15
|
+
leaf: p.leaf,
|
|
16
|
+
merklePath: row.merkle_path ? JSON.parse(row.merkle_path) : [],
|
|
17
|
+
root: batch?.root ?? null,
|
|
18
|
+
batchId: batch?.id ?? null,
|
|
19
|
+
bitcoin: batch?.bitcoinHeight ? { height: batch.bitcoinHeight, time: new Date((batch.bitcoinTime ?? 0) * 1000).toISOString() } : null,
|
|
20
|
+
howToVerify: [
|
|
21
|
+
'SHA-256 of canonicalJson (UTF-8) must equal leaf.',
|
|
22
|
+
'Walk merklePath from leaf: for each step, hash sha256(current || sibling) when side is R, or sha256(sibling || current) when side is L. The result must equal root.',
|
|
23
|
+
`Download the OpenTimestamps proof (/proof/${p.id}.ots) and run: ots verify -d ${batch?.root ?? '<root>'} ${p.id}.ots (or open it at opentimestamps.org). It names the Bitcoin block whose merkle root commits to root.`,
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** The forecast's batch root as a standard `.ots` file, or null when it has not been stamped yet. */
|
|
28
|
+
export function proofOts(ctx, predictionId) {
|
|
29
|
+
const p = getPrediction(ctx, predictionId);
|
|
30
|
+
const batch = p?.batchId ? getBatch(ctx, p.batchId) : null;
|
|
31
|
+
return batch && batch.receipts.length ? otsFile(batch.root, batch.receipts) : null;
|
|
32
|
+
}
|
|
33
|
+
const toBatch = (r) => ({
|
|
34
|
+
id: r.id,
|
|
35
|
+
root: r.root,
|
|
36
|
+
size: r.size,
|
|
37
|
+
createdAt: new Date(r.created_at).toISOString(),
|
|
38
|
+
receipts: JSON.parse(r.receipts),
|
|
39
|
+
bitcoinHeight: r.bitcoin_height,
|
|
40
|
+
bitcoinTime: r.bitcoin_time,
|
|
41
|
+
});
|
|
42
|
+
export function getBatch(ctx, id) {
|
|
43
|
+
const r = ctx.store.db.prepare('SELECT * FROM proof_batches WHERE id = ?').get(id);
|
|
44
|
+
return r ? toBatch(r) : null;
|
|
45
|
+
}
|
|
46
|
+
/** Batch every not-yet-stamped forecast and submit the Merkle root to the OpenTimestamps calendars. */
|
|
47
|
+
export async function stamp(ctx) {
|
|
48
|
+
const rows = ctx.store.db.prepare('SELECT id, leaf FROM predictions WHERE batch_id IS NULL ORDER BY created_at').all();
|
|
49
|
+
const nowIso = ctx.now().toISOString();
|
|
50
|
+
if (!rows.length)
|
|
51
|
+
return { module: 'tortoise', input: 'stamp', generatedAt: nowIso, result: { batch: null, reason: 'nothing to stamp' }, signals: [], provenance: [] };
|
|
52
|
+
const { root, paths } = merkle(rows.map((r) => r.leaf));
|
|
53
|
+
const { receipts, provenance } = await submit(ctx, root);
|
|
54
|
+
if (!receipts.length) {
|
|
55
|
+
return { module: 'tortoise', input: 'stamp', generatedAt: nowIso, result: { batch: null, reason: 'no calendar accepted the digest' }, signals: [], provenance };
|
|
56
|
+
}
|
|
57
|
+
const id = `batch-${root.slice(0, 16)}`;
|
|
58
|
+
const db = ctx.store.db;
|
|
59
|
+
db.prepare('INSERT INTO proof_batches (id, root, size, created_at, receipts) VALUES (?, ?, ?, ?, ?)').run(id, root, rows.length, Date.parse(nowIso), JSON.stringify(receipts));
|
|
60
|
+
const upd = db.prepare('UPDATE predictions SET batch_id = ?, merkle_path = ? WHERE id = ?');
|
|
61
|
+
rows.forEach((r, i) => upd.run(id, JSON.stringify(paths[i]), r.id));
|
|
62
|
+
return { module: 'tortoise', input: 'stamp', generatedAt: nowIso, result: { batch: getBatch(ctx, id) }, signals: [], provenance };
|
|
63
|
+
}
|
|
64
|
+
/** Recompute everything from the stored forecast and check it all the way down to Bitcoin. */
|
|
65
|
+
export async function verify(ctx, predictionId) {
|
|
66
|
+
const provenance = [];
|
|
67
|
+
const steps = [];
|
|
68
|
+
const nowIso = ctx.now().toISOString();
|
|
69
|
+
const done = (v) => ({
|
|
70
|
+
module: 'tortoise',
|
|
71
|
+
input: predictionId,
|
|
72
|
+
generatedAt: nowIso,
|
|
73
|
+
result: { predictionId, steps, ...v },
|
|
74
|
+
signals: [],
|
|
75
|
+
provenance,
|
|
76
|
+
});
|
|
77
|
+
const p = getPrediction(ctx, predictionId);
|
|
78
|
+
if (!p)
|
|
79
|
+
throw new Error(`no prediction ${predictionId}`);
|
|
80
|
+
const leaf = leafOf(p);
|
|
81
|
+
if (leaf !== p.leaf) {
|
|
82
|
+
steps.push(`hash of stored forecast ${leaf.slice(0, 16)}... does not match recorded leaf ${p.leaf.slice(0, 16)}...`);
|
|
83
|
+
return done({ status: 'TAMPERED', leaf, root: null, bitcoin: null });
|
|
84
|
+
}
|
|
85
|
+
steps.push(`forecast hash recomputed: ${leaf.slice(0, 16)}...`);
|
|
86
|
+
if (!p.batchId)
|
|
87
|
+
return done({ status: 'NOT_STAMPED', leaf, root: null, bitcoin: null });
|
|
88
|
+
const batch = getBatch(ctx, p.batchId);
|
|
89
|
+
const pathRow = ctx.store.db.prepare('SELECT merkle_path FROM predictions WHERE id = ?').get(p.id);
|
|
90
|
+
const root = applyPath(leaf, JSON.parse(pathRow.merkle_path));
|
|
91
|
+
if (root !== batch.root) {
|
|
92
|
+
steps.push(`merkle path leads to ${root.slice(0, 16)}..., batch root is ${batch.root.slice(0, 16)}...`);
|
|
93
|
+
return done({ status: 'TAMPERED', leaf, root, bitcoin: null });
|
|
94
|
+
}
|
|
95
|
+
steps.push(`merkle path checks out to batch root ${root.slice(0, 16)}... (${batch.size} forecasts in batch ${batch.id})`);
|
|
96
|
+
const attestations = [];
|
|
97
|
+
for (const rc of batch.receipts) {
|
|
98
|
+
try {
|
|
99
|
+
const atts = parseTimestamp(Buffer.from(rc.ots, 'hex'), Buffer.from(batch.root, 'hex'));
|
|
100
|
+
for (const a of atts) {
|
|
101
|
+
if (a.kind === 'pending') {
|
|
102
|
+
const up = await upgrade(ctx, a);
|
|
103
|
+
provenance.push(up.prov);
|
|
104
|
+
if (up.attestations.length)
|
|
105
|
+
attestations.push(...up.attestations);
|
|
106
|
+
else
|
|
107
|
+
steps.push(`${a.uri}: still pending (Bitcoin confirmation usually takes a few hours)`);
|
|
108
|
+
}
|
|
109
|
+
else
|
|
110
|
+
attestations.push(a);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
steps.push(`receipt from ${rc.calendar} could not be parsed: ${e.message}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const a of attestations.filter((x) => x.kind === 'bitcoin')) {
|
|
118
|
+
const block = await bitcoinBlock(ctx, a.height);
|
|
119
|
+
provenance.push(block.prov);
|
|
120
|
+
if (!block.data) {
|
|
121
|
+
steps.push(`Bitcoin block ${a.height} could not be fetched (${block.prov.status})`);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (matchesMerkleRoot(a.commitment, block.data.merkleRoot)) {
|
|
125
|
+
ctx.store.db.prepare('UPDATE proof_batches SET bitcoin_height = ?, bitcoin_time = ?, verified_at = ? WHERE id = ?').run(a.height, block.data.time, Date.now(), batch.id);
|
|
126
|
+
steps.push(`commitment equals merkle root of Bitcoin block ${a.height} (${block.data.hash.slice(0, 16)}...)`);
|
|
127
|
+
return done({ status: 'VERIFIED', leaf, root, bitcoin: { height: a.height, blockHash: block.data.hash, time: new Date(block.data.time * 1000).toISOString() } });
|
|
128
|
+
}
|
|
129
|
+
steps.push(`attestation claims block ${a.height} but its merkle root does not match`);
|
|
130
|
+
return done({ status: 'ERROR', leaf, root, bitcoin: null });
|
|
131
|
+
}
|
|
132
|
+
return done({ status: 'PENDING', leaf, root, bitcoin: null });
|
|
133
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Travel and place risk brief: what a visitor should know about a place for the coming week.
|
|
3
|
+
* Official advice: US State Department travel advisories (levels 1-4) and UK FCDO foreign travel advice.
|
|
4
|
+
* Weather: Open-Meteo 7-day forecast (storms, heavy rain, strong gusts, heat, cold, UV), no key.
|
|
5
|
+
* Air quality: OpenAQ PM2.5 near the place (OPENAQ_API_KEY).
|
|
6
|
+
* Health: WHO Disease Outbreak News for the country, last 90 days.
|
|
7
|
+
* Hazards: GDACS orange/red alerts in the country, strong earthquakes within 300 km in the last week,
|
|
8
|
+
* active fires within the place (NASA FIRMS, when FIRMS_MAP_KEY is set), and confirmed internet outages.
|
|
9
|
+
* The brief reports what these sources say; it does not call a place safe.
|
|
10
|
+
*/
|
|
11
|
+
import type { Ctx } from '../core/context.js';
|
|
12
|
+
import type { ModuleResult, Provenance } from '../core/types.js';
|
|
13
|
+
export type RiskLevel = 'low' | 'moderate' | 'high' | 'severe';
|
|
14
|
+
export interface TravelBrief {
|
|
15
|
+
place: {
|
|
16
|
+
name: string;
|
|
17
|
+
lat: number;
|
|
18
|
+
lon: number;
|
|
19
|
+
country: string | null;
|
|
20
|
+
countryCode: string | null;
|
|
21
|
+
};
|
|
22
|
+
level: RiskLevel;
|
|
23
|
+
headline: string;
|
|
24
|
+
points: string[];
|
|
25
|
+
advisories: {
|
|
26
|
+
us: {
|
|
27
|
+
level: number;
|
|
28
|
+
text: string;
|
|
29
|
+
updated: string | null;
|
|
30
|
+
url: string;
|
|
31
|
+
} | null;
|
|
32
|
+
uk: {
|
|
33
|
+
alerts: string[];
|
|
34
|
+
latestChange: string | null;
|
|
35
|
+
updated: string | null;
|
|
36
|
+
url: string;
|
|
37
|
+
} | null;
|
|
38
|
+
};
|
|
39
|
+
weather: {
|
|
40
|
+
days: {
|
|
41
|
+
date: string;
|
|
42
|
+
summary: string;
|
|
43
|
+
tMax: number;
|
|
44
|
+
tMin: number;
|
|
45
|
+
rainMm: number;
|
|
46
|
+
gustKmh: number;
|
|
47
|
+
uv: number | null;
|
|
48
|
+
}[];
|
|
49
|
+
warnings: string[];
|
|
50
|
+
} | null;
|
|
51
|
+
air: {
|
|
52
|
+
pm25: number | null;
|
|
53
|
+
category: string | null;
|
|
54
|
+
stations: number;
|
|
55
|
+
} | null;
|
|
56
|
+
outbreaks: {
|
|
57
|
+
title: string;
|
|
58
|
+
date: string;
|
|
59
|
+
url: string;
|
|
60
|
+
}[];
|
|
61
|
+
hazards: {
|
|
62
|
+
type: string;
|
|
63
|
+
name: string;
|
|
64
|
+
level: string;
|
|
65
|
+
url: string;
|
|
66
|
+
}[];
|
|
67
|
+
quakes: {
|
|
68
|
+
mag: number;
|
|
69
|
+
place: string;
|
|
70
|
+
time: string;
|
|
71
|
+
km: number;
|
|
72
|
+
url: string;
|
|
73
|
+
}[];
|
|
74
|
+
fires: {
|
|
75
|
+
hotspots: number;
|
|
76
|
+
clusters: number;
|
|
77
|
+
} | null;
|
|
78
|
+
internet: {
|
|
79
|
+
outages: string[];
|
|
80
|
+
} | null;
|
|
81
|
+
}
|
|
82
|
+
export declare const namesFor: (country: string) => string[];
|
|
83
|
+
export declare function usAdvisory(ctx: Ctx, country: string): Promise<{
|
|
84
|
+
data: TravelBrief['advisories']['us'];
|
|
85
|
+
prov: Provenance;
|
|
86
|
+
}>;
|
|
87
|
+
export declare function ukAdvice(ctx: Ctx, country: string): Promise<{
|
|
88
|
+
data: TravelBrief['advisories']['uk'];
|
|
89
|
+
prov: Provenance[];
|
|
90
|
+
}>;
|
|
91
|
+
/** Brief for a place: official advice, weather, air, outbreaks, hazards, quakes, fires and internet outages. */
|
|
92
|
+
export declare function travel(ctx: Ctx, placeQuery: string, opts?: {
|
|
93
|
+
fires?: boolean;
|
|
94
|
+
}): Promise<ModuleResult<TravelBrief>>;
|