@unknownncat/swt-libsignal 1.0.4

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.
Files changed (55) hide show
  1. package/dist/base_key_type.d.ts +5 -0
  2. package/dist/base_key_type.js +4 -0
  3. package/dist/chain_type.d.ts +5 -0
  4. package/dist/chain_type.js +4 -0
  5. package/dist/crypto.d.ts +2 -0
  6. package/dist/crypto.js +95 -0
  7. package/dist/curve.d.ts +5 -0
  8. package/dist/curve.js +67 -0
  9. package/dist/fingerprint.d.ts +5 -0
  10. package/dist/fingerprint.js +76 -0
  11. package/dist/generated/WhisperTextProtocol.d.ts +49 -0
  12. package/dist/generated/WhisperTextProtocol.js +199 -0
  13. package/dist/index.d.ts +20 -0
  14. package/dist/index.js +13 -0
  15. package/dist/job_queue.d.ts +3 -0
  16. package/dist/job_queue.js +48 -0
  17. package/dist/key-helper.d.ts +14 -0
  18. package/dist/key-helper.js +42 -0
  19. package/dist/protobuf.d.ts +1 -0
  20. package/dist/protobuf.js +2 -0
  21. package/dist/protocol_address.d.ts +9 -0
  22. package/dist/protocol_address.js +50 -0
  23. package/dist/session/builder/index.d.ts +2 -0
  24. package/dist/session/builder/index.js +2 -0
  25. package/dist/session/builder/session-builder.d.ts +13 -0
  26. package/dist/session/builder/session-builder.js +148 -0
  27. package/dist/session/builder/types.d.ts +38 -0
  28. package/dist/session/builder/types.js +1 -0
  29. package/dist/session/cipher/encoding.d.ts +13 -0
  30. package/dist/session/cipher/encoding.js +135 -0
  31. package/dist/session/cipher/index.d.ts +3 -0
  32. package/dist/session/cipher/index.js +3 -0
  33. package/dist/session/cipher/session-cipher.d.ts +26 -0
  34. package/dist/session/cipher/session-cipher.js +300 -0
  35. package/dist/session/cipher/types.d.ts +47 -0
  36. package/dist/session/cipher/types.js +1 -0
  37. package/dist/session/constants.d.ts +3 -0
  38. package/dist/session/constants.js +3 -0
  39. package/dist/session/index.d.ts +3 -0
  40. package/dist/session/index.js +3 -0
  41. package/dist/session/record/index.d.ts +3 -0
  42. package/dist/session/record/index.js +3 -0
  43. package/dist/session/record/session-entry.d.ts +20 -0
  44. package/dist/session/record/session-entry.js +146 -0
  45. package/dist/session/record/session-record.d.ts +21 -0
  46. package/dist/session/record/session-record.js +95 -0
  47. package/dist/session/record/types.d.ts +71 -0
  48. package/dist/session/record/types.js +1 -0
  49. package/dist/session/utils.d.ts +7 -0
  50. package/dist/session/utils.js +18 -0
  51. package/dist/signal-errors.d.ts +18 -0
  52. package/dist/signal-errors.js +24 -0
  53. package/dist/teste.d.ts +1 -0
  54. package/dist/teste.js +18 -0
  55. package/package.json +40 -0
@@ -0,0 +1,42 @@
1
+ import { randomBytes } from 'crypto';
2
+ import * as curve from './curve.js';
3
+ function isNonNegativeInteger(n) {
4
+ return (typeof n === 'number' &&
5
+ Number.isInteger(n) &&
6
+ n >= 0);
7
+ }
8
+ export const generateIdentityKeyPair = curve.signalCrypto.generateIdentityKeyPair;
9
+ export function generateRegistrationId() {
10
+ const bytes = randomBytes(2);
11
+ return (((bytes[0] ?? 0) << 8) | (bytes[1] ?? 0)) & 0x3fff;
12
+ }
13
+ export async function generateSignedPreKey(identityKeyPair, signedKeyId) {
14
+ if (!(identityKeyPair.privateKey instanceof Uint8Array) ||
15
+ identityKeyPair.privateKey.length !== 64) {
16
+ throw new TypeError('Invalid Ed25519 private key');
17
+ }
18
+ if (!(identityKeyPair.publicKey instanceof Uint8Array) ||
19
+ identityKeyPair.publicKey.length !== 32) {
20
+ throw new TypeError('Invalid Ed25519 public key');
21
+ }
22
+ if (!isNonNegativeInteger(signedKeyId)) {
23
+ throw new TypeError(`Invalid argument for signedKeyId: ${signedKeyId}`);
24
+ }
25
+ const keyPair = await curve.generateKeyPair();
26
+ const signature = curve.calculateSignature(identityKeyPair.privateKey, keyPair.publicKey);
27
+ return {
28
+ keyId: signedKeyId,
29
+ keyPair,
30
+ signature
31
+ };
32
+ }
33
+ export async function generatePreKey(keyId) {
34
+ if (!isNonNegativeInteger(keyId)) {
35
+ throw new TypeError(`Invalid argument for keyId: ${keyId}`);
36
+ }
37
+ const keyPair = await curve.generateKeyPair();
38
+ return {
39
+ keyId,
40
+ keyPair
41
+ };
42
+ }
@@ -0,0 +1 @@
1
+ export { PreKeyWhisperMessage, WhisperMessage } from "./generated/WhisperTextProtocol.js";
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+ export { PreKeyWhisperMessage, WhisperMessage } from "./generated/WhisperTextProtocol.js";
@@ -0,0 +1,9 @@
1
+ export declare class ProtocolAddress {
2
+ readonly id: string;
3
+ readonly deviceId: number;
4
+ private cachedString;
5
+ static from(encodedAddress: string): ProtocolAddress;
6
+ constructor(id: string, deviceId: number);
7
+ toString(): string;
8
+ equals(other: unknown): boolean;
9
+ }
@@ -0,0 +1,50 @@
1
+ export class ProtocolAddress {
2
+ id;
3
+ deviceId;
4
+ cachedString = null;
5
+ static from(encodedAddress) {
6
+ if (typeof encodedAddress !== 'string') {
7
+ throw new TypeError('encodedAddress must be a string');
8
+ }
9
+ const separatorIndex = encodedAddress.lastIndexOf('.');
10
+ if (separatorIndex <= 0 || separatorIndex === encodedAddress.length - 1) {
11
+ throw new Error('Invalid address encoding');
12
+ }
13
+ const id = encodedAddress.slice(0, separatorIndex);
14
+ const deviceStr = encodedAddress.slice(separatorIndex + 1);
15
+ if (!/^\d+$/.test(deviceStr)) {
16
+ throw new Error('Invalid deviceId encoding');
17
+ }
18
+ const deviceId = Number(deviceStr);
19
+ if (!Number.isSafeInteger(deviceId) || deviceId < 0) {
20
+ throw new Error('Invalid deviceId value');
21
+ }
22
+ return new ProtocolAddress(id, deviceId);
23
+ }
24
+ constructor(id, deviceId) {
25
+ if (typeof id !== 'string' || id.length === 0) {
26
+ throw new TypeError('id must be a non-empty string');
27
+ }
28
+ if (id.includes('.')) {
29
+ throw new TypeError('id must not contain "."');
30
+ }
31
+ if (!Number.isSafeInteger(deviceId) || deviceId < 0) {
32
+ throw new TypeError('deviceId must be a non-negative safe integer');
33
+ }
34
+ this.id = id;
35
+ this.deviceId = deviceId;
36
+ }
37
+ toString() {
38
+ if (this.cachedString === null) {
39
+ this.cachedString = `${this.id}.${this.deviceId}`;
40
+ }
41
+ return this.cachedString;
42
+ }
43
+ equals(other) {
44
+ if (!(other instanceof ProtocolAddress)) {
45
+ return false;
46
+ }
47
+ return (this.id === other.id &&
48
+ this.deviceId === other.deviceId);
49
+ }
50
+ }
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ export * from './session-builder.js';
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ export * from './session-builder.js';
@@ -0,0 +1,13 @@
1
+ import type { ProtocolAddress } from '../../protocol_address.js';
2
+ import { SessionRecord } from '../record/index.js';
3
+ import type { PreKeyBundle, PreKeyWhisperMessage, SessionBuilderStorage } from './types.js';
4
+ export declare class SessionBuilder {
5
+ private readonly addr;
6
+ private readonly storage;
7
+ constructor(storage: SessionBuilderStorage, protocolAddress: ProtocolAddress);
8
+ initOutgoing(device: PreKeyBundle): Promise<void>;
9
+ initIncoming(record: SessionRecord, message: PreKeyWhisperMessage): Promise<number | undefined>;
10
+ private initSession;
11
+ private calculateSendingRatchet;
12
+ private deriveSecrets;
13
+ }
@@ -0,0 +1,148 @@
1
+ import { BaseKeyType } from '../../base_key_type.js';
2
+ import { ChainType } from '../../chain_type.js';
3
+ import { SessionRecord } from '../record/index.js';
4
+ import { crypto } from '../../crypto.js';
5
+ import { signalCrypto } from '../../curve.js';
6
+ import { UntrustedIdentityKeyError, PreKeyError } from '../../signal-errors.js';
7
+ import { enqueue } from '../../job_queue.js';
8
+ export class SessionBuilder {
9
+ addr;
10
+ storage;
11
+ constructor(storage, protocolAddress) {
12
+ this.addr = protocolAddress;
13
+ this.storage = storage;
14
+ }
15
+ async initOutgoing(device) {
16
+ const fqAddr = this.addr.toString();
17
+ return enqueue(fqAddr, async () => {
18
+ if (!await this.storage.isTrustedIdentity(this.addr.id, device.identityKey)) {
19
+ throw new UntrustedIdentityKeyError(this.addr.id, device.identityKey);
20
+ }
21
+ signalCrypto.verify(device.identityKey, device.signedPreKey.publicKey, device.signedPreKey.signature);
22
+ const baseKey = await signalCrypto.generateDHKeyPair();
23
+ const session = await this.initSession(true, { pubKey: baseKey.publicKey, privKey: baseKey.privateKey }, undefined, device.identityKey, device.preKey?.publicKey, device.signedPreKey.publicKey, device.registrationId);
24
+ const pendingPreKey = {
25
+ baseKey: baseKey.publicKey,
26
+ signedKeyId: device.signedPreKey.keyId
27
+ };
28
+ if (device.preKey) {
29
+ pendingPreKey.preKeyId = device.preKey.keyId;
30
+ }
31
+ session.pendingPreKey = pendingPreKey;
32
+ let record = await this.storage.loadSession(fqAddr);
33
+ if (!record) {
34
+ record = new SessionRecord();
35
+ }
36
+ else {
37
+ const openSession = record.getOpenSession();
38
+ if (openSession)
39
+ record.closeSession(openSession);
40
+ }
41
+ record.setSession(session);
42
+ await this.storage.storeSession(fqAddr, record);
43
+ });
44
+ }
45
+ async initIncoming(record, message) {
46
+ const fqAddr = this.addr.toString();
47
+ if (!await this.storage.isTrustedIdentity(fqAddr, message.identityKey)) {
48
+ throw new UntrustedIdentityKeyError(this.addr.id, message.identityKey);
49
+ }
50
+ if (record.getSession(message.baseKey)) {
51
+ return undefined;
52
+ }
53
+ const [preKeyPair, signedPreKeyPair] = await Promise.all([
54
+ message.preKeyId ? this.storage.loadPreKey(message.preKeyId) : Promise.resolve(undefined),
55
+ this.storage.loadSignedPreKey(message.signedPreKeyId)
56
+ ]);
57
+ if (message.preKeyId && !preKeyPair) {
58
+ throw new PreKeyError('Invalid PreKey ID');
59
+ }
60
+ if (!signedPreKeyPair) {
61
+ throw new PreKeyError('Missing SignedPreKey');
62
+ }
63
+ const existingOpenSession = record.getOpenSession();
64
+ if (existingOpenSession) {
65
+ console.warn('Closing open session in favor of incoming prekey bundle');
66
+ record.closeSession(existingOpenSession);
67
+ }
68
+ const session = await this.initSession(false, preKeyPair, signedPreKeyPair, message.identityKey, message.baseKey, undefined, message.registrationId);
69
+ record.setSession(session);
70
+ return message.preKeyId;
71
+ }
72
+ async initSession(isInitiator, ourEphemeralKey, ourSignedKey, theirIdentityPubKey, theirEphemeralPubKey, theirSignedPubKey, registrationId) {
73
+ if (isInitiator) {
74
+ ourSignedKey = ourEphemeralKey;
75
+ }
76
+ else {
77
+ theirSignedPubKey = theirEphemeralPubKey;
78
+ }
79
+ const sharedSecretLen = (!ourEphemeralKey || !theirEphemeralPubKey) ? 128 : 160;
80
+ const sharedSecret = new Uint8Array(sharedSecretLen);
81
+ sharedSecret.fill(0xff, 0, 32);
82
+ const ourIdentityKey = await this.storage.getOurIdentity();
83
+ const [a1, a2, a3] = await Promise.all([
84
+ signalCrypto.calculateAgreement(theirSignedPubKey, ourIdentityKey.privKey),
85
+ signalCrypto.calculateAgreement(theirIdentityPubKey, ourSignedKey.privKey),
86
+ signalCrypto.calculateAgreement(theirSignedPubKey, ourSignedKey.privKey)
87
+ ]);
88
+ sharedSecret.set(a1, isInitiator ? 32 : 64);
89
+ sharedSecret.set(a2, isInitiator ? 64 : 32);
90
+ sharedSecret.set(a3, 96);
91
+ if (ourEphemeralKey && theirEphemeralPubKey) {
92
+ const a4 = signalCrypto.calculateAgreement(theirEphemeralPubKey, ourEphemeralKey.privKey);
93
+ sharedSecret.set(a4, 128);
94
+ }
95
+ const masterKey = this.deriveSecrets(sharedSecret, new Uint8Array(32), new TextEncoder().encode('WhisperText'), 2);
96
+ const session = SessionRecord.createEntry();
97
+ session.registrationId = registrationId;
98
+ const ephemeralKP = isInitiator
99
+ ? await signalCrypto.generateDHKeyPair().then(kp => ({
100
+ pubKey: kp.publicKey,
101
+ privKey: kp.privateKey
102
+ }))
103
+ : {
104
+ pubKey: ourSignedKey.pubKey,
105
+ privKey: ourSignedKey.privKey
106
+ };
107
+ session.currentRatchet = {
108
+ rootKey: masterKey[0],
109
+ ephemeralKeyPair: ephemeralKP,
110
+ lastRemoteEphemeralKey: theirSignedPubKey,
111
+ previousCounter: 0
112
+ };
113
+ session.indexInfo = {
114
+ created: Date.now(),
115
+ used: Date.now(),
116
+ remoteIdentityKey: theirIdentityPubKey,
117
+ baseKey: isInitiator ? ourEphemeralKey.pubKey : theirEphemeralPubKey,
118
+ baseKeyType: isInitiator ? BaseKeyType.OURS : BaseKeyType.THEIRS,
119
+ closed: -1
120
+ };
121
+ if (isInitiator) {
122
+ this.calculateSendingRatchet(session, theirSignedPubKey);
123
+ }
124
+ return session;
125
+ }
126
+ calculateSendingRatchet(session, remoteKey) {
127
+ const ratchet = session.currentRatchet;
128
+ const sharedSecret = signalCrypto.calculateAgreement(remoteKey, ratchet.ephemeralKeyPair.privKey);
129
+ const masterKey = this.deriveSecrets(sharedSecret, ratchet.rootKey, new TextEncoder().encode('WhisperRatchet'), 2);
130
+ session.addChain(ratchet.ephemeralKeyPair.pubKey, {
131
+ messageKeys: {},
132
+ chainKey: {
133
+ counter: -1,
134
+ key: masterKey[1]
135
+ },
136
+ chainType: ChainType.SENDING
137
+ });
138
+ ratchet.rootKey = masterKey[0];
139
+ }
140
+ deriveSecrets(input, salt, info, chunks = 3) {
141
+ const hkdf = crypto.hkdf(input, salt, info, { length: chunks * 32 });
142
+ const result = [];
143
+ for (let i = 0; i < chunks; i++) {
144
+ result.push(hkdf.subarray(i * 32, (i + 1) * 32));
145
+ }
146
+ return result;
147
+ }
148
+ }
@@ -0,0 +1,38 @@
1
+ import type { SessionRecord } from '../record/index.js';
2
+ export interface PreKeyWhisperMessage {
3
+ identityKey: Uint8Array;
4
+ registrationId: number;
5
+ baseKey: Uint8Array;
6
+ signedPreKeyId: number;
7
+ preKeyId?: number;
8
+ message: Uint8Array;
9
+ }
10
+ export interface IdentityKeyPair {
11
+ pubKey: Uint8Array;
12
+ privKey: Uint8Array;
13
+ }
14
+ export type KeyPair = {
15
+ pubKey: Uint8Array;
16
+ privKey: Uint8Array;
17
+ };
18
+ export interface PreKeyBundle {
19
+ identityKey: Uint8Array;
20
+ registrationId: number;
21
+ preKey?: {
22
+ keyId: number;
23
+ publicKey: Uint8Array;
24
+ };
25
+ signedPreKey: {
26
+ keyId: number;
27
+ publicKey: Uint8Array;
28
+ signature: Uint8Array;
29
+ };
30
+ }
31
+ export interface SessionBuilderStorage {
32
+ isTrustedIdentity(addressName: string, identityKey: Uint8Array): Promise<boolean>;
33
+ loadSession(addressName: string): Promise<SessionRecord | undefined>;
34
+ storeSession(addressName: string, record: SessionRecord): Promise<void>;
35
+ getOurIdentity(): Promise<IdentityKeyPair>;
36
+ loadPreKey(preKeyId: number): Promise<KeyPair | undefined>;
37
+ loadSignedPreKey(signedPreKeyId: number): Promise<KeyPair | undefined>;
38
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { WhisperMessageProto, PreKeyWhisperMessageProto } from './types.js';
2
+ export declare class WhisperMessageEncoder {
3
+ static encodeWhisperMessage(msg: WhisperMessageProto): Uint8Array;
4
+ static decodeWhisperMessage(buf: Uint8Array): WhisperMessageProto;
5
+ static encodePreKeyWhisperMessage(msg: PreKeyWhisperMessageProto): Uint8Array;
6
+ static decodePreKeyWhisperMessage(buf: Uint8Array): PreKeyWhisperMessageProto;
7
+ private static encodeFieldVarint;
8
+ private static encodeFieldBytes;
9
+ private static encodeVarint;
10
+ private static decodeVarint;
11
+ private static decodeFieldHeader;
12
+ private static concatUint8Arrays;
13
+ }
@@ -0,0 +1,135 @@
1
+ export class WhisperMessageEncoder {
2
+ static encodeWhisperMessage(msg) {
3
+ const parts = [];
4
+ if (msg.ephemeralKey)
5
+ parts.push(this.encodeFieldBytes(1, msg.ephemeralKey));
6
+ if (msg.counter !== undefined)
7
+ parts.push(this.encodeFieldVarint(2, msg.counter));
8
+ if (msg.previousCounter !== undefined)
9
+ parts.push(this.encodeFieldVarint(3, msg.previousCounter));
10
+ if (msg.ciphertext)
11
+ parts.push(this.encodeFieldBytes(4, msg.ciphertext));
12
+ return this.concatUint8Arrays(parts);
13
+ }
14
+ static decodeWhisperMessage(buf) {
15
+ const msg = {};
16
+ let offset = 0;
17
+ while (offset < buf.length) {
18
+ const [tag, type, nextOffset] = this.decodeFieldHeader(buf, offset);
19
+ offset = nextOffset;
20
+ if (type === 2) {
21
+ const [len, next] = this.decodeVarint(buf, offset);
22
+ offset = next;
23
+ const value = buf.subarray(offset, offset + len);
24
+ offset += len;
25
+ if (tag === 1)
26
+ msg.ephemeralKey = value;
27
+ if (tag === 4)
28
+ msg.ciphertext = value;
29
+ }
30
+ else if (type === 0) {
31
+ const [value, next] = this.decodeVarint(buf, offset);
32
+ offset = next;
33
+ if (tag === 2)
34
+ msg.counter = value;
35
+ if (tag === 3)
36
+ msg.previousCounter = value;
37
+ }
38
+ }
39
+ return msg;
40
+ }
41
+ static encodePreKeyWhisperMessage(msg) {
42
+ const parts = [];
43
+ if (msg.identityKey)
44
+ parts.push(this.encodeFieldBytes(1, msg.identityKey));
45
+ if (msg.registrationId !== undefined)
46
+ parts.push(this.encodeFieldVarint(2, msg.registrationId));
47
+ if (msg.baseKey)
48
+ parts.push(this.encodeFieldBytes(3, msg.baseKey));
49
+ if (msg.signedPreKeyId !== undefined)
50
+ parts.push(this.encodeFieldVarint(4, msg.signedPreKeyId));
51
+ if (msg.preKeyId !== undefined)
52
+ parts.push(this.encodeFieldVarint(5, msg.preKeyId));
53
+ if (msg.message)
54
+ parts.push(this.encodeFieldBytes(6, msg.message));
55
+ return this.concatUint8Arrays(parts);
56
+ }
57
+ static decodePreKeyWhisperMessage(buf) {
58
+ const msg = {};
59
+ let offset = 0;
60
+ while (offset < buf.length) {
61
+ const [tag, type, nextOffset] = this.decodeFieldHeader(buf, offset);
62
+ offset = nextOffset;
63
+ if (type === 2) {
64
+ const [len, next] = this.decodeVarint(buf, offset);
65
+ offset = next;
66
+ const value = buf.subarray(offset, offset + len);
67
+ offset += len;
68
+ if (tag === 1)
69
+ msg.identityKey = value;
70
+ if (tag === 3)
71
+ msg.baseKey = value;
72
+ if (tag === 6)
73
+ msg.message = value;
74
+ }
75
+ else if (type === 0) {
76
+ const [value, next] = this.decodeVarint(buf, offset);
77
+ offset = next;
78
+ if (tag === 2)
79
+ msg.registrationId = value;
80
+ if (tag === 4)
81
+ msg.signedPreKeyId = value;
82
+ if (tag === 5)
83
+ msg.preKeyId = value;
84
+ }
85
+ }
86
+ return msg;
87
+ }
88
+ static encodeFieldVarint(tag, value) {
89
+ const header = this.encodeVarint((tag << 3) | 0);
90
+ const val = this.encodeVarint(value);
91
+ return this.concatUint8Arrays([header, val]);
92
+ }
93
+ static encodeFieldBytes(tag, value) {
94
+ const header = this.encodeVarint((tag << 3) | 2);
95
+ const len = this.encodeVarint(value.length);
96
+ return this.concatUint8Arrays([header, len, value]);
97
+ }
98
+ static encodeVarint(value) {
99
+ const result = [];
100
+ while ((value & 0xffffff80) !== 0) {
101
+ result.push((value & 0xff) | 0x80);
102
+ value >>>= 7;
103
+ }
104
+ result.push(value & 0xff);
105
+ return new Uint8Array(result);
106
+ }
107
+ static decodeVarint(buf, offset) {
108
+ let value = 0;
109
+ let shift = 0;
110
+ let i = offset;
111
+ while (i < buf.length) {
112
+ const byte = buf[i];
113
+ value |= (byte & 0x7f) << shift;
114
+ if ((byte & 0x80) === 0)
115
+ return [value, i + 1];
116
+ shift += 7;
117
+ i++;
118
+ }
119
+ throw new Error('Varint overflow');
120
+ }
121
+ static decodeFieldHeader(buf, offset) {
122
+ const [header, nextOffset] = this.decodeVarint(buf, offset);
123
+ return [header >> 3, header & 0x07, nextOffset];
124
+ }
125
+ static concatUint8Arrays(arrays) {
126
+ const total = arrays.reduce((sum, a) => sum + a.length, 0);
127
+ const result = new Uint8Array(total);
128
+ let offset = 0;
129
+ for (const arr of arrays) {
130
+ result.set(arr, offset);
131
+ offset += arr.length;
132
+ }
133
+ return result;
134
+ }
135
+ }
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './encoding.js';
3
+ export * from './session-cipher.js';
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './encoding.js';
3
+ export * from './session-cipher.js';
@@ -0,0 +1,26 @@
1
+ import type { EncryptResult, SessionCipherStorage } from './types.js';
2
+ import { ProtocolAddress } from '../../protocol_address.js';
3
+ export declare class SessionCipher {
4
+ private readonly addr;
5
+ private readonly addrStr;
6
+ private readonly storage;
7
+ constructor(storage: SessionCipherStorage, protocolAddress: ProtocolAddress);
8
+ toString(): string;
9
+ private _encodeTupleByte;
10
+ private _decodeTupleByte;
11
+ private getRecord;
12
+ private storeRecord;
13
+ private queueJob;
14
+ encrypt(data: Uint8Array): Promise<EncryptResult>;
15
+ decryptWhisperMessage(data: Uint8Array): Promise<Uint8Array>;
16
+ decryptPreKeyWhisperMessage(data: Uint8Array): Promise<Uint8Array>;
17
+ hasOpenSession(): Promise<boolean>;
18
+ closeOpenSession(): Promise<void>;
19
+ private decryptWithSessions;
20
+ private doDecryptWhisperMessage;
21
+ private fillMessageKeys;
22
+ private maybeStepRatchet;
23
+ private calculateRatchet;
24
+ private deriveSecrets;
25
+ private verifyMAC;
26
+ }