Wallet Infrastructure

Published on
January 15, 2022
Published by
G2C Team

All applications created using the G2C Suite are based on a powerful wallet infrastructure that uses a series of objects and structures that live on the blockchain using the Metanet protocol. The most important entities of the wallet infrastructure are the application and the user:

  • An application object is the root object from which all children objects hang (users).
  • Users are objects with a well defined data structure where each have a wallet to operate into the application.

So, beginning with the creation of the application object, G2C Suite builds a data based object tree structure in which the application object is its root, all the users are branches and the user objects (objects that belong to each user) are the leaves.

As follows the process of application and user creation.

Create application

The first step to perform is the creation of an application using the G2C control panel. The process is simple and straightforward and can be completed in just a few minutes.

As a result, the blockchain objects are generated and you obtain a random collection of 12 words to authenticate the application owner. These words must be stored in a safe place since they allow access to operate on behalf of the application owner.  

Create application user

The process of creation of an application user requires the collaboration of both client and backend code. From the client side, g2c_getRandomWords() function must be called before doing anything:

getRandomWords() {
   try {
     const words = g2c_getRandomWords();
     return words;
   } catch (error) {
     throw error;
   }
 }

As a result, this function generates a random valid collection of 12 words. These words must be stored securely, as anyone with access to them can access to the attached wallet.

Next, the second step, is calling the function g2cclient_createUser() from the client side, using the 12 word generated in the previous step.

async createUser() {
   try {
     // const createUserParameters = {
     //    userwords,
     //    application,
     //    nick
     // }
     await g2cclient_createUser(createUserParameters, (response) => {
       // do whatever you want to do to process the response (also control errors)
       const userAuth = response.data.userauth;
     });
   } catch (error) {
     throw error;
   }
}

As a consequence of this function call, the client side obtains a userauth authorization token that must be provided in the next step of the process. Note that with this separation of concerns between client and server side code, the collection of 12 words never flows to the server nor leaves the client side, so the privacy of this critical data is preserved.

As these calls write to the blockchain, the application wallet must be funded with sats in order to proceed with the involved transactions. This way also, it is not possible to create bulky dummy users indefinitely.

As said before, the last step involves the collaboration of both client and server side, so the server side has to call the g2cserver_createApplicationUser() function from the G2C Suite. The userauth authorization token generated just before must be used as an input parameter.

async createApplicationUser() {
 try {
   // const createApplicationUserParameters = {
   //    apptokenid,
   //    apptokens1,
   //    apptokenc1,
   //    userauth,
   //    application,
   //    nick,
   // }
   await g2cserver_createApplicationUser(createApplicatonUserParameters, (response) => {
     // do whatever you want to do to process the response (also control errors)
     const profile = response.data.profile; // txid of new user profile
     const userRoot = response.data.userroot; // txid of rnew user root tree
     const costs = response.data.costs; // object with attached costs
   });
 } catch (error) {
   throw error;
 }
}

As a result, this function call returns the identification of the involved blockchain transactions and an expenses summary.