Change contact prekeys in db to allow multiple entries for each contact

pull/6/head
sachaaaaa 7 years ago
parent b193a99db9
commit 2f562ce9e1

@ -47,8 +47,12 @@ const migrations = [
transaction.db.createObjectStore('preKeys'); transaction.db.createObjectStore('preKeys');
transaction.db.createObjectStore('signedPreKeys'); transaction.db.createObjectStore('signedPreKeys');
transaction.db.createObjectStore('items'); transaction.db.createObjectStore('items');
transaction.db.createObjectStore('contactPreKeys');
transaction.db.createObjectStore('contactSignedPreKeys'); const contactPreKeys = transaction.db.createObjectStore('contactPreKeys', { autoIncrement : true });
contactPreKeys.createIndex('publicKeyString', 'publicKeyString', { unique: false });
const contactSignedPreKeys = transaction.db.createObjectStore('contactSignedPreKeys', { autoIncrement : true });
contactSignedPreKeys.createIndex('publicKeyString', 'publicKeyString', { unique: false });
window.log.info('creating debug log'); window.log.info('creating debug log');
transaction.db.createObjectStore('debug'); transaction.db.createObjectStore('debug');

@ -231,7 +231,8 @@
window.log.info('Successfully fetched contact prekey:', pubKey); window.log.info('Successfully fetched contact prekey:', pubKey);
resolve({ resolve({
keyId: prekey.get('keyId'), keyId: prekey.get('keyId'),
publicKey: prekey.get('publicKey') publicKey: prekey.get('publicKey'),
identityKey: prekey.get('identityKey'),
}); });
}, },
() => { () => {
@ -243,7 +244,8 @@
}, },
storeContactPreKey(pubKey, preKey) { storeContactPreKey(pubKey, preKey) {
const prekey = new ContactPreKey({ const prekey = new ContactPreKey({
id: pubKey, // id: (autoincrement)
publicKeyString: pubKey,
publicKey: preKey.publicKey, publicKey: preKey.publicKey,
keyId: preKey.keyId, keyId: preKey.keyId,
}); });
@ -328,6 +330,8 @@
prekey.get('id') prekey.get('id')
); );
resolve({ resolve({
id: preKey.get('id'),
publicKeyString: preKey.get('publicKeyString'),
publicKey: prekey.get('publicKey'), publicKey: prekey.get('publicKey'),
signature: prekey.get('signature'), signature: prekey.get('signature'),
created_at: prekey.get('created_at'), created_at: prekey.get('created_at'),
@ -378,7 +382,8 @@
}, },
storeContactSignedPreKey(pubKey, signedPreKey) { storeContactSignedPreKey(pubKey, signedPreKey) {
const prekey = new ContactSignedPreKey({ const prekey = new ContactSignedPreKey({
id: pubKey, // id: (autoincrement)
publicKeyString: pubKey,
keyId: signedPreKey.keyId, keyId: signedPreKey.keyId,
publicKey: signedPreKey.publicKey, publicKey: signedPreKey.publicKey,
signature: signedPreKey.signature, signature: signedPreKey.signature,

@ -65,17 +65,30 @@
addMockContact() { addMockContact() {
libsignal.KeyHelper.generateIdentityKeyPair().then(keyPair => { libsignal.KeyHelper.generateIdentityKeyPair().then(keyPair => {
const pubKey = StringView.arrayBufferToHex(keyPair.pubKey); const pubKey = StringView.arrayBufferToHex(keyPair.pubKey);
const keyId = Math.floor((Math.random() * 1000) + 1);
const signedKeyId = Math.floor((Math.random() * 1000) + 1); const signedKeyId = Math.floor((Math.random() * 1000) + 1);
Promise.all([ const promises = [
libsignal.KeyHelper.generatePreKey(keyId),
libsignal.KeyHelper.generateSignedPreKey(keyPair, signedKeyId) libsignal.KeyHelper.generateSignedPreKey(keyPair, signedKeyId)
]).then((keys) => { .then((signedPreKey) => {
const [preKey, signedPreKey] = keys; const contactSignedPreKey = {
textsecure.storage.protocol.storeContactPreKey(pubKey, { publicKey: preKey.keyPair.pubKey, keyId: keyId }); publicKey: signedPreKey.keyPair.pubKey,
textsecure.storage.protocol.storeContactSignedPreKey(pubKey, { publicKey: signedPreKey.keyPair.pubKey, signature: signedPreKey.signature, keyId: signedPreKey.keyId }); signature: signedPreKey.signature,
keyId: signedPreKey.keyId
};
return textsecure.storage.protocol.storeContactSignedPreKey(pubKey, contactSignedPreKey);
}),
];
for (let keyId = 0; keyId < 100; keyId += 1) {
promises.push(
libsignal.KeyHelper.generatePreKey(keyId)
.then((preKey) => {
return textsecure.storage.protocol.storeContactPreKey(pubKey, { publicKey: preKey.keyPair.pubKey, keyId: keyId });
}),
)
}
Promise.all(promises).then(
log.info("Added mock contact with pubkey " + pubKey) log.info("Added mock contact with pubkey " + pubKey)
}); );
}); });
}, },
registerSecondDevice(setProvisioningUrl, confirmNumber, progressCallback) { registerSecondDevice(setProvisioningUrl, confirmNumber, progressCallback) {

Loading…
Cancel
Save