hashkeydid_go

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: MIT Imports: 16 Imported by: 0

README

HashKey DID Go SDK

Tag License Go Report Card

Go module to work with HashKey DID Protocol.

Installation

go get github.com/hashkeydid/hashkeydid-go

Usage

hashkeydid-go provides simple access to the HashKey DID Contracts.

Core

hashkeydid-go.Core is the core struct of this project to use this SDK function.

core, err := hashkeydid.NewDIDCore(
	hashkeydid.DefaultPlatONUrl, 
	hashkeydid.DefaultDIDContractAddr, 
	hashkeydid.DefaultDIDResolverContractAddr,
)
Opts

To query the historical info of DID, SDK provides an option arg called opts. User can query the status with a custom block height.

// query the status on Block 40069811
opts := &bind.CallOpts{BlockNumber: new(big.Int).SetUint64(40069811)}
Sample1-GetName
// after user set reverse
name, err := core.GetDIDNameByAddr(opts, address)
// force
name, err := core.GetDIDNameByAddrForce(opts, address)
Sample2-GetAvatar

In HashKey DID, avatarUrl supports many forms (Detail).

chainList is a map which includes information of chains. SDK provides a default chainList for user to query on-chain status. User can provide a list with custom chainIds and RPCUrls.

chainList in args can be nil.

// query by DID name
avatar, err := core.GetAvatarByDIDName(opts, name, chainList)

// query by tokenId
avatar, err := core.GetAvatarByTokenId(opts, tokenId, nil)

Documentation

Index

Constants

View Source
const DefaultDIDContractAddr = "0x7fDd3f96cBDE51737A9E24b461E7E92A057C3BBf"
View Source
const DefaultDIDResolverContractAddr = "0x606729294604A1c71f4BFc001894E4f8095Ec2eF"
View Source
const DefaultPlatONUrl = "https://openapi2.platon.network/rpc"

Variables

View Source
var (
	ErrAddrNotClaimed    = fmt.Errorf("this address has not claimed a did")
	ErrAddrNotSetReverse = fmt.Errorf("this address has not set reverse record")
	ErrDidNotClaimed     = fmt.Errorf("this did name has not been claimed")
	ErrTokenIdNotMinted  = fmt.Errorf("this tokenId has not been minted")
	ErrAvatarNotSet      = fmt.Errorf("the avatar text has not been set on this did")
	ErrInvalidAvatarText = fmt.Errorf("the avatar text is invalid")
	ErrInvalidTokenURI   = fmt.Errorf("the tokenURI of avatar is invalid")
	ErrInvalidTokenId    = fmt.Errorf("the token id is invalid")
	ErrTimeExpired       = fmt.Errorf("the time has expired")
	ErrInvalidEvidence   = fmt.Errorf("the evidence is invalid")
)
View Source
var (
	Big0 = new(big.Int).SetUint64(0)
)
View Source
var ChainList = map[string]*ChainInfo{
	"1":      {"Ethereum", "https://eth-mainnet.nodereal.io/v1/1659dfb40aa24bbb8153a677b98064d7"},
	"137":    {"Polygon", "https://matic-mainnet-archive-rpc.bwarelabs.com"},
	"8217":   {"Klaytn", "https://klaytn01.fandom.finance"},
	"210425": {"PlatON", "https://openapi2.platon.network/rpc"},
}

ChainList is a map contains the infos of chain by the index of chainId

Functions

func GetMetadataDescription

func GetMetadataDescription(tokenId string) (string, error)

GetMetadataDescription returns the description in metadata by tokenId

func GetMetadataImage

func GetMetadataImage(tokenId string) (string, error)

GetMetadataImage returns the image url in metadata by tokenId

func GetMetadataName

func GetMetadataName(tokenId string) (string, error)

GetMetadataName returns the name in metadata by tokenId

Types

type ChainInfo

type ChainInfo struct {
	ChainName string
	RPCUrl    string
}

type Core

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

Core is structure for basic interaction with contracts

func NewDIDCore

func NewDIDCore(rpcUrl string, didAddr string, resolverAddr string) (*Core, error)

NewDIDCore Creates a did-go core with give addresses

func (*Core) AddKYC added in v0.0.3

func (c *Core) AddKYC(opts *bind.TransactOpts, tokenId uint64, KYCProvider common.Address, KYCId uint64, status bool, updateTime uint64, expireTime uint64, evidence []byte) (*types.Transaction, error)

AddKYC add KYC information for specific token id

func (*Core) GetAvatarByDIDName

func (c *Core) GetAvatarByDIDName(opts *bind.CallOpts, didName string, chainList map[string]*ChainInfo) (string, error)

GetAvatarByDIDName returns the image url in resolver text queried by did name

func (*Core) GetAvatarByTokenId

func (c *Core) GetAvatarByTokenId(opts *bind.CallOpts, tokenId uint64, chainList map[string]*ChainInfo) (string, error)

GetAvatarByTokenId returns the image url in resolver text queried by tokenId

func (*Core) GetDIDNameByAddr

func (c *Core) GetDIDNameByAddr(opts *bind.CallOpts, address common.Address) (string, error)

GetDIDNameByAddr returns the did name by address when user set reverse

func (*Core) GetDIDNameByAddrForce

func (c *Core) GetDIDNameByAddrForce(opts *bind.CallOpts, address common.Address) (string, error)

GetDIDNameByAddrForce returns the did name by address

func (*Core) GetKYCInfo added in v0.0.3

func (c *Core) GetKYCInfo(opts *bind.CallOpts, tokenId uint64, KYCProvider common.Address, KYCId uint64) (*KYCInfo, error)

GetKYCInfo returns the KYC information for specific token id from DID

func (*Core) GetMetadataAvatarByDIDName

func (c *Core) GetMetadataAvatarByDIDName(opts *bind.CallOpts, didName string) (string, error)

GetMetadataAvatarByDIDName returns the image url in metadata queried by did name

func (*Core) GetMetadataAvatarByTokenId

func (c *Core) GetMetadataAvatarByTokenId(opts *bind.CallOpts, tokenId uint64) (string, error)

GetMetadataAvatarByTokenId returns the image url in metadata queried by tokenId

func (*Core) IssueDG added in v0.0.3

func (c *Core) IssueDG(opts *bind.TransactOpts, name string, symbol string, baseUri string, evidence []byte, transferable bool) (*types.Transaction, error)

IssueDG issue a new DeedGrain token

func (*Core) IssueNFT added in v0.0.3

func (c *Core) IssueNFT(opts *bind.TransactOpts, name string, symbol string, baseUri string, evidence []byte, supply uint64) (*types.Transaction, error)

IssueNFT issue a new DeedGrain NFT

func (*Core) SetNFTSupply added in v0.0.3

func (c *Core) SetNFTSupply(opts *bind.TransactOpts, NFTAddr common.Address, supply uint64) (*types.Transaction, error)

SetNFTSupply set NFT supply

func (*Core) SetReverse

func (c *Core) SetReverse(status bool) error

SetReverse sets the reverse status for address

func (*Core) SetTokenSupply added in v0.0.3

func (c *Core) SetTokenSupply(opts *bind.TransactOpts, DGAddr common.Address, tokenId *big.Int, supply uint64) (*types.Transaction, error)

SetTokenSupply set every kind of token's supply

type KYCInfo added in v0.0.3

type KYCInfo struct {
	Status     bool
	UpdateTime *big.Int
	ExpireTime *big.Int
}

type Metadata

type Metadata struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Image       string `json:"image"`
}

func GetMetadata

func GetMetadata(tokenId string) (*Metadata, error)

GetMetadata returns the Metadata by tokenId

Directories

Path Synopsis
contracts
did

Jump to

Keyboard shortcuts

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