@solarpunkltd/swarm-id 0.0.0-stage → 0.8.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.
Files changed (111) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +89 -2
  3. package/dist/bus/account-bus.d.ts +104 -0
  4. package/dist/bus/account-delta.d.ts +52 -0
  5. package/dist/bus/bus-context.d.ts +7 -0
  6. package/dist/bus/envelope.d.ts +9 -0
  7. package/dist/bus/messages.d.ts +241 -0
  8. package/dist/bus/presence.d.ts +62 -0
  9. package/dist/bus/signaling-transport.d.ts +79 -0
  10. package/dist/chunk/bmt.d.ts +16 -0
  11. package/dist/chunk/cac.d.ts +17 -0
  12. package/dist/chunk/constants.d.ts +10 -0
  13. package/dist/chunk/encrypted-cac.d.ts +47 -0
  14. package/dist/chunk/encryption.d.ts +85 -0
  15. package/dist/chunk/index.d.ts +5 -0
  16. package/dist/chunks/chat-binding-DO5aGhPl.js +23 -0
  17. package/dist/chunks/chat-binding-DO5aGhPl.js.map +1 -0
  18. package/dist/errors.d.ts +35 -0
  19. package/dist/index.d.ts +27 -0
  20. package/dist/internal.d.ts +49 -0
  21. package/dist/internal.esm.js +2 -0
  22. package/dist/internal.esm.js.map +1 -0
  23. package/dist/proxy/act/act.d.ts +58 -0
  24. package/dist/proxy/act/crypto.d.ts +46 -0
  25. package/dist/proxy/act/grantee-list.d.ts +81 -0
  26. package/dist/proxy/act/history.d.ts +182 -0
  27. package/dist/proxy/act/index.d.ts +114 -0
  28. package/dist/proxy/app-stamp-limits.d.ts +62 -0
  29. package/dist/proxy/chunk-upload-stream.d.ts +37 -0
  30. package/dist/proxy/chunking.d.ts +15 -0
  31. package/dist/proxy/collection.d.ts +38 -0
  32. package/dist/proxy/download-data.d.ts +27 -0
  33. package/dist/proxy/errors.d.ts +8 -0
  34. package/dist/proxy/feed-manifest.d.ts +60 -0
  35. package/dist/proxy/feeds/epochs/async-finder.d.ts +70 -0
  36. package/dist/proxy/feeds/epochs/epoch.d.ts +79 -0
  37. package/dist/proxy/feeds/epochs/finder.d.ts +60 -0
  38. package/dist/proxy/feeds/epochs/index.d.ts +30 -0
  39. package/dist/proxy/feeds/epochs/types.d.ts +110 -0
  40. package/dist/proxy/feeds/epochs/updater.d.ts +76 -0
  41. package/dist/proxy/feeds/epochs/utils.d.ts +21 -0
  42. package/dist/proxy/feeds/index.d.ts +4 -0
  43. package/dist/proxy/feeds/sequence/async-finder.d.ts +14 -0
  44. package/dist/proxy/feeds/sequence/finder.d.ts +11 -0
  45. package/dist/proxy/feeds/sequence/index.d.ts +22 -0
  46. package/dist/proxy/feeds/sequence/types.d.ts +82 -0
  47. package/dist/proxy/feeds/sequence/updater.d.ts +20 -0
  48. package/dist/proxy/index.d.ts +5 -0
  49. package/dist/proxy/manifest-builder.d.ts +164 -0
  50. package/dist/proxy/mantaray.d.ts +76 -0
  51. package/dist/proxy/soc-restamp-slots.d.ts +48 -0
  52. package/dist/proxy/stamp-chunk.d.ts +45 -0
  53. package/dist/proxy/stamp-worker-handler.d.ts +32 -0
  54. package/dist/proxy/stamp-worker-pool.d.ts +52 -0
  55. package/dist/proxy/stamp-worker.d.ts +1 -0
  56. package/dist/proxy/types.d.ts +38 -0
  57. package/dist/proxy/upload.d.ts +207 -0
  58. package/dist/schemas.d.ts +671 -0
  59. package/dist/stamp-worker.iife.js +1 -0
  60. package/dist/storage/debounced-uploader.d.ts +61 -0
  61. package/dist/storage/utilization-store.d.ts +113 -0
  62. package/dist/swarm-id-client.d.ts +1143 -0
  63. package/dist/swarm-id-proxy.d.ts +1079 -0
  64. package/dist/swarm-id.esm.js +2 -0
  65. package/dist/swarm-id.esm.js.map +1 -0
  66. package/dist/sync/batch-write-coordinator.d.ts +348 -0
  67. package/dist/sync/device-roster.d.ts +59 -0
  68. package/dist/sync/device-state.d.ts +199 -0
  69. package/dist/sync/fold-account-from-swarm.d.ts +53 -0
  70. package/dist/sync/index.d.ts +11 -0
  71. package/dist/sync/merge-snapshot.d.ts +57 -0
  72. package/dist/sync/partition-intent.d.ts +218 -0
  73. package/dist/sync/partition-lease.d.ts +531 -0
  74. package/dist/sync/partition-lock.d.ts +218 -0
  75. package/dist/sync/partition-state.d.ts +287 -0
  76. package/dist/sync/session-check.d.ts +29 -0
  77. package/dist/sync/store-interfaces.d.ts +48 -0
  78. package/dist/sync/sync-account.d.ts +45 -0
  79. package/dist/sync/timing-constants.d.ts +32 -0
  80. package/dist/sync/types.d.ts +18 -0
  81. package/dist/types.d.ts +3042 -0
  82. package/dist/utils/account-state-snapshot.d.ts +43 -0
  83. package/dist/utils/active-devices.d.ts +45 -0
  84. package/dist/utils/avatar.d.ts +30 -0
  85. package/dist/utils/batch-utilization.d.ts +840 -0
  86. package/dist/utils/batch-write-lock.d.ts +12 -0
  87. package/dist/utils/bee-error.d.ts +11 -0
  88. package/dist/utils/chat-binding.d.ts +113 -0
  89. package/dist/utils/coalesced-task.d.ts +28 -0
  90. package/dist/utils/collection.d.ts +6 -0
  91. package/dist/utils/connection-info.d.ts +11 -0
  92. package/dist/utils/constants.d.ts +28 -0
  93. package/dist/utils/device-id.d.ts +109 -0
  94. package/dist/utils/hex.d.ts +31 -0
  95. package/dist/utils/json-rpc.d.ts +34 -0
  96. package/dist/utils/key-derivation.d.ts +124 -0
  97. package/dist/utils/lock-soc.d.ts +35 -0
  98. package/dist/utils/postage-contract.d.ts +143 -0
  99. package/dist/utils/postage-stamp-association.d.ts +39 -0
  100. package/dist/utils/promise.d.ts +37 -0
  101. package/dist/utils/sealed-values.d.ts +23 -0
  102. package/dist/utils/seed-encryption.d.ts +17 -0
  103. package/dist/utils/site-allow-list.d.ts +54 -0
  104. package/dist/utils/stamp-lifespan.d.ts +37 -0
  105. package/dist/utils/storage-managers.d.ts +62 -0
  106. package/dist/utils/storage-probe.d.ts +40 -0
  107. package/dist/utils/tag.d.ts +11 -0
  108. package/dist/utils/ttl.d.ts +120 -0
  109. package/dist/utils/url.d.ts +55 -0
  110. package/dist/utils/versioned-storage.d.ts +183 -0
  111. package/package.json +91 -3
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Account State Snapshot Module
3
+ *
4
+ * The in-memory account-state snapshot: what sync captures before building a
5
+ * device view, and what the account bus carries as an `account-delta`.
6
+ * `serializeAccountStateSnapshot` is the delta's wire form; the receiver
7
+ * validates it with `AccountStateSnapshotSchemaV1` (`bus/messages.ts`).
8
+ */
9
+ import type { ConnectedApp, PostageStamp, AccountMetadata, AccountStateSnapshot, SyncedAccount } from "../schemas";
10
+ export type { AccountStateSnapshot } from "../schemas";
11
+ /**
12
+ * The account record as an account-state snapshot — the ONE assembly every
13
+ * publisher shares (the sync coordinator's feed write, the proxy's feed write,
14
+ * the proxy's `account-delta`, and the fold that consumes one).
15
+ *
16
+ * `timestamp` is the caller's clock for this snapshot, used for both the
17
+ * envelope and `metadata.lastModified`: a publisher passes `Date.now()`, a
18
+ * caller re-reading a record it did not just change passes that record's own
19
+ * `lastModified` rather than restamping it.
20
+ *
21
+ * Every never-edited scalar clock falls back to the account's STABLE
22
+ * `createdAt`, NEVER a fresh `Date.now()`: re-stamping an unchanged name /
23
+ * default-stamp / settings on every publish would let a device that never
24
+ * touched the field clobber a peer's genuine concurrent edit under per-field
25
+ * LWW (docs/Account-State.md, "Convergence rules"). `createdAt` is identical
26
+ * across devices and predates every edit,
27
+ * so any real change still wins.
28
+ *
29
+ * `defaultPostageStampBatchID` may be absent: an account with no drives is a
30
+ * supported state, and only the feed write (which needs a stamp to pay for
31
+ * itself) may treat that as a reason not to publish.
32
+ */
33
+ export declare function accountToStateSnapshot(account: SyncedAccount, accountId: string, timestamp: number): AccountStateSnapshot;
34
+ /**
35
+ * Serialize account data into a plain object suitable for JSON encoding.
36
+ */
37
+ export declare function serializeAccountStateSnapshot(input: {
38
+ accountId: string;
39
+ metadata: AccountMetadata;
40
+ connectedApps: ConnectedApp[];
41
+ postageStamps: PostageStamp[];
42
+ timestamp: number;
43
+ }): Record<string, unknown>;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The registry half of the partition-contention rival set: devices that
3
+ * signed in recently enough to plausibly be acquiring RIGHT NOW.
4
+ *
5
+ * The other half is the account bus. A device beating `presence` in the room
6
+ * (`bus/presence.ts`) is alive by construction, and every caller unions that
7
+ * set with this one; this filter is the bootstrap for a context with no bus,
8
+ * and for a device that signed in moments ago and has not beaten yet.
9
+ *
10
+ * The intent round reads every known device's per-device intent address to
11
+ * deconflict simultaneous fresh claims. If that set is "all devices the account
12
+ * ever saw", long-dead devices (ghosts from old sessions — the device list is
13
+ * append-only and never pruned) each add an absent network read to every
14
+ * acquire; on a flaky gateway that cost can push a single acquire past its
15
+ * timeout, so a live device can't even claim a FREE partition. A non-active
16
+ * device must not be able to influence an active one.
17
+ *
18
+ * Filtering by `lastSignedInAt` recency is SAFE (not a correctness mechanism)
19
+ * because the deviceId-INDEPENDENT occupancy beacon, which is NOT gated on this
20
+ * set, is the real dual-acquire backstop for a live peer that this prune drops:
21
+ * - `PartitionLease.refreshHoldersFromOccupancy` (in `acquire`) catches a peer
22
+ * that already HOLDS a partition; and
23
+ * - `PartitionLease.occupancyBeaconBeatsUs` (in `refresh`) resolves a symmetric
24
+ * fresh-claim dual-acquire with such a peer.
25
+ * `lastSignedInAt` advances only on an actual SIGN-IN (a creation or a
26
+ * reactivation), never on a poll (#652) — so a long-running device IS pruned
27
+ * from THIS half after the window; the bus half is what keeps it a rival, and
28
+ * the occupancy channel is what keeps that safe. Pruning only removes the
29
+ * per-acquire absent-read cost of dead ghosts.
30
+ */
31
+ import type { Device } from "../schemas";
32
+ /**
33
+ * How recently a device must have signed in to count as a contention rival
34
+ * without a bus beat. The stamp is frozen at sign-in (#652), so this bounds the
35
+ * age of the SESSION, not any publish cadence: long enough that a device which
36
+ * just signed in is a rival through its first acquires, far below a prior
37
+ * session, so stale ghosts are dropped. A live device past the window stays a
38
+ * rival through the bus half, not this one.
39
+ */
40
+ export declare const KNOWN_DEVICE_MAX_AGE_MS: number;
41
+ /**
42
+ * Device ids that are (a) not removed and (b) signed in within `maxAgeMs` of
43
+ * `nowMs`. A missing `lastSignedInAt` counts as stale.
44
+ */
45
+ export declare function activeDeviceIds(devices: Device[], nowMs: number, maxAgeMs: number): string[];
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Account avatars. Every account has one generated from its id, which
3
+ * {@link Avatar.source} reports — leaving room for another kind of image
4
+ * should one ever be added.
5
+ *
6
+ * The generator is Polycon by Christian Montoya
7
+ * (https://github.com/Montoya/polycon). Original algorithm: SDBM hash → 2×2
8
+ * grid of triangles/squares with color pairs. Adapted here with a custom brand
9
+ * color palette.
10
+ */
11
+ import type { Avatar } from "../types";
12
+ /**
13
+ * Render an account's generated avatar as a standalone SVG string.
14
+ *
15
+ * The same seed always yields the same image, so a dApp passing the identity
16
+ * id from `ConnectionInfo` renders exactly the avatar Swarm ID shows for that
17
+ * account. Prefer `SwarmIdClient.getAvatar()`, which falls back to this only
18
+ * while the account has no avatar of its own.
19
+ *
20
+ * @param seed - Value the avatar is derived from (e.g. `connectionInfo.identity.id`)
21
+ * @param size - Width and height in pixels
22
+ */
23
+ export declare function generatedAvatarSvg(seed: string, size?: number): string;
24
+ /**
25
+ * The generated avatar for `seed` as a renderable {@link Avatar}.
26
+ *
27
+ * @param seed - Value the avatar is derived from (e.g. `connectionInfo.identity.id`)
28
+ * @param size - Width and height in pixels
29
+ */
30
+ export declare function generatedAvatar(seed: string, size?: number): Avatar;