Skip to content

Commit

Permalink
chore(deps): update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazarii-4chain committed Apr 19, 2024
2 parents 4fdc92f + ced6c2b commit 5dea8bc
Show file tree
Hide file tree
Showing 15 changed files with 568 additions and 11 deletions.
39 changes: 39 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Code of Conduct

## 1. Purpose

The primary goal of this project is to foster an inclusive, respectful, and open community for everyone, regardless of their background or identity. This Code of Conduct outlines our expectations for participant behavior and the consequences for unacceptable behavior.

## 2. Open Discussions & Respectful Feedback

- **Encourage Diverse Ideas:** Everyone brings a unique perspective. Encourage different viewpoints, and listen openly to each other’s ideas.

- **Constructive Feedback:** Focus on providing constructive feedback rather than criticizing individuals. Discuss ideas, not the person presenting them.

- **Avoid Harmful Language:** Refrain from using offensive or harmful language, including but not limited to sexist, racist, homophobic, transphobic, ableist, or discriminatory remarks.

## 3. No Politics or Off-topic Discussions

- **Stay On Topic:** Keep discussions focused on the project and avoid bringing in off-topic or political discussions.

- **Respectful Discourse:** If discussions become heated, maintain a level of respect and understanding, and work towards a compromise.

## 4. Reporting & Enforcement

- **Report Violations:** If you observe a violation of this Code of Conduct, please report it by contacting the project team members.

- **Consequences:** Violations of this Code of Conduct may result in temporary or permanent banning from the project community.

## 5. Inclusion & Diversity

- **Welcome Everyone:** Foster an environment where everyone feels welcome, regardless of their background, identity, or level of experience.

- **Help Newcomers:** Offer help and guidance to newcomers to make them feel welcome in our community.

## 6. Be Kind & Courteous

- **Respect Time & Effort:** Recognize and respect the time and effort put in by contributors and maintainers.

- **Courtesy:** Be courteous and polite. Treat others as you would like to be treated.

By participating in this project, you agree to abide by this Code of Conduct. Let’s work together to make this community respectful and inclusive for everyone.
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
updates:
# Maintain dependencies for the core library
- package-ecosystem: "gomod"
target-branch: "master"
target-branch: "main"
directory: "/"
schedule:
interval: "daily"
Expand All @@ -19,7 +19,7 @@ updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
target-branch: "master"
target-branch: "main"
directory: "/"
schedule:
interval: "weekly"
Expand Down
2 changes: 1 addition & 1 deletion .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pull_request_rules:

- name: Close stale pull request
conditions:
- base=master
- base=main
- -closed
- updated-at<21 days ago
actions:
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ name: "CodeQL"

on:
push:
branches: [master]
branches:
- master
- main
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
branches:
- master
- main
# schedule:
# - cron: '0 23 * * 0'

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/sync-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- master
- main
paths:
- .github/labels.yml
jobs:
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# SPV Wallet: Go Client

[![Release](https://img.shields.io/github/release-pre/bitcoin-sv/spv-wallet-go-client.svg?logo=github&style=flat&v=2)](https://github.com/bitcoin-sv/spv-wallet-go-client/releases)
[![Build Status](https://img.shields.io/github/actions/workflow/status/bitcoin-sv/spv-wallet-go-client/run-tests.yml?branch=master&v=2)](https://github.com/bitcoin-sv/spv-wallet-go-client/actions)
[![Build Status](https://img.shields.io/github/actions/workflow/status/bitcoin-sv/spv-wallet-go-client/run-tests.yml?branch=main&v=2)](https://github.com/bitcoin-sv/spv-wallet-go-client/actions)
[![Report](https://goreportcard.com/badge/github.com/bitcoin-sv/spv-wallet-go-client?style=flat&v=2)](https://goreportcard.com/report/github.com/bitcoin-sv/spv-wallet-go-client)
[![codecov](https://codecov.io/gh/bitcoin-sv/spv-wallet-go-client/branch/master/graph/badge.svg?v=2)](https://codecov.io/gh/bitcoin-sv/spv-wallet-go-client)
[![codecov](https://codecov.io/gh/bitcoin-sv/spv-wallet-go-client/branch/main/graph/badge.svg?v=2)](https://codecov.io/gh/bitcoin-sv/spv-wallet-go-client)
[![Mergify Status](https://img.shields.io/endpoint.svg?url=https://api.mergify.com/v1/badges/bitcoin-sv/spv-wallet-go-client&style=flat&v=2)](https://mergify.io)
<br>

Expand All @@ -14,6 +14,7 @@
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat&v=2)](https://github.com/RichardLitt/standard-readme)
[![Makefile Included](https://img.shields.io/badge/Makefile-Supported%20-brightgreen?=flat&logo=probot&v=2)](Makefile)


<br/>
</div>

Expand Down Expand Up @@ -47,6 +48,8 @@ go get -u github.com/bitcoin-sv/spv-wallet-go-client
## Documentation
View the generated [documentation](https://pkg.go.dev/github.com/bitcoin-sv/spv-wallet-go-client)

For in-depth information and guidance, please refer to the [SPV Wallet Documentation](https://bsvblockchain.gitbook.io/docs).

[![GoDoc](https://godoc.org/github.com/bitcoin-sv/spv-wallet-go-client?status.svg&style=flat&v=2)](https://pkg.go.dev/github.com/bitcoin-sv/spv-wallet-go-client)

<br/>
Expand Down
49 changes: 49 additions & 0 deletions contacts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package walletclient

import (
"context"
"errors"
"fmt"

"github.com/bitcoin-sv/spv-wallet-go-client/transports"
"github.com/bitcoin-sv/spv-wallet/models"
)

// UpsertContact add or update contact. When adding a new contact, the system utilizes Paymail's PIKE capability to dispatch an invitation request, asking the counterparty to include the current user in their contacts.
func (b *WalletClient) UpsertContact(ctx context.Context, paymail, fullName string, metadata *models.Metadata) (*models.Contact, transports.ResponseError) {
return b.transport.UpsertContact(ctx, paymail, fullName, metadata, "")
}

// UpsertContactForPaymail add or update contact. When adding a new contact, the system utilizes Paymail's PIKE capability to dispatch an invitation request, asking the counterparty to include the current user specified paymail in their contacts.
func (b *WalletClient) UpsertContactForPaymail(ctx context.Context, paymail, fullName string, metadata *models.Metadata, requesterPaymail string) (*models.Contact, transports.ResponseError) {
return b.transport.UpsertContact(ctx, paymail, fullName, metadata, requesterPaymail)
}

// AcceptContact will accept the contact associated with the paymail
func (b *WalletClient) AcceptContact(ctx context.Context, paymail string) transports.ResponseError {
return b.transport.AcceptContact(ctx, paymail)
}

// RejectContact will reject the contact associated with the paymail
func (b *WalletClient) RejectContact(ctx context.Context, paymail string) transports.ResponseError {
return b.transport.RejectContact(ctx, paymail)
}

// ConfirmContact will try to confirm the contact
func (b *WalletClient) ConfirmContact(ctx context.Context, contact *models.Contact, passcode string, period, digits uint) transports.ResponseError {
isTotpValid, err := b.ValidateTotpForContact(contact, passcode, period, digits)
if err != nil {
return transports.WrapError(fmt.Errorf("totp validation failed: %w", err))
}

if !isTotpValid {
return transports.WrapError(errors.New("totp is invalid"))
}

return b.transport.ConfirmContact(ctx, contact.Paymail)
}

// GetContacts will get contacts by conditions
func (b *WalletClient) GetContacts(ctx context.Context, conditions map[string]interface{}, metadata *models.Metadata, queryParams *transports.QueryParams) ([]*models.Contact, transports.ResponseError) {
return b.transport.GetContacts(ctx, conditions, metadata, queryParams)
}
145 changes: 145 additions & 0 deletions contacts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package walletclient

import (
"context"
"testing"

"github.com/bitcoin-sv/spv-wallet-go-client/fixtures"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TestContactActionsRouting will test routing
func TestContactActionsRouting(t *testing.T) {
tcs := []struct {
name string
route string
responsePayload string
f func(c *WalletClient) error
}{
{
name: "RejectContact",
route: "/contact/rejected/",
responsePayload: "{}",
f: func(c *WalletClient) error { return c.RejectContact(context.Background(), fixtures.PaymailAddress) },
},
{
name: "AcceptContact",
route: "/contact/accepted/",
responsePayload: "{}",
f: func(c *WalletClient) error { return c.AcceptContact(context.Background(), fixtures.PaymailAddress) },
},
{
name: "GetContacts",
route: "/contact/search/",
responsePayload: "[]",
f: func(c *WalletClient) error {
_, err := c.GetContacts(context.Background(), nil, nil, nil)
return err
},
},
{
name: "UpsertContact",
route: "/contact/",
responsePayload: "{}",
f: func(c *WalletClient) error {
_, err := c.UpsertContact(context.Background(), "", "", nil)
return err
},
},
{
name: "UpsertContactForPaymail",
route: "/contact/",
responsePayload: "{}",
f: func(c *WalletClient) error {
_, err := c.UpsertContactForPaymail(context.Background(), "", "", nil, "")
return err
},
},
{
name: "ConfirmContact",
route: "/contact/confirmed/",
responsePayload: "{}",
f: func(c *WalletClient) error {
contact := models.Contact{PubKey: fixtures.PubKey}

passcode, _ := c.GenerateTotpForContact(&contact, 30, 2)
return c.ConfirmContact(context.Background(), &contact, passcode, 30, 2)
},
},
}

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
// given
tmq := testTransportHandler{
Type: fixtures.RequestType,
Path: tc.route,
Result: tc.responsePayload,
ClientURL: fixtures.ServerURL,
Client: WithHTTPClient,
}

client := getTestWalletClientWithOpts(tmq, WithXPriv(fixtures.XPrivString))

// when
err := tc.f(client)

// then
assert.NoError(t, err)
})
}

}

func TestConfirmContact(t *testing.T) {
t.Run("TOTP is valid - call Confirm Action", func(t *testing.T) {
// given
tmq := testTransportHandler{
Type: fixtures.RequestType,
Path: "/contact/confirmed/",
Result: "{}",
ClientURL: fixtures.ServerURL,
Client: WithHTTPClient,
}

client := getTestWalletClientWithOpts(tmq, WithXPriv(fixtures.XPrivString))

contact := &models.Contact{PubKey: fixtures.PubKey}
totp, err := client.GenerateTotpForContact(contact, 30, 2)
require.NoError(t, err)

// when
result := client.ConfirmContact(context.Background(), contact, totp, 30, 2)

// then
require.Nil(t, result)
})

t.Run("TOTP is invalid - do not call Confirm Action", func(t *testing.T) {
// given
tmq := testTransportHandler{
Type: fixtures.RequestType,
Path: "/unknown/",
Result: "{}",
ClientURL: fixtures.ServerURL,
Client: WithHTTPClient,
}

client := getTestWalletClientWithOpts(tmq, WithXPriv(fixtures.XPrivString))

alice := &models.Contact{PubKey: "034252e5359a1de3b8ec08e6c29b80594e88fb47e6ae9ce65ee5a94f0d371d2cde"}
a_totp, err := client.GenerateTotpForContact(alice, 30, 2)
require.NoError(t, err)

bob := &models.Contact{PubKey: "02dde493752f7bc89822ed8a13e0e4aa04550c6c4430800e4be1e5e5c2556cf65b"}

// when
result := client.ConfirmContact(context.Background(), bob, a_totp, 30, 2)

// then
require.NotNil(t, result)
require.Equal(t, result.Error(), "totp is invalid")
})
}
1 change: 1 addition & 0 deletions fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
XPrivString = "xprv9s21ZrQH143K3N6qVJQAu4EP51qMcyrKYJLkLgmYXgz58xmVxVLSsbx2DfJUtjcnXK8NdvkHMKfmmg5AJT2nqqRWUrjSHX29qEJwBgBPkJQ"
AccessKeyString = "7779d24ca6f8821f225042bf55e8f80aa41b08b879b72827f51e41e6523b9cd0"
PaymailAddress = "[email protected]"
PubKey = "034252e5359a1de3b8ec08e6c29b80594e88fb47e6ae9ce65ee5a94f0d371d2cde"
)

func MarshallForTestHandler(object any) string {
Expand Down
4 changes: 3 additions & 1 deletion go.mod

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

11 changes: 9 additions & 2 deletions go.sum

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

Loading

0 comments on commit 5dea8bc

Please sign in to comment.