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

@cns-space/cns-resolver-sdk

v1.1.1

Published

CNS resolver sdk for querying on-chain user records

Downloads

54

Readme

CNS Resolver SDK

This is the for resolving official CNS information. This documentation would outline the technical details and APIs provided. For any projects interested in integrating CNS information, here provides sufficient information on either implementing the resolving logics separately or directly using the SDK.

Getting Started

Install

yarn add @cns-space/cns-resolver-sdk

or

npm install @cns-space/cns-resolver-sdk

Using the resolver

import { CNSResolver, MaestroCNS } from '@cns-space/cns-resolver-sdk';

// Initiating the resolver instance
const network: 'preprod' | 'mainnet' = 'preprod';
const resolver = new CNSResolver(new MaestroCNS(apiKey, network));

// Resolving domain
const addr = await resolver.resolveAddress('cns.ada');

// Resolving virtual sub-domain
const addr = await resolver.resolveAddress('mysubdomain.cns.ada');

// Resolving user records
const records = await resolver.resolveUserRecord('cns.ada');

Information CNS provided

  1. Domain Address

    • The current address owning the CNS token.
    • Example of a domain name: cns.ada
  2. Virtual Sub-domain Address

    • The pointer configured by CNS owner to other customized Cardano addresses.
    • Information represents by a key-value on chain through inline datum.
    • Example of a virtual sub-domain name: mysubdomain.cns.ada (key: mysubdomain, value: the Cardano address)
  3. Social Records

    • The social medias handle configured by the CNS owner.
    • Information represents by a key-value on chain through inline datum.
    • key: capitalized social media type (e.g. TELEGRAM, TWITTER, DISCORD etc)
    • value: the handle as configured.
  4. Customized Records

    • Any other key value information the user wishes to set.
    • Information represents by a key-value on chain through inline datum.

Resolving Methodology

| Item | Validation | Resolving Methods | SDK API | | -------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------- | | Domain Address | Expiry | 1. Get the current address the CNS residing on | resolveAddress | | All User Records | Expiry | 1. Get the inline datum of the user record | resolveUserRecord | | Virtual Sub-domain Address | Expiry & Enabled | 1. Get the inline datum of the user record 2. Resolve the one with correct virtual sub-domain key | resolveAddress & resolveVirtualSubdomains | | Social Records | Expiry | 1. Get the inline datum of the user record 2. Resolve the one with correct social key | resolveSocialRecord & resolveSocialRecords | | Customized Records | Expiry | 1. Get the inline datum of the user record 2. Resolve the one with correct key | resolveOtherRecord & resolveOtherRecords |

Validation Approach

  1. Expiry - Expiry Validation

    • Read the metadata attached with the CNS, and get the expiry field
    • Compare the current millisecond with expiry record
    • Valid if current millisecond < expiry
    • Example implementation
  2. Enabled - Virtual Sub-domain Enabled

Schemas

CNS Metadata

interface CNSMetadata {
    name: string;
    image: string;
    expiry: number; // Timestamp Millisecond
    origin: string;
    cnsType: string;
    mediaType: string;
    description: string;
    virtualSubdomainLimits: number;
    virtualSubdomainEnabled: 'Enabled' | 'Disabled';
}

User Record Inline Datum (JSON example)

import PlutusTx.AssocMap (Map(..))

data CNSUserRecordDatum = CNSUserRecordDatum
  (Map BuiltinByteString Address)           -- First map represents virtual sub-domain mapping
  (Map BuiltinByteString BuiltinByteString) -- Second map represents social profile mapping
  (Map BuiltinByteString BuiltinByteString) -- Third map represents custom records