generated from mrz1836/go-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
568 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ on: | |
push: | ||
branches: | ||
- master | ||
- main | ||
paths: | ||
- .github/labels.yml | ||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ const ( | |
XPrivString = "xprv9s21ZrQH143K3N6qVJQAu4EP51qMcyrKYJLkLgmYXgz58xmVxVLSsbx2DfJUtjcnXK8NdvkHMKfmmg5AJT2nqqRWUrjSHX29qEJwBgBPkJQ" | ||
AccessKeyString = "7779d24ca6f8821f225042bf55e8f80aa41b08b879b72827f51e41e6523b9cd0" | ||
PaymailAddress = "[email protected]" | ||
PubKey = "034252e5359a1de3b8ec08e6c29b80594e88fb47e6ae9ce65ee5a94f0d371d2cde" | ||
) | ||
|
||
func MarshallForTestHandler(object any) string { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.