Skip to content

izertis/tokenization-lib-wallet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tokenization library

Library for web and mobile applications that centralizes the logic of:

  1. Generation and parsing of QRs for Citizens and Merchants.
  2. Interaction with the ERC20 contract "izToken".
  3. Backend call to process tickets.

Environment Variable Configuration

The library needs to initialize the environment variables once at the start of the application (before using any functionality).

Método

initTokenizationLibEnvVars(newVars: Partial<{ BACK_END_URL: string; BLOCKCHAIN_RPC_URL: string; SMART_CONTRACT_ADDRESS: string }>): void

This method should be called only once at the beginning of the app (for example, in your App.tsx), and it’s required for the library to access the backend and blockchain. This function merges the provided variables with the internal configuration. You can call it multiple times, but it is recommended to do it only once at startup.

import { initTokenizationLibEnvVars } from "tokenization-library";

initTokenizationLibEnvVars({
  BACK_END_URL: "https://api.example.com",
  SMART_CONTRACT_ADDRESS: "0x123456789abcdef",
  BLOCKCHAIN_RPC_URL: "https://rpc.sepolia.org",
});

Features

1. Generation and parsing of QRs for Citizens and Merchants.

Generation of strings to be used for QR generation

Methods

  • generateCitizenQR(did: string) > Generates a QR to identify a citizen.

  • generateMechantQR(merchantDID: string, citizenDID: string, CID: string) > Generates a QR for merchant payments. The CID will later be used by the citizen to retrieve the ticket breakdown.

  • parseMerchOrCitizenQR(qr: string) > Utility to parse a QR generated by generateMechantQR() or generateCitizenQR() and validate its structure. For citizens, it returns the DID contained in the QR, and for merchants, it returns the original parameters (merchantDID: string, citizenDID: string, CID: string)

2. Interaction with the ERC20 "izToken" contract

Integrates ethers.js to interact with the pre-generated typechains of the izToken contract.

Methods

  • getTokenBalance(address: string) > Gets the user’s token balance in readable format.

  • getCitizenAidType(address: string) > Returns the benefit type associated with the user: 0 = NONE, 1 = STATIONERY, 2 = GROCERY.

  • getPartyPermission(address: string) > Returns the user’s current role: 0 = NONE, 1 = CITIZEN, 2 = MERCHANT.

  • getMerchantName(address: string) > Returns the registered merchant's name string

  • sendTokens(privateKey: string, toAddress: string, amount: number, eventData?: string) > Sends tokens to another address with optional data. Returns the transaction hash.

  • burnTokens(privateKey: string, amount: number, eventData?: string) > Burns tokens from the user’s balance. Returns the transaction hash.

3. Backend call to process tickets.

Sends tickets in File | Blob | RNFileType format (see type definitions) to the backend API.

Methods

  • processTicketImage(aid_id: AidCodeType, imageFile: TicketProcessingFileType, authorization: string): Sends a ticket image to the backend to process its products and calculate the economic aid.

Input Parameters

  • aid_id (0 | 1 | 2 ) > Identifier for the type of aid (1 = STATIONERY, 2 = GROCERY).

  • imageFile (File | Blob | RNFileType) > Image in File, Blob or React Native format { uri, name, type }.

  • authorization (string) > String with credentials (Bearer or Basic Auth).

Response

The response is an object with:

  • payment_amount > total amount.

  • aid_amount > subsidized amount.

  • aid_products > array of applicable products with name and price.

Build

To build the library:

npm run build

Testing

To run tests:

npm run test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published