Rename textsecure.api and make it internal-only

This commit is contained in:
lilia 2015-04-30 14:10:04 -07:00
parent 45a61780af
commit 9e7d8c0a08
7 changed files with 24 additions and 28 deletions

View file

@ -38790,7 +38790,7 @@ window.textsecure.utils = function() {
var handleAttachment = function(attachment) { var handleAttachment = function(attachment) {
function getAttachment() { function getAttachment() {
return textsecure.api.getAttachment(attachment.id.toString()); return TextSecureServer.getAttachment(attachment.id.toString());
} }
function decryptAttachment(encrypted) { function decryptAttachment(encrypted) {
@ -39024,9 +39024,7 @@ textsecure.processDecrypted = function(decrypted, source) {
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
window.textsecure = window.textsecure || {}; TextSecureServer = function () {
window.textsecure.api = function () {
'use strict'; 'use strict';
var self = {}; var self = {};
@ -39410,7 +39408,7 @@ window.textsecure.api = function () {
registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) { registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) {
return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) { return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
return new Promise(function(resolve) { return new Promise(function(resolve) {
new WebSocketResource(textsecure.api.getTempWebsocket(), function(request) { new WebSocketResource(TextSecureServer.getTempWebsocket(), function(request) {
if (request.path == "/v1/address" && request.verb == "PUT") { if (request.path == "/v1/address" && request.verb == "PUT") {
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body); var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
setProvisioningUrl([ setProvisioningUrl([
@ -39441,7 +39439,7 @@ window.textsecure.api = function () {
}).then(TextSecureServer.registerKeys).then(textsecure.registration.done); }).then(TextSecureServer.registerKeys).then(textsecure.registration.done);
}, },
refreshPreKeys: function() { refreshPreKeys: function() {
return textsecure.api.getMyKeys().then(function(preKeyCount) { return TextSecureServer.getMyKeys().then(function(preKeyCount) {
if (preKeyCount < 10) { if (preKeyCount < 10) {
return generateKeys(100).then(TextSecureServer.registerKeys); return generateKeys(100).then(TextSecureServer.registerKeys);
} }
@ -39462,7 +39460,7 @@ window.textsecure.api = function () {
var registrationId = axolotl.util.generateRegistrationId(); var registrationId = axolotl.util.generateRegistrationId();
textsecure.storage.put("registrationId", registrationId); textsecure.storage.put("registrationId", registrationId);
return textsecure.api.confirmCode( return TextSecureServer.confirmCode(
number, verificationCode, password, signalingKey, registrationId, single_device number, verificationCode, password, signalingKey, registrationId, single_device
).then(function(response) { ).then(function(response) {
textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1); textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1);
@ -39560,7 +39558,7 @@ function generateKeys(count, progressCallback) {
constructor: MessageReceiver, constructor: MessageReceiver,
connect: function() { connect: function() {
// initialize the socket and start listening for messages // initialize the socket and start listening for messages
this.socket = textsecure.api.getMessageWebsocket(); this.socket = TextSecureServer.getMessageWebsocket();
var eventTarget = this.target; var eventTarget = this.target;
new WebSocketResource(this.socket, function(request) { new WebSocketResource(this.socket, function(request) {
@ -39639,9 +39637,9 @@ window.textsecure.messaging = function() {
var promises = []; var promises = [];
if (updateDevices !== undefined) if (updateDevices !== undefined)
for (var i in updateDevices) for (var i in updateDevices)
promises[promises.length] = textsecure.api.getKeysForNumber(number, updateDevices[i]).then(handleResult); promises[promises.length] = TextSecureServer.getKeysForNumber(number, updateDevices[i]).then(handleResult);
else else
return textsecure.api.getKeysForNumber(number).then(handleResult); return TextSecureServer.getKeysForNumber(number).then(handleResult);
return Promise.all(promises); return Promise.all(promises);
} }
@ -39687,7 +39685,7 @@ window.textsecure.messaging = function() {
for (var i = 0; i < deviceObjectList.length; i++) for (var i = 0; i < deviceObjectList.length; i++)
promises[i] = addEncryptionFor(i); promises[i] = addEncryptionFor(i);
return Promise.all(promises).then(function() { return Promise.all(promises).then(function() {
return textsecure.api.sendMessages(number, jsonData); return TextSecureServer.sendMessages(number, jsonData);
}); });
} }
@ -39838,7 +39836,7 @@ window.textsecure.messaging = function() {
var iv = textsecure.crypto.getRandomBytes(16); var iv = textsecure.crypto.getRandomBytes(16);
return textsecure.crypto.encryptAttachment(attachment.data, proto.key, iv).then(function(encryptedBin) { return textsecure.crypto.encryptAttachment(attachment.data, proto.key, iv).then(function(encryptedBin) {
return textsecure.api.putAttachment(encryptedBin).then(function(id) { return TextSecureServer.putAttachment(encryptedBin).then(function(id) {
proto.id = id; proto.id = id;
proto.contentType = attachment.contentType; proto.contentType = attachment.contentType;
return proto; return proto;

View file

@ -41,7 +41,7 @@
registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) { registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) {
return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) { return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
return new Promise(function(resolve) { return new Promise(function(resolve) {
new WebSocketResource(textsecure.api.getTempWebsocket(), function(request) { new WebSocketResource(TextSecureServer.getTempWebsocket(), function(request) {
if (request.path == "/v1/address" && request.verb == "PUT") { if (request.path == "/v1/address" && request.verb == "PUT") {
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body); var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
setProvisioningUrl([ setProvisioningUrl([
@ -72,7 +72,7 @@
}).then(TextSecureServer.registerKeys).then(textsecure.registration.done); }).then(TextSecureServer.registerKeys).then(textsecure.registration.done);
}, },
refreshPreKeys: function() { refreshPreKeys: function() {
return textsecure.api.getMyKeys().then(function(preKeyCount) { return TextSecureServer.getMyKeys().then(function(preKeyCount) {
if (preKeyCount < 10) { if (preKeyCount < 10) {
return generateKeys(100).then(TextSecureServer.registerKeys); return generateKeys(100).then(TextSecureServer.registerKeys);
} }
@ -92,7 +92,7 @@
var registrationId = axolotl.util.generateRegistrationId(); var registrationId = axolotl.util.generateRegistrationId();
textsecure.storage.put("registrationId", registrationId); textsecure.storage.put("registrationId", registrationId);
return textsecure.api.confirmCode( return TextSecureServer.confirmCode(
number, verificationCode, password, signalingKey, registrationId, single_device number, verificationCode, password, signalingKey, registrationId, single_device
).then(function(response) { ).then(function(response) {
textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1); textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1);

View file

@ -14,9 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
window.textsecure = window.textsecure || {}; TextSecureServer = function () {
window.textsecure.api = function () {
'use strict'; 'use strict';
var self = {}; var self = {};

View file

@ -128,7 +128,7 @@ window.textsecure.utils = function() {
var handleAttachment = function(attachment) { var handleAttachment = function(attachment) {
function getAttachment() { function getAttachment() {
return textsecure.api.getAttachment(attachment.id.toString()); return TextSecureServer.getAttachment(attachment.id.toString());
} }
function decryptAttachment(encrypted) { function decryptAttachment(encrypted) {

View file

@ -30,7 +30,7 @@
constructor: MessageReceiver, constructor: MessageReceiver,
connect: function() { connect: function() {
// initialize the socket and start listening for messages // initialize the socket and start listening for messages
this.socket = textsecure.api.getMessageWebsocket(); this.socket = TextSecureServer.getMessageWebsocket();
var eventTarget = this.target; var eventTarget = this.target;
new WebSocketResource(this.socket, function(request) { new WebSocketResource(this.socket, function(request) {

View file

@ -40,9 +40,9 @@ window.textsecure.messaging = function() {
var promises = []; var promises = [];
if (updateDevices !== undefined) if (updateDevices !== undefined)
for (var i in updateDevices) for (var i in updateDevices)
promises[promises.length] = textsecure.api.getKeysForNumber(number, updateDevices[i]).then(handleResult); promises[promises.length] = TextSecureServer.getKeysForNumber(number, updateDevices[i]).then(handleResult);
else else
return textsecure.api.getKeysForNumber(number).then(handleResult); return TextSecureServer.getKeysForNumber(number).then(handleResult);
return Promise.all(promises); return Promise.all(promises);
} }
@ -88,7 +88,7 @@ window.textsecure.messaging = function() {
for (var i = 0; i < deviceObjectList.length; i++) for (var i = 0; i < deviceObjectList.length; i++)
promises[i] = addEncryptionFor(i); promises[i] = addEncryptionFor(i);
return Promise.all(promises).then(function() { return Promise.all(promises).then(function() {
return textsecure.api.sendMessages(number, jsonData); return TextSecureServer.sendMessages(number, jsonData);
}); });
} }
@ -239,7 +239,7 @@ window.textsecure.messaging = function() {
var iv = textsecure.crypto.getRandomBytes(16); var iv = textsecure.crypto.getRandomBytes(16);
return textsecure.crypto.encryptAttachment(attachment.data, proto.key, iv).then(function(encryptedBin) { return textsecure.crypto.encryptAttachment(attachment.data, proto.key, iv).then(function(encryptedBin) {
return textsecure.api.putAttachment(encryptedBin).then(function(id) { return TextSecureServer.putAttachment(encryptedBin).then(function(id) {
proto.id = id; proto.id = id;
proto.contentType = attachment.contentType; proto.contentType = attachment.contentType;
return proto; return proto;

View file

@ -15,17 +15,17 @@
*/ */
var getKeysForNumberMap = {}; var getKeysForNumberMap = {};
textsecure.api.getKeysForNumber = function(number, deviceId) { TextSecureServer.getKeysForNumber = function(number, deviceId) {
var res = getKeysForNumberMap[number]; var res = getKeysForNumberMap[number];
if (res !== undefined) { if (res !== undefined) {
delete getKeysForNumberMap[number]; delete getKeysForNumberMap[number];
return Promise.resolve(res); return Promise.resolve(res);
} else } else
throw new Error("getKeysForNumber of unknown/used number"); throw new Error("getKeysForNumber of unknown/used number");
} };
var messagesSentMap = {}; var messagesSentMap = {};
textsecure.api.sendMessages = function(destination, messageArray) { TextSecureServer.sendMessages = function(destination, messageArray) {
for (i in messageArray) { for (i in messageArray) {
var msg = messageArray[i]; var msg = messageArray[i];
if ((msg.type != 1 && msg.type != 3) || if ((msg.type != 1 && msg.type != 3) ||
@ -39,4 +39,4 @@ textsecure.api.sendMessages = function(destination, messageArray) {
messagesSentMap[destination + "." + messageArray[i].destinationDeviceId] = msg; messagesSentMap[destination + "." + messageArray[i].destinationDeviceId] = msg;
} }
} };