docs
  • Introduction
  • Getting started
    • Meet the network using CLI
    • Your first transaction
    • Run smart contract
    • Run your own node
    • Ledger Support
  • Architecture
    • Dnode
    • Dncli
    • XFI & Other coins
    • Fees & Gas
    • Addresses
  • Staking
    • Delegate sXFI & LPT
    • Become a validator
    • Rewards & Inflation
    • Slashing
    • More
  • Move VM
    • Modules
    • Scripts
    • Script Arguments
    • Standard Library
    • Events
    • Resources
    • Move Book
    • More
  • Oracles
    • Query Price
  • PegZone
    • Deposit
    • Usage
    • Withdraw
  • Useful Resources
    • Dfinance Website
    • Wallet
    • Move Book
    • Block Explorer
    • Swagger UI
    • Community
    • VSCode Move IDE
Powered by GitBook
On this page

Was this helpful?

  1. Architecture

Addresses

PreviousFees & GasNextStaking

Last updated 4 years ago

Was this helpful?

Dfinance protocol uses address format. Bech32 encoding provides robust integrity checks on data and the human readable part (HRP) provides contextual hints that can assist UI developers with providing informative error messages.

  • Human readable part is called a prefix and in the case of dfinance it's wallet.

  • Default HDPath for dfinance addresses is 44'/118'/0'/0/0.

wallet173pur9yxzauc7pccwwpk7whnf30czvf53wkcyn # Example of dfinance address, contains prefix 'wallet', then '1' and address bytes.

Use algorithm to generate public and private keys, then use Bech32 to create addresses.

Mnemonic based keys supported by and implementations.

Example in Golang:

package main

import (
    "encoding/hex"
    "fmt"

    "github.com/cosmos/cosmos-sdk/crypto/keys/hd"
    sdk "github.com/cosmos/cosmos-sdk/types"
    "github.com/cosmos/go-bip39"
    "github.com/tendermint/tendermint/crypto/secp256k1"
)

func main() {
    // Configure Cosmos SDK.
    prefix := "wallet"
    config := sdk.GetConfig()
    config.SetBech32PrefixForAccount(prefix, prefix + sdk.PrefixPublic)
    config.Seal()

    // Generate new address from new private key.
    privKey := secp256k1.GenPrivKey()
    pubKey  := privKey.PubKey()
    addr    := sdk.AccAddress(pubKey.Address())

    fmt.Printf("Private key: %s\nPublic key: %s\nAddress: %s\n", hex.EncodeToString(privKey[:]), hex.EncodeToString(pubKey.Bytes()), addr)

    // Generate address from new mnemonic.
    entropy, err := bip39.NewEntropy(256)
    if err != nil {
        panic(err)
    }

    passphrase := "12345678" // Replace with your passphrase.
    hdPath := "44'/118'/0'/0/0"
    mnemonic, err := bip39.NewMnemonic(entropy)
    if err != nil {
        panic(err)
    }

    fmt.Printf("\nNew generated mnemonic is: %s\n", mnemonic)

    seed, err := bip39.NewSeedWithErrorChecking(mnemonic, passphrase)
    if err != nil {
        panic(err)
    }

    masterPrivKey, ch := hd.ComputeMastersFromSeed(seed)

    // If hdPath is empty, just use masterPrivKey[:], don't need to derive.
    derivedPrivKey, err := hd.DerivePrivateKeyForPath(masterPrivKey, ch, hdPath)
    if err != nil {
        panic(err)
    }

    derivedPubKey := secp256k1.PrivKeySecp256k1(derivedPrivKey).PubKey()
    derivedAddr   := sdk.AccAddress(derivedPubKey.Address())

    fmt.Printf("Private key: %s\nPublic key: %s\nAddress: %s\n", hex.EncodeToString(derivedPrivKey[:]), hex.EncodeToString(derivedPubKey.Bytes()), derivedAddr)
}
Bech32
secp256k1
bip39
bip32