How to use the libsodium-wrappers.crypto_box_keypair function in libsodium-wrappers

To help you get started, we’ve selected a few libsodium-wrappers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github multiparty / jiff / lib / jiff-client.js View on Github external
sodium_promise.then(function() {
        msg = JSON.parse(msg);
        if(jiff.id == null)
          jiff.id = msg.party_id;

        if(jiff.party_count == null)
          jiff.party_count = msg.party_count;

        if(jiff.secret_key == null || jiff.public_key == null) {
          // this party's public and secret key
          var genkey = sodium.crypto_box_keypair();
          jiff.secret_key = genkey.privateKey;
          jiff.public_key = genkey.publicKey;
        }

        jiff.socket.emit("public_key", '['+jiff.public_key.toString()+']');
        // Now: (1) this party is connect (2) server (and other parties) know this public key
        // Resend all pending messages
        jiff.socket.resend_mailbox();

        jiff.execute_wait_callbacks();
      });
    });
github TankerHQ / sdk-js / packages / crypto / src / tcrypto.js View on Github external
export function makeEncryptionKeyPair(): SodiumKeyPair {
  const out = sodium.crypto_box_keypair();
  delete out.keyType;
  return out;
}
github samuelmaddock / metastream / app / browser / platform / swarm / crypto.ts View on Github external
export function keyPair(): KeyPair {
  const { publicKey, privateKey } = sodium.crypto_box_keypair()
  return {
    publicKey: Buffer.from(publicKey as any),
    secretKey: Buffer.from(privateKey as any)
  }
}
github EQEmu / Server / wi / network / servertalk_client.js View on Github external
SendHandshake() {
		var handshake;
		
		if(this.m_encrypted) {
			var keypair = sodium.crypto_box_keypair();	
			this.m_public_key_ours = keypair.publicKey;
			this.m_private_key_ours = keypair.privateKey;
			this.m_nonce_ours = Buffer.from(sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES));
			this.m_shared_key = sodium.crypto_box_beforenm(this.m_public_key_theirs, this.m_private_key_ours);
			
			this.m_public_key_theirs = null;
			this.m_private_key_ours = null;
					
			var message = Buffer.alloc(this.m_identifier.length + this.m_credentials.length + 2);
			message.write(this.m_identifier, 0);
			message.write(this.m_credentials, this.m_identifier.length + 1);
			
			var ciphertext = sodium.crypto_box_easy_afternm(message, this.m_nonce_ours, this.m_shared_key);
			
			handshake = Buffer.concat([Buffer.from(this.m_public_key_ours), Buffer.from(this.m_nonce_ours), Buffer.from(ciphertext)], sodium.crypto_box_PUBLICKEYBYTES + sodium.crypto_box_NONCEBYTES + ciphertext.length);		
			this.IncrementUint64(this.m_nonce_ours);
github maidsafe / safe_examples / dns_example / src / scripts / safe_api / request_manager.js View on Github external
init: function() {
      try {
        var keyPair = sodium.crypto_box_keypair();
        this.publicKey = keyPair.publicKey;
        this.secretKey = keyPair.privateKey;
        this.nonce = sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES);
      } catch(e) {
        notifierCallback(new Error('Failed to initialise HandshakeKeys - libsodium error'));
      }
    }
  };