Inspiration

If we can use Metamask in web2 apps, then why not the NEAR wallet? I have seen a lot of apps that are using metamask to log in users into their applications. In those users, users' persona revolves around their wallet address, unlike the traditional login systems where you have to give email or use social login.

What it does

It is a library that gives developers a way to integrate NEAR wallet into their web2 or web3 application. This is just a tool that helps the developers, developer can decide what to do with it.

In the github repo, I have created a demo API that shows how to use the library into a express project to create a JWT token for authentication.

How we built it

The library is built with node js and tweetnacl library. I also want to create library for python developers too.

Challenges we ran into

Main challenge, I faced is signing message on frontend. Unlike web3js or ethers, I couldn’t find a good documentation for signing of the message with near-api-js. I talked with members from NEAR team to solve this issue. They have helped me to get the signature on the frontend.

Maybe, I will raise an issue showing this problem and get a signing function at the top level. I first want to be sure that I am not wrong.

Here is example what I have to do to get to signature function:

walletConnection._near.connection.signer.signMessage(
str2ab("hello,  this is the message and it should be as long as it can be"), 
window..accountId, 
networkId
)

I have created function in library to convert string to array buffer. There maybe function to do this in near-api-js but I couldn’t find so I just created it myself.

“Everything is working on my machine”, (lol) you know what I am talking about.

Main challenge, I am facing right now is when demo API is deployed on the server. I am using onRender to deploy the demo API so judges can test out the demo application. The problem is just while installing the dependencies on the server, it is throwing the error saying “dependency not found”. I just have to figure theat out and demo API will be live for testing by the judges, I will try to get it live soon but I am not sure if that will be in time.

Accomplishments that we're proud of

I am proud of things I worked on to test the APIs. Normally APIs I develop are relatively simple and you can just test it from postman which will give the result. Here that was not possible to I have to actual test it with mocha and chai. I actually tried it and failed miserably.

So in conclusion, I couldn’t test it with actual tests so I just created a script to test it but at least I tried to test API with mocha and chai. Previously, I wouldn’t even try.

What we learned

Learning experience was great. I just spent a lot of time going through the documentation and actual code of near-api-js. From that I learned a lot about the library and how it works.

Also, the inspiration for this project is sign in with ethereum so I tried to back engineer how that library works. To do that, I went through the codebase of SIWE. That took a while.

I read the EIP for sign in with ethereum and structured signature for learning purposes.

What's next for Login with NEAR

Current, I am just using NEAR web wallet. In future, I want to try it with other wallets from NEAR ecosystem.

There are other things that I want to do such as:

  • Create a OAuth 2.0 compliant wallet-based identity provider with LIWN
  • Getting a NEP for login with NEAR (similar to EIP-4361)
  • Improvement in near-api-js to make signature function more accessible (I maybe wrong about this)
  • Get some projects in NEAR ecosystem to try the library and understand how to improve it

Built With

Share this project:

Updates