bitgo

package module
v0.0.0-...-1904a9a Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

BitGo Golang SDK V2

The BitGo Platform and SDK makes it easy to build multi-signature Bitcoin applications today.

Build Status

Installing

Use go get to install the latest version of the library. This command will install the BitGo Golang SDK executable along with the library and its dependencies:

go get -u github.com/jazzserve/bitgo

Next, include library in your application:

import "github.com/jazzserve/bitgo"

Documentation

View API Documentation.

Example Usage

List Wallets

b, err := bitgo.New("test", time.Minute)
if err != nil {
	log.Fatal(err.Error())
}

list, err := b.Token("{Access token}").Coin("tbtc").Debug(true).ListWallets(bitgo.ListParams{
	AllTokens: true,
})
if err != nil {
	log.Fatalf("%#v\n", err.(bitgo.Error))
}

for _, w := range list.Wallets {
	log.Println(w.ID, w.Label)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	ID           string `json:"id"`
	Address      string `json:"address"`
	Chain        int    `json:"chain"`
	Index        int    `json:"index"`
	Coin         string `json:"coin"`
	Wallet       string `json:"wallet"`
	CoinSpecific struct {
		RedeemScript string `json:"redeemScript"`
	} `json:"coinSpecific"`
	Label   string `json:"label"`
	Balance struct {
		Updated       time.Time `json:"updated"`
		NumTx         int       `json:"numTx"`
		NumUnspents   int       `json:"numUnspents"`
		TotalReceived int       `json:"totalReceived"`
		TotalSent     int       `json:"totalSent"`
	} `json:"balance"`
}

type AddressParams

type AddressParams struct {
	Chain            int                  `json:"chain,omitempty"`
	Label            string               `json:"label,omitempty"`
	ForwarderVersion ForwarderVersionType `json:"forwarderVersion,omitempty"`
}

type BitGo

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

func New

func New(url string, timeout time.Duration) (b *BitGo, err error)

func (*BitGo) BuildTransaction

func (b *BitGo) BuildTransaction(walletId string, params BuildTransactionParams) (transaction Transaction, err error)

func (*BitGo) Coin

func (b *BitGo) Coin(coin string) *BitGo

func (*BitGo) CreateWalletAddress

func (b *BitGo) CreateWalletAddress(walletId string, params *AddressParams) (address Address, err error)

func (*BitGo) CurrentUserProfile

func (b *BitGo) CurrentUserProfile() (userProfile UserProfile, err error)

func (*BitGo) Debug

func (b *BitGo) Debug(debug bool) *BitGo

func (*BitGo) EstimateTransactionFees

func (b *BitGo) EstimateTransactionFees(numBlocks int) (transactionFees TransactionFees, err error)

func (*BitGo) GenerateWallet

func (b *BitGo) GenerateWallet(params GenerateWalletParams) (wallet GeneratedWallet, err error)

func (*BitGo) GetTotalBalances

func (b *BitGo) GetTotalBalances() (total TotalBalances, err error)

func (*BitGo) GetWallet

func (b *BitGo) GetWallet(walletId string, params GetWalletParams) (wallet Wallet, err error)

func (*BitGo) GetWalletAddress

func (b *BitGo) GetWalletAddress(walletId string, addressOrId string) (address Address, err error)

func (*BitGo) GetWalletByAddress

func (b *BitGo) GetWalletByAddress(address string) (wallet Wallet, err error)

func (*BitGo) GetWalletTransfer

func (b *BitGo) GetWalletTransfer(walletId string, transferId string) (transfer Transfer, err error)

func (*BitGo) GetWalletTransferBySequenceID

func (b *BitGo) GetWalletTransferBySequenceID(walletId string, sequenceId string) (transfer Transfer, err error)

func (*BitGo) ListWalletTransfers

func (b *BitGo) ListWalletTransfers(walletId string, params ListParams) (list TransferList, err error)

func (*BitGo) ListWalletWebhooks

func (b *BitGo) ListWalletWebhooks(walletId string, params GetWalletParams) (webhooks Webhooks, err error)

func (*BitGo) ListWallets

func (b *BitGo) ListWallets(params ListParams) (list ListWallets, err error)

func (*BitGo) Lock

func (b *BitGo) Lock() (err error)

func (*BitGo) Login

func (b *BitGo) Login(params LoginParams) (token Token, err error)

func (*BitGo) Logout

func (b *BitGo) Logout() (err error)

func (*BitGo) SendTransaction

func (b *BitGo) SendTransaction(walletId string, params SendParams) (transactionDescription TransactionDescription, err error)

func (*BitGo) SendTransactionToMany

func (b *BitGo) SendTransactionToMany(walletId string, params SendToManyParams) (transactionDescription TransactionDescription, err error)

func (*BitGo) SessionInformation

func (b *BitGo) SessionInformation() (session Session, err error)

func (*BitGo) SignTransaction

func (b *BitGo) SignTransaction(walletId string, params SignTransactionParams) (signedTransaction SignedTransaction, err error)

func (*BitGo) Token

func (b *BitGo) Token(token string) *BitGo

func (*BitGo) Unlock

func (b *BitGo) Unlock(params UnlockParams) (err error)

func (*BitGo) UpdateWallet

func (b *BitGo) UpdateWallet(walletId string, params UpdateWalletParams) (wallet Wallet, err error)

func (*BitGo) UpdateWalletAddress

func (b *BitGo) UpdateWalletAddress(walletId string, addressOrId string, params UpdateWalletAddressParams) (address Address, err error)

type BuildTransactionParams

type BuildTransactionParams struct {
	Recipients []Recipient `json:"recipients"`
}

type Error

type Error struct {
	Message   string `json:"error"`
	RequestId string `json:"requestId"`
	Name      string `json:"name"`
}

func (Error) Error

func (e Error) Error() string

type ForwarderVersionType

type ForwarderVersionType int

Create Wallet Address

const (
	FORWARDER_VERSION_0 ForwarderVersionType = 0
	FORWARDER_VERSION_1                      = 1
)

type GenerateWalletParams

type GenerateWalletParams struct {
	Label                           string `json:"label" valid:"required"`
	Passphrase                      string `json:"passphrase" valid:"required"`
	UserKey                         string `json:"userKey,omitempty"`
	BackupXpub                      string `json:"backupXpub,omitempty"`
	BackupXpubProvider              string `json:"backupXpubProvider,omitempty"`
	Enterprise                      string `json:"enterprise,omitempty"`
	DisableTransactionNotifications bool   `json:"disableTransactionNotifications,omitempty"`
	GasPrice                        int    `json:"gasPrice,omitempty"`
	PasscodeEncryptionCode          string `json:"passcodeEncryptionCode,omitempty"`
}

type GeneratedWallet

type GeneratedWallet struct {
	Wallet struct {
		Wallet struct {
			ID    string `json:"id"`
			Users []struct {
				User        string   `json:"user"`
				Permissions []string `json:"permissions"`
			} `json:"users"`
			Coin                            string   `json:"coin"`
			Label                           string   `json:"label"`
			M                               int      `json:"m"`
			N                               int      `json:"n"`
			Keys                            []string `json:"keys"`
			Tags                            []string `json:"tags"`
			DisableTransactionNotifications bool     `json:"disableTransactionNotifications"`
			Freeze                          struct {
			} `json:"freeze"`
			Deleted           bool `json:"deleted"`
			ApprovalsRequired int  `json:"approvalsRequired"`
			IsCold            bool `json:"isCold"`
			CoinSpecific      struct {
			} `json:"coinSpecific"`
			Balance                int    `json:"balance"`
			ConfirmedBalance       int    `json:"confirmedBalance"`
			SpendableBalance       int    `json:"spendableBalance"`
			BalanceString          string `json:"balanceString"`
			ConfirmedBalanceString string `json:"confirmedBalanceString"`
			SpendableBalanceString string `json:"spendableBalanceString"`
			ReceiveAddress         struct {
				Address      string `json:"address"`
				Chain        int    `json:"chain"`
				Index        int    `json:"index"`
				Coin         string `json:"coin"`
				Wallet       string `json:"wallet"`
				CoinSpecific struct {
					RedeemScript string `json:"redeemScript"`
				} `json:"coinSpecific"`
			} `json:"receiveAddress"`
			PendingApprovals []interface{} `json:"pendingApprovals"`
		} `json:"_wallet"`
	} `json:"wallet"`
}

type GetWalletParams

type GetWalletParams struct {
	AllTokens bool `url:"allTokens,omitempty"`
}

type Keychain

type Keychain struct {
	EncryptedPrv string `json:"encryptedPrv"`
}

type ListParams

type ListParams struct {
	Limit     int    `url:"limit,omitempty"`
	PrevId    string `url:"prevId,omitempty"`
	AllTokens bool   `url:"allTokens,omitempty"`
}

type ListWallets

type ListWallets struct {
	NextBatchPrevId string `json:"nextBatchPrevId"`
	Wallets         []struct {
		ID    string `json:"id"`
		Users []struct {
			User        string   `json:"user"`
			Permissions []string `json:"permissions"`
		} `json:"users"`
		Coin                            string   `json:"coin"`
		Label                           string   `json:"label"`
		M                               int      `json:"m"`
		N                               int      `json:"n"`
		Keys                            []string `json:"keys"`
		Tags                            []string `json:"tags"`
		DisableTransactionNotifications bool     `json:"disableTransactionNotifications"`
		Freeze                          struct {
		} `json:"freeze"`
		Deleted           bool `json:"deleted"`
		ApprovalsRequired int  `json:"approvalsRequired"`
		CoinSpecific      struct {
		} `json:"coinSpecific"`
	} `json:"wallets"`
}

type ListWebhooks

type ListWebhooks struct {
	Webhooks Webhooks `json:"webhooks"`
}

type LoginParams

type LoginParams struct {
	Email      string `json:"email" valid:"required"`
	Password   string `json:"password" valid:"required"`
	Otp        string `json:"otp" valid:"required"`
	Extensible bool   `json:"extensible,omitempty"`
}

type Recipient

type Recipient struct {
	Address  string `json:"address" valid:"required"`
	Amount   int    `json:"amount" valid:"required"`
	GasPrice int    `json:"gasPrice,omitempty"`
}

type SendParams

type SendParams struct {
	Address string `json:"address" valid:"required"`
	Amount  string `json:"amount" valid:"required"`

	WalletPassphrase string `json:"walletPassphrase" valid:"required"`
	Prv              string `json:"prv,omitempty"`
	NumBlocks        int    `json:"numBlocks,omitempty"`
	FeeRate          int    `json:"feeRate,omitempty"`
	Comment          string `json:"comment,omitempty"`
	//	Unspents                    array  `json:"unspents,omitempty"`
	MinConfirms                 int    `json:"minConfirms,omitempty"`
	EnforceMinConfirmsForChange bool   `json:"enforceMinConfirmsForChange,omitempty"`
	TargetWalletUnspents        int    `json:"targetWalletUnspents,omitempty"`
	NoSplitChange               bool   `json:"noSplitChange,omitempty"`
	MinValue                    int    `json:"minValue,omitempty"`
	MaxValue                    int    `json:"maxValue,omitempty"`
	GasPrice                    int    `json:"gasPrice,omitempty"`
	GasLimit                    int    `json:"gasLimit,omitempty"`
	SequenceId                  string `json:"sequenceId,omitempty"`
	Segwit                      bool   `json:"segwit,omitempty"`
	LastLedgerSequence          int    `json:"lastLedgerSequence,omitempty"`
	LedgerSequenceDelta         string `json:"ledgerSequenceDelta,omitempty"`
}

type SendToManyParams

type SendToManyParams struct {
	Recipients []Recipient `json:"recipients" valid:"required"`

	WalletPassphrase string `json:"walletPassphrase" valid:"required"`
	Prv              string `json:"prv,omitempty"`
	NumBlocks        int    `json:"numBlocks,omitempty"`
	FeeRate          int    `json:"feeRate,omitempty"`
	Comment          string `json:"comment,omitempty"`
	//	Unspents                    array  `json:"unspents,omitempty"`
	MinConfirms                 int    `json:"minConfirms,omitempty"`
	EnforceMinConfirmsForChange bool   `json:"enforceMinConfirmsForChange,omitempty"`
	TargetWalletUnspents        int    `json:"targetWalletUnspents,omitempty"`
	NoSplitChange               bool   `json:"noSplitChange,omitempty"`
	MinValue                    int    `json:"minValue,omitempty"`
	MaxValue                    int    `json:"maxValue,omitempty"`
	GasPrice                    int    `json:"gasPrice,omitempty"`
	GasLimit                    int    `json:"gasLimit,omitempty"`
	SequenceId                  string `json:"sequenceId,omitempty"`
	Segwit                      bool   `json:"segwit,omitempty"`
	LastLedgerSequence          int    `json:"lastLedgerSequence,omitempty"`
	LedgerSequenceDelta         string `json:"ledgerSequenceDelta,omitempty"`
}

type Session

type Session struct {
	Client  string    `json:"client"`
	User    string    `json:"user"`
	Scope   []string  `json:"scope"`
	Expires time.Time `json:"expires"`
	Origin  string    `json:"origin"`
	Unlock  struct {
		Time    time.Time `json:"time"`
		Expires time.Time `json:"expires"`
		TxCount int       `json:"txCount"`
		TxValue int       `json:"txValue"`
	} `json:"unlock"`
}

type SignTransactionParams

type SignTransactionParams struct {
	TxPrebuild       Transaction `json:"txPrebuild"`
	Keychain         Keychain    `json:"keychain"`
	WalletPassphrase string      `json:"walletPassphrase"`
}

type SignedTransaction

type SignedTransaction struct {
	TxHex string `json:"txHex"`
}

type Token

type Token struct {
	TokenType string   `json:"token_type"`
	ExpiresIn int      `json:"expires_in"`
	ExpiresAt int      `json:"expires_at"`
	Scope     []string `json:"scope"`
	User      struct {
		ID       string `json:"id"`
		Username string `json:"username"`
		Name     struct {
			Full  string `json:"full"`
			First string `json:"first"`
			Last  string `json:"last"`
		} `json:"name"`
		Email struct {
			Email    string `json:"email"`
			Verified bool   `json:"verified"`
		} `json:"email"`
		Phone struct {
			Phone    string `json:"phone"`
			Verified bool   `json:"verified"`
		} `json:"phone"`
		Identity struct {
			Civic struct {
				State string `json:"state"`
			} `json:"civic"`
			Verified bool `json:"verified"`
		} `json:"identity"`
		OtpDevices []struct {
			ID       string `json:"id"`
			Type     string `json:"type"`
			Label    string `json:"label"`
			Verified bool   `json:"verified"`
		} `json:"otpDevices"`
		RateLimits struct {
		} `json:"rateLimits"`
		DisableReset2FA bool `json:"disableReset2FA"`
		Currency        struct {
			Currency    string `json:"currency"`
			BitcoinUnit string `json:"bitcoinUnit"`
		} `json:"currency"`
		Timezone     string `json:"timezone"`
		IsActive     bool   `json:"isActive"`
		EcdhKeychain string `json:"ecdhKeychain"`
		Referrer     struct {
		} `json:"referrer"`
		Apps struct {
			Coinbase struct {
			} `json:"coinbase"`
		} `json:"apps"`
		ForceResetPassword bool          `json:"forceResetPassword"`
		AllowedCoins       []interface{} `json:"allowedCoins"`
		Agreements         struct {
			TermsOfUse               int       `json:"termsOfUse"`
			TermsOfUseAcceptanceDate time.Time `json:"termsOfUseAcceptanceDate"`
		} `json:"agreements"`
		LastLogin   time.Time `json:"lastLogin"`
		Enterprises []struct {
			ID string `json:"id"`
		} `json:"enterprises"`
	} `json:"user"`
	EncryptedToken    string `json:"encryptedToken"`
	DerivationPath    string `json:"derivationPath"`
	EncryptedECDHXprv string `json:"encryptedECDHXprv"`
	AccessToken       string `json:"access_token"`
}

type TotalBalances

type TotalBalances struct {
	Balance                int    `json:"balance"`
	BalanceString          string `json:"balanceString"`
	ConfirmedBalance       int    `json:"confirmedBalance"`
	ConfirmedBalanceString string `json:"confirmedBalanceString"`
	SpendableBalance       int    `json:"spendableBalance"`
	SpendableBalanceString string `json:"spendableBalanceString"`
}

type Transaction

type Transaction struct {
	TxHex  string `json:"txHex"`
	TxInfo struct {
		NP2SHInputs   int `json:"nP2SHInputs"`
		NSegwitInputs int `json:"nSegwitInputs"`
		NOutputs      int `json:"nOutputs"`
		Unspents      []struct {
			Chain        int    `json:"chain"`
			Index        int    `json:"index"`
			RedeemScript string `json:"redeemScript"`
			ID           string `json:"id"`
			Address      string `json:"address"`
			Value        int    `json:"value"`
		} `json:"unspents"`
		ChangeAddresses []string `json:"changeAddresses"`
	} `json:"txInfo"`
	FeeInfo struct {
		Size           int    `json:"size"`
		Fee            int    `json:"fee"`
		FeeRate        int    `json:"feeRate"`
		PayGoFee       int    `json:"payGoFee"`
		PayGoFeeString string `json:"payGoFeeString"`
	} `json:"feeInfo"`
}

type TransactionDescription

type TransactionDescription struct {
	Txid   string `json:"txid"`
	Status string `json:"status"`
}

type TransactionFees

type TransactionFees struct {
	FeePerKb  int `json:"feePerKb"`
	NumBlocks int `json:"numBlocks"`
}

type Transfer

type Transfer struct {
	ID            string    `json:"id"`
	Coin          string    `json:"coin"`
	Wallet        string    `json:"wallet"`
	Txid          string    `json:"txid"`
	Height        int       `json:"height"`
	Date          time.Time `json:"date"`
	Confirmations int       `json:"confirmations"`
	Type          string    `json:"type"`
	Value         int       `json:"value"`
	ValueString   string    `json:"valueString"`
	BitgoFee      int       `json:"bitgoFee"`
	Usd           float64   `json:"usd"`
	UsdRate       float64   `json:"usdRate"`
	State         string    `json:"state"`
	VSize         int       `json:"vSize"`
	NSegwitInputs int       `json:"nSegwitInputs"`
	Tags          []string  `json:"tags"`
	SequenceID    string    `json:"sequenceId"`
	History       []struct {
		Date   time.Time `json:"date"`
		Action string    `json:"action"`
	} `json:"history"`
	Entries []struct {
		Address     string `json:"address"`
		Value       int    `json:"value"`
		ValueString string `json:"valueString"`
		Wallet      string `json:"wallet,omitempty"`
		Label       string `json:"label,omitempty"`
	} `json:"entries"`
	Outputs []struct {
		ID          string `json:"id"`
		Address     string `json:"address"`
		Value       int    `json:"value"`
		ValueString string `json:"valueString"`
		Wallet      string `json:"wallet"`
		Chain       int    `json:"chain"`
		Index       int    `json:"index"`
	} `json:"outputs"`
	Inputs []struct {
		ID          string `json:"id"`
		Address     string `json:"address"`
		Value       int    `json:"value"`
		ValueString string `json:"valueString"`
		Wallet      string `json:"wallet"`
		Chain       int    `json:"chain"`
		Index       int    `json:"index"`
	} `json:"inputs"`
	ConfirmedTime time.Time `json:"confirmedTime"`
	CreatedTime   time.Time `json:"createdTime"`
}

type TransferList

type TransferList struct {
	NextBatchPrevId string     `json:"nextBatchPrevId"`
	Coin            string     `json:"coin"`
	Count           int        `json:"count"`
	Transfers       []Transfer `json:"transfers"`
}

type UnlockParams

type UnlockParams struct {
	Otp      string `json:"otp" valid:"required"`
	Duration int    `json:"duration,omitempty"`
}

type UpdateWalletAddressParams

type UpdateWalletAddressParams struct {
	Label string `json:"label,omitempty"`
}

type UpdateWalletParams

type UpdateWalletParams struct {
	Label                           string  `json:"label,omitempty"`
	DisableTransactionNotifications bool    `json:"disableTransactionNotifications,omitempty"`
	ApprovalsRequired               float64 `json:"approvalsRequired,omitempty"`
}

type UserProfile

type UserProfile struct {
	User struct {
		ID       string `json:"id"`
		IsActive bool   `json:"isActive"`
		Name     struct {
			First string `json:"first"`
			Full  string `json:"full"`
			Last  string `json:"last"`
		} `json:"name"`
		Username string `json:"username"`
	} `json:"user"`
}

type Wallet

type Wallet struct {
	ID    string `json:"id"`
	Users []struct {
		User        string   `json:"user"`
		Permissions []string `json:"permissions"`
	} `json:"users"`
	Coin                            string   `json:"coin"`
	Label                           string   `json:"label"`
	M                               int      `json:"m"`
	N                               int      `json:"n"`
	Keys                            []string `json:"keys"`
	Tags                            []string `json:"tags"`
	DisableTransactionNotifications bool     `json:"disableTransactionNotifications"`
	Freeze                          struct {
	} `json:"freeze"`
	Deleted           bool `json:"deleted"`
	ApprovalsRequired int  `json:"approvalsRequired"`
	CoinSpecific      struct {
	} `json:"coinSpecific"`
	Balance                int    `json:"balance"`
	ConfirmedBalance       int    `json:"confirmedBalance"`
	SpendableBalance       int    `json:"spendableBalance"`
	BalanceString          string `json:"balanceString"`
	ConfirmedBalanceString string `json:"confirmedBalanceString"`
	SpendableBalanceString string `json:"spendableBalanceString"`
	ReceiveAddress         struct {
		Address      string `json:"address"`
		Chain        int    `json:"chain"`
		Index        int    `json:"index"`
		Coin         string `json:"coin"`
		Wallet       string `json:"wallet"`
		CoinSpecific struct {
			RedeemScript string `json:"redeemScript"`
		} `json:"coinSpecific"`
	} `json:"receiveAddress"`
	Admin struct {
		Policy struct {
			ID      string    `json:"id"`
			Label   string    `json:"label"`
			Version int       `json:"version"`
			Date    time.Time `json:"date"`
			Rules   []struct {
				ID     string `json:"id"`
				Coin   string `json:"coin"`
				Type   string `json:"type"`
				Action struct {
					Type string `json:"type"`
				} `json:"action"`
				Condition struct {
					AmountString string        `json:"amountString"`
					TimeWindow   int           `json:"timeWindow"`
					GroupTags    []string      `json:"groupTags"`
					ExcludeTags  []interface{} `json:"excludeTags"`
				} `json:"condition"`
			} `json:"rules"`
		} `json:"policy"`
	} `json:"admin"`
}

type Webhook

type Webhook struct {
	ID       string    `json:"id"`
	Label    string    `json:"label"`
	Created  time.Time `json:"created"`
	WalletID string    `json:"walletId"`
	Coin     string    `json:"coin"`
	Type     string    `json:"type"`
	URL      string    `json:"url"`
	Version  int       `json:"version"`
}

type WebhookEvent

type WebhookEvent struct {
	Hash     string `json:"hash"`
	Transfer string `json:"transfer"`
	Coin     string `json:"coin"`
	Type     string `json:"type"`
	Wallet   string `json:"wallet"`
}

type Webhooks

type Webhooks []Webhook

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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