@stellar/typescript-wallet-sdk 1.7.0 → 1.8.0-beta.1731096658096
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/CHANGELOG.MD +8 -0
- package/examples/helpers/ask-question.ts +15 -0
- package/examples/sep10/.env.example +2 -0
- package/examples/sep10/README.md +34 -0
- package/examples/sep10/sep10Server.ts +53 -0
- package/examples/sep10/sep10Wallet.ts +45 -0
- package/examples/sep10/well_known/stellar.toml +18 -0
- package/examples/sep12/.env.example +2 -0
- package/examples/sep12/README.md +25 -0
- package/examples/sep12/sep12.ts +38 -0
- package/examples/sep24/sep24.ts +1 -15
- package/lib/bundle.js +3277 -1898
- package/lib/bundle.js.map +1 -1
- package/lib/bundle_browser.js +117 -48
- package/lib/bundle_browser.js.map +1 -1
- package/lib/walletSdk/Anchor/Sep24.d.ts +19 -7
- package/lib/walletSdk/Anchor/Sep38.d.ts +1 -0
- package/lib/walletSdk/Anchor/Sep6.d.ts +3 -1
- package/lib/walletSdk/Anchor/index.d.ts +5 -3
- package/lib/walletSdk/Customer/index.d.ts +12 -6
- package/lib/walletSdk/Exceptions/index.d.ts +3 -0
- package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +2 -1
- package/lib/walletSdk/Types/anchor.d.ts +14 -22
- package/lib/walletSdk/Types/sep12.d.ts +7 -1
- package/lib/walletSdk/Types/sep24.d.ts +21 -0
- package/package.json +8 -4
- package/src/walletSdk/Anchor/Sep24.ts +44 -12
- package/src/walletSdk/Anchor/Sep38.ts +1 -1
- package/src/walletSdk/Anchor/Sep6.ts +9 -2
- package/src/walletSdk/Anchor/index.ts +5 -10
- package/src/walletSdk/Customer/index.ts +33 -14
- package/src/walletSdk/Exceptions/index.ts +9 -0
- package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +8 -1
- package/src/walletSdk/Types/anchor.ts +15 -20
- package/src/walletSdk/Types/sep12.ts +7 -1
- package/src/walletSdk/Types/sep24.ts +19 -0
- package/test/customer.test.ts +25 -15
- package/test/stellar.test.ts +155 -31
- package/test/wallet.test.ts +18 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { Anchor } from "../Anchor";
|
|
3
|
-
import { Sep24PostParams, Sep24PostResponse, AnchorTransaction, GetTransactionParams, GetTransactionsParams, AnchorServiceInfo } from "../Types";
|
|
3
|
+
import { Sep24PostParams, Sep24PostResponse, AnchorTransaction, GetTransactionParams, GetTransactionsParams, AnchorServiceInfo, Sep24Info } from "../Types";
|
|
4
4
|
import { Watcher } from "../Watcher";
|
|
5
5
|
type Sep24Params = {
|
|
6
6
|
anchor: Anchor;
|
|
@@ -19,12 +19,30 @@ export type Interactive = Sep24;
|
|
|
19
19
|
export declare class Sep24 {
|
|
20
20
|
private anchor;
|
|
21
21
|
private httpClient;
|
|
22
|
+
private anchorInfo;
|
|
22
23
|
/**
|
|
23
24
|
* Creates a new instance of the Sep24 class.
|
|
24
25
|
* @constructor
|
|
25
26
|
* @param {Sep24Params} params - Parameters to initialize the Sep24 instance.
|
|
26
27
|
*/
|
|
27
28
|
constructor(params: Sep24Params);
|
|
29
|
+
/**
|
|
30
|
+
* Get SEP-24 anchor information.
|
|
31
|
+
* If `shouldRefresh` is set to `true`, it fetches fresh values; otherwise, it returns cached values if available.
|
|
32
|
+
* @param {boolean} [shouldRefresh=false] - Flag to force a refresh of TOML values.
|
|
33
|
+
* @param {string} [lang=this.anchor.language] - The language in which to retrieve information.
|
|
34
|
+
* @returns {Promise<Sep24Info>} - SEP-24 information about the anchor.
|
|
35
|
+
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
36
|
+
*/
|
|
37
|
+
info(shouldRefresh?: boolean, lang?: string): Promise<Sep24Info>;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Please use info() instead.
|
|
40
|
+
*
|
|
41
|
+
* Get SEP-24 anchor information.
|
|
42
|
+
* @returns {Promise<AnchorServiceInfo>} - SEP-24 information about the anchor.
|
|
43
|
+
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
44
|
+
*/
|
|
45
|
+
getServicesInfo(): Promise<AnchorServiceInfo>;
|
|
28
46
|
/**
|
|
29
47
|
* Initiates a deposit request.
|
|
30
48
|
* @param {Sep24PostParams} params - The SEP-24 Post params.
|
|
@@ -51,12 +69,6 @@ export declare class Sep24 {
|
|
|
51
69
|
*/
|
|
52
70
|
withdraw({ assetCode, authToken, lang, extraFields, withdrawalAccount, }: Sep24PostParams): Promise<Sep24PostResponse>;
|
|
53
71
|
private flow;
|
|
54
|
-
/**
|
|
55
|
-
* Retrieves information about the Anchor.
|
|
56
|
-
* @returns {Promise<AnchorServiceInfo>} An object containing information about the Anchor.
|
|
57
|
-
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
58
|
-
*/
|
|
59
|
-
getServicesInfo(): Promise<AnchorServiceInfo>;
|
|
60
72
|
/**
|
|
61
73
|
* Creates a new instance of the Watcher class, to watch sep24 transactions.
|
|
62
74
|
* @returns {Watcher} A new Watcher instance.
|
|
@@ -27,6 +27,7 @@ export declare class Sep38 {
|
|
|
27
27
|
* If `shouldRefresh` is set to `true`, it fetches fresh values; otherwise, it returns cached values if available.
|
|
28
28
|
* @param {boolean} [shouldRefresh=false] - Flag to force a refresh of TOML values.
|
|
29
29
|
* @returns {Promise<Sep38Info>} - SEP-38 information about the anchor.
|
|
30
|
+
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
30
31
|
*/
|
|
31
32
|
info(shouldRefresh?: boolean): Promise<Sep38Info>;
|
|
32
33
|
/**
|
|
@@ -25,9 +25,11 @@ export declare class Sep6 {
|
|
|
25
25
|
* Get SEP-6 anchor information.
|
|
26
26
|
* If `shouldRefresh` is set to `true`, it fetches fresh values; otherwise, it returns cached values if available.
|
|
27
27
|
* @param {boolean} [shouldRefresh=false] - Flag to force a refresh of TOML values.
|
|
28
|
+
* @param {string} [lang=this.anchor.language] - The language in which to retrieve information.
|
|
28
29
|
* @returns {Promise<Sep6Info>} - SEP-6 information about the anchor.
|
|
30
|
+
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
29
31
|
*/
|
|
30
|
-
info(shouldRefresh?: boolean): Promise<Sep6Info>;
|
|
32
|
+
info(shouldRefresh?: boolean, lang?: string): Promise<Sep6Info>;
|
|
31
33
|
/**
|
|
32
34
|
* Deposits funds using the SEP-6 protocol. Next steps by
|
|
33
35
|
* the anchor are given in the response.
|
|
@@ -101,10 +101,12 @@ export declare class Anchor {
|
|
|
101
101
|
*/
|
|
102
102
|
quote(authToken?: AuthToken): Quote;
|
|
103
103
|
/**
|
|
104
|
-
*
|
|
104
|
+
* @deprecated Please use sep24().info() instead.
|
|
105
|
+
*
|
|
106
|
+
* Get SEP-24 anchor information.
|
|
105
107
|
* @param {string} [lang=this.language] - The language in which to retrieve information.
|
|
106
|
-
* @returns {Promise<AnchorServiceInfo>}
|
|
107
|
-
* @throws {ServerRequestFailedError} If the
|
|
108
|
+
* @returns {Promise<AnchorServiceInfo>} - SEP-24 information about the anchor.
|
|
109
|
+
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
108
110
|
*/
|
|
109
111
|
getServicesInfo(lang?: string): Promise<AnchorServiceInfo>;
|
|
110
112
|
}
|
|
@@ -27,12 +27,14 @@ export declare class Sep12 {
|
|
|
27
27
|
* Retrieve customer information. All arguments are optional, but at least one
|
|
28
28
|
* must be given. For more information:
|
|
29
29
|
* @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#request}
|
|
30
|
-
* @param {
|
|
30
|
+
* @param {GetCustomerParams} params - The parameters for retrieving customer information.
|
|
31
31
|
* @param {string} [params.id] - The id of the customer .
|
|
32
32
|
* @param {string} [params.type] - The type of action the customer is being KYCd for.
|
|
33
33
|
* @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#type-specification}
|
|
34
34
|
* @param {string} [params.memo] - A memo associated with the customer.
|
|
35
35
|
* @param {string} [params.lang] - The desired language. Defaults to "en".
|
|
36
|
+
* @param {string} [params.transactionId] - The id of the transaction that the customer is
|
|
37
|
+
* being KYC'ed for.
|
|
36
38
|
* @returns {Promise<GetCustomerResponse>} The customer information.
|
|
37
39
|
* @throws {CustomerNotFoundError} If the customer is not found.
|
|
38
40
|
*/
|
|
@@ -43,31 +45,35 @@ export declare class Sep12 {
|
|
|
43
45
|
* @param {AddCustomerParams} params - The parameters for adding a customer.
|
|
44
46
|
* @param {CustomerInfoMap} [params.sep9Info] - Customer information. What fields you should
|
|
45
47
|
* give is indicated by the anchor.
|
|
46
|
-
* @param {
|
|
48
|
+
* @param {CustomerBinaryInfoMap} [params.sep9BinaryInfo] - Customer information that is in binary
|
|
47
49
|
* format (eg. Buffer of an image).
|
|
48
50
|
* @param {string} [params.type] - The type of the customer.
|
|
49
51
|
* @param {string} [params.memo] - A memo associated with the customer.
|
|
52
|
+
* @param {string} [params.transactionId] - The id of the transaction that the customer is
|
|
53
|
+
* being KYC'ed for.
|
|
50
54
|
* @returns {Promise<AddCustomerResponse>} Add customer response.
|
|
51
55
|
*/
|
|
52
|
-
add({ sep9Info, sep9BinaryInfo, type, memo, }: AddCustomerParams): Promise<AddCustomerResponse>;
|
|
56
|
+
add({ sep9Info, sep9BinaryInfo, type, memo, transactionId, }: AddCustomerParams): Promise<AddCustomerResponse>;
|
|
53
57
|
/**
|
|
54
58
|
* Updates an existing customer. Customer info is given in sep9Info param. If it
|
|
55
59
|
* is binary type (eg. Buffer of an image) include it in sep9BinaryInfo.
|
|
56
60
|
* @param {AddCustomerParams} params - The parameters for adding a customer.
|
|
57
61
|
* @param {CustomerInfoMap} [params.sep9Info] - Customer information. What fields you should
|
|
58
62
|
* give is indicated by the anchor.
|
|
59
|
-
* @param {
|
|
63
|
+
* @param {CustomerBinaryInfoMap} [params.sep9BinaryInfo] - Customer information that is in binary
|
|
60
64
|
* format (eg. Buffer of an image).
|
|
61
65
|
* @param {string} [params.id] - The id of the customer.
|
|
62
66
|
* @param {string} [params.type] - The type of the customer.
|
|
63
67
|
* @param {string} [params.memo] - A memo associated with the customer.
|
|
68
|
+
* @param {string} [params.transactionId] - The id of the transaction that the customer is
|
|
69
|
+
* being KYC'ed for.
|
|
64
70
|
* @returns {Promise<AddCustomerResponse>} Add customer response.
|
|
65
71
|
* @throws {Sep9InfoRequiredError} If no SEP-9 info is given.
|
|
66
72
|
*/
|
|
67
|
-
update({ sep9Info, sep9BinaryInfo, id, type, memo, }: AddCustomerParams): Promise<AddCustomerResponse>;
|
|
73
|
+
update({ sep9Info, sep9BinaryInfo, id, type, memo, transactionId, }: AddCustomerParams): Promise<AddCustomerResponse>;
|
|
68
74
|
/**
|
|
69
75
|
* Deletes a customer.
|
|
70
|
-
* @param {string} accountAddress - The account address of the customer to delete.
|
|
76
|
+
* @param {string} [accountAddress] - The account address of the customer to delete.
|
|
71
77
|
* @param {string} [memo] - An optional memo for customer identification.
|
|
72
78
|
*/
|
|
73
79
|
delete(accountAddress?: string, memo?: string): Promise<void>;
|
|
@@ -52,6 +52,9 @@ export declare class OperationsLimitExceededError extends Error {
|
|
|
52
52
|
export declare class WithdrawalTxNotPendingUserTransferStartError extends Error {
|
|
53
53
|
constructor(status: string);
|
|
54
54
|
}
|
|
55
|
+
export declare class WithdrawalTxMissingDestinationError extends Error {
|
|
56
|
+
constructor();
|
|
57
|
+
}
|
|
55
58
|
export declare class WithdrawalTxMissingMemoError extends Error {
|
|
56
59
|
constructor();
|
|
57
60
|
}
|
|
@@ -73,7 +73,7 @@ export declare class TransactionBuilder extends CommonTransactionBuilder<Transac
|
|
|
73
73
|
pathPay({ destinationAddress, sendAsset, destAsset, sendAmount, destAmount, destMin, sendMax, }: PathPayParams): TransactionBuilder;
|
|
74
74
|
/**
|
|
75
75
|
* Swap assets using the Stellar network. This swaps using the
|
|
76
|
-
*
|
|
76
|
+
* pathPaymentStrictSend operation.
|
|
77
77
|
* @param {StellarAssetId} fromAsset - The source asset to be sent.
|
|
78
78
|
* @param {StellarAssetId} toAsset - The destination asset to receive.
|
|
79
79
|
* @param {string} amount - The amount of the source asset to be sent.
|
|
@@ -98,6 +98,7 @@ export declare class TransactionBuilder extends CommonTransactionBuilder<Transac
|
|
|
98
98
|
* @param {WithdrawTransaction} transaction - The withdrawal transaction.
|
|
99
99
|
* @param {StellarAssetId} assetId - The asset ID to transfer.
|
|
100
100
|
* @throws {WithdrawalTxNotPendingUserTransferStartError} If the withdrawal transaction status is not pending_user_transfer_start.
|
|
101
|
+
* @throws {WithdrawalTxMissingDestinationError} If the withdrawal transaction is missing withdraw_anchor_account field.
|
|
101
102
|
* @throws {WithdrawalTxMissingMemoError} If the withdrawal transaction is missing a memo.
|
|
102
103
|
* @throws {WithdrawalTxMemoError} If there is an issue with the withdrawal transaction memo.
|
|
103
104
|
* @returns {TransactionBuilder} The TransactionBuilder instance.
|
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
import { MemoType } from "@stellar/stellar-sdk";
|
|
2
2
|
import { Optional } from "utility-types";
|
|
3
3
|
import { AuthToken } from "./auth";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
export interface AnchorServiceAsset {
|
|
19
|
-
enabled: boolean;
|
|
20
|
-
min_amount: number;
|
|
21
|
-
max_amount: number;
|
|
22
|
-
fee_fixed: number;
|
|
23
|
-
fee_percent: number;
|
|
24
|
-
}
|
|
4
|
+
import { Sep24AssetInfo, Sep24AssetInfoMap, Sep24Info } from "./sep24";
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Please use Sep24Info interface instead.
|
|
7
|
+
*/
|
|
8
|
+
export type AnchorServiceInfo = Sep24Info;
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Please use Sep24AssetInfoMap interface instead.
|
|
11
|
+
*/
|
|
12
|
+
export type AssetInfoMap = Sep24AssetInfoMap;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Please use Sep24AssetInfo interface instead.
|
|
15
|
+
*/
|
|
16
|
+
export type AnchorServiceAsset = Sep24AssetInfo;
|
|
25
17
|
export interface BaseTransaction {
|
|
26
18
|
id: string;
|
|
27
19
|
kind: string;
|
|
@@ -57,7 +49,7 @@ export interface WithdrawTransaction extends ProcessingAnchorTransaction {
|
|
|
57
49
|
to?: string;
|
|
58
50
|
withdraw_memo?: string;
|
|
59
51
|
withdraw_memo_type: MemoType;
|
|
60
|
-
withdraw_anchor_account
|
|
52
|
+
withdraw_anchor_account?: string;
|
|
61
53
|
}
|
|
62
54
|
export type Sep6Transaction = DepositTransaction & WithdrawTransaction & {
|
|
63
55
|
from?: string;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
export type CustomerInfoMap = {
|
|
2
3
|
[key: string]: string;
|
|
3
4
|
};
|
|
5
|
+
export type CustomerBinaryInfoMap = {
|
|
6
|
+
[key: string]: Buffer;
|
|
7
|
+
};
|
|
4
8
|
export declare enum Sep12Status {
|
|
5
9
|
ACCEPTED = "ACCEPTED",
|
|
6
10
|
PROCESSING = "PROCESSING",
|
|
@@ -33,6 +37,7 @@ export type GetCustomerParams = {
|
|
|
33
37
|
type?: string;
|
|
34
38
|
memo?: string;
|
|
35
39
|
lang?: string;
|
|
40
|
+
transactionId?: string;
|
|
36
41
|
};
|
|
37
42
|
export type GetCustomerResponse = {
|
|
38
43
|
id?: string;
|
|
@@ -47,10 +52,11 @@ export type GetCustomerResponse = {
|
|
|
47
52
|
};
|
|
48
53
|
export type AddCustomerParams = {
|
|
49
54
|
sep9Info?: CustomerInfoMap;
|
|
50
|
-
sep9BinaryInfo?:
|
|
55
|
+
sep9BinaryInfo?: CustomerBinaryInfoMap;
|
|
51
56
|
id?: string;
|
|
52
57
|
memo?: string;
|
|
53
58
|
type?: string;
|
|
59
|
+
transactionId?: string;
|
|
54
60
|
};
|
|
55
61
|
export type AddCustomerResponse = {
|
|
56
62
|
id: string;
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import { Memo } from "@stellar/stellar-sdk";
|
|
2
2
|
import { AuthToken } from "./auth";
|
|
3
|
+
export interface Sep24Info {
|
|
4
|
+
deposit: Sep24AssetInfoMap;
|
|
5
|
+
withdraw: Sep24AssetInfoMap;
|
|
6
|
+
fee: {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
};
|
|
9
|
+
features: {
|
|
10
|
+
account_creation: boolean;
|
|
11
|
+
claimable_balances: boolean;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface Sep24AssetInfoMap {
|
|
15
|
+
[asset_code: string]: Sep24AssetInfo;
|
|
16
|
+
}
|
|
17
|
+
export interface Sep24AssetInfo {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
min_amount: number;
|
|
20
|
+
max_amount: number;
|
|
21
|
+
fee_fixed: number;
|
|
22
|
+
fee_percent: number;
|
|
23
|
+
}
|
|
3
24
|
export declare enum FLOW_TYPE {
|
|
4
25
|
DEPOSIT = "deposit",
|
|
5
26
|
WITHDRAW = "withdraw"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stellar/typescript-wallet-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0-beta.1731096658096",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=18"
|
|
6
6
|
},
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"eslint": "^8.51.0",
|
|
26
26
|
"eslint-config-prettier": "^9.0.0",
|
|
27
27
|
"eslint-plugin-jsdoc": "^46.8.2",
|
|
28
|
+
"express": "^4.19.2",
|
|
28
29
|
"husky": "^8.0.0",
|
|
29
30
|
"jest": "^29.4.1",
|
|
30
31
|
"lint-staged": "^14.0.1",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"dependencies": {
|
|
47
48
|
"@stablelib/base64": "^2.0.0",
|
|
48
49
|
"@stablelib/utf8": "^2.0.0",
|
|
49
|
-
"@stellar/stellar-sdk": "
|
|
50
|
+
"@stellar/stellar-sdk": "13.0.0-beta.1",
|
|
50
51
|
"axios": "^1.4.0",
|
|
51
52
|
"base64url": "^3.0.1",
|
|
52
53
|
"https-browserify": "^1.0.0",
|
|
@@ -69,6 +70,9 @@
|
|
|
69
70
|
"build:web": "webpack --config webpack.config.js",
|
|
70
71
|
"build:node": "webpack --env NODE=true --config webpack.config.js",
|
|
71
72
|
"build": "run-p build:web build:node",
|
|
72
|
-
"example:
|
|
73
|
+
"example:sep10Server": "ts-node examples/sep10/sep10Server.ts",
|
|
74
|
+
"example:sep10Wallet": "ts-node examples/sep10/sep10Wallet.ts",
|
|
75
|
+
"example:sep24": "ts-node examples/sep24/sep24.ts",
|
|
76
|
+
"example:sep12": "ts-node examples/sep12/sep12.ts"
|
|
73
77
|
}
|
|
74
|
-
}
|
|
78
|
+
}
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
GetTransactionsParams,
|
|
16
16
|
AnchorServiceInfo,
|
|
17
17
|
WatcherSepType,
|
|
18
|
+
Sep24Info,
|
|
18
19
|
} from "../Types";
|
|
19
20
|
import {
|
|
20
21
|
Watcher,
|
|
@@ -44,6 +45,7 @@ export type Interactive = Sep24;
|
|
|
44
45
|
export class Sep24 {
|
|
45
46
|
private anchor: Anchor;
|
|
46
47
|
private httpClient: AxiosInstance;
|
|
48
|
+
private anchorInfo: Sep24Info;
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
51
|
* Creates a new instance of the Sep24 class.
|
|
@@ -57,6 +59,45 @@ export class Sep24 {
|
|
|
57
59
|
this.httpClient = httpClient;
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Get SEP-24 anchor information.
|
|
64
|
+
* If `shouldRefresh` is set to `true`, it fetches fresh values; otherwise, it returns cached values if available.
|
|
65
|
+
* @param {boolean} [shouldRefresh=false] - Flag to force a refresh of TOML values.
|
|
66
|
+
* @param {string} [lang=this.anchor.language] - The language in which to retrieve information.
|
|
67
|
+
* @returns {Promise<Sep24Info>} - SEP-24 information about the anchor.
|
|
68
|
+
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
69
|
+
*/
|
|
70
|
+
async info(
|
|
71
|
+
shouldRefresh?: boolean,
|
|
72
|
+
lang: string = this.anchor.language,
|
|
73
|
+
): Promise<Sep24Info> {
|
|
74
|
+
if (this.anchorInfo && !shouldRefresh) {
|
|
75
|
+
return this.anchorInfo;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const { transferServerSep24 } = await this.anchor.sep1();
|
|
79
|
+
try {
|
|
80
|
+
const resp = await this.httpClient.get(
|
|
81
|
+
`${transferServerSep24}/info?lang=${lang}`,
|
|
82
|
+
);
|
|
83
|
+
this.anchorInfo = resp.data;
|
|
84
|
+
return resp.data;
|
|
85
|
+
} catch (e) {
|
|
86
|
+
throw new ServerRequestFailedError(e);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Please use info() instead.
|
|
92
|
+
*
|
|
93
|
+
* Get SEP-24 anchor information.
|
|
94
|
+
* @returns {Promise<AnchorServiceInfo>} - SEP-24 information about the anchor.
|
|
95
|
+
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
96
|
+
*/
|
|
97
|
+
async getServicesInfo(): Promise<AnchorServiceInfo> {
|
|
98
|
+
return this.info();
|
|
99
|
+
}
|
|
100
|
+
|
|
60
101
|
/**
|
|
61
102
|
* Initiates a deposit request.
|
|
62
103
|
* @param {Sep24PostParams} params - The SEP-24 Post params.
|
|
@@ -132,13 +173,13 @@ export class Sep24 {
|
|
|
132
173
|
const toml = await this.anchor.sep1();
|
|
133
174
|
const transferServerEndpoint = toml.transferServerSep24;
|
|
134
175
|
|
|
135
|
-
const
|
|
176
|
+
const sep24Info = await this.info();
|
|
136
177
|
|
|
137
178
|
let assets: string[];
|
|
138
179
|
if (type === FLOW_TYPE.DEPOSIT) {
|
|
139
|
-
assets = Object.keys(
|
|
180
|
+
assets = Object.keys(sep24Info.deposit);
|
|
140
181
|
} else {
|
|
141
|
-
assets = Object.keys(
|
|
182
|
+
assets = Object.keys(sep24Info.withdraw);
|
|
142
183
|
}
|
|
143
184
|
if (!assets.includes(assetCode)) {
|
|
144
185
|
throw new AssetNotSupportedError(type, assetCode);
|
|
@@ -175,15 +216,6 @@ export class Sep24 {
|
|
|
175
216
|
}
|
|
176
217
|
}
|
|
177
218
|
|
|
178
|
-
/**
|
|
179
|
-
* Retrieves information about the Anchor.
|
|
180
|
-
* @returns {Promise<AnchorServiceInfo>} An object containing information about the Anchor.
|
|
181
|
-
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
182
|
-
*/
|
|
183
|
-
async getServicesInfo(): Promise<AnchorServiceInfo> {
|
|
184
|
-
return this.anchor.getServicesInfo();
|
|
185
|
-
}
|
|
186
|
-
|
|
187
219
|
/**
|
|
188
220
|
* Creates a new instance of the Watcher class, to watch sep24 transactions.
|
|
189
221
|
* @returns {Watcher} A new Watcher instance.
|
|
@@ -63,6 +63,7 @@ export class Sep38 {
|
|
|
63
63
|
* If `shouldRefresh` is set to `true`, it fetches fresh values; otherwise, it returns cached values if available.
|
|
64
64
|
* @param {boolean} [shouldRefresh=false] - Flag to force a refresh of TOML values.
|
|
65
65
|
* @returns {Promise<Sep38Info>} - SEP-38 information about the anchor.
|
|
66
|
+
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
66
67
|
*/
|
|
67
68
|
async info(shouldRefresh?: boolean): Promise<Sep38Info> {
|
|
68
69
|
if (this.sep38Info && !shouldRefresh) {
|
|
@@ -70,7 +71,6 @@ export class Sep38 {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
const { anchorQuoteServer } = await this.anchor.sep1();
|
|
73
|
-
|
|
74
74
|
try {
|
|
75
75
|
const resp = await this.httpClient.get(`${anchorQuoteServer}/info`, {
|
|
76
76
|
headers: this.headers,
|
|
@@ -60,16 +60,23 @@ export class Sep6 {
|
|
|
60
60
|
* Get SEP-6 anchor information.
|
|
61
61
|
* If `shouldRefresh` is set to `true`, it fetches fresh values; otherwise, it returns cached values if available.
|
|
62
62
|
* @param {boolean} [shouldRefresh=false] - Flag to force a refresh of TOML values.
|
|
63
|
+
* @param {string} [lang=this.anchor.language] - The language in which to retrieve information.
|
|
63
64
|
* @returns {Promise<Sep6Info>} - SEP-6 information about the anchor.
|
|
65
|
+
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
64
66
|
*/
|
|
65
|
-
async info(
|
|
67
|
+
async info(
|
|
68
|
+
shouldRefresh?: boolean,
|
|
69
|
+
lang: string = this.anchor.language,
|
|
70
|
+
): Promise<Sep6Info> {
|
|
66
71
|
if (this.anchorInfo && !shouldRefresh) {
|
|
67
72
|
return this.anchorInfo;
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
const { transferServer } = await this.anchor.sep1();
|
|
71
76
|
try {
|
|
72
|
-
const resp = await this.httpClient.get(
|
|
77
|
+
const resp = await this.httpClient.get(
|
|
78
|
+
`${transferServer}/info?lang=${lang}`,
|
|
79
|
+
);
|
|
73
80
|
this.anchorInfo = resp.data;
|
|
74
81
|
return resp.data;
|
|
75
82
|
} catch (e) {
|
|
@@ -184,10 +184,12 @@ export class Anchor {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
/**
|
|
187
|
-
*
|
|
187
|
+
* @deprecated Please use sep24().info() instead.
|
|
188
|
+
*
|
|
189
|
+
* Get SEP-24 anchor information.
|
|
188
190
|
* @param {string} [lang=this.language] - The language in which to retrieve information.
|
|
189
|
-
* @returns {Promise<AnchorServiceInfo>}
|
|
190
|
-
* @throws {ServerRequestFailedError} If the
|
|
191
|
+
* @returns {Promise<AnchorServiceInfo>} - SEP-24 information about the anchor.
|
|
192
|
+
* @throws {ServerRequestFailedError} If the server request to fetch information fails.
|
|
191
193
|
*/
|
|
192
194
|
async getServicesInfo(
|
|
193
195
|
lang: string = this.language,
|
|
@@ -198,15 +200,8 @@ export class Anchor {
|
|
|
198
200
|
try {
|
|
199
201
|
const resp = await this.httpClient.get(
|
|
200
202
|
`${transferServerEndpoint}/info?lang=${lang}`,
|
|
201
|
-
{
|
|
202
|
-
headers: {
|
|
203
|
-
"Content-Type": "application/json",
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
203
|
);
|
|
207
|
-
|
|
208
204
|
const servicesInfo: AnchorServiceInfo = resp.data;
|
|
209
|
-
|
|
210
205
|
return servicesInfo;
|
|
211
206
|
} catch (e) {
|
|
212
207
|
throw new ServerRequestFailedError(e);
|
|
@@ -2,13 +2,13 @@ import { AxiosInstance } from "axios";
|
|
|
2
2
|
import queryString from "query-string";
|
|
3
3
|
import { Sep9InfoRequiredError, CustomerNotFoundError } from "../Exceptions";
|
|
4
4
|
import {
|
|
5
|
-
CustomerInfoMap,
|
|
6
5
|
GetCustomerParams,
|
|
7
6
|
GetCustomerResponse,
|
|
8
7
|
AddCustomerResponse,
|
|
9
8
|
AddCustomerParams,
|
|
10
9
|
AuthToken,
|
|
11
10
|
} from "../Types";
|
|
11
|
+
import { camelToSnakeCaseObject } from "../Utils";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @alias Customer alias for Sep12 class.
|
|
@@ -52,17 +52,20 @@ export class Sep12 {
|
|
|
52
52
|
* Retrieve customer information. All arguments are optional, but at least one
|
|
53
53
|
* must be given. For more information:
|
|
54
54
|
* @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#request}
|
|
55
|
-
* @param {
|
|
55
|
+
* @param {GetCustomerParams} params - The parameters for retrieving customer information.
|
|
56
56
|
* @param {string} [params.id] - The id of the customer .
|
|
57
57
|
* @param {string} [params.type] - The type of action the customer is being KYCd for.
|
|
58
58
|
* @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md#type-specification}
|
|
59
59
|
* @param {string} [params.memo] - A memo associated with the customer.
|
|
60
60
|
* @param {string} [params.lang] - The desired language. Defaults to "en".
|
|
61
|
+
* @param {string} [params.transactionId] - The id of the transaction that the customer is
|
|
62
|
+
* being KYC'ed for.
|
|
61
63
|
* @returns {Promise<GetCustomerResponse>} The customer information.
|
|
62
64
|
* @throws {CustomerNotFoundError} If the customer is not found.
|
|
63
65
|
*/
|
|
64
66
|
async getCustomer(params: GetCustomerParams): Promise<GetCustomerResponse> {
|
|
65
|
-
const qs = queryString.stringify(params);
|
|
67
|
+
const qs = queryString.stringify(camelToSnakeCaseObject(params));
|
|
68
|
+
|
|
66
69
|
const resp = await this.httpClient.get(`${this.baseUrl}/customer?${qs}`, {
|
|
67
70
|
headers: this.headers,
|
|
68
71
|
});
|
|
@@ -78,28 +81,38 @@ export class Sep12 {
|
|
|
78
81
|
* @param {AddCustomerParams} params - The parameters for adding a customer.
|
|
79
82
|
* @param {CustomerInfoMap} [params.sep9Info] - Customer information. What fields you should
|
|
80
83
|
* give is indicated by the anchor.
|
|
81
|
-
* @param {
|
|
84
|
+
* @param {CustomerBinaryInfoMap} [params.sep9BinaryInfo] - Customer information that is in binary
|
|
82
85
|
* format (eg. Buffer of an image).
|
|
83
86
|
* @param {string} [params.type] - The type of the customer.
|
|
84
87
|
* @param {string} [params.memo] - A memo associated with the customer.
|
|
88
|
+
* @param {string} [params.transactionId] - The id of the transaction that the customer is
|
|
89
|
+
* being KYC'ed for.
|
|
85
90
|
* @returns {Promise<AddCustomerResponse>} Add customer response.
|
|
86
91
|
*/
|
|
87
92
|
async add({
|
|
88
|
-
sep9Info,
|
|
89
|
-
sep9BinaryInfo,
|
|
93
|
+
sep9Info = {},
|
|
94
|
+
sep9BinaryInfo = {},
|
|
90
95
|
type,
|
|
91
96
|
memo,
|
|
97
|
+
transactionId,
|
|
92
98
|
}: AddCustomerParams): Promise<AddCustomerResponse> {
|
|
93
|
-
let customerMap:
|
|
99
|
+
let customerMap: { [key: string]: string | Buffer } = {
|
|
100
|
+
...sep9Info,
|
|
101
|
+
...sep9BinaryInfo,
|
|
102
|
+
};
|
|
103
|
+
|
|
94
104
|
if (type) {
|
|
95
105
|
customerMap = { type, ...customerMap };
|
|
96
106
|
}
|
|
97
107
|
if (memo) {
|
|
98
108
|
customerMap["memo"] = memo;
|
|
99
109
|
}
|
|
110
|
+
if (transactionId) {
|
|
111
|
+
customerMap["transaction_id"] = transactionId;
|
|
112
|
+
}
|
|
100
113
|
|
|
101
114
|
// Check if binary data given so can adjust headers
|
|
102
|
-
const includesBinary =
|
|
115
|
+
const includesBinary = Object.keys(sep9BinaryInfo).length > 0;
|
|
103
116
|
const resp = await this.httpClient.put(
|
|
104
117
|
`${this.baseUrl}/customer`,
|
|
105
118
|
customerMap,
|
|
@@ -118,22 +131,25 @@ export class Sep12 {
|
|
|
118
131
|
* @param {AddCustomerParams} params - The parameters for adding a customer.
|
|
119
132
|
* @param {CustomerInfoMap} [params.sep9Info] - Customer information. What fields you should
|
|
120
133
|
* give is indicated by the anchor.
|
|
121
|
-
* @param {
|
|
134
|
+
* @param {CustomerBinaryInfoMap} [params.sep9BinaryInfo] - Customer information that is in binary
|
|
122
135
|
* format (eg. Buffer of an image).
|
|
123
136
|
* @param {string} [params.id] - The id of the customer.
|
|
124
137
|
* @param {string} [params.type] - The type of the customer.
|
|
125
138
|
* @param {string} [params.memo] - A memo associated with the customer.
|
|
139
|
+
* @param {string} [params.transactionId] - The id of the transaction that the customer is
|
|
140
|
+
* being KYC'ed for.
|
|
126
141
|
* @returns {Promise<AddCustomerResponse>} Add customer response.
|
|
127
142
|
* @throws {Sep9InfoRequiredError} If no SEP-9 info is given.
|
|
128
143
|
*/
|
|
129
144
|
async update({
|
|
130
|
-
sep9Info,
|
|
131
|
-
sep9BinaryInfo,
|
|
145
|
+
sep9Info = {},
|
|
146
|
+
sep9BinaryInfo = {},
|
|
132
147
|
id,
|
|
133
148
|
type,
|
|
134
149
|
memo,
|
|
150
|
+
transactionId,
|
|
135
151
|
}: AddCustomerParams): Promise<AddCustomerResponse> {
|
|
136
|
-
let customerMap:
|
|
152
|
+
let customerMap: { [key: string]: string | Buffer } = {};
|
|
137
153
|
if (id) {
|
|
138
154
|
customerMap["id"] = id;
|
|
139
155
|
}
|
|
@@ -143,13 +159,16 @@ export class Sep12 {
|
|
|
143
159
|
if (memo) {
|
|
144
160
|
customerMap["memo"] = memo;
|
|
145
161
|
}
|
|
162
|
+
if (transactionId) {
|
|
163
|
+
customerMap["transaction_id"] = transactionId;
|
|
164
|
+
}
|
|
146
165
|
if (!Object.keys({ ...sep9Info, ...sep9BinaryInfo }).length) {
|
|
147
166
|
throw new Sep9InfoRequiredError();
|
|
148
167
|
}
|
|
149
168
|
customerMap = { ...customerMap, ...sep9Info, ...sep9BinaryInfo };
|
|
150
169
|
|
|
151
170
|
// Check if binary data given so can adjust headers
|
|
152
|
-
const includesBinary =
|
|
171
|
+
const includesBinary = Object.keys(sep9BinaryInfo).length > 0;
|
|
153
172
|
const resp = await this.httpClient.put(
|
|
154
173
|
`${this.baseUrl}/customer`,
|
|
155
174
|
customerMap,
|
|
@@ -164,7 +183,7 @@ export class Sep12 {
|
|
|
164
183
|
|
|
165
184
|
/**
|
|
166
185
|
* Deletes a customer.
|
|
167
|
-
* @param {string} accountAddress - The account address of the customer to delete.
|
|
186
|
+
* @param {string} [accountAddress] - The account address of the customer to delete.
|
|
168
187
|
* @param {string} [memo] - An optional memo for customer identification.
|
|
169
188
|
*/
|
|
170
189
|
async delete(accountAddress?: string, memo?: string) {
|
|
@@ -159,6 +159,15 @@ export class WithdrawalTxNotPendingUserTransferStartError extends Error {
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
export class WithdrawalTxMissingDestinationError extends Error {
|
|
163
|
+
constructor() {
|
|
164
|
+
super(
|
|
165
|
+
`Anchor should set the withdraw_anchor_account field for transactions in pending_user_transfer_start status.`,
|
|
166
|
+
);
|
|
167
|
+
Object.setPrototypeOf(this, WithdrawalTxMissingDestinationError.prototype);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
162
171
|
export class WithdrawalTxMissingMemoError extends Error {
|
|
163
172
|
constructor() {
|
|
164
173
|
super(`Withdrawal transaction missing memo`);
|