Giter Site home page Giter Site logo

go-ledger-sdk's Introduction

go-ledger-sdk

A golang SDK for using Ledger wallets from golang Spacemesh wallets such as smrepl

Note: this repository is no longer maintained. Please see spacemesh-sdk instead.

API

Enumerate Ledger devices.

/**
 * @param {int} productID USB Product ID filter, 0 - all.
 * @return {[]*HidDevice} Discovered Ledger devices.
 *
 * @example
 * devices := ledger.GetDevices(0)
 * if devices != nil && len(devices) > 0 {
 * 	device := devices[0]
 * 	if err := device.Open(); err == nil {
 * 		...
 * 		device.Close()
 * 	} else {
 * 		fmt.Printf("Open device ERROR: %v\n", err)
 * 	}
 * }
 */
func GetDevices(productID int) []*HidDevice

Open Ledger device for communication.

/**
 * @return {error} Error value.
 *
 * @example
 * devices := ledger.GetDevices(0)
 * if devices != nil && len(devices) > 0 {
 * 	device := devices[0]
 * 	if err := device.Open(); err == nil {
 * 		...
 * 		device.Close()
 * 	} else {
 * 		fmt.Printf("Open device ERROR: %v\n", err)
 * 	}
 * }
 */
func (device *HidDevice) Open() error

Close communication with Ledger device.

/**
 * @example
 * devices := ledger.GetDevices(0)
 * if devices != nil && len(devices) > 0 {
 * 	device := devices[0]
 * 	if err := device.Open(); err == nil {
 * 		...
 * 		device.Close()
 * 	} else {
 * 		fmt.Printf("Open device ERROR: %v\n", err)
 * 	}
 * }
 */
func (device *HidDevice) Close()

Get the ledger app version.

/**
 * @returns {Version} Result object containing the application version number.
 * @return {error} Error value.
 *
 * @example
 * version, err := device.GetVersion()
 * if err != nil {
 * 	fmt.Printf("get version ERROR: %v\n", err)
 * } else {
 * 	fmt.Printf("version: %+v\n", version)
 * }
 */
func (device *HidDevice) GetVersion() (*Version, error)

Get a public key from the specified BIP 32 path.

/**
 * @param {BipPath} path The BIP 32 path indexes. Path must begin with `44'/540'/n'`, and shuld be 5 indexes long.
 * @return {ExtendedPublicKey} The public key with chaincode for the given path.
 * @return {error} Error value.
 *
 * @example
 * publicKey, err := device.GetExtendedPublicKey(ledger.StringToPath("44'/540'/0'/0/0'"))
 * if err != nil {
 * 	fmt.Printf("get public key ERROR: %v\n", err)
 * } else {
 * 	fmt.Printf("public key: %+v\n", publicKey)
 * }
 */
func (device *HidDevice) GetExtendedPublicKey(path BipPath) (*ExtendedPublicKey, error)

Gets an address from the specified BIP 32 path.

/**
 * @param {BipPath} path The BIP 32 path indexes. Path must begin with `44'/540'/0'/0/i`
 * @return {[]byte} The address for the given path.
 * @return {error} Error value.
 *
 * @example
 * address, err := device.GetAddress(ledger.StringToPath("44'/540'/0'/0/0'"))
 * if err != nil {
 * 	fmt.Printf("get address ERROR: %v\n", err)
 * } else {
 * 	fmt.Printf("address: %+v\n", address)
 * }
 */
func (device *HidDevice) GetAddress(path BipPath) ([]byte, error)

Show an address from the specified BIP 32 path for verify.

/**
 * @param {BipPath} indexes The path indexes. Path must begin with `44'/540'/0'/0/i`
 * @return {error} Error value.
 *
 * @example
 * err := device.ShowAddress(ledger.StringToPath("44'/540'/0'/0/1'"))
 * if err != nil {
 * 	fmt.Printf("show address ERROR: %v\n", err)
 * } else {
 * 	fmt.Printf("show address: OK\n")
 * }
 */
func (device *HidDevice) ShowAddress(path BipPath) error

Sign a transaction by the specified BIP 32 path account address.

/**
 * @param {BipPath} path The BIP 32 path indexes. Path must begin with `44'/540'/0'/0/i`
 * @param {[]byte} tx The XDR encoded transaction data, include transaction type
 * @return {[]byte} Signed transaction.
 * @return {error} Error value
 *
 * @example
 * tx := make([]byte, 0)
 * var bin []byte
 * bin, _ = hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000000") // network id
 * tx = append(tx, bin...)
 * tx = append(tx, 0) // coin transaction with ed
 * tx = append(tx, uint64_to_buf(1)...) // nonce
 * bin, _ = hex.DecodeString("0000000000000000000000000000000000000000") // recepient
 * tx = append(tx, bin...)
 * tx = append(tx, uint64_to_buf(1000000)...) // gas limit
 * tx = append(tx, uint64_to_buf(1000)...) // gas price
 * tx = append(tx, uint64_to_buf(1000000000000)...) // amount
 * tx = append(tx, publicKey.PublicKey...)
 * 
 * response, err := device.SignTx(ledger.StringToPath("44'/540'/0'/0/0'"), tx)
 * if err != nil {
 * 	fmt.Printf("Verify coin tx ERROR: %v\n", err)
 * } else {
 * 	hash := sha512.Sum512(tx)
 * 	fmt.Printf("Verify coin tx: %v\n", ed25519.Verify(publicKey.PublicKey, hash[:], response[1:65]))
 * }
 */
func (device *HidDevice) SignTx(path BipPath, tx []byte) ([]byte, error)

go-ledger-sdk's People

Contributors

andrewar2 avatar avive avatar lrettig avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-ledger-sdk's Issues

./transport.go:62:15: undefined: HidDevice

Getting this mysterious error whenever I try to run on Windows or Linux (main branch, as well as my more recent branches). Works fine on macOS. And for some reason GHA CLI doesn't produce this error.

> go version
go version go1.20.2 darwin/arm64
> GOOS=linux go test -v -tags=speculos
# github.com/spacemeshos/go-ledger-sdk [github.com/spacemeshos/go-ledger-sdk.test]
./transport.go:62:15: undefined: HidDevice
FAIL    github.com/spacemeshos/go-ledger-sdk [build failed]
> go version
go version go1.20.2 linux/amd64
> go test -v -tags=speculos
# github.com/spacemeshos/go-ledger-sdk [github.com/spacemeshos/go-ledger-sdk.test]
./transport.go:62:15: undefined: HidDevice
FAIL    github.com/spacemeshos/go-ledger-sdk [build failed]

speculos_test.go:251: get public key ERROR: Post "http://127.0.0.1:5001/apdu": EOF

Getting this error from CLI: https://github.com/spacemeshos/go-ledger-sdk/actions/runs/4453279188/jobs/7821677253. This works fine locally on macOS; tests on Linux run into #4.

Run go test -v -tags=speculos
=== RUN   TestSpeculos
    speculos_test.go:251: get public key ERROR: Post "http://127.0.0.1:5001/apdu": EOF
--- FAIL: TestSpeculos (0.00s)
FAIL
exit status 1
FAIL	github.com/spacemeshos/go-ledger-sdk	0.005s
Error: Process completed with exit code 1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.