From c5eff859cb2c1250f8408d56ee78ba22edfb22e4 Mon Sep 17 00:00:00 2001 From: Hubert Chathi Date: Fri, 19 Nov 2021 17:48:25 -0500 Subject: [PATCH] add JavaScript function for getting unpublished fallback key --- javascript/index.d.ts | 1 + javascript/olm_post.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/javascript/index.d.ts b/javascript/index.d.ts index 141f695..6b9f7a6 100644 --- a/javascript/index.d.ts +++ b/javascript/index.d.ts @@ -29,6 +29,7 @@ declare class Account { remove_one_time_keys(session: Session); generate_fallback_key(); fallback_key(): string; + unpublished_fallback_key(): string; pickle(key: string | Uint8Array): string; unpickle(key: string | Uint8Array, pickle: string); } diff --git a/javascript/olm_post.js b/javascript/olm_post.js index 450861a..305e4c5 100644 --- a/javascript/olm_post.js +++ b/javascript/olm_post.js @@ -172,6 +172,34 @@ Account.prototype['fallback_key'] = restore_stack(function() { return UTF8ToString(keys, keys_length); }); +Account.prototype['fallback_key'] = restore_stack(function() { + var keys_length = account_method( + Module['_olm_account_fallback_key_length'] + )(this.ptr); + var keys = stack(keys_length + NULL_BYTE_PADDING_LENGTH); + account_method(Module['_olm_account_fallback_key'])( + this.ptr, keys, keys_length + ); + return UTF8ToString(keys, keys_length); +}); + +Account.prototype['unpublished_fallback_key'] = restore_stack(function() { + var keys_length = account_method( + Module['_olm_account_unpublished_fallback_key_length'] + )(this.ptr); + var keys = stack(keys_length + NULL_BYTE_PADDING_LENGTH); + account_method(Module['_olm_account_unpublished_fallback_key'])( + this.ptr, keys, keys_length + ); + return UTF8ToString(keys, keys_length); +}); + +Account.prototype['forget_previous_fallback'] = restore_stack(function() { + account_method(Module['_olm_account_forget_previous_fallback_key'])( + this.ptr + ); +}); + Account.prototype['pickle'] = restore_stack(function(key) { var key_array = array_from_string(key); var pickle_length = account_method(