@freesignal/protocol 0.2.0 → 0.2.1
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/api.d.ts +2 -0
- package/api.js +9 -4
- package/package.json +1 -1
package/api.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class FreeSignalAPI {
|
|
|
15
15
|
keyExchange: LocalStorage<string, Crypto.KeyPair>;
|
|
16
16
|
users: LocalStorage<UserId, IdentityKeys>;
|
|
17
17
|
});
|
|
18
|
+
get userId(): Uint8Array;
|
|
18
19
|
encryptData(data: Uint8Array, userId: string): Promise<EncryptedData>;
|
|
19
20
|
decryptData(data: Uint8Array, userId: string): Promise<Uint8Array>;
|
|
20
21
|
protected digestToken(auth?: string): Promise<{
|
|
@@ -35,4 +36,5 @@ export declare class FreeSignalAPI {
|
|
|
35
36
|
secretSignKey: Uint8Array;
|
|
36
37
|
secretBoxKey: Uint8Array;
|
|
37
38
|
};
|
|
39
|
+
static getUserId(publicKey: string | Uint8Array): string;
|
|
38
40
|
}
|
package/api.js
CHANGED
|
@@ -27,6 +27,9 @@ class FreeSignalAPI {
|
|
|
27
27
|
this.keyExchange = new x3dh_1.KeyExchange(secretSignKey, secretBoxKey, keyExchange);
|
|
28
28
|
this.users = users;
|
|
29
29
|
}
|
|
30
|
+
get userId() {
|
|
31
|
+
return crypto_1.default.hash(this.signKey.publicKey);
|
|
32
|
+
}
|
|
30
33
|
encryptData(data, userId) {
|
|
31
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
35
|
const session = yield this.sessions.get(userId);
|
|
@@ -56,7 +59,7 @@ class FreeSignalAPI {
|
|
|
56
59
|
const identityKeys = yield this.users.get(userId);
|
|
57
60
|
if (!identityKeys)
|
|
58
61
|
throw new Error('User not found or invalid auth token');
|
|
59
|
-
if ((0, utils_1.verifyUint8Array)(crypto_1.default.hash(crypto_1.default.ECDH.
|
|
62
|
+
if ((0, utils_1.verifyUint8Array)(crypto_1.default.hash(crypto_1.default.ECDH.scalarMult((0, utils_1.decodeBase64)(identityKeys.publicKey), this.boxKey.secretKey)), (0, utils_1.decodeBase64)(sharedId)))
|
|
60
63
|
return { identityKeys, userId: auth };
|
|
61
64
|
else
|
|
62
65
|
throw new Error('Authorization token not valid');
|
|
@@ -65,9 +68,8 @@ class FreeSignalAPI {
|
|
|
65
68
|
});
|
|
66
69
|
}
|
|
67
70
|
createToken(publicKey) {
|
|
68
|
-
const sharedId = crypto_1.default.hash(crypto_1.default.ECDH.
|
|
69
|
-
|
|
70
|
-
return `Bearer ${(0, utils_1.encodeBase64)(userId)}:${(0, utils_1.encodeBase64)(sharedId)}`;
|
|
71
|
+
const sharedId = crypto_1.default.hash(crypto_1.default.ECDH.scalarMult(publicKey, this.boxKey.secretKey));
|
|
72
|
+
return `Bearer ${(0, utils_1.encodeBase64)(this.userId)}:${(0, utils_1.encodeBase64)(sharedId)}`;
|
|
71
73
|
}
|
|
72
74
|
;
|
|
73
75
|
packDatagrams(messages) {
|
|
@@ -114,5 +116,8 @@ class FreeSignalAPI {
|
|
|
114
116
|
secretBoxKey: crypto_1.default.ECDH.keyPair().secretKey
|
|
115
117
|
};
|
|
116
118
|
}
|
|
119
|
+
static getUserId(publicKey) {
|
|
120
|
+
return (0, utils_1.encodeBase64)(crypto_1.default.hash(publicKey instanceof Uint8Array ? publicKey : (0, utils_1.decodeBase64)(publicKey)));
|
|
121
|
+
}
|
|
117
122
|
}
|
|
118
123
|
exports.FreeSignalAPI = FreeSignalAPI;
|