@riocrypto/common-server 1.0.1650 → 1.0.1652

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts CHANGED
@@ -80,7 +80,6 @@ export * from "./clients/bitso-client";
80
80
  export * from "./clients/circle-client";
81
81
  export * from "./clients/polygon-client";
82
82
  export * from "./clients/coincover-client";
83
- export * from "./clients/coinbase-client";
84
83
  export * from "./clients/fogbender-client";
85
84
  export * from "./clients/brex-client";
86
85
  export * from "./helpers/get-user-helper";
package/build/index.js CHANGED
@@ -96,7 +96,6 @@ __exportStar(require("./clients/bitso-client"), exports);
96
96
  __exportStar(require("./clients/circle-client"), exports);
97
97
  __exportStar(require("./clients/polygon-client"), exports);
98
98
  __exportStar(require("./clients/coincover-client"), exports);
99
- __exportStar(require("./clients/coinbase-client"), exports);
100
99
  __exportStar(require("./clients/fogbender-client"), exports);
101
100
  __exportStar(require("./clients/brex-client"), exports);
102
101
  __exportStar(require("./helpers/get-user-helper"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1650",
3
+ "version": "1.0.1652",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -1,11 +0,0 @@
1
- import { Crypto } from "@riocrypto/common";
2
- declare class CoinbaseClient {
3
- private apiKey;
4
- private baseUrl;
5
- private productIdMappings;
6
- constructor(apiKey: string, env?: "production" | "sandbox");
7
- private getRequestHeaders;
8
- createMarketOrder(crypto: Crypto, amount: number): Promise<any>;
9
- }
10
- export declare const buildCoinbaseClient: () => Promise<CoinbaseClient>;
11
- export {};
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.buildCoinbaseClient = void 0;
16
- const secret_manager_client_1 = require("./secret-manager-client");
17
- const axios_1 = __importDefault(require("axios"));
18
- const common_1 = require("@riocrypto/common");
19
- const crypto_1 = require("crypto");
20
- class CoinbaseClient {
21
- constructor(apiKey, env) {
22
- this.apiKey = apiKey;
23
- if (env) {
24
- this.baseUrl =
25
- env === "production"
26
- ? "https://api.exchange.coinbase.com"
27
- : "https://api-public.sandbox.exchange.coinbase.com";
28
- }
29
- else {
30
- if ([common_1.RioEnv.Development, common_1.RioEnv.Production, common_1.RioEnv.Staging].includes(process.env.RIO_ENV)) {
31
- this.baseUrl = "https://api.exchange.coinbase.com";
32
- }
33
- else {
34
- this.baseUrl = "https://api-public.sandbox.exchange.coinbase.com";
35
- }
36
- }
37
- this.productIdMappings = {
38
- [common_1.Crypto.USDTEthereum]: "USDT-USD",
39
- };
40
- }
41
- getRequestHeaders(requestPath, body, method) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- // create the json request object
44
- const cb_access_timestamp = Date.now() / 1000;
45
- const cb_access_passphrase = yield secret_manager_client_1.secretManagerClient.getSecretValue("COINBASE_API_PASSPHRASE");
46
- if (!cb_access_passphrase) {
47
- throw new common_1.SecretManagerError();
48
- }
49
- const secret = yield secret_manager_client_1.secretManagerClient.getSecretValue("COINBASE_API_SECRET");
50
- if (!secret) {
51
- throw new common_1.SecretManagerError();
52
- }
53
- // create the prehash string by concatenating required parts
54
- const message = cb_access_timestamp + method + requestPath + body;
55
- // decode the base64 secret
56
- const key = Buffer.from(secret, "base64");
57
- // create a sha256 hmac with the secret
58
- const hmac = (0, crypto_1.createHmac)("sha256", key);
59
- // sign the require message with the hmac and base64 encode the result
60
- const cb_access_sign = hmac.update(message).digest("base64");
61
- return {
62
- "CB-ACCESS-KEY": this.apiKey,
63
- "CB-ACCESS-SIGN": cb_access_sign,
64
- "CB-ACCESS-TIMESTAMP": cb_access_timestamp,
65
- "CB-ACCESS-PASSPHRASE": cb_access_passphrase,
66
- };
67
- });
68
- }
69
- createMarketOrder(crypto, amount) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const requestPath = "/orders";
72
- const body = JSON.stringify({
73
- type: "market",
74
- funds: amount,
75
- side: "buy",
76
- product_id: this.productIdMappings[crypto],
77
- });
78
- const headers = yield this.getRequestHeaders(requestPath, body, "POST");
79
- const { data } = yield axios_1.default.post(`${this.baseUrl}${requestPath}`, body, {
80
- headers,
81
- });
82
- return data;
83
- });
84
- }
85
- }
86
- const buildCoinbaseClient = () => __awaiter(void 0, void 0, void 0, function* () {
87
- // Retrieve secrets asynchronously
88
- const COINBASE_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("COINBASE_API_KEY");
89
- if (!COINBASE_API_KEY) {
90
- throw new common_1.SecretManagerError();
91
- }
92
- // Create GuenoClient instance and return
93
- return new CoinbaseClient(COINBASE_API_KEY);
94
- });
95
- exports.buildCoinbaseClient = buildCoinbaseClient;