This example assumes you have already installed the SDK and generated SDK keys as explained in ο»Ώ
Build a rudimentary blockchain-based password manager in a few lines of code! The code below stores and retrieves encrypted, immutable passwords on the blockchain.
Replace your SDK key and project id and try it out!
const { Mintblue } = require('mintblue');
if(process.argv.length < 4 || !['get', 'add'].includes(process.argv[2])) {
console.log('Usage:');
console.log('Add/Update password: node pwmanage.js add [name] [password]');
console.log('Retrieve password: node pwmanage.js get [name]');
process.exit();
}
const command = process.argv[2];
const name = process.argv[3];
let pw = process.argv[4];
(async () => {
let client = await Mintblue.create({token: '[YOUR_SDK_KEY]'});
let project = '[YOUR_PROJECT_ID]';
if(command === 'add') {
const { txid } = await client.createTransaction({
project_id: project,
outputs: [{
type: 'data',
value: { name, pw },
encrypt: true
}]
});
console.log(`Password stored encrypted in transaction with id ${txid}`);
} else if (command === 'get') {
const txs = await client.listTransactions(project);
for(let i = 0; i < txs.length; i++) {
const payload = await client.getTransaction(txs[i].txid);
if(payload[0].value.name === name) {
console.log(`Password for ${name} is ${payload[0].value.pw}`);
process.exit();
}
}
console.log(`Password not found for ${name}`);
}
})();
ο»Ώ
ο»Ώ