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('signedPreKeys');
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');
transaction.db.createObjectStore('debug');

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

@ -65,17 +65,30 @@
addMockContact() {
libsignal.KeyHelper.generateIdentityKeyPair().then(keyPair => {
const pubKey = StringView.arrayBufferToHex(keyPair.pubKey);
const keyId = Math.floor((Math.random() * 1000) + 1);
const signedKeyId = Math.floor((Math.random() * 1000) + 1);
Promise.all([
libsignal.KeyHelper.generatePreKey(keyId),
const promises = [
libsignal.KeyHelper.generateSignedPreKey(keyPair, signedKeyId)
]).then((keys) => {
const [preKey, signedPreKey] = keys;
textsecure.storage.protocol.storeContactPreKey(pubKey, { publicKey: preKey.keyPair.pubKey, keyId: keyId });
textsecure.storage.protocol.storeContactSignedPreKey(pubKey, { publicKey: signedPreKey.keyPair.pubKey, signature: signedPreKey.signature, keyId: signedPreKey.keyId });
.then((signedPreKey) => {
const contactSignedPreKey = {
publicKey: signedPreKey.keyPair.pubKey,
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)
});
);
});
},
registerSecondDevice(setProvisioningUrl, confirmNumber, progressCallback) {

Loading…
Cancel
Save