Files
cell/examples/seif_client.js
John Alanbrook f4ea552271
Some checks failed
Build and Deploy / build-macos (push) Failing after 5s
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
initial try at seif handshake example
2025-05-25 00:07:20 -05:00

50 lines
1.5 KiB
JavaScript

// Seif Handshake Client Example
// Implements the Seif Protocol handshake client side
var crypto = use('crypto');
var json = use('json');
var io = use('io');
// Alice's key pair
var alice_keys = crypto.keypair();
console.log("Alice public key:", alice_keys.public);
console.log("Alice private key:", alice_keys.private);
// Bob's public key (in real usage, this would be obtained separately)
// For this example, we'll use a hardcoded key or read from file
var bob_public_key = null;
// Try to read Bob's public key from file if it exists
if (io.exists('bob_public.key')) {
bob_public_key = io.slurp('bob_public.key').trim();
console.log("Loaded Bob's public key from file:", bob_public_key);
} else {
// For testing, use the server's public key printed by seif_server.js
console.log("Please create bob_public.key with the server's public key");
console.log("Run seif_server.js first to get the public key");
return;
}
// Generate random handshake key
var handshake_key = crypto.keypair().public; // Using public key as random 32-byte value
console.log("Generated handshake key:", handshake_key);
console.log("Sending handshake to server...");
// Contact the server
$_.contact((actor, reason) => {
if (!actor) {
console.error("Could not establish connection:", reason);
return;
}
}, {
address: "localhost",
port: 5678,
seif: 1,
handshake: crypto.encrypt_pk(bob_public_key, handshake_key),
payload: crypto.encrypt(handshake_key, alice_keys.public)
});
$_.receiver(e => {
console.log("Received message:", e);
});