Skip to content

Commit

Permalink
fix: payment option config - base 64 signing key (#895)
Browse files Browse the repository at this point in the history
* store payment option signingKeyId as base64 encoded string
  • Loading branch information
volodymyr-basiuk authored Jan 16, 2025
1 parent b5e6bd9 commit 218a503
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2826,6 +2826,7 @@ components:
type: string
signingKeyID:
type: string
description: base64 encoded keyID
expiration:
type: string
format: date-time
Expand Down
4 changes: 3 additions & 1 deletion internal/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions internal/api/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"bytes"
"context"
b64 "encoding/base64"
"encoding/json"
"fmt"
"math/big"
Expand Down Expand Up @@ -566,13 +567,13 @@ func TestServer_CreatePaymentRequest(t *testing.T) {
PaymentOptionID: 1,
Amount: *amount,
Recipient: common.Address{},
SigningKeyID: signingKeyID.ID,
SigningKeyID: b64.StdEncoding.EncodeToString([]byte(signingKeyID.ID)),
},
{
PaymentOptionID: 2,
Amount: *amount,
Recipient: common.Address{},
SigningKeyID: signingKeyID.ID,
SigningKeyID: b64.StdEncoding.EncodeToString([]byte(signingKeyID.ID)),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/domain/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type PaymentRequestItem struct {
Nonce big.Int
PaymentRequestID uuid.UUID
PaymentOptionID payments.OptionConfigIDType // The numeric id that identify a payment option in payments config file.
SigningKeyID string
SigningKeyID string // Base64 encoded key id
Payment protocol.PaymentRequestInfoDataItem
}

Expand Down
17 changes: 15 additions & 2 deletions internal/core/services/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/ecdsa"
"crypto/rand"
b64 "encoding/base64"
"encoding/hex"
"fmt"
"math/big"
Expand Down Expand Up @@ -427,9 +428,15 @@ func (p *payment) paymentRequestSignature(
) ([]byte, error) {
paymentType := string(setting.PaymentOption.Type)

decodedKeyID, err := b64.StdEncoding.DecodeString(chainConfig.SigningKeyID)
if err != nil {
log.Error(ctx, "decoding base64 key id", "err", err)
return nil, err
}

keyID := kms.KeyID{
Type: kms.KeyTypeEthereum,
ID: chainConfig.SigningKeyID,
ID: string(decodedKeyID),
}

typedData := apitypes.TypedData{
Expand Down Expand Up @@ -529,9 +536,15 @@ func (p *payment) paymentRequestSignature(
}

func (p *payment) getSignerAddress(ctx context.Context, signingKeyID string) (common.Address, error) {
decodedKeyID, err := b64.StdEncoding.DecodeString(signingKeyID)
if err != nil {
log.Error(ctx, "decoding base64 key id", "err", err)
return common.Address{}, err
}

bytesPubKey, err := p.kms.PublicKey(kms.KeyID{
Type: kms.KeyTypeEthereum,
ID: signingKeyID,
ID: string(decodedKeyID),
})
if err != nil {
return common.Address{}, err
Expand Down

0 comments on commit 218a503

Please sign in to comment.