This reference application demonstrates how to use BASE API using BASE JS LIBRARY.
The application lets user to choose a passphrase to create his private & public key pair and use his private key to encrypt data and save it to BASE. User can retrieve his data any time and decrypt it using his private key. Either passphrase or private key is never sent to BASE platform.
-
Initialise Base
const base = new Base("https://base-node-staging.herokuapp.com", 'localhost', '', '');
-
Choose a passphrase and crate a keypair
base.createKeyPairHelper('').createKeyPair("some passphrase").then(keyPair => { console.log("PublicKey:" + keyPair.publicKey); console.log("PrivateKey:" + keyPair.privateKey); });
-
Create account or check for existence
let account; try { account = await base.accountManager.checkAccount(passphrase, "somemessage"); } catch(e) { account = await base.accountManager.registration(passphrase, "somemessage"); }
-
Save & Read your data
//Save let data = new Map(); data.set("email", "[email protected]"); let encryptedData = await base.profileManager.updateData(data); //Read let decryptedData = await base.profileManager.getData(); console.log(decryptedData.get("email"));
$ node --version
v8.11.2
$ npm --version
6.1.0
$ npm i
$ npm run start