nostr-double-ratchet 0.0.13 → 0.0.15

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/dist/Invite.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { VerifiedEvent, UnsignedEvent } from "nostr-tools";
2
- import { NostrSubscribe, Unsubscribe } from "./types";
2
+ import { NostrSubscribe, Unsubscribe, EncryptFunction, DecryptFunction } from "./types";
3
3
  import { Session } from "./Session.ts";
4
- import { EncryptFunction, DecryptFunction } from "./types";
5
4
  /**
6
5
  * Invite is a safe way to exchange session keys and initiate secret sessions.
7
6
  *
@@ -14,13 +13,13 @@ import { EncryptFunction, DecryptFunction } from "./types";
14
13
  */
15
14
  export declare class Invite {
16
15
  inviterEphemeralPublicKey: string;
17
- linkSecret: string;
16
+ sharedSecret: string;
18
17
  inviter: string;
19
18
  inviterEphemeralPrivateKey?: Uint8Array | undefined;
20
19
  label?: string | undefined;
21
20
  maxUses?: number | undefined;
22
21
  usedBy: string[];
23
- constructor(inviterEphemeralPublicKey: string, linkSecret: string, inviter: string, inviterEphemeralPrivateKey?: Uint8Array | undefined, label?: string | undefined, maxUses?: number | undefined, usedBy?: string[]);
22
+ constructor(inviterEphemeralPublicKey: string, sharedSecret: string, inviter: string, inviterEphemeralPrivateKey?: Uint8Array | undefined, label?: string | undefined, maxUses?: number | undefined, usedBy?: string[]);
24
23
  static createNew(inviter: string, label?: string, maxUses?: number): Invite;
25
24
  static fromUrl(url: string): Invite;
26
25
  static deserialize(json: string): Invite;
@@ -50,10 +49,10 @@ export declare class Invite {
50
49
  * Note: You need to publish the returned event on Nostr using NDK or another Nostr system of your choice,
51
50
  * so the inviter can create the session on their side.
52
51
  */
53
- accept(nostrSubscribe: NostrSubscribe, inviteePublicKey: string, inviteeSecretKey: Uint8Array | EncryptFunction): Promise<{
52
+ accept(nostrSubscribe: NostrSubscribe, inviteePublicKey: string, encryptor: Uint8Array | EncryptFunction): Promise<{
54
53
  session: Session;
55
54
  event: VerifiedEvent;
56
55
  }>;
57
- listen(inviterSecretKey: Uint8Array | DecryptFunction, nostrSubscribe: NostrSubscribe, onSession: (session: Session, identity?: string) => void): Unsubscribe;
56
+ listen(decryptor: Uint8Array | DecryptFunction, nostrSubscribe: NostrSubscribe, onSession: (session: Session, identity?: string) => void): Unsubscribe;
58
57
  }
59
58
  //# sourceMappingURL=Invite.d.ts.map
@@ -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,MAAM,SAAS,CAAC;AAEzE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG3D;;;;;;;;;GASG;AACH,qBAAa,MAAM;IAEJ,yBAAyB,EAAE,MAAM;IACjC,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,MAAM;IACf,0BAA0B,CAAC,EAAE,UAAU;IACvC,KAAK,CAAC,EAAE,MAAM;IACd,OAAO,CAAC,EAAE,MAAM;IAChB,MAAM,EAAE,MAAM,EAAE;gBANhB,yBAAyB,EAAE,MAAM,EACjC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,0BAA0B,CAAC,EAAE,UAAU,YAAA,EACvC,KAAK,CAAC,EAAE,MAAM,YAAA,EACd,OAAO,CAAC,EAAE,MAAM,YAAA,EAChB,MAAM,GAAE,MAAM,EAAO;IAGhC,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAiB3E,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IA2BnC,MAAM,CAAC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@@ -1,5 +1,5 @@
1
- import { VerifiedEvent } from "nostr-tools";
2
- import { SessionState, Unsubscribe, NostrSubscribe, MessageCallback } from "./types";
1
+ import { VerifiedEvent, UnsignedEvent } from "nostr-tools";
2
+ import { SessionState, Unsubscribe, NostrSubscribe, EventCallback } from "./types";
3
3
  /**
4
4
  * Double ratchet secure communication session over Nostr
5
5
  *
@@ -18,27 +18,34 @@ export declare class Session {
18
18
  /**
19
19
  * Initializes a new secure communication session
20
20
  * @param nostrSubscribe Function to subscribe to Nostr events
21
- * @param theirNostrPublicKey The public key of the other party
21
+ * @param theirNextNostrPublicKey The public key of the other party
22
22
  * @param ourCurrentPrivateKey Our current private key for Nostr
23
23
  * @param isInitiator Whether we are initiating the conversation (true) or responding (false)
24
24
  * @param sharedSecret Initial shared secret for securing the first message chain
25
25
  * @param name Optional name for the session (for debugging)
26
26
  * @returns A new Session instance
27
27
  */
28
- static init(nostrSubscribe: NostrSubscribe, theirNostrPublicKey: string, ourCurrentPrivateKey: Uint8Array, isInitiator: boolean, sharedSecret: Uint8Array, name?: string): Session;
28
+ static init(nostrSubscribe: NostrSubscribe, theirNextNostrPublicKey: string, ourCurrentPrivateKey: Uint8Array, isInitiator: boolean, sharedSecret: Uint8Array, name?: string): Session;
29
29
  /**
30
- * Sends an encrypted message through the session
31
- * @param data The plaintext message to send
30
+ * Sends a text message through the encrypted session
31
+ * @param text The plaintext message to send
32
32
  * @returns A verified Nostr event containing the encrypted message
33
33
  * @throws Error if we are not the initiator and trying to send the first message
34
34
  */
35
- send(data: string): VerifiedEvent;
35
+ send(text: string): VerifiedEvent;
36
+ /**
37
+ * Send a Nostr event through the encrypted session
38
+ * @param event Partial Nostr event to send. Must be unsigned. Id and will be generated if not provided.
39
+ * @returns A verified Nostr event containing the encrypted message
40
+ * @throws Error if we are not the initiator and trying to send the first message
41
+ */
42
+ sendEvent(event: Partial<UnsignedEvent>): VerifiedEvent;
36
43
  /**
37
44
  * Subscribes to incoming messages on this session
38
45
  * @param callback Function to be called when a message is received
39
46
  * @returns Unsubscribe function to stop receiving messages
40
47
  */
41
- onMessage(callback: MessageCallback): Unsubscribe;
48
+ onEvent(callback: EventCallback): Unsubscribe;
42
49
  /**
43
50
  * Stop listening to incoming messages
44
51
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Session.d.ts","sourceRoot":"","sources":["../src/Session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyD,aAAa,EAAE,MAAM,aAAa,CAAC;AAEnG,OAAO,EACL,YAAY,EAEZ,WAAW,EACX,cAAc,EACd,eAAe,EAEhB,MAAM,SAAS,CAAC;AAKjB;;;;;GAKG;AACH,qBAAa,OAAO;IAQN,OAAO,CAAC,cAAc;IAAyB,KAAK,EAAE,YAAY;IAP9E,OAAO,CAAC,gBAAgB,CAAC,CAAc;IACvC,OAAO,CAAC,oBAAoB,CAAC,CAAc;IAC3C,OAAO,CAAC,qBAAqB,CAAsC;IACnE,OAAO,CAAC,6BAA6B,CAAK;IACnC,IAAI,EAAE,MAAM,CAAC;gBAGA,cAAc,EAAE,cAAc,EAAS,KAAK,EAAE,YAAY;IAI9E;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;IA6BlL;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa;IAoBjC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,WAAW;IAOjD;;OAEG;IACH,KAAK;IAML,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,cAAc;IAuBtB,OAAO,CAAC,WAAW;IAyBnB,OAAO,CAAC,eAAe;IAyBvB,OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,g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sB;CAkB/B"}
@@ -1 +1,51 @@
1
+ import { Session } from './Session';
2
+ import { NostrSubscribe } from './types';
3
+ /**
4
+ * WIP: Conversation management system similar to Signal's Sesame
5
+ * https://signal.org/docs/specifications/sesame/
6
+ */
7
+ export declare class UserRecord {
8
+ userId: string;
9
+ private nostrSubscribe;
10
+ private deviceRecords;
11
+ private isStale;
12
+ private staleTimestamp?;
13
+ constructor(userId: string, nostrSubscribe: NostrSubscribe);
14
+ /**
15
+ * Adds or updates a device record for this user
16
+ */
17
+ conditionalUpdate(deviceId: string, publicKey: string): void;
18
+ /**
19
+ * Inserts a new session for a device, making it the active session
20
+ */
21
+ insertSession(deviceId: string, session: Session): void;
22
+ /**
23
+ * Activates an inactive session for a device
24
+ */
25
+ activateSession(deviceId: string, session: Session): void;
26
+ /**
27
+ * Marks a device record as stale
28
+ */
29
+ markDeviceStale(deviceId: string): void;
30
+ /**
31
+ * Marks the entire user record as stale
32
+ */
33
+ markUserStale(): void;
34
+ /**
35
+ * Gets all non-stale device records with active sessions
36
+ */
37
+ getActiveDevices(): Array<[string, Session]>;
38
+ /**
39
+ * Creates a new session for a device
40
+ */
41
+ createSession(deviceId: string, sharedSecret: Uint8Array, ourCurrentPrivateKey: Uint8Array, isInitiator: boolean, name?: string): Session;
42
+ /**
43
+ * Deletes stale records that are older than maxLatency
44
+ */
45
+ pruneStaleRecords(maxLatency: number): void;
46
+ /**
47
+ * Cleanup when destroying the user record
48
+ */
49
+ close(): void;
50
+ }
1
51
  //# sourceMappingURL=UserRecord.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"UserRecord.d.ts","sourceRoot":"","sources":["../src/UserRecord.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"UserRecord.d.ts","sourceRoot":"","sources":["../src/UserRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAUzC;;;GAGG;AACH,qBAAa,UAAU;IAMZ,MAAM,EAAE,MAAM;IACrB,OAAO,CAAC,cAAc;IANxB,OAAO,CAAC,aAAa,CAAwC;IAC7D,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,cAAc,CAAC,CAAS;gBAGvB,MAAM,EAAE,MAAM,EACb,cAAc,EAAE,cAAc;IAGxC;;OAEG;IACI,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAanE;;OAEG;IACI,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAe9D;;OAEG;IACI,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAuBhE;;OAEG;IACI,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAQ9C;;OAEG;IACI,aAAa,IAAI,IAAI;IAK5B;;OAEG;IACI,gBAAgB,IAAI,KAAK,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAQnD;;OAEG;IACI,aAAa,CAClB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,UAAU,EACxB,oBAAoB,EAAE,UAAU,EAChC,WAAW,EAAE,OAAO,EACpB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO;IAmBV;;OAEG;IACI,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAyBlD;;OAEG;IACI,KAAK,IAAI,IAAI;CAOrB"}