nostr-double-ratchet 0.0.12 → 0.0.14
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 +7 -8
- package/dist/Invite.d.ts.map +1 -1
- package/dist/Session.d.ts +2 -2
- package/dist/Session.d.ts.map +1 -1
- package/dist/UserRecord.d.ts +51 -0
- package/dist/UserRecord.d.ts.map +1 -0
- package/dist/nostr-double-ratchet.es.js +333 -331
- package/dist/nostr-double-ratchet.umd.js +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Invite.ts +62 -56
- package/src/Session.ts +24 -22
- package/src/UserRecord.ts +182 -0
- package/src/types.ts +4 -1
- package/src/utils.ts +4 -2
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
|
*
|
|
@@ -13,14 +12,14 @@ import { EncryptFunction, DecryptFunction } from "./types";
|
|
|
13
12
|
* Also make sure to keep the session key safe.
|
|
14
13
|
*/
|
|
15
14
|
export declare class Invite {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
inviterEphemeralPublicKey: 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(
|
|
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,
|
|
52
|
+
accept(nostrSubscribe: NostrSubscribe, inviteePublicKey: string, encryptor: Uint8Array | EncryptFunction): Promise<{
|
|
54
53
|
session: Session;
|
|
55
54
|
event: VerifiedEvent;
|
|
56
55
|
}>;
|
|
57
|
-
listen(
|
|
56
|
+
listen(decryptor: Uint8Array | DecryptFunction, nostrSubscribe: NostrSubscribe, onSession: (session: Session, identity?: string) => void): Unsubscribe;
|
|
58
57
|
}
|
|
59
58
|
//# 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,
|
|
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,EAAsB,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/H,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc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C;IAsCtD,MAAM,CAAC,SAAS,EAAE,UAAU,GAAG,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,WAAW;CAiDzJ"}
|
package/dist/Session.d.ts
CHANGED
|
@@ -18,14 +18,14 @@ 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
|
|
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,
|
|
28
|
+
static init(nostrSubscribe: NostrSubscribe, theirNextNostrPublicKey: string, ourCurrentPrivateKey: Uint8Array, isInitiator: boolean, sharedSecret: Uint8Array, name?: string): Session;
|
|
29
29
|
/**
|
|
30
30
|
* Sends an encrypted message through the session
|
|
31
31
|
* @param data The plaintext message to send
|
package/dist/Session.d.ts.map
CHANGED
|
@@ -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,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OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,aAAa;IAmCrB,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,sBAAsB;CAkB/B"}
|
|
@@ -0,0 +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
|
+
}
|
|
51
|
+
//# sourceMappingURL=UserRecord.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,CA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