@riocrypto/common 1.0.487 → 1.0.488

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.
@@ -1,9 +1,16 @@
1
- import { Crypto } from "../types/crypto";
2
1
  declare class BitstampClient {
3
2
  private apiKey;
4
- private secret;
5
- constructor(apiKey: string, secret: string);
6
- getWithdrawFee(crypto: Crypto): number | null;
3
+ private apiSecret;
4
+ constructor(apiKey: string, apiSecret: string);
5
+ getHeaders(payload?: any): Promise<{
6
+ "X-Auth": string;
7
+ "X-Auth-Signature": string;
8
+ "X-Auth-Nonce": string;
9
+ "X-Auth-Timestamp": string;
10
+ "X-Auth-Version": string;
11
+ "Content-Type": string;
12
+ }>;
13
+ getTransactions(): Promise<any>;
7
14
  }
8
15
  export declare const bitstampClient: BitstampClient;
9
16
  export {};
@@ -1,44 +1,83 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
2
37
  Object.defineProperty(exports, "__esModule", { value: true });
3
38
  exports.bitstampClient = void 0;
4
- const crypto_1 = require("../types/crypto");
39
+ const axios_1 = __importDefault(require("axios"));
40
+ const crypto = __importStar(require("crypto"));
41
+ const uuid = __importStar(require("uuid"));
5
42
  class BitstampClient {
6
- constructor(apiKey, secret) {
43
+ constructor(apiKey, apiSecret) {
7
44
  this.apiKey = apiKey;
8
- this.secret = secret;
45
+ this.apiSecret = apiSecret;
46
+ }
47
+ getHeaders(payload) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const timestamp = String(Math.round(Date.now()));
50
+ const nonce = uuid.v4().toString();
51
+ const content_type = "application/x-www-form-urlencoded";
52
+ let payload_string = new URLSearchParams(payload).toString();
53
+ const message = `BITSTAMP ${this.apiKey}POSTwww.bitstamp.net/api/v2/crypto-transactions/${content_type}${nonce}${timestamp}v2${payload_string}`;
54
+ const message_encoded = new TextEncoder().encode(message);
55
+ const signature = crypto
56
+ .createHmac("sha256", this.apiSecret)
57
+ .update(message_encoded)
58
+ .digest("hex");
59
+ const headers = {
60
+ "X-Auth": `BITSTAMP ${this.apiKey}`,
61
+ "X-Auth-Signature": signature,
62
+ "X-Auth-Nonce": nonce,
63
+ "X-Auth-Timestamp": timestamp,
64
+ "X-Auth-Version": "v2",
65
+ "Content-Type": content_type,
66
+ };
67
+ return headers;
68
+ });
9
69
  }
10
- getWithdrawFee(crypto) {
11
- if (crypto === crypto_1.Crypto.BTC) {
12
- return 0.0005;
13
- }
14
- else if (crypto === crypto_1.Crypto.ETH) {
15
- return 0.006;
16
- }
17
- else if (crypto === crypto_1.Crypto.USDC) {
18
- return 20;
19
- }
20
- else {
21
- return null;
22
- }
70
+ getTransactions() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const payload = { offset: "0" };
73
+ let payload_string = new URLSearchParams(payload).toString();
74
+ const headers = yield this.getHeaders(payload);
75
+ const response = yield axios_1.default.post("https://www.bitstamp.net/api/v2/crypto-transactions/", payload_string, { headers });
76
+ if (response.status !== 200) {
77
+ throw new Error("Status code not 200");
78
+ }
79
+ return response.data;
80
+ });
23
81
  }
24
82
  }
25
- // private getHeaders(data: string, url: string, path: string, method: string) {
26
- // const nonce = uuidv4();
27
- // const timestamp = Date.now();
28
- // let message = `${
29
- // this.apiKey
30
- // }${method}${url}${path}${""}${""}${nonce}${timestamp}${"v2"}${data}`;
31
- // const headers = {
32
- // "X-Auth": "BITSTAMP " + this.apiKey,
33
- // "X-Auth-Signature": crypto
34
- // .createHmac("sha256", this.secret)
35
- // .update(message)
36
- // .digest("hex"),
37
- // "X-Auth-Nonce": nonce,
38
- // "X-Auth-Timestamp": timestamp,
39
- // "X-Auth-Version": "v2",
40
- // };
41
- // return headers;
42
- // }
43
- // }
44
83
  exports.bitstampClient = new BitstampClient(process.env.BITSTAMP_API_KEY, process.env.BITSTAMP_SECRET);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.487",
3
+ "version": "1.0.488",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",