@stellar/typescript-wallet-sdk 1.0.0-alpha.2 → 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.
Files changed (75) hide show
  1. package/.husky/pre-commit +4 -0
  2. package/docs/WalletGuide.md +323 -0
  3. package/lib/bundle.js +32343 -5920
  4. package/lib/bundle.js.map +1 -1
  5. package/lib/index.d.ts +25 -0
  6. package/lib/walletSdk/Exceptions/index.d.ts +41 -0
  7. package/lib/walletSdk/Types/anchor.d.ts +148 -0
  8. package/lib/walletSdk/Types/auth.d.ts +35 -0
  9. package/lib/walletSdk/Types/horizon.d.ts +12 -0
  10. package/lib/walletSdk/Types/index.d.ts +30 -0
  11. package/lib/walletSdk/Types/sep24.d.ts +30 -0
  12. package/lib/walletSdk/Types/utils.d.ts +77 -0
  13. package/lib/walletSdk/Types/watcher.d.ts +30 -0
  14. package/lib/walletSdk/Utils/camelToSnakeCase.d.ts +2 -0
  15. package/lib/walletSdk/Utils/index.d.ts +3 -0
  16. package/lib/walletSdk/Utils/toml.d.ts +3 -0
  17. package/lib/walletSdk/Utils/url.d.ts +1 -0
  18. package/lib/walletSdk/Watcher/Types.d.ts +65 -0
  19. package/lib/walletSdk/Watcher/index.d.ts +33 -0
  20. package/lib/walletSdk/anchor/Sep24.d.ts +48 -0
  21. package/lib/walletSdk/anchor/index.d.ts +20 -12
  22. package/lib/walletSdk/auth/WalletSigner.d.ts +4 -0
  23. package/lib/walletSdk/auth/index.d.ts +19 -7
  24. package/lib/walletSdk/exception/index.d.ts +9 -0
  25. package/lib/walletSdk/horizon/Account.d.ts +17 -0
  26. package/lib/walletSdk/horizon/AccountService.d.ts +8 -0
  27. package/lib/walletSdk/horizon/Stellar.d.ts +11 -1
  28. package/lib/walletSdk/horizon/index.d.ts +3 -0
  29. package/lib/walletSdk/horizon/transaction/TransactionBuilder.d.ts +12 -0
  30. package/lib/walletSdk/index.d.ts +19 -18
  31. package/lib/walletSdk/interactive/index.d.ts +16 -5
  32. package/lib/walletSdk/recovery/index.d.ts +18 -0
  33. package/lib/walletSdk/util/camelToSnakeCase.d.ts +2 -0
  34. package/package.json +18 -6
  35. package/prettier.config.js +1 -0
  36. package/src/index.ts +39 -1
  37. package/src/walletSdk/Anchor/Sep24.ts +267 -0
  38. package/src/walletSdk/Anchor/index.ts +63 -32
  39. package/src/walletSdk/Auth/WalletSigner.ts +29 -3
  40. package/src/walletSdk/Auth/index.ts +108 -35
  41. package/src/walletSdk/Exceptions/index.ts +103 -0
  42. package/src/walletSdk/Horizon/Account.ts +50 -0
  43. package/src/walletSdk/Horizon/AccountService.ts +19 -0
  44. package/src/walletSdk/Horizon/Stellar.ts +76 -0
  45. package/src/walletSdk/Horizon/index.ts +3 -0
  46. package/src/walletSdk/Horizon/transaction/TransactionBuilder.ts +65 -0
  47. package/src/walletSdk/Recovery/index.ts +32 -0
  48. package/src/walletSdk/Types/anchor.ts +174 -0
  49. package/src/walletSdk/Types/auth.ts +43 -0
  50. package/src/walletSdk/Types/horizon.ts +14 -0
  51. package/src/walletSdk/Types/index.ts +39 -0
  52. package/src/walletSdk/Types/sep24.ts +41 -0
  53. package/src/walletSdk/Types/utils.ts +77 -0
  54. package/src/walletSdk/Types/watcher.ts +34 -0
  55. package/src/walletSdk/Utils/camelToSnakeCase.ts +16 -0
  56. package/src/walletSdk/Utils/index.ts +3 -0
  57. package/src/walletSdk/Utils/toml.ts +103 -0
  58. package/src/walletSdk/{util → Utils}/url.ts +1 -1
  59. package/src/walletSdk/Watcher/index.ts +364 -0
  60. package/src/walletSdk/index.ts +90 -60
  61. package/test/account.test.ts +37 -0
  62. package/test/fixtures/TransactionsResponse.ts +247 -0
  63. package/test/stellar.test.ts +65 -0
  64. package/test/wallet.test.ts +1704 -0
  65. package/tsconfig.json +3 -7
  66. package/webpack.config.js +2 -0
  67. package/src/walletSdk/exception/index.ts +0 -27
  68. package/src/walletSdk/horizon/Account.ts +0 -0
  69. package/src/walletSdk/horizon/AccountService.ts +0 -0
  70. package/src/walletSdk/horizon/Stellar.ts +0 -6
  71. package/src/walletSdk/horizon/constants.ts +0 -4
  72. package/src/walletSdk/interactive/index.ts +0 -103
  73. package/src/walletSdk/recovery/Recovery.ts +0 -6
  74. package/src/walletSdk/toml/index.ts +0 -179
  75. package/test/index.test.ts +0 -73
package/lib/index.d.ts CHANGED
@@ -1,3 +1,28 @@
1
+ /**
2
+ * Types
3
+ */
4
+ import * as Types from "./walletSdk/Types";
5
+ export { Types };
6
+ /**
7
+ * Classes
8
+ */
9
+ export { Wallet, Config, StellarConfiguration, ApplicationConfiguration, } from "./walletSdk";
10
+ export { Anchor } from "./walletSdk/Anchor";
11
+ export { Sep10, WalletSigner, DefaultSigner } from "./walletSdk/Auth";
12
+ export { PublicKeypair, SigningKeypair, AccountService, Stellar, } from "./walletSdk/Horizon";
13
+ export { Sep24 } from "./walletSdk/Anchor/Sep24";
14
+ export { Recovery } from "./walletSdk/Recovery";
15
+ export { Watcher } from "./walletSdk/Watcher";
16
+ /**
17
+ * Utils
18
+ */
19
+ import * as Utils from "./walletSdk/Utils";
20
+ export { Utils };
21
+ /**
22
+ * Exceptions
23
+ */
24
+ import * as Exceptions from "./walletSdk/Exceptions";
25
+ export { Exceptions };
1
26
  import * as walletSdk from "./walletSdk";
2
27
  import { Keypair } from "stellar-sdk";
3
28
  export { walletSdk, Keypair };
@@ -0,0 +1,41 @@
1
+ import { Networks, Horizon } from "stellar-sdk";
2
+ import { AnchorTransaction, FLOW_TYPE } from "../Types";
3
+ export declare class ServerRequestFailedError extends Error {
4
+ constructor(e: Error);
5
+ }
6
+ export declare class AssetNotSupportedError extends Error {
7
+ constructor(type: FLOW_TYPE, assetCode: string);
8
+ }
9
+ export declare class InvalidMemoError extends Error {
10
+ constructor();
11
+ }
12
+ export declare class ClientDomainWithMemoError extends Error {
13
+ constructor();
14
+ }
15
+ export declare class MissingTransactionIdError extends Error {
16
+ constructor();
17
+ }
18
+ export declare class InvalidTransactionResponseError extends Error {
19
+ constructor(transactionResponse: AnchorTransaction);
20
+ }
21
+ export declare class InvalidTransactionsResponseError extends Error {
22
+ constructor(transactionsResponse: AnchorTransaction[]);
23
+ }
24
+ export declare class AccountDoesNotExistError extends Error {
25
+ constructor(network: Networks);
26
+ }
27
+ export declare class TransactionSubmitFailedError extends Error {
28
+ constructor(response: Horizon.SubmitTransactionResponse);
29
+ }
30
+ export declare class InsufficientStartingBalanceError extends Error {
31
+ constructor();
32
+ }
33
+ export declare class MissingTokenError extends Error {
34
+ constructor();
35
+ }
36
+ export declare class InvalidTokenError extends Error {
37
+ constructor();
38
+ }
39
+ export declare class ExpiredTokenError extends Error {
40
+ constructor(expiresAt: number);
41
+ }
@@ -0,0 +1,148 @@
1
+ import { MemoType } from "stellar-sdk";
2
+ import { Optional } from "utility-types";
3
+ export interface AnchorServiceInfo {
4
+ deposit: AssetInfoMap;
5
+ withdraw: AssetInfoMap;
6
+ fee: {
7
+ enabled: boolean;
8
+ };
9
+ features: {
10
+ account_creation: boolean;
11
+ claimable_balances: boolean;
12
+ };
13
+ }
14
+ export interface AssetInfoMap {
15
+ [asset_code: string]: AnchorServiceAsset;
16
+ }
17
+ export interface AnchorServiceAsset {
18
+ enabled: boolean;
19
+ min_amount: number;
20
+ max_amount: number;
21
+ fee_fixed: number;
22
+ fee_percent: number;
23
+ }
24
+ export interface BaseTransaction {
25
+ id: string;
26
+ kind: string;
27
+ status: TransactionStatus;
28
+ more_info_url: string;
29
+ started_at: string;
30
+ message?: string;
31
+ }
32
+ export interface ProcessingAnchorTransaction extends BaseTransaction {
33
+ status_eta?: number;
34
+ kyc_verified?: boolean;
35
+ amount_in_asset?: string;
36
+ amount_in: string;
37
+ amount_out_asset?: string;
38
+ amount_out: string;
39
+ amount_fee_asset?: string;
40
+ amount_fee: string;
41
+ completed_at?: string;
42
+ stellar_transaction_id?: string;
43
+ external_transaction_id?: string;
44
+ refunds?: Refunds;
45
+ }
46
+ export interface DepositTransaction extends ProcessingAnchorTransaction {
47
+ from?: string;
48
+ to?: string;
49
+ deposit_memo?: string;
50
+ deposit_memo_type?: MemoType;
51
+ claimable_balance_id?: string;
52
+ }
53
+ export interface WithdrawTransaction extends ProcessingAnchorTransaction {
54
+ from: string;
55
+ to?: string;
56
+ withdraw_memo?: string;
57
+ withdraw_memo_type: MemoType;
58
+ withdraw_anchor_account: string;
59
+ }
60
+ export interface ErrorTransaction extends Optional<DepositTransaction & WithdrawTransaction> {
61
+ }
62
+ export type AnchorTransaction = DepositTransaction | WithdrawTransaction | ErrorTransaction;
63
+ export interface Refunds {
64
+ amount_refunded: string;
65
+ amount_fee: string;
66
+ payments: Payment[];
67
+ }
68
+ export interface Payment {
69
+ id: string;
70
+ id_type: string;
71
+ amount: string;
72
+ fee: string;
73
+ }
74
+ export type GetTransactionParams = {
75
+ authToken: string;
76
+ id?: string;
77
+ stellarTransactionId?: string;
78
+ externalTransactionId?: string;
79
+ lang?: string;
80
+ };
81
+ export type GetTransactionsParams = {
82
+ authToken: string;
83
+ assetCode: string;
84
+ noOlderThan?: string;
85
+ limit?: number;
86
+ kind?: string;
87
+ pagingId?: string;
88
+ lang?: string;
89
+ };
90
+ export declare enum TransactionStatus {
91
+ /**
92
+ * There is not yet enough information for this transaction to be initiated. Perhaps the user has
93
+ * not yet entered necessary info in an interactive flow
94
+ */
95
+ incomplete = "incomplete",
96
+ /**
97
+ * The user has not yet initiated their transfer to the anchor. This is the next necessary step in
98
+ * any deposit or withdrawal flow after transitioning from `incomplete`
99
+ */
100
+ pending_user_transfer_start = "pending_user_transfer_start",
101
+ /**
102
+ * The Stellar payment has been successfully received by the anchor and the off-chain funds are
103
+ * available for the customer to pick up. Only used for withdrawal transactions.
104
+ */
105
+ pending_user_transfer_complete = "pending_user_transfer_complete",
106
+ /**
107
+ * Pending External deposit/withdrawal has been submitted to external network, but is not yet
108
+ * confirmed. This is the status when waiting on Bitcoin or other external crypto network to
109
+ * complete a transaction, or when waiting on a bank transfer.
110
+ */
111
+ pending_external = "pending_external",
112
+ /**
113
+ * Deposit/withdrawal is being processed internally by anchor. This can also be used when the
114
+ * anchor must verify KYC information prior to deposit/withdrawal.
115
+ */
116
+ pending_anchor = "pending_anchor",
117
+ /**
118
+ * Deposit/withdrawal operation has been submitted to Stellar network, but is not yet confirmed.
119
+ */
120
+ pending_stellar = "pending_stellar",
121
+ /** The user must add a trustline for the asset for the deposit to complete. */
122
+ pending_trust = "pending_trust",
123
+ /**
124
+ * The user must take additional action before the deposit / withdrawal can complete, for example
125
+ * an email or 2fa confirmation of a withdrawal.
126
+ */
127
+ pending_user = "pending_user",
128
+ /** Deposit/withdrawal fully completed */
129
+ completed = "completed",
130
+ /** The deposit/withdrawal is fully refunded */
131
+ refunded = "refunded",
132
+ /**
133
+ * Funds were never received by the anchor and the transaction is considered abandoned by the
134
+ * user. Anchors are responsible for determining when transactions are considered expired.
135
+ */
136
+ expired = "expired",
137
+ /**
138
+ * Could not complete deposit because no satisfactory asset/XLM market was available to create the
139
+ * account
140
+ */
141
+ no_market = "no_market",
142
+ /** Deposit/withdrawal size less than min_amount. */
143
+ too_small = "too_small",
144
+ /** Deposit/withdrawal size exceeded max_amount. */
145
+ too_large = "too_large",
146
+ /** Catch-all for any error not enumerated above. */
147
+ error = "error"
148
+ }
@@ -0,0 +1,35 @@
1
+ import { Transaction } from "stellar-sdk";
2
+ import { WalletSigner } from "../Auth/WalletSigner";
3
+ import { AccountKeypair } from "../Horizon/Account";
4
+ export type AuthenticateParams = {
5
+ accountKp: AccountKeypair;
6
+ walletSigner?: WalletSigner;
7
+ memoId?: string;
8
+ clientDomain?: string;
9
+ };
10
+ export type AuthToken = string;
11
+ export type ChallengeParams = {
12
+ accountKp: AccountKeypair;
13
+ memoId?: string;
14
+ clientDomain?: string;
15
+ };
16
+ export type XdrEncodedTransaction = string;
17
+ export type NetworkPassphrase = string;
18
+ export type ChallengeResponse = {
19
+ transaction: XdrEncodedTransaction;
20
+ network_passphrase: NetworkPassphrase;
21
+ };
22
+ export type SignParams = {
23
+ accountKp: AccountKeypair;
24
+ challengeResponse: ChallengeResponse;
25
+ walletSigner: WalletSigner;
26
+ };
27
+ export type SignWithClientAccountParams = {
28
+ transaction: Transaction;
29
+ accountKp: AccountKeypair;
30
+ };
31
+ export type SignWithDomainAccountParams = {
32
+ transactionXDR: XdrEncodedTransaction;
33
+ networkPassphrase: NetworkPassphrase;
34
+ accountKp: AccountKeypair;
35
+ };
@@ -0,0 +1,12 @@
1
+ import { Memo, Server } from "stellar-sdk";
2
+ import { AccountKeypair } from "../Horizon/Account";
3
+ export declare enum NETWORK_URLS {
4
+ PUBLIC = "https://horizon.stellar.org",
5
+ TESTNET = "https://horizon-testnet.stellar.org"
6
+ }
7
+ export type TransactionParams = {
8
+ sourceAddress: AccountKeypair;
9
+ baseFee: number;
10
+ memo?: Memo;
11
+ timebounds?: Server.Timebounds | number;
12
+ };
@@ -0,0 +1,30 @@
1
+ import { Server, Networks } from "stellar-sdk";
2
+ import { ApplicationConfiguration, StellarConfiguration } from "walletSdk";
3
+ export type WalletParams = {
4
+ stellarConfiguration: StellarConfiguration;
5
+ applicationConfiguration?: ApplicationConfiguration;
6
+ language?: string;
7
+ };
8
+ export type WalletAnchor = {
9
+ homeDomain: string;
10
+ language?: string;
11
+ };
12
+ export type WalletRecovery = {
13
+ servers: Server[];
14
+ };
15
+ export type ConfigParams = {
16
+ stellarConfiguration: StellarConfiguration;
17
+ applicationConfiguration?: ApplicationConfiguration;
18
+ };
19
+ export type StellarConfigurationParams = {
20
+ network: Networks;
21
+ horizonUrl: string;
22
+ baseFee?: number;
23
+ defaultTimeout?: number;
24
+ };
25
+ export * from "./anchor";
26
+ export * from "./auth";
27
+ export * from "./horizon";
28
+ export * from "./sep24";
29
+ export * from "./utils";
30
+ export * from "./watcher";
@@ -0,0 +1,30 @@
1
+ import { Memo } from "stellar-sdk";
2
+ import { AuthToken } from "./auth";
3
+ export declare enum FLOW_TYPE {
4
+ DEPOSIT = "deposit",
5
+ WITHDRAW = "withdraw"
6
+ }
7
+ export type ExtraFields = {
8
+ [api_key: string]: string;
9
+ };
10
+ export type Sep24PostParams = {
11
+ authToken: AuthToken;
12
+ assetCode: string;
13
+ lang?: string;
14
+ extraFields?: ExtraFields;
15
+ destinationMemo?: Memo;
16
+ destinationAccount?: string;
17
+ withdrawalAccount?: string;
18
+ account?: string;
19
+ };
20
+ export declare enum Sep24ResponseType {
21
+ authentication_required = "authentication_required",
22
+ interactive_customer_info_needed = "interactive_customer_info_needed",
23
+ error = "error"
24
+ }
25
+ export interface Sep24PostResponse {
26
+ type: Sep24ResponseType.authentication_required | Sep24ResponseType.interactive_customer_info_needed | Sep24ResponseType.error;
27
+ id?: string;
28
+ url?: string;
29
+ error?: string;
30
+ }
@@ -0,0 +1,77 @@
1
+ export type TomlInfo = {
2
+ version: string;
3
+ networkPassphrase: string;
4
+ federationServer: string;
5
+ authServer: string;
6
+ transferServer: string;
7
+ transferServerSep24: string;
8
+ kycServer: string;
9
+ webAuthEndpoint: string;
10
+ signingKey: string;
11
+ horizonUrl: string;
12
+ accounts: Array<string>;
13
+ uriRequestSigningKey: string;
14
+ directPaymentServer: string;
15
+ anchorQuoteServer: string;
16
+ documentation: {
17
+ orgName: string;
18
+ orgDba: string;
19
+ orgUrl: string;
20
+ orgLogo: string;
21
+ orgDescription: string;
22
+ orgPhysicalAddress: string;
23
+ orgPhysicalAddressAttestation: string;
24
+ orgPhoneNumber: string;
25
+ orgPhoneNumberAttestation: string;
26
+ orgKeybase: string;
27
+ orgTwitter: string;
28
+ orgGithub: string;
29
+ orgOfficialEmail: string;
30
+ orgSupportEmail: string;
31
+ orgLicensingAuthority: string;
32
+ orgLicenseType: string;
33
+ orgLicenseNumber: string;
34
+ };
35
+ principals: Array<{
36
+ name: string;
37
+ email: string;
38
+ keybase: string;
39
+ telegram: string;
40
+ twitter: string;
41
+ github: string;
42
+ idPhotoHash: string;
43
+ verificationPhotoHash: string;
44
+ }>;
45
+ currencies: Array<{
46
+ code: string;
47
+ codeTemplate: string;
48
+ issuer: string;
49
+ status: string;
50
+ displayDecimals: number;
51
+ name: string;
52
+ desc: string;
53
+ conditions: string;
54
+ image: string;
55
+ fixedNumber: number;
56
+ maxNumber: number;
57
+ isUnlimited: boolean;
58
+ isAssetAnchored: boolean;
59
+ anchorAssetType: string;
60
+ anchorAsset: string;
61
+ attestationOfReserve: string;
62
+ redemptionInstructions: string;
63
+ collateralAddresses: Array<string>;
64
+ collateralAddressMessages: Array<string>;
65
+ collateralAddressSignatures: Array<string>;
66
+ regulated: boolean;
67
+ approvalServer: string;
68
+ approvalCriteria: string;
69
+ }>;
70
+ validators: Array<{
71
+ alias: string;
72
+ displayName: string;
73
+ publicKey: string;
74
+ host: string;
75
+ history: string;
76
+ }>;
77
+ };
@@ -0,0 +1,30 @@
1
+ import { AnchorTransaction } from "./anchor";
2
+ export type WatchTransactionsParams = {
3
+ authToken: string;
4
+ assetCode: string;
5
+ onMessage: (transaction: AnchorTransaction) => void;
6
+ onError: (error: AnchorTransaction | Error) => void;
7
+ watchlist?: string[];
8
+ timeout?: number;
9
+ isRetry?: boolean;
10
+ lang?: string;
11
+ kind?: string;
12
+ noOlderThan?: string;
13
+ };
14
+ export type WatchTransactionParams = {
15
+ authToken: string;
16
+ assetCode: string;
17
+ id: string;
18
+ onMessage: (transaction: AnchorTransaction) => void;
19
+ onSuccess: (transaction: AnchorTransaction) => void;
20
+ onError: (error: AnchorTransaction | Error) => void;
21
+ timeout?: number;
22
+ isRetry?: boolean;
23
+ lang?: string;
24
+ };
25
+ export type WatcherRefreshFunction = () => void;
26
+ export type WatcherStopFunction = () => void;
27
+ export interface WatcherResponse {
28
+ refresh: WatcherRefreshFunction;
29
+ stop: WatcherStopFunction;
30
+ }
@@ -0,0 +1,2 @@
1
+ export declare const camelToSnakeCaseKey: (key: string) => string;
2
+ export declare const camelToSnakeCaseObject: (obj: any) => any;
@@ -0,0 +1,3 @@
1
+ export * from "./camelToSnakeCase";
2
+ export * from "./toml";
3
+ export * from "./url";
@@ -0,0 +1,3 @@
1
+ import { StellarTomlResolver } from "stellar-sdk";
2
+ import { TomlInfo } from "../Types";
3
+ export declare const parseToml: (toml: StellarTomlResolver.StellarToml) => TomlInfo;
@@ -0,0 +1 @@
1
+ export declare const getUrlDomain: (url: string) => any;
@@ -0,0 +1,65 @@
1
+ export declare enum TransactionStatus {
2
+ /**
3
+ * There is not yet enough information for this transaction to be initiated. Perhaps the user has
4
+ * not yet entered necessary info in an interactive flow
5
+ */
6
+ incomplete = "incomplete",
7
+ /**
8
+ * The user has not yet initiated their transfer to the anchor. This is the next necessary step in
9
+ * any deposit or withdrawal flow after transitioning from `incomplete`
10
+ */
11
+ pending_user_transfer_start = "pending_user_transfer_start",
12
+ /**
13
+ * The Stellar payment has been successfully received by the anchor and the off-chain funds are
14
+ * available for the customer to pick up. Only used for withdrawal transactions.
15
+ */
16
+ pending_user_transfer_complete = "pending_user_transfer_complete",
17
+ /**
18
+ * Pending External deposit/withdrawal has been submitted to external network, but is not yet
19
+ * confirmed. This is the status when waiting on Bitcoin or other external crypto network to
20
+ * complete a transaction, or when waiting on a bank transfer.
21
+ */
22
+ pending_external = "pending_external",
23
+ /**
24
+ * Deposit/withdrawal is being processed internally by anchor. This can also be used when the
25
+ * anchor must verify KYC information prior to deposit/withdrawal.
26
+ */
27
+ pending_anchor = "pending_anchor",
28
+ /**
29
+ * Deposit/withdrawal operation has been submitted to Stellar network, but is not yet confirmed.
30
+ */
31
+ pending_stellar = "pending_stellar",
32
+ /** The user must add a trustline for the asset for the deposit to complete. */
33
+ pending_trust = "pending_trust",
34
+ /**
35
+ * The user must take additional action before the deposit / withdrawal can complete, for example
36
+ * an email or 2fa confirmation of a withdrawal.
37
+ */
38
+ pending_user = "pending_user",
39
+ /** Deposit/withdrawal fully completed */
40
+ completed = "completed",
41
+ /** The deposit/withdrawal is fully refunded */
42
+ refunded = "refunded",
43
+ /**
44
+ * Funds were never received by the anchor and the transaction is considered abandoned by the
45
+ * user. Anchors are responsible for determining when transactions are considered expired.
46
+ */
47
+ expired = "expired",
48
+ /**
49
+ * Could not complete deposit because no satisfactory asset/XLM market was available to create the
50
+ * account
51
+ */
52
+ no_market = "no_market",
53
+ /** Deposit/withdrawal size less than min_amount. */
54
+ too_small = "too_small",
55
+ /** Deposit/withdrawal size exceeded max_amount. */
56
+ too_large = "too_large",
57
+ /** Catch-all for any error not enumerated above. */
58
+ error = "error"
59
+ }
60
+ export type WatcherRefreshFunction = () => void;
61
+ export type WatcherStopFunction = () => void;
62
+ export interface WatcherResponse {
63
+ refresh: WatcherRefreshFunction;
64
+ stop: WatcherStopFunction;
65
+ }
@@ -0,0 +1,33 @@
1
+ import { Anchor } from "../Anchor";
2
+ import { WatchTransactionParams, WatchTransactionsParams, WatcherResponse } from "../Types";
3
+ export declare class Watcher {
4
+ private anchor;
5
+ private _oneTransactionWatcher;
6
+ private _allTransactionsWatcher?;
7
+ private _watchOneTransactionRegistry;
8
+ private _watchAllTransactionsRegistry;
9
+ private _transactionsRegistry;
10
+ private _transactionsIgnoredRegistry;
11
+ constructor(anchor: Anchor);
12
+ /**
13
+ * Watch all transactions returned from a transfer server. When new or
14
+ * updated transactions come in, run an `onMessage` callback.
15
+ *
16
+ * On initial load, it'll return ALL pending transactions via onMessage.
17
+ * Subsequent messages will be any one of these events:
18
+ * - Any new transaction appears
19
+ * - Any of the initial pending transactions change any state
20
+ *
21
+ * You may also provide an array of transaction ids, `watchlist`, and this
22
+ * watcher will always react to transactions whose ids are in the watchlist.
23
+ */
24
+ watchAllTransactions({ authToken, assetCode, onMessage, onError, watchlist, timeout, isRetry, lang, kind, noOlderThan, }: WatchTransactionsParams): WatcherResponse;
25
+ /**
26
+ * Watch a transaction until it stops pending. Takes three callbacks:
27
+ * * onMessage - When the transaction comes back as pending_ or incomplete.
28
+ * * onSuccess - When the transaction comes back as completed / refunded / expired.
29
+ * * onError - When there's a runtime error, or the transaction comes back as
30
+ * no_market / too_small / too_large / error.
31
+ */
32
+ watchOneTransaction({ authToken, assetCode, id, onMessage, onSuccess, onError, timeout, isRetry, lang, }: WatchTransactionParams): WatcherResponse;
33
+ }
@@ -0,0 +1,48 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { Anchor } from "../Anchor";
3
+ import { Sep24PostParams, Sep24PostResponse, AnchorTransaction, GetTransactionParams, GetTransactionsParams, AnchorServiceInfo } from "../Types";
4
+ import { Watcher } from "../Watcher";
5
+ type Sep24Params = {
6
+ anchor: Anchor;
7
+ httpClient: AxiosInstance;
8
+ };
9
+ export declare class Sep24 {
10
+ private anchor;
11
+ private httpClient;
12
+ constructor(params: Sep24Params);
13
+ deposit({ assetCode, authToken, lang, extraFields, destinationMemo, destinationAccount, }: Sep24PostParams): Promise<Sep24PostResponse>;
14
+ withdraw({ assetCode, authToken, lang, extraFields, withdrawalAccount, }: Sep24PostParams): Promise<Sep24PostResponse>;
15
+ private flow;
16
+ getServicesInfo(): Promise<AnchorServiceInfo>;
17
+ watcher(): Watcher;
18
+ /**
19
+ * Get single transaction's current status and details. One of the [id], [stellarTransactionId],
20
+ * [externalTransactionId] must be provided.
21
+ *
22
+ * @param authToken auth token of the account authenticated with the anchor
23
+ * @param id transaction ID
24
+ * @param stellarTransactionId stellar transaction ID
25
+ * @param externalTransactionId external transaction ID
26
+ * @return transaction object
27
+ * @throws [MissingTransactionIdError] if none of the id params is provided
28
+ * @throws [InvalidTransactionResponseError] if Anchor returns an invalid transaction
29
+ * @throws [ServerRequestFailedError] if server request fails
30
+ */
31
+ getTransactionBy({ authToken, id, stellarTransactionId, externalTransactionId, lang, }: GetTransactionParams): Promise<AnchorTransaction>;
32
+ /**
33
+ * Get account's transactions specified by asset and other params.
34
+ *
35
+ * @param authToken auth token of the account authenticated with the anchor
36
+ * @param assetCode target asset to query for
37
+ * @param noOlderThan response should contain transactions starting on or after this date & time
38
+ * @param limit response should contain at most 'limit' transactions
39
+ * @param kind kind of transaction that is desired. E.g.: 'deposit', 'withdrawal'
40
+ * @param pagingId response should contain transactions starting prior to this ID (exclusive)
41
+ * @param lang desired language (localization), it can also accept locale in the format 'en-US'
42
+ * @return list of transactions as requested by the client, sorted in time-descending order
43
+ * @throws [InvalidTransactionsResponseError] if Anchor returns an invalid response
44
+ * @throws [ServerRequestFailedError] if server request fails
45
+ */
46
+ getTransactionsForAsset({ authToken, assetCode, noOlderThan, limit, kind, pagingId, lang, }: GetTransactionsParams): Promise<AnchorTransaction[]>;
47
+ }
48
+ export {};
@@ -1,16 +1,24 @@
1
- import { Auth } from "../Auth";
2
- import { Interactive } from "../interactive";
3
- import { TomlInfo } from "../toml";
1
+ import { AxiosInstance } from "axios";
2
+ import { Config } from "walletSdk";
3
+ import { Sep10 } from "../Auth";
4
+ import { Sep24 } from "./Sep24";
5
+ import { AnchorServiceInfo, TomlInfo } from "../Types";
6
+ type AnchorParams = {
7
+ cfg: Config;
8
+ homeDomain: string;
9
+ httpClient: AxiosInstance;
10
+ language: string;
11
+ };
4
12
  export declare class Anchor {
13
+ language: string;
14
+ private cfg;
5
15
  private homeDomain;
6
16
  private httpClient;
7
- private cfg;
8
- constructor(cfg: any, homeDomain: string, httpClient: any);
9
- getInfo(): Promise<TomlInfo>;
10
- auth(): Promise<Auth>;
11
- interactive(): Interactive;
12
- getServicesInfo(): Promise<any>;
13
- getTransaction(): void;
14
- getTransactionForAsset(): void;
15
- getHistory(): void;
17
+ private toml;
18
+ constructor(params: AnchorParams);
19
+ sep1(shouldRefresh?: boolean): Promise<TomlInfo>;
20
+ sep10(): Promise<Sep10>;
21
+ sep24(): Sep24;
22
+ getServicesInfo(lang?: string): Promise<AnchorServiceInfo>;
16
23
  }
24
+ export {};
@@ -1,3 +1,7 @@
1
+ import { Transaction } from "stellar-sdk";
2
+ import { SignWithClientAccountParams, SignWithDomainAccountParams } from "../Types";
1
3
  export interface WalletSigner {
4
+ signWithClientAccount({ transaction, accountKp, }: SignWithClientAccountParams): Transaction;
5
+ signWithDomainAccount({ transactionXDR, networkPassphrase, accountKp, }: SignWithDomainAccountParams): Promise<Transaction>;
2
6
  }
3
7
  export declare const DefaultSigner: WalletSigner;