aboutsummaryrefslogtreecommitdiff
path: root/javascript
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-07-10 11:57:53 +0100
committerMark Haines <mark.haines@matrix.org>2015-07-10 11:57:53 +0100
commitb6e248c9a58cccbcd5dea7bdc8e3cdee4af03722 (patch)
tree0924e69d210b7d6878c7fb11f68b942b15f3ca6c /javascript
parent373acefde7be92f86b8294b325519ad916b1e054 (diff)
Output simpler JSON for the account keys, don't sign the JSON but instead provide a olm_account_sign method so that the user of the library can sign the JSON themselves
Diffstat (limited to 'javascript')
-rw-r--r--javascript/demo.html21
-rw-r--r--javascript/olm_post.js36
2 files changed, 25 insertions, 32 deletions
diff --git a/javascript/demo.html b/javascript/demo.html
index 2120f95..20e780b 100644
--- a/javascript/demo.html
+++ b/javascript/demo.html
@@ -19,8 +19,8 @@ document.addEventListener("DOMContentLoaded", function (event) {
return {start:start, done:done};
}
- var alice = new Olm.Account();
- var bob = new Olm.Account();
+ window.alice = new Olm.Account();
+ window.bob = new Olm.Account();
var a_session = new Olm.Session();
var b_session = new Olm.Session();
var message_1;
@@ -32,19 +32,12 @@ document.addEventListener("DOMContentLoaded", function (event) {
bob.generate_one_time_keys(1);
}]);
tasks.push(["alice", "Create outbound session", function() {
- var bobs_id_keys = JSON.parse(bob.identity_keys("bob", "bob_device", 0, 0));
- var bobs_id_key;
- for (key in bobs_id_keys.keys) {
- if (key.startsWith("curve25519:")) {
- bobs_id_key = bobs_id_keys.keys[key];
- }
- }
+ var bobs_id_keys = JSON.parse(bob.identity_keys());
+ var bobs_id_key = bobs_id_keys.curve25519;
var bobs_ot_keys = JSON.parse(bob.one_time_keys());
var bobs_ot_key;
- for (key in bobs_ot_keys) {
- if (key.startsWith("curve25519:")) {
- bobs_ot_key = bobs_ot_keys[key];
- }
+ for (key in bobs_ot_keys.curve25519) {
+ bobs_ot_key = bobs_ot_keys.curve25519[key];
}
a_session.create_outbound(alice, bobs_id_key, bobs_ot_key);
}]);
@@ -104,7 +97,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
task[2]();
p.done();
window.setTimeout(do_tasks, 50, next);
- }, 0)
+ }, 50)
} else {
next();
}
diff --git a/javascript/olm_post.js b/javascript/olm_post.js
index aa28f86..df1c481 100644
--- a/javascript/olm_post.js
+++ b/javascript/olm_post.js
@@ -63,32 +63,32 @@ Account.prototype['create'] = restore_stack(function() {
);
});
-Account.prototype['identity_keys'] = restore_stack(function(
- user_id, device_id, valid_after, valid_until
-) {
- var user_id_array = array_from_string(user_id);
- var device_id_array = array_from_string(device_id);
+Account.prototype['identity_keys'] = restore_stack(function() {
var keys_length = account_method(
Module['_olm_account_identity_keys_length']
- )(
- this.ptr, user_id_array.length, device_id_array.length,
- valid_after, valid_after / Math.pow(2, 32),
- valid_until, valid_until / Math.pow(2, 32)
- );
- var user_id_buffer = stack(user_id_array);
- var device_id_buffer = stack(device_id_array);
+ )(this.ptr);
var keys = stack(keys_length);
account_method(Module['_olm_account_identity_keys'])(
- this.ptr,
- user_id_buffer, user_id_array.length,
- device_id_buffer, device_id_array.length,
- valid_after, valid_after / Math.pow(2, 32),
- valid_until, valid_until / Math.pow(2, 32),
- keys, keys_length
+ this.ptr, keys, keys_length
);
return Pointer_stringify(keys, keys_length);
});
+Account.prototype['sign'] = restore_stack(function(message) {
+ var signature_length = account_method(
+ Module['_olm_account_signature_length']
+ )(this.ptr);
+ var message_array = array_from_string(message);
+ var message_buffer = stack(message_array);
+ var signature_buffer = stack(signature_length);
+ account_method(Module['_olm_account_sign'])(
+ this.ptr,
+ message_buffer, message_array.length,
+ signature_buffer, signature_length
+ );
+ return Pointer_stringify(signature_buffer, signature_length);
+});
+
Account.prototype['one_time_keys'] = restore_stack(function() {
var keys_length = account_method(
Module['_olm_account_one_time_keys_length']