Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use gouroboros for address implementation #133

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions bursa.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -18,10 +18,10 @@ import (
"encoding/json"
"fmt"

// TODO: replace these w/ gOuroboros (blinklabs-io/gouroboros#364)
"github.com/fivebinaries/go-cardano-serialization/address"
ouroboros "github.com/blinklabs-io/gouroboros"
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
// TODO: create our own bip32 implementation, see #132
"github.com/fivebinaries/go-cardano-serialization/bip32"
"github.com/fivebinaries/go-cardano-serialization/network"
"github.com/fxamacker/cbor/v2"
bip39 "github.com/tyler-smith/go-bip39"

Expand Down Expand Up @@ -62,7 +62,7 @@ func NewWallet(
w := &Wallet{
Mnemonic: mnemonic,
PaymentAddress: addr.String(),
StakeAddress: addr.ToReward().String(),
StakeAddress: addr.StakeAddress().String(),
PaymentVKey: GetPaymentVKey(paymentKey),
PaymentSKey: GetPaymentSKey(paymentKey),
PaymentExtendedSKey: GetPaymentExtendedSKey(paymentKey),
Expand All @@ -75,7 +75,7 @@ func NewWallet(

func NewDefaultWallet(mnemonic string) (*Wallet, error) {
cfg := config.GetConfig()
w, err := NewWallet(mnemonic, "", cfg.Network, 0, 0, 0, 0)
w, err := NewWallet(mnemonic, cfg.Network, "", 0, 0, 0, 0)
if err != nil {
return nil, fmt.Errorf("failed to create default wallet: %s", err)
}
Expand Down Expand Up @@ -204,12 +204,13 @@ func GetStakeExtendedSKey(stakeKey bip32.XPrv) KeyFile {

func GetAddress(
accountKey bip32.XPrv,
net string,
networkName string,
num uint32,
) *address.BaseAddress {
nw := network.TestNet()
if net == "mainnet" {
nw = network.MainNet()
) *lcommon.Address {
network, ok := ouroboros.NetworkByName(networkName)
if !ok {
fmt.Println("couldn't get network")
return nil
}
paymentKeyPublicHash := GetPaymentKey(
accountKey,
Expand All @@ -223,18 +224,17 @@ func GetAddress(
).Public().
PublicKey().
Hash()
addr := address.NewBaseAddress(
nw,
&address.StakeCredential{
Kind: address.KeyStakeCredentialType,
Payload: paymentKeyPublicHash[:],
},
&address.StakeCredential{
Kind: address.KeyStakeCredentialType,
Payload: stakeKeyPublicHash[:],
},
addr, err := lcommon.NewAddressFromParts(
lcommon.AddressTypeKeyKey,
network.Id,
paymentKeyPublicHash[:],
stakeKeyPublicHash[:],
)
return addr
if err != nil {
fmt.Println("error creating address", err)
return nil
}
return &addr
}

func GetExtendedPrivateKey(privateKey []byte, publicKey []byte) bip32.XPrv {
Expand Down
16 changes: 10 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/blinklabs-io/bursa
go 1.22.11

require (
github.com/blinklabs-io/gouroboros v0.108.2
github.com/fivebinaries/go-cardano-serialization v0.0.0-20220907134105-ec9b85086588
github.com/fxamacker/cbor/v2 v2.7.0
github.com/kelseyhightower/envconfig v1.4.0
Expand All @@ -16,32 +17,35 @@ require (
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcutil v1.0.2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.6 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/spec v0.20.6 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/copier v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/utxorpc/go-codegen v0.16.0 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/crypto v0.32.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/protobuf v1.36.3 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading