paytonz-node-api-sdk 1.0.0
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/README.md +743 -0
- package/lib/CpaySDK.d.ts +30 -0
- package/lib/CpaySDK.js +35 -0
- package/lib/CpaySDKBase.d.ts +30 -0
- package/lib/CpaySDKBase.js +216 -0
- package/lib/CryptoNowSDK.d.ts +30 -0
- package/lib/CryptoNowSDK.js +35 -0
- package/lib/CryptoNowSDKBase.d.ts +30 -0
- package/lib/CryptoNowSDKBase.js +216 -0
- package/lib/PaytonzSDK.d.ts +28 -0
- package/lib/PaytonzSDK.js +33 -0
- package/lib/PaytonzSDKBase.d.ts +30 -0
- package/lib/PaytonzSDKBase.js +198 -0
- package/lib/auth/auth.d.ts +9 -0
- package/lib/auth/auth.interface.d.ts +25 -0
- package/lib/auth/auth.interface.js +2 -0
- package/lib/auth/auth.js +37 -0
- package/lib/checkout/checkout.d.ts +24 -0
- package/lib/checkout/checkout.interface.d.ts +94 -0
- package/lib/checkout/checkout.interface.js +2 -0
- package/lib/checkout/checkout.js +215 -0
- package/lib/client/client.d.ts +11 -0
- package/lib/client/client.interface.d.ts +45 -0
- package/lib/client/client.interface.js +2 -0
- package/lib/client/client.js +62 -0
- package/lib/constant.d.ts +1 -0
- package/lib/constant.js +4 -0
- package/lib/currency/currency.d.ts +10 -0
- package/lib/currency/currency.interface.d.ts +20 -0
- package/lib/currency/currency.interface.js +2 -0
- package/lib/currency/currency.js +50 -0
- package/lib/external/external.d.ts +13 -0
- package/lib/external/external.interface.d.ts +59 -0
- package/lib/external/external.interface.js +12 -0
- package/lib/external/external.js +64 -0
- package/lib/external/external.solana.d.ts +9 -0
- package/lib/external/external.solana.js +47 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +28 -0
- package/lib/interfaces/cpay.interface.d.ts +20 -0
- package/lib/interfaces/cpay.interface.js +2 -0
- package/lib/interfaces/cryptonow.interface.d.ts +20 -0
- package/lib/interfaces/cryptonow.interface.js +2 -0
- package/lib/interfaces/paytonz.interface.d.ts +20 -0
- package/lib/interfaces/paytonz.interface.js +2 -0
- package/lib/multisend/multisend.d.ts +11 -0
- package/lib/multisend/multisend.interface.d.ts +28 -0
- package/lib/multisend/multisend.interface.js +2 -0
- package/lib/multisend/multisend.js +75 -0
- package/lib/swap/swap.d.ts +11 -0
- package/lib/swap/swap.interface.d.ts +84 -0
- package/lib/swap/swap.interface.js +2 -0
- package/lib/swap/swap.js +75 -0
- package/lib/transaction/transaction.d.ts +9 -0
- package/lib/transaction/transaction.interface.d.ts +82 -0
- package/lib/transaction/transaction.interface.js +2 -0
- package/lib/transaction/transaction.js +34 -0
- package/lib/utils/httpClient.d.ts +9 -0
- package/lib/utils/httpClient.js +64 -0
- package/lib/wallet/wallet.d.ts +16 -0
- package/lib/wallet/wallet.interface.d.ts +60 -0
- package/lib/wallet/wallet.interface.js +2 -0
- package/lib/wallet/wallet.js +107 -0
- package/lib/wallet/wallet.signature.d.ts +14 -0
- package/lib/wallet/wallet.signature.js +104 -0
- package/lib/withdrawal/withdrawal.d.ts +14 -0
- package/lib/withdrawal/withdrawal.interface.d.ts +79 -0
- package/lib/withdrawal/withdrawal.interface.js +14 -0
- package/lib/withdrawal/withdrawal.js +104 -0
- package/package.json +26 -0
- package/src/PaytonzSDK.ts +41 -0
- package/src/PaytonzSDKBase.ts +252 -0
- package/src/auth/auth.interface.ts +26 -0
- package/src/auth/auth.ts +31 -0
- package/src/checkout/checkout.interface.ts +110 -0
- package/src/checkout/checkout.ts +279 -0
- package/src/constant.ts +1 -0
- package/src/currency/currency.interface.ts +21 -0
- package/src/currency/currency.ts +60 -0
- package/src/external/external.interface.ts +65 -0
- package/src/external/external.solana.ts +54 -0
- package/src/external/external.ts +73 -0
- package/src/index.ts +5 -0
- package/src/interfaces/paytonz.interface.ts +23 -0
- package/src/multisend/multisend.interface.ts +32 -0
- package/src/multisend/multisend.ts +91 -0
- package/src/swap/swap.interface.ts +90 -0
- package/src/swap/swap.ts +93 -0
- package/src/transaction/transaction.interface.ts +76 -0
- package/src/transaction/transaction.ts +35 -0
- package/src/utils/httpClient.ts +60 -0
- package/src/wallet/wallet.interface.ts +67 -0
- package/src/wallet/wallet.signature.ts +106 -0
- package/src/wallet/wallet.ts +103 -0
- package/src/withdrawal/withdrawal.interface.ts +89 -0
- package/src/withdrawal/withdrawal.ts +135 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AccessWalletOptions } from "src/interfaces/paytonz.interface";
|
|
2
|
+
|
|
3
|
+
interface MultisendFileOptions {
|
|
4
|
+
address: string;
|
|
5
|
+
amount: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface EstimateSystemFeeOptions {
|
|
9
|
+
currencyToken: string;
|
|
10
|
+
multisendWallets: MultisendFileOptions[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface EstimateMultisendInfo {
|
|
14
|
+
estimationId: string;
|
|
15
|
+
countTxs: number;
|
|
16
|
+
systemFee: string;
|
|
17
|
+
minerFee: string;
|
|
18
|
+
totalAmount: string;
|
|
19
|
+
allowance: string;
|
|
20
|
+
currencyFee: string;
|
|
21
|
+
needApprove: boolean;
|
|
22
|
+
multisendWallets: MultisendFileOptions[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface EstimateMultisendCommonOptions extends AccessWalletOptions {
|
|
26
|
+
estimationId: string;
|
|
27
|
+
idempotencyKey?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MultisendInfo {
|
|
31
|
+
ids: string[];
|
|
32
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { PaytonzSDKBase, PaytonzSDKBaseOptions } from "../PaytonzSDKBase";
|
|
2
|
+
import {
|
|
3
|
+
EstimateMultisendCommonOptions,
|
|
4
|
+
EstimateMultisendInfo,
|
|
5
|
+
EstimateSystemFeeOptions,
|
|
6
|
+
MultisendInfo,
|
|
7
|
+
} from "./multisend.interface";
|
|
8
|
+
|
|
9
|
+
export interface PaytonzSDKOptions extends PaytonzSDKBaseOptions {}
|
|
10
|
+
|
|
11
|
+
export class Multisend extends PaytonzSDKBase {
|
|
12
|
+
constructor(parameters: PaytonzSDKOptions) {
|
|
13
|
+
super(parameters);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async estimateSystemFee(
|
|
17
|
+
options: EstimateSystemFeeOptions,
|
|
18
|
+
accessToken?: string
|
|
19
|
+
): Promise<EstimateMultisendInfo> {
|
|
20
|
+
try {
|
|
21
|
+
if (!accessToken) {
|
|
22
|
+
accessToken = await this.getToken(true);
|
|
23
|
+
}
|
|
24
|
+
const path = `/api/public/multisend/estimateSystemFee`;
|
|
25
|
+
|
|
26
|
+
return this.auth_post<EstimateMultisendInfo>(
|
|
27
|
+
`${path}`,
|
|
28
|
+
options,
|
|
29
|
+
accessToken
|
|
30
|
+
);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async approve(
|
|
37
|
+
options: EstimateMultisendCommonOptions,
|
|
38
|
+
accessToken?: string
|
|
39
|
+
): Promise<EstimateMultisendInfo> {
|
|
40
|
+
try {
|
|
41
|
+
if (!accessToken) {
|
|
42
|
+
accessToken = await this.getToken(true);
|
|
43
|
+
}
|
|
44
|
+
const path = `/api/public/multisend/approve`;
|
|
45
|
+
|
|
46
|
+
return this.auth_post<EstimateMultisendInfo>(
|
|
47
|
+
`${path}`,
|
|
48
|
+
options,
|
|
49
|
+
accessToken
|
|
50
|
+
);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async estimateMinerFee(
|
|
57
|
+
options: EstimateMultisendCommonOptions,
|
|
58
|
+
accessToken?: string
|
|
59
|
+
): Promise<EstimateMultisendInfo> {
|
|
60
|
+
try {
|
|
61
|
+
if (!accessToken) {
|
|
62
|
+
accessToken = await this.getToken(true);
|
|
63
|
+
}
|
|
64
|
+
const path = `/api/public/multisend/estimateMinerFee`;
|
|
65
|
+
|
|
66
|
+
return this.auth_post<EstimateMultisendInfo>(
|
|
67
|
+
`${path}`,
|
|
68
|
+
options,
|
|
69
|
+
accessToken
|
|
70
|
+
);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async create(
|
|
77
|
+
options: EstimateMultisendCommonOptions,
|
|
78
|
+
accessToken?: string
|
|
79
|
+
): Promise<MultisendInfo> {
|
|
80
|
+
try {
|
|
81
|
+
if (!accessToken) {
|
|
82
|
+
accessToken = await this.getToken(true);
|
|
83
|
+
}
|
|
84
|
+
const path = `/api/public/multisend`;
|
|
85
|
+
|
|
86
|
+
return this.auth_post<MultisendInfo>(`${path}`, options, accessToken);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { AccessWalletOptions } from "src/interfaces/paytonz.interface";
|
|
2
|
+
|
|
3
|
+
export interface SwapEstimateOptions {
|
|
4
|
+
fromId: string;
|
|
5
|
+
toId: string;
|
|
6
|
+
amount: string;
|
|
7
|
+
sort?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SwapCreateOptions extends AccessWalletOptions {
|
|
12
|
+
currencyFromId: string;
|
|
13
|
+
toId: string;
|
|
14
|
+
currencyToId: string;
|
|
15
|
+
amount: number;
|
|
16
|
+
partner: string;
|
|
17
|
+
fixed: boolean;
|
|
18
|
+
rateId: string;
|
|
19
|
+
idempotencyKey?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SwapEstimateInfo {
|
|
23
|
+
id: string;
|
|
24
|
+
supportRate: number;
|
|
25
|
+
duration: string;
|
|
26
|
+
min: number;
|
|
27
|
+
max: number;
|
|
28
|
+
fixed: boolean;
|
|
29
|
+
partner: string;
|
|
30
|
+
exists: boolean;
|
|
31
|
+
fromAmount: number;
|
|
32
|
+
fromCurrency: string;
|
|
33
|
+
fromNetwork: string;
|
|
34
|
+
toAmount: number;
|
|
35
|
+
toCurrency: string;
|
|
36
|
+
toNetwork: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SwapCreateInfo {
|
|
40
|
+
id: string;
|
|
41
|
+
exchangeId: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SwapHistoryListOptions {
|
|
45
|
+
currencyFromId?: string;
|
|
46
|
+
currencyToId?: string;
|
|
47
|
+
search?: string;
|
|
48
|
+
sort?: string;
|
|
49
|
+
order?: string;
|
|
50
|
+
page?: number;
|
|
51
|
+
limit?: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface SwapWalletInfo {
|
|
55
|
+
id: string;
|
|
56
|
+
address: string;
|
|
57
|
+
amount: {
|
|
58
|
+
value: number;
|
|
59
|
+
usd: number;
|
|
60
|
+
};
|
|
61
|
+
currency: {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
paymentId: string;
|
|
66
|
+
hash: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface SwapHistoryInfo {
|
|
70
|
+
page: number;
|
|
71
|
+
pages: number;
|
|
72
|
+
countItems: number;
|
|
73
|
+
entities: {
|
|
74
|
+
_id: string;
|
|
75
|
+
exchangeId: string;
|
|
76
|
+
partner: string;
|
|
77
|
+
fixed: boolean;
|
|
78
|
+
typeNetwork: string;
|
|
79
|
+
status: boolean;
|
|
80
|
+
systemStatus: string;
|
|
81
|
+
convertRate: number;
|
|
82
|
+
from: SwapWalletInfo;
|
|
83
|
+
to: SwapWalletInfo;
|
|
84
|
+
merchant: string;
|
|
85
|
+
user: string;
|
|
86
|
+
rateId: string;
|
|
87
|
+
createdAt: Date;
|
|
88
|
+
updatedAt: Date;
|
|
89
|
+
}[];
|
|
90
|
+
}
|
package/src/swap/swap.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { PaytonzSDKBase, PaytonzSDKBaseOptions } from "../PaytonzSDKBase";
|
|
2
|
+
import {
|
|
3
|
+
SwapCreateInfo,
|
|
4
|
+
SwapCreateOptions,
|
|
5
|
+
SwapEstimateInfo,
|
|
6
|
+
SwapEstimateOptions,
|
|
7
|
+
SwapHistoryInfo,
|
|
8
|
+
SwapHistoryListOptions,
|
|
9
|
+
} from "./swap.interface";
|
|
10
|
+
|
|
11
|
+
export interface PaytonzSDKOptions extends PaytonzSDKBaseOptions {}
|
|
12
|
+
|
|
13
|
+
export class Swap extends PaytonzSDKBase {
|
|
14
|
+
constructor(parameters: PaytonzSDKOptions) {
|
|
15
|
+
super(parameters);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async estimate(
|
|
19
|
+
options: SwapEstimateOptions,
|
|
20
|
+
accessToken?: string
|
|
21
|
+
): Promise<SwapEstimateInfo[]> {
|
|
22
|
+
try {
|
|
23
|
+
if (!accessToken) {
|
|
24
|
+
accessToken = await this.getToken(true);
|
|
25
|
+
}
|
|
26
|
+
const path = `/api/public/swap/estimate`;
|
|
27
|
+
|
|
28
|
+
return this.auth_get<SwapEstimateInfo[]>(
|
|
29
|
+
`${path}`,
|
|
30
|
+
{ ...options },
|
|
31
|
+
accessToken
|
|
32
|
+
);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async bestOffer(
|
|
39
|
+
options: SwapEstimateOptions,
|
|
40
|
+
accessToken?: string
|
|
41
|
+
): Promise<SwapEstimateInfo> {
|
|
42
|
+
try {
|
|
43
|
+
if (!accessToken) {
|
|
44
|
+
accessToken = await this.getToken(true);
|
|
45
|
+
}
|
|
46
|
+
const path = `/api/public/swap/best-offer`;
|
|
47
|
+
|
|
48
|
+
return this.auth_get<SwapEstimateInfo>(
|
|
49
|
+
`${path}`,
|
|
50
|
+
{ ...options },
|
|
51
|
+
accessToken
|
|
52
|
+
);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async create(
|
|
59
|
+
options: SwapCreateOptions,
|
|
60
|
+
accessToken?: string
|
|
61
|
+
): Promise<SwapCreateInfo> {
|
|
62
|
+
try {
|
|
63
|
+
if (!accessToken) {
|
|
64
|
+
accessToken = await this.getToken(true);
|
|
65
|
+
}
|
|
66
|
+
const path = `/api/public/swap/create`;
|
|
67
|
+
|
|
68
|
+
return this.auth_post<SwapCreateInfo>(`${path}`, options, accessToken);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async history(
|
|
75
|
+
options: SwapHistoryListOptions,
|
|
76
|
+
accessToken?: string
|
|
77
|
+
): Promise<SwapHistoryInfo> {
|
|
78
|
+
try {
|
|
79
|
+
if (!accessToken) {
|
|
80
|
+
accessToken = await this.getToken(true);
|
|
81
|
+
}
|
|
82
|
+
const path = `/api/public/swap/history`;
|
|
83
|
+
|
|
84
|
+
return this.auth_get<SwapHistoryInfo>(
|
|
85
|
+
`${path}`,
|
|
86
|
+
{ ...options },
|
|
87
|
+
accessToken
|
|
88
|
+
);
|
|
89
|
+
} catch (err) {
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export interface TransactionListOptions {
|
|
2
|
+
search?: string;
|
|
3
|
+
from?: number;
|
|
4
|
+
to?: number;
|
|
5
|
+
currencyId?: string;
|
|
6
|
+
fromUSD?: number;
|
|
7
|
+
toUSD?: number;
|
|
8
|
+
type?: string;
|
|
9
|
+
status?: string;
|
|
10
|
+
sort?: string;
|
|
11
|
+
order?: string;
|
|
12
|
+
page?: number;
|
|
13
|
+
limit?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TransactionListInfo {
|
|
17
|
+
page: number;
|
|
18
|
+
pages: number;
|
|
19
|
+
countItem: number;
|
|
20
|
+
entities: {
|
|
21
|
+
id: string;
|
|
22
|
+
type: string;
|
|
23
|
+
typeNetwork: string;
|
|
24
|
+
status: boolean;
|
|
25
|
+
systemStatus: string;
|
|
26
|
+
merchant: string;
|
|
27
|
+
user: string;
|
|
28
|
+
checkout?: {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
identifier: string;
|
|
33
|
+
charge: {
|
|
34
|
+
id: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
info: {
|
|
38
|
+
incomingTxHash: string;
|
|
39
|
+
currencyId: string;
|
|
40
|
+
currency: string;
|
|
41
|
+
nodeType: string;
|
|
42
|
+
currencyType: string;
|
|
43
|
+
exchangeId: number;
|
|
44
|
+
from: string;
|
|
45
|
+
to: string;
|
|
46
|
+
fromId: string;
|
|
47
|
+
toId: string;
|
|
48
|
+
hashs: [string];
|
|
49
|
+
addresses: [string];
|
|
50
|
+
multisend: {
|
|
51
|
+
address: string;
|
|
52
|
+
value: string;
|
|
53
|
+
usd: string;
|
|
54
|
+
}[];
|
|
55
|
+
amount: { value: string; usd: number };
|
|
56
|
+
minerFee: { value: string; usd: number; currency: string };
|
|
57
|
+
systemFee?: {
|
|
58
|
+
value: string;
|
|
59
|
+
usd: number;
|
|
60
|
+
currency: string;
|
|
61
|
+
hash: string;
|
|
62
|
+
};
|
|
63
|
+
call?: {
|
|
64
|
+
contractAddress: string;
|
|
65
|
+
method: string;
|
|
66
|
+
options: Record<string, any>;
|
|
67
|
+
arguments: any[];
|
|
68
|
+
value: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
fees?: Record<string, any>;
|
|
72
|
+
errorMessage?: string;
|
|
73
|
+
createdAt: Date;
|
|
74
|
+
updatedAt?: Date;
|
|
75
|
+
}[];
|
|
76
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PaytonzSDKBase, PaytonzSDKBaseOptions } from "../PaytonzSDKBase";
|
|
2
|
+
import {
|
|
3
|
+
TransactionListInfo,
|
|
4
|
+
TransactionListOptions,
|
|
5
|
+
} from "./transaction.interface";
|
|
6
|
+
|
|
7
|
+
export interface PaytonzSDKOptions extends PaytonzSDKBaseOptions {}
|
|
8
|
+
|
|
9
|
+
export class Transaction extends PaytonzSDKBase {
|
|
10
|
+
constructor(parameters: PaytonzSDKOptions) {
|
|
11
|
+
super(parameters);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async list(
|
|
15
|
+
options: TransactionListOptions,
|
|
16
|
+
accessToken?: string
|
|
17
|
+
): Promise<TransactionListInfo> {
|
|
18
|
+
try {
|
|
19
|
+
if (!accessToken) {
|
|
20
|
+
accessToken = await this.getToken(true);
|
|
21
|
+
}
|
|
22
|
+
const path = `/api/public/transaction/list`;
|
|
23
|
+
|
|
24
|
+
return this.auth_get<TransactionListInfo>(
|
|
25
|
+
`${path}`,
|
|
26
|
+
{ ...options },
|
|
27
|
+
accessToken
|
|
28
|
+
);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default Transaction;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import http from "http";
|
|
2
|
+
import https from "https";
|
|
3
|
+
import got, { Headers, Method } from "got";
|
|
4
|
+
import { default as URLOptions } from "got/dist/source/core/utils/url-to-options";
|
|
5
|
+
|
|
6
|
+
export interface Options {
|
|
7
|
+
timeout?: number;
|
|
8
|
+
headers?: Headers;
|
|
9
|
+
method?: Method;
|
|
10
|
+
json?: Record<string, any>;
|
|
11
|
+
searchParams?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const DEFAULT_HEADER = {
|
|
15
|
+
"content-type": "application/json;charset=utf-8",
|
|
16
|
+
};
|
|
17
|
+
const keepAliveAgent = new http.Agent({ keepAlive: true, maxSockets: 256 });
|
|
18
|
+
const keepAliveAgent2 = new https.Agent({ keepAlive: true, maxSockets: 256 });
|
|
19
|
+
|
|
20
|
+
export const request = async function <T>(url, options: Options = {}) {
|
|
21
|
+
const instance = got.extend({
|
|
22
|
+
request: (url, options, callback) => {
|
|
23
|
+
if (url.protocol === "https:") {
|
|
24
|
+
return https.request({ ...options, ...URLOptions(url) }, callback);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return http.request({ ...options, ...URLOptions(url) }, callback);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const response = await instance<T>(url, {
|
|
33
|
+
method: options.method,
|
|
34
|
+
timeout: options.timeout || 6000,
|
|
35
|
+
headers: options.headers || DEFAULT_HEADER,
|
|
36
|
+
agent: {
|
|
37
|
+
http: keepAliveAgent,
|
|
38
|
+
https: keepAliveAgent2,
|
|
39
|
+
},
|
|
40
|
+
json: options.json,
|
|
41
|
+
searchParams: options.searchParams,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
45
|
+
return response.body;
|
|
46
|
+
}
|
|
47
|
+
if (response.statusMessage) {
|
|
48
|
+
throw Error(response.statusMessage);
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
const parseError = JSON.parse(
|
|
52
|
+
err?.response?.body || '{"message":"Unknown error"}'
|
|
53
|
+
);
|
|
54
|
+
if (parseError && parseError.data && parseError.data.message) {
|
|
55
|
+
throw Error(parseError.data.message);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
throw Error(err.message);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
interface WalletTokensData {
|
|
2
|
+
currencyId: string;
|
|
3
|
+
currencyName: string;
|
|
4
|
+
balance: string;
|
|
5
|
+
holdBalance: string;
|
|
6
|
+
balanceUSD: string;
|
|
7
|
+
availableBalance: string;
|
|
8
|
+
availableBalanceUSD: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface NftItem {
|
|
12
|
+
contractAddress: string;
|
|
13
|
+
tokenId: number;
|
|
14
|
+
balance: number;
|
|
15
|
+
holdBalance: number;
|
|
16
|
+
name: string;
|
|
17
|
+
symbol: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface NftData {
|
|
21
|
+
erc721: NftItem[];
|
|
22
|
+
erc1155: NftItem[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface WalletInfo {
|
|
26
|
+
id: string;
|
|
27
|
+
address: string;
|
|
28
|
+
currencyId: string;
|
|
29
|
+
balance: string;
|
|
30
|
+
balanceUSD: string;
|
|
31
|
+
holdBalance: string;
|
|
32
|
+
availableBalance: string;
|
|
33
|
+
availableBalanceUSD: string;
|
|
34
|
+
tokens?: WalletTokensData[];
|
|
35
|
+
nfts?: NftData;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface CreateWalletOptions {
|
|
39
|
+
currencyId: string;
|
|
40
|
+
typeWallet?: string;
|
|
41
|
+
privateKey?: string;
|
|
42
|
+
isMnemonic?: boolean;
|
|
43
|
+
password?: string;
|
|
44
|
+
setMain?: boolean;
|
|
45
|
+
isNew?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface CreateWalletInfo {
|
|
49
|
+
id: string;
|
|
50
|
+
address: string;
|
|
51
|
+
balance: number;
|
|
52
|
+
balanceUSD: number;
|
|
53
|
+
passphrase: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SignatureCommonOptions {
|
|
57
|
+
password?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface SignatureOnOptions extends SignatureCommonOptions {
|
|
61
|
+
sign: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface SignatureChangePasswordOptions {
|
|
65
|
+
oldPassword?: string;
|
|
66
|
+
password: string;
|
|
67
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { PaytonzSDKBase, PaytonzSDKBaseOptions } from "../PaytonzSDKBase";
|
|
2
|
+
import {
|
|
3
|
+
SignatureChangePasswordOptions,
|
|
4
|
+
SignatureCommonOptions,
|
|
5
|
+
SignatureOnOptions,
|
|
6
|
+
} from "./wallet.interface";
|
|
7
|
+
|
|
8
|
+
export interface PaytonzSDKOptions extends PaytonzSDKBaseOptions {}
|
|
9
|
+
|
|
10
|
+
export class WalletSignature extends PaytonzSDKBase {
|
|
11
|
+
constructor(parameters: PaytonzSDKOptions) {
|
|
12
|
+
super(parameters);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async on(
|
|
16
|
+
options: SignatureOnOptions,
|
|
17
|
+
accessToken?: string
|
|
18
|
+
): Promise<boolean> {
|
|
19
|
+
try {
|
|
20
|
+
if (!accessToken) {
|
|
21
|
+
accessToken = await this.getToken(true);
|
|
22
|
+
}
|
|
23
|
+
const path = `/api/public/wallet/signature/on`;
|
|
24
|
+
|
|
25
|
+
return this.auth_post<boolean>(`${path}`, options, accessToken);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async off(
|
|
32
|
+
options: SignatureCommonOptions,
|
|
33
|
+
accessToken?: string
|
|
34
|
+
): Promise<string> {
|
|
35
|
+
try {
|
|
36
|
+
if (!accessToken) {
|
|
37
|
+
accessToken = await this.getToken(true);
|
|
38
|
+
}
|
|
39
|
+
const path = `/api/public/wallet/signature/off`;
|
|
40
|
+
|
|
41
|
+
return this.auth_post<string>(`${path}`, options, accessToken);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async status(accessToken?: string): Promise<boolean> {
|
|
48
|
+
try {
|
|
49
|
+
if (!accessToken) {
|
|
50
|
+
accessToken = await this.getToken(true);
|
|
51
|
+
}
|
|
52
|
+
const path = `/api/public/wallet/signature/status`;
|
|
53
|
+
|
|
54
|
+
return this.auth_get<boolean>(`${path}`, {}, accessToken);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async download(
|
|
61
|
+
options: SignatureCommonOptions,
|
|
62
|
+
accessToken?: string
|
|
63
|
+
): Promise<string> {
|
|
64
|
+
try {
|
|
65
|
+
if (!accessToken) {
|
|
66
|
+
accessToken = await this.getToken(true);
|
|
67
|
+
}
|
|
68
|
+
const path = `/api/public/wallet/signature/download`;
|
|
69
|
+
|
|
70
|
+
return this.auth_post<string>(`${path}`, options, accessToken);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async changePassword(
|
|
77
|
+
options: SignatureChangePasswordOptions,
|
|
78
|
+
accessToken?: string
|
|
79
|
+
): Promise<boolean> {
|
|
80
|
+
try {
|
|
81
|
+
if (!accessToken) {
|
|
82
|
+
accessToken = await this.getToken(true);
|
|
83
|
+
}
|
|
84
|
+
const path = `/api/public/wallet/signature/change-password`;
|
|
85
|
+
|
|
86
|
+
return this.auth_post<boolean>(`${path}`, options, accessToken);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
throw err;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async passwordStatus(accessToken?: string): Promise<boolean> {
|
|
93
|
+
try {
|
|
94
|
+
if (!accessToken) {
|
|
95
|
+
accessToken = await this.getToken(true);
|
|
96
|
+
}
|
|
97
|
+
const path = `/api/public/wallet/signature/password-status`;
|
|
98
|
+
|
|
99
|
+
return this.auth_get<boolean>(`${path}`, {}, accessToken);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
throw err;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default WalletSignature;
|