Skip to content

Commit

Permalink
linter & better comments in coinbase.client.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
axotion committed Aug 5, 2023
1 parent 21bab12 commit 46075c5
Show file tree
Hide file tree
Showing 26 changed files with 448 additions and 431 deletions.
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Coinbase SDK

Coinbase SDK without external dependencies. Based purely on fetch API.
Coinbase SDK without external dependencies. Based purely on fetch API, this implementation ensures that the SDK remains lightweight and self-contained, without relying on any third-party libraries or modules for handling HTTP requests and other functionalities.

## Features
- [x] Typescript support
- [x] No external dependencies
- [x] Coinbase API v2 support (https://developers.coinbase.com/api/v2)
- [x] Notification verifier for webhooks
- [x] Notification verifier for webhooks/notifications
- [x] High test coverage
- [x] Easy of use and extendability
- [x] Easy of use

## Supported authentication methods

Expand All @@ -29,6 +29,14 @@ npm i coinbase-sdk

## Usage of Client

A new instance of CoinbaseClient is created using the ApiKeyRequestMaker constructor. The ApiKeyRequestMaker class is used to handle API key-based authentication with Coinbase. It requires two arguments: the apikey and apisecret. These values should be replaced with your actual Coinbase API key and API secret.

A new strategy called OAuth2RequestMaker is in **TBA** state. It will be used to handle OAuth2 authentication with Coinbase.

It may throw exceptions like
- **PayloadPreconditionFailedException** - when payload is not valid, e.g. missing required fields or some fields are required by other fields
- **RequestTimedoutException** - when request timed out, 30 seconds is a value set by coinbase
- **InvalidResponseException** - when response is not valid, e.g. status code is not 200 or response is not in JSON format. This exception also contains json response body (jsonResponse).
```typescript
import {CoinbaseClient, ApiKeyRequestMaker} from 'coinbase-sdk';

Expand All @@ -46,6 +54,15 @@ const response = await coinbaseClient.getAccounts({

## Usage of notification Verifier

The provided code demonstrates the usage of the NotificationVerifier class from the coinbase-sdk library. The NotificationVerifier is a utility class that allows you to verify the authenticity and integrity of incoming notifications from Coinbase.

**Return value**:

If the verification is successful, the verify method will complete normally without throwing any exceptions or errors.

If the verification fails, the verify method will throw an InvalidSignatureException. This exception indicates that the signature of the incoming notification is invalid, suggesting that the notification may not be from Coinbase or may have been tampered with.


```typescript
import { NotificationVerifier } from 'coinbase-sdk';

Expand All @@ -62,13 +79,13 @@ await notificationVerifier.verify(request)
- [x] accounts
- [x] addresses
- [x] buys
- [ ] deposits
- [ ] deposits - **In progress**
- [x] payment_methods
- [x] prices
- [ ] sells
- [ ] sells - In progress
- [x] transactions
- [ ] users
- [ ] withdrawals
- [ ] ~~users~~ - **Will not be supported**
- [ ] withdrawals - **In progress**
- [x] exchange_rates
- [x] time
- [x] currencies
Expand All @@ -82,7 +99,8 @@ npm run test

## License

[MIT](https://choosealicense.com/licenses/mit/)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

## Contact
kamilfronczak@pm.me

Loading

0 comments on commit 46075c5

Please sign in to comment.