go_mhda

package module
v0.0.0-...-d6599b7 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 License: MIT Imports: 7 Imported by: 0

README

go-mhda

MultiChain Hierarchical Deterministic Address format (MHDA) with Uniform Resource Name (URN) format RFC 8141 compatibility.

This is address notation expands BIP32/44/84, and providing additional possibilities for configuring any blockchain address types.

URN:

urn:mhda:nt:{network_type}:ct:{coin_type}:ci:{chain_id}:dt:{derivation_type}:dp:{derivation_path}:aa:{algorithm}:af:{address_format}:ap:{address_prefix}:as:{address_suffix}
Parameter Name Type Description
urn URN Namespace constant string "mhda"
nt Network Type required string Network type, grouped by name: "evm", "tvm", "avm", "btc", "cosmos"
ct Coin Type required numeric Coin type, according slip44: Bitcoin/BTC=0, Litecoin/LTC=2, Ethereum/ETH=60, Tron/TRX=195, Polygon/MATIC=966
ci Chain Id required string Chain id: for numeric - "0x1", "0x10", for another - string "axelar"
dt Derivation Path Type optional string Derivation path type by name: "root", "bip32", "bip44", "bip49", "bip84", "cip11"
dp Derivation Path optional string | null Derivation path, according dt parameter: null, "m/0'/0/0", "m/44'/0'/0'/0/0", "m/49'/0'/0'/0/0", "m/84h/0h/0h/0/0"
aa Address Algorithm optional string | null Address hierarchical algorithm by name: "ed25519", "secp256k1"
af Address Format optional string | null Address format by name: "hex", "p2pkh", "p2s4", "bech32"
ap Address Prefix optional string | null Address prefix: "0x", "1|3|bc1"
as Address Suffix optional string | null Address suffix

Examples Ethereum

BIP-44
# Short format
# default filled: aa=secp256k1, af=hex, ap=0x
urn:mhda:nt:evm:ct:60:ci:0x1:dt:bip44:dp:m/44h/60h/0h/0/0

# Long format
urn:mhda:nt:evm:ct:60:ci:0x1:dt:bip44:dp:m/44h/60h/0h/0/0:aa:secp256k1:af:hex:ap:0x

Examples Bitcoin

BIP-44
# Legacy (P2PKH) // ap=1
urn:mhda:nt:btc:ct:0:ci:bitcoin:dt:bip44:dp:m/44h/0h/0h/0/0:aa:secp256k1:af:p2pkh:ap:1

# Nested SegWit (P2SH) // ap=3
urn:mhda:nt:btc:ct:0:ci:bitcoin:dt:bip44:dp:m/84h/0h/0h/0/0:aa:secp256k1:af:p2sh:ap:3

# Native SegWit (Bech32) // ap=bc1q
urn:mhda:nt:btc:ct:0:ci:bitcoin:dt:bip44:dp:m/84h/0h/0h/0/0:aa:secp256k1:af:p2pkh:ap:bc1q

# Taproot (P2TR)  // ap=bc1p
urn:mhda:nt:btc:ct:0:ci:bitcoin:dt:bip84:dp:m/86h/0h/0h/0/0:aa:secp256k1:af:p2pkh:ap:bc1p

Examples Avalanche

BIP-44
# C-Chain
urn:mhda:nt:evm:ct:60:ci:0xa86a:dt:bip44:dp:m/44h/60h/0h/0/0

# X-Chain   https://subnets.avax.network/x-chain
# default filled: aa=secp256k1, af=hex, ap=X-avax
urn:mhda:nt:avm:ct:9000:ci:0x1:dt:bip44:dp:m/44h/9000h/0h/0/0
# Long
urn:mhda:nt:avm:ct:9000:ci:0x1:dt:bip44:dp:m/44h/9000h/0h/0/0:aa:secp256k1:af:hex:ap:X-avax

Root key (no derivation path)
# Short format
# default filled: dp=null, aa=secp256k1, af=hex, ap=0x
urn:mhda:nt:evm:ct:60:ci:0x1

# Long format
urn:mhda:nt:evm:ct:60:ci:0x1:aa:secp256k1:af:hex:ap:0x

Documentation

Index

Constants

View Source
const (
	Secp256k1  = Algorithm(`secp256k1`)
	Ed25519    = Algorithm(`ed25519`)
	Sr25519    = Algorithm(`sr25519`)   // Polkadot https://wiki.polkadot.network/docs/learn-account-advanced
	Secp256r1  = Algorithm(`secp256r1`) // SUI https://docs.sui.io/learn/cryptography/sui-wallet-specs
	Secp384r1  = Algorithm(`secp384r1`)
	Secp521r1  = Algorithm(`secp521r1`)
	Prime256v1 = Algorithm(`prime256v1`) // OpenSSL

	HEX    = Format(`hex`)
	P2PKH  = Format(`p2pkh`)
	P2S4   = Format(`p2s4`)
	P2WPKH = Format(`p2wpkh`)
	Bech32 = Format(`bech32`)
	Base58 = Format(`base58`)

	SS58 = Format(`ss58`)
)
View Source
const (
	// btc
	BTC  = CoinType(0)
	LTC  = CoinType(2)
	DOGE = CoinType(3)

	// evm
	ETH   = CoinType(60)
	BNB   = CoinType(714) // old stype
	BSC   = CoinType(9006)
	MATIC = CoinType(966)
	GLMR  = CoinType(1284)

	DASH = CoinType(5)

	XMR  = CoinType(128)
	ZEC  = CoinType(133)
	ATOM = CoinType(168)
	TRX  = CoinType(195)
	SOL  = CoinType(501)

	//https://support.avax.network/en/articles/7004986-what-derivation-paths-does-avalanche-use
	AVAX = CoinType(9000)
)
View Source
const (
	ROOT  = DerivationType(`root`)
	BIP32 = DerivationType(`bip32`)
	BIP44 = DerivationType(`bip44`)
	BIP84 = DerivationType(`bip84`)
	CIP11 = DerivationType(`cip11`)
	ZIP32 = DerivationType(`zip32`)

	ChargeExternal = ChargeType(0)
	ChargeInternal = ChargeType(1)
)
View Source
const (
	Bitcoin     = NetworkType(`btc`)
	EthereumVM  = NetworkType(`evm`)
	AvalancheVM = NetworkType(`avm`)
	TronVM      = NetworkType(`tvm`)
	Cosmos      = NetworkType(`cosmos`)
	Solana      = NetworkType(`sol`)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountIndex

type AccountIndex uint32

type Address

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

func NewAddress

func NewAddress(chain *Chain, path *DerivationPath, params ...string) *Address

NewAddress add optional params: aa, af, ap, as

func (*Address) Algorithm

func (a *Address) Algorithm() Algorithm

func (*Address) Chain

func (a *Address) Chain() *Chain

func (*Address) DerivationPath

func (a *Address) DerivationPath() *DerivationPath

func (*Address) Format

func (a *Address) Format() Format

func (*Address) Hash

func (a *Address) Hash() string

func (*Address) NSS

func (a *Address) NSS() string

func (*Address) NSSHash

func (a *Address) NSSHash() string

func (*Address) SetAddressAlgorithm

func (a *Address) SetAddressAlgorithm(aa string) error

func (*Address) SetAddressFormat

func (a *Address) SetAddressFormat(af string) error

func (*Address) SetAddressPrefix

func (a *Address) SetAddressPrefix(ap string) error

func (*Address) SetAddressSuffix

func (a *Address) SetAddressSuffix(as string) error

func (*Address) SetCoinType

func (a *Address) SetCoinType(ct string) error

func (*Address) SetDerivationPath

func (a *Address) SetDerivationPath(dp string) error

func (*Address) SetDerivationType

func (a *Address) SetDerivationType(dt string) error

func (*Address) String

func (a *Address) String() string

type AddressIndex

type AddressIndex struct {
	Index      uint32
	IsHardened bool
}

type Algorithm

type Algorithm string

type Chain

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

func ChainFromKey

func ChainFromKey(chainKey ChainKey) (*Chain, error)

func ChainFromNSS

func ChainFromNSS(src string) (*Chain, error)

func NewChain

func NewChain(networkType NetworkType, coinType CoinType, chainId ChainId) *Chain

func (*Chain) ChainId

func (c *Chain) ChainId() ChainId

func (*Chain) CoinType

func (c *Chain) CoinType() CoinType

func (*Chain) Key

func (c *Chain) Key() ChainKey

func (*Chain) NetworkType

func (c *Chain) NetworkType() NetworkType

func (*Chain) SetChainId

func (c *Chain) SetChainId(chainId ChainId)

func (*Chain) SetCoinType

func (c *Chain) SetCoinType(coinType CoinType)

func (*Chain) SetNetworkType

func (c *Chain) SetNetworkType(networkType NetworkType)

func (*Chain) String

func (c *Chain) String() string

type ChainId

type ChainId string

type ChainKey

type ChainKey string

ChainKey - string identifier for declaration any chain or subchain

type ChargeType

type ChargeType uint8

type CoinType

type CoinType uint

type DerivationPath

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

func NewDerivationPath

func NewDerivationPath(derivationType DerivationType, coin CoinType, account AccountIndex, charge ChargeType, index AddressIndex) *DerivationPath

func ParseDerivationPath

func ParseDerivationPath(dt DerivationType, path string) (*DerivationPath, error)

func (*DerivationPath) Account

func (dp *DerivationPath) Account() AccountIndex

func (*DerivationPath) AddressIndex

func (dp *DerivationPath) AddressIndex() AddressIndex

func (*DerivationPath) Charge

func (dp *DerivationPath) Charge() ChargeType

func (*DerivationPath) Coin

func (dp *DerivationPath) Coin() CoinType

func (*DerivationPath) DerivationType

func (dp *DerivationPath) DerivationType() DerivationType

func (*DerivationPath) IsHardenedAddress

func (dp *DerivationPath) IsHardenedAddress() bool

func (*DerivationPath) ParsePath

func (dp *DerivationPath) ParsePath(path string) error

func (*DerivationPath) String

func (dp *DerivationPath) String() string

type DerivationType

type DerivationType string

type Format

type Format string

type MHDA

type MHDA interface {
	Chain() *Chain
	// DerivationType() DerivationType
	DerivationPath() *DerivationPath
	Algorithm() Algorithm
	Format() Format
	NSS() string
	String() string
	Hash() string
	NSSHash() string
}

func ParseNSS

func ParseNSS(src string) (MHDA, error)

func ParseURN

func ParseURN(src string) (MHDA, error)

func ParseURNRx

func ParseURNRx(src string) (MHDA, error)

type NetworkType

type NetworkType string

func NetworkTypeFromString

func NetworkTypeFromString(src string) (NetworkType, error)

func (NetworkType) IsValid

func (nt NetworkType) IsValid() bool

func (NetworkType) String

func (nt NetworkType) String() string

Jump to

Keyboard shortcuts

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