Component to generate and regenerate a keypair, in a deterministic and private way. The cryptographic part consists of two Zenroom smart contracts, the first executed server-side to generate a seed (based on public data such as user name), the second generate client side, based on the output of the first smart contract and on private information, namely "The challenges".
npm i keypair-lib
import { getSafetyQuestions } from 'keypair-lib'
getSafetyQuestions('en_GB');
outcome:
{
"question1":"Where my parents met?",
"question2":"What is the name of your first pet?",
"question3":"What is your home town?",
"question4":"What is the name of your first teacher?",
"question5":"What is the surname of your mother before wedding?"
}
import { createPBKDF } from 'keypair-lib'
const userData = {
username: "JohnDoe",
email: "[email protected]",
phone: "12345678",
};
const data = await createPBKDF(userData);
content of data will be:
{
"key_derivation": "IF+tlV3TquNpuXVheRz8vKwkD567Nf9YzrI/AIi5Yr0gX62VXdOq42m5dWF5HPw="
}
import { sanitizeAnswers } from 'keypair-lib'
const answers = {
question1: "L'Aquila",
question2: "C arl",
question3: "88 ggg",
question4: "null",
question5: "null",
};
sanitizeAnswers(answers);
outcome:
{
"question1": "laquila",
"question2": "carl",
"question3": "88ggg",
"question4": "null",
"question5": "null",
}
import { recoveryKeypair } from 'keypair-lib'
const answers = {
question1: "Paris",
question2: "ScoobyDoo",
question3: "Amsterdam",
question4: "null",
question5: "null",
};
const PBKDF = "qf3skXnPGFMrE28UJS7S8BdT8g==";
const username = "user";
const data = await recoveryKeypair(answers, PBKDF, username);
outcome:
{
"hashedAnswers": {
"question1.hash": "XdJytPMWt3anuOPQiUs34eQr49XTsgS4pYNsxQWXprE=",
"question2.hash": "2hauYmg/8TGnG5IeCTzlFKHvw1XpxbKaMdmEUbUNQ2c=",
"question3.hash": "ABPAH+DQlCCbi9PSO4+W26vNAd3SoDnuuoLRiRrPDWE=",
"question4.hash": "dCNOmK/nSY+12vHzasLXiswzlGT5UHA7jAGYkvmCuQs=",
"question5.hash": "dCNOmK/nSY+12vHzasLXiswzlGT5UHA7jAGYkvmCuQs=",
},
"user": {
"keyring": {
"edch": "j4CSgFCZO/oD1D4LxM9lZQcSeBM+r7QV5Bj5KG1Avls=",
},
"edch_public_key": "BAWoSHRZrYHfbIVd/dljETf3VeA5Fah5drZUV3T4Z2Y5IgbRA89c06gF6vh3b+QxZhGLd4dCpipecYfjTEgibnQ=",
},
}
import { verifyAnswers } from 'keypair-lib'
const answers = {
question1: "Paris",
question2: "ScoobyDoo",
question3: "Amsterdam",
question4: "null",
question5: "null",
};
const PBKDF = "qf3skXnPGFMrE28UJS7S8BdT8g==";
const publicKey = "BAWoSHRZrYHfbIVd/dljETf3VeA5Fah5drZUV3T4Z2Y5IgbRA89c06gF6vh3b+QxZhGLd4dCpipecYfjTEgibnQ=";
const username = "user";
const data = await verifyAnswers(answers, PBKDF, username, publicKey);
outcome:
true
To configure backend environment variables please put an .env file at the top of your project like this or rename .env.sample to .env:
#BACKEND CREDENTIALS
BACKEND_PRIVATE_KEY=Aku7vkJ7K01gQehKELav3qaQfTeTMZKgK+5VhaR3Ui0=
BACKEND_PUBLIC_KEY=BBCQg21VcjsmfTmNsg+I+8m1Cm0neaYONTqRnXUjsJLPa8075IYH+a9w2wRO7rFM1cKmv19Igd7ntDZcUvLq3xI=
BACKEND_PASSWORD=myVerySecretPassword
#UNCOMMENT HERE IF YOU WANT TO PUT A DIFFERENT CONTRACT
#SERVER_SIDE_CONTRACT=./src/zencode/Keypair-Creation-Server-Side.zen
#CLIENT_SIDE_CONTRACT=./src/zencode/Keypair-Creation-Client-Side.zen
#UNCOMMENT HERE IF YOU WANT TO OVERRIDE FOLDER OR FILENAME default: prop/questions-en_GB.json
#QUESTION_FOLDER=.src/props/
#QUESTION_FILE_PREPEND=questions-