resolution

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 19 Imported by: 2

README

Test Lint Go Report Card GoDoc Unstoppable Domains Documentation Get help on Discord

resolution-go

resolution-go is a library for interacting with blockchain domain names. It can be used to retrieve payment addresses, IPFS hashes for decentralized websites, DNS records and other records types

resolution-go is primarily built and maintained by Unstoppable Domains.

resolution-go decentralized domains across two zones:

  • Unstoppable Name Service (UNS)
    • .crypto
    • .wallet
    • .coin
    • .bitcoin
    • .x
    • .888
    • .nft
    • .dao
    • .blockchain
  • Zilliqa Name Service (ZNS)
    • .zil

Usage

package main

import (
  "fmt"
  "github.com/Zilliqa/gozilliqa-sdk/provider"
  "github.com/ethereum/go-ethereum/ethclient"
  "github.com/unstoppabledomains/resolution-go"
  "github.com/unstoppabledomains/resolution-go/namingservice"
)

func main() {
  // Resolve .crypto
  uns, _ := resolution.NewUnsBuilder().Build()
  ethAddress, _ := uns.Addr("brad.crypto", "ETH")
  fmt.Println("ETH address for brad.crypto is", ethAddress)

  // Resolve .zil
  zns, _ := resolution.NewZnsBuilder().Build()
  btcAddress, _ := zns.Addr("brad.zil", "BTC")
  fmt.Println("BTC address for brad.zil is", btcAddress)

  // Detect domain naming service
  namingServices := map[string]resolution.NamingService{namingservice.UNS: uns, namingservice.ZNS: zns}
  domainToDetect := "ryan.crypto"
  namingServiceName, _ := resolution.DetectNamingService(domainToDetect)
  if namingServices[namingServiceName] != nil {
    resolvedAddress, _ := namingServices[namingServiceName].Addr(domainToDetect, "ETH")
    fmt.Println("ETH address for", domainToDetect, "is", resolvedAddress)
  }

  // Set custom Ethereum endpoint for UNS service
  ethContractBackend, _ := ethclient.Dial("https://mainnet.infura.io/v3/c5da69dfac9c4d9d96dd232580d4124e")
  unsWithCustomBackend, _ := resolution.NewUnsBuilder().SetContractBackend(ethContractBackend).Build()
  allUnsRecords, _ := unsWithCustomBackend.AllRecords("beresnev.crypto")
  fmt.Println("Records for beresnev.crypto", allUnsRecords)

  // Set custom Zilliqa endpoint for ZNS service
  zilliqaProvider := provider.NewProvider("https://api.zilliqa.com")
  znsWithCustomProvider, _ := resolution.NewZnsBuilder().SetProvider(zilliqaProvider).Build()
  allZnsRecords, _ := znsWithCustomProvider.AllRecords("brad.zil")
  fmt.Println("Records for brad.zil", allZnsRecords)
}

Network support

Library supports Ethereum mainnet and Zilliqa mainnet only.

Contributions

Contributions to this library are more than welcome. The easiest way to contribute is through GitHub issues and pull requests.

Free advertising for integrated apps

Once your app has a working Unstoppable Domains integration, register it here. Registered apps appear on the Unstoppable Domains homepage and Applications page — putting your app in front of tens of thousands of potential customers per day.

Also, every week we select a newly-integrated app to feature in the Unstoppable Update newsletter. This newsletter is delivered to straight into the inbox of ~100,000 crypto fanatics — all of whom could be new customers to grow your business.

Get help

Join our discord community and ask questions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectNamingService

func DetectNamingService(domainName string) (string, error)

DetectNamingService helper to detect naming service type for provided domain. Returns ZNS or UNS for valid domain and error if domain is not valid or not supported by resolution-go library.

func ZnsNameHash

func ZnsNameHash(domainName string) (string, error)

ZnsNameHash Namehash for .zil domains

Types

type DomainNotConfiguredError

type DomainNotConfiguredError struct {
	DomainName string
}

DomainNotConfiguredError Error when domain does not have a resolver set

func (*DomainNotConfiguredError) Error

func (e *DomainNotConfiguredError) Error() string

type DomainNotRegisteredError

type DomainNotRegisteredError struct {
	DomainName string
	Namehash   string
}

DomainNotRegisteredError Error when domain is missing an owner

func (*DomainNotRegisteredError) Error

func (e *DomainNotRegisteredError) Error() string

type DomainNotSupportedError

type DomainNotSupportedError struct {
	DomainName string
}

DomainNotSupportedError Error when domain is not supported by the naming service

func (*DomainNotSupportedError) Error

func (e *DomainNotSupportedError) Error() string

type InvalidDomainNameReturnedError added in v1.1.2

type InvalidDomainNameReturnedError struct {
	Namehash   string
	DomainName string
}

InvalidDomainNameReturnedError Error when ERC721 metadata provides returns incorrect domain name

func (*InvalidDomainNameReturnedError) Error added in v1.1.2

type MetadataClient added in v1.1.2

type MetadataClient interface {
	Get(url string) (resp *http.Response, err error)
}

type MethodIsNotSupportedError added in v1.1.2

type MethodIsNotSupportedError struct {
	NamingServiceName string
}

MethodIsNotSupportedError Error when naming services does not support called method

func (*MethodIsNotSupportedError) Error added in v1.1.2

func (e *MethodIsNotSupportedError) Error() string

type NamingService

type NamingService interface {
	// Records Retrieve records of domain.
	// Keys must be provided in raw format according to specification.
	// Keys specification: https://docs.unstoppabledomains.com/domain-registry-essentials/records-reference.
	// Supported keys reference: https://github.com/unstoppabledomains/dot-crypto/blob/master/src/supported-keys/supported-keys.json.
	// It returns key-value map of specified keys set on provided domain. Map can contain empty strings if keys are not found.
	Records(domainName string, keys []string) (map[string]string, error)

	// Record Retrieve single record of domain.
	// Keys must be provided in raw format according to specification.
	// Keys specification: https://docs.unstoppabledomains.com/domain-registry-essentials/records-reference.
	// Supported keys reference: https://github.com/unstoppabledomains/dot-crypto/blob/master/src/supported-keys/supported-keys.json.
	// Returns result in string or empty string if no result found.
	Record(domainName string, key string) (string, error)

	// Addr Retrieve the value of domain's currency ticker.
	// Ticker must contain cryptocurrency like: BTC, ETH.
	// Returns result in string or empty string if no result found.
	Addr(domainName string, ticker string) (string, error)

	// AddrVersion Retrieve the version value of domain's currency ticker.
	// This method should be used to query multi-chain currency like USDT.
	// Returns result in string or empty string if no result found.
	AddrVersion(domainName string, ticker string, version string) (string, error)

	// Email Retrieve the email of domain.
	// Returns result in string or empty string if no result found.
	Email(domainName string) (string, error)

	// Resolver Retrieve the resolver address.
	// Returns result or DomainNotConfiguredError if resolver is not found.
	Resolver(domainName string) (string, error)

	// Owner Retrieve the owner address.
	// Returns result or DomainNotRegisteredError if owner is not found.
	Owner(domainName string) (string, error)

	// IpfsHash Retrieve hash of IPFS website attached to domain.
	IpfsHash(domainName string) (string, error)

	// HTTPUrl Retrieve the http redirect url of a domain.
	HTTPUrl(domainName string) (string, error)

	// AllRecords Retrieve all records of a domain.
	// Returns result in string or empty string record is not found.
	AllRecords(domainName string) (map[string]string, error)

	// DNS Retrieve the DNS records of a domain.
	// Returns a set of valid and filtered non-empty DNS records attached to domain.
	DNS(domainName string, types []dnsrecords.Type) ([]dnsrecords.Record, error)

	// IsSupportedDomain checks whether domain name is supported by the naming service.
	IsSupportedDomain(domainName string) (bool, error)

	// TokenURI returns ERC721 metadata token URI
	TokenURI(domainName string) (string, error)

	// TokenURIMetadata returns ERC721 metadata
	TokenURIMetadata(domainName string) (TokenMetadata, error)

	// Unhash returns a domain name from a hash using TokenMetadata.Name field and ensures it indeed matches the given hash.
	// domainHash should be in hex numeric string format, for example: "0x29bf1b111e709f0953848df35e419490fbad5d316690e4de61adc52695ddf9f3"
	// ERC721 Token ID could be passed to this method but should be converted to hex numeric string before usage.
	//
	// Examples of usage:
	//
	// domainName, err := NamingService.Unhash("0x29bf1b111e709f0953848df35e419490fbad5d316690e4de61adc52695ddf9f3")
	// domainName, err := NamingService.Unhash("0x691f36df38168d9297e784f45a87257a70c58c4040d469c6d0b91d253a837e32")
	//
	// Usage with ERC721 token id:
	//
	// var erc721TokenID big.Int
	// erc721TokenID.SetString("47548000072528700265403562077742902343248290986511625310517899838602191535666", 10)
	// domainHash := hex.EncodeToString(erc721TokenID.Bytes())
	// domainName, err := NamingService.Unhash(domainHash)
	//
	Unhash(domainHash string) (string, error)

	// Namehash returns a namehash of a domain following the EIP-137 standard
	Namehash(domainName string) (string, error)
}

NamingService Unstoppable supports multiple naming services (.zil and .crypto). Each naming service implements shared interface and returns similar record types.

type TokenMetadata added in v1.1.2

type TokenMetadata struct {
	Name            string                   `json:"name"`
	Description     string                   `json:"description"`
	Image           string                   `json:"image"`
	ExternalUrl     string                   `json:"external_url"`
	ExternalLink    string                   `json:"external_link"`
	ImageData       string                   `json:"image_data"`
	BackgroundColor string                   `json:"background_color"`
	AnimationUrl    string                   `json:"animation_url"`
	YoutubeUrl      string                   `json:"youtube_url"`
	Attributes      []TokenMetadataAttribute `json:"attributes"`
}

type TokenMetadataAttribute added in v1.1.2

type TokenMetadataAttribute struct {
	DisplayType string     `json:"display_type"`
	TraitType   string     `json:"trait_type"`
	Value       json.Token `json:"value"`
}

type Uns added in v1.1.2

type Uns struct {
	// contains filtered or unexported fields
}

Uns is a naming service handles Unstoppable domains resolution.

func (*Uns) Addr added in v1.1.2

func (c *Uns) Addr(domainName string, ticker string) (string, error)

func (*Uns) AddrVersion added in v1.1.2

func (c *Uns) AddrVersion(domainName string, ticker string, version string) (string, error)

func (*Uns) AllRecords added in v1.1.2

func (c *Uns) AllRecords(domainName string) (map[string]string, error)

func (*Uns) DNS added in v1.1.2

func (c *Uns) DNS(domainName string, types []dnsrecords.Type) ([]dnsrecords.Record, error)

func (*Uns) Data added in v1.1.2

func (c *Uns) Data(domainName string, keys []string) (*struct {
	Resolver common.Address
	Owner    common.Address
	Values   []string
}, error)

Data Get raw data attached to domain

func (*Uns) Email added in v1.1.2

func (c *Uns) Email(domainName string) (string, error)

func (*Uns) HTTPUrl added in v1.1.2

func (c *Uns) HTTPUrl(domainName string) (string, error)

func (*Uns) IpfsHash added in v1.1.2

func (c *Uns) IpfsHash(domainName string) (string, error)

func (*Uns) IsSupportedDomain added in v1.1.2

func (c *Uns) IsSupportedDomain(domainName string) (bool, error)

func (*Uns) Namehash added in v1.1.2

func (c *Uns) Namehash(domainName string) (string, error)

func (*Uns) Owner added in v1.1.2

func (c *Uns) Owner(domainName string) (string, error)

func (*Uns) Record added in v1.1.2

func (c *Uns) Record(domainName string, key string) (string, error)

func (*Uns) Records added in v1.1.2

func (c *Uns) Records(domainName string, keys []string) (map[string]string, error)

func (*Uns) Resolver added in v1.1.2

func (c *Uns) Resolver(domainName string) (string, error)

func (*Uns) TokenURI added in v1.1.2

func (c *Uns) TokenURI(domainName string) (string, error)

func (*Uns) TokenURIMetadata added in v1.1.2

func (c *Uns) TokenURIMetadata(domainName string) (TokenMetadata, error)

func (*Uns) Unhash added in v1.1.2

func (c *Uns) Unhash(domainHash string) (string, error)

type UnsBuilder added in v1.1.2

type UnsBuilder interface {
	// SetContractBackend set Ethereum backend for communication with UNS registry
	SetContractBackend(backend bind.ContractBackend) UnsBuilder

	// SetMetadataClient set http backend for communication with ERC721 metadata server
	SetMetadataClient(backend MetadataClient) UnsBuilder

	// SetEthereumNetwork set Ethereum network for communication with UNS registry
	SetEthereumNetwork(network string) UnsBuilder

	// Build Uns instance
	Build() (*Uns, error)
}

UnsBuilder is a builder to setup and build instance of Uns service.

func NewUnsBuilder added in v1.1.2

func NewUnsBuilder() UnsBuilder

NewUnsBuilder Creates builder to setup new instance of Uns service.

type Zns

type Zns struct {
	// contains filtered or unexported fields
}

Zns is a naming service handles .zil domains resolution.

func (*Zns) Addr

func (z *Zns) Addr(domainName string, ticker string) (string, error)

func (*Zns) AddrVersion

func (z *Zns) AddrVersion(domainName string, ticker string, version string) (string, error)

func (*Zns) AllRecords

func (z *Zns) AllRecords(domainName string) (map[string]string, error)

func (*Zns) DNS

func (z *Zns) DNS(domainName string, types []dnsrecords.Type) ([]dnsrecords.Record, error)

func (*Zns) Email

func (z *Zns) Email(domainName string) (string, error)

func (*Zns) HTTPUrl

func (z *Zns) HTTPUrl(domainName string) (string, error)

func (*Zns) IpfsHash

func (z *Zns) IpfsHash(domainName string) (string, error)

func (*Zns) IsSupportedDomain

func (z *Zns) IsSupportedDomain(domainName string) (bool, error)

func (*Zns) Namehash added in v1.1.2

func (z *Zns) Namehash(domainName string) (string, error)

func (*Zns) Owner

func (z *Zns) Owner(domainName string) (string, error)

func (*Zns) Record

func (z *Zns) Record(domainName string, key string) (string, error)

func (*Zns) Records

func (z *Zns) Records(domainName string, keys []string) (map[string]string, error)

func (*Zns) Resolver

func (z *Zns) Resolver(domainName string) (string, error)

func (*Zns) State

func (z *Zns) State(domainName string) (*ZnsDomainState, error)

State Get raw data attached to domain.

func (*Zns) TokenURI added in v1.1.2

func (z *Zns) TokenURI(_ string) (string, error)

func (*Zns) TokenURIMetadata added in v1.1.2

func (z *Zns) TokenURIMetadata(_ string) (TokenMetadata, error)

func (*Zns) Unhash added in v1.1.2

func (z *Zns) Unhash(_ string) (string, error)

type ZnsBuilder

type ZnsBuilder interface {
	// SetProvider set Zilliqa blockchain provider to communicate with ZNS registry
	SetProvider(provider ZnsProvider) ZnsBuilder
	// Build Zns instance
	Build() (*Zns, error)
}

ZnsBuilder is a builder to setup and build instance of Zns service.

func NewZnsBuilder

func NewZnsBuilder() ZnsBuilder

NewZnsBuilder Creates ZNS builder instance.

type ZnsDomainState

type ZnsDomainState struct {
	Resolver string
	Owner    string
	Records  map[string]string
}

ZnsDomainState State of ZNS domain

type ZnsProvider

type ZnsProvider interface {
	GetSmartContractSubState(contractAddress string, params ...interface{}) (string, error)
}

ZnsProvider ZnsProvider

Directories

Path Synopsis
cns
uns

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL