signal-desktop/libtextsecure/test/in_memory_axolotl_store.js
lilia 96eafc7750 Integrate libaxolotl async storage changes
* Session records are now opaque strings, so treat them that way:
  - no more cross checking identity key and session records
  - Move hasOpenSession to axolotl wrapper
  - Remote registration ids must be fetched async'ly via protocol wrapper
* Implement async AxolotlStore using textsecure.storage
* Add some db stores and move prekeys and signed keys to indexeddb
* Add storage tests
* Rename identityKey storage key from libaxolotl25519KeyidentityKey to
  simply identityKey, since it's no longer hardcoded in libaxolotl
* Rework registration and key-generation, keeping logic in libtextsecure
  and rendering in options.js.
* Remove key_worker since workers are handled at the libaxolotl level
  now
2015-05-05 17:44:55 -07:00

93 lines
2.7 KiB
JavaScript

function AxolotlStore() {
this.store = {};
}
AxolotlStore.prototype = {
getMyIdentityKey: function() {
return this.get('identityKey');
},
getMyRegistrationId: function() {
return this.get('registrationId');
},
put: function(key, value) {
if (key === undefined || value === undefined || key === null || value === null)
throw new Error("Tried to store undefined/null");
this.store[key] = value;
},
get: function(key, defaultValue) {
if (key === null || key === undefined)
throw new Error("Tried to get value for undefined/null key");
if (key in this.store) {
return this.store[key];
} else {
return defaultValue;
}
},
remove: function(key) {
if (key === null || key === undefined)
throw new Error("Tried to remove value for undefined/null key");
delete this.store[key];
},
getIdentityKey: function(identifier) {
if (identifier === null || identifier === undefined)
throw new Error("Tried to get identity key for undefined/null key");
return new Promise(function(resolve) {
resolve(this.get('identityKey' + identifier));
}.bind(this));
},
putIdentityKey: function(identifier, identityKey) {
if (identifier === null || identifier === undefined)
throw new Error("Tried to put identity key for undefined/null key");
return new Promise(function(resolve) {
resolve(this.put('identityKey' + identifier, identityKey));
}.bind(this));
},
/* Returns a prekeypair object or undefined */
getPreKey: function(keyId) {
return new Promise(function(resolve) {
var res = this.get('25519KeypreKey' + keyId);
resolve(res);
}.bind(this));
},
putPreKey: function(keyId, keyPair) {
return new Promise(function(resolve) {
resolve(this.put('25519KeypreKey' + keyId, keyPair));
}.bind(this));
},
removePreKey: function(keyId) {
return new Promise(function(resolve) {
resolve(this.remove('25519KeypreKey' + keyId));
}.bind(this));
},
/* Returns a signed keypair object or undefined */
getSignedPreKey: function(keyId) {
return new Promise(function(resolve) {
var res = this.get('25519KeysignedKey' + keyId);
resolve(res);
}.bind(this));
},
putSignedPreKey: function(keyId, keyPair) {
return new Promise(function(resolve) {
resolve(this.put('25519KeysignedKey' + keyId, keyPair));
}.bind(this));
},
removeSignedPreKey: function(keyId) {
return new Promise(function(resolve) {
resolve(this.remove('25519KeysignedKey' + keyId));
}.bind(this));
},
getSession: function(identifier) {
return new Promise(function(resolve) {
resolve(this.get('session' + identifier));
}.bind(this));
},
putSession: function(identifier, record) {
return new Promise(function(resolve) {
resolve(this.put('session' + identifier, record));
}.bind(this));
}
};