Skip to content

Commit

Permalink
feat(BUX-400): add comments to exported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszos4chain committed Apr 4, 2024
1 parent 9cf6e97 commit e72d1e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
8 changes: 5 additions & 3 deletions totp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
}
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions totp/totp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit e72d1e3

Please sign in to comment.