Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Minor formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Apr 3, 2022
1 parent e3401ac commit d43e94f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 58 deletions.
33 changes: 19 additions & 14 deletions authentication_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ type ParamRequestKey string
const (
// ParamXPubKey the request parameter for the xpub string
ParamXPubKey ParamRequestKey = "xpub"

// ParamXPubHashKey the request parameter for the xpub ID
ParamXPubHashKey ParamRequestKey = "xpub_hash"

// ParamAdminRequest the request parameter whether this is an admin request
ParamAdminRequest ParamRequestKey = "auth_admin"

// ParamAuthSigned the request parameter that says whether the request was signed
ParamAuthSigned ParamRequestKey = "auth_signed"
)
Expand All @@ -77,22 +80,23 @@ func createSignature(xPriv *bip32.ExtendedKey, bodyString string) (payload *Auth

// Get the xPub
payload = new(AuthPayload)
payload.xPub, err = bitcoin.GetExtendedPublicKey(xPriv)
if err != nil { // Should never error if key is correct
if payload.xPub, err = bitcoin.GetExtendedPublicKey(
xPriv,
); err != nil { // Should never error if key is correct
return
}

// auth_nonce is a random unique string to seed the signing message
// this can be checked server side to make sure the request is not being replayed
payload.AuthNonce, err = utils.RandomHex(32)
if err != nil { // Should never error if key is correct
if payload.AuthNonce, err = utils.RandomHex(32); err != nil { // Should never error if key is correct
return
}

// Derive the address for signing
var key *bip32.ExtendedKey
key, err = utils.DeriveChildKeyFromHex(xPriv, payload.AuthNonce)
if err != nil {
if key, err = utils.DeriveChildKeyFromHex(
xPriv, payload.AuthNonce,
); err != nil {
return
}

Expand All @@ -114,8 +118,9 @@ func createSignatureAccessKey(privateKeyHex, bodyString string) (payload *AuthPa
}

var privateKey *bec.PrivateKey
privateKey, err = bitcoin.PrivateKeyFromString(privateKeyHex)
if err != nil {
if privateKey, err = bitcoin.PrivateKeyFromString(
privateKeyHex,
); err != nil {
return
}
publicKey := privateKey.PubKey()
Expand All @@ -134,6 +139,7 @@ func createSignatureAccessKey(privateKeyHex, bodyString string) (payload *AuthPa
return createSignatureCommon(payload, bodyString, privateKey)
}

// createSignatureCommon will create a signature
func createSignatureCommon(payload *AuthPayload, bodyString string, privateKey *bec.PrivateKey) (*AuthPayload, error) {

// Create the auth header hash
Expand All @@ -148,13 +154,12 @@ func createSignatureCommon(payload *AuthPayload, bodyString string, privateKey *
}

// Signature, using bitcoin signMessage
hexKey := hex.EncodeToString(privateKey.Serialise())
message := getSigningMessage(key, payload)
var err error
payload.Signature, err = bitcoin.SignMessage(
hexKey, message, true,
)
if err != nil {
if payload.Signature, err = bitcoin.SignMessage(
hex.EncodeToString(privateKey.Serialise()),
getSigningMessage(key, payload),
true,
); err != nil {
return nil, err
}

Expand Down
45 changes: 1 addition & 44 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,51 +312,8 @@ func (c *Client) GetOrStartTxn(ctx context.Context, name string) context.Context
// GetFeeUnit get the fee from a miner
// todo: move into it's own Service / package
func (c *Client) GetFeeUnit(_ context.Context, _ string) *utils.FeeUnit {
// todo: use a custom fee
return defaultFee
/*
func (c *Client) GetFeeUnit(ctx context.Context, useMiner string) *utils.FeeUnit {
if useMiner == "" {
useMiner = minercraft.MinerTaal
}
cacheKey := "draft-transaction-fee-" + useMiner
var fee *utils.FeeUnit
err := c.Cachestore().GetModel(ctx, cacheKey, fee)
if err == nil && fee != nil {
return fee
}
var client *minercraft.Client
if client, err = minercraft.NewClient(nil, nil, nil); err != nil {
log.Printf("error occurred creating minercraft client: %s", err.Error())
return defaultFee
}
miner := client.MinerByName(useMiner)
var response *minercraft.FeeQuoteResponse
if response, err = client.FeeQuote(context.Background(), miner); err != nil {
log.Printf("error occurred getting fee quote: %s", err.Error())
return defaultFee
}
for _, quote := range response.Quote.Fee {
if quote.FeeType == "standard" && quote.MiningFee.Satoshis > 0 {
fee = &utils.FeeUnit{
Satoshis: quote.MiningFee.Satoshis,
Bytes: quote.MiningFee.Bytes,
}
break
}
}
err = c.Cachestore().SetModel(ctx, cacheKey, fee)
if err != nil {
log.Printf("error occurred caching fee quote: %s", err.Error())
}
return fee
}
*/
}

// GetTaskPeriod will return the period for a given task name
Expand Down

0 comments on commit d43e94f

Please sign in to comment.