From e72d1e36309b90b42ecc125ed444b9c0afee6679 Mon Sep 17 00:00:00 2001 From: arkadiuszos4chain Date: Thu, 4 Apr 2024 10:52:05 +0200 Subject: [PATCH] feat(BUX-400): add comments to exported functions --- contacts.go | 2 +- totp.go | 8 +++++--- totp/totp.go | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/contacts.go b/contacts.go index ae7d36d..24a36de 100644 --- a/contacts.go +++ b/contacts.go @@ -31,7 +31,7 @@ func (b *WalletClient) RejectContact(ctx context.Context, paymail string) transp // ConfirmContact will try to confirm the contact func (b *WalletClient) ConfirmContact(ctx context.Context, contact *models.Contact, passcode string, validationPeriod, digits uint) transports.ResponseError { - isTotpValid, err := b.ConfirmTotpForContact(contact, passcode, validationPeriod, digits) + isTotpValid, err := b.ValidateTotpForContact(contact, passcode, validationPeriod, digits) if err != nil { return transports.WrapError(fmt.Errorf("totp validation failed: %w", err)) } diff --git a/totp.go b/totp.go index 7c034e1..a4ba40a 100644 --- a/totp.go +++ b/totp.go @@ -11,6 +11,7 @@ import ( "github.com/libsv/go-bk/bip32" ) +// GenerateTotpForContact creates one time-based one-time password based on secret shared between the user and the contact func (b *WalletClient) GenerateTotpForContact(contact *models.Contact, validationPeriod, digits uint) (string, error) { if b.xPriv == nil { return "", errors.New("init client with xPriv first") @@ -34,7 +35,8 @@ func (b *WalletClient) GenerateTotpForContact(contact *models.Contact, validatio return ts.GenarateTotp(xpriv, cXpub) } -func (b *WalletClient) ConfirmTotpForContact(contact *models.Contact, passcode string, validationPeriod, digits uint) (bool, error) { +// ValidateTotpForContact validates one time-based one-time password based on secret shared between the user and the contact +func (b *WalletClient) ValidateTotpForContact(contact *models.Contact, passcode string, validationPeriod, digits uint) (bool, error) { if b.xPriv == nil { return false, errors.New("init client with xPriv first") } @@ -58,9 +60,9 @@ func (b *WalletClient) ConfirmTotpForContact(contact *models.Contact, passcode s } func deriveXprivForPki(xpriv *bip32.ExtendedKey) (*bip32.ExtendedKey, error) { - // derive xpriv for current PKI - // TODO: currently we don't support PKI rotation // PKI derivation path: m/0/0/0 + // NOTICE: we currently do not support PKI rotation; however, adjustments will be made if and when we decide to implement it + pkiXpriv, err := bitcoin.GetHDKeyByPath(xpriv, utils.ChainExternal, 0) if err != nil { return nil, err diff --git a/totp/totp.go b/totp/totp.go index ec26d49..f2cee51 100644 --- a/totp/totp.go +++ b/totp/totp.go @@ -10,11 +10,13 @@ import ( "github.com/pquerna/otp/totp" ) +// Time-base one-time password service type Service struct { Period uint Digits uint } +// GenerateTotp creates one time-based one-time password based on secrets calculated from the keys func (s *Service) GenarateTotp(xPriv, xPub *bip32.ExtendedKey) (string, error) { secret, err := sharedSecret(xPriv, xPub) if err != nil { @@ -24,6 +26,7 @@ func (s *Service) GenarateTotp(xPriv, xPub *bip32.ExtendedKey) (string, error) { return totp.GenerateCodeCustom(string(secret), time.Now(), s.getOpts()) } +// ValidateTotp checks if given one-time password is valid func (s *Service) ValidateTotp(xPriv, xPub *bip32.ExtendedKey, passcode string) (bool, error) { secret, err := sharedSecret(xPriv, xPub) if err != nil {