spank-olm.cpp (3036B)
1 #include "spank-olm.hpp" 2 3 // Binding code for emscripten using embind. It should only be included when compiling for Emscripten. 4 #ifdef __EMSCRIPTEN__ 5 #include <emscripten/bind.h> 6 #include <botan/rng.h> 7 #include <botan/der_enc.h> 8 9 EMSCRIPTEN_BINDINGS(spank_olm) 10 { 11 using namespace emscripten; 12 class_<spank_olm::Account>("Account") 13 .constructor<>() 14 .function("new_account", &spank_olm::Account::new_account) 15 .function("sign", &spank_olm::Account::sign) 16 .function("mark_keys_as_published", &spank_olm::Account::mark_keys_as_published) 17 .function("generate_one_time_keys", &spank_olm::Account::generate_one_time_keys) 18 .function("generate_fallback_key", &spank_olm::Account::generate_fallback_key) 19 .function("forget_old_fallback_key", &spank_olm::Account::forget_old_fallback_key) 20 .function("lookup_key", &spank_olm::Account::lookup_key) 21 .function("remove_key", &spank_olm::Account::remove_key) 22 .function("pickle", &spank_olm::Account::pickle) 23 .function("unpickle", &spank_olm::Account::unpickle) 24 .property("identity_keys", &spank_olm::Account::identity_keys, return_value_policy::reference()) 25 .property("one_time_keys", &spank_olm::Account::one_time_keys, return_value_policy::reference()) 26 .property("current_fallback_key", &spank_olm::Account::current_fallback_key, return_value_policy::reference()) 27 .property("prev_fallback_key", &spank_olm::Account::prev_fallback_key, return_value_policy::reference()) 28 .property("next_one_time_key_id", &spank_olm::Account::next_one_time_key_id, return_value_policy::reference()); 29 30 constant("MAX_ONE_TIME_KEYS", spank_olm::MAX_ONE_TIME_KEYS); 31 32 register_optional<spank_olm::IdentityKeys>(); 33 register_optional<spank_olm::OneTimeKey>(); 34 register_optional<spank_olm::OneTimeKey const*>(); 35 36 class_<Botan::Public_Key>("Public_Key"); 37 class_<Botan::X25519_PrivateKey>("X25519_PrivateKey"); 38 class_<Botan::RandomNumberGenerator>("RandomNumberGenerator"); 39 40 41 // Register Ed25519_PrivateKey which cant be default constructed 42 class_<Botan::Ed25519_PrivateKey>("Ed25519_PrivateKey"); 43 44 // Register the secure_vector type for use in the Account struct. 45 // Note that this is downcasted to a vector of uint8_t instead of the original type. 46 register_vector<Botan::uint8_t>("SecureVector"); 47 48 // Register string_view for use in the Account struct. 49 class_<std::string_view>("string_view") 50 .constructor<>(); 51 52 // Register OneTimeKey which cant be default constructed 53 class_<spank_olm::OneTimeKey>("OneTimeKey") 54 .constructor<std::uint32_t, bool, Botan::X25519_PrivateKey>(); 55 56 // Register IdentityKeys which cant be default constructed 57 class_<spank_olm::IdentityKeys>("IdentityKeys") 58 .constructor<Botan::Ed25519_PrivateKey, Botan::X25519_PrivateKey>(); 59 60 // Register FixedSizeArray 61 class_<spank_olm::FixedSizeArray<spank_olm::OneTimeKey, spank_olm::MAX_ONE_TIME_KEYS>>("FixedSizeArrayOneTimeKeys"); 62 } 63 #endif