Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <sstream>
  2.  
  3. #include <napi.h>
  4.  
  5. #include "ed25519.h"
  6.  
  7. #define SEED_LENGTH 32
  8.  
  9. namespace bindings_ed25519
  10. {
  11. Napi::Value create_seed(const Napi::CallbackInfo &info)
  12. {
  13. Napi::Env env = info.Env();
  14.  
  15. if(info.Length() != 0)
  16. {
  17. Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException();
  18. return env.Null();
  19. }
  20.  
  21. unsigned char seed[SEED_LENGTH];
  22. int code = ed25519_create_seed(seed);
  23. if(code != 0)
  24. {
  25. Napi::TypeError::New(env, "Failed to create seed").ThrowAsJavaScriptException();
  26. return env.Null();
  27. }
  28.  
  29. return Napi::Buffer<unsigned char>::Copy(env, seed, SEED_LENGTH);;
  30. }
  31.  
  32. /* ... */
  33. }
  34.  
  35. Napi::Object init(Napi::Env env, Napi::Object exports)
  36. {
  37. exports.Set(Napi::String::New(env, "ed25519_create_seed"), Napi::Function::New(env, bindings_ed25519::create_seed));
  38. return exports;
  39. }
  40.  
  41. NODE_API_MODULE(addon, init)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement