@freesignal/protocol 0.2.8 → 0.2.11
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/double-ratchet.d.ts +37 -4
- package/double-ratchet.js +133 -39
- package/index.d.ts +12 -15
- package/index.js +31 -20
- package/node.d.ts +27 -0
- package/node.js +105 -0
- package/package.json +3 -8
- package/test.js +21 -26
- package/types.d.ts +66 -136
- package/types.js +238 -366
- package/x3dh.d.ts +18 -19
- package/x3dh.js +75 -114
- package/api.d.ts +0 -54
- package/api.js +0 -195
package/test.js
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
4
10
|
};
|
|
5
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const _1 = require(".");
|
|
7
|
-
const crypto_1 = __importDefault(require("@freesignal/crypto"));
|
|
8
12
|
const utils_1 = require("@freesignal/utils");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
console.log("Successfully handshaked");
|
|
23
|
-
else
|
|
24
|
-
console.log("Error during handshake");
|
|
25
|
-
const longmsg = _1.Datagram.create(alice.signatureKey, bob.signatureKey, _1.Protocols.MESSAGE, alicesession.encrypt(new Uint8Array(1000000).fill(33).map(val => val + Math.floor(Math.random() * 93))));
|
|
26
|
-
console.log(longmsg.encode().length);
|
|
27
|
-
}
|
|
28
|
-
else
|
|
29
|
-
console.log("Error");
|
|
30
|
-
});
|
|
13
|
+
const _1 = require(".");
|
|
14
|
+
const node_1 = require("./node");
|
|
15
|
+
const bob = new node_1.FreeSignalNode({ keyExchange: new _1.AsyncMap(), sessions: new _1.AsyncMap(), users: new _1.AsyncMap() });
|
|
16
|
+
const alice = new node_1.FreeSignalNode({ keyExchange: new _1.AsyncMap(), sessions: new _1.AsyncMap(), users: new _1.AsyncMap() });
|
|
17
|
+
setImmediate(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
const aliceHandshake = yield alice.sendHandshake(yield bob.generateKeyData());
|
|
19
|
+
yield bob.receive(aliceHandshake);
|
|
20
|
+
console.log("Session established successfully between Alice and Bob.");
|
|
21
|
+
const data = (yield bob.encrypt(alice.userId.toString(), _1.Protocols.MESSAGE, (0, utils_1.encodeData)("Hi Alice!"))).toBytes();
|
|
22
|
+
console.log((0, utils_1.decodeData)(yield alice.receive(data)));
|
|
23
|
+
const longmsg = yield alice.sendData(bob.userId.toString(), new Uint8Array(1000000).fill(33).map(val => val + Math.floor(Math.random() * 93)));
|
|
24
|
+
console.log(longmsg.toBytes().length);
|
|
25
|
+
}));
|
package/types.d.ts
CHANGED
|
@@ -16,43 +16,47 @@
|
|
|
16
16
|
* You should have received a copy of the GNU General Public License
|
|
17
17
|
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
18
18
|
*/
|
|
19
|
-
import { Encodable } from "@freesignal/interfaces";
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
import { LocalStorage, Encodable } from "@freesignal/interfaces";
|
|
20
|
+
export declare class UserId {
|
|
21
|
+
private readonly array;
|
|
22
|
+
private constructor();
|
|
23
|
+
toString(): string;
|
|
24
|
+
toJSON(): string;
|
|
25
|
+
toUint8Array(): Uint8Array;
|
|
26
|
+
static fromKey(identityKey: string | Uint8Array | IdentityKey): UserId;
|
|
27
|
+
static from(userId: string | Uint8Array | UserId): UserId;
|
|
28
|
+
}
|
|
29
|
+
export interface IdentityKey extends Encodable {
|
|
30
|
+
readonly info: number;
|
|
31
|
+
readonly signatureKey: Uint8Array;
|
|
32
|
+
readonly exchangeKey: Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
export declare namespace IdentityKey {
|
|
35
|
+
const keyLength: number;
|
|
36
|
+
const version = 1;
|
|
37
|
+
function isIdentityKeys(obj: any): boolean;
|
|
38
|
+
function from(identityKey: IdentityKey | Uint8Array | string): IdentityKey;
|
|
39
|
+
function from(signatureKey: Uint8Array | string, exchangeKey: Uint8Array | string): IdentityKey;
|
|
32
40
|
}
|
|
33
|
-
export interface
|
|
34
|
-
readonly
|
|
35
|
-
readonly
|
|
41
|
+
export interface PrivateIdentityKey {
|
|
42
|
+
readonly info: number;
|
|
43
|
+
readonly signatureKey: Uint8Array;
|
|
44
|
+
readonly exchangeKey: Uint8Array;
|
|
45
|
+
readonly identityKey: IdentityKey;
|
|
36
46
|
}
|
|
37
|
-
export declare namespace
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
encode(): Uint8Array;
|
|
44
|
-
toString(): string;
|
|
45
|
-
toJSON(): string;
|
|
46
|
-
}
|
|
47
|
-
export function isIdentityKeys(obj: any): boolean;
|
|
48
|
-
export function from(identityKeys: IdentityKeys): IdentityKeysConstructor;
|
|
49
|
-
export {};
|
|
47
|
+
export declare namespace PrivateIdentityKey {
|
|
48
|
+
const keyLength: number;
|
|
49
|
+
const version = 1;
|
|
50
|
+
function isIdentityKeys(obj: any): boolean;
|
|
51
|
+
function from(identityKey: PrivateIdentityKey | Uint8Array | string): PrivateIdentityKey;
|
|
52
|
+
function from(signatureKey: Uint8Array | string, exchangeKey: Uint8Array | string): PrivateIdentityKey;
|
|
50
53
|
}
|
|
51
54
|
export declare enum Protocols {
|
|
52
55
|
NULL = "",
|
|
53
56
|
MESSAGE = "/freesignal/message",
|
|
54
57
|
RELAY = "/freesignal/relay",
|
|
55
|
-
HANDSHAKE = "/freesignal/handshake"
|
|
58
|
+
HANDSHAKE = "/freesignal/handshake",
|
|
59
|
+
DISCOVER = "/freesignal/discover"
|
|
56
60
|
}
|
|
57
61
|
export declare namespace Protocols {
|
|
58
62
|
function isProtocol(protocol: any): boolean;
|
|
@@ -61,44 +65,31 @@ export declare namespace Protocols {
|
|
|
61
65
|
function encode(protocol: Protocols, length?: number): Uint8Array;
|
|
62
66
|
function decode(array: Uint8Array): Protocols;
|
|
63
67
|
}
|
|
64
|
-
export
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
export declare class Datagram implements Encodable {
|
|
69
|
+
static version: number;
|
|
70
|
+
private _id;
|
|
71
|
+
private _version;
|
|
67
72
|
readonly sender: string;
|
|
68
73
|
readonly receiver: string;
|
|
69
74
|
readonly protocol: Protocols;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
constructor(data: Uint8Array | Datagram);
|
|
89
|
-
get signed(): boolean;
|
|
90
|
-
get signature(): string | undefined;
|
|
91
|
-
set payload(data: Uint8Array);
|
|
92
|
-
get payload(): Uint8Array | undefined;
|
|
93
|
-
encode(): Uint8Array;
|
|
94
|
-
sign(secretKey: Uint8Array): this;
|
|
95
|
-
toString(): string;
|
|
96
|
-
toJSON(): string;
|
|
97
|
-
}
|
|
98
|
-
export function create(sender: Uint8Array | string, receiver: Uint8Array | string, protocol: Protocols, payload?: Uint8Array | Encodable): DatagramConstructor;
|
|
99
|
-
export function isDatagram(obj: any): boolean;
|
|
100
|
-
export function from(data: Uint8Array | Datagram | string): DatagramConstructor;
|
|
101
|
-
export {};
|
|
75
|
+
private _createdAt;
|
|
76
|
+
private _payload?;
|
|
77
|
+
private _signature?;
|
|
78
|
+
private secretKey?;
|
|
79
|
+
private static headerOffset;
|
|
80
|
+
constructor(sender: Uint8Array | string, receiver: Uint8Array | string, protocol: Protocols, payload?: Uint8Array | Encodable);
|
|
81
|
+
get id(): string;
|
|
82
|
+
get version(): number;
|
|
83
|
+
get createdAt(): number;
|
|
84
|
+
get signed(): boolean;
|
|
85
|
+
get signature(): string | undefined;
|
|
86
|
+
set payload(data: Uint8Array);
|
|
87
|
+
get payload(): Uint8Array | undefined;
|
|
88
|
+
toBytes(): Uint8Array;
|
|
89
|
+
sign(secretKey: Uint8Array): this;
|
|
90
|
+
toString(): string;
|
|
91
|
+
toJSON(): string;
|
|
92
|
+
static from(data: Uint8Array | Datagram | string): Datagram;
|
|
102
93
|
}
|
|
103
94
|
/**
|
|
104
95
|
* Interface representing an encrypted payload.
|
|
@@ -136,7 +127,7 @@ export interface EncryptedData extends Encodable {
|
|
|
136
127
|
/**
|
|
137
128
|
* Serializes the payload into a Uint8Array for transport.
|
|
138
129
|
*/
|
|
139
|
-
|
|
130
|
+
toBytes(): Uint8Array;
|
|
140
131
|
/**
|
|
141
132
|
* Returns the payload as a Base64 string.
|
|
142
133
|
*/
|
|
@@ -162,74 +153,13 @@ export declare class EncryptedData {
|
|
|
162
153
|
*/
|
|
163
154
|
static from(array: Uint8Array | EncryptedData): EncryptedData;
|
|
164
155
|
}
|
|
165
|
-
export declare class
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
constructor(encrypted: Uint8Array | EncryptedData);
|
|
175
|
-
get length(): number;
|
|
176
|
-
get version(): number;
|
|
177
|
-
get count(): number;
|
|
178
|
-
get previous(): number;
|
|
179
|
-
get publicKey(): Uint8Array;
|
|
180
|
-
get nonce(): Uint8Array;
|
|
181
|
-
get ciphertext(): Uint8Array;
|
|
182
|
-
encode(): Uint8Array;
|
|
183
|
-
toString(): string;
|
|
184
|
-
toJSON(): {
|
|
185
|
-
version: number;
|
|
186
|
-
count: number;
|
|
187
|
-
previous: number;
|
|
188
|
-
publicKey: string;
|
|
189
|
-
nonce: string;
|
|
190
|
-
ciphertext: string;
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
declare enum DataType {
|
|
194
|
-
UKNOWN = -1,
|
|
195
|
-
RAW = 0,
|
|
196
|
-
NUMBER = 1,
|
|
197
|
-
STRING = 2,
|
|
198
|
-
ARRAY = 3,
|
|
199
|
-
OBJECT = 4
|
|
200
|
-
}
|
|
201
|
-
declare namespace DataType {
|
|
202
|
-
function getType(type: string): DataType;
|
|
203
|
-
function getName(type: DataType): string;
|
|
204
|
-
function from(data: any): DataType;
|
|
205
|
-
}
|
|
206
|
-
export declare class DataEncoder<T> implements Encodable {
|
|
207
|
-
readonly data: T;
|
|
208
|
-
readonly type: string;
|
|
209
|
-
constructor(data: T);
|
|
210
|
-
protected get _type(): DataType;
|
|
211
|
-
encode(): Uint8Array;
|
|
212
|
-
toString(): string;
|
|
213
|
-
toJSON(): T;
|
|
214
|
-
static from<T = any>(array: Uint8Array): DataEncoder<T>;
|
|
215
|
-
}
|
|
216
|
-
export declare namespace XFreeSignal {
|
|
217
|
-
export const MIME = "application/x-freesignal";
|
|
218
|
-
export const version = 1;
|
|
219
|
-
export function encodeBody(type: 'data' | 'error', data: any, compressed?: boolean): BodyInit;
|
|
220
|
-
export function decodeBody<T = any>(body: Uint8Array): Body<T>;
|
|
221
|
-
class Body<T> implements Encodable {
|
|
222
|
-
readonly type: 'data' | 'error';
|
|
223
|
-
readonly data: T;
|
|
224
|
-
constructor(type: 'data' | 'error', data: T);
|
|
225
|
-
encode(compressed?: boolean): Uint8Array;
|
|
226
|
-
toString(): string;
|
|
227
|
-
toJSON(): {
|
|
228
|
-
type: "data" | "error";
|
|
229
|
-
data: T;
|
|
230
|
-
};
|
|
231
|
-
static from<T = any>(array: Uint8Array): Body<T>;
|
|
232
|
-
}
|
|
233
|
-
export {};
|
|
156
|
+
export declare class AsyncMap<K, V> implements LocalStorage<K, V> {
|
|
157
|
+
private readonly map;
|
|
158
|
+
constructor(iterable?: Iterable<readonly [K, V]>);
|
|
159
|
+
set(key: K, value: V): Promise<void>;
|
|
160
|
+
get(key: K): Promise<V | undefined>;
|
|
161
|
+
has(key: K): Promise<boolean>;
|
|
162
|
+
delete(key: K): Promise<boolean>;
|
|
163
|
+
clear(): Promise<void>;
|
|
164
|
+
entries(): ArrayIterator<[K, V]>;
|
|
234
165
|
}
|
|
235
|
-
export {};
|