@neykoor/libsignal-node 1.0.3 → 1.0.6
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 +28 -41
- package/lib/base-key-type.d.ts +1 -0
- package/lib/base-key-type.d.ts.map +1 -0
- package/lib/base-key-type.js +1 -0
- package/lib/base-key-type.js.map +1 -0
- package/lib/chain-type.d.ts +1 -0
- package/lib/chain-type.d.ts.map +1 -0
- package/lib/chain-type.js +1 -0
- package/lib/chain-type.js.map +1 -0
- package/lib/crypto.d.ts +1 -0
- package/lib/crypto.d.ts.map +1 -0
- package/lib/crypto.js +10 -9
- package/lib/crypto.js.map +1 -0
- package/lib/curve.d.ts +1 -0
- package/lib/curve.d.ts.map +1 -0
- package/lib/curve.js +20 -19
- package/lib/curve.js.map +1 -0
- package/lib/direction.d.ts +1 -0
- package/lib/direction.d.ts.map +1 -0
- package/lib/direction.js +1 -0
- package/lib/direction.js.map +1 -0
- package/lib/errors.d.ts +1 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +6 -5
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +21 -20
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +17 -16
- package/lib/index.js.map +1 -0
- package/lib/keyhelper.d.ts +3 -2
- package/lib/keyhelper.d.ts.map +1 -0
- package/lib/keyhelper.js +9 -8
- package/lib/keyhelper.js.map +1 -0
- package/lib/logger.d.ts +1 -0
- package/lib/logger.d.ts.map +1 -0
- package/lib/logger.js +1 -0
- package/lib/logger.js.map +1 -0
- package/lib/memory-storage.d.ts +5 -4
- package/lib/memory-storage.d.ts.map +1 -0
- package/lib/memory-storage.js +3 -2
- package/lib/memory-storage.js.map +1 -0
- package/lib/numeric-fingerprint.d.ts +1 -0
- package/lib/numeric-fingerprint.d.ts.map +1 -0
- package/lib/numeric-fingerprint.js +7 -6
- package/lib/numeric-fingerprint.js.map +1 -0
- package/lib/prekey-bundle-validator.d.ts +2 -1
- package/lib/prekey-bundle-validator.d.ts.map +1 -0
- package/lib/prekey-bundle-validator.js +13 -12
- package/lib/prekey-bundle-validator.js.map +1 -0
- package/lib/protobufs.d.ts +2 -1
- package/lib/protobufs.d.ts.map +1 -0
- package/lib/protobufs.js +2 -1
- package/lib/protobufs.js.map +1 -0
- package/lib/protocol-address.d.ts +1 -0
- package/lib/protocol-address.d.ts.map +1 -0
- package/lib/protocol-address.js +19 -10
- package/lib/protocol-address.js.map +1 -0
- package/lib/queue-job.d.ts +1 -0
- package/lib/queue-job.d.ts.map +1 -0
- package/lib/queue-job.js +1 -7
- package/lib/queue-job.js.map +1 -0
- package/lib/session-builder.d.ts +4 -3
- package/lib/session-builder.d.ts.map +1 -0
- package/lib/session-builder.js +17 -16
- package/lib/session-builder.js.map +1 -0
- package/lib/session-cipher.d.ts +5 -4
- package/lib/session-cipher.d.ts.map +1 -0
- package/lib/session-cipher.js +37 -36
- package/lib/session-cipher.js.map +1 -0
- package/lib/session-record.d.ts +6 -2
- package/lib/session-record.d.ts.map +1 -0
- package/lib/session-record.js +62 -39
- package/lib/session-record.js.map +1 -0
- package/lib/types.d.ts +4 -3
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +1 -0
- package/lib/types.js.map +1 -0
- package/lib/util.d.ts +1 -0
- package/lib/util.d.ts.map +1 -0
- package/lib/util.js +1 -0
- package/lib/util.js.map +1 -0
- package/lib/whisper-text-protocol.d.ts +85 -2
- package/lib/whisper-text-protocol.d.ts.map +1 -0
- package/lib/whisper-text-protocol.js +375 -335
- package/lib/whisper-text-protocol.js.map +1 -0
- package/package.json +46 -36
package/lib/memory-storage.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { timingSafeEqual } from
|
|
2
|
-
import { SessionRecord } from
|
|
1
|
+
import { timingSafeEqual } from "crypto";
|
|
2
|
+
import { SessionRecord } from "./session-record.js";
|
|
3
3
|
function safeEqual(a, b) {
|
|
4
4
|
if (a.byteLength !== b.byteLength) {
|
|
5
5
|
return false;
|
|
@@ -66,3 +66,4 @@ export class MemorySignalStorage {
|
|
|
66
66
|
this.signedPreKeys.set(id, keyPair);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
//# sourceMappingURL=memory-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-storage.js","sourceRoot":"","sources":["../src/memory-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AAGxC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAGhD,SAAS,SAAS,CAAC,CAAS,EAAE,CAAS;IACrC,IAAI,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU,EAAE,CAAC;QAClC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAC9B,CAAC;AAED,MAAM,OAAO,mBAAmB;IAQ9B,YAAY,eAAwB,EAAE,cAAsB;QALpD,aAAQ,GAAG,IAAI,GAAG,EAAyB,CAAA;QAC3C,YAAO,GAAG,IAAI,GAAG,EAAmB,CAAA;QACpC,kBAAa,GAAG,IAAI,GAAG,EAAmB,CAAA;QAC1C,sBAAiB,GAAG,IAAI,GAAG,EAAkB,CAAA;QAGnD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;IACtC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,EAAU;QAC1B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAC9B,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,EAAU,EAAE,OAAsB;QACnD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,UAAkB,EAAE,WAAmB,EAAE,UAAqB;QACpF,MAAM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C,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,oBAAoB;QACxB,OAAO,IAAI,CAAC,cAAc,CAAA;IAC5B,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,OAAO,IAAI,CAAC,eAAe,CAAA;IAC7B,CAAC;IAED,WAAW,CAAC,EAAU,EAAE,OAAgB;QACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAC/B,CAAC;IAED,iBAAiB,CAAC,EAAU,EAAE,OAAgB;QAC5C,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IACrC,CAAC;CACF"}
|
|
@@ -3,3 +3,4 @@ export declare class FingerprintGenerator {
|
|
|
3
3
|
constructor(iterations: number);
|
|
4
4
|
createFor(localIdentifier: string, localIdentityKey: ArrayBuffer, remoteIdentifier: string, remoteIdentityKey: ArrayBuffer): Promise<string>;
|
|
5
5
|
}
|
|
6
|
+
//# sourceMappingURL=numeric-fingerprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numeric-fingerprint.d.ts","sourceRoot":"","sources":["../src/numeric-fingerprint.ts"],"names":[],"mappings":"AAmDA,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,UAAU,CAAQ;gBAEd,UAAU,EAAE,MAAM;IAI9B,SAAS,CACP,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,WAAW,EAC7B,gBAAgB,EAAE,MAAM,EACxB,iBAAiB,EAAE,WAAW,GAC7B,OAAO,CAAC,MAAM,CAAC;CAenB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as crypto from
|
|
1
|
+
import * as crypto from "./crypto.js";
|
|
2
2
|
const VERSION = 0;
|
|
3
3
|
function iterateHash(data, key, count) {
|
|
4
4
|
let result = Buffer.from(data);
|
|
@@ -20,7 +20,7 @@ function getEncodedChunk(hash, offset) {
|
|
|
20
20
|
100000;
|
|
21
21
|
let s = chunk.toString();
|
|
22
22
|
while (s.length < 5) {
|
|
23
|
-
s =
|
|
23
|
+
s = "0" + s;
|
|
24
24
|
}
|
|
25
25
|
return s;
|
|
26
26
|
}
|
|
@@ -40,15 +40,16 @@ export class FingerprintGenerator {
|
|
|
40
40
|
this.iterations = iterations;
|
|
41
41
|
}
|
|
42
42
|
createFor(localIdentifier, localIdentityKey, remoteIdentifier, remoteIdentityKey) {
|
|
43
|
-
if (typeof localIdentifier !==
|
|
44
|
-
typeof remoteIdentifier !==
|
|
43
|
+
if (typeof localIdentifier !== "string" ||
|
|
44
|
+
typeof remoteIdentifier !== "string" ||
|
|
45
45
|
!(localIdentityKey instanceof ArrayBuffer) ||
|
|
46
46
|
!(remoteIdentityKey instanceof ArrayBuffer)) {
|
|
47
|
-
throw new Error(
|
|
47
|
+
throw new Error("Invalid arguments");
|
|
48
48
|
}
|
|
49
49
|
return Promise.all([
|
|
50
50
|
getDisplayStringFor(localIdentifier, localIdentityKey, this.iterations),
|
|
51
51
|
getDisplayStringFor(remoteIdentifier, remoteIdentityKey, this.iterations)
|
|
52
|
-
]).then(fingerprints => fingerprints.sort().join(
|
|
52
|
+
]).then(fingerprints => fingerprints.sort().join(""));
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
+
//# sourceMappingURL=numeric-fingerprint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numeric-fingerprint.js","sourceRoot":"","sources":["../src/numeric-fingerprint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,UAAU,CAAA;AAElC,MAAM,OAAO,GAAG,CAAC,CAAA;AAEjB,SAAS,WAAW,CAAC,IAAiB,EAAE,GAAgB,EAAE,KAAa;IACnE,IAAI,MAAM,GAAW,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAExC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EA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C,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;IACvD,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prekey-bundle-validator.d.ts","sourceRoot":"","sources":["../src/prekey-bundle-validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AA8B9C,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CA2BxE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PreKeyError } from
|
|
1
|
+
import { PreKeyError } from "./errors.js";
|
|
2
2
|
const MIN_REGISTRATION_ID = 1;
|
|
3
3
|
const MAX_REGISTRATION_ID = 0x3fff;
|
|
4
4
|
const IDENTITY_KEY_LENGTH = 33;
|
|
@@ -6,7 +6,7 @@ const PUBLIC_KEY_LENGTH = 33;
|
|
|
6
6
|
const SIGNATURE_LENGTH = 64;
|
|
7
7
|
const MAX_KEY_ID = 0xffffff;
|
|
8
8
|
function isNonNegativeInteger(n) {
|
|
9
|
-
return typeof n ===
|
|
9
|
+
return typeof n === "number" && Number.isInteger(n) && n >= 0;
|
|
10
10
|
}
|
|
11
11
|
function assertBufferLength(value, length, field) {
|
|
12
12
|
if (!(value instanceof Uint8Array)) {
|
|
@@ -22,23 +22,24 @@ function assertKeyId(value, field) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
export function assertValidDeviceKeyBundle(bundle) {
|
|
25
|
-
if (!bundle || typeof bundle !==
|
|
26
|
-
throw new PreKeyError(
|
|
25
|
+
if (!bundle || typeof bundle !== "object") {
|
|
26
|
+
throw new PreKeyError("Device key bundle must be an object");
|
|
27
27
|
}
|
|
28
28
|
if (!isNonNegativeInteger(bundle.registrationId) ||
|
|
29
29
|
bundle.registrationId < MIN_REGISTRATION_ID ||
|
|
30
30
|
bundle.registrationId > MAX_REGISTRATION_ID) {
|
|
31
31
|
throw new PreKeyError(`Invalid registrationId: ${String(bundle.registrationId)}`);
|
|
32
32
|
}
|
|
33
|
-
assertBufferLength(bundle.identityKey, IDENTITY_KEY_LENGTH,
|
|
34
|
-
if (!bundle.signedPreKey || typeof bundle.signedPreKey !==
|
|
35
|
-
throw new PreKeyError(
|
|
33
|
+
assertBufferLength(bundle.identityKey, IDENTITY_KEY_LENGTH, "identityKey");
|
|
34
|
+
if (!bundle.signedPreKey || typeof bundle.signedPreKey !== "object") {
|
|
35
|
+
throw new PreKeyError("Missing signedPreKey");
|
|
36
36
|
}
|
|
37
|
-
assertKeyId(bundle.signedPreKey.keyId,
|
|
38
|
-
assertBufferLength(bundle.signedPreKey.publicKey, PUBLIC_KEY_LENGTH,
|
|
39
|
-
assertBufferLength(bundle.signedPreKey.signature, SIGNATURE_LENGTH,
|
|
37
|
+
assertKeyId(bundle.signedPreKey.keyId, "signedPreKey.keyId");
|
|
38
|
+
assertBufferLength(bundle.signedPreKey.publicKey, PUBLIC_KEY_LENGTH, "signedPreKey.publicKey");
|
|
39
|
+
assertBufferLength(bundle.signedPreKey.signature, SIGNATURE_LENGTH, "signedPreKey.signature");
|
|
40
40
|
if (bundle.preKey) {
|
|
41
|
-
assertKeyId(bundle.preKey.keyId,
|
|
42
|
-
assertBufferLength(bundle.preKey.publicKey, PUBLIC_KEY_LENGTH,
|
|
41
|
+
assertKeyId(bundle.preKey.keyId, "preKey.keyId");
|
|
42
|
+
assertBufferLength(bundle.preKey.publicKey, PUBLIC_KEY_LENGTH, "preKey.publicKey");
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
//# sourceMappingURL=prekey-bundle-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prekey-bundle-validator.js","sourceRoot":"","sources":["../src/prekey-bundle-validator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEt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,cAAc,GAAG,mBAAmB;QAC3C,MAAM,CAAC,cAAc,GAAG,mBAAmB,EAC3C,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,2BAA2B,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,CAAA;IACnF,CAAC;IAED,kBAAkB,CAAC,MAAM,CAAC,WAAW,EAAE,mBAAmB,EAAE,aAAa,CAAC,CAAA;IAE1E,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;QACpE,MAAM,IAAI,WAAW,CAAC,sBAAsB,CAAC,CAAA;IAC/C,CAAC;IAED,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAA;IAC5D,kBAAkB,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,iBAAiB,EAAE,wBAAwB,CAAC,CAAA;IAC9F,kBAAkB,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,gBAAgB,EAAE,wBAAwB,CAAC,CAAA;IAE7F,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAAA;QAChD,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,CAAA;IACpF,CAAC;AACH,CAAC"}
|
package/lib/protobufs.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { textsecure } from
|
|
1
|
+
import { textsecure } from "./whisper-text-protocol.js";
|
|
2
2
|
export declare const WhisperMessage: typeof textsecure.WhisperMessage;
|
|
3
3
|
export declare const PreKeyWhisperMessage: typeof textsecure.PreKeyWhisperMessage;
|
|
4
4
|
export type WhisperMessage = textsecure.WhisperMessage;
|
|
5
5
|
export type PreKeyWhisperMessage = textsecure.PreKeyWhisperMessage;
|
|
6
|
+
//# sourceMappingURL=protobufs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobufs.d.ts","sourceRoot":"","sources":["../src/protobufs.ts"],"names":[],"mappings":"AAAA,OAAa,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAE7D,eAAO,MAAM,cAAc,kCAAiC,CAAA;AAC5D,eAAO,MAAM,oBAAoB,wCAAuC,CAAA;AACxE,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,cAAc,CAAA;AACtD,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAAC,oBAAoB,CAAA"}
|
package/lib/protobufs.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import root, { textsecure } from
|
|
1
|
+
import root, { textsecure } from "./whisper-text-protocol.js";
|
|
2
2
|
export const WhisperMessage = root.textsecure.WhisperMessage;
|
|
3
3
|
export const PreKeyWhisperMessage = root.textsecure.PreKeyWhisperMessage;
|
|
4
|
+
//# sourceMappingURL=protobufs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protobufs.js","sourceRoot":"","sources":["../src/protobufs.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAE7D,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,CAAA;AAC5D,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-address.d.ts","sourceRoot":"","sources":["../src/protocol-address.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAe;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAEvB,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,eAAe;gBAmBxC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAkBxC,QAAQ,IAAI,MAAM;IAIlB,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;CAO5B"}
|
package/lib/protocol-address.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
export class ProtocolAddress {
|
|
2
2
|
static from(encodedAddress) {
|
|
3
|
-
if (typeof encodedAddress !==
|
|
4
|
-
throw new Error(
|
|
3
|
+
if (typeof encodedAddress !== "string") {
|
|
4
|
+
throw new Error("Invalid address encoding");
|
|
5
5
|
}
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const sep = encodedAddress.lastIndexOf(".");
|
|
7
|
+
if (sep === -1) {
|
|
8
|
+
throw new Error("Invalid address encoding");
|
|
9
|
+
}
|
|
10
|
+
const id = encodedAddress.slice(0, sep);
|
|
11
|
+
const deviceIdPart = encodedAddress.slice(sep + 1);
|
|
12
|
+
if (!/^\d+$/.test(deviceIdPart)) {
|
|
13
|
+
throw new Error("Invalid address encoding");
|
|
14
|
+
}
|
|
15
|
+
return new ProtocolAddress(id, parseInt(deviceIdPart, 10));
|
|
8
16
|
}
|
|
9
17
|
constructor(id, deviceId) {
|
|
10
|
-
if (typeof id !==
|
|
11
|
-
throw new TypeError(
|
|
18
|
+
if (typeof id !== "string") {
|
|
19
|
+
throw new TypeError("id required for addr");
|
|
12
20
|
}
|
|
13
|
-
if (id.indexOf(
|
|
14
|
-
throw new TypeError(
|
|
21
|
+
if (id.indexOf(".") !== -1) {
|
|
22
|
+
throw new TypeError("encoded addr detected");
|
|
15
23
|
}
|
|
16
24
|
this.id = id;
|
|
17
|
-
if (typeof deviceId !==
|
|
18
|
-
throw new TypeError(
|
|
25
|
+
if (typeof deviceId !== "number") {
|
|
26
|
+
throw new TypeError("number required for deviceId");
|
|
19
27
|
}
|
|
20
28
|
this.deviceId = deviceId;
|
|
21
29
|
}
|
|
@@ -29,3 +37,4 @@ export class ProtocolAddress {
|
|
|
29
37
|
return other.id === this.id && other.deviceId === this.deviceId;
|
|
30
38
|
}
|
|
31
39
|
}
|
|
40
|
+
//# sourceMappingURL=protocol-address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-address.js","sourceRoot":"","sources":["../src/protocol-address.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,eAAe;IAI1B,MAAM,CAAC,IAAI,CAAC,cAAsB;QAChC,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAC7C,CAAC;QAED,MAAM,GAAG,GAAG,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAC7C,CAAC;QAED,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;QACvC,MAAM,YAAY,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;QAClD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAC7C,CAAC;QAED,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,QAAQ,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,CAAA;IAC5D,CAAC;IAED,YAAY,EAAU,EAAE,QAAgB;QACtC,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,SAAS,CAAC,sBAAsB,CAAC,CAAA;QAC7C,CAAC;QAED,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,SAAS,CAAC,uBAAuB,CAAC,CAAA;QAC9C,CAAC;QAED,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QAEZ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACjC,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAA;QACrD,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAA;IACtC,CAAC;IAED,EAAE,CAAC,KAAc;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,eAAe,CAAC,EAAE,CAAC;YACxC,OAAO,KAAK,CAAA;QACd,CAAC;QAED,OAAO,KAAK,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,QAAQ,CAAA;IACjE,CAAC;CACF"}
|
package/lib/queue-job.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-job.d.ts","sourceRoot":"","sources":["../src/queue-job.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,CAAC,CAAC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,CAAA;AAoCpC,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAqBhF"}
|
package/lib/queue-job.js
CHANGED
|
@@ -24,13 +24,6 @@ async function _asyncQueueExecutor(queue, cleanup) {
|
|
|
24
24
|
cleanup();
|
|
25
25
|
}
|
|
26
26
|
export function queueJob(bucket, awaitable) {
|
|
27
|
-
const namedAwaitable = awaitable;
|
|
28
|
-
if (!namedAwaitable.name) {
|
|
29
|
-
Object.defineProperty(namedAwaitable, 'name', { writable: true });
|
|
30
|
-
if (typeof bucket === 'string') {
|
|
31
|
-
namedAwaitable.name = bucket;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
27
|
let inactive = false;
|
|
35
28
|
if (!_queueAsyncBuckets.has(bucket)) {
|
|
36
29
|
_queueAsyncBuckets.set(bucket, []);
|
|
@@ -47,3 +40,4 @@ export function queueJob(bucket, awaitable) {
|
|
|
47
40
|
}
|
|
48
41
|
return job;
|
|
49
42
|
}
|
|
43
|
+
//# sourceMappingURL=queue-job.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue-job.js","sourceRoot":"","sources":["../src/queue-job.ts"],"names":[],"mappings":"AAQA,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAwB,CAAA;AAC1D,MAAM,QAAQ,GAAG,GAAG,CAAA;AAEpB,KAAK,UAAU,mBAAmB,CAAC,KAAkB,EAAE,OAAmB;IACxE,IAAI,IAAI,GAAG,CAAC,CAAA;IAEZ,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QAC9C,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;YAClC,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAE,CAAA;YACrB,IAAI,CAAC;gBACH,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,SAAS,EAAE,CAAC,CAAA;YACpC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;YACf,CAAC;QACH,CAAC;QAED,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YACzB,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;YACtB,IAAI,GAAG,CAAC,CAAA;QACV,CAAC;aAAM,CAAC;YACN,MAAK;QACP,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAA;AACX,CAAC;AAED,MAAM,UAAU,QAAQ,CAAI,MAAe,EAAE,SAAuB;IAClE,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QACpC,kBAAkB,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QAClC,QAAQ,GAAG,IAAI,CAAA;IACjB,CAAC;IAED,MAAM,KAAK,GAAG,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAE,CAAA;IAC7C,MAAM,GAAG,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAC7C,KAAK,CAAC,IAAI,CAAC;QACT,SAAS,EAAE,SAA+B;QAC1C,OAAO,EAAE,OAAmC;QAC5C,MAAM;KACP,CAAC,CACH,CAAA;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;IACrE,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
package/lib/session-builder.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ProtocolAddress } from
|
|
2
|
-
import { SessionRecord } from
|
|
3
|
-
import type { DeviceKeyBundle, IncomingPreKeyMessage, SignalStorage } from
|
|
1
|
+
import type { ProtocolAddress } from "./protocol-address.js";
|
|
2
|
+
import { SessionRecord } from "./session-record.js";
|
|
3
|
+
import type { DeviceKeyBundle, IncomingPreKeyMessage, SignalStorage } from "./types.js";
|
|
4
4
|
export declare class SessionBuilder {
|
|
5
5
|
private addr;
|
|
6
6
|
private storage;
|
|
@@ -10,3 +10,4 @@ export declare class SessionBuilder {
|
|
|
10
10
|
private initSession;
|
|
11
11
|
private calculateSendingRatchet;
|
|
12
12
|
}
|
|
13
|
+
//# sourceMappingURL=session-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-builder.d.ts","sourceRoot":"","sources":["../src/session-builder.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAGzD,OAAO,EAAgB,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEpF,qBAAa,cAAc;IACzB,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,OAAO,CAAe;gBAElB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,eAAe;IAK9D,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDpD,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;YA0CxF,WAAW;IAmFzB,OAAO,CAAC,uBAAuB;CAgB9B"}
|
package/lib/session-builder.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { BaseKeyType } from
|
|
2
|
-
import { ChainType } from
|
|
3
|
-
import * as crypto from
|
|
4
|
-
import * as curve from
|
|
5
|
-
import { Direction } from
|
|
6
|
-
import * as errors from
|
|
7
|
-
import { queueJob } from
|
|
8
|
-
import { assertValidDeviceKeyBundle } from
|
|
9
|
-
import { SessionRecord } from
|
|
1
|
+
import { BaseKeyType } from "./base-key-type.js";
|
|
2
|
+
import { ChainType } from "./chain-type.js";
|
|
3
|
+
import * as crypto from "./crypto.js";
|
|
4
|
+
import * as curve from "./curve.js";
|
|
5
|
+
import { Direction } from "./direction.js";
|
|
6
|
+
import * as errors from "./errors.js";
|
|
7
|
+
import { queueJob } from "./queue-job.js";
|
|
8
|
+
import { assertValidDeviceKeyBundle } from "./prekey-bundle-validator.js";
|
|
9
|
+
import { SessionEntry, SessionRecord } from "./session-record.js";
|
|
10
10
|
export class SessionBuilder {
|
|
11
11
|
constructor(storage, protocolAddress) {
|
|
12
12
|
this.addr = protocolAddress;
|
|
@@ -20,7 +20,7 @@ export class SessionBuilder {
|
|
|
20
20
|
throw new errors.UntrustedIdentityKeyError(this.addr.id, device.identityKey);
|
|
21
21
|
}
|
|
22
22
|
if (!curve.verifySignature(device.identityKey, device.signedPreKey.publicKey, device.signedPreKey.signature)) {
|
|
23
|
-
throw new Error(
|
|
23
|
+
throw new Error("Signature validation failed");
|
|
24
24
|
}
|
|
25
25
|
const baseKey = curve.generateKeyPair();
|
|
26
26
|
const devicePreKey = device.preKey && device.preKey.publicKey;
|
|
@@ -58,12 +58,12 @@ export class SessionBuilder {
|
|
|
58
58
|
if (message.preKeyId !== undefined) {
|
|
59
59
|
preKeyPair = await this.storage.loadPreKey(message.preKeyId);
|
|
60
60
|
if (!preKeyPair) {
|
|
61
|
-
throw new errors.PreKeyError(
|
|
61
|
+
throw new errors.PreKeyError("Invalid PreKey ID");
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
const signedPreKeyPair = await this.storage.loadSignedPreKey(message.signedPreKeyId);
|
|
65
65
|
if (!signedPreKeyPair) {
|
|
66
|
-
throw new errors.PreKeyError(
|
|
66
|
+
throw new errors.PreKeyError("Missing SignedPreKey");
|
|
67
67
|
}
|
|
68
68
|
const existingOpenSession = record.getOpenSession();
|
|
69
69
|
if (existingOpenSession) {
|
|
@@ -77,13 +77,13 @@ export class SessionBuilder {
|
|
|
77
77
|
let theirSignedPubKey = theirSignedPubKeyInput;
|
|
78
78
|
if (isInitiator) {
|
|
79
79
|
if (ourSignedKey) {
|
|
80
|
-
throw new Error(
|
|
80
|
+
throw new Error("Invalid call to initSession");
|
|
81
81
|
}
|
|
82
82
|
ourSignedKey = ourEphemeralKey;
|
|
83
83
|
}
|
|
84
84
|
else {
|
|
85
85
|
if (theirSignedPubKey) {
|
|
86
|
-
throw new Error(
|
|
86
|
+
throw new Error("Invalid call to initSession");
|
|
87
87
|
}
|
|
88
88
|
theirSignedPubKey = theirEphemeralPubKey;
|
|
89
89
|
}
|
|
@@ -114,7 +114,7 @@ export class SessionBuilder {
|
|
|
114
114
|
const a4 = curve.calculateAgreement(theirEphemeralPubKey, ourEphemeralKey.privKey);
|
|
115
115
|
sharedSecret.set(new Uint8Array(a4), 32 * 4);
|
|
116
116
|
}
|
|
117
|
-
const masterKey = crypto.deriveSecrets(Buffer.from(sharedSecret), Buffer.alloc(32), Buffer.from(
|
|
117
|
+
const masterKey = crypto.deriveSecrets(Buffer.from(sharedSecret), Buffer.alloc(32), Buffer.from("WhisperText"));
|
|
118
118
|
const session = SessionRecord.createEntry();
|
|
119
119
|
session.registrationId = registrationId;
|
|
120
120
|
session.currentRatchet = {
|
|
@@ -139,7 +139,7 @@ export class SessionBuilder {
|
|
|
139
139
|
calculateSendingRatchet(session, remoteKey) {
|
|
140
140
|
const ratchet = session.currentRatchet;
|
|
141
141
|
const sharedSecret = curve.calculateAgreement(remoteKey, ratchet.ephemeralKeyPair.privKey);
|
|
142
|
-
const masterKey = crypto.deriveSecrets(sharedSecret, ratchet.rootKey, Buffer.from(
|
|
142
|
+
const masterKey = crypto.deriveSecrets(sharedSecret, ratchet.rootKey, Buffer.from("WhisperRatchet"));
|
|
143
143
|
session.addChain(ratchet.ephemeralKeyPair.pubKey, {
|
|
144
144
|
messageKeys: {},
|
|
145
145
|
chainKey: {
|
|
@@ -151,3 +151,4 @@ export class SessionBuilder {
|
|
|
151
151
|
ratchet.rootKey = masterKey[0];
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
+
//# sourceMappingURL=session-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-builder.js","sourceRoot":"","sources":["../src/session-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAA;AAClC,OAAO,KAAK,KAAK,MAAM,SAAS,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,7 +1,7 @@
|
|
|
1
|
-
import { ProtocolAddress } from
|
|
2
|
-
import type { Chain, SessionEntry } from
|
|
3
|
-
import { SessionRecord } from
|
|
4
|
-
import type { EncryptedMessage, SignalStorage } from
|
|
1
|
+
import { ProtocolAddress } from "./protocol-address.js";
|
|
2
|
+
import type { Chain, SessionEntry } from "./session-record.js";
|
|
3
|
+
import { SessionRecord } from "./session-record.js";
|
|
4
|
+
import type { EncryptedMessage, SignalStorage } from "./types.js";
|
|
5
5
|
export declare class SessionCipher {
|
|
6
6
|
private addr;
|
|
7
7
|
private storage;
|
|
@@ -27,3 +27,4 @@ export declare class SessionCipher {
|
|
|
27
27
|
hasOpenSession(): Promise<boolean>;
|
|
28
28
|
closeOpenSession(): Promise<void>;
|
|
29
29
|
}
|
|
30
|
+
//# sourceMappingURL=session-cipher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-cipher.d.ts","sourceRoot":"","sources":["../src/session-cipher.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAKpD,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAc9D,qBAAa,aAAa;IACxB,OAAO,CAAC,IAAI,CAAiB;IAC7B,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,oBAAoB,CAAC,CAAQ;gBAGnC,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,eAAe,EAChC,oBAAoB,GAAE,MAAM,GAAG,SAA4C;IAW7E,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,gBAAgB;IAIxB,QAAQ,IAAI,MAAM;IAIZ,SAAS,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAS/C,WAAW,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IASjD,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAIpD,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA8FpD,mBAAmB,CACvB,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,YAAY,EAAE,GACvB,OAAO,CAAC;QAAE,OAAO,EAAE,YAAY,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAuBlD,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBxD,2BAA2B,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAiD9D,uBAAuB,CAAC,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAyDhG,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAiBpD,gBAAgB,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI;IA0BzF,gBAAgB,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAkB5E,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAWlC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;CAYvC"}
|
package/lib/session-cipher.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ChainType } from
|
|
2
|
-
import * as crypto from
|
|
3
|
-
import * as curve from
|
|
4
|
-
import { Direction } from
|
|
5
|
-
import * as errors from
|
|
6
|
-
import { ProtocolAddress } from
|
|
7
|
-
import * as protobufs from
|
|
8
|
-
import { queueJob } from
|
|
9
|
-
import { wipeBuffer, wipeBuffers } from
|
|
10
|
-
import { SessionBuilder } from
|
|
11
|
-
import { SessionRecord } from
|
|
1
|
+
import { ChainType } from "./chain-type.js";
|
|
2
|
+
import * as crypto from "./crypto.js";
|
|
3
|
+
import * as curve from "./curve.js";
|
|
4
|
+
import { Direction } from "./direction.js";
|
|
5
|
+
import * as errors from "./errors.js";
|
|
6
|
+
import { ProtocolAddress } from "./protocol-address.js";
|
|
7
|
+
import * as protobufs from "./protobufs.js";
|
|
8
|
+
import { queueJob } from "./queue-job.js";
|
|
9
|
+
import { wipeBuffer, wipeBuffers } from "./util.js";
|
|
10
|
+
import { SessionBuilder } from "./session-builder.js";
|
|
11
|
+
import { SessionRecord } from "./session-record.js";
|
|
12
12
|
const VERSION = 3;
|
|
13
13
|
const DEFAULT_STALE_SESSION_MAX_AGE_MS = 90 * 24 * 60 * 60 * 1000;
|
|
14
14
|
const MIN_MESSAGE_LENGTH = 1 + 1 + 8;
|
|
@@ -21,7 +21,7 @@ function assertBuffer(value) {
|
|
|
21
21
|
export class SessionCipher {
|
|
22
22
|
constructor(storage, protocolAddress, staleSessionMaxAgeMs = DEFAULT_STALE_SESSION_MAX_AGE_MS) {
|
|
23
23
|
if (!(protocolAddress instanceof ProtocolAddress)) {
|
|
24
|
-
throw new TypeError(
|
|
24
|
+
throw new TypeError("protocolAddress must be a ProtocolAddress");
|
|
25
25
|
}
|
|
26
26
|
this.addr = protocolAddress;
|
|
27
27
|
this.storage = storage;
|
|
@@ -29,7 +29,7 @@ export class SessionCipher {
|
|
|
29
29
|
}
|
|
30
30
|
_encodeTupleByte(number1, number2) {
|
|
31
31
|
if (number1 > 15 || number2 > 15) {
|
|
32
|
-
throw TypeError(
|
|
32
|
+
throw TypeError("Numbers must be 4 bits or less");
|
|
33
33
|
}
|
|
34
34
|
return (number1 << 4) | number2;
|
|
35
35
|
}
|
|
@@ -42,7 +42,7 @@ export class SessionCipher {
|
|
|
42
42
|
async getRecord() {
|
|
43
43
|
const record = await this.storage.loadSession(this.addr.toString());
|
|
44
44
|
if (record && !(record instanceof SessionRecord)) {
|
|
45
|
-
throw new TypeError(
|
|
45
|
+
throw new TypeError("SessionRecord type expected from loadSession");
|
|
46
46
|
}
|
|
47
47
|
return record;
|
|
48
48
|
}
|
|
@@ -62,11 +62,11 @@ export class SessionCipher {
|
|
|
62
62
|
return await this.queueJob(async () => {
|
|
63
63
|
const record = await this.getRecord();
|
|
64
64
|
if (!record) {
|
|
65
|
-
throw new errors.SessionError(
|
|
65
|
+
throw new errors.SessionError("No sessions");
|
|
66
66
|
}
|
|
67
67
|
const session = record.getOpenSession();
|
|
68
68
|
if (!session) {
|
|
69
|
-
throw new errors.SessionError(
|
|
69
|
+
throw new errors.SessionError("No open session");
|
|
70
70
|
}
|
|
71
71
|
const remoteIdentityKey = session.indexInfo.remoteIdentityKey;
|
|
72
72
|
if (!(await this.storage.isTrustedIdentity(this.addr.id, remoteIdentityKey, Direction.SENDING))) {
|
|
@@ -74,13 +74,13 @@ export class SessionCipher {
|
|
|
74
74
|
}
|
|
75
75
|
const chain = session.getChain(session.currentRatchet.ephemeralKeyPair.pubKey);
|
|
76
76
|
if (!chain) {
|
|
77
|
-
throw new errors.SessionError(
|
|
77
|
+
throw new errors.SessionError("No chain found for current ratchet");
|
|
78
78
|
}
|
|
79
79
|
if (chain.chainType === ChainType.RECEIVING) {
|
|
80
|
-
throw new errors.SessionError(
|
|
80
|
+
throw new errors.SessionError("Tried to encrypt on a receiving chain");
|
|
81
81
|
}
|
|
82
82
|
this.fillMessageKeys(chain, chain.chainKey.counter + 1);
|
|
83
|
-
const keys = crypto.deriveSecrets(chain.messageKeys[chain.chainKey.counter], Buffer.alloc(32), Buffer.from(
|
|
83
|
+
const keys = crypto.deriveSecrets(chain.messageKeys[chain.chainKey.counter], Buffer.alloc(32), Buffer.from("WhisperMessageKeys"));
|
|
84
84
|
wipeBuffer(chain.messageKeys[chain.chainKey.counter]);
|
|
85
85
|
delete chain.messageKeys[chain.chainKey.counter];
|
|
86
86
|
const msg = protobufs.WhisperMessage.create();
|
|
@@ -133,7 +133,7 @@ export class SessionCipher {
|
|
|
133
133
|
}
|
|
134
134
|
async decryptWithSessions(data, sessions) {
|
|
135
135
|
if (!sessions.length) {
|
|
136
|
-
throw new errors.SessionError(
|
|
136
|
+
throw new errors.SessionError("No sessions available");
|
|
137
137
|
}
|
|
138
138
|
const errs = [];
|
|
139
139
|
for (const session of sessions) {
|
|
@@ -150,14 +150,14 @@ export class SessionCipher {
|
|
|
150
150
|
errs.push(e);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
throw Object.assign(new errors.SessionError(
|
|
153
|
+
throw Object.assign(new errors.SessionError("No matching sessions found for message"), { errors: errs });
|
|
154
154
|
}
|
|
155
155
|
async decryptWhisperMessage(data) {
|
|
156
156
|
assertBuffer(data);
|
|
157
157
|
return await this.queueJob(async () => {
|
|
158
158
|
const record = await this.getRecord();
|
|
159
159
|
if (!record) {
|
|
160
|
-
throw new errors.SessionError(
|
|
160
|
+
throw new errors.SessionError("No session record");
|
|
161
161
|
}
|
|
162
162
|
const result = await this.decryptWithSessions(data, record.getSessions());
|
|
163
163
|
const remoteIdentityKey = result.session.indexInfo.remoteIdentityKey;
|
|
@@ -174,18 +174,18 @@ export class SessionCipher {
|
|
|
174
174
|
async decryptPreKeyWhisperMessage(data) {
|
|
175
175
|
assertBuffer(data);
|
|
176
176
|
if (data.byteLength < MIN_MESSAGE_LENGTH) {
|
|
177
|
-
throw new errors.SessionError(
|
|
177
|
+
throw new errors.SessionError("Message too short");
|
|
178
178
|
}
|
|
179
179
|
const versions = this._decodeTupleByte(data[0]);
|
|
180
180
|
if (versions[1] > 3 || versions[0] < 3) {
|
|
181
|
-
throw new Error(
|
|
181
|
+
throw new Error("Incompatible version number on PreKeyWhisperMessage");
|
|
182
182
|
}
|
|
183
183
|
return await this.queueJob(async () => {
|
|
184
184
|
let record = await this.getRecord();
|
|
185
185
|
const preKeyProto = protobufs.PreKeyWhisperMessage.decode(data.slice(1));
|
|
186
186
|
if (!record) {
|
|
187
187
|
if (preKeyProto.registrationId == null) {
|
|
188
|
-
throw new errors.PreKeyError(
|
|
188
|
+
throw new errors.PreKeyError("No registrationId");
|
|
189
189
|
}
|
|
190
190
|
record = new SessionRecord();
|
|
191
191
|
}
|
|
@@ -200,7 +200,7 @@ export class SessionCipher {
|
|
|
200
200
|
});
|
|
201
201
|
const session = record.getSession(Buffer.from(preKeyProto.baseKey));
|
|
202
202
|
if (!session) {
|
|
203
|
-
throw new errors.SessionError(
|
|
203
|
+
throw new errors.SessionError("No session established for incoming PreKeyWhisperMessage");
|
|
204
204
|
}
|
|
205
205
|
const plaintext = await this.doDecryptWhisperMessage(Buffer.from(preKeyProto.message), session);
|
|
206
206
|
await this.storeRecord(record);
|
|
@@ -213,32 +213,32 @@ export class SessionCipher {
|
|
|
213
213
|
async doDecryptWhisperMessage(messageBuffer, session) {
|
|
214
214
|
assertBuffer(messageBuffer);
|
|
215
215
|
if (!session) {
|
|
216
|
-
throw new TypeError(
|
|
216
|
+
throw new TypeError("session required");
|
|
217
217
|
}
|
|
218
218
|
if (messageBuffer.byteLength < MIN_MESSAGE_LENGTH) {
|
|
219
|
-
throw new errors.SessionError(
|
|
219
|
+
throw new errors.SessionError("Message too short");
|
|
220
220
|
}
|
|
221
221
|
const versions = this._decodeTupleByte(messageBuffer[0]);
|
|
222
222
|
if (versions[1] > 3 || versions[0] < 3) {
|
|
223
|
-
throw new Error(
|
|
223
|
+
throw new Error("Incompatible version number on WhisperMessage");
|
|
224
224
|
}
|
|
225
225
|
const messageProto = messageBuffer.slice(1, -8);
|
|
226
226
|
const message = protobufs.WhisperMessage.decode(messageProto);
|
|
227
227
|
this.maybeStepRatchet(session, Buffer.from(message.ephemeralKey), message.previousCounter);
|
|
228
228
|
const chain = session.getChain(Buffer.from(message.ephemeralKey));
|
|
229
229
|
if (!chain) {
|
|
230
|
-
throw new errors.SessionError(
|
|
230
|
+
throw new errors.SessionError("No chain found for message ephemeral key");
|
|
231
231
|
}
|
|
232
232
|
if (chain.chainType === ChainType.SENDING) {
|
|
233
|
-
throw new errors.SessionError(
|
|
233
|
+
throw new errors.SessionError("Tried to decrypt on a sending chain");
|
|
234
234
|
}
|
|
235
235
|
this.fillMessageKeys(chain, message.counter);
|
|
236
236
|
if (!Object.prototype.hasOwnProperty.call(chain.messageKeys, message.counter)) {
|
|
237
|
-
throw new errors.MessageCounterError(
|
|
237
|
+
throw new errors.MessageCounterError("Key used already or never filled");
|
|
238
238
|
}
|
|
239
239
|
const messageKey = chain.messageKeys[message.counter];
|
|
240
240
|
delete chain.messageKeys[message.counter];
|
|
241
|
-
const keys = crypto.deriveSecrets(messageKey, Buffer.alloc(32), Buffer.from(
|
|
241
|
+
const keys = crypto.deriveSecrets(messageKey, Buffer.alloc(32), Buffer.from("WhisperMessageKeys"));
|
|
242
242
|
wipeBuffer(messageKey);
|
|
243
243
|
const ourIdentityKey = await this.storage.getOurIdentity();
|
|
244
244
|
const macInput = Buffer.alloc(messageProto.byteLength + 33 * 2 + 1);
|
|
@@ -255,10 +255,10 @@ export class SessionCipher {
|
|
|
255
255
|
fillMessageKeys(chain, counter) {
|
|
256
256
|
while (chain.chainKey.counter < counter) {
|
|
257
257
|
if (counter - chain.chainKey.counter > 2000) {
|
|
258
|
-
throw new errors.SessionError(
|
|
258
|
+
throw new errors.SessionError("Over 2000 messages into the future!");
|
|
259
259
|
}
|
|
260
260
|
if (chain.chainKey.key === undefined) {
|
|
261
|
-
throw new errors.SessionError(
|
|
261
|
+
throw new errors.SessionError("Chain closed");
|
|
262
262
|
}
|
|
263
263
|
const key = chain.chainKey.key;
|
|
264
264
|
chain.messageKeys[chain.chainKey.counter + 1] = crypto.calculateMAC(key, Buffer.from([1]));
|
|
@@ -290,7 +290,7 @@ export class SessionCipher {
|
|
|
290
290
|
calculateRatchet(session, remoteKey, sending) {
|
|
291
291
|
const ratchet = session.currentRatchet;
|
|
292
292
|
const sharedSecret = curve.calculateAgreement(remoteKey, ratchet.ephemeralKeyPair.privKey);
|
|
293
|
-
const masterKey = crypto.deriveSecrets(sharedSecret, ratchet.rootKey, Buffer.from(
|
|
293
|
+
const masterKey = crypto.deriveSecrets(sharedSecret, ratchet.rootKey, Buffer.from("WhisperRatchet"), 2);
|
|
294
294
|
const chainKey = sending ? ratchet.ephemeralKeyPair.pubKey : remoteKey;
|
|
295
295
|
session.addChain(chainKey, {
|
|
296
296
|
messageKeys: {},
|
|
@@ -324,3 +324,4 @@ export class SessionCipher {
|
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
+
//# sourceMappingURL=session-cipher.js.map
|