refactor(types): Strengthen Type Safety in Signal Handling & Core Utilities (#1764)
* refactor(types): Strengthen Type Safety in Signal Handling & Core Utilities * chore: revert typescript and move types to libsignal * chore: update libsignal dependency resolution and checksum * fix: a minor regression * chore: update libsignal resolution and checksum
This commit is contained in:
committed by
GitHub
parent
e305d4848e
commit
421ca2eb92
@@ -1,4 +1,3 @@
|
||||
/* @ts-ignore */
|
||||
import { decrypt, encrypt } from 'libsignal/src/crypto'
|
||||
import { SenderKeyMessage } from './sender-key-message'
|
||||
import { SenderKeyName } from './sender-key-name'
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as nodeCrypto from 'crypto'
|
||||
/* @ts-ignore */
|
||||
import { generateKeyPair } from 'libsignal/src/curve'
|
||||
|
||||
type KeyPairType = ReturnType<typeof generateKeyPair>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* @ts-ignore */
|
||||
import { calculateMAC } from 'libsignal/src/crypto'
|
||||
import { SenderMessageKey } from './sender-message-key'
|
||||
|
||||
@@ -8,7 +7,7 @@ export class SenderChainKey {
|
||||
private readonly iteration: number
|
||||
private readonly chainKey: Buffer
|
||||
|
||||
constructor(iteration: number, chainKey: any) {
|
||||
constructor(iteration: number, chainKey: Uint8Array | Buffer) {
|
||||
this.iteration = iteration
|
||||
if (Buffer.isBuffer(chainKey)) {
|
||||
// backported from @MartinSchere's PR
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* @ts-ignore */
|
||||
import { calculateSignature, verifySignature } from 'libsignal/src/curve'
|
||||
import { proto } from '../../../WAProto/index.js'
|
||||
import { CiphertextMessage } from './ciphertext-message'
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* @ts-ignore */
|
||||
import { deriveSecrets } from 'libsignal/src/crypto'
|
||||
|
||||
export class SenderMessageKey {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
/* @ts-ignore */
|
||||
import * as libsignal from 'libsignal'
|
||||
/* @ts-ignore */
|
||||
import { LRUCache } from 'lru-cache'
|
||||
import type { SignalAuthState, SignalKeyStoreWithTransaction } from '../Types'
|
||||
import type { SignalRepository } from '../Types/Signal'
|
||||
@@ -28,7 +26,7 @@ export function makeLibSignalRepository(
|
||||
|
||||
const parsedKeys = auth.keys as SignalKeyStoreWithTransaction
|
||||
|
||||
function isLikelySyncMessage(addr: any): boolean {
|
||||
function isLikelySyncMessage(addr: libsignal.ProtocolAddress): boolean {
|
||||
const key = addr.toString()
|
||||
|
||||
// Only bypass for WhatsApp system addresses, not regular user contacts
|
||||
@@ -285,7 +283,7 @@ export function makeLibSignalRepository(
|
||||
return repository
|
||||
}
|
||||
|
||||
const jidToSignalProtocolAddress = (jid: string) => {
|
||||
const jidToSignalProtocolAddress = (jid: string): libsignal.ProtocolAddress => {
|
||||
const decoded = jidDecode(jid)!
|
||||
const { user, device, server } = decoded
|
||||
|
||||
@@ -303,7 +301,7 @@ const jidToSignalSenderKeyName = (group: string, user: string): SenderKeyName =>
|
||||
function signalStorage(
|
||||
{ creds, keys }: SignalAuthState,
|
||||
lidMapping: LIDMappingStore
|
||||
): SenderKeyStore & Record<string, any> {
|
||||
): SenderKeyStore & libsignal.SignalStorage {
|
||||
return {
|
||||
loadSession: async (id: string) => {
|
||||
try {
|
||||
@@ -340,8 +338,7 @@ function signalStorage(
|
||||
|
||||
return null
|
||||
},
|
||||
// TODO: Replace with libsignal.SessionRecord when type exports are added to libsignal
|
||||
storeSession: async (id: string, session: any) => {
|
||||
storeSession: async (id: string, session: libsignal.SessionRecord) => {
|
||||
await keys.set({ session: { [id]: session.serialize() } })
|
||||
},
|
||||
isTrustedIdentity: () => {
|
||||
@@ -384,7 +381,7 @@ function signalStorage(
|
||||
const { signedIdentityKey } = creds
|
||||
return {
|
||||
privKey: Buffer.from(signedIdentityKey.private),
|
||||
pubKey: generateSignalPubKey(signedIdentityKey.public)
|
||||
pubKey: Buffer.from(generateSignalPubKey(signedIdentityKey.public))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user