GithubHelp home page GithubHelp logo

axotion / coinbase-sdk Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 114 KB

Coinbase SDK without external dependencies. Based on fetch API.

JavaScript 1.10% TypeScript 98.90%
coinbase coinbase-api nodejs typescript

coinbase-sdk's Introduction

Coinbase SDK

Coinbase Sign-in SDK (https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/welcome) 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

  • Typescript support
  • No external dependencies
  • Coinbase API v2 support (https://developers.coinbase.com/api/v2)
  • Notification verifier for webhooks/notifications
  • High test coverage
  • Easy of use

Supported authentication methods

  • API key
  • OAuth2

Requirements

Installation

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).
import {CoinbaseClient, ApiKeyRequestMaker} from 'coinbase-sdk';

const coinbaseClient = new CoinbaseClient(
    new ApiKeyRequestMaker(
        'apikey', 'apisecret'
    )
);

const response = await coinbaseClient.getAccounts({
    limit: 10,
    order: 'asc'
})

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.

import { NotificationVerifier } from 'coinbase-sdk';

const notificationVerifier = new NotificationVerifier();

// Will throw InvalidSignatureException if signature is invalid
await notificationVerifier.verify(jsonBody, cbSignatureHeader)

Supported client methods

  • accounts
  • addresses
  • buys
  • deposits - In progress
  • payment_methods
  • prices
  • sells - In progress
  • transactions
  • users - In progress
  • withdrawals - In progress
  • exchange_rates
  • time
  • currencies
  • prices

How to run tests

npm run test

License

The MIT License (MIT). Please see License File for more information.

Contact

[email protected]

coinbase-sdk's People

Contributors

axotion avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

bjrothman

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.