nostr-double-ratchet 0.0.11 → 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 +10 -1
- package/dist/Invite.d.ts +7 -7
- package/dist/Invite.d.ts.map +1 -1
- package/dist/{Channel.d.ts → Session.d.ts} +12 -12
- package/dist/{Channel.d.ts.map → Session.d.ts.map} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/nostr-double-ratchet.es.js +1599 -1495
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/utils.d.ts +5 -5
- package/dist/utils.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/Invite.ts +13 -13
- package/src/{Channel.ts → Session.ts} +14 -14
- package/src/index.ts +1 -1
- package/src/types.ts +3 -3
- package/src/utils.ts +6 -6
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
|
|
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 {
|
|
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
|
|
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
|
*
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
-
|
|
54
|
+
session: Session;
|
|
55
55
|
event: VerifiedEvent;
|
|
56
56
|
}>;
|
|
57
|
-
listen(inviterSecretKey: Uint8Array | DecryptFunction, nostrSubscribe: NostrSubscribe,
|
|
57
|
+
listen(inviterSecretKey: Uint8Array | DecryptFunction, nostrSubscribe: NostrSubscribe, onSession: (session: Session, identity?: string) => void): Unsubscribe;
|
|
58
58
|
}
|
|
59
59
|
//# sourceMappingURL=Invite.d.ts.map
|
package/dist/Invite.d.ts.map
CHANGED
|
@@ -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,
|
|
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,uBAAuB,EAAE,MAAM;IAC/B,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,MAAM;IACf,wBAAwB,CAAC,EAAE,UAAU;IACrC,KAAK,CAAC,EAAE,MAAM;IACd,OAAO,CAAC,EAAE,MAAM;IAChB,MAAM,EAAE,MAAM,EAAE;gBANhB,uBAAuB,EAAE,MAAM,EAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,wBAAwB,CAAC,EAAE,UAAU,YAAA,EACrC,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,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAaxC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM;IAuB9C,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,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 {
|
|
2
|
+
import { SessionState, Unsubscribe, NostrSubscribe, MessageCallback } from "./types";
|
|
3
3
|
/**
|
|
4
|
-
* Double ratchet secure communication
|
|
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
|
|
9
|
+
export declare class Session {
|
|
10
10
|
private nostrSubscribe;
|
|
11
|
-
state:
|
|
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:
|
|
17
|
+
constructor(nostrSubscribe: NostrSubscribe, state: SessionState);
|
|
18
18
|
/**
|
|
19
|
-
* Initializes a new secure communication
|
|
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
|
|
26
|
-
* @returns A new
|
|
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):
|
|
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
|
|
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
|
|
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=
|
|
55
|
+
//# sourceMappingURL=Session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
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,gBAAgB;IA8BxB,OAAO,CAAC,sBAAsB;CAiB/B"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
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"}
|