@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.
- package/LICENSE +202 -0
- package/README.md +89 -2
- package/dist/bus/account-bus.d.ts +104 -0
- package/dist/bus/account-delta.d.ts +52 -0
- package/dist/bus/bus-context.d.ts +7 -0
- package/dist/bus/envelope.d.ts +9 -0
- package/dist/bus/messages.d.ts +241 -0
- package/dist/bus/presence.d.ts +62 -0
- package/dist/bus/signaling-transport.d.ts +79 -0
- package/dist/chunk/bmt.d.ts +16 -0
- package/dist/chunk/cac.d.ts +17 -0
- package/dist/chunk/constants.d.ts +10 -0
- package/dist/chunk/encrypted-cac.d.ts +47 -0
- package/dist/chunk/encryption.d.ts +85 -0
- package/dist/chunk/index.d.ts +5 -0
- package/dist/chunks/chat-binding-DO5aGhPl.js +23 -0
- package/dist/chunks/chat-binding-DO5aGhPl.js.map +1 -0
- package/dist/errors.d.ts +35 -0
- package/dist/index.d.ts +27 -0
- package/dist/internal.d.ts +49 -0
- package/dist/internal.esm.js +2 -0
- package/dist/internal.esm.js.map +1 -0
- package/dist/proxy/act/act.d.ts +58 -0
- package/dist/proxy/act/crypto.d.ts +46 -0
- package/dist/proxy/act/grantee-list.d.ts +81 -0
- package/dist/proxy/act/history.d.ts +182 -0
- package/dist/proxy/act/index.d.ts +114 -0
- package/dist/proxy/app-stamp-limits.d.ts +62 -0
- package/dist/proxy/chunk-upload-stream.d.ts +37 -0
- package/dist/proxy/chunking.d.ts +15 -0
- package/dist/proxy/collection.d.ts +38 -0
- package/dist/proxy/download-data.d.ts +27 -0
- package/dist/proxy/errors.d.ts +8 -0
- package/dist/proxy/feed-manifest.d.ts +60 -0
- package/dist/proxy/feeds/epochs/async-finder.d.ts +70 -0
- package/dist/proxy/feeds/epochs/epoch.d.ts +79 -0
- package/dist/proxy/feeds/epochs/finder.d.ts +60 -0
- package/dist/proxy/feeds/epochs/index.d.ts +30 -0
- package/dist/proxy/feeds/epochs/types.d.ts +110 -0
- package/dist/proxy/feeds/epochs/updater.d.ts +76 -0
- package/dist/proxy/feeds/epochs/utils.d.ts +21 -0
- package/dist/proxy/feeds/index.d.ts +4 -0
- package/dist/proxy/feeds/sequence/async-finder.d.ts +14 -0
- package/dist/proxy/feeds/sequence/finder.d.ts +11 -0
- package/dist/proxy/feeds/sequence/index.d.ts +22 -0
- package/dist/proxy/feeds/sequence/types.d.ts +82 -0
- package/dist/proxy/feeds/sequence/updater.d.ts +20 -0
- package/dist/proxy/index.d.ts +5 -0
- package/dist/proxy/manifest-builder.d.ts +164 -0
- package/dist/proxy/mantaray.d.ts +76 -0
- package/dist/proxy/soc-restamp-slots.d.ts +48 -0
- package/dist/proxy/stamp-chunk.d.ts +45 -0
- package/dist/proxy/stamp-worker-handler.d.ts +32 -0
- package/dist/proxy/stamp-worker-pool.d.ts +52 -0
- package/dist/proxy/stamp-worker.d.ts +1 -0
- package/dist/proxy/types.d.ts +38 -0
- package/dist/proxy/upload.d.ts +207 -0
- package/dist/schemas.d.ts +671 -0
- package/dist/stamp-worker.iife.js +1 -0
- package/dist/storage/debounced-uploader.d.ts +61 -0
- package/dist/storage/utilization-store.d.ts +113 -0
- package/dist/swarm-id-client.d.ts +1143 -0
- package/dist/swarm-id-proxy.d.ts +1079 -0
- package/dist/swarm-id.esm.js +2 -0
- package/dist/swarm-id.esm.js.map +1 -0
- package/dist/sync/batch-write-coordinator.d.ts +348 -0
- package/dist/sync/device-roster.d.ts +59 -0
- package/dist/sync/device-state.d.ts +199 -0
- package/dist/sync/fold-account-from-swarm.d.ts +53 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/merge-snapshot.d.ts +57 -0
- package/dist/sync/partition-intent.d.ts +218 -0
- package/dist/sync/partition-lease.d.ts +531 -0
- package/dist/sync/partition-lock.d.ts +218 -0
- package/dist/sync/partition-state.d.ts +287 -0
- package/dist/sync/session-check.d.ts +29 -0
- package/dist/sync/store-interfaces.d.ts +48 -0
- package/dist/sync/sync-account.d.ts +45 -0
- package/dist/sync/timing-constants.d.ts +32 -0
- package/dist/sync/types.d.ts +18 -0
- package/dist/types.d.ts +3042 -0
- package/dist/utils/account-state-snapshot.d.ts +43 -0
- package/dist/utils/active-devices.d.ts +45 -0
- package/dist/utils/avatar.d.ts +30 -0
- package/dist/utils/batch-utilization.d.ts +840 -0
- package/dist/utils/batch-write-lock.d.ts +12 -0
- package/dist/utils/bee-error.d.ts +11 -0
- package/dist/utils/chat-binding.d.ts +113 -0
- package/dist/utils/coalesced-task.d.ts +28 -0
- package/dist/utils/collection.d.ts +6 -0
- package/dist/utils/connection-info.d.ts +11 -0
- package/dist/utils/constants.d.ts +28 -0
- package/dist/utils/device-id.d.ts +109 -0
- package/dist/utils/hex.d.ts +31 -0
- package/dist/utils/json-rpc.d.ts +34 -0
- package/dist/utils/key-derivation.d.ts +124 -0
- package/dist/utils/lock-soc.d.ts +35 -0
- package/dist/utils/postage-contract.d.ts +143 -0
- package/dist/utils/postage-stamp-association.d.ts +39 -0
- package/dist/utils/promise.d.ts +37 -0
- package/dist/utils/sealed-values.d.ts +23 -0
- package/dist/utils/seed-encryption.d.ts +17 -0
- package/dist/utils/site-allow-list.d.ts +54 -0
- package/dist/utils/stamp-lifespan.d.ts +37 -0
- package/dist/utils/storage-managers.d.ts +62 -0
- package/dist/utils/storage-probe.d.ts +40 -0
- package/dist/utils/tag.d.ts +11 -0
- package/dist/utils/ttl.d.ts +120 -0
- package/dist/utils/url.d.ts +55 -0
- package/dist/utils/versioned-storage.d.ts +183 -0
- package/package.json +91 -3
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Versioned Storage Utility
|
|
3
|
+
*
|
|
4
|
+
* Provides a framework-agnostic way to store and retrieve versioned data
|
|
5
|
+
* with automatic migration support.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
/**
|
|
9
|
+
* Versioned storage wrapper schema
|
|
10
|
+
* Used to check if data is in versioned format
|
|
11
|
+
*/
|
|
12
|
+
export declare const VersionedStorageSchema: z.ZodObject<{
|
|
13
|
+
version: z.ZodNumber;
|
|
14
|
+
data: z.ZodUnknown;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export type VersionedStorage = z.infer<typeof VersionedStorageSchema>;
|
|
17
|
+
/**
|
|
18
|
+
* Storage adapter interface - allows different storage backends
|
|
19
|
+
*/
|
|
20
|
+
export interface StorageAdapter {
|
|
21
|
+
getItem(key: string): string | undefined;
|
|
22
|
+
setItem(key: string, value: string): void;
|
|
23
|
+
removeItem(key: string): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Version parser function - handles migration from one version to another
|
|
27
|
+
*/
|
|
28
|
+
export type VersionParser<T> = (data: unknown, version: number) => T[];
|
|
29
|
+
/**
|
|
30
|
+
* Serializer function - converts data to JSON-serializable format
|
|
31
|
+
*/
|
|
32
|
+
export type Serializer<T> = (data: T) => Record<string, unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* What a listener learns about a write besides the data. `noRepublish` is set
|
|
35
|
+
* by a writer for a change peers must not hear about: one it folded from a
|
|
36
|
+
* peer (a bus delta, a Swarm fold), a volatile field nobody else needs, or a
|
|
37
|
+
* device-local sign-out. Another instance in the same window must not publish
|
|
38
|
+
* that write to the room (#707). Absent for a write from another window,
|
|
39
|
+
* whose origin the `storage` event cannot carry.
|
|
40
|
+
*/
|
|
41
|
+
export interface StorageChange {
|
|
42
|
+
noRepublish: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** Listener for storage change events, from other windows or this one. */
|
|
45
|
+
export type StorageChangeListener<T> = (data: T[], change?: StorageChange) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Encryption of fields inside the stored records. Sealing is asynchronous and
|
|
48
|
+
* reading storage is not, so `prime` opens what is stored into memory and
|
|
49
|
+
* `open` then reads it synchronously. What `prime` could not open, `open`
|
|
50
|
+
* treats as absent. `seal` is handed what is stored at the time of the write,
|
|
51
|
+
* so it can keep a stored record this page could not read.
|
|
52
|
+
*/
|
|
53
|
+
export interface RecordSealing {
|
|
54
|
+
seal(records: Record<string, unknown>[], stored: unknown): Promise<Record<string, unknown>[]>;
|
|
55
|
+
open(data: unknown): unknown;
|
|
56
|
+
prime(data: unknown): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Options for versioned storage
|
|
60
|
+
*/
|
|
61
|
+
export interface VersionedStorageOptions<T> {
|
|
62
|
+
/** Storage key */
|
|
63
|
+
key: string;
|
|
64
|
+
/** Current version number */
|
|
65
|
+
currentVersion: number;
|
|
66
|
+
/** Storage adapter (e.g., localStorage) */
|
|
67
|
+
storage: StorageAdapter;
|
|
68
|
+
/** Version parsers - map of version to parser function */
|
|
69
|
+
parsers: Record<number, VersionParser<T>>;
|
|
70
|
+
/** Optional serializer for complex types */
|
|
71
|
+
serializer?: Serializer<T>;
|
|
72
|
+
/** Logger name for error messages */
|
|
73
|
+
loggerName?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Seals fields of every record on write. With it, writes are asynchronous
|
|
76
|
+
* and queued per key in this window, a load reads only what `prime` opened,
|
|
77
|
+
* and listeners hear of a change once it is primed.
|
|
78
|
+
*/
|
|
79
|
+
sealing?: RecordSealing;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* LocalStorage adapter for browser environments
|
|
83
|
+
*/
|
|
84
|
+
export declare class LocalStorageAdapter implements StorageAdapter {
|
|
85
|
+
getItem(key: string): string | undefined;
|
|
86
|
+
setItem(key: string, value: string): void;
|
|
87
|
+
removeItem(key: string): void;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* In-memory storage adapter (for testing or non-browser environments)
|
|
91
|
+
*/
|
|
92
|
+
export declare class MemoryStorageAdapter implements StorageAdapter {
|
|
93
|
+
private storage;
|
|
94
|
+
getItem(key: string): string | undefined;
|
|
95
|
+
setItem(key: string, value: string): void;
|
|
96
|
+
removeItem(key: string): void;
|
|
97
|
+
clear(): void;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Generic versioned storage manager
|
|
101
|
+
*/
|
|
102
|
+
export declare class VersionedStorageManager<T> {
|
|
103
|
+
private options;
|
|
104
|
+
private listeners;
|
|
105
|
+
private boundStorageHandler;
|
|
106
|
+
private boundSameWindowHandler;
|
|
107
|
+
constructor(options: VersionedStorageOptions<T>);
|
|
108
|
+
/**
|
|
109
|
+
* Subscribe to writes to this key that this instance did not make: other
|
|
110
|
+
* windows' through the browser's `storage` event, and other manager
|
|
111
|
+
* instances' in THIS window through the `swarm-id-storage-write` event that
|
|
112
|
+
* `save()` and `clear()` dispatch — the `storage` event never fires in the
|
|
113
|
+
* window that wrote. This instance's own writes are skipped.
|
|
114
|
+
*
|
|
115
|
+
* @param listener - Callback function that receives the updated data
|
|
116
|
+
* @returns Unsubscribe function to remove the listener
|
|
117
|
+
*/
|
|
118
|
+
subscribe(listener: StorageChangeListener<T>): () => void;
|
|
119
|
+
/**
|
|
120
|
+
* Set up the browser storage event listener
|
|
121
|
+
* Only listens for changes to this manager's specific key
|
|
122
|
+
*/
|
|
123
|
+
private setupStorageEventListener;
|
|
124
|
+
/**
|
|
125
|
+
* Clean up the storage event listener when no more subscribers
|
|
126
|
+
*/
|
|
127
|
+
private cleanupStorageEventListener;
|
|
128
|
+
/**
|
|
129
|
+
* Broadcast a write to other manager instances in this window.
|
|
130
|
+
*/
|
|
131
|
+
private notifySameWindow;
|
|
132
|
+
private reloadAndNotify;
|
|
133
|
+
/**
|
|
134
|
+
* Notify all listeners of data changes
|
|
135
|
+
*/
|
|
136
|
+
private notifyListeners;
|
|
137
|
+
/**
|
|
138
|
+
* Load data from storage
|
|
139
|
+
*/
|
|
140
|
+
load(): T[];
|
|
141
|
+
/**
|
|
142
|
+
* Parse versioned data and migrate if needed
|
|
143
|
+
*/
|
|
144
|
+
private parse;
|
|
145
|
+
/**
|
|
146
|
+
* Open the sealed fields of what is stored into memory, so `load` can read
|
|
147
|
+
* them. A no-op without sealing.
|
|
148
|
+
*/
|
|
149
|
+
prime(): Promise<void>;
|
|
150
|
+
/** The records as stored, still sealed, or `undefined` when there are none. */
|
|
151
|
+
private storedData;
|
|
152
|
+
/**
|
|
153
|
+
* Save data to storage. Resolves once written, which with sealing is after
|
|
154
|
+
* every earlier write to this key in this window. With sealing a write that
|
|
155
|
+
* fails rejects, so the caller can tell the person. Without it the failure
|
|
156
|
+
* is only logged.
|
|
157
|
+
*/
|
|
158
|
+
save(data: T[], options?: {
|
|
159
|
+
noRepublish?: boolean;
|
|
160
|
+
}): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* Read, change and write back as one step: the change sees what is stored
|
|
163
|
+
* when its turn comes, after every earlier write to this key in this window.
|
|
164
|
+
* A change that returns `undefined` writes nothing. Rejects when the write
|
|
165
|
+
* fails.
|
|
166
|
+
*/
|
|
167
|
+
update(mutate: (stored: T[]) => T[] | undefined, options?: {
|
|
168
|
+
noRepublish?: boolean;
|
|
169
|
+
}): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Clear data from storage
|
|
172
|
+
*/
|
|
173
|
+
clear(): Promise<void>;
|
|
174
|
+
private serialize;
|
|
175
|
+
private seal;
|
|
176
|
+
private write;
|
|
177
|
+
/** The returned turn rejects on failure. The queue moves on regardless. */
|
|
178
|
+
private enqueue;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Create a versioned storage manager with localStorage
|
|
182
|
+
*/
|
|
183
|
+
export declare function createLocalStorageManager<T>(options: Omit<VersionedStorageOptions<T>, "storage">): VersionedStorageManager<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,94 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solarpunkltd/swarm-id",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.8.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Swarm ID library for authentication and Bee API operations",
|
|
6
|
+
"main": "dist/swarm-id.esm.js",
|
|
7
|
+
"module": "dist/swarm-id.esm.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/swarm-id.esm.js"
|
|
13
|
+
},
|
|
14
|
+
"./internal": {
|
|
15
|
+
"types": "./dist/internal.d.ts",
|
|
16
|
+
"import": "./dist/internal.esm.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"swarm",
|
|
24
|
+
"identity",
|
|
25
|
+
"authentication",
|
|
26
|
+
"bee",
|
|
27
|
+
"web3"
|
|
28
|
+
],
|
|
29
|
+
"author": "Solar Punk, based on Swarm ID by snaha",
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/Solar-Punk-Ltd/solarpunk-id.git",
|
|
34
|
+
"directory": "lib"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/Solar-Punk-Ltd/solarpunk-id/tree/main/lib#readme",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/Solar-Punk-Ltd/solarpunk-id/issues"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@ethersphere/bee-js": "^13.0.0",
|
|
42
|
+
"@ethersphere/core-sdk": "^0.1.1",
|
|
43
|
+
"@noble/curves": "1.2.0",
|
|
44
|
+
"@noble/hashes": "1.3.2",
|
|
45
|
+
"cafe-utility": "34.0.0",
|
|
46
|
+
"zod": "4.1.13"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@rollup/plugin-commonjs": "29.0.0",
|
|
50
|
+
"@rollup/plugin-json": "6.1.0",
|
|
51
|
+
"@rollup/plugin-node-resolve": "16.0.3",
|
|
52
|
+
"@rollup/plugin-replace": "6.0.3",
|
|
53
|
+
"@rollup/plugin-terser": "0.4.4",
|
|
54
|
+
"@rollup/plugin-typescript": "12.3.0",
|
|
55
|
+
"@types/node": "24.10.1",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "8.69.0",
|
|
57
|
+
"@typescript-eslint/parser": "8.69.0",
|
|
58
|
+
"@vitest/ui": "^4.0.16",
|
|
59
|
+
"esbuild": "^0.28.0",
|
|
60
|
+
"eslint": "10.9.1",
|
|
61
|
+
"prettier": "3.7.3",
|
|
62
|
+
"rollup": "4.53.3",
|
|
63
|
+
"tslib": "2.8.1",
|
|
64
|
+
"typescript": "5.8.3",
|
|
65
|
+
"vitest": "4.0.14",
|
|
66
|
+
"@swarm-id/signaling": "0.1.0",
|
|
67
|
+
"@swarm-id/eslint-rules": "0.0.0"
|
|
68
|
+
},
|
|
69
|
+
"engines": {
|
|
70
|
+
"node": ">=22",
|
|
71
|
+
"pnpm": ">=11"
|
|
72
|
+
},
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public"
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "rollup -c",
|
|
78
|
+
"build:watch": "rollup -c -w",
|
|
79
|
+
"clean": "rm -rf dist",
|
|
80
|
+
"test": "vitest run",
|
|
81
|
+
"test:watch": "vitest",
|
|
82
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
83
|
+
"test:live": "vitest run --config vitest.live.config.ts",
|
|
84
|
+
"test:ui": "vitest --ui",
|
|
85
|
+
"test:coverage": "vitest run --coverage",
|
|
86
|
+
"lint": "eslint .",
|
|
87
|
+
"lint:fix": "eslint . --fix",
|
|
88
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
89
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
90
|
+
"typecheck": "tsc --noEmit -p tsconfig.check.json",
|
|
91
|
+
"check:all": "pnpm format:check && pnpm lint && pnpm typecheck && pnpm test",
|
|
92
|
+
"check:pack": "node dev/check-pack.js"
|
|
93
|
+
}
|
|
6
94
|
}
|