@stellar/typescript-wallet-sdk 1.2.0 → 1.3.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 (96) hide show
  1. package/.eslintrc.js +76 -0
  2. package/.github/workflows/integrationTest.yml +19 -0
  3. package/.github/workflows/runTests.yml +14 -0
  4. package/.husky/pre-commit +1 -0
  5. package/README.md +19 -12
  6. package/examples/sep24/.env.example +4 -0
  7. package/examples/sep24/README.md +17 -0
  8. package/examples/sep24/sep24.ts +69 -14
  9. package/examples/tsconfig.json +10 -0
  10. package/jest.config.js +1 -0
  11. package/jest.integration.config.js +9 -0
  12. package/lib/bundle.js +6929 -2377
  13. package/lib/bundle.js.map +1 -1
  14. package/lib/bundle_browser.js +6915 -2410
  15. package/lib/bundle_browser.js.map +1 -1
  16. package/lib/index.d.ts +1 -1
  17. package/lib/walletSdk/Anchor/Sep24.d.ts +65 -22
  18. package/lib/walletSdk/Anchor/Sep38.d.ts +56 -0
  19. package/lib/walletSdk/Anchor/Sep6.d.ts +127 -0
  20. package/lib/walletSdk/Anchor/index.d.ts +91 -1
  21. package/lib/walletSdk/Asset/index.d.ts +11 -1
  22. package/lib/walletSdk/Auth/WalletSigner.d.ts +41 -1
  23. package/lib/walletSdk/Auth/index.d.ts +21 -0
  24. package/lib/walletSdk/Customer/index.d.ts +70 -0
  25. package/lib/walletSdk/Exceptions/index.d.ts +45 -2
  26. package/lib/walletSdk/Horizon/AccountService.d.ts +30 -20
  27. package/lib/walletSdk/Horizon/Stellar.d.ts +79 -2
  28. package/lib/walletSdk/Horizon/Transaction/CommonTransactionBuilder.d.ts +57 -0
  29. package/lib/walletSdk/Horizon/Transaction/SponsoringBuilder.d.ts +38 -0
  30. package/lib/walletSdk/Horizon/Transaction/TransactionBuilder.d.ts +112 -11
  31. package/lib/walletSdk/Horizon/index.d.ts +3 -1
  32. package/lib/walletSdk/Recovery/AccountRecover.d.ts +58 -0
  33. package/lib/walletSdk/Recovery/index.d.ts +69 -7
  34. package/lib/walletSdk/Types/anchor.d.ts +17 -2
  35. package/lib/walletSdk/Types/auth.d.ts +14 -1
  36. package/lib/walletSdk/Types/horizon.d.ts +17 -6
  37. package/lib/walletSdk/Types/index.d.ts +15 -3
  38. package/lib/walletSdk/Types/recovery.d.ts +128 -0
  39. package/lib/walletSdk/Types/sep12.d.ts +57 -0
  40. package/lib/walletSdk/Types/sep38.d.ts +93 -0
  41. package/lib/walletSdk/Types/sep6.d.ts +160 -0
  42. package/lib/walletSdk/Types/watcher.d.ts +7 -2
  43. package/lib/walletSdk/Utils/extractAxiosErrorData.d.ts +2 -0
  44. package/lib/walletSdk/Utils/index.d.ts +1 -0
  45. package/lib/walletSdk/Utils/toml.d.ts +2 -2
  46. package/lib/walletSdk/Watcher/getTransactions.d.ts +8 -0
  47. package/lib/walletSdk/Watcher/index.d.ts +41 -4
  48. package/lib/walletSdk/index.d.ts +43 -5
  49. package/package.json +17 -4
  50. package/src/index.ts +2 -0
  51. package/src/walletSdk/Anchor/Sep24.ts +93 -86
  52. package/src/walletSdk/Anchor/Sep38.ts +180 -0
  53. package/src/walletSdk/Anchor/Sep6.ts +291 -0
  54. package/src/walletSdk/Anchor/index.ts +138 -5
  55. package/src/walletSdk/Asset/index.ts +21 -4
  56. package/src/walletSdk/Auth/WalletSigner.ts +23 -5
  57. package/src/walletSdk/Auth/index.ts +24 -5
  58. package/src/walletSdk/Customer/index.ts +174 -0
  59. package/src/walletSdk/Exceptions/index.ts +115 -4
  60. package/src/walletSdk/Horizon/AccountService.ts +33 -21
  61. package/src/walletSdk/Horizon/Stellar.ts +89 -5
  62. package/src/walletSdk/Horizon/Transaction/CommonTransactionBuilder.ts +43 -4
  63. package/src/walletSdk/Horizon/Transaction/SponsoringBuilder.ts +30 -7
  64. package/src/walletSdk/Horizon/Transaction/TransactionBuilder.ts +88 -15
  65. package/src/walletSdk/Horizon/index.ts +2 -1
  66. package/src/walletSdk/Recovery/AccountRecover.ts +255 -0
  67. package/src/walletSdk/Recovery/index.ts +314 -13
  68. package/src/walletSdk/Types/anchor.ts +23 -2
  69. package/src/walletSdk/Types/auth.ts +36 -2
  70. package/src/walletSdk/Types/horizon.ts +7 -5
  71. package/src/walletSdk/Types/index.ts +17 -4
  72. package/src/walletSdk/Types/recovery.ts +152 -0
  73. package/src/walletSdk/Types/sep12.ts +61 -0
  74. package/src/walletSdk/Types/sep38.ts +106 -0
  75. package/src/walletSdk/Types/sep6.ts +168 -0
  76. package/src/walletSdk/Types/watcher.ts +8 -2
  77. package/src/walletSdk/Utils/camelToSnakeCase.ts +1 -0
  78. package/src/walletSdk/Utils/extractAxiosErrorData.ts +28 -0
  79. package/src/walletSdk/Utils/index.ts +1 -0
  80. package/src/walletSdk/Utils/toml.ts +2 -2
  81. package/src/walletSdk/Watcher/getTransactions.ts +65 -0
  82. package/src/walletSdk/Watcher/index.ts +70 -9
  83. package/src/walletSdk/index.ts +45 -8
  84. package/test/README.md +18 -0
  85. package/test/accountService.test.ts +21 -3
  86. package/test/customer.test.ts +82 -0
  87. package/test/docker/docker-compose.yml +97 -0
  88. package/test/integration.test.ts +166 -0
  89. package/test/recovery.test.ts +107 -0
  90. package/test/sep38.test.ts +71 -0
  91. package/test/sep6.test.ts +240 -0
  92. package/test/stellar.test.ts +57 -12
  93. package/test/transaction.test.ts +8 -10
  94. package/test/tsconfig.json +10 -0
  95. package/test/utils/index.ts +12 -0
  96. package/test/wallet.test.ts +60 -21
@@ -1,6 +1,7 @@
1
1
  import { Networks, Horizon } from "stellar-sdk";
2
- import { AnchorTransaction, FLOW_TYPE } from "../Types";
2
+ import { AnchorTransaction, FLOW_TYPE, AxiosErrorData, GetCustomerParams } from "../Types";
3
3
  export declare class ServerRequestFailedError extends Error {
4
+ data: AxiosErrorData;
4
5
  constructor(e: Error);
5
6
  }
6
7
  export declare class AssetNotSupportedError extends Error {
@@ -25,7 +26,7 @@ export declare class AccountDoesNotExistError extends Error {
25
26
  constructor(network: Networks);
26
27
  }
27
28
  export declare class TransactionSubmitFailedError extends Error {
28
- constructor(response: Horizon.SubmitTransactionResponse);
29
+ constructor(response: Horizon.HorizonApi.SubmitTransactionResponse);
29
30
  }
30
31
  export declare class InsufficientStartingBalanceError extends Error {
31
32
  constructor();
@@ -54,6 +55,48 @@ export declare class WithdrawalTxNotPendingUserTransferStartError extends Error
54
55
  export declare class WithdrawalTxMissingMemoError extends Error {
55
56
  constructor();
56
57
  }
58
+ export declare class PathPayOnlyOneAmountError extends Error {
59
+ constructor();
60
+ }
57
61
  export declare class WithdrawalTxMemoError extends Error {
58
62
  constructor();
59
63
  }
64
+ export declare class Sep9InfoRequiredError extends Error {
65
+ constructor();
66
+ }
67
+ export declare class CustomerNotFoundError extends Error {
68
+ constructor(params: GetCustomerParams);
69
+ }
70
+ export declare class KYCServerNotFoundError extends Error {
71
+ constructor();
72
+ }
73
+ export declare class RecoveryServerNotFoundError extends Error {
74
+ constructor(serverKey: string);
75
+ }
76
+ export declare class RecoveryIdentityNotFoundError extends Error {
77
+ constructor(serverKey: string);
78
+ }
79
+ export declare class NotAllSignaturesFetchedError extends Error {
80
+ constructor();
81
+ }
82
+ export declare class LostSignerKeyNotFound extends Error {
83
+ constructor();
84
+ }
85
+ export declare class NoDeviceKeyForAccountError extends Error {
86
+ constructor();
87
+ }
88
+ export declare class UnableToDeduceKeyError extends Error {
89
+ constructor();
90
+ }
91
+ export declare class NoAccountSignersError extends Error {
92
+ constructor();
93
+ }
94
+ export declare class DeviceKeyEqualsMasterKeyError extends Error {
95
+ constructor();
96
+ }
97
+ export declare class NoAccountAndNoSponsorError extends Error {
98
+ constructor();
99
+ }
100
+ export declare class Sep38PriceOnlyOneAmountError extends Error {
101
+ constructor();
102
+ }
@@ -1,47 +1,57 @@
1
1
  /// <reference types="node" />
2
- import { Server, ServerApi } from "stellar-sdk";
2
+ import { Horizon } from "stellar-sdk";
3
3
  import { Config } from "walletSdk";
4
4
  import { SigningKeypair } from "./Account";
5
5
  import { HORIZON_ORDER } from "../Types";
6
+ /**
7
+ * KYC management with Sep-12.
8
+ * @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md}
9
+ * Do not create this object directly, use the Stellar class.
10
+ * @class
11
+ */
6
12
  export declare class AccountService {
7
13
  private server;
8
14
  private network;
15
+ /**
16
+ * Creates a new instance of the AccountService class.
17
+ * @constructor
18
+ * @param {Config} cfg - Configuration for the service.
19
+ */
9
20
  constructor(cfg: Config);
10
21
  /**
11
22
  * Generate new account keypair (public and secret key). This key pair can be
12
23
  * used to create a Stellar account.
13
- *
14
- * @return public key and secret key
24
+ * @returns {SigningKeypair} Keypair capable of signing.
15
25
  */
16
26
  createKeypair(): SigningKeypair;
17
27
  /**
18
28
  * Generate new account keypair (public and secret key) from random bytes. This key pair can be
19
29
  * used to create a Stellar account.
20
- *
21
- * @return public key and secret key
30
+ * @param {Buffer} randomBytes - Random bytes to create keypair from.
31
+ * @returns {SigningKeypair} Keypair capable of signing.
22
32
  */
23
33
  createKeypairFromRandom(randomBytes: Buffer): SigningKeypair;
24
34
  /**
25
35
  * Get account information from the Stellar network.
26
- *
27
- * @param accountAddress Stellar address of the account
28
- * @param serverInstance optional Horizon server instance when default doesn't work
29
- * @return account information
36
+ * @param {object} params - The parameters for retrieving account information.
37
+ * @param {string} params.accountAddress - Stellar address of the account.
38
+ * @param {Horizon.HorizonApi.Server} [params.serverInstance=this.server] - Horizon server instance when default doesn't work.
39
+ * @returns {Promise<Horizon.ServerApi.AccountRecord>} Account information.
30
40
  */
31
41
  getInfo({ accountAddress, serverInstance, }: {
32
42
  accountAddress: string;
33
- serverInstance?: Server;
34
- }): Promise<ServerApi.AccountRecord>;
43
+ serverInstance?: Horizon.Server;
44
+ }): Promise<Horizon.ServerApi.AccountRecord>;
35
45
  /**
36
46
  * Get account operations for the specified Stellar address.
37
- *
38
- * @param accountAddress Stellar address of the account
39
- * @param limit optional how many operations to fetch, maximum is 200, default is 10
40
- * @param order optional data order, ascending or descending, defaults to descending
41
- * @param cursor optional cursor to specify a starting point
42
- * @param includeFailed optional flag to include failed operations, defaults to false
43
- * @return a list of operations
44
- * @throws [OperationsLimitExceededException] when maximum limit of 200 is exceeded
47
+ * @param {object} params - The parameters for retrieving account history.
48
+ * @param {string} params.accountAddress - Stellar address of the account
49
+ * @param {number} [params.limit=HORIZON_LIMIT_DEFAULT] - How many operations to fetch, maximum is 200, default is 10
50
+ * @param {HORIZON_ORDER} [params.order=HORIZON_ORDER.DESC] - Data order, ascending or descending, defaults to descending
51
+ * @param {string} [params.cursor] - Cursor to specify a starting point
52
+ * @param {boolean} [params.includeFailed=false] - Flag to include failed operations.
53
+ * @returns {Promise<Horizon.ServerApi.CollectionPage<Horizon.ServerApi.OperationRecord>>} A list of operations.
54
+ * @throws {OperationsLimitExceededError} when maximum limit of 200 is exceeded.
45
55
  */
46
56
  getHistory({ accountAddress, limit, order, cursor, includeFailed, }: {
47
57
  accountAddress: string;
@@ -49,5 +59,5 @@ export declare class AccountService {
49
59
  order?: HORIZON_ORDER;
50
60
  cursor?: string;
51
61
  includeFailed?: boolean;
52
- }): Promise<ServerApi.CollectionPage<ServerApi.OperationRecord>>;
62
+ }): Promise<Horizon.ServerApi.CollectionPage<Horizon.ServerApi.OperationRecord>>;
53
63
  }
@@ -1,16 +1,93 @@
1
- import { Server, Transaction, FeeBumpTransaction } from "stellar-sdk";
1
+ import { Horizon, Transaction, FeeBumpTransaction } from "stellar-sdk";
2
2
  import { Config } from "walletSdk";
3
3
  import { AccountService } from "./AccountService";
4
4
  import { TransactionBuilder } from "./Transaction/TransactionBuilder";
5
5
  import { TransactionParams, SubmitWithFeeIncreaseParams, FeeBumpTransactionParams } from "../Types";
6
+ /**
7
+ * Interaction with the Stellar Network.
8
+ * Do not create this object directly, use the Wallet class.
9
+ * @class
10
+ */
6
11
  export declare class Stellar {
7
12
  private cfg;
8
- server: Server;
13
+ server: Horizon.Server;
14
+ /**
15
+ * Creates a new instance of the Stellar class.
16
+ * @constructor
17
+ * @param {Config} cfg - Configuration object.
18
+ */
9
19
  constructor(cfg: Config);
20
+ /**
21
+ * Returns an AccountService instance for managing Stellar accounts.
22
+ * @returns {AccountService} An AccountService instance.
23
+ */
10
24
  account(): AccountService;
25
+ /**
26
+ * Construct a Stellar transaction.
27
+ * @param {TransactionParams} params - The Transaction params.
28
+ * @param {AccountKeypair} params.sourceAddress - The source account keypair.
29
+ * @param {Horizon.Server.Timebounds | number} [params.timebounds] - The timebounds for the transaction.
30
+ * If a number is given, then timebounds constructed from now to now + number in seconds.
31
+ * @param {number} [params.baseFee] - The base fee for the transaction. Defaults to the config base fee.
32
+ * @param {Memo} [params.memo] - The memo for the transaction.
33
+ * @returns {TransactionBuilder} A TransactionBuilder instance.
34
+ * @throws {AccountDoesNotExistError} If the source account does not exist.
35
+ */
11
36
  transaction({ sourceAddress, baseFee, memo, timebounds, }: TransactionParams): Promise<TransactionBuilder>;
37
+ /**
38
+ * Creates a FeeBumpTransaction instance for increasing the fee of an existing transaction.
39
+ * @param {FeeBumpTransactionParams} params - The Fee Bump Transaction params.
40
+ * @param {AccountKeypair} params.feeAddress - The account that will pay for the transaction's fee.
41
+ * @param {Transaction} params.transaction - The transaction to be fee bumped.
42
+ * @param {number} [params.baseFee] - The base fee (stroops) for the fee bump transaction. Defaults to the config base fee.
43
+ * @returns {FeeBumpTransaction} A FeeBumpTransaction instance.
44
+ */
12
45
  makeFeeBump({ feeAddress, transaction, baseFee, }: FeeBumpTransactionParams): FeeBumpTransaction;
46
+ /**
47
+ * Submits a signed transaction to the server. If the submission fails with status
48
+ * 504 indicating a timeout error, it will automatically retry.
49
+ * @param {Transaction|FeeBumpTransaction} signedTransaction - The signed transaction to submit.
50
+ * @returns {boolean} `true` if the transaction was successfully submitted.
51
+ * @throws {TransactionSubmitFailedError} If the transaction submission fails.
52
+ */
13
53
  submitTransaction(signedTransaction: Transaction | FeeBumpTransaction): Promise<boolean>;
54
+ /**
55
+ * Submits a signed transaction. If the submission fails with error code: tx_too_late,
56
+ * then resubmit with an increased base fee.
57
+ * @see {@link https://developers.stellar.org/docs/encyclopedia/error-handling#retrying-until-success-strategy}
58
+ * for more info on this strategy.
59
+ * @param {SubmitWithFeeIncreaseParams} params - The SubmitWithFeeIncrease params.
60
+ * @param {AccountKeypair} params.sourceAddress - The source account keypair.
61
+ * @param {number} params.timeout - The number of seconds from now the transaction is allowed to be submitted.
62
+ * @param {number} params.baseFeeIncrease - The amount to increase base fee (in stroops) if submission fails.
63
+ * @param {(builder: TransactionBuilder) => TransactionBuilder} params.buildingFunction - Function for building the
64
+ * operations of the transactions.
65
+ * @param {(builder: TransactionBuilder) => TransactionBuilder} [params.signerFunction] - Function for signing the transaction.
66
+ * If not given, will use the soure keypair to sign.
67
+ * @param {number} [params.baseFee] - The base fee (stroops) of the transaction.
68
+ * @param {Memo} [params.memo] - The memo of the transaction.
69
+ * @param {number} [params.maxFee] - The max fee allowed (stroops) of the transaction, afterward will stop submitting and throw error.
70
+ * @returns {Transaction} The submitted transaction.
71
+ * @throws {TransactionSubmitWithFeeIncreaseFailedError} If the transaction submission with fee increase fails.
72
+ */
14
73
  submitWithFeeIncrease({ sourceAddress, timeout, baseFeeIncrease, buildingFunction, signerFunction, baseFee, memo, maxFee, }: SubmitWithFeeIncreaseParams): Promise<Transaction>;
74
+ /**
75
+ * Decodes a Stellar transaction from xdr.
76
+ * @param {string} xdr - The XDR representation of the transaction.
77
+ * @returns {Transaction|FeeBumpTransaction} The decoded transaction.
78
+ */
15
79
  decodeTransaction(xdr: string): Transaction | FeeBumpTransaction;
80
+ /**
81
+ * Returns the recommended fee (stroops) to use in a transaction based on the current
82
+ * stellar network fee stats.
83
+ * @returns {string} The recommended fee amount in stroops.
84
+ */
85
+ getRecommendedFee(): Promise<string>;
86
+ /**
87
+ * Funds an account on the stellar test network. If it is already funded then call will error.
88
+ * Please note: only funds on the testnet network.
89
+ * @see {@link https://developers.stellar.org/docs/fundamentals-and-concepts/testnet-and-pubnet#friendbot}
90
+ * @param {string} address - The stellar address.
91
+ */
92
+ fundTestnetAccount(address: string): Promise<void>;
16
93
  }
@@ -0,0 +1,57 @@
1
+ import { xdr } from "stellar-sdk";
2
+ import { IssuedAssetId } from "../../Asset";
3
+ import { AccountKeypair } from "../Account";
4
+ export declare abstract class CommonTransactionBuilder<T> {
5
+ protected sourceAddress: string;
6
+ protected operations: Array<xdr.Operation>;
7
+ constructor(sourceAddress: string, operations: Array<xdr.Operation>);
8
+ /**
9
+ * Add a trustline for an asset so can receive or send it.
10
+ * @param {IssuedAssetId} asset - The asset for which support is added.
11
+ * @param {string} [trustLimit] - The trust limit for the asset.
12
+ * @returns {T} The builder class instance called with.
13
+ */
14
+ addAssetSupport(asset: IssuedAssetId, trustLimit?: string): T;
15
+ /**
16
+ * Remove a trustline for an asset.
17
+ * @param {IssuedAssetId} asset - The asset for which support is added.
18
+ * @returns {T} The builder class instance called with.
19
+ */
20
+ removeAssetSupport(asset: IssuedAssetId): T;
21
+ /**
22
+ * Add a signer to the account.
23
+ * @see {@link https://developers.stellar.org/docs/encyclopedia/signatures-multisig}
24
+ * @param {AccountKeypair} signerAddress - The new account being added
25
+ * @param {number} signerWeight - The weight given to the new signer.
26
+ * @returns {T} The builder class instance called with.
27
+ */
28
+ addAccountSigner(signerAddress: AccountKeypair, signerWeight: number): T;
29
+ /**
30
+ * Removes a signer from an account.
31
+ * @see {@link https://developers.stellar.org/docs/encyclopedia/signatures-multisig}
32
+ * @param {AccountKeypair} signerAddress - The new account being added
33
+ * @returns {T} The builder class instance called with.
34
+ */
35
+ removeAccountSigner(signerAddress: AccountKeypair): T;
36
+ /**
37
+ * Locking an account by setting the master key weight to 0.
38
+ * Be careful, if no other signers then the account will be locked and unable to
39
+ * sign new transactions permanently.
40
+ * @returns {T} The builder class instance called with.
41
+ */
42
+ lockAccountMasterKey(): T;
43
+ /**
44
+ * Set thesholds for an account.
45
+ * @see {@link https://developers.stellar.org/docs/encyclopedia/signatures-multisig#thresholds}
46
+ * @param {object} options - The threshold options.
47
+ * @param {number} [options.low] - The low theshold level.
48
+ * @param {number} [options.medium] - The medium theshold level.
49
+ * @param {number} [options.high] - The high theshold level.
50
+ * @returns {T} The builder class instance called with.
51
+ */
52
+ setThreshold({ low, medium, high, }: {
53
+ low?: number;
54
+ medium?: number;
55
+ high?: number;
56
+ }): T;
57
+ }
@@ -0,0 +1,38 @@
1
+ import { xdr } from "stellar-sdk";
2
+ import { CommonTransactionBuilder } from "./CommonTransactionBuilder";
3
+ import { AccountKeypair } from "../Account";
4
+ /**
5
+ * Used for building transactions that will include a sponsor.
6
+ * Do not create this object directly, use the TransactionBuilder class to create.
7
+ * @class
8
+ */
9
+ export declare class SponsoringBuilder extends CommonTransactionBuilder<SponsoringBuilder> {
10
+ private sponsorAccount;
11
+ /**
12
+ * Creates a new instance of the SponsoringBuilder class.
13
+ * @constructor
14
+ * @param {string} sponsoredAddress - The address of the account being sponsored.
15
+ * @param {AccountKeypair} sponsorAccount - The sponsor account keypair.
16
+ * @param {xdr.Operation[]} operations - An array of Stellar operations.
17
+ * @param {(builder: SponsoringBuilder) => SponsoringBuilder} buildingFunction - Function for creating the
18
+ * operations that will be sponsored.
19
+ */
20
+ constructor(sponsoredAddress: string, sponsorAccount: AccountKeypair, operations: Array<xdr.Operation>, buildingFunction: (builder: SponsoringBuilder) => SponsoringBuilder);
21
+ /**
22
+ * Creates a Stellar account with sponsored reserves.
23
+ * @param {AccountKeypair} newAccount - The new account's keypair.
24
+ * @param {number} [startingBalance=0] - The starting balance for the new account (default is 0 XLM).
25
+ * @returns {SponsoringBuilder} The SponsoringBuilder instance.
26
+ */
27
+ createAccount(newAccount: AccountKeypair, startingBalance?: number): SponsoringBuilder;
28
+ /**
29
+ * Start sponsoring the future reserves of an account.
30
+ * @returns {void}
31
+ */
32
+ startSponsoring(): void;
33
+ /**
34
+ * Stop sponsoring the future reserves of an account.
35
+ * @returns {void}
36
+ */
37
+ stopSponsoring(): void;
38
+ }
@@ -1,20 +1,121 @@
1
- import { Account as StellarAccount, Transaction, Server, Memo, xdr } from "stellar-sdk";
1
+ import { Account as StellarAccount, Transaction, Horizon, Memo, xdr } from "stellar-sdk";
2
2
  import { Config } from "walletSdk";
3
3
  import { AccountKeypair } from "../Account";
4
- import { IssuedAssetId, StellarAssetId } from "../../Asset";
5
- import { WithdrawTransaction } from "../../Types";
6
- export declare class TransactionBuilder {
7
- private network;
8
- private operations;
4
+ import { StellarAssetId } from "../../Asset";
5
+ import { WithdrawTransaction, PathPayParams } from "../../Types";
6
+ import { CommonTransactionBuilder } from "./CommonTransactionBuilder";
7
+ import { SponsoringBuilder } from "./SponsoringBuilder";
8
+ /**
9
+ * Used for building transactions.
10
+ * Do not create this object directly, use the Stellar class to create a transaction.
11
+ * @class
12
+ */
13
+ export declare class TransactionBuilder extends CommonTransactionBuilder<TransactionBuilder> {
14
+ private cfg;
9
15
  private builder;
10
- sourceAccount: string;
11
- constructor(cfg: Config, sourceAccount: StellarAccount, baseFee?: number, memo?: Memo, timebounds?: Server.Timebounds);
16
+ /**
17
+ * Creates a new instance of the TransactionBuilder class for constructing Stellar transactions.
18
+ * @constructor
19
+ * @param {Config} cfg - Configuration object for Stellar operations.
20
+ * @param {StellarAccount} sourceAccount - The source account for the transaction.
21
+ * @param {number} [baseFee] - The base fee for the transaction. If not given will use the config base fee.
22
+ * @param {Memo} [memo] - The memo for the transaction.
23
+ * @param {Horizon.Server.Timebounds} [timebounds] - The timebounds for the transaction. If not given will use the config timebounds.
24
+ */
25
+ constructor(cfg: Config, sourceAccount: StellarAccount, baseFee?: number, memo?: Memo, timebounds?: Horizon.Server.Timebounds);
26
+ /**
27
+ * Sponsoring a transaction.
28
+ * @param {AccountKeypair} sponsorAccount - The account doing the sponsoring.
29
+ * @param {(builder: SponsoringBuilder) => SponsoringBuilder} buildingFunction - Function for creating the
30
+ * operations that will be sponsored.
31
+ * @see {@link ./SponsoringBuilder.ts} or {@link ./CommonTransactionBuilder.ts} for operations that can be sponsored.
32
+ * @param {AccountKeypair} [sponsoredAccount] - The account that will be sponsored.
33
+ * @returns {TransactionBuilder} The transaction builder to build the transaction before submitting.
34
+ */
35
+ sponsoring(sponsorAccount: AccountKeypair, buildingFunction: (builder: SponsoringBuilder) => SponsoringBuilder, sponsoredAccount?: AccountKeypair): TransactionBuilder;
36
+ /**
37
+ * Creates a Stellar account.
38
+ * @param {AccountKeypair} newAccount - The new account's keypair.
39
+ * @param {number} [startingBalance=1] - The starting balance for the new account (default is 1 XLM).
40
+ * @throws {InsufficientStartingBalanceError} If the starting balance is less than 1.
41
+ * @returns {TransactionBuilder} The TransactionBuilder instance.
42
+ */
12
43
  createAccount(newAccount: AccountKeypair, startingBalance?: number): TransactionBuilder;
44
+ /**
45
+ * Adds a payment operation to transfer an amount of an asset to a destination address.
46
+ * @param {string} destinationAddress - The destination account's public key.
47
+ * @param {StellarAssetId} assetId - The asset to transfer.
48
+ * @param {string} amount - The amount to transfer.
49
+ * @returns {TransactionBuilder} The TransactionBuilder instance.
50
+ */
13
51
  transfer(destinationAddress: string, assetId: StellarAssetId, amount: string): TransactionBuilder;
52
+ /**
53
+ * Creates and adds a path payment operation to the transaction builder.
54
+ * @param {PathPayParams} params - The path payment parameters.
55
+ * @param {string} params.destinationAddress - The destination Stellar address to which the payment is sent.
56
+ * @param {StellarAssetId} params.sendAsset - The asset to be sent.
57
+ * @param {StellarAssetId} params.destAsset - The asset the destination will receive.
58
+ * @param {string} [params.sendAmount] - The amount to be sent. Must specify either sendAmount or destAmount,
59
+ * but not both.
60
+ * @param {string} [params.destAmount] - The amount to be received by the destination. Must specify either sendAmount or destAmount,
61
+ * but not both.
62
+ * @param {string} [params.destMin] - The minimum amount of the destination asset to be receive. This is a
63
+ * protective measure, it allows you to specify a lower bound for an acceptable conversion. Only used
64
+ * if using sendAmount.
65
+ * (optional, default is ".0000001").
66
+ * @param {string} [params.sendMax] - The maximum amount of the destination asset to be sent. This is a
67
+ * protective measure, it allows you to specify an upper bound for an acceptable conversion. Only used
68
+ * if using destAmount.
69
+ * (optional, default is int64 max).
70
+ *
71
+ * @returns {TransactionBuilder} - Returns the current TransactionBuilder instance for method chaining.
72
+ */
73
+ pathPay({ destinationAddress, sendAsset, destAsset, sendAmount, destAmount, destMin, sendMax, }: PathPayParams): TransactionBuilder;
74
+ /**
75
+ * Swap assets using the Stellar network. This swaps using the
76
+ * pathPaymentStrictReceive operation.
77
+ * @param {StellarAssetId} fromAsset - The source asset to be sent.
78
+ * @param {StellarAssetId} toAsset - The destination asset to receive.
79
+ * @param {string} amount - The amount of the source asset to be sent.
80
+ * @param {string} [destMin] - (Optional) The minimum amount of the destination asset to be received.
81
+ * @returns {TransactionBuilder} Returns the current instance of the TransactionBuilder for method chaining.
82
+ */
83
+ swap(fromAsset: StellarAssetId, toAsset: StellarAssetId, amount: string, destMin?: string): TransactionBuilder;
84
+ /**
85
+ * Adds an operation to the transaction.
86
+ * @param {xdr.Operation} op - The operation to add.
87
+ * @returns {TransactionBuilder} The TransactionBuilder instance.
88
+ */
14
89
  addOperation(op: xdr.Operation): TransactionBuilder;
90
+ /**
91
+ * Add a memo for the transaction.
92
+ * @param {Memo} memo - The memo to add to the transaction.
93
+ * @returns {TransactionBuilder} The TransactionBuilder instance.
94
+ */
15
95
  setMemo(memo: Memo): TransactionBuilder;
16
- addAssetSupport(asset: IssuedAssetId, trustLimit?: string): TransactionBuilder;
17
- removeAssetSupport(asset: IssuedAssetId): TransactionBuilder;
18
- build(): Transaction;
96
+ /**
97
+ * Add a transfer operation to the builder from a sep-24 withdrawal transaction.
98
+ * @param {WithdrawTransaction} transaction - The withdrawal transaction.
99
+ * @param {StellarAssetId} assetId - The asset ID to transfer.
100
+ * @throws {WithdrawalTxNotPendingUserTransferStartError} If the withdrawal transaction status is not pending_user_transfer_start.
101
+ * @throws {WithdrawalTxMissingMemoError} If the withdrawal transaction is missing a memo.
102
+ * @throws {WithdrawalTxMemoError} If there is an issue with the withdrawal transaction memo.
103
+ * @returns {TransactionBuilder} The TransactionBuilder instance.
104
+ */
19
105
  transferWithdrawalTransaction(transaction: WithdrawTransaction, assetId: StellarAssetId): TransactionBuilder;
106
+ /**
107
+ * Merges account into a destination account.
108
+ * **Warning**: This operation will give full control of the account to the destination account,
109
+ * effectively removing the merged account from the network.
110
+ * @param {string} destination - The stellar account merging into.
111
+ * @param {string} [source] - Account that is being merged. If not given then will default to
112
+ * the TransactionBuilder source account.
113
+ * @returns {TransactionBuilder} The TransactionBuilder instance.
114
+ */
115
+ accountMerge(destination: string, source?: string): TransactionBuilder;
116
+ /**
117
+ * Builds the Stellar transaction so can be submitted.
118
+ * @returns {Transaction} The built Stellar transaction.
119
+ */
120
+ build(): Transaction;
20
121
  }
@@ -1,4 +1,6 @@
1
- export { PublicKeypair, SigningKeypair } from "./Account";
1
+ export { AccountKeypair, PublicKeypair, SigningKeypair } from "./Account";
2
2
  export { AccountService } from "./AccountService";
3
3
  export { Stellar } from "./Stellar";
4
+ export { CommonTransactionBuilder } from "./Transaction/CommonTransactionBuilder";
4
5
  export { TransactionBuilder } from "./Transaction/TransactionBuilder";
6
+ export { SponsoringBuilder } from "./Transaction/SponsoringBuilder";
@@ -0,0 +1,58 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { Transaction } from "stellar-sdk";
3
+ import { RecoveryServer, RecoveryServerKey, RecoveryServerMap, RecoveryServerSigningMap } from "walletSdk/Types";
4
+ import { AccountKeypair, Stellar } from "../Horizon";
5
+ /**
6
+ * Used for Account Recovery using Sep-30.
7
+ * @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0030.md}
8
+ * @class
9
+ */
10
+ export declare abstract class AccountRecover {
11
+ protected stellar: Stellar;
12
+ protected httpClient: AxiosInstance;
13
+ protected servers: RecoveryServerMap;
14
+ /**
15
+ * Creates a new instance of the AccountRecover class.
16
+ * @constructor
17
+ * @param {Stellar} stellar - The stellar instance used to interact with Horizon server.
18
+ * @param {AxiosInstance} httpClient - The client used to make http calls.
19
+ * @param {RecoveryServerMap} servers - The recovery servers to use.
20
+ */
21
+ constructor(stellar: Stellar, httpClient: AxiosInstance, servers: RecoveryServerMap);
22
+ /**
23
+ * Sign transaction with recovery servers. It is used to recover an account using
24
+ * [SEP-30](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0030.md).
25
+ * @param {Transaction} transaction - The transaction with new signer to be signed by recovery servers.
26
+ * @param {AccountKeypair} account - The keypair of the account that will be recovered.
27
+ * @param {RecoveryServerSigningMap} serverAuth - The map of recovery servers to use.
28
+ * @returns {Transaction} - The transaction with recovery server signatures
29
+ * @throws {NotAllSignaturesFetchedError} when all recovery servers don't return signatures
30
+ */
31
+ signWithRecoveryServers(transaction: Transaction, account: AccountKeypair, serverAuth: RecoveryServerSigningMap): Promise<Transaction>;
32
+ /**
33
+ * Replace a lost device key with a new key.
34
+ * @param {AccountKeypair} account - The target account.
35
+ * @param {AccountKeypair} newKey - The key to replace the lost key with.
36
+ * @param {RecoveryServerSigningMap} serverAuth - A map of recovery servers to use.
37
+ * @param {AccountKeypair} [lostKey] - The lost device key. If not specified, try to deduce the key from the account signers list.
38
+ * @param {AccountKeypair} [sponsorAddress] - The sponsor address of the transaction. Please note that not all SEP-30 servers support signing sponsored transactions.
39
+ * @returns {Promise<Transaction>} The transaction with operations for replacing the device key.
40
+ */
41
+ replaceDeviceKey(account: AccountKeypair, newKey: AccountKeypair, serverAuth: RecoveryServerSigningMap, lostKey?: AccountKeypair, sponsorAddress?: AccountKeypair): Promise<Transaction>;
42
+ protected getServer: (serverKey: RecoveryServerKey) => RecoveryServer;
43
+ /**
44
+ * Try to deduce the lost key. If any of these criteria match, one of the signers
45
+ * from the account will be recognized as the lost device key:
46
+ * 1. Only signer that's not in [serverAuth]
47
+ * 2. All signers in [serverAuth] have the same weight, and the potential signer is
48
+ * the only one with a different weight.
49
+ * @private
50
+ * @param {Horizon.ServerApi.AccountRecord} stellarAccount - The Stellar account to lookup existing signers on account.
51
+ * @param {RecoveryServerSigningMap} serverAuth - A map of recovery servers to use.
52
+ * @returns {Horizon.ServerApi.AccountRecordSigners} The deduced account signer.
53
+ * @throws {NoDeviceKeyForAccountError} When no existing ("lost") device key is found.
54
+ * @throws {UnableToDeduceKeyError} When no criteria match.
55
+ */
56
+ private deduceKey;
57
+ private addRecoveryServerTxnSignature;
58
+ }
@@ -1,18 +1,80 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { Server } from "stellar-sdk";
2
+ import { Transaction } from "stellar-sdk";
3
3
  import { Config } from "walletSdk";
4
- import { Stellar } from "../Horizon";
4
+ import { AccountSigner, AccountThreshold, CommonBuilder, RecoverableWallet, RecoverableWalletConfig, RecoveryAccountInfoMap, RecoveryAuthMap, RecoveryServerKey, RecoveryServerMap } from "walletSdk/Types";
5
+ import { AccountRecover } from "./AccountRecover";
6
+ import { Sep10 } from "../Auth";
7
+ import { AccountKeypair, Stellar } from "../Horizon";
5
8
  type RecoveryParams = {
6
9
  cfg: Config;
7
10
  stellar: Stellar;
8
11
  httpClient: AxiosInstance;
9
- servers: Server[];
12
+ servers: RecoveryServerMap;
10
13
  };
11
- export declare class Recovery {
14
+ /**
15
+ * Used for Account Recovery using Sep-30.
16
+ * @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0030.md}
17
+ * Do not create this object directly, use the Wallet class.
18
+ * @class
19
+ */
20
+ export declare class Recovery extends AccountRecover {
12
21
  private cfg;
13
- private stellar;
14
- private httpClient;
15
- private servers;
22
+ /**
23
+ * Creates a new instance of the Recovery class.
24
+ * @constructor
25
+ * @param {RecoveryParams} params - The params used for the Recovery instance.
26
+ */
16
27
  constructor(params: RecoveryParams);
28
+ /**
29
+ * Create new auth object to authenticate account with the recovery server using SEP-10.
30
+ * @param {RecoveryServerKey} key - The key mapping to a recovery server.
31
+ * @returns {Sep10} - The Sep-10 auth object.
32
+ */
33
+ sep10Auth(key: RecoveryServerKey): Sep10;
34
+ /**
35
+ * Create new recoverable wallet using
36
+ * [SEP-30](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0030.md). It
37
+ * registers the account with recovery servers, adds recovery servers and device account as new
38
+ * account signers, and sets threshold weights on the account.
39
+ *
40
+ * **Warning**: This transaction will lock master key of the account. Make sure you have access to
41
+ * specified [RecoverableWalletConfig.deviceAddress]
42
+ *
43
+ * This transaction can be sponsored.
44
+ * @param {RecoverableWalletConfig} config - The configuration for recoverable wallet.
45
+ * @returns {Promise<RecoverableWallet>} The wallet.
46
+ */
47
+ createRecoverableWallet(config: RecoverableWalletConfig): Promise<RecoverableWallet>;
48
+ /**
49
+ * Retrieves account information from multiple recovery servers for a specified account address.
50
+ * @param {AccountKeypair} accountAddress - The account address for which to retrieve information.
51
+ * @param {RecoveryAuthMap} auth - A map of recovery server keys to their respective authentication tokens.
52
+ * @throws {ServerRequestFailedError} If any of the requests to recovery servers fail.
53
+ * @returns {Promise<RecoveryAccountInfoMap>} A map of recovery server keys to their respective account information.
54
+ */
55
+ getAccountInfo(accountAddress: AccountKeypair, auth: RecoveryAuthMap): Promise<RecoveryAccountInfoMap>;
56
+ /**
57
+ * Add recovery servers and device account as new account signers, and set new threshold weights
58
+ * on the account.
59
+ *
60
+ * This transaction can be sponsored.
61
+ * @param {AccountKeypair} account - Stellar address of the account that is receiving new signers.
62
+ * @param {AccountSigner[]} accountSigners - A list of account signers and their weights.
63
+ * @param {AccountThreshold} accountThreshold - Low, medium, and high thresholds to set on the account.
64
+ * @param {AccountKeypair} [sponsorAddress] - Stellar address of the account sponsoring this transaction.
65
+ * @param {(builder: CommonBuilder) => CommonBuilder} [builderExtra] - Stellar address of the account sponsoring this transaction.
66
+ * @returns {Promise<Transaction>} The built transaction.
67
+ */
68
+ registerRecoveryServerSigners(account: AccountKeypair, accountSigners: AccountSigner[], accountThreshold: AccountThreshold, sponsorAddress?: AccountKeypair, builderExtra?: (builder: CommonBuilder) => CommonBuilder): Promise<Transaction>;
69
+ /**
70
+ * Register account with recovery servers using
71
+ * [SEP-30](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0030.md).
72
+ * @param {AccountKeypair} account - Account being registerd.
73
+ * @param {RecoveryIdentityMap} identityMap - map of identities to recovery keys.
74
+ * @returns {Promise<string[]>} List of recovery signer public keys.
75
+ */
76
+ private enrollWithRecoveryServer;
77
+ private getLatestRecoverySigner;
78
+ private register;
17
79
  }
18
80
  export {};