Implement megaphone conditional standard_donate with local device createdAt

This commit is contained in:
ayumi-signal
2026-01-15 09:40:22 -08:00
committed by GitHub
parent 5528cd37c0
commit 1cfda1f210
16 changed files with 452 additions and 19 deletions

View File

@@ -5,7 +5,7 @@ import { assert } from 'chai';
import lodash from 'lodash';
import * as sinon from 'sinon';
import { getRandomBytes } from '../../Crypto.node.js';
import { generateRegistrationId, getRandomBytes } from '../../Crypto.node.js';
import { generateKeyPair } from '../../Curve.node.js';
import AccountManager from '../../textsecure/AccountManager.preload.js';
import type {
@@ -32,6 +32,7 @@ describe('AccountManager', () => {
const ourAci = generateAci();
const ourPni = generatePni();
const ourRegistrationId = generateRegistrationId();
const identityKey = generateKeyPair();
const pubKey = getRandomBytes(33);
const privKey = getRandomBytes(32);
@@ -42,6 +43,9 @@ describe('AccountManager', () => {
sandbox
.stub(signalProtocolStore, 'getIdentityKeyPair')
.returns(identityKey);
sandbox
.stub(signalProtocolStore, 'getLocalRegistrationId')
.resolves(ourRegistrationId);
const { user } = itemStorage;
sandbox.stub(user, 'getAci').returns(ourAci);
sandbox.stub(user, 'getPni').returns(ourPni);
@@ -77,6 +81,29 @@ describe('AccountManager', () => {
});
});
describe('encrypted device createdAt', () => {
it('roundtrips', async () => {
const deviceId = 2;
const createdAt = new Date().getTime();
const encrypted = await accountManager._encryptDeviceCreatedAt(
createdAt,
deviceId
);
if (!encrypted) {
throw new Error('failed to encrypt!');
}
assert.strictEqual(typeof encrypted, 'string');
const decrypted = await accountManager.decryptDeviceCreatedAt(
encrypted,
deviceId
);
assert.strictEqual(decrypted, createdAt);
});
});
describe('#_cleanSignedPreKeys', () => {
let originalLoadSignedPreKeys: any;
let originalRemoveSignedPreKey: any;