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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@justaname.id/sdk

v0.2.136

Published

JustaName SDK is a toolkit for managing Ethereum Name Service (ENS) domains and subnames. It simplifies the integration of ENS functionalities into any application, including resolving ENS names, issuing off-chain subnames, and enabling Sign-In with ENS (

Downloads

4,281

Readme

JustaName SDK

JustaName SDK is a toolkit for managing Ethereum Name Service (ENS) domains and subnames. It simplifies the integration of ENS functionalities into any application, including resolving ENS names, issuing off-chain subnames, and enabling Sign-In with ENS (SIWENS). The SDK supports both Ethereum Mainnet and Testnet environments.

Table of Contents

Motivation

Managing ENS domains and integrating them into applications can be complex and time-consuming. JustaName SDK aims to streamline this process by providing an easy-to-use interface for off-chain ENS management, subname issuance, and authentication using ENS domains. By abstracting the underlying complexities, developers can focus on building feature-rich applications without worrying about ENS integration details.

Features

  • ENS Management: Manage ENS domains and subnames off-chain effortlessly.
  • Subname Issuance: Issue and update subnames without interacting directly with smart contracts.
  • ENS Resolution: Resolve on-chain and off-chain ENS easily within your application.
  • Sign-In with ENS (SIWENS): Authenticate users using their ENS domains for a decentralized and secure sign-in experience.
  • Mainnet and Testnet Support: Compatible with Ethereum Mainnet and Testnet environments.
  • Easy Integration: Simplifies the incorporation of ENS functionalities into any application.

How It Works

JustaName SDK interacts with the JustaName API to perform off-chain operations related to ENS domains and subnames. It handles the necessary cryptographic operations, such as signing messages and verifying signatures, to ensure secure interactions. By using the SDK, developers can perform tasks like issuing subnames, updating records, and authenticating users without dealing with the complexities of the Ethereum blockchain directly.

Installation

Install the package using npm or yarn:

npm install @justaname.id/sdk

# or

yarn add @justaname.id/sdk

Quickstart Guide

Initialization

First, import the JustaName SDK and initialize it with your configuration:

import { JustaName } from '@justaname.id/sdk';
import { ethers } from 'ethers';

// Initialize the SDK with your configuration
const justaname = JustaName.init({
    networks: [
        {
          chainId: 1, // Ethereum Mainnet
          providerUrl: 'https://mainnet.infura.io/v3/YOUR_INFURA_KEY'
        }
    ],
    ensDomains: [
        {
          chainId: 1,
          domain: 'your_ens_domain.eth',
          apiKey: 'your-api-key',
        }
            
    ],
    config: {
        domain: 'yourdapp.com',
        origin: 'https://yourdapp.com'
    }
});

// Create a signer (for example purposes, we're creating a random wallet)
const signer = ethers.Wallet.createRandom();

Issuing a Subname

To issue a subname off-chain, you can use the following code:

async function issueSubname() {
    const challenge = await justaname.siwe.requestChallenge({
        address: signer.address,
        chainId: 1 // Ethereum Mainnet
    });
    
    const signature = await signer.signMessage(challenge.challenge);
    
    const response = await justaname.subnames.addSubname(
    {
        username: 'username1',
        chainId: 1
    },
    {
        xMessage: challenge.challenge,
        xAddress: signer.address,
        xSignature: signature
    });
    
    console.log('Subname issued successfully:', response);
    return response;
}

Updating a Subname

To update records associated with a subname, such as setting an avatar:

async function updateSubname() {
    const challenge = await justaname.siwe.requestChallenge({
        address: signer.address,
        chainId: 1
    });
    
    const signature = await signer.signMessage(challenge.challenge);
    
    const response = await justaname.subnames.updateSubname(
    {
        username: 'username1',
        chainId: 1,
        text: [
            {
            key: 'avatar',
            value: 'https://youravatar.com/avatar.png'
            }
        ]
    },
    {
        xMessage: challenge.challenge,
        xAddress: signer.address,
        xSignature: signature
    });
    
    console.log('Subname updated successfully:', response);
    return response;
}

Signing In with ENS

Enable users to sign in to your application using their ENS domain:

async function signIn() {
    const message = await justaname.signIn.requestSignIn({
        ens: 'your_ens_domain.eth',
        address: signer.address
    });
    
    const signature = await signer.signMessage(message);
    
    const response = await justaname.signIn.signIn({
        message: message,
        signature: signature
    });
    
    console.log('User signed in with ENS:', response.ens);
    return response;
}

Putting It All Together

You can combine these functions to manage subnames and authenticate users:

async function main() {
    await issueSubname();
    await updateSubname();
    await signIn();
}

main().catch(console.error);

Available Methods

Subname Management

  • acceptSubname
  • reserveSubname
  • addSubname
  • updateSubname
  • revokeSubname
  • rejectSubname
  • getSubnamesByEnsDomainWithCount
  • getSubname
  • getSubnamesByAddress
  • getInvitationsByAddress
  • getSubnamesByEnsDomain
  • searchSubnames
  • isSubnameAvailable
  • getRecords
  • getPrimaryNameByAddress

SIWE

  • requestChallenge
  • verifyChallenge

Sign-In with ENS

  • requestSignIn
  • signIn
  • generateNonce

Offchain Resolvers

  • getAllOffchainResolvers

Benefits

Simplified ENS Integration: Abstracts the complexities of interacting with the Ethereum blockchain and ENS smart contracts.

Off-Chain Management: Perform ENS domain and subname operations off-chain, reducing gas costs and improving performance.

Enhanced Security: Utilizes cryptographic signatures to ensure secure operations.

User-Friendly Authentication: Allows users to sign in with their ENS domains, enhancing user experience and security.

Flexible Environment Support: Works seamlessly with both Ethereum Mainnet and Testnet networks.

Contributing

Contributions are welcome! If you have suggestions or find issues, please open an issue or submit a pull request on the GitHub repository.