getIdentityKeyPair returns undefined
danieltigse opened this issue · comments
I am starting to implement this protocol. I just want to test the encryption and decryption in a simulated environment.
var KeyHelper = libsignal.KeyHelper;
var store = new SignalProtocolStore();
generateKeys(123, function(aliceKeys){
generateKeys(456, function(bobKeys){
var recipientId = "daniel123";
var deviceId = 0;
var address = new libsignal.SignalProtocolAddress(recipientId, deviceId);
// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.
var sessionBuilder = new libsignal.SessionBuilder(store, address);
// Process a prekey fetched from the server. Returns a promise that resolves
// once a session is created and saved in the store, or rejects if the
// identityKey differs from a previously seen identity for this address.
var promise = sessionBuilder.processPreKey({
registrationId: bobKeys.registrationId,
identityKey: bobKeys.identityKeyPair.pubKey,
signedPreKey: {
keyId : bobKeys.signedPreKey.keyId,
publicKey : bobKeys.signedPreKey.keyPair.pubKey,
signature : bobKeys.signedPreKey.signature
},
preKey: {
keyId : bobKeys.preKey.keyId,
publicKey : bobKeys.preKey.keyPair.pubKey
}
});
promise.then(function onsuccess() {
// encrypt messages
console.log("Vamo a encriptar");
});
promise.catch(function onerror(error) {
// handle identity key conflict
console.log(error);
});
});
});
function generateKeys(keyId, callback){
var keys = {};
keys.registrationId = KeyHelper.generateRegistrationId();
// Store registrationId somewhere durable and safe.
KeyHelper.generateIdentityKeyPair().then(function(identityKeyPair) {
// keyPair -> { pubKey: ArrayBuffer, privKey: ArrayBuffer }
// Store identityKeyPair somewhere durable and safe.
keys.identityKeyPair = identityKeyPair;
KeyHelper.generatePreKey(keyId).then(function(preKey) {
store.storePreKey(preKey.keyId, preKey.keyPair);
keys.preKey = preKey;
KeyHelper.generateSignedPreKey(identityKeyPair, keyId).then(function(signedPreKey) {
store.storeSignedPreKey(signedPreKey.keyId, signedPreKey.keyPair);
keys.signedPreKey = signedPreKey;
callback(keys);
});
});
});
}
I have the following error at sessionBuilder.processPreKey
:
libsignal-protocol.js:35952 Uncaught (in promise) TypeError: Cannot read property 'privKey' of undefined
at SessionBuilder.<anonymous> (libsignal-protocol.js:35952)
The library is calling the function getIdentityKeyPair
of my store interface (I am using the InMemorySignalProtocolStore.js
). This function is trying to get data with the key identityKey
but I never store any data with that key.
The solution was to insert this lines
store.put('identityKey', aliceKeys.identityKeyPair);
store.put('registrationId', aliceKeys.registrationId);
below: generateKeys(123, function(aliceKeys)