nostr-double-ratchet 0.0.10 → 0.0.12

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,8 +1,17 @@
1
1
  * Double ratchet on nostr
2
2
  - [x] 1-on-1 channel
3
3
  - [ ] group channel
4
- * Invites for securely exchanging session keys. Don't use your long-term key for initiating a session.
4
+ * Invites for securely exchanging session keys
5
5
  * Breaking changes are likely
6
6
  * Stable version on [NPM](https://www.npmjs.com/package/nostr-double-ratchet)
7
7
  * check out [tests](./tests/) for usage
8
8
  * [Documentation](https://nostr-double-ratchet.iris.to/)
9
+ * [Source code](https://github.com/mmalmi/nostr-double-ratchet)
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install nostr-double-ratchet
15
+ # or
16
+ yarn add nostr-double-ratchet
17
+ ```
package/dist/Invite.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { VerifiedEvent, UnsignedEvent } from "nostr-tools";
2
2
  import { NostrSubscribe, Unsubscribe } from "./types";
3
- import { Channel } from "./Channel";
3
+ import { Session } from "./Session.ts";
4
4
  import { EncryptFunction, DecryptFunction } from "./types";
5
5
  /**
6
- * Invite is a safe way to exchange session keys and initiate secret channels.
6
+ * Invite is a safe way to exchange session keys and initiate secret sessions.
7
7
  *
8
8
  * It can be shared privately as an URL (e.g. QR code) or published as a Nostr event.
9
9
  *
@@ -25,7 +25,7 @@ export declare class Invite {
25
25
  static fromUrl(url: string): Invite;
26
26
  static deserialize(json: string): Invite;
27
27
  static fromEvent(event: VerifiedEvent): Invite;
28
- static fromUser(user: string, subscribe: NostrSubscribe): Promise<Invite | undefined>;
28
+ static fromUser(user: string, subscribe: NostrSubscribe, onInvite: (invite: Invite) => void): Unsubscribe;
29
29
  /**
30
30
  * Save Invite as JSON. Includes the inviter's session private key, so don't share this.
31
31
  */
@@ -36,11 +36,11 @@ export declare class Invite {
36
36
  getUrl(root?: string): string;
37
37
  getEvent(): UnsignedEvent;
38
38
  /**
39
- * Called by the invitee. Accepts the invite and creates a new channel with the inviter.
39
+ * Called by the invitee. Accepts the invite and creates a new session with the inviter.
40
40
  *
41
41
  * @param inviteeSecretKey - The invitee's secret key or a signing function
42
42
  * @param nostrSubscribe - A function to subscribe to Nostr events
43
- * @returns An object containing the new channel and an event to be published
43
+ * @returns An object containing the new session and an event to be published
44
44
  *
45
45
  * 1. Inner event: No signature, content encrypted with DH(inviter, invitee).
46
46
  * Purpose: Authenticate invitee. Contains invitee session key.
@@ -48,12 +48,12 @@ export declare class Invite {
48
48
  * Purpose: Contains inner event. Hides invitee from others who might have the shared Nostr key.
49
49
 
50
50
  * Note: You need to publish the returned event on Nostr using NDK or another Nostr system of your choice,
51
- * so the inviter can create the channel on their side.
51
+ * so the inviter can create the session on their side.
52
52
  */
53
53
  accept(nostrSubscribe: NostrSubscribe, inviteePublicKey: string, inviteeSecretKey: Uint8Array | EncryptFunction): Promise<{
54
- channel: Channel;
54
+ session: Session;
55
55
  event: VerifiedEvent;
56
56
  }>;
57
- listen(inviterSecretKey: Uint8Array | DecryptFunction, nostrSubscribe: NostrSubscribe, onChannel: (channel: Channel, identity?: string) => void): Unsubscribe;
57
+ listen(inviterSecretKey: Uint8Array | DecryptFunction, nostrSubscribe: NostrSubscribe, onSession: (session: Session, identity?: string) => void): Unsubscribe;
58
58
  }
59
59
  //# 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,WAAW,CAAC;AAEpC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG3D;;;;;;;;;GASG;AACH,qBAAa,MA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E,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,WAAW;IAwBzG;;OAEG;IACH,SAAS,IAAI,MAAM;IAYnB;;OAEG;IACH,MAAM,CAAC,IAAI,SAAoB;IAY/B,QAAQ,IAAI,aAAa;IAUzB;;;;;;;;;;;;;;OAcG;IACG,MAAM,CACR,cAAc,EAAE,cAAc,EAC9B,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,UAAU,GAAG,eAAe,GAC/C,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,aAAa,CAAA;KAAE,CAAC;IAkCtD,MAAM,CAAC,gBAAgB,EAAE,UAAU,GAAG,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,WAAW;CA4ChK"}
@@ -1,40 +1,40 @@
1
1
  import { VerifiedEvent } from "nostr-tools";
2
- import { ChannelState, Unsubscribe, NostrSubscribe, MessageCallback } from "./types";
2
+ import { SessionState, Unsubscribe, NostrSubscribe, MessageCallback } from "./types";
3
3
  /**
4
- * Double ratchet secure communication channel over Nostr
4
+ * Double ratchet secure communication session over Nostr
5
5
  *
6
6
  * Very similar to Signal's "Double Ratchet with header encryption"
7
7
  * https://signal.org/docs/specifications/doubleratchet/
8
8
  */
9
- export declare class Channel {
9
+ export declare class Session {
10
10
  private nostrSubscribe;
11
- state: ChannelState;
11
+ state: SessionState;
12
12
  private nostrUnsubscribe?;
13
13
  private nostrNextUnsubscribe?;
14
14
  private internalSubscriptions;
15
15
  private currentInternalSubscriptionId;
16
16
  name: string;
17
- constructor(nostrSubscribe: NostrSubscribe, state: ChannelState);
17
+ constructor(nostrSubscribe: NostrSubscribe, state: SessionState);
18
18
  /**
19
- * Initializes a new secure communication channel
19
+ * Initializes a new secure communication session
20
20
  * @param nostrSubscribe Function to subscribe to Nostr events
21
21
  * @param theirNostrPublicKey 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
- * @param name Optional name for the channel (for debugging)
26
- * @returns A new Channel instance
25
+ * @param name Optional name for the session (for debugging)
26
+ * @returns A new Session instance
27
27
  */
28
- static init(nostrSubscribe: NostrSubscribe, theirNostrPublicKey: string, ourCurrentPrivateKey: Uint8Array, isInitiator: boolean, sharedSecret: Uint8Array, name?: string): Channel;
28
+ static init(nostrSubscribe: NostrSubscribe, theirNostrPublicKey: string, ourCurrentPrivateKey: Uint8Array, isInitiator: boolean, sharedSecret: Uint8Array, name?: string): Session;
29
29
  /**
30
- * Sends an encrypted message through the channel
30
+ * Sends an encrypted message through the session
31
31
  * @param data 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
35
  send(data: string): VerifiedEvent;
36
36
  /**
37
- * Subscribes to incoming messages on this channel
37
+ * Subscribes to incoming messages on this session
38
38
  * @param callback Function to be called when a message is received
39
39
  * @returns Unsubscribe function to stop receiving messages
40
40
  */
@@ -52,4 +52,4 @@ export declare class Channel {
52
52
  private handleNostrEvent;
53
53
  private subscribeToNostrEvents;
54
54
  }
55
- //# sourceMappingURL=Channel.d.ts.map
55
+ //# sourceMappingURL=Session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Channel.d.ts","sourceRoot":"","sources":["../src/Channel.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;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AAC,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,gBAAgB;IA8BxB,OAAO,CAAC,sBAAsB;CAiB/B"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "./Channel";
1
+ export * from "./Session.ts";
2
2
  export * from "./Invite";
3
3
  export * from "./types";
4
4
  export * from "./utils";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}