Guest User

Untitled

a guest
Nov 7th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. function registerUserPublicKey() {
  2. var user = {
  3. password: '123456Toto'
  4. };
  5. var client = storj.BridgeClient(api, {
  6. basicauth: user
  7. });
  8. // Generate KeyPair
  9. var keypair = storj.KeyPair();
  10. console.log(keypair);
  11. // Load keypair from your saved private key
  12. //var keypair = storj.KeyPair(fs.readFileSync('c:/temp/privatekey').toString());
  13. // Login using the keypair generated
  14. var client = storj.BridgeClient(api, {
  15. keyPair: keypair
  16. });
  17. fs.writeFileSync('c:/temp/privatekey', keypair.getPrivateKey());
  18. // Add the keypair public key to the user account for authentication
  19. client.addPublicKey(keypair.getPublicKey(), function (err) {
  20. console.log(keypair.getPublicKey());
  21. if (err) {
  22. // Handle error on failure.
  23. return console.log('error', err.message);
  24. }
  25. // Save the private key for using to login later.
  26. // You should probably encrypt this
  27. fs.writeFileSync('c:/temp/privatekey', keypair.getPrivateKey());
  28. console.log("User " + user + " registred successfully");
  29. });
  30. }
Advertisement
Add Comment
Please, Sign In to add comment