@le-space/orbitdb-storage-bridge 0.27.2 → 0.28.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/README.md CHANGED
@@ -56,7 +56,7 @@ entry is the Storacha-era class and the helpers it grew.
56
56
  | `/restore-cid` | `restoreFromCID`, `restoreFromBlocks`: a database back from a CID, or from blocks verified one by one |
57
57
  | `/extract-blocks` | `extractDatabaseBlocks`, `bundleDatabases`: one database's blocks, or several databases' in one bundle |
58
58
  | `/app-backup` | one sealed file for an application: `buildAppBackup`, `openAppBackup`, `restoreAppBackup`, `readAppBackupHeader`, `isAppBackup` |
59
- | `/live-backup` | increments: `createLiveBackup`, `collectIncrement`, `readIncrement`, `mergeIncrements`, `restoreFromIncrements`, `joinIncrements` |
59
+ | `/live-backup` | increments: `createLiveBackup`, `collectIncrement`, `readIncrement`, `mergeIncrements`, `restoreFromIncrements`, `joinIncrements`, and `advanceConfirmation` / `reconcileConfirmation` for a store that refuses later |
60
60
  | `/dehydrate` | `dehydrate`, `hydrate`: a database where a second device finds it from a secret alone |
61
61
  | `/pointer-ipns` | `publishPointer`, `resolvePointer`: the IPNS pointer `dehydrate` publishes, under a name derived from a seed |
62
62
  | `/gateway-fetch` | `fetchFromGateways`: bytes by CID over HTTP, verified against the CID |
@@ -66,7 +66,7 @@ entry is the Storacha-era class and the helpers it grew.
66
66
  | `/backends/types` | the contract: `defineBackend`, `BackendError`, the capability flags |
67
67
  | `/backends/memory` | the in-process driver |
68
68
  | `/backends/aleph` | `createAlephBackend`: ingest to Aleph – its IPFS host, else an API node – with no key, or with `aleph-pin`'s pin to keep in the same call; `onProgress` for the upload |
69
- | `/backends/aleph-pin` | `createAlephPin`, `createAlephAuthorizer`, `listAlephStores`, `waitForMessage`, `createAlephForget`, `forgetAlephStores`: what makes Aleph keep a file, and lets it go |
69
+ | `/backends/aleph-pin` | `createAlephPin`, `createAlephAuthorizer`, `listAlephStores`, `waitForMessage`, `messageStatus`, `alephCredits`, `createAlephForget`, `forgetAlephStores`: what makes Aleph keep a file, and lets it go |
70
70
  | `/backends/aleph-upload` | `unixfsCid`: the CID Aleph gives a file, before the upload; `postFile`, the limits and the upload errors |
71
71
  | `/backends/pinata` | Pinata: pin by CID or upload, with a scoped JWT; `remove()` by file id |
72
72
  | `/backends/lighthouse` | Lighthouse: upload with an API key; `list()` and `remove()` |
@@ -130,6 +130,7 @@ Galaxy A57 with the same key brought the database back and wrote to it. Source:
130
130
  | [docs/APP-BACKUP.md](docs/APP-BACKUP.md) | an application's backup in one sealed file: several databases, a keyring header, kept on Aleph from the browser, restored by merging |
131
131
  | [docs/LIVE-BACKUP.md](docs/LIVE-BACKUP.md) | increments between two full backups: what was written since the last one, shipped as one small CAR, with nobody clicking and no peer online |
132
132
  | [SVELTE-COMPONENTS.md](SVELTE-COMPONENTS.md) | the browser components — older than this repository's copy of them; [docs/STORACHA-UI-HISTORY.md](docs/STORACHA-UI-HISTORY.md) records what each piece could do and where it went |
133
+ | [docs/POST-QUANTUM.md](docs/POST-QUANTUM.md) | what a quantum computer would and would not break: the encryption holds, the signatures do not, and the restore is gated on the AEAD rather than on a signature |
133
134
  | [docs/LOGGING.md](docs/LOGGING.md) | debug namespaces, in Node and in a browser |
134
135
  | [ROADMAP.md](ROADMAP.md) | what is planned |
135
136
  | [docs/STORACHA-SUNSET.md](docs/STORACHA-SUNSET.md) | why Storacha stopped being the default, with dates and evidence |
@@ -350,6 +350,78 @@ export async function waitForMessage(itemHash, options = {}) {
350
350
  return { itemHash, status, timedOut: true };
351
351
  }
352
352
 
353
+ /**
354
+ * What Aleph says about a message now, asked once: `processed`, `pending`,
355
+ * `rejected`, `removing`, `removed`, `forgotten` – or `unknown` when it does
356
+ * not know the message at all (a request that never arrived, or was dropped
357
+ * before it was checked). `waitForMessage` follows a pending one; this is for
358
+ * coming back later, e.g. to an increment that was still pending when its
359
+ * flush ended (`createLiveBackup().reconcile`).
360
+ *
361
+ * `unknown` right after sending is normal: a node answers 404 until the
362
+ * message has reached it. `reconcile` therefore takes `unknown` as refused
363
+ * only for an increment shipped more than `UNKNOWN_GRACE_MS` ago.
364
+ *
365
+ * @param {string} itemHash
366
+ * @param {object} [options]
367
+ * @param {string} [options.apiHost]
368
+ * @param {typeof fetch} [options.fetch]
369
+ * @returns {Promise<{ itemHash: string, status: string, errorCode?: number, details?: unknown }>}
370
+ * @throws when Aleph does not answer (anything but 200 or 404), or answers 200 without a status
371
+ */
372
+ export async function messageStatus(itemHash, options = {}) {
373
+ const apiHost = options.apiHost || DEFAULT_ALEPH_API_HOST;
374
+ const doFetch = options.fetch || globalThis.fetch;
375
+ if (!itemHash)
376
+ throw new BackendError(
377
+ "INVALID_BACKEND",
378
+ "messageStatus needs the message's item hash",
379
+ );
380
+ const response = await doFetch(
381
+ `${apiHost}/api/v0/messages/${encodeURIComponent(itemHash)}`,
382
+ );
383
+ if (response.status === 404) return { itemHash, status: "unknown" };
384
+ if (!response.ok)
385
+ throw new BackendError(
386
+ "UNSUPPORTED",
387
+ `Aleph did not answer: ${response.status}`,
388
+ );
389
+ // A body that says nothing is no answer – not "unknown", which a caller
390
+ // takes as refused and ships again.
391
+ const body = await response.json().catch(() => null);
392
+ if (typeof body?.status !== "string")
393
+ throw new BackendError(
394
+ "UNSUPPORTED",
395
+ `Aleph answered ${response.status} without a message status`,
396
+ );
397
+ return {
398
+ itemHash,
399
+ status: body.status,
400
+ ...(body?.error_code != null ? { errorCode: body.error_code } : {}),
401
+ ...(body?.details != null ? { details: body.details } : {}),
402
+ };
403
+ }
404
+
405
+ /**
406
+ * An account's credits, or null when Aleph does not say.
407
+ *
408
+ * @param {string} address - EIP-55 checksummed (Aleph keys accounts by that form)
409
+ * @param {object} [options]
410
+ * @param {string} [options.apiHost]
411
+ * @param {typeof fetch} [options.fetch]
412
+ * @returns {Promise<number|null>}
413
+ */
414
+ export async function alephCredits(address, options = {}) {
415
+ const apiHost = options.apiHost || DEFAULT_ALEPH_API_HOST;
416
+ const doFetch = options.fetch || globalThis.fetch;
417
+ const response = await doFetch(
418
+ `${apiHost}/api/v0/addresses/${address}/balance`,
419
+ ).catch(() => null);
420
+ if (!response?.ok) return null;
421
+ const body = await response.json().catch(() => ({}));
422
+ return Number.isFinite(body?.credit_balance) ? body.credit_balance : null;
423
+ }
424
+
353
425
  /**
354
426
  * The STORE messages kept for an account, newest first: its own, and those a
355
427
  * delegate sent for it.
@@ -38,6 +38,27 @@
38
38
  * being ingest-only. `./aleph-pin.js` is that implementation: `createAlephPin`
39
39
  * builds and signs the STORE, and is what a caller passes as `pin`.
40
40
  *
41
+ * ## Upload and STORE in one call, when the pin can sign
42
+ *
43
+ * Ingest first and a STORE afterwards is two steps with a gap between them:
44
+ * the STORE names a CID that Aleph's nodes (CCNs) must then fetch from the
45
+ * IPFS host, which holds the upload unpinned. Since about 2026-11-04 that
46
+ * fetch fails — Belege's backups were rejected with `error_code` 4, "File not
47
+ * found: <cid> (could not retrieve IPFS content at this time)", and the host
48
+ * dropped the file later (gateway 504). Measured again on 2026-11-11 with a
49
+ * throwaway account: `/api/v0/add` on the IPFS host answers 200 again, the
50
+ * file is on the gateway, the API node's `/storage/raw/<cid>` does not have
51
+ * it, and the separate STORE stays `pending` for many minutes.
52
+ *
53
+ * So a `pin` with `sign` (`createAlephPin`) now sends every upload to the API
54
+ * node's `add_file` with the signed STORE beside the file: the node pins it
55
+ * itself and answers with the message's status, nothing has to be fetched
56
+ * from anywhere. The ingest host is used only without a signing pin, where
57
+ * nothing would keep the file anyway. `pinCid` (a STORE for a CID already
58
+ * elsewhere) still exists and still depends on the CCNs finding the file;
59
+ * follow its item hash with `waitForMessage` and treat `error_code` 4 as
60
+ * "upload it again, signed".
61
+ *
41
62
  * @author @NiKrause
42
63
  * @requires ./types.js - the backend contract
43
64
  */
@@ -71,10 +92,11 @@ export const ALEPH_GATEWAYS = Object.freeze(["https://ipfs.aleph.cloud/ipfs"]);
71
92
 
72
93
  const ALEPH_INGEST = "https://ipfs.aleph.cloud/api/v0/add";
73
94
  /**
74
- * Where an upload goes when the IPFS host takes none: an API node's
75
- * `/api/v0/ipfs/add_file`. Since 2026-10-26 every `/api/v0/` call on Aleph's
76
- * IPFS hosts answers 404 (they serve the gateway only); the API nodes still
77
- * take a file, with the limits `./aleph-upload.js` names.
95
+ * Where an upload goes when the IPFS host takes none, and always when the pin
96
+ * can sign: an API node's `/api/v0/ipfs/add_file`. From 2026-10-26 every
97
+ * `/api/v0/` call on Aleph's IPFS hosts answered 404 (on 2026-11-11 `add`
98
+ * answered 200 again); the API nodes take a file, with the limits
99
+ * `./aleph-upload.js` names.
78
100
  */
79
101
  export const DEFAULT_ALEPH_API_HOST = "https://api2.aleph.im";
80
102
  const DEFAULT_TIMEOUT_MS = 120_000;
@@ -201,10 +223,15 @@ export function createAlephBackend(options = {}) {
201
223
  ...(meta.name ? { name: meta.name } : {}),
202
224
  };
203
225
 
204
- // The IPFS host first, while it answers at all: an upload there is
205
- // free of any limit below 1 GiB and needs no message. A 404 or 405 says
206
- // it takes none, and is remembered for this backend's lifetime.
207
- if (ingestUrl && !ingestGone) {
226
+ const signed = typeof pin?.sign === "function";
227
+
228
+ // The IPFS host first, while it answers at all and no STORE can go
229
+ // beside the file: an upload there is free of any limit below 1 GiB and
230
+ // needs no message. A 404 or 405 says it takes none, and is remembered
231
+ // for this backend's lifetime. With a pin that signs it is skipped: a
232
+ // STORE sent after it, separately, has to fetch the file back from that
233
+ // host, and since 2026-11-04 that fails (see the header).
234
+ if (ingestUrl && !ingestGone && !signed) {
208
235
  try {
209
236
  const id = await viaIngest({ bytes, name, contentType, onProgress });
210
237
  // Said out loud in the handle, because "stored" and "kept" are not
@@ -221,7 +248,6 @@ export function createAlephBackend(options = {}) {
221
248
  // The API node. With a signed STORE message beside the file the node
222
249
  // keeps it in the same call; without one it takes at most 25 MiB and
223
250
  // keeps it for a day, until a STORE names it.
224
- const signed = typeof pin?.sign === "function";
225
251
  // The node measures the request body, the form around the file included.
226
252
  const limit =
227
253
  (signed ? ALEPH_API_SIGNED_LIMIT : ALEPH_API_UNSIGNED_LIMIT) -
@@ -46,6 +46,19 @@
46
46
  * says how many updates are waiting, when the last increment went out and
47
47
  * what the last failure was, so an application can show "last backed up …".
48
48
  *
49
+ * ## A store that answers "pending" and refuses later
50
+ *
51
+ * Aleph takes a STORE with "pending" and may reject it minutes later – a file
52
+ * its nodes could not fetch, credit that ran out. An increment shipped under
53
+ * such an answer has moved the chain on, and nothing would ship its content
54
+ * again. So the chain also remembers how far the store has *confirmed* it
55
+ * (`kept`) and the increments shipped since (`unconfirmed`); `reconcile()`
56
+ * asks about those again and, when one turns out refused or unknown, goes
57
+ * back to `kept`: the next flush ships everything since, under the next
58
+ * number after the last one kept, so a restore finds no gap. The bookkeeping
59
+ * is `advanceConfirmation` / `reconcileConfirmation`, exported for an
60
+ * application that keeps its own chain state.
61
+ *
49
62
  * @requires ./backup-car.js - createCARFromBlocks
50
63
  * @requires ./restore-cid.js - readBlocksFromCAR, restoreFromBlocks
51
64
  */
@@ -56,7 +69,12 @@ import { CID } from "multiformats/cid";
56
69
  import { sha256 } from "multiformats/hashes/sha2";
57
70
  import { base58btc } from "multiformats/bases/base58";
58
71
  import { createCARFromBlocks } from "./backup-car.js";
59
- import { readBlocksFromCAR, restoreFromBlocks, entryDatabaseId, standalone } from "./restore-cid.js";
72
+ import {
73
+ readBlocksFromCAR,
74
+ restoreFromBlocks,
75
+ entryDatabaseId,
76
+ standalone,
77
+ } from "./restore-cid.js";
60
78
 
61
79
  /** What the manifest at an increment's root calls itself. */
62
80
  export const INCREMENT_KIND = "increment";
@@ -76,6 +94,10 @@ const DAG_CBOR = dagCbor.code;
76
94
  * @property {string|null} base - the full backup the increments build on, as the caller named it
77
95
  * @property {string|null} previous - the backend's id of the last increment
78
96
  * @property {Object<string, { heads: string[] }>} databases - by address: the heads last shipped
97
+ * @property {{ sequence: number, previous: string|null, databases: object }|null} [kept] - the last
98
+ * point the store confirmed; null before any
99
+ * @property {Array<{ sequence: number, previous: string|null, databases: object, cid: string }>} [unconfirmed] -
100
+ * increments shipped since that the store has not confirmed, oldest first
79
101
  */
80
102
 
81
103
  /**
@@ -517,7 +539,10 @@ export async function joinIncrements(
517
539
  // OrbitDB names its blocks in base58btc; a CAR in base32. The log reads
518
540
  // its own names, and identities are looked up by theirs, so each block
519
541
  // goes in under the name its reader will ask for.
520
- await database.log.storage.put(cid.toV1().toString(base58btc), standalone(bytes));
542
+ await database.log.storage.put(
543
+ cid.toV1().toString(base58btc),
544
+ standalone(bytes),
545
+ );
521
546
  }
522
547
 
523
548
  let joined = 0;
@@ -538,6 +563,101 @@ export async function joinIncrements(
538
563
  };
539
564
  }
540
565
 
566
+ /**
567
+ * How long an increment may be unknown to the store before that counts as
568
+ * refused: Aleph answers 404 for a message that has not reached the node yet.
569
+ */
570
+ export const UNKNOWN_GRACE_MS = 10 * 60_000;
571
+
572
+ /** Statuses that mean the store does not keep a blob. */
573
+ export const NOT_KEPT = Object.freeze(["rejected", "unknown", "forgotten"]);
574
+
575
+ /**
576
+ * How far a store has confirmed a chain, and what was shipped since.
577
+ *
578
+ * A *point* is whatever the caller needs to go back to – `sequence`,
579
+ * `previous` and its own fields (the heads shipped by then, a count of
580
+ * files, …). It is kept as given, never read here beyond `sequence`.
581
+ *
582
+ * @typedef {object} Confirmation
583
+ * @property {object|null} kept - the last point the store confirmed
584
+ * @property {Array<object & { cid: string }>} pending - points shipped since, oldest first
585
+ */
586
+
587
+ /**
588
+ * The confirmation after an increment was shipped.
589
+ *
590
+ * `processed` with nothing open before it moves `kept` to this point; any
591
+ * other answer puts the point aside as pending, with the blob's id to ask
592
+ * about later.
593
+ *
594
+ * @param {Confirmation|null|undefined} confirmation
595
+ * @param {object} point - where the chain stands with this increment
596
+ * @param {string} cid - the increment's id in the store
597
+ * @param {string} [status="processed"] - the store's answer
598
+ * @returns {Confirmation}
599
+ */
600
+ export function advanceConfirmation(
601
+ confirmation,
602
+ point,
603
+ cid,
604
+ status = "processed",
605
+ ) {
606
+ const pending = confirmation?.pending ?? [];
607
+ if (status === "processed" && pending.length === 0) {
608
+ return { kept: point, pending: [] };
609
+ }
610
+ return {
611
+ kept: confirmation?.kept ?? null,
612
+ pending: [...pending, { ...point, cid }],
613
+ };
614
+ }
615
+
616
+ /**
617
+ * The confirmation by what the store says now.
618
+ *
619
+ * Walks the pending points oldest first: a `processed` one moves `kept` on; a
620
+ * refused, unknown or forgotten one ends it – everything pending is dropped
621
+ * and `rewind` is the point to go back to (`null`: before anything was
622
+ * confirmed, the caller's own start). A point the store has not decided on
623
+ * stops the walk. `gap` says an increment *after* a refused one is kept: a
624
+ * restore cannot cross that, and only a new full backup mends it.
625
+ *
626
+ * @param {Confirmation} confirmation
627
+ * @param {(cid: string) => string|undefined} statusOf - the store's word on a blob, if known
628
+ * @returns {{ kept: object|null, pending: object[], changed: boolean, rewound: boolean, rewind: object|null, gap: boolean }}
629
+ */
630
+ export function reconcileConfirmation(confirmation, statusOf) {
631
+ let kept = confirmation?.kept ?? null;
632
+ const pending = [...(confirmation?.pending ?? [])];
633
+ let changed = false;
634
+ while (pending.length) {
635
+ const status = statusOf(pending[0].cid);
636
+ if (status === "processed") {
637
+ const point = { ...pending.shift() };
638
+ delete point.cid;
639
+ kept = point;
640
+ changed = true;
641
+ continue;
642
+ }
643
+ if (status && NOT_KEPT.includes(status)) {
644
+ const gap = pending
645
+ .slice(1)
646
+ .some((point) => statusOf(point.cid) === "processed");
647
+ return {
648
+ kept,
649
+ pending: [],
650
+ changed: true,
651
+ rewound: true,
652
+ rewind: kept,
653
+ gap,
654
+ };
655
+ }
656
+ break;
657
+ }
658
+ return { kept, pending, changed, rewound: false, rewind: null, gap: false };
659
+ }
660
+
541
661
  /** A state with nothing shipped yet. */
542
662
  export const emptyLiveBackupState = () => ({
543
663
  v: LIVE_BACKUP_STATE_VERSION,
@@ -545,6 +665,8 @@ export const emptyLiveBackupState = () => ({
545
665
  base: null,
546
666
  previous: null,
547
667
  databases: {},
668
+ kept: null,
669
+ unconfirmed: [],
548
670
  });
549
671
 
550
672
  /**
@@ -565,7 +687,10 @@ export const emptyLiveBackupState = () => ({
565
687
  * @param {() => Promise<Map<string, { bytes: Uint8Array }>>|Map} [params.blocks] - blocks of the
566
688
  * application's own to carry in the next increment (receipt files, …)
567
689
  * @param {boolean} [params.keep=true] - ask a backend whose handle says
568
- * `retained: false` to keep the increment (`pinCid`)
690
+ * `retained: false` to keep the increment (`pinCid`). A handle that already
691
+ * carries the store's answer (`status`, as an Aleph upload with a signing
692
+ * pin does: the STORE went with the file) is not pinned a second time; its
693
+ * answer is the one followed and recorded
569
694
  * @param {(sequence: number, at: Date) => string} [params.name] - the blob's name
570
695
  * @param {(shipped: { sequence: number, handle: object, kept?: object, entries: number, blocks: number, bytes: number, at: Date }) => void} [params.onShipped]
571
696
  * @param {(error: Error) => void} [params.onError]
@@ -576,7 +701,7 @@ export const emptyLiveBackupState = () => ({
576
701
  * flush and the state stays, so the next one ships it all again.
577
702
  * @param {() => Date} [params.now]
578
703
  * @returns {{ watch: Function, unwatch: Function, start: Function, stop: Function, close: Function,
579
- * flush: () => Promise<object|null>, rebase: Function, status: () => object }}
704
+ * flush: () => Promise<object|null>, rebase: Function, reconcile: Function, status: () => object }}
580
705
  */
581
706
  export function createLiveBackup({
582
707
  databases,
@@ -607,6 +732,8 @@ export function createLiveBackup({
607
732
  let pending = 0;
608
733
  let inflight = null;
609
734
  let again = false;
735
+ /** A reconcile applying its answers: a flush waits for it, or it would ship from a state about to move. */
736
+ let reconciling = null;
610
737
  let timer = null;
611
738
  let settling = null;
612
739
  let lastShipped = null;
@@ -701,6 +828,7 @@ export function createLiveBackup({
701
828
  };
702
829
 
703
830
  const ship = async () => {
831
+ if (reconciling) await reconciling.catch(() => {});
704
832
  await load();
705
833
  // Counted before the walk: OrbitDB appends before it emits `update`, so
706
834
  // every update counted here is in the log the walk is about to read, and
@@ -725,13 +853,27 @@ export function createLiveBackup({
725
853
  contentType: "application/vnd.ipld.car",
726
854
  });
727
855
  let kept;
728
- if (
856
+ if (typeof handle?.status === "string") {
857
+ // The upload carried its own keep request (a signed Aleph upload): a
858
+ // second one through pinCid would be paid twice, and would take the
859
+ // path whose STOREs the nodes could not fetch (2026-11).
860
+ kept = {
861
+ id: handle.id,
862
+ backend: handle.backend,
863
+ retained: handle.retained === true,
864
+ status: handle.status,
865
+ ...(handle.itemHash ? { itemHash: handle.itemHash } : {}),
866
+ };
867
+ } else if (
729
868
  keep &&
730
869
  handle?.retained === false &&
731
870
  typeof backend.pinCid === "function"
732
871
  ) {
733
872
  kept = await backend.pinCid(handle.id, { name: handle.name });
734
- if (confirmKept) kept = await confirmKept(kept, handle);
873
+ }
874
+ if (kept) {
875
+ if (confirmKept && kept.status !== "processed")
876
+ kept = await confirmKept(kept, handle);
735
877
  if (kept?.status === "rejected") {
736
878
  throw new Error(
737
879
  `The store refused to keep increment ${collected.manifest.sequence}${kept.errorCode != null ? ` (${kept.errorCode})` : ""}: it was uploaded but is not kept.`,
@@ -754,6 +896,23 @@ export function createLiveBackup({
754
896
  w.shipped.heads = heads;
755
897
  state.databases[address] = { heads };
756
898
  }
899
+ // How far the store has confirmed the chain: a pending answer is put
900
+ // aside, so `reconcile()` can go back if it is refused later.
901
+ const confirmation = advanceConfirmation(
902
+ { kept: state.kept, pending: state.unconfirmed },
903
+ {
904
+ sequence: state.sequence,
905
+ previous: state.previous,
906
+ databases: JSON.parse(JSON.stringify(state.databases)),
907
+ // When it went out: a store that does not know a message yet
908
+ // (Aleph's 404 before it has propagated) is not a refusal.
909
+ shippedAt: at.toISOString(),
910
+ },
911
+ state.previous,
912
+ kept?.status ?? "processed",
913
+ );
914
+ state.kept = confirmation.kept;
915
+ state.unconfirmed = confirmation.pending;
757
916
  pending = Math.max(0, pending - countedPending);
758
917
  await save();
759
918
 
@@ -819,10 +978,98 @@ export function createLiveBackup({
819
978
  w.shipped.heads = heads;
820
979
  state.databases[address] = { heads };
821
980
  }
981
+ // A full backup is where the chain is kept from.
982
+ if (base !== undefined) {
983
+ state.kept = {
984
+ sequence: 0,
985
+ previous: null,
986
+ databases: JSON.parse(JSON.stringify(state.databases)),
987
+ };
988
+ state.unconfirmed = [];
989
+ }
822
990
  pending = 0;
823
991
  await save();
824
992
  };
825
993
 
994
+ /**
995
+ * Ask the store again about the increments it had not confirmed, and go
996
+ * back to the last confirmed point when one was refused.
997
+ *
998
+ * @param {(cid: string, point: object) => Promise<string|undefined>|string|undefined} statusOf -
999
+ * the store's word on an increment by its id: `processed`, `pending`,
1000
+ * `rejected`, `unknown`, `forgotten` (for Aleph: `messageStatus` on the
1001
+ * STORE's item hash, which the caller kept from `onShipped`)
1002
+ * @returns {Promise<{ changed: boolean, rewound: boolean, gap: boolean, sequence: number }>}
1003
+ * `gap`: an increment after a refused one is kept – make a full backup and `rebase({ base })`
1004
+ */
1005
+ const reconcile = async (statusOf) => {
1006
+ if (inflight) await inflight.catch(() => {});
1007
+ await load();
1008
+ // The answers first, which takes network time; a flush may run meanwhile.
1009
+ const answers = new Map();
1010
+ const asked = Date.now();
1011
+ for (const point of state.unconfirmed ?? []) {
1012
+ let answer = await statusOf(point.cid, point);
1013
+ // Not known yet is not refused while the message may still be on its way.
1014
+ const age = point.shippedAt ? asked - Date.parse(point.shippedAt) : Infinity;
1015
+ if (answer === "unknown" && age < UNKNOWN_GRACE_MS) answer = undefined;
1016
+ answers.set(point.cid, answer);
1017
+ }
1018
+ // Then applied to the state as it is now, with no flush running and none
1019
+ // starting until it is done: a point shipped meanwhile has no answer, so
1020
+ // the walk stops before it – or, when an earlier one was refused, it goes
1021
+ // back with the rest.
1022
+ if (inflight) await inflight.catch(() => {});
1023
+ let release;
1024
+ let wentBack = false;
1025
+ reconciling = new Promise((resolve) => (release = resolve));
1026
+ try {
1027
+ const now_ = reconcileConfirmation(
1028
+ { kept: state.kept ?? null, pending: state.unconfirmed ?? [] },
1029
+ (cid) => answers.get(cid),
1030
+ );
1031
+ if (!now_.changed)
1032
+ return {
1033
+ changed: false,
1034
+ rewound: false,
1035
+ gap: false,
1036
+ sequence: state.sequence,
1037
+ };
1038
+ state.kept = now_.kept;
1039
+ state.unconfirmed = now_.pending;
1040
+ if (now_.rewound) {
1041
+ const back = now_.rewind ?? {
1042
+ sequence: 0,
1043
+ previous: null,
1044
+ databases: {},
1045
+ };
1046
+ state.sequence = back.sequence;
1047
+ state.previous = back.previous;
1048
+ state.databases = JSON.parse(JSON.stringify(back.databases ?? {}));
1049
+ for (const [address, w] of watched) {
1050
+ const heads = state.databases[address]?.heads ?? [];
1051
+ w.shipped = await reachable(w.database, heads);
1052
+ w.shipped.heads = heads;
1053
+ }
1054
+ // Nothing announces what has to go again: count it, so a flush ships it.
1055
+ pending = Math.max(pending, 1);
1056
+ wentBack = true;
1057
+ }
1058
+ await save();
1059
+ return {
1060
+ changed: true,
1061
+ rewound: now_.rewound,
1062
+ gap: now_.gap,
1063
+ sequence: state.sequence,
1064
+ };
1065
+ } finally {
1066
+ reconciling = null;
1067
+ release();
1068
+ // Only once the flush can see the state it is to ship from.
1069
+ if (wentBack && running && (after || every)) scheduleFlush();
1070
+ }
1071
+ };
1072
+
826
1073
  const start = async () => {
827
1074
  if (running) return;
828
1075
  running = true;
@@ -853,13 +1100,25 @@ export function createLiveBackup({
853
1100
  base: state.base,
854
1101
  previous: state.previous,
855
1102
  pending,
1103
+ unconfirmed: (state.unconfirmed ?? []).length,
1104
+ keptSequence: state.kept?.sequence ?? null,
856
1105
  watched: watched.size,
857
1106
  lastShipped,
858
1107
  lastError,
859
1108
  failures,
860
1109
  });
861
1110
 
862
- return { watch, unwatch, start, stop, close, flush, rebase, status };
1111
+ return {
1112
+ watch,
1113
+ unwatch,
1114
+ start,
1115
+ stop,
1116
+ close,
1117
+ flush,
1118
+ rebase,
1119
+ reconcile,
1120
+ status,
1121
+ };
863
1122
  }
864
1123
 
865
1124
  export default createLiveBackup;
package/lib/peer-fetch.js CHANGED
@@ -99,27 +99,42 @@ export const PINATA_BITSWAP =
99
99
  * whatever address this constant holds. See `offNetworkRisk` in the
100
100
  * webrtc-qr package for how differently browsers report that.
101
101
  *
102
- * What is below is what the routing announced on 2026-10-29. The two
103
- * `/dns6/…libp2p.direct/tcp/4001/tls/ws` addresses carry no certificate hash
104
- * and so do not rot when the node restarts; the `webrtc-direct` ones do.
105
- * `test/peer-fetch-live.test.js` checks the peer id against the routing, which
106
- * is how this gets noticed next time rather than in a demo six weeks later.
102
+ * - **There is more than one node, and the routing names one at a time.**
103
+ * On 2026-11-11 it answered `12D3KooWACE5…` again, for six fresh blobs in a
104
+ * row — now over IPv4 (`46.255.204.211`), with a `/dns4/…libp2p.direct`
105
+ * name — while `12D3KooWJBw9…` (IPv6 only) was what it said two weeks
106
+ * earlier. So this constant holds both, the one the routing names now
107
+ * first; a dial to the other costs a failed attempt, not a wrong answer.
108
+ *
109
+ * The `/dns4/` and `/dns6/…libp2p.direct/tcp/4001/tls/ws` addresses carry no
110
+ * certificate hash and so do not rot when a node restarts; the
111
+ * `webrtc-direct` ones do. `test/peer-fetch-live.test.js` checks, every day in
112
+ * the live smoke test, that the routing names one of {@link ALEPH_PEER_IDS},
113
+ * which is how this gets noticed next time rather than in a demo six weeks
114
+ * later.
107
115
  */
116
+ const ACE5 = "12D3KooWACE5dRw5V9WXuDTcngjE3ZaDSZ4qYJGfuhXZbENnL54y";
117
+ const JBW9 = "12D3KooWJBw9CSUWQi7P7amZsjrsBAzoB2gJzyUUGkuBkdLc87co";
118
+
108
119
  export const ALEPH_BITSWAP = Object.freeze([
109
- "/dns6/2a01-240-ad00-0-a81e-30ff-fe24-e1c8.k51qzi5uqu5dja77dpum225l7jiqrxsfjg2cflzyewf8ixq3r7dmcku10s6l5o.libp2p.direct/tcp/4001/tls/ws/p2p/12D3KooWJBw9CSUWQi7P7amZsjrsBAzoB2gJzyUUGkuBkdLc87co",
110
- "/dns6/2a01-240-ad00-2-a81e-30ff-fe24-e1c8.k51qzi5uqu5dja77dpum225l7jiqrxsfjg2cflzyewf8ixq3r7dmcku10s6l5o.libp2p.direct/tcp/4001/tls/ws/p2p/12D3KooWJBw9CSUWQi7P7amZsjrsBAzoB2gJzyUUGkuBkdLc87co",
111
- "/ip6/2a01:240:ad00:0:a81e:30ff:fe24:e1c8/udp/4001/webrtc-direct/certhash/uEiBshqkW727Q236d7ivxBGMuc0E9Tsj3FZJMKJJgDuP4Lg/p2p/12D3KooWJBw9CSUWQi7P7amZsjrsBAzoB2gJzyUUGkuBkdLc87co",
112
- "/ip6/2a01:240:ad00:2:a81e:30ff:fe24:e1c8/udp/4001/webrtc-direct/certhash/uEiBshqkW727Q236d7ivxBGMuc0E9Tsj3FZJMKJJgDuP4Lg/p2p/12D3KooWJBw9CSUWQi7P7amZsjrsBAzoB2gJzyUUGkuBkdLc87co",
120
+ // What the routing announced on 2026-11-11.
121
+ `/dns4/46-255-204-211.k51qzi5uqu5dgbm3weyum8p0k8k4a97eea0fkepym4bhy1g862d5av7yezl2fy.libp2p.direct/tcp/4001/tls/ws/p2p/${ACE5}`,
122
+ `/ip4/46.255.204.211/udp/4001/webrtc-direct/certhash/uEiCbM9yMfnP02vviIL26n8bI0-vU0DGUHx20POBLKGjEmg/p2p/${ACE5}`,
123
+ // What it announced on 2026-10-29.
124
+ `/dns6/2a01-240-ad00-0-a81e-30ff-fe24-e1c8.k51qzi5uqu5dja77dpum225l7jiqrxsfjg2cflzyewf8ixq3r7dmcku10s6l5o.libp2p.direct/tcp/4001/tls/ws/p2p/${JBW9}`,
125
+ `/dns6/2a01-240-ad00-2-a81e-30ff-fe24-e1c8.k51qzi5uqu5dja77dpum225l7jiqrxsfjg2cflzyewf8ixq3r7dmcku10s6l5o.libp2p.direct/tcp/4001/tls/ws/p2p/${JBW9}`,
126
+ `/ip6/2a01:240:ad00:0:a81e:30ff:fe24:e1c8/udp/4001/webrtc-direct/certhash/uEiBshqkW727Q236d7ivxBGMuc0E9Tsj3FZJMKJJgDuP4Lg/p2p/${JBW9}`,
127
+ `/ip6/2a01:240:ad00:2:a81e:30ff:fe24:e1c8/udp/4001/webrtc-direct/certhash/uEiBshqkW727Q236d7ivxBGMuc0E9Tsj3FZJMKJJgDuP4Lg/p2p/${JBW9}`,
113
128
  ]);
114
129
 
115
130
  /**
116
- * Aleph's peer id, as announced on 2026-10-29.
117
- *
118
- * Not the stable part: it changed once already, which is what made every
119
- * address above dead until this commit.
131
+ * Aleph's peer ids, the one the routing named most recently (2026-11-11)
132
+ * first. Not the stable part: the routing has switched between them.
120
133
  */
121
- export const ALEPH_PEER_ID =
122
- "12D3KooWJBw9CSUWQi7P7amZsjrsBAzoB2gJzyUUGkuBkdLc87co";
134
+ export const ALEPH_PEER_IDS = Object.freeze([ACE5, JBW9]);
135
+
136
+ /** The first of {@link ALEPH_PEER_IDS}: the node the routing named last. */
137
+ export const ALEPH_PEER_ID = ACE5;
123
138
 
124
139
  /**
125
140
  * Routers that answer a page.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/orbitdb-storage-bridge",
3
- "version": "0.27.2",
3
+ "version": "0.28.1",
4
4
  "description": "Back up, restore and replicate OrbitDB databases through pluggable storage backends, with hash and identity preservation",
5
5
  "main": "lib/orbitdb-storacha-bridge.js",
6
6
  "type": "module",
@@ -119,6 +119,8 @@
119
119
  "@jest/globals": "^30.5.1",
120
120
  "@le-space/ucanto-principal": "^9.1.1",
121
121
  "@libp2p/websockets": "^10.1.17",
122
+ "@noble/curves": "^1.9.7",
123
+ "@noble/hashes": "^1.8.0",
122
124
  "@orbitdb/identity-provider-did": "^1.0.2",
123
125
  "@storacha/capabilities": "^2.0.0",
124
126
  "@storacha/client": "^2.0.0",