gamemoney 3.0.0 → 4.1.1

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/package.json CHANGED
@@ -1,17 +1,10 @@
1
1
  {
2
2
  "name": "gamemoney",
3
- "version": "3.0.0",
3
+ "version": "4.1.1",
4
4
  "description": "GameMoney API wrapper for Node.js",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "scripts": {
8
- "prepublish": "npm run lint && npm run test && npm run build",
9
- "lint": "tslint 'src/**/*.ts' -t codeFrame",
10
- "test": "mocha -r ts-node/register src/**/*.spec.ts",
11
- "build": "tsc"
12
- },
13
5
  "keywords": [
14
6
  "gamemoney",
7
+ "gmpays",
15
8
  "gm",
16
9
  "merchant"
17
10
  ],
@@ -23,26 +16,70 @@
23
16
  "author": {
24
17
  "name": "Maxim Makarov",
25
18
  "email": "maxpain177@gmail.com",
26
- "url": "http://maxpain.pro"
19
+ "url": "https://maxpain.pro"
27
20
  },
28
21
  "license": "MIT",
29
22
  "repository": {
30
23
  "type": "git",
31
24
  "url": "https://github.com/gamemoney-ps/gamemoney-node-sdk"
32
25
  },
26
+ "type": "module",
27
+ "exports": {
28
+ ".": {
29
+ "import": "./index.js",
30
+ "types": "./index.d.ts"
31
+ }
32
+ },
33
+ "scripts": {
34
+ "prebuild": "rm -rf .build",
35
+ "build": "tsc",
36
+ "postbuild": "cp -r package*.json .npmignore ./src/certs README.md .build",
37
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
38
+ "lint": "xo",
39
+ "lint:fix": "xo --fix"
40
+ },
41
+ "lint-staged": {
42
+ "*.ts": "xo"
43
+ },
44
+ "jest": {
45
+ "testMatch": [
46
+ "**/*.test.ts"
47
+ ],
48
+ "preset": "ts-jest/presets/default-esm",
49
+ "globals": {
50
+ "ts-jest": {
51
+ "useESM": true
52
+ }
53
+ },
54
+ "moduleNameMapper": {
55
+ "^(\\.{1,2}/.*)\\.js$": "$1"
56
+ },
57
+ "maxConcurrency": 50
58
+ },
59
+ "xo": {
60
+ "extends": "@onmoon",
61
+ "prettier": true
62
+ },
63
+ "prettier": "@onmoon/prettier-config",
33
64
  "devDependencies": {
34
- "@types/chai": "^4.2.7",
35
- "@types/mocha": "^5.2.7",
36
- "@types/node": "^13.5.0",
37
- "@types/request-promise-native": "^1.0.17",
38
- "chai": "^4.2.0",
39
- "mocha": "^7.0.0",
40
- "ts-node": "^8.6.2",
41
- "tslint": "^6.0.0",
42
- "typescript": "^3.7.5"
65
+ "@onmoon/eslint-config": "^1.0.11",
66
+ "@onmoon/prettier-config": "^1.0.2",
67
+ "@onmoon/tsconfigs": "^2.0.0",
68
+ "@types/body-parser": "^1.19.2",
69
+ "@types/express": "^4.17.13",
70
+ "@types/jest": "^27.4.0",
71
+ "@types/node": "^17.0.18",
72
+ "@types/uuid": "^8.3.4",
73
+ "body-parser": "^1.19.2",
74
+ "express": "^4.17.3",
75
+ "husky": "^7.0.4",
76
+ "lint-staged": "^12.3.4",
77
+ "ts-jest": "^27.1.3",
78
+ "typescript": "^4.5.5",
79
+ "uuid": "^8.3.2",
80
+ "xo": "^0.48.0"
43
81
  },
44
82
  "dependencies": {
45
- "request": "^2.88.0",
46
- "request-promise-native": "^1.0.8"
83
+ "got": "^12.0.1"
47
84
  }
48
- }
85
+ }
package/utils.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ import crypto from 'node:crypto';
3
+ export declare type RsaKey = Parameters<crypto.Sign['sign']>[0];
4
+ export declare type HmacKey = Parameters<typeof crypto.createHmac>[1];
5
+ declare type JsonPrimitive = number | number[] | string | string[] | undefined | null;
6
+ declare type Json = {
7
+ [key: string]: Json | JsonPrimitive;
8
+ };
9
+ interface Body extends Json {
10
+ signature: string;
11
+ }
12
+ export declare function parametersToString(body: Json): string;
13
+ export declare function verifyRsaSignature(body: Body): boolean;
14
+ export declare function generateRsaSignature(body: Json, key: RsaKey): string;
15
+ export declare function generateHmacSignature(body: Json, key: HmacKey): string;
16
+ export declare function getRandomString(length: number): string;
17
+ export {};
package/utils.js ADDED
@@ -0,0 +1,51 @@
1
+ import { URL } from 'node:url';
2
+ import crypto from 'node:crypto';
3
+ import fs from 'node:fs';
4
+ const publicCert = fs
5
+ .readFileSync(new URL('certs/gm.crt', import.meta.url))
6
+ .toString();
7
+ export function parametersToString(body) {
8
+ let parametersString = '';
9
+ const keys = Object.keys(body).sort();
10
+ if (Array.isArray(body)) {
11
+ keys.sort((a, b) => Number(a) - Number(b));
12
+ }
13
+ for (const key of keys) {
14
+ let value = body[key];
15
+ if (key === 'signature') {
16
+ continue;
17
+ }
18
+ if (value === null || value === undefined) {
19
+ value = '';
20
+ }
21
+ if (typeof value === 'object' && value !== null) {
22
+ value = parametersToString(value);
23
+ }
24
+ parametersString += `${key}:${value};`;
25
+ }
26
+ return parametersString;
27
+ }
28
+ export function verifyRsaSignature(body) {
29
+ return crypto
30
+ .createVerify('RSA-SHA256')
31
+ .update(parametersToString(body), 'utf8')
32
+ .verify(publicCert, body.signature, 'base64');
33
+ }
34
+ export function generateRsaSignature(body, key) {
35
+ return crypto
36
+ .createSign('RSA-SHA256')
37
+ .update(parametersToString(body), 'utf8')
38
+ .sign(key, 'base64');
39
+ }
40
+ export function generateHmacSignature(body, key) {
41
+ return crypto
42
+ .createHmac('sha256', key)
43
+ .update(parametersToString(body), 'utf8')
44
+ .digest('hex');
45
+ }
46
+ export function getRandomString(length) {
47
+ return crypto
48
+ .randomBytes(Math.ceil(length / 2))
49
+ .toString('hex')
50
+ .slice(0, length);
51
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Maxim Makarov
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/index.d.ts DELETED
@@ -1,257 +0,0 @@
1
- /// <reference types="node" />
2
- import { TSignType, IResponse } from './request';
3
- import { SignPrivateKeyInput } from 'crypto';
4
- export interface IConfig {
5
- privateKey?: SignPrivateKeyInput;
6
- hmacKey: string;
7
- project: number;
8
- }
9
- export interface ICreateInvoiceRequest {
10
- type: string;
11
- user: number;
12
- ip: string;
13
- amount: number;
14
- comment: string;
15
- success_url?: string;
16
- fail_url?: string;
17
- wallet: string;
18
- project_invoice?: number | string;
19
- currency?: string;
20
- user_currency?: string;
21
- language?: string;
22
- [index: string]: any;
23
- }
24
- export interface ICreateInvoiceResponse extends IResponse {
25
- invoice: number;
26
- type: 'message' | 'redirect' | 'error';
27
- data: string;
28
- }
29
- export interface IGetInvoiceStatusRequestWithProjectInvoiceID {
30
- invoice: number;
31
- }
32
- export interface IGetInvoiceStatusRequestWithGamemoneyInvoiceID {
33
- project_invoice: string;
34
- }
35
- export declare type IGetInvoiceStatusRequest = IGetInvoiceStatusRequestWithProjectInvoiceID | IGetInvoiceStatusRequestWithGamemoneyInvoiceID;
36
- export interface IGetInvoiceStatusResponse extends IResponse {
37
- project: string;
38
- invoice: string;
39
- status: string;
40
- amount: string;
41
- net_amount: string;
42
- recieved_amount: string;
43
- user: string;
44
- type: string;
45
- wallet: string;
46
- project_invoice: string;
47
- currency_project: string;
48
- currency_user: string;
49
- date_create: string;
50
- date_pay: string;
51
- rate: string;
52
- }
53
- export interface IGetInvoiceListRequest {
54
- start: string;
55
- finish: string;
56
- [index: string]: any;
57
- }
58
- export interface IGetInvoiceListResponse extends IResponse {
59
- list: IGetInvoiceStatusResponse[];
60
- is_limit_exceeded: 'yes' | 'no';
61
- }
62
- export interface ICancelCheckoutRequest {
63
- projectId: number | string;
64
- [index: string]: any;
65
- }
66
- export interface IGetCheckoutStatusRequest {
67
- projectId: number | string;
68
- [index: string]: any;
69
- }
70
- export interface IRefund {
71
- id: string;
72
- amount: string;
73
- net_amount: string;
74
- paid_amount: string;
75
- comment: string;
76
- }
77
- export interface IGetCheckoutStatusResponse extends IResponse {
78
- id: string;
79
- project: string;
80
- projectId: string;
81
- amount: number;
82
- net_amount: number;
83
- paid_amount: number;
84
- status: string;
85
- user: string;
86
- wallet: string;
87
- description: string;
88
- comment: string;
89
- redirect_url: string;
90
- type: string;
91
- currency_project: string;
92
- currency_user: string;
93
- date_create: string;
94
- rate: string;
95
- refunds: IRefund[];
96
- }
97
- export interface IGetCheckoutListRequest {
98
- start: string;
99
- finish: string;
100
- [index: string]: any;
101
- }
102
- export interface IGetCheckoutListResponse extends IResponse {
103
- list: IGetCheckoutStatusResponse[];
104
- }
105
- export interface ICreateCheckoutRequest {
106
- projectId: number | string;
107
- user: number;
108
- ip: string;
109
- amount: number | string;
110
- wallet: string;
111
- description: string;
112
- type: string;
113
- currency?: string;
114
- userCurrency?: string;
115
- [index: string]: any;
116
- }
117
- export interface IAddCardRequest {
118
- user: number;
119
- redirect: string;
120
- [index: string]: any;
121
- }
122
- export interface IAddCardResponse extends IResponse {
123
- url: string;
124
- }
125
- export interface IGetCardListRequest {
126
- user: number;
127
- [index: string]: any;
128
- }
129
- export interface IGetCardListResponse extends IResponse {
130
- pans: string[];
131
- }
132
- export interface IDeleteCardRequest {
133
- user: number;
134
- pan: string;
135
- [index: string]: any;
136
- }
137
- export interface IPrepareExchangeRequest {
138
- minAmount: number;
139
- maxAmount: number;
140
- from: string;
141
- to: string;
142
- livetime?: number;
143
- [index: string]: any;
144
- }
145
- export interface IPrepareExchangeResponse extends IResponse {
146
- id: string;
147
- rate: string;
148
- exchanged_amount_from: string;
149
- exchanged_amount_to: string;
150
- }
151
- export interface IConvertExchangeRequest {
152
- id: number;
153
- amount: number;
154
- [index: string]: any;
155
- }
156
- export interface IFastConvertExchangeRequest {
157
- amount: number;
158
- from: string;
159
- to: string;
160
- [index: string]: any;
161
- }
162
- export interface IFastConvertExchangeResponse extends IResponse {
163
- id: string;
164
- rate: string;
165
- }
166
- export interface IGetExchangeInfoRequest {
167
- minAmount: number;
168
- maxAmount: number;
169
- from: string;
170
- to: string;
171
- livetime?: number;
172
- }
173
- export interface IGetExchangeInfoResponse extends IResponse {
174
- rate: string;
175
- exchanged_amount_from: string;
176
- exchanged_amount_to: string;
177
- }
178
- export interface IGetExchangeStatusRequest {
179
- id?: number;
180
- externalId?: string;
181
- }
182
- export interface IGetExchangeStatusResponse extends IResponse {
183
- id: string;
184
- from: string;
185
- to: string;
186
- rate: string;
187
- amount_from: string;
188
- amount_to: string;
189
- status: string;
190
- }
191
- export interface IGetBalanceStatisticsRequest {
192
- currency: string;
193
- [index: string]: any;
194
- }
195
- export interface IGetBalanceStatisticsResponse extends IResponse {
196
- project: string;
197
- currency: string;
198
- project_income: string;
199
- project_outcome: string;
200
- project_balance: string;
201
- contract_income: string;
202
- contract_outcome: string;
203
- contract_balance: string;
204
- }
205
- export interface IGetDaysBalanceStatisticsRequest {
206
- currency: string;
207
- start: string;
208
- finish: string;
209
- [index: string]: any;
210
- }
211
- export interface IDaysBalance {
212
- date: string;
213
- income: string;
214
- outcome: string;
215
- }
216
- export interface IGetDaysBalanceStatisticsResponse extends IResponse {
217
- project: string;
218
- currency: string;
219
- days_balance: IDaysBalance[];
220
- }
221
- export interface IPaySystem {
222
- type: string;
223
- fee: string;
224
- fixed_fee: string;
225
- currency: string;
226
- }
227
- export interface IGetPayTypesStatisticsResponse extends IResponse {
228
- project: string;
229
- invoice: IPaySystem[];
230
- checkout: IPaySystem[];
231
- }
232
- export declare class GameMoney {
233
- request: any;
234
- private config;
235
- constructor(config: IConfig);
236
- send(url: string, body?: any, signType?: TSignType): Promise<any>;
237
- generateHmacSignature(body: any): string;
238
- createInvoice(body: ICreateInvoiceRequest): Promise<ICreateInvoiceResponse>;
239
- getInvoiceStatus(body: IGetInvoiceStatusRequest): Promise<IGetInvoiceStatusResponse>;
240
- getInvoiceList(body: IGetInvoiceListRequest): Promise<IGetInvoiceListResponse>;
241
- createCheckout(body: ICreateCheckoutRequest): Promise<IResponse>;
242
- cancelCheckout(body: ICancelCheckoutRequest): Promise<IResponse>;
243
- getCheckoutStatus(body: IGetCheckoutStatusRequest): Promise<IGetCheckoutStatusResponse>;
244
- getCheckoutList(body: IGetCheckoutListRequest): Promise<IGetCheckoutListResponse>;
245
- addCard(body: IAddCardRequest): Promise<IAddCardResponse>;
246
- getCardList(body: IGetCardListRequest): Promise<IGetCardListResponse>;
247
- deleteCard(body: IDeleteCardRequest): Promise<IResponse>;
248
- prepareExchange(body: IPrepareExchangeRequest): Promise<IPrepareExchangeResponse>;
249
- convertExchange(body: IConvertExchangeRequest): Promise<IResponse>;
250
- fastConvertExchange(body: IFastConvertExchangeRequest): Promise<IFastConvertExchangeResponse>;
251
- getExchangeInfo(body: IGetExchangeInfoRequest): Promise<IGetExchangeInfoResponse>;
252
- getExchangeStatus(body: IGetExchangeStatusRequest): Promise<IGetExchangeStatusResponse>;
253
- getBalanceStatistics(body: IGetBalanceStatisticsRequest): Promise<IGetBalanceStatisticsResponse>;
254
- getDaysBalanceStatistics(body: IGetDaysBalanceStatisticsRequest): Promise<IGetDaysBalanceStatisticsResponse>;
255
- getPayTypesStatistics(): Promise<IGetPayTypesStatisticsResponse>;
256
- }
257
- export { verifyRsaSignature } from './utils';
package/dist/index.js DELETED
@@ -1,82 +0,0 @@
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
- const request_1 = __importDefault(require("./request"));
7
- const utils_1 = require("./utils");
8
- class GameMoney {
9
- constructor(config) {
10
- this.config = config;
11
- const { hmacKey, privateKey } = config;
12
- this.request = new request_1.default(hmacKey, privateKey);
13
- }
14
- send(url, body = {}, signType = 'hmac') {
15
- body.project = this.config.project;
16
- if (signType === 'rsa' && !this.config.privateKey) {
17
- throw new Error('To make requests with signType: \'rsa\', privateKey must be specified');
18
- }
19
- return this.request.send(url, body, signType);
20
- }
21
- generateHmacSignature(body) {
22
- return utils_1.generateHmacSignature(body, this.config.hmacKey);
23
- }
24
- createInvoice(body) {
25
- return this.send('/invoice/', body);
26
- }
27
- getInvoiceStatus(body) {
28
- return this.send('/invoice/status', body);
29
- }
30
- getInvoiceList(body) {
31
- return this.send('/invoice/list', body);
32
- }
33
- createCheckout(body) {
34
- return this.send('/checkout/insert', body, 'rsa');
35
- }
36
- cancelCheckout(body) {
37
- return this.send('/checkout/cancel', body);
38
- }
39
- getCheckoutStatus(body) {
40
- return this.send('/checkout/status', body);
41
- }
42
- getCheckoutList(body) {
43
- return this.send('/checkout/list', body);
44
- }
45
- addCard(body) {
46
- return this.send('/card/add', body);
47
- }
48
- getCardList(body) {
49
- return this.send('/card/list', body);
50
- }
51
- deleteCard(body) {
52
- return this.send('/card/delete', body);
53
- }
54
- prepareExchange(body) {
55
- return this.send('/exchange/prepare', body);
56
- }
57
- convertExchange(body) {
58
- return this.send('/exchange/convert', body);
59
- }
60
- fastConvertExchange(body) {
61
- return this.send('/exchange/fastconvert', body);
62
- }
63
- getExchangeInfo(body) {
64
- return this.send('/exchange/info', body);
65
- }
66
- getExchangeStatus(body) {
67
- return this.send('/exchange/status', body);
68
- }
69
- getBalanceStatistics(body) {
70
- return this.send('/statistics/balance', body);
71
- }
72
- getDaysBalanceStatistics(body) {
73
- return this.send('/statistics/days_balance_project', body);
74
- }
75
- getPayTypesStatistics() {
76
- return this.send('/statistics/paytypes');
77
- }
78
- }
79
- exports.GameMoney = GameMoney;
80
- var utils_2 = require("./utils");
81
- exports.verifyRsaSignature = utils_2.verifyRsaSignature;
82
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,wDAAyD;AAEzD,mCAA+C;AA2Q/C,MAAa,SAAS;IAIrB,YAAY,MAAe;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;QAEtC,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IAChD,CAAC;IAEM,IAAI,CAAC,GAAW,EAAE,OAAY,EAAE,EAAE,WAAsB,MAAM;QACpE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAA;QAElC,IAAI,QAAQ,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YAClD,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAA;SACxF;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;IAC9C,CAAC;IAEM,qBAAqB,CAAC,IAAS;QACrC,OAAO,6BAAqB,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACxD,CAAC;IAGM,aAAa,CAAC,IAA2B;QAC/C,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;IACpC,CAAC;IAGM,gBAAgB,CAAC,IAA8B;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AAI,CAAC,CAAA;IAChD,CAAC;IAGM,eAAe,CAAC,IAA6B;QACnD,OAAO,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAA;IACzC,CAAC;IAGM,iBAAiB,CAAC,IAA+B;QACvD,OAAO,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAA;IAC3C,CAAC;IAGM,oBAAoB,CAAC,IAAkC;QAC7D,OAAO,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAA;IAC9C,CAAC;IAGM,wBAAwB,CAAC,IAAsC;QACrE,OAAO,IAAI,CAAC,IAAI,CAAC,kCAAkC,EAAE,IAAI,CAAC,CAAA;IAC3D,CAAC;IAGM,qBAAqB;QAC3B,OAAO,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;IACzC,CAAC;CACD;AAnHD,8BAmHC;AAED,iCAA4C;AAAnC,qCAAA,kBAAkB,CAAA"}
package/dist/request.d.ts DELETED
@@ -1,18 +0,0 @@
1
- /// <reference types="node" />
2
- import { SignPrivateKeyInput } from 'crypto';
3
- export declare type TSignType = 'hmac' | 'rsa';
4
- export interface IResponse {
5
- state: 'success' | 'error';
6
- time: number;
7
- error?: string;
8
- rand: string;
9
- signature: string;
10
- }
11
- export default class GameMoneyRequest {
12
- private static readonly uri;
13
- private request;
14
- private hmacKey;
15
- private privateKey;
16
- constructor(hmacKey: string, privateKey?: SignPrivateKeyInput);
17
- send(url: string, body: any, signType?: TSignType): Promise<IResponse>;
18
- }
package/dist/request.js DELETED
@@ -1,53 +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
- const request_promise_native_1 = __importDefault(require("request-promise-native"));
16
- const utils_1 = require("./utils");
17
- class GameMoneyRequest {
18
- constructor(hmacKey, privateKey) {
19
- this.hmacKey = hmacKey;
20
- this.privateKey = privateKey;
21
- this.request = request_promise_native_1.default.defaults({
22
- baseUrl: GameMoneyRequest.uri,
23
- json: true
24
- });
25
- }
26
- send(url, body, signType = 'hmac') {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- if (!body.rand) {
29
- body.rand = utils_1.getRandomString(20);
30
- }
31
- const signature = signType === 'hmac'
32
- ? utils_1.generateHmacSignature(body, this.hmacKey)
33
- : utils_1.generateRsaSignature(body, this.privateKey);
34
- const response = yield this.request.post({
35
- url,
36
- form: Object.assign(Object.assign({}, body), { signature })
37
- });
38
- if (!utils_1.verifyRsaSignature(response)) {
39
- throw new Error('Response signature mismatch');
40
- }
41
- if (body.rand && body.rand !== response.rand) {
42
- throw new Error(`Wrong rand parameter: ${response.rand}`);
43
- }
44
- if (response.state === 'error') {
45
- throw new Error(response.error);
46
- }
47
- return response;
48
- });
49
- }
50
- }
51
- exports.default = GameMoneyRequest;
52
- GameMoneyRequest.uri = 'https://paygate.gamemoney.com';
53
- //# sourceMappingURL=request.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request.js","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,oFAA4C;AAE5C,mCAKgB;AAYhB,MAAqB,gBAAgB;IAMpC,YAAY,OAAe,EAAE,UAAgC;QAC5D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,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
3
- interface IBody {
4
- signature: string;
5
- }
6
- export declare function paramsToString(body: IBody): string;
7
- export declare function verifyRsaSignature(body: IBody): boolean;
8
- export declare function generateRsaSignature(body: IBody, privateKey: SignPrivateKeyInput): string;
9
- export declare function generateHmacSignature(body: IBody, key: string): string;
10
- export declare function getRandomString(length: number): string;
11
- export {};