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 🙏

© 2025 – Pkg Stats / Ryan Hefner

earthid-web-sdk

v1.0.23

Published

A simple SDK for interacting with EarthID's web features

Readme

EarthID Web SDK

A lightweight SDK to easily integrate EarthID's web-based identity and document-sharing features into your web or JavaScript application.

Supports secure authentication, QR code generation, and real-time socket communication with the EarthID platform.


📦 Installation

Install via npm:

npm install earthid-web-sdk

🚀 Quick Start

import EarthIDSDK from 'earthid-web-sdk';

const sdk = new EarthIDSDK({
  apiKey: 'YOUR_API_KEY',
  baseUrl: 'https://stage-apiv2.myearth.id',
  socketUrl: 'https://stage-socketv2.myearth.id',
  debug: true  // Optional: Enable debug logging
});

📚 Table of Contents

  • Installation
  • Quick Start
  • Initialization
  • API Methods
    • getVendor
    • generateHash
    • generateQrCodeNest
    • listenForServiceProviderResponse
    • listenForUserData
    • disconnect
  • QR Code Use Cases & Examples
  • Typical Flow Sequence
  • License

🛠 Initialization

Initialize the SDK using your EarthID credentials:

const sdk = new EarthIDSDK({
  apiKey: 'YOUR_API_KEY',
  baseUrl: 'https://stage-apiv2.myearth.id',
  socketUrl: 'https://stage-socketv2.myearth.id'
});

📡 Available Methods

1. getVendor()

Fetch vendor information using your vendor API key and a session ID.

const vendor = await sdk.getVendor('VENDOR_API_KEY', 'SESSION_ID');
console.log(vendor);

Returns vendor metadata including secretKey and apiKey.


2. generateHash()

Generate a secure HMAC SHA-256 hash for authentication.

const timestamp = Date.now();
const hash = sdk.getHash('VENDOR_SECRET_KEY', 'VENDOR_API_KEY', timestamp);

Parameters:

  • vendorSecretKey (string)
  • vendorApiKey (string)
  • timestamp (number, optional)

3. generateQrCodeNest()

Generate a QR code for a specific request type using a hash.

const qrCode = await sdk.generateQrCodeNest(hash, 'VENDOR_API_KEY', timestamp, 'document');

4. listenForServiceProviderResponse()

Listen for service provider events via WebSocket:

sdk.listenForServiceProviderResponse((err, data) => {
  if (err) console.error(err);
  else console.log('Service Provider:', data);
});

5. listenForUserData()

Listen for user authentication data:

sdk.listenForUserData((err, data) => {
  if (err) console.error(err);
  else console.log('User Data:', data);
});

6. disconnect()

Disconnect from the WebSocket server:

sdk.disconnect();

📘 QR Code Use Cases & Examples

When calling generateQrCodeNest(), the requestType parameter determines the use case:

| Request Type | Description | |------------------|-----------------------------------------------------------------------------| | login | Initiate Passwordless(QR-based) login and wallet authentication | | document | Request for document access from wallet | | selectiveData | Selective Data Disclosure — request specific fields from user's document | | minAge | Request Proof of Age for ZKP for minimum age (e.g., 18+, 21+) | | ageRange | Request Proof of Age for a specific age range (e.g., 5-12, 18-35) | | balance | Request proof of minimum wallet balance | | idvProof | Request for ID Verification proof from the wallet |

Examples:

  1. Passwordless Login flow
const qr = await sdk.generateQrCodeNest(hash, apiKey, timestamp, 'login');
  1. Document request
const qr = await sdk.generateQrCodeNest(hash, apiKey, timestamp, 'document');
  1. Selective Data Disclosure
const qr = await sdk.generateQrCodeNest(hash, apiKey, timestamp, 'selectiveData');
  1. ZKP Minimum Age (e.g., 18+)
const zkpData = {
    "request": "minAge",
    "type": "date",
    "value": inputValue(i.e. 18, 21, etc.),
    "unit": "years"
}

const zkpDataString = JSON.stringify(zkpData);

const jsonStringWithSingleQuotes = zkpDataString.replace(/"/g, "'");

const qr = await sdk.generateQrCodeNest(hash, apiKey, timestamp, jsonStringWithSingleQuotes);
  1. ZKP Age Range (e.g., 18-35)
const ageData = {
      request: "ageRange",
      type: "date",
      minValue: "13",
      maxValue: "16",
      unit: "years"
};

const ageDataString = JSON.stringify(ageData);

const jsonStringWithSingleQuotes = ageDataString.replace(/"/g, "'");

const qr = await sdk.generateQrCodeNest(hash, apiKey, timestamp, jsonStringWithSingleQuotes);
  1. ZKP for Proof of Funds
const zkpData = {
    "request": "balance",
    "type": "number",
    "minimum": formDataJson.inputValue
}

const zkpDataString = JSON.stringify(zkpData);

const jsonStringWithSingleQuotes = zkpDataString.replace(/"/g, "'");

const qr = await sdk.generateQrCodeNest(hash, apiKey, timestamp, jsonStringWithSingleQuotes);
  1. ID Verification Proof
const idvData = {
    "request": "idvProof",
    "company": "EarthID"
}

const idvDataString = JSON.stringify(idvData);

const jsonStringWithSingleQuotes = idvDataString.replace(/"/g, "'");

const qr = await sdk.generateQrCodeNest(hash, apiKey, timestamp, jsonStringWithSingleQuotes);

🔁 Typical Flow Sequence (Example: Login)

Below is the typical sequence for initiating a secure login flow using the SDK:

// Step 1: Create SDK instance
const sdk = new EarthIDSDK({ apiKey, baseUrl, socketUrl });

// Step 2: Get vendor metadata
const vendor = await sdk.getVendor('VENDOR_API_KEY', 'SESSION_ID');

// Step 3: Generate a secure hash
const timestamp = Date.now();
const hash = sdk.getHash(vendor.values[0].secretKey, vendor.values[0].apiKey, timestamp);

// Step 4: Generate QR code for login (or any request type)
const qrCode = await sdk.generateQrCodeNest(hash, vendor.values[0].apiKey, timestamp, 'login');

// Step 5: Set up listeners to receive data in real-time
sdk.listenForServiceProviderResponse((err, data) => console.log('Service Provider:', data));
sdk.listenForUserData((err, data) => console.log('User Data:', data));

// Step 6: After receiving the user data process it for further verification or data handling as per the use case

Use the same sequence for any other request type — just change the last parameter in generateQrCodeNest() based on your use case.


🧪 Debug Mode

Enable debug logging by passing debug: true during initialization. Logs include socket connections, QR code responses, and internal status.


📦 Version

The SDK includes a static version:

console.log(EarthIDSDK.version); // "1.0.0"

📝 License

MIT License — Feel free to use, modify, and contribute.