nostr-double-ratchet 0.0.32 → 0.0.33

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
@@ -1,11 +1,13 @@
1
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/mmalmi/nostr-double-ratchet)
2
+
1
3
  * Double ratchet on nostr
2
4
  - [x] 1-on-1 channel
3
5
  - [ ] group channel
4
6
  * Invites for securely exchanging session keys
5
7
  * Breaking changes are likely
6
8
  * Stable version on [NPM](https://www.npmjs.com/package/nostr-double-ratchet)
7
- * check out [tests](https://github.com/mmalmi/nostr-double-ratchet/tree/master/tests) for usage
8
- * [Documentation](https://nostr-double-ratchet.iris.to/)
9
+ * check out [tests](https://github.com/mmalmi/nostr-double-ratchet/tree/main/tests) for usage
10
+ * [Documentation](https://mmalmi.github.io/nostr-double-ratchet/)
9
11
  * [Source code](https://github.com/mmalmi/nostr-double-ratchet)
10
12
 
11
13
  ## Installation
package/dist/Invite.d.ts CHANGED
@@ -34,6 +34,11 @@ export declare class Invite {
34
34
  */
35
35
  getUrl(root?: string): string;
36
36
  getEvent(): UnsignedEvent;
37
+ /**
38
+ * Creates an "invite tombstone" event that clears the original content and removes the list tag.
39
+ * Used when the inviter logs out and wants to make the invite invisible to other devices.
40
+ */
41
+ getDeletionEvent(): UnsignedEvent;
37
42
  /**
38
43
  * Called by the invitee. Accepts the invite and creates a new session with the inviter.
39
44
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Invite.d.ts","sourceRoot":"","sources":["../src/Invite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,aAAa,EAAE,aAAa,EAAuB,MAAM,aAAa,CAAC;AACvI,OAAO,EAAqB,cAAc,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAwB,MAAM,SAAS,CAAC;AAEjI,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAQvC;;;;;;;;;GASG;AACH,qBAAa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MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,WAAW;IAwB1G;;OAEG;IACH,SAAS,IAAI,MAAM;IAYnB;;OAEG;IACH,MAAM,CAAC,IAAI,SAAoB;IAW/B,QAAQ,IAAI,aAAa;IAkBzB;;;OAGG;IACH,gBAAgB,IAAI,aAAa;IAiBjC;;;;;;;;;;;;;;;OAeG;IACG,MAAM,CACR,cAAc,EAAE,cAAc,EAC9B,gBAAgB,EAAE,MAAM,EACxB,SAAS,EAAE,UAAU,GAAG,eAAe,GACxC,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,aAAa,CAAA;KAAE,CAAC;IAsCtD,MAAM,CAAC,SAAS,EAAE,UAAU,GAAG,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,WAAW;CA0C3J"}
@@ -1,30 +1,71 @@
1
1
  import { Session } from './Session';
2
2
  import { NostrSubscribe } from './types';
3
+ interface DeviceRecord {
4
+ deviceId: string;
5
+ publicKey: string;
6
+ activeSession?: Session;
7
+ inactiveSessions: Session[];
8
+ isStale: boolean;
9
+ staleTimestamp?: number;
10
+ lastActivity?: number;
11
+ }
3
12
  /**
4
- * WIP: Conversation management system similar to Signal's Sesame
5
- * https://signal.org/docs/specifications/sesame/
13
+ * Manages sessions for a single user across multiple devices
14
+ * Structure: UserRecord → DeviceRecord → Sessions
6
15
  */
7
16
  export declare class UserRecord {
8
- _userId: string;
9
- private _nostrSubscribe;
17
+ readonly userId: string;
18
+ private readonly nostrSubscribe;
10
19
  private deviceRecords;
11
20
  private isStale;
12
21
  private staleTimestamp?;
13
- constructor(_userId: string, _nostrSubscribe: NostrSubscribe);
22
+ constructor(userId: string, nostrSubscribe: NostrSubscribe);
14
23
  /**
15
- * Adds or updates a device record for this user
24
+ * Creates or updates a device record for this user
16
25
  */
17
- conditionalUpdate(deviceId: string, publicKey: string): void;
26
+ upsertDevice(deviceId: string, publicKey: string): DeviceRecord;
18
27
  /**
19
- * Inserts a new session for a device, making it the active session
28
+ * Gets a device record by deviceId
20
29
  */
21
- insertSession(deviceId: string, session: Session): void;
30
+ getDevice(deviceId: string): DeviceRecord | undefined;
31
+ /**
32
+ * Gets all device records for this user
33
+ */
34
+ getAllDevices(): DeviceRecord[];
22
35
  /**
23
- * Activates an inactive session for a device
36
+ * Gets all active (non-stale) device records
24
37
  */
25
- activateSession(deviceId: string, session: Session): void;
38
+ getActiveDevices(): DeviceRecord[];
39
+ /**
40
+ * Removes a device record and closes all its sessions
41
+ */
42
+ removeDevice(deviceId: string): boolean;
43
+ /**
44
+ * Adds or updates a session for a specific device
45
+ */
46
+ upsertSession(deviceId: string, session: Session, publicKey?: string): void;
47
+ /**
48
+ * Gets the active session for a specific device
49
+ */
50
+ getActiveSession(deviceId: string): Session | undefined;
51
+ /**
52
+ * Gets all sessions (active + inactive) for a specific device
53
+ */
54
+ getDeviceSessions(deviceId: string): Session[];
55
+ /**
56
+ * Gets all active sessions across all devices for this user
57
+ */
58
+ getActiveSessions(): Session[];
59
+ /**
60
+ * Gets all sessions (active + inactive) across all devices
61
+ */
62
+ getAllSessions(): Session[];
26
63
  /**
27
- * Marks a device record as stale
64
+ * Gets sessions that are ready to send messages
65
+ */
66
+ getSendableSessions(): Session[];
67
+ /**
68
+ * Marks a specific device as stale
28
69
  */
29
70
  markDeviceStale(deviceId: string): void;
30
71
  /**
@@ -32,39 +73,45 @@ export declare class UserRecord {
32
73
  */
33
74
  markUserStale(): void;
34
75
  /**
35
- * Gets all non-stale device records with active sessions
76
+ * Removes stale devices and sessions older than maxLatency
36
77
  */
37
- getActiveDevices(): Array<[string, Session]>;
78
+ pruneStaleRecords(maxLatency: number): void;
38
79
  /**
39
- * Creates a new session for a device
80
+ * Gets the most recently active device
40
81
  */
41
- createSession(deviceId: string, sharedSecret: Uint8Array, ourCurrentPrivateKey: Uint8Array, isInitiator: boolean, name?: string): Session;
82
+ getMostActiveDevice(): DeviceRecord | undefined;
42
83
  /**
43
- * Deletes stale records that are older than maxLatency
84
+ * Gets the preferred session (from most active device)
44
85
  */
45
- pruneStaleRecords(maxLatency: number): void;
86
+ getPreferredSession(): Session | undefined;
87
+ /**
88
+ * Checks if this user has any active sessions
89
+ */
90
+ hasActiveSessions(): boolean;
91
+ /**
92
+ * Gets total count of devices
93
+ */
94
+ getDeviceCount(): number;
95
+ /**
96
+ * Gets total count of active sessions
97
+ */
98
+ getActiveSessionCount(): number;
46
99
  /**
47
100
  * Cleanup when destroying the user record
48
101
  */
49
102
  close(): void;
50
103
  /**
51
- * Return all sessions that are currently considered *active*.
52
- * For now this means any session in a non-stale device record as well as
53
- * all sessions added through `addSession`.
54
- * Prioritizes initiator sessions (can send first message) over responder sessions.
104
+ * @deprecated Use upsertDevice instead
55
105
  */
56
- getActiveSessions(): Session[];
106
+ conditionalUpdate(deviceId: string, publicKey: string): void;
57
107
  /**
58
- * Return *all* sessions — active or inactive — that we have stored for this
59
- * user. This is required for `SessionManager.onEvent` so that it can attach
60
- * listeners to existing sessions.
108
+ * @deprecated Use upsertSession instead
61
109
  */
62
- getAllSessions(): Session[];
110
+ insertSession(deviceId: string, session: Session): void;
63
111
  /**
64
- * Unified helper that either associates the session with a device record
65
- * (if deviceId provided **and** the record exists) or falls back to the
66
- * legacy extraSessions list.
112
+ * Creates a new session for a device
67
113
  */
68
- upsertSession(deviceId: string | undefined, session: Session): void;
114
+ createSession(deviceId: string, sharedSecret: Uint8Array, ourCurrentPrivateKey: Uint8Array, isInitiator: boolean, name?: string): Session;
69
115
  }
116
+ export {};
70
117
  //# sourceMappingURL=UserRecord.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UserRecord.d.ts","sourceRoot":"","sources":["../src/UserRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,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