@riocrypto/common-server 1.0.2182 → 1.0.2184
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/helpers/get-is-fireblocks-signature-valid.d.ts +2 -0
- package/build/helpers/get-is-fireblocks-signature-valid.js +31 -0
- package/build/index.d.ts +1 -2
- package/build/index.js +1 -2
- package/package.json +2 -2
- package/build/helpers/get-asset-price.d.ts +0 -3
- package/build/helpers/get-asset-price.js +0 -23
- package/build/helpers/get-exchange-rates.d.ts +0 -8
- package/build/helpers/get-exchange-rates.js +0 -85
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getIsFireblocksWebhookValid = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const publicKey = `-----BEGIN PUBLIC KEY-----
|
|
9
|
+
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0+6wd9OJQpK60ZI7qnZG
|
|
10
|
+
jjQ0wNFUHfRv85Tdyek8+ahlg1Ph8uhwl4N6DZw5LwLXhNjzAbQ8LGPxt36RUZl5
|
|
11
|
+
YlxTru0jZNKx5lslR+H4i936A4pKBjgiMmSkVwXD9HcfKHTp70GQ812+J0Fvti/v
|
|
12
|
+
4nrrUpc011Wo4F6omt1QcYsi4GTI5OsEbeKQ24BtUd6Z1Nm/EP7PfPxeb4CP8KOH
|
|
13
|
+
clM8K7OwBUfWrip8Ptljjz9BNOZUF94iyjJ/BIzGJjyCntho64ehpUYP8UJykLVd
|
|
14
|
+
CGcu7sVYWnknf1ZGLuqqZQt4qt7cUUhFGielssZP9N9x7wzaAIFcT3yQ+ELDu1SZ
|
|
15
|
+
dE4lZsf2uMyfj58V8GDOLLE233+LRsRbJ083x+e2mW5BdAGtGgQBusFfnmv5Bxqd
|
|
16
|
+
HgS55hsna5725/44tvxll261TgQvjGrTxwe7e5Ia3d2Syc+e89mXQaI/+cZnylNP
|
|
17
|
+
SwCCvx8mOM847T0XkVRX3ZrwXtHIA25uKsPJzUtksDnAowB91j7RJkjXxJcz3Vh1
|
|
18
|
+
4k182UFOTPRW9jzdWNSyWQGl/vpe9oQ4c2Ly15+/toBo4YXJeDdDnZ5c/O+KKadc
|
|
19
|
+
IMPBpnPrH/0O97uMPuED+nI6ISGOTMLZo35xJ96gPBwyG5s2QxIkKPXIrhgcgUnk
|
|
20
|
+
tSM7QYNhlftT4/yVvYnk0YcCAwEAAQ==
|
|
21
|
+
-----END PUBLIC KEY-----`.replace(/\\n/g, "\n");
|
|
22
|
+
const getIsFireblocksWebhookValid = (req) => {
|
|
23
|
+
const message = JSON.stringify(req.body);
|
|
24
|
+
const signature = req.headers["fireblocks-signature"];
|
|
25
|
+
const verifier = crypto_1.default.createVerify("RSA-SHA512");
|
|
26
|
+
verifier.write(message);
|
|
27
|
+
verifier.end();
|
|
28
|
+
const isVerified = verifier.verify(publicKey, signature, "base64");
|
|
29
|
+
return isVerified;
|
|
30
|
+
};
|
|
31
|
+
exports.getIsFireblocksWebhookValid = getIsFireblocksWebhookValid;
|
package/build/index.d.ts
CHANGED
|
@@ -101,16 +101,15 @@ export * from "./helpers/get-processor-fees";
|
|
|
101
101
|
export * from "./helpers/get-network-fees";
|
|
102
102
|
export * from "./helpers/calculate-aggregate-volume-and-revenue";
|
|
103
103
|
export * from "./helpers/calculate-volume-and-revenue";
|
|
104
|
-
export * from "./helpers/get-exchange-rates";
|
|
105
104
|
export * from "./helpers/get-user";
|
|
106
105
|
export * from "./helpers/unescape";
|
|
107
106
|
export * from "./helpers/get-user-transaction-limits";
|
|
108
107
|
export * from "./helpers/sanitize-user-doc";
|
|
109
108
|
export * from "./helpers/get-currency-api-exchange-rates";
|
|
110
109
|
export * from "./helpers/get-tax-rate";
|
|
111
|
-
export * from "./helpers/get-asset-price";
|
|
112
110
|
export * from "./helpers/generate-payment-reference";
|
|
113
111
|
export * from "./helpers/get-order-from-reference";
|
|
114
112
|
export * from "./helpers/send-with-xss-guard";
|
|
115
113
|
export * from "./helpers/generate-idempotency-key-from-mongo-id";
|
|
116
114
|
export * from "./helpers/generate-idempotency-key-from-order";
|
|
115
|
+
export * from "./helpers/get-is-fireblocks-signature-valid";
|
package/build/index.js
CHANGED
|
@@ -117,16 +117,15 @@ __exportStar(require("./helpers/get-processor-fees"), exports);
|
|
|
117
117
|
__exportStar(require("./helpers/get-network-fees"), exports);
|
|
118
118
|
__exportStar(require("./helpers/calculate-aggregate-volume-and-revenue"), exports);
|
|
119
119
|
__exportStar(require("./helpers/calculate-volume-and-revenue"), exports);
|
|
120
|
-
__exportStar(require("./helpers/get-exchange-rates"), exports);
|
|
121
120
|
__exportStar(require("./helpers/get-user"), exports);
|
|
122
121
|
__exportStar(require("./helpers/unescape"), exports);
|
|
123
122
|
__exportStar(require("./helpers/get-user-transaction-limits"), exports);
|
|
124
123
|
__exportStar(require("./helpers/sanitize-user-doc"), exports);
|
|
125
124
|
__exportStar(require("./helpers/get-currency-api-exchange-rates"), exports);
|
|
126
125
|
__exportStar(require("./helpers/get-tax-rate"), exports);
|
|
127
|
-
__exportStar(require("./helpers/get-asset-price"), exports);
|
|
128
126
|
__exportStar(require("./helpers/generate-payment-reference"), exports);
|
|
129
127
|
__exportStar(require("./helpers/get-order-from-reference"), exports);
|
|
130
128
|
__exportStar(require("./helpers/send-with-xss-guard"), exports);
|
|
131
129
|
__exportStar(require("./helpers/generate-idempotency-key-from-mongo-id"), exports);
|
|
132
130
|
__exportStar(require("./helpers/generate-idempotency-key-from-order"), exports);
|
|
131
|
+
__exportStar(require("./helpers/get-is-fireblocks-signature-valid"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2184",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@google-cloud/secret-manager": "^5.3.0",
|
|
29
29
|
"@google-cloud/storage": "^6.9.5",
|
|
30
30
|
"@hyperdx/node-opentelemetry": "^0.7.0",
|
|
31
|
-
"@riocrypto/common": "^1.0.
|
|
31
|
+
"@riocrypto/common": "^1.0.1926",
|
|
32
32
|
"@types/express": "^4.17.13",
|
|
33
33
|
"axios": "^1.7.4",
|
|
34
34
|
"crypto-js": "^4.2.0",
|
|
@@ -1,23 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getAssetPrice = void 0;
|
|
13
|
-
const market_data_1 = require("../models/market-data");
|
|
14
|
-
const getAssetPrice = (mongoose, crypto) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
-
const MarketData = (0, market_data_1.buildMarketData)(mongoose);
|
|
16
|
-
const marketData = yield MarketData.findOne();
|
|
17
|
-
if (!marketData) {
|
|
18
|
-
throw new Error("Market data not found");
|
|
19
|
-
}
|
|
20
|
-
const assetPriceInUSD = marketData.assetPricesInUSD[crypto].value;
|
|
21
|
-
return assetPriceInUSD;
|
|
22
|
-
});
|
|
23
|
-
exports.getAssetPrice = getAssetPrice;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Fiat, Side } from "@riocrypto/common";
|
|
2
|
-
import { Mongoose } from "mongoose";
|
|
3
|
-
export declare const getExchangeRates: (mongoose: Mongoose, fiat: Fiat, side: Side) => Promise<{
|
|
4
|
-
conversionRateToUSD: number;
|
|
5
|
-
conversionRateToUSDWithMarkups?: number | undefined;
|
|
6
|
-
conversionRateFromUSD: number;
|
|
7
|
-
conversionRateFromUSDWithMarkups?: number | undefined;
|
|
8
|
-
}>;
|
|
@@ -1,85 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getExchangeRates = void 0;
|
|
13
|
-
const common_1 = require("@riocrypto/common");
|
|
14
|
-
const rio_settings_1 = require("../models/rio-settings");
|
|
15
|
-
const market_data_1 = require("../models/market-data");
|
|
16
|
-
const getExchangeRates = (mongoose, fiat, side) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const RioSettings = (0, rio_settings_1.buildRioSettings)(mongoose);
|
|
18
|
-
const rioSettings = yield RioSettings.findOne();
|
|
19
|
-
if (!rioSettings) {
|
|
20
|
-
throw new Error("Rio settings not found");
|
|
21
|
-
}
|
|
22
|
-
const MarketData = (0, market_data_1.buildMarketData)(mongoose);
|
|
23
|
-
const marketData = yield MarketData.findOne();
|
|
24
|
-
if (!marketData) {
|
|
25
|
-
throw new Error("Market data not found");
|
|
26
|
-
}
|
|
27
|
-
const afterHoursExchangeRateMarkup = side === common_1.Side.Buy
|
|
28
|
-
? rioSettings.buyOrderAfterHoursExchangeRateMarkup
|
|
29
|
-
: rioSettings.sellOrderAfterHoursExchangeRateMarkup;
|
|
30
|
-
const generalExchangeRateMarkup = side === common_1.Side.Buy
|
|
31
|
-
? rioSettings.buyOrderGeneralExchangeRateMarkup
|
|
32
|
-
: rioSettings.sellOrderGeneralExchangeRateMarkup;
|
|
33
|
-
const conversionRateToUSD = marketData.conversionRatesToUSD[fiat].value;
|
|
34
|
-
let conversionRateFromUSD = marketData.conversionRatesFromUSD[fiat].value;
|
|
35
|
-
let conversionRateToUSDWithMarkups = conversionRateToUSD;
|
|
36
|
-
let conversionRateFromUSDWithMarkups = conversionRateFromUSD;
|
|
37
|
-
// Time based markups
|
|
38
|
-
if (fiat === common_1.Fiat.PEN) {
|
|
39
|
-
if (rioSettings.isAfterHours[common_1.Country.Peru].value) {
|
|
40
|
-
conversionRateToUSDWithMarkups =
|
|
41
|
-
conversionRateToUSDWithMarkups *
|
|
42
|
-
(1 -
|
|
43
|
-
afterHoursExchangeRateMarkup[common_1.Fiat.PEN] -
|
|
44
|
-
generalExchangeRateMarkup[common_1.Fiat.PEN]);
|
|
45
|
-
conversionRateFromUSDWithMarkups =
|
|
46
|
-
conversionRateFromUSDWithMarkups *
|
|
47
|
-
(1 -
|
|
48
|
-
afterHoursExchangeRateMarkup[common_1.Fiat.PEN] -
|
|
49
|
-
generalExchangeRateMarkup[common_1.Fiat.PEN]);
|
|
50
|
-
}
|
|
51
|
-
if (generalExchangeRateMarkup) {
|
|
52
|
-
conversionRateToUSDWithMarkups =
|
|
53
|
-
conversionRateToUSDWithMarkups *
|
|
54
|
-
(1 - generalExchangeRateMarkup[common_1.Fiat.PEN]);
|
|
55
|
-
conversionRateFromUSDWithMarkups =
|
|
56
|
-
conversionRateFromUSDWithMarkups *
|
|
57
|
-
(1 - generalExchangeRateMarkup[common_1.Fiat.PEN]);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (fiat === common_1.Fiat.MXN) {
|
|
61
|
-
if (rioSettings.isAfterHours[common_1.Country.Mexico].value) {
|
|
62
|
-
conversionRateToUSDWithMarkups =
|
|
63
|
-
conversionRateToUSDWithMarkups *
|
|
64
|
-
(1 - afterHoursExchangeRateMarkup[common_1.Fiat.MXN]);
|
|
65
|
-
conversionRateFromUSDWithMarkups =
|
|
66
|
-
conversionRateFromUSDWithMarkups *
|
|
67
|
-
(1 - afterHoursExchangeRateMarkup[common_1.Fiat.MXN]);
|
|
68
|
-
}
|
|
69
|
-
if (generalExchangeRateMarkup) {
|
|
70
|
-
conversionRateToUSDWithMarkups =
|
|
71
|
-
conversionRateToUSDWithMarkups *
|
|
72
|
-
(1 - generalExchangeRateMarkup[common_1.Fiat.MXN]);
|
|
73
|
-
conversionRateFromUSDWithMarkups =
|
|
74
|
-
conversionRateFromUSDWithMarkups *
|
|
75
|
-
(1 - generalExchangeRateMarkup[common_1.Fiat.MXN]);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
conversionRateToUSD,
|
|
80
|
-
conversionRateToUSDWithMarkups,
|
|
81
|
-
conversionRateFromUSD,
|
|
82
|
-
conversionRateFromUSDWithMarkups,
|
|
83
|
-
};
|
|
84
|
-
});
|
|
85
|
-
exports.getExchangeRates = getExchangeRates;
|