11#include < emscripten.h>
22#include < emscripten/bind.h>
33#include < iostream>
4+ #include < dilithium.h>
5+ #include < misc.h>
46
57namespace {
8+ class DilithiumWrapper {
9+ explicit DilithiumWrapper ()
10+ :_dilithium() { }
11+
12+ public:
13+
14+ static DilithiumWrapper empty ()
15+ {
16+ return DilithiumWrapper ();
17+ }
18+
19+ std::vector<uint8_t > getSKRaw ()
20+ {
21+ return _dilithium.getSK () ;
22+ }
23+
24+ std::string getSK ()
25+ {
26+ return bin2hstr ( _dilithium.getSK () );
27+ }
28+
29+ std::vector<uint8_t > getPKRaw ()
30+ {
31+ return _dilithium.getPK () ;
32+ }
33+
34+ std::string getPK ()
35+ {
36+ return bin2hstr ( _dilithium.getPK () );
37+ }
38+
39+ private:
40+ Dilithium _dilithium;
41+ };
42+
43+ std::string EMSCRIPTEN_KEEPALIVE
44+ _bin2hstr (const std::vector<unsigned char >& input)
45+ {
46+ return bin2hstr (input, 0 );
47+ }
48+
49+ std::string EMSCRIPTEN_KEEPALIVE
50+ _getString ()
51+ {
52+ return " Test String from Dilithium JS Wrapper" ;
53+ }
54+
55+ int EMSCRIPTEN_KEEPALIVE
56+ crypto_sign_keypair (
57+ unsigned char pk,
58+ unsigned char sk)
59+ {
60+ return crypto_sign_keypair (pk, sk);
61+ }
62+
63+ using namespace emscripten ;
64+
65+ EMSCRIPTEN_BINDINGS (my_module) {
66+
67+ function (" getString" , &_getString);
68+ function (" crypto_sign_keypair" , &crypto_sign_keypair);
69+ function (" bin2hstr" , &_bin2hstr);
70+
71+ class_<DilithiumWrapper>(" Dilithium" )
72+ .class_function (" empty" , &DilithiumWrapper::empty)
73+ .function (" getPKRaw" , &DilithiumWrapper::getPKRaw)
74+ .function (" getPK" , &DilithiumWrapper::getPK)
75+ .function (" getSKRaw" , &DilithiumWrapper::getSKRaw)
76+ .function (" getSK" , &DilithiumWrapper::getSK);
77+ }
78+
679}
0 commit comments