@ust-protocol/ots-verify 1.0.0-rc.5 → 1.0.0-rc.6

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.
Files changed (2) hide show
  1. package/index.mjs +9 -5
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -79,6 +79,10 @@ export function makeSubstrateVerify({ upgrade = true, fetchImpl = fetch, explore
79
79
  // seam. This plugin is honest about its ceiling; a reachable explorer that DISAGREES on the merkle root is a
80
80
  // definitive NO.
81
81
  const need = Math.max(1, Math.min(quorum, explorers.length));
82
+ // #71-followup P1 — query ALL configured explorers BEFORE deciding: a disagreement by a LATER source must
83
+ // still count (early-returning on quorum could miss it). ANY reachable source that disagrees on the merkle
84
+ // root is a DEFINITIVE NO, even if others agree. And a quorum of ONE is NOT `corroborated` — it is a single
85
+ // trusted oracle, honestly labelled `explorer-single`.
82
86
  let agree = 0, time = null, conflict = false;
83
87
  for (const base of explorers) {
84
88
  try {
@@ -86,16 +90,16 @@ export function makeSubstrateVerify({ upgrade = true, fetchImpl = fetch, explore
86
90
  if (!/^[0-9a-f]{64}$/.test(hash)) continue;
87
91
  const blk = await (await fetchImpl(`${base}/block/${hash}`, { signal: AbortSignal.timeout(10000) })).json();
88
92
  if (!blk || typeof blk.merkle_root !== 'string') continue;
89
- if (blk.merkle_root !== wantMerkle) { conflict = true; break; } // an independent source DISAGREES NO
93
+ if (blk.merkle_root !== wantMerkle) { conflict = true; continue; } // an independent source DISAGREES keep querying, but this is a NO
90
94
  const tip = Number((await (await fetchImpl(`${base}/blocks/tip/height`, { signal: AbortSignal.timeout(10000) })).text()).trim());
91
95
  if (!Number.isFinite(tip) || tip - parsed.height + 1 < minConfirmations) continue; // this source lags on burial → don't count
92
96
  agree++;
93
- time = blk.timestamp ? new Date(blk.timestamp * 1000).toISOString().slice(0, 19) + 'Z' : 'bitcoin-block-' + parsed.height;
94
- if (agree >= need) return { final: true, time, assurance: 'explorer-corroborated', explorers: agree };
97
+ time = time || (blk.timestamp ? new Date(blk.timestamp * 1000).toISOString().slice(0, 19) + 'Z' : 'bitcoin-block-' + parsed.height);
95
98
  } catch { /* explorer unreachable — try the next */ }
96
99
  }
97
- if (conflict) return { final: false, time: 'unproven' }; // a real merkle conflict
98
- return { final: false, time: 'unproven', detail: `only ${agree}/${need} independent explorers corroborated` };
100
+ if (conflict) return { final: false, time: 'unproven' }; // ANY reachable disagreement → definitive NO
101
+ if (agree < need) return { final: false, time: 'unproven', detail: `only ${agree}/${need} independent explorers corroborated` };
102
+ return { final: true, time, assurance: need >= 2 ? 'explorer-corroborated' : 'explorer-single', explorers: agree };
99
103
  };
100
104
  }
101
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ust-protocol/ots-verify",
3
- "version": "1.0.0-rc.5",
3
+ "version": "1.0.0-rc.6",
4
4
  "description": "Opt-in Bitcoin/OpenTimestamps substrateVerify for UST anchors — cross-checks a genesis/hour root against a REAL Bitcoin block header + >=6 confirmations. #68 witness / #69 A2 / #71 explorer-corroborated (2-of-N).",
5
5
  "type": "module",
6
6
  "main": "index.mjs",