Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(SPV-1087): add new version of the client with documentation. #311

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0d94f7c
refactor(SPV-1087): Remove old project structure. (#2)
mgosek-4chain Oct 23, 2024
fa1d4d6
refactor(SPV-1087): Paste authentication, utils files content from t…
mgosek-4chain Oct 24, 2024
5c649a1
ci(SPV-1138): add separated linter files and fix warnings. (#4)
dorzepowski Oct 28, 2024
fd131af
refactor(SPV-1087): add configurations API implementation, spv client…
mgosek-4chain Nov 4, 2024
6e7159d
refactor(SPV-1087): add user transactions api implementation. (#7)
mgosek-4chain Nov 13, 2024
6e5fd7b
refactor(SPV-1192): add page filter query builder implementation. (#14)
mgosek-4chain Nov 14, 2024
6efd9e6
refactor(SPV-1192): replace query params by page filter. (#15)
mgosek-4chain Nov 14, 2024
4d3962d
refactor(SPV-1174): add user contacts, invitation api implementation…
mgosek-4chain Nov 18, 2024
3acdd4c
refactor(SPV-1184): add users information + user access key api imple…
mgosek-4chain Nov 18, 2024
2da8fae
refactor(SPV-1206): add user utxos API implementation. (#16)
mgosek-4chain Nov 18, 2024
4d0325a
refactor(SPV-1183): add user merkleroots api implementation (#11)
mgosek-4chain Nov 18, 2024
dbceb5c
refactor(SPV-1209): fix url path building in user APIs. (#17)
mgosek-4chain Nov 19, 2024
b823c1f
Feat/spv-1207/migrate totp operations logic from old spv wallet go cl…
ac4ch Nov 21, 2024
cdf95b0
refactoring(SPV-1208) Migrate_Merkel_Roots_Sync_operations_logic_from…
ac4ch Nov 27, 2024
1eb35b5
refactor(SPV-1213): Admin API access with user xpubs implementation.…
mgosek-4chain Nov 27, 2024
f34a5ed
refactor(SPV-1173): add example pkg, taskfile, keys generator, readme…
mgosek-4chain Nov 27, 2024
f89e3d8
Ref(SPV-1216) Fix unit tests status codes (#24)
ac4ch Dec 2, 2024
d055443
Refactor(SPV-1217) Remove_TransportWrapper_and_Verify_OnAfterResponse…
ac4ch Dec 2, 2024
83cb51d
refactor(SPV-1230): admin endpoints group - Contacts API. (#23)
mgosek-4chain Dec 4, 2024
948960b
refactor(SPV-1232): admin endpoints group - Transactions API. (#29)
mgosek-4chain Dec 5, 2024
ef2f7a1
refactor(SPV-1233): admin endpoints group - Access Keys API (#30)
mgosek-4chain Dec 5, 2024
ba729fb
refactor(SPV-1234): admin endpoints group - Webhooks API. (#32)
mgosek-4chain Dec 6, 2024
cb16fb6
Feat(SPV-1162) Fix authenticators initialization (#33)
ac4ch Dec 6, 2024
1dd5458
feat(SPV-1241): migrate FinalizeTransaction and SendToRecipients (#27)
dzolt-4chain Dec 6, 2024
7e183e1
refactor(SPV-1231): admin endpoints group - Paymails API. (#28)
mgosek-4chain Dec 6, 2024
dd1f0c2
refactor(SPV-1235): admin endpoints group - UTXOs API. (#34)
mgosek-4chain Dec 7, 2024
8eaaf1c
refactor(SPV-12374): admin endpoints group - Stats API. (#35)
mgosek-4chain Dec 7, 2024
1e8db9e
refactor(SPV-1238): admin endpoints group - Status API. (#36)
mgosek-4chain Dec 7, 2024
75a9281
Feat(SPV-1163)Fix configuration workflow (#38)
ac4ch Dec 9, 2024
6f39d9a
refactor(SPV-1264): user endpoints - Paymails API. (#40)
mgosek-4chain Dec 9, 2024
285311f
fix(SPV-1283): use proper upsertcontact command field for a path par…
wregulski Dec 10, 2024
ddd8076
fix(SPV-1264): paymail query filter usage in admin, user APIs. (#42)
mgosek-4chain Dec 11, 2024
c2f733f
Refact(SPV-1274) http mock responders usage (#43)
ac4ch Dec 11, 2024
2026d93
feat(SPV-1258): add admin endpoint for confirm contacts (#39)
dzolt-4chain Dec 12, 2024
0d8c7ca
refactor(SPV-1289): standardize building and processing search querie…
mgosek-4chain Dec 17, 2024
2f37c16
feat(SPV-1214): admin contact filter (#46)
jakubmkowalski Dec 19, 2024
60a612d
refactor(SPV-1278): add regression tests implementation. (#37)
mgosek-4chain Dec 23, 2024
04c03bb
feat(SPV-1317): admin endpoints - Contacts API, add missing contact c…
mgosek-4chain Dec 23, 2024
dc73034
refactor(SPV-1301): standardize building and processing search querie…
mgosek-4chain Dec 31, 2024
fc7736c
feat(SPV-1344): add shared config API implementation to admin API. (#49)
mgosek-4chain Dec 31, 2024
2c00c3d
refactor(SPV-1275): revise and update examples. (#50)
mgosek-4chain Jan 7, 2025
943094d
refactoring(SPV-1338)StandardizeHTTP_formatters (#52)
ac4ch Jan 7, 2025
30ffde5
refactor(SPV-1351): add notifications package from previous version o…
mgosek-4chain Jan 7, 2025
32893b4
Merge remote-tracking branch 'upstream/main' into refactor/SPV-1087-a…
mgosek-4chain Jan 7, 2025
590e108
refactor(SPV-1087): update go mod, go sum.
mgosek-4chain Jan 7, 2025
ae0be49
refactor(SPV-1087): restore deleted sections.
mgosek-4chain Jan 7, 2025
28af727
refactor(SPV-1087): restore mergify.
mgosek-4chain Jan 7, 2025
812572f
refactor(SPV-1087): revert to the state from the go v2 fork.
mgosek-4chain Jan 7, 2025
275bccb
Merge branch 'main' into refactor/SPV-1087-add-new-version-of-the-client
dorzepowski Jan 8, 2025
c2094b7
Merge branch 'main' into refactor/SPV-1087-add-new-version-of-the-client
dorzepowski Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(SPV-1213): Admin API access with user xpubs implementation. (#…
  • Loading branch information
mgosek-4chain authored Nov 27, 2024
commit 1eb35b59201aea82b7092208a2eca698cd7f844e
1 change: 1 addition & 0 deletions .golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ linters-settings:
wrapcheck:
ignoreSigRegexps:
- spverrors\.(Newf|Wrapf)
- errutil\.HTTPErrorFormatter
ignorePackageGlobs:
- "github.com/go-ozzo/ozzo-validation"
revive:
Expand Down
110 changes: 110 additions & 0 deletions admin_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package spvwallet

import (
"context"
"fmt"
"net/url"

bip32 "github.com/bitcoin-sv/go-sdk/compat/bip32"
"github.com/bitcoin-sv/spv-wallet-go-client/commands"
"github.com/bitcoin-sv/spv-wallet-go-client/config"
xpubs "github.com/bitcoin-sv/spv-wallet-go-client/internal/api/v1/admin/users"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/auth"
"github.com/bitcoin-sv/spv-wallet-go-client/internal/restyutil"
"github.com/bitcoin-sv/spv-wallet-go-client/queries"
"github.com/bitcoin-sv/spv-wallet/models/response"
)

// AdminAPI provides a simplified interface for interacting with admin-related APIs.
// It abstracts the complexities of making HTTP requests and handling responses,
// allowing developers to easily interact with admin API endpoints.
//
// A zero-value AdminAPI is not usable. Use the NewAdminAPI function to create
// a properly initialized instance.
//
// Methods may return wrapped errors, including models.SPVError or
// ErrUnrecognizedAPIResponse, depending on the behavior of the SPV Wallet API.
type AdminAPI struct {
xpubsAPI *xpubs.API // Internal API for managing operations related to XPubs.
}

// CreateXPub creates a new XPub record via the Admin XPubs API.
// The provided command contains the necessary parameters to define the XPub record.
//
// The API response is unmarshaled into a *response.Xpub struct.
// Returns an error if the API request fails or the response cannot be decoded.
func (a *AdminAPI) CreateXPub(ctx context.Context, cmd *commands.CreateUserXpub) (*response.Xpub, error) {
res, err := a.xpubsAPI.CreateXPub(ctx, cmd)
if err != nil {
return nil, xpubs.HTTPErrorFormatter("failed to create XPub", err).FormatPostErr()
}

return res, nil
}

// XPubs retrieves a paginated list of user XPubs via the Admin XPubs API.
// The response includes user XPubs along with pagination metadata, such as
// the current page number, sort order, and the field used for sorting (sortBy).
//
// Query parameters can be configured using optional query options. These options allow
// filtering based on metadata, pagination settings, or specific XPub attributes.
//
// The API response is unmarshaled into a *queries.XPubPage struct.
// Returns an error if the API request fails or the response cannot be decoded.
func (a *AdminAPI) XPubs(ctx context.Context, opts ...queries.XPubQueryOption) (*queries.XPubPage, error) {
res, err := a.xpubsAPI.XPubs(ctx, opts...)
if err != nil {
return nil, xpubs.HTTPErrorFormatter("failed to retrieve XPubs page", err).FormatGetErr()
}

return res, nil
}

// NewAdminAPIWithXPriv initializes a new AdminAPI instance using an extended private key (xPriv).
// This function configures the API client with the provided configuration and uses the xPriv key for authentication.
// If any step fails, an appropriate error is returned.
//
// Note: Requests made with this instance will be securely signed.
func NewAdminAPIWithXPriv(cfg config.Config, xPriv string) (*AdminAPI, error) {
key, err := bip32.GenerateHDKeyFromString(xPriv)
if err != nil {
return nil, fmt.Errorf("failed to generate HD key from xPriv: %w", err)
}

authenticator, err := auth.NewXprivAuthenticator(key)
if err != nil {
return nil, fmt.Errorf("failed to initialize xPriv authenticator: %w", err)
}

return initAdminAPI(cfg, authenticator)
}

// NewAdminWithXPub initializes a new AdminAPI instance using an extended public key (xPub).
// This function configures the API client with the provided configuration and uses the xPub key for authentication.
// If any configuration or initialization step fails, an appropriate error is returned.
//
// Note: Requests made with this instance will not be signed.
// For enhanced security, it is strongly recommended to use `NewAdminAPIWithXPriv` instead.
func NewAdminWithXPub(cfg config.Config, xPub string) (*AdminAPI, error) {
key, err := bip32.GetHDKeyFromExtendedPublicKey(xPub)
if err != nil {
return nil, fmt.Errorf("failed to generate HD key from xPub: %w", err)
}

authenticator, err := auth.NewXpubOnlyAuthenticator(key)
if err != nil {
return nil, fmt.Errorf("failed to initialize xPub authenticator: %w", err)
}

return initAdminAPI(cfg, authenticator)
}

func initAdminAPI(cfg config.Config, auth authenticator) (*AdminAPI, error) {
url, err := url.Parse(cfg.Addr)
if err != nil {
return nil, fmt.Errorf("failed to parse addr to url.URL: %w", err)
}

httpClient := restyutil.NewHTTPClient(cfg, auth)
return &AdminAPI{xpubsAPI: xpubs.NewAPI(url, httpClient)}, nil
}
Loading