npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

parse-near-auth-adapter

v0.1.2

Published

Allow users to authenticate with their near wallets

Downloads

3,052

Readme

Near wallet Auth Adapter for parse server

This package allows parse users to login using their near wallets

Install

npm i parse-near-auth-adapter

or if you prefer yarn

yarn add parse-near-auth-adapter

Setup

  1. Add NearAuthAdapter to your parse server options
const { NearAuthAdapter } = require("parse-near-auth-adapter");

const parseServerApi = new ParseServer({
  ...restOfParseOptions,
  auth: {
    NearAuthAdapter: {
      module: NearAuthAdapter,
      tokenValidity: 10000, // how long a signToken is valid in milis (default 15seconds)
      connectionConfig: {
        networkId: "testnet", // if main net change this to main net
        nodeUrl: "https://rpc.testnet.near.org", // change to match network id
        walletUrl: "https://wallet.testnet.near.org", // change to match network id
        helperUrl: "https://helper.testnet.near.org", // change to match network id
        explorerUrl: "https://explorer.testnet.near.org", // change to match network id
      },
    },
  },
});
  1. Setup Cloud code
const { setupNearAuthAdapterCloudCode } = require("parse-near-auth-adapter");

// setup your other cloud functions
setupNearAuthAdapterCloudCode(); // this will set one cloud function used to generate tokens

You are all set now, you can start using it on clients

Client side example (Linking Users)

import * as nearAPI from "near-api-js";
import { sha256 } from "js-sha256";

// we assume you already signin to near wallet via  wallet.requestSignIn()
// we assume Parse user is already signin
const linkWallet = async () => {
  const currentWallet = {
    accountId: walletConnection.getAccountId(),
    balance: (await walletConnection.account().state()).amount,
  };
  // this means the near wallet is not connected to your website (use the near requestSignin to connect near wallet to your website)
  if (!currentWallet?.accountId) return;

  const res = await Parse.Cloud.run("getNearSignToken", { walletId: currentUser?.accountId }).catch((error) => {
    // handle error
  });
  // this is the token that needs to be signed
  const token = res?.data?.get("token");

  // get the signer from the wallet connection
  const signer = (await wallet.account()).connection.signer;
  // get the keyPar for the signer
  const key = await signer.keyStore.getKey(nearConfig.networkId, currentUser.accountId);
  // sha256 the token to prepare for signing
  const digestedToken = new Uint8Array(sha256.array(token));

  // sign using the key pair
  const signed = await key.sign(digestedToken, currentUser.accountId, nearConfig.networkId);

  // get string representation of public key
  const publicKey = key.publicKey.toString();
  // get hex representation of the signature
  const signature = Buffer.from(signed.signature).toString("hex");
  // id is the connected near wallet accountId
  const id = currentUser.accountId;

  // more details on the please visit:
  // https://docs.parseplatform.org/js/guide/#linking-users
  // The NearAuthAdapter expects this authdata
  const authData = { publicKey, signature, id, token };

  let provider;
  provider = {
    authenticate: (options) => {
      options.success(provider, { ...authData });
    },
    restoreAuthentication() {
      return true;
    },

    getAuthType() {
      return "NearAuthAdapter";
    },

    getAuthData() {
      return {
        authData: {
          ...authData,
        },
      };
    },
  };

  // get current logged in Parse User
  const user = await Parse.User.currentAsync();
  // register the provider to allow linking
  await Parse.User._registerAuthenticationProvider(provider);
  // link user with the provider
  await user.linkWith(provider.getAuthType(), authData).catch((error) => {
    // handle error
  });
  // check if linked
  user._isLinked(provider); // should be true
};

Client side example (Login)

const login = async () => {
  const currentWallet = {
    accountId: walletConnection.getAccountId(),
    balance: (await walletConnection.account().state()).amount,
  };
  // this means the near wallet is not connected to your website (use the near requestSignin to connect near wallet to your website)
  if (!currentWallet?.accountId) return;

  // call cloud function to get a fresh token
  const res = await Parse.Cloud.run("getNearSignToken", { walletId: currentUser?.accountId }).catch((error) => {
    // handle error
  });
  // this is the token that needs to be signed
  const token = res?.data?.get("token");

  // get the signer from the wallet connection
  const signer = (await wallet.account()).connection.signer;
  // get the keyPar for the signer
  const key = await signer.keyStore.getKey(nearConfig.networkId, currentUser.accountId);
  // sha256 the token to prepare for signing
  const digestedToken = new Uint8Array(sha256.array(token));

  // sign using the key pair
  const signed = await key.sign(digestedToken, currentUser.accountId, nearConfig.networkId);

  // get string representation of public key
  const publicKey = key.publicKey.toString();
  // get hex representation of the signature
  const signature = Buffer.from(signed.signature).toString("hex");
  // id is the connected near wallet accountId
  const id = currentUser.accountId;

  // more details on the please visit:
  // https://docs.parseplatform.org/js/guide/#linking-users
  // The NearAuthAdapter expects this authdata
  const authData = { publicKey, signature, id, token };

  const user = await Parse.User.LogInWith("NearAuthAdapter", {
    authData,
  }).catch((error) => {
    // handle error
    // probably no linked wallet , or signature mismatch
  });
  if (user) {
    // user is the currently logged in user
  }
};

How Does it work ?

The Near Auth adapter is simple and straight forward, these are the steps

  1. client requests a token (the token is a randomly generated base64Url string)
  2. client hashes the token using sha256 and then sign it through the near-js-api
  3. client sends to Parse Server the near accountId, publicKey as string (from the pair that signed the token), the token as string, and a hex string representation of the signature
  4. Parse server will check the following and only link/login if all pass:
    • the provided publicKey is actually a valid accessKey that belongs the provided near accountID
    • The token is a valid token generated by parse server and is not older than 5 minutes
    • the signature is valid

Licence:

Project is distributed under MIT license.

contributions

Contributions are welcomes

Sponsors

This adapter was made possible by agoraneos