0.0.5 • Published 2 years ago

aveonfs v0.0.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Aveon NPM Package Walkthrough(aveonfs)

Gitter

  • Aveon is an open sourced,decentralized DataBase & Secure Auth provider for Web3 Development.
  • Based on IPFS, Aveon aims to provide goodness of decentralization and high security with minimal code setup for authentication purposes like Register,Login,etc.

Purpose of this?

  • The purpose of starting this project is to apply the concept of decentralization without actually using complex blockchains and solidity and stuff,To study decentralization and speculate the capacity of P2P networks and of course to provide a tool with better security than standard databases like MySql,MongoDb,etc.

  • Basically to speculate if an easier and highly secure counterpart of blockchain is possible or not?

How to use??

Its super easy to use this package :D

1. Step1: npm i aveonfs

2. Step2: Checkout our code snippets below to understand the code usage

Code Examples

WarningPLEASE READ!:

  • All the parameters in example code snippets were specifically generated for example showcase and are not meant to be used in production by developer.

  • For Registering,Parameters like CAT,URK,MDT are generated by RegisterFunction but parameters like UUID and parameter to cut UUID from x to y is supposed to de decided by the developer using the package.

  • It is strictly advised to follow the Instructions mentioned in the Parameters section of each snippet otherwise contact the development team via Issues on Github or by mail if you have any doubts or queries regarding anything.

How to Register??

const aveon = require('aveonfs')

//Parameters to be set
const obj = {username:"lid hqiw",PAASSWD:"d23dh 3 d3"} //user credential object
const uuid = "uuidbyjay12d12d2d12dh182d9129d2udzd129dz20d29dd"
const CUTUUIDFROM = "2"
const CUTUUIDTO = "31"
const RECSECRET = "recsecx"

const var1 = aveon.RegisterUser(obj,uuid,CUTUUIDFROM,CUTUUIDTO,RECSECRET)
var1.then(x=>{console.log(x)})

//BOOM! registeration of user done right there!!!

Code-Explanation =>

  • Firstly we are importing/requiring the aveon package
  • Then we set some parameter variables which are supposed to be passed to the Register Function.Lets understand what parameters are being passed to the function and why?

Parameters to be given to Register Function:

1.obj: JSON object holding user credentials like username,password,email,etc

2.UUID: UUID is basically anything which uniquely identifies a user, in case of apps which have access to system information UUID can be Hardware UUID and for websites it can be a secret phase into the code or as a environment variable set by developer and a part of which will be used as a key for encrypting their CAT(ClientAccessToken). The part to be used as a key is determined by the developer using the package.

3.CutUUIDFrom: The parameter to be given by the developer for deciding from which index to begin UUID slicing.

4.CutUUIDTo: The parameter to be given by the developer for deciding till which index the UUID should be sliced.

5.RECSECRET: Just a secret phrase or key to be given by the developer which will be mixed with arbitary generation of each during recovering the CAT.

  • Parameters All Set!

  • Now what we gonna do is set a variable to our RegisterUser function,pass the parameters in proper sequence to the function and then add a .then block to the variable to receive the returned promise which includes CAT,URK and MDT.

  • Just make it clear CAT to be stored on user's device.

  • URK and MDT are supposed to be stored securely by user just like secret phrase keys.

  • Registeration all done HAHA!

How to Login??

const aveon = require('aveonfs')

const Encat = "U2FsdGVkX18dd5xIavrusBB3xXhUOtE2JHnHHxwiMwx5KEPS2Rkk4zmlF34oJ8QOdavfC2EnLqIPBZv9lyVX0KwVwKRdc6xZd9NB7t6XKGeX65q1DCE8BEsLCrIiyfiKdkbOLtRGWaMn4lSH2cRISA=="
const uuid = "uuidbyjay12d12d2d12dh182d9129d2udzd129dz20d29dd"
const CUTUUIDFROM = "2"
const CUTUUIDTO = "31"

var op = aveon.LoginUser(Encat,uuid,CUTUUIDFROM,CUTUUIDTO)

op.then(x=>{console.log(x)})

Code-Explanation =>

  • Firstly we are importing/requiring the aveon package
  • Then we set some parameter variables which are supposed to be passed to the Login Function.Lets understand what parameters are being passed to the function and why?

Parameters to be given to LoginUser Function:

  1. Encat: Encat is basically Encrypted CAT which we stored on user's side during Registeration process.

  2. UUID: UUID is basically anything which uniquely identifies a user, in case of apps which have access to system information UUID can be Hardware UUID and for websites it can be a secret phase into the code or as a environment variable set by developer and a part of which will be used as a key for encrypting their CAT(ClientAccessToken). The part to be used as a key is determined by the developer using the package.

  3. CutUUIDFrom: The parameter to be given by the developer for deciding from which index to begin UUID slicing.

  4. CutUUIDTo: The parameter to be given by the developer for deciding till which index the UUID should be sliced.

NOTE- Please make sure that UUID, CutUUIDFrom and CutUUIDTo parameter were same for a specific user during their registeration and login process.

  • Parameters all set!

  • Now what we gonna do is set a variable to our Loginuser function,pass the parameters in proper sequence to the function and then add a .then block to the variable to receive the returned promise which includes user object

  • Login all done HAHA!

How to recover CAT?

  • Well yes now comes the point on how we recover user's CAT incase it is deleted from user's device

  • Thats why we provided you URK!

const aveon = require('aveonfs')

const URK = "QmdWiJ9QKrJfC96pnoPEuy47UdpEcCSrYcQLFHUm8m68hgf6b24ba1-1931-4b4b-bf9b-2f7f75d228b6"
const RECSECRET = "recsecx"


var op = aveon.RecoverUserCAT(URK,RECSECRET)

op.then(x=>{console.log(x)})

Parameters to be given to RecoverUserCAT function:

  1. URK: The URK which developer asked their user to safeguard.

  2. RECSECRET: Secret set by developer.

  • Parameters all set!

  • Now what we gonna do is set a variable to our RecoverUserCAT function,pass the parameters in proper sequence to the function and then add a .then block to the variable to receive the returned promise which includes the retrieved/recovered CAT for the user.

How to Update??

const aveon = require('aveonfs')

const Encat = "U2FsdGVkX19PMlQ9EDUfI4JFfvLQyvXTCSbo2V1/Kr1kWFNmRhaWib+IsD3Rmy2OV2+VBZw0e+mq8HLjOc8GHg4lE27pCLBet9iQjvyyz0DitNp70ciOoXRewD9b6Y7wz4HIzxV2EjxLdtb2zsyTmQ=="
const uuid = "uuidbyjay12d12d2d12dh182d9129d2udzd129dz20d29dd"
const URK = "QmNwHC2S3jTgPm38jMNtZBfUn1ofieMsFxcfftNNRkfFJdf6b24ba1-1931-4b4b-bf9b-2f7f75d228b6"
const CUTUUIDFROM = "2"
const CUTUUIDTO = "31"
const RECSECRET = "recsecx"
const credential_field = "username"
const new_field_value = "Updated121sO1so" //since i am updating username field so a new username


var op = aveon.UpdateUser(credential_field,new_field_value,Encat,uuid,CUTUUIDFROM,CUTUUIDTO,URK,RECSECRET)

op.then(x=>{console.log(x)})

Parameters to be given to UpdateUser Function:

  1. credential_field: Basically the name of the field i wanna update, remember the name should match the key which you used in credential object during Registeration.

For example: I used obj = {username:"user1",PAASWD:"pass1"} during registeration

As you can see i want to update username so i am using term "username" and not "uname" or anything since thats what i used in credential object while updating.

If i wanted to update password i would use "PAASWD" since that is the key i am using.

  1. new_field_value: Basically the new value i want to update, in my case it would be a new username but it can be a new mail id if you are gonna update mail or password if you gonna update password.

  2. Encat: EncC\at is basically Encrypted CAT which we stored on user's side during Registeration process.

  3. UUID: UUID is basically anything which uniquely identifies a user, in case of apps which have access to system information UUID can be Hardware UUID and for websites it can be a secret phase into the code or as a environment variable set by developer and a part of which will be used as a key for encrypting their CAT(ClientAccessToken). The part to be used as a key is determined by the developer using the package.

  4. CutUUIDFrom: The parameter to be given by the developer for deciding from which index to begin UUID slicing.

  5. CutUUIDTo: The parameter to be given by the developer for deciding till which index the UUID should be sliced.

  6. URK: It is needed for modification purposes, in this case since as we update data on ipfs, the corresponding access hash changes to it and our CAT/URK/MDTs hold access hash in some way.

  7. MDT: It is needed for same modification purposes, in this case since as we update data on ipfs, the corresponding access hash changes to it and our CAT/URK/MDTs hold access hash in some way.

  • Parameters all set!

  • Now what we gonna do is set a variable to our UpdateUser function,pass the parameters in proper sequence to the function and then add a .then block to the variable to receive the returned promise which includes a object with updated CAT/URK/MDT

  • Remember, these updated ones are supposed to be replaced with the existing ones, as i mentioned above for every data change, corresponding access hash changes and CAT/URK/MDT hold access hash in some way, so yeah it is the developer's job to update user's CAT in their device and make them aware about updated URK and MDT.

  • user data updated! Cheers :)

How to Delete User Document?

  • Deleting a user document works a bit differently when it comes to Aveon,Since we use IPFS at core and as we know that data once sent to peers cannot be deleted.

  • So what the developer can do is delete the CAT stored on user's side after user's deletion request.

  • We will come up with a better solution for Deleting if needed by the community.

How to Add User Relations??

  • In case with Aveon, User Relations are defined as every single property linked to a single user on the social network of developer who is developing with Aveon package.

  • For example: User's About me, User's Profile Picture, User's friend list or following list,etc

  • With Aveon, developer has freedom to put in any user relation of their choice by simply creating a json object of the relation and passing it to the method. Lets take a look at Adding Relations below

const aveon = require('aveonfs')

const Encat = "U2FsdGVkX19KIp6c7bWDJxChtjUPWnsQGSLYsnSrClAwihVSg6CJdt15BFMdqoQygF/+zNWgsX0cDGhqOUB7ZCjw8vjxEz3knT0ttmHrl29xwhGHHtUYMZpLXXd0PQ+hQC0ezHDlljNvwSqY230nJw=="
const uuid = "uuidbyjay12d12d2d12dh182d9129d2udzd129dz20d29dd"
const CUTUUIDFROM = "2"
const CUTUUIDTO = "31"
const RECSECRET = "recsecx"
const URK = "QmdWiJ9QKrJfC96pnoPEuy47UdpEcCSrYcQLFHUm8m68hgf6b24ba1-1931-4b4b-bf9b-2f7f75d228b6"
const relations_obj = {userpfp:"ref_of_pfp",userbio:"about user"}

var op = aveon.AddUserRelations(relations_obj,Encat,uuid,CUTUUIDFROM,CUTUUIDTO,URK,RECSECRET)

op.then(x=>{console.log(x)})

Parameters to be given to AddUserRelations Function:

  1. RelationsObj: Basically all user relations which I am storing in above example with a specific user like user's pfp reference, user's bio and user's following and I hope you all can notice that I or anyone using this package as a developer has freedom to put any form of user relation within the object and then pass that whole object to add function.

  2. Encat: Encat is basically Encrypted CAT which we stored on user's side during Registeration process.

  3. uuid: UUID is basically anything which uniquely identifies a user, in case of apps which have access to system information UUID can be Hardware UUID and for websites it can be a secret phase into the code or as a environment variable set by developer and a part of which will be used as a key for encrypting their CAT(ClientAccessToken). The part to be used as a key is determined by the developer using the package.

  4. CutUUIDFrom: The parameter to be given by the developer for deciding from which index to begin UUID slicing.

  5. CutUUIDTo: The parameter to be given by the developer for deciding till which index the UUID should be sliced.

  6. URK: It is needed for modification purposes, in this case since as we update data on ipfs, the corresponding access hash changes to it and our CAT/URK/MDTs hold access hash in some way.

  7. MDT: It is needed for same modification purposes, in this case since as we update data on ipfs, the corresponding access hash changes to it and our CAT/URK/MDTs hold access hash in some way.

NOTE- Please make sure that UUID, CutUUIDFrom and CutUUIDTo parameter were same for a specific user during their registeration and login process.

  • Parameters all set!

  • Now what we gonna do is set a variable to our AddUserRelations function,pass the parameters in proper sequence to the function and then add a .then block to the variable to receive the returned promise which includes a object with updated CAT/URK/MDT

  • Remember, these updated ones are supposed to be replaced with the existing ones, as i mentioned above for every data change, corresponding access hash changes and CAT/URK/MDT hold access hash in some way, so yeah it is the developer's job to update user's CAT in their device and make them aware about updated URK and MDT.

  • Since we add the User Relations straight to the existing user's credential JSON object so yeah you gotta update CAT/URK/MDTs here aswell.

  • user-relations added!Cheers!

How to Fetch User Object??

  • The bonus method to fetch the whole user object.
const aveon = require('aveonfs')

const Encat = "U2FsdGVkX18dd5xIavrusBB3xXhUOtE2JHnHHxwiMwx5KEPS2Rkk4zmlF34oJ8QOdavfC2EnLqIPBZv9lyVX0KwVwKRdc6xZd9NB7t6XKGeX65q1DCE8BEsLCrIiyfiKdkbOLtRGWaMn4lSH2cRISA=="
const uuid = "uuidbyjay12d12d2d12dh182d9129d2udzd129dz20d29dd"
const CUTUUIDFROM = "2"
const CUTUUIDTO = "31"

var op = aveon.FetchUserObject(Encat,uuid,CUTUUIDFROM,CUTUUIDTO)

op.then(x=>{console.log(x)})

Parameters to be given to FetchUserObject Function:

  1. Encat: Encat is basically Encrypted CAT which we stored on user's side during Registeration process.

  2. uuid: UUID is basically anything which uniquely identifies a user, in case of apps which have access to system information UUID can be Hardware UUID and for websites it can be a secret phase into the code or as a environment variable set by developer and a part of which will be used as a key for encrypting their CAT(ClientAccessToken). The part to be used as a key is determined by the developer using the package.

  3. CutUUIDFrom: The parameter to be given by the developer for deciding from which index to begin UUID slicing.

  4. CutUUIDTo: The parameter to be given by the developer for deciding till which index the UUID should be sliced.

NOTE- Please make sure that UUID, CutUUIDFrom and CutUUIDTo parameter were same for a specific user during their registeration and login process.

  • Parameters all set!

  • Now what we gonna do is set a variable to our AddUserRelations function,pass the parameters in proper sequence to the function and then add a .then block to the variable to receive the returned promise which includes the user object.

  • user-object fetched! It is simple as that :D

How will our user have accounts logged in on multiple devices if needed

  • Now this is a bit tricky part but dont worry we got you covered!

  • Since CAT is wrapped around UUID which is specific to each hardware in case of apps, if user tries to migrate their CAT to another new device or a device with existing CAT then the function will not return correct user details and will say we cannot decrypt the CAT for further processing.

  • So what do we do? We use MDT :) yes MultiDeviceTokens are generated during data generation for each user and are outputted with particular methods as you might have seen in some examples.

  • Ask your user to give their MDT and URK to the app and app will process it for you.

  • Lets take a look at code example:

const aveon = require('aveonfs')

const MDT = "U2FsdGVkX1/rfz0hZqDGIl6NQuJ5XMtE9clPd7M6Nb3wH7p/1PaKL9vQ2lxrogZWxFxrsKxhyWT3yCO0vW4PDQ=="
const URK = "QmT65o7yLJxByAmha85MEwP9QiEQdXCxqAHZcK1Dud7Hehf6b24ba1-1931-4b4b-bf9b-2f7f75d228b6"

var op = aveon.AllowMultiDeviceAccess(MDT,URK)

op.then(x=>{console.log(x)})
  • Parameters all set!

  • Now what we gonna do is set a variable to our AllowMultiDeviceAccess function,pass the parameters in proper sequence to the function and then add a .then block to the variable to receive the returned promise which includes the user credentials object.

  • And thats how we do it ;)

How to store any type of data?

  • Apart from Secure Auth abilities,Aveon also provides the developer with an option to store whatever they wish to in form of JSON Object.

  • We are still planning out this feature and will be rolled out soon!

AddData

const aveon = require('aveonfs')

const obj = {Movie: "Inception", Lead: "Leonardo DiCaprio"}
const uuid = "uuidbyjay12d12d2d12dh182d9129d2udzd129dz20d29dd"
const CUTUUIDFROM = "2"
const CUTUUIDTO = "31"
const RECSECRET = "recsecx"

var op = aveon.AddData(obj,uuid,CUTUUIDFROM,CUTUUIDTO,RECSECRET)

console.log(op.then(x=>{console.log(x)}))

Parameters to be given to AddData function

  1. obj: the data, developer wishes to store in a JSON object

  2. uuid: UUID is basically anything which uniquely identifies a user, in case of apps which have access to system information UUID can be Hardware UUID and for websites it can be a secret phase into the code or as a environment variable set by developer and a part of which will be used as a key for encrypting their CAT(ClientAccessToken). The part to be used as a key is determined by the developer using the package.

  3. CutUUIDFrom: The parameter to be given by the developer for deciding from which index to begin UUID slicing.

  4. CutUUIDTo: The parameter to be given by the developer for deciding till which index the UUID should be sliced.

  5. RECSECRET: Secret set by developer.

  • Parameters all set!

  • Now what we gonna do is set a variable to our AddData function,pass the parameters in proper sequence to the function and then add a .then block to the variable to receive the returned promise which includes the CAT/URK/MDT.

  • And now i hope you all are aware about usecases of CAT/URK/MDT.

ReadData

const aveon = require('aveonfs')

const Encat = "U2FsdGVkX1+oQEwLLSJpjQLbXVjKMI+feGwbv7igiWbMcQGz3fYt9/Gs3uG5kRBFRAzXO8qVKbDiv0WnKOLWfla1aRfXWWwDQBsrbWk10CNZBxY5ic2rOqKD8uvAIp799HG3bpHUJVUZFqR7VvBnNA=="
const uuid = "uuidbyjay12d12d2d12dh182d9129d2udzd129dz20d29dd"
const CUTUUIDFROM = "2"
const CUTUUIDTO = "31"
const RECSECRET = "recsecx"

var op = aveon.ReadData(Encat,uuid,CUTUUIDFROM,CUTUUIDTO,RECSECRET)

console.log(op.then(x=>{console.log(x)}))

Parameters to be given to ReadData function

  1. Encat: Encat is basically Encrypted CAT which we stored on user's side during Registeration process.

  2. uuid: UUID is basically anything which uniquely identifies a user, in case of apps which have access to system information UUID can be Hardware UUID and for websites it can be a secret phase into the code or as a environment variable set by developer and a part of which will be used as a key for encrypting their CAT(ClientAccessToken). The part to be used as a key is determined by the developer using the package.

  3. CutUUIDFrom: The parameter to be given by the developer for deciding from which index to begin UUID slicing.

  4. CutUUIDTo: The parameter to be given by the developer for deciding till which index the UUID should be sliced.

  5. RECSECRET: Secret set by developer.

  • Parameters all set!

  • Now what we gonna do is set a variable to our AddData function,pass the parameters in proper sequence to the function and then add a .then block to the variable to receive the returned promise which includes the data object which we passed above in AddData.

  • Easy peasy! If you made it till here then pat yourself on the back because we gonna discuss the last method of Aveon now.

UpdateData

const aveon = require('aveonfs')

const Encat = "U2FsdGVkX19owfRSHodGrZSSjAkHTFWLNcKyNQd2OJ+maPnzo/JsWb1UjVguQZBwOVH5XNMeCpKmGG0W7pfrM2cEe0YPqU866CXb3+ed63g4ATfTUF7lwmElxIXeZtfgBCECnAzW4k3ws5PhhsheVg=="
const uuid = "uuidbyjay12d12d2d12dh182d9129d2udzd129dz20d29dd"
const URK = "QmTNuJRGhixh12rBif7VEmXZ9DowbUxK7QZpeV6RnjX7Ze7636497b-ae0e-48e1-95f3-a574f2408c7e"
const CUTUUIDFROM = "2"
const CUTUUIDTO = "31"
const RECSECRET = "recsecx"
const credential_field = "director"
const new_data_added = "C. Nolan"


var op = aveon.UpdateData(credential_field,new_data_added,Encat,uuid,CUTUUIDFROM,CUTUUIDTO,URK,RECSECRET)

console.log(op.then(x=>{console.log(x)}))

Parameters to be given to ReadData function

  1. credential_field: Basically the name of the field i wanna update, remember the name should match the key which you used in credential object during Registeration.

  2. new_data_added: Basically the new value i want to update, in my case it would be a new username but it can be a new mail id if you are gonna update mail or password if you gonna update password.

  3. Encat: Encat is basically Encrypted CAT which we stored on user's side during Registeration process.

  4. uuid: UUID is basically anything which uniquely identifies a user, in case of apps which have access to system information UUID can be Hardware UUID and for websites it can be a secret phase into the code or as a environment variable set by developer and a part of which will be used as a key for encrypting their CAT(ClientAccessToken). The part to be used as a key is determined by the developer using the package.

  5. URK: It is needed for modification purposes, in this case since as we update data on ipfs, the corresponding access hash changes to it and our CAT/URK/MDTs hold access hash in some way.

  6. CutUUIDFrom: The parameter to be given by the developer for deciding from which index to begin UUID slicing.

  7. CutUUIDTo: The parameter to be given by the developer for deciding till which index the UUID should be sliced.

  8. RECSECRET: Secret set by developer.

  • Parameters all set!

  • Now what we gonna do is set a variable to our AddData function,pass the parameters in proper sequence to the function and then add a .then block to the variable to receive the returned promise which includes the data object which we passed above in AddData.

  • Easy peasy! If you made it till here then pat yourself on the back because we gonna discuss the last method of Aveon now.

Support:

It is my humble request to all the developers using the package to please contribute and improvise this package if needed.

Thank you.

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago