This is a experimental implementation of polygon account abstraction and polygon ID for the Polygon DevX EMEA Hackathon X, performed in august 2023 by the Nila team based in Amsterdam, the Netherlands.
The challenge is too build an off-chain and on-chain issuer and user wallet that can be solely operated from a WhatsApp environment with a WABA account. To reach our Nila customers, web3 UX is too difficult to use. Please read the attached presentation or Buildl description for more business challenge related information.
There are three main components in this application:
- The chatbot flows using a custom made json-flow builder for front-end communication
- The nodeJS server providing 3 APIs to request credentials and generate proof
- additional Python Lambda functions to run the chatbotflow (webhooks,userKYC,etcetera.)
Nila is registered as Aadhava Agri Services Private Limited
The Nila-id node comes with a number of limitations
-
The BabyJubJub key is randomly generated, future versions will look at using the private key to securily generate and reinstantiate the BJJ key. This will save storing and fetching seed keys from the backend storage after each run.
-
As the Nila-sensing-network (formally chitta) is not available on Polygon, we are not able to create production-ready origin certificates.
-
It is impossible for now to verify multiple queries at once, this makes the UX very complex and cumbersome.
-
The JS-SDK Polygon ID documentation is incomplete and unclear. It uses different naming between examples, tutorials and documentation.
-
The UX provides a lot of QR codes to the user. It is likely he will get confused, in next version, the use of shorturls might be an improvement over qr images.
Our users in general are not proficient in english. Our chatbot is created to allow any minor language to be hardcoded into the UI. for the nila-id experiment we only used english. Others versions of the chatbot are also responding in Tamil, Kannada, Telugu and Hindi.
The nila-id-sdk instantiates the credentials and identity from a persistent database (DynamoDB) into the common in-memory database used by PolygonID.
Unlike the polygonID JS-SDK, the Nila-id-sdk has the ability to restore a privatekey of the issuer or user. This allows off-chain credentials to be created and proof generated. Knowing its 'not web3' limitations, the Nila team will move to minimalizing the middleware need and create certificates onchain using account abstraction.
- NodeJS => 18.x
- Python => 3.9
- Typescript => 5.1.x
- npm => 9.x.x
- docker => 20.x
- serverless => 3.33
- ethereum provider account (e.g Alchemy)
- a verified META WhatsApp for business (WABA)
- a twillio account to launch the custom JSON flow
- AWS account for S3 and dynamoDB (you can choose other providers at your convenience)
- a phone number at your disposal with an allowed country prefix; e.g +1
# reverse hash service url
RHS_URL="https://rhs-staging.polygonid.me"
# state v2 contract address in the mumbai network
ORIGIN_CERTS_CONTRACT="0x134B1BE34911E39A8397ec6289782989729807a4"
# Nila crop token minter in the mumbai network (check latest version)
FIELD_ACTIVITY_MINT_CONTRACT="0x134B1BE34911E39A8397ec6289782989729807a4"
# path to the circuits folder
CIRCUITS_PATH="./circuits"
# url to polygon mumbai network rpc node
RPC_URL="https://rpc-mumbai.maticvigil.com"
# provider api keys
# if you use another provider then alchemy, please change the ethers.providers.AlchemyProvider to your provider
PROVIDER_API_KEY=<PROVIDER_API_KEY>
#AWS KEYS
ACCESSKEYID=<AWS_IAM_ACCESS_KEY>
SECRETACCESSKEY=<AWS_IAM_SECRET_ACCESS_KEY>
REGION=<AWS_REGION>
ENDPOINT=<AWS_ENDPOINT>
S3BUCKET=<S3_BUCKET_FOR_CREATED_QR_IMAGES>
# Twilio
ACCOUNT_SID=<TWILLIO_ACCOUNT_SID>
AUTH_TOKEN=<TWILLIO_AUTH_TOKEN>
# url
URI=<NODEJS_SERVER_URI>
- 'Say hi 👋' to the WABA phone number you registered with.
- Register your property using the prop flow.
- Type 'Sell' to invoke the origin certification
- if a cultivation and a harvest event are detected, the origin certificate and proof QR will be send to the registered WhatsApp user.
- the proof QR can be shared, send to anyone interested.
- Answer the storage questions.
- if in store or will be stored, let the storage manager scan the storage QR.
-- storage manager flow:
- Scan the storage QR (or type 'issue [croptype] storage credentials for [phonenumber]')
- enter quantity
- enter grade
- receive the updated storage account root id.
-- user flow:
- receive result of scan, verify quantity and grade
- if confirmed, the storage certificate and proof QR will be send to the registered WhatsApp user
Proof can only be generated for 2 query types:
Origin:
- Quantity of Type (
return crop type (signals a crop of this type has been cultivated by the userDID)
)
Storage:
- Stored_at_issuer_location (
return user aadhar (signals user produce is stored in issuer storage.)
)
In the future options will be given to generate additional proofs. See the Dorahack BUIDL description for more possible credentials.
Support for cross and mixing proofs, such as 'crop_type on location x' or 'aadhar with x amount' is wanted.
APIs will be limited by a authentication id given in the env file. The id will be hardcoded in the chatbot flow. This means Nila-ID is open to several attack vectors:
- Twilio and Meta potentially have access to the id
- The phone number and the authentication id are the
Future versions of the Nila Account Abstraction will focus on eliminating these threads.
Origin Credentials are not stored locally in this version of nila-id. Even though a credential schema has a expiration date. Credentials are generated for one-time proof.
Storage Credentials are not stored locally in this version of nila-id. Storage credentials will be stored on-chain in future versions, as branches in a storage merkle tree.
- Get an account at Twilio
- Sign-up for WABA messaging
- Update the env file with your account sid and secret
- create the messaging flows, for each flow (handler,supply,etc) type:
python [file_name].py
- Purchase a phone number and link it to the Whatsapp Messaging
- Create a AWS account
- You are ready to go!
- Clone this repository:
git clone https://github.com/Blockchainforcommons/nila-id
- Update the env file
- Deploy onchain issuer contract. Use these next states:
- For mumbai network:
0x134B1BE34911E39A8397ec6289782989729807a4
- For mumbai network:
- Run
npm start
- Open https://localhost:8080 in your web browser
- Please download Ngrok or a similar to ingress the localhost,
- add the Ngrok uri to your chatbot env file
- update the apis endpoints in the flow, for each flow (handler,supply,etc) type:
python [file_name].py
- You are ready to go!
- MacBook M1, OS: Monterey 12.4