Skip to content

Instantly share code, notes, and snippets.

@edmundmiller
Created March 1, 2019 21:09
Show Gist options
  • Save edmundmiller/6fab6f12643401cf50a6e14c722d9f73 to your computer and use it in GitHub Desktop.
Save edmundmiller/6fab6f12643401cf50a6e14c722d9f73 to your computer and use it in GitHub Desktop.
// Whatever it is to make a web3 call mock to RSA contract
let ethbs;
////////////
// Step 1 //
////////////
let aKeyId = ethbs.createKey(nodeId, 1, keyName, signature, keyInstance);
let CreationEvent = [nodeAAddress, keyId, stepNumber]; //Step number would be 1
////////////
// Step 2 //
////////////
/* CreationEvent triggers this */
let keyName = ethbs.getKeyName(aKeyId);
let nodeId = ethbs.getNodeId(aKeyId);
// Create a new ephemeral RSA key pair on NODE-B key manager.
// Retrieve the ephemeral RSA public key from the NODE-B key manager.
// Encrypt the ephemeral RSA public key with NODE-A’s public key.
let ephKeyId = ethbs.createEphKey(
nodeId,
2,
keyName,
signature,
keyInstance,
encryptedEphKey
);
/* This is the normal creation event */
let ephKeyCreationCreation = [nodeAddress, keyId, stepNumber]; //Step number would be 2
/* This would be the ephEvent. So you can get it on Node A*/
let ephKeyCreationCreation = [encryptedPubKey];
// Sign the encrypted ephemeral RSA public key with the local node’s (NODE-B) private key.
let retrievalRequest = ethbs.requestKey(ephKeyId);
let RequestEvent = [nodeBAddress, keyId]; // Id would be 2
////////////
// Step 3 //
////////////
/* Triggered by RequestEvent */
// Verify the signature of NODE-B
// Verify the RSA key existence in the local key manager.
let whetherNodeBhasAuth = ethbs.getAuthority(ephKeyId, bAddress); // I need to create a user registery
// Verify the user’s authority to the RSA key. /* WIP */
// Decrypt NODE-B’s ephemeral RSA public key with NODE-A’s private key.
// Retrieve the requested RSA key pair from the local key manager.
// Encrypt the retrieved RSA key pair with NODE-B’s ephemeral RSA public key.
// Sign the encrypted RSA key pair with NODE-A’s private key.
let retrievalResponse = ethbs.authorizeNode(ephKeyId, aAddress);
////////////
// Step 4 //
////////////
// A smart contract processes the key response for this node.
// Verify the signature of NODE-A.
// Error:
// Delete the new ephemeral RSA key.
// Record the event in the ledger.
let errorDelete = ethbs.deleteKey(ephKeyId);
let errorDeleteEvent = [addressOfDeleter, ephKeyId];
// If the key retrieval request is rejected:
// Delete the new ephemeral RSA key created for this exchange.
// Record the event in the ledger.
let errorDelete = ethbs.deleteKey(ephKeyId);
let errorDeleteEvent = [addressOfDeleter, ephKeyId];
// Retrieve the ephemeral RSA private key from the key manager.
// Decrypt the RSA key pair using ephemeral RSA private key.
// Import the RSA public and private keys into the local (NODE-B) key manager.
// Delete the new ephemeral RSA key pair created for this exchange.
// Record this event in the ledger.
let errorDelete = ethbs.deleteKey(ephKeyId);
let errorDeleteEvent = [addressOfDeleter, ephKeyId];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment