@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,9 +1,39 @@
1
- // TODO - https://stellarorg.atlassian.net/browse/WAL-815?atlOrigin=eyJpIjoiYTE4MTdlZDIwMDU1NGU2YjlhZjQ3MDFlYmJhZWM1NTciLCJwIjoiaiJ9
2
1
  import { AxiosInstance } from "axios";
3
- import { Server } from "stellar-sdk";
2
+ import { Transaction } from "stellar-sdk";
4
3
 
5
4
  import { Config } from "walletSdk";
6
- import { Stellar } from "../Horizon";
5
+ import {
6
+ AccountSigner,
7
+ AccountThreshold,
8
+ CommonBuilder,
9
+ RecoverableAccountInfo,
10
+ RecoverableWallet,
11
+ RecoverableWalletConfig,
12
+ RecoveryAccount,
13
+ RecoveryAccountInfoMap,
14
+ RecoveryAccountSigner,
15
+ RecoveryAuthMap,
16
+ RecoveryIdentityMap,
17
+ RecoveryServerKey,
18
+ RecoveryServerMap,
19
+ } from "walletSdk/Types";
20
+ import { AccountRecover } from "./AccountRecover";
21
+ import { Sep10 } from "../Auth";
22
+ import {
23
+ DeviceKeyEqualsMasterKeyError,
24
+ NoAccountAndNoSponsorError,
25
+ NoAccountSignersError,
26
+ RecoveryIdentityNotFoundError,
27
+ ServerRequestFailedError,
28
+ } from "../Exceptions";
29
+ import {
30
+ AccountKeypair,
31
+ PublicKeypair,
32
+ TransactionBuilder,
33
+ SponsoringBuilder,
34
+ Stellar,
35
+ } from "../Horizon";
36
+ import { camelToSnakeCaseObject } from "../Utils";
7
37
 
8
38
  // Let's prevent exporting this constructor type as
9
39
  // we should not create this Recovery class directly.
@@ -11,22 +41,293 @@ type RecoveryParams = {
11
41
  cfg: Config;
12
42
  stellar: Stellar;
13
43
  httpClient: AxiosInstance;
14
- servers: Server[];
44
+ servers: RecoveryServerMap;
15
45
  };
16
46
 
17
- // Do not create this object directly, use the Wallet class.
18
- export class Recovery {
47
+ /**
48
+ * Used for Account Recovery using Sep-30.
49
+ * @see {@link https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0030.md}
50
+ * Do not create this object directly, use the Wallet class.
51
+ * @class
52
+ */
53
+ export class Recovery extends AccountRecover {
19
54
  private cfg: Config;
20
- private stellar: Stellar;
21
- private httpClient: AxiosInstance;
22
- private servers: Server[];
23
55
 
56
+ /**
57
+ * Creates a new instance of the Recovery class.
58
+ * @constructor
59
+ * @param {RecoveryParams} params - The params used for the Recovery instance.
60
+ */
24
61
  constructor(params: RecoveryParams) {
25
62
  const { cfg, stellar, httpClient, servers } = params;
26
-
63
+ super(stellar, httpClient, servers);
27
64
  this.cfg = cfg;
28
- this.stellar = stellar;
29
- this.httpClient = httpClient;
30
- this.servers = servers;
65
+ }
66
+
67
+ /**
68
+ * Create new auth object to authenticate account with the recovery server using SEP-10.
69
+ * @param {RecoveryServerKey} key - The key mapping to a recovery server.
70
+ * @returns {Sep10} - The Sep-10 auth object.
71
+ */
72
+ sep10Auth(key: RecoveryServerKey): Sep10 {
73
+ const server = this.getServer(key);
74
+ return new Sep10({
75
+ cfg: this.cfg,
76
+ webAuthEndpoint: server.authEndpoint,
77
+ homeDomain: server.homeDomain,
78
+ httpClient: this.httpClient,
79
+ });
80
+ }
81
+
82
+ /**
83
+ * Create new recoverable wallet using
84
+ * [SEP-30](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0030.md). It
85
+ * registers the account with recovery servers, adds recovery servers and device account as new
86
+ * account signers, and sets threshold weights on the account.
87
+ *
88
+ * **Warning**: This transaction will lock master key of the account. Make sure you have access to
89
+ * specified [RecoverableWalletConfig.deviceAddress]
90
+ *
91
+ * This transaction can be sponsored.
92
+ * @param {RecoverableWalletConfig} config - The configuration for recoverable wallet.
93
+ * @returns {Promise<RecoverableWallet>} The wallet.
94
+ */
95
+ async createRecoverableWallet(
96
+ config: RecoverableWalletConfig,
97
+ ): Promise<RecoverableWallet> {
98
+ if (config.deviceAddress.publicKey == config.accountAddress.publicKey) {
99
+ throw new DeviceKeyEqualsMasterKeyError();
100
+ }
101
+
102
+ const recoverySigners = await this.enrollWithRecoveryServer(
103
+ config.accountAddress,
104
+ config.accountIdentity,
105
+ );
106
+
107
+ const accountSigners: AccountSigner[] = recoverySigners.map((rs) => ({
108
+ address: PublicKeypair.fromPublicKey(rs),
109
+ weight: config.signerWeight.recoveryServer,
110
+ }));
111
+
112
+ accountSigners.push({
113
+ address: config.deviceAddress,
114
+ weight: config.signerWeight.device,
115
+ });
116
+
117
+ const transaction = await this.registerRecoveryServerSigners(
118
+ config.accountAddress,
119
+ accountSigners,
120
+ config.accountThreshold,
121
+ config.sponsorAddress,
122
+ config.builderExtra,
123
+ );
124
+
125
+ return {
126
+ transaction,
127
+ signers: recoverySigners,
128
+ };
129
+ }
130
+
131
+ /**
132
+ * Retrieves account information from multiple recovery servers for a specified account address.
133
+ * @param {AccountKeypair} accountAddress - The account address for which to retrieve information.
134
+ * @param {RecoveryAuthMap} auth - A map of recovery server keys to their respective authentication tokens.
135
+ * @throws {ServerRequestFailedError} If any of the requests to recovery servers fail.
136
+ * @returns {Promise<RecoveryAccountInfoMap>} A map of recovery server keys to their respective account information.
137
+ */
138
+ async getAccountInfo(
139
+ accountAddress: AccountKeypair,
140
+ auth: RecoveryAuthMap,
141
+ ): Promise<RecoveryAccountInfoMap> {
142
+ return Object.keys(auth).reduce(
143
+ async (
144
+ infoMapPromise: Promise<RecoveryAccountInfoMap>,
145
+ serverKey: RecoveryServerKey,
146
+ ) => {
147
+ const infoMap = await infoMapPromise;
148
+
149
+ const authToken = auth[serverKey];
150
+
151
+ const requestUrl = `${this.getServer(serverKey).endpoint}/accounts/${
152
+ accountAddress.publicKey
153
+ }`;
154
+
155
+ try {
156
+ const resp = await this.httpClient.get(requestUrl, {
157
+ headers: {
158
+ "Content-Type": "application/json",
159
+ Authorization: `Bearer ${authToken.token}`,
160
+ },
161
+ });
162
+
163
+ const accountInfo: RecoverableAccountInfo = resp.data;
164
+
165
+ return {
166
+ ...infoMap,
167
+ [serverKey]: accountInfo,
168
+ };
169
+ } catch (e) {
170
+ throw new ServerRequestFailedError(e);
171
+ }
172
+ },
173
+ Promise.resolve({}),
174
+ );
175
+ }
176
+
177
+ /**
178
+ * Add recovery servers and device account as new account signers, and set new threshold weights
179
+ * on the account.
180
+ *
181
+ * This transaction can be sponsored.
182
+ * @param {AccountKeypair} account - Stellar address of the account that is receiving new signers.
183
+ * @param {AccountSigner[]} accountSigners - A list of account signers and their weights.
184
+ * @param {AccountThreshold} accountThreshold - Low, medium, and high thresholds to set on the account.
185
+ * @param {AccountKeypair} [sponsorAddress] - Stellar address of the account sponsoring this transaction.
186
+ * @param {(builder: CommonBuilder) => CommonBuilder} [builderExtra] - Stellar address of the account sponsoring this transaction.
187
+ * @returns {Promise<Transaction>} The built transaction.
188
+ */
189
+ async registerRecoveryServerSigners(
190
+ account: AccountKeypair,
191
+ accountSigners: AccountSigner[],
192
+ accountThreshold: AccountThreshold,
193
+ sponsorAddress?: AccountKeypair,
194
+ builderExtra?: (builder: CommonBuilder) => CommonBuilder,
195
+ ): Promise<Transaction> {
196
+ let accountInfo = undefined;
197
+
198
+ try {
199
+ accountInfo = await this.stellar
200
+ .account()
201
+ .getInfo({ accountAddress: account.publicKey });
202
+ } catch (e) {
203
+ // In case it's an "Account not found" error let the code continue
204
+ if (e?.response?.status !== 404) {
205
+ throw e;
206
+ }
207
+ }
208
+
209
+ const sourceAddress = accountInfo ? account : sponsorAddress;
210
+
211
+ if (!sourceAddress) {
212
+ throw new NoAccountAndNoSponsorError();
213
+ }
214
+
215
+ const builder: TransactionBuilder = await this.stellar.transaction({
216
+ sourceAddress,
217
+ });
218
+
219
+ if (sponsorAddress) {
220
+ if (accountInfo) {
221
+ const buildingFunction = (_builder: SponsoringBuilder) =>
222
+ this.register(
223
+ _builder,
224
+ accountSigners,
225
+ accountThreshold,
226
+ builderExtra,
227
+ ) as SponsoringBuilder;
228
+
229
+ builder.sponsoring(sponsorAddress, buildingFunction);
230
+ } else {
231
+ const buildingFunction = (_builder: SponsoringBuilder) => {
232
+ _builder.createAccount(account);
233
+ return this.register(
234
+ _builder,
235
+ accountSigners,
236
+ accountThreshold,
237
+ builderExtra,
238
+ ) as SponsoringBuilder;
239
+ };
240
+
241
+ builder.sponsoring(sponsorAddress, buildingFunction, account);
242
+ }
243
+ } else {
244
+ this.register(builder, accountSigners, accountThreshold, builderExtra);
245
+ }
246
+
247
+ return builder.build();
248
+ }
249
+
250
+ /**
251
+ * Register account with recovery servers using
252
+ * [SEP-30](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0030.md).
253
+ * @param {AccountKeypair} account - Account being registerd.
254
+ * @param {RecoveryIdentityMap} identityMap - map of identities to recovery keys.
255
+ * @returns {Promise<string[]>} List of recovery signer public keys.
256
+ */
257
+ private async enrollWithRecoveryServer(
258
+ account: AccountKeypair,
259
+ identityMap: RecoveryIdentityMap,
260
+ ): Promise<string[]> {
261
+ return Promise.all(
262
+ Object.keys(this.servers).map(async (key) => {
263
+ const server = this.servers[key];
264
+
265
+ const accountIdentities = identityMap[key];
266
+
267
+ if (!accountIdentities) {
268
+ throw new RecoveryIdentityNotFoundError(key);
269
+ }
270
+
271
+ const authToken = await this.sep10Auth(key).authenticate({
272
+ accountKp: account,
273
+ walletSigner: server.walletSigner,
274
+ clientDomain: server.clientDomain,
275
+ });
276
+
277
+ const requestUrl = `${server.endpoint}/accounts/${account.publicKey}`;
278
+
279
+ let recoveryAccount: RecoveryAccount;
280
+ try {
281
+ const resp = await this.httpClient.post(
282
+ requestUrl,
283
+ {
284
+ identities: accountIdentities.map((ai) =>
285
+ camelToSnakeCaseObject(ai),
286
+ ),
287
+ },
288
+ {
289
+ headers: {
290
+ "Content-Type": "application/json",
291
+ Authorization: `Bearer ${authToken.token}`,
292
+ },
293
+ },
294
+ );
295
+
296
+ recoveryAccount = resp.data;
297
+ } catch (e) {
298
+ throw new ServerRequestFailedError(e);
299
+ }
300
+
301
+ return this.getLatestRecoverySigner(recoveryAccount.signers);
302
+ }),
303
+ );
304
+ }
305
+
306
+ private getLatestRecoverySigner(signers: RecoveryAccountSigner[]): string {
307
+ if (signers.length === 0) {
308
+ throw new NoAccountSignersError();
309
+ }
310
+
311
+ return signers[0].key;
312
+ }
313
+
314
+ private register(
315
+ builder: CommonBuilder,
316
+ accountSigners: AccountSigner[],
317
+ accountThreshold: AccountThreshold,
318
+ builderExtra?: (builder: CommonBuilder) => CommonBuilder,
319
+ ): CommonBuilder {
320
+ builder.lockAccountMasterKey();
321
+
322
+ accountSigners.forEach(({ address, weight }) =>
323
+ builder.addAccountSigner(address, weight),
324
+ );
325
+
326
+ const { low, medium, high } = accountThreshold;
327
+ builder.setThreshold({ low, medium, high });
328
+
329
+ builderExtra?.(builder);
330
+
331
+ return builder;
31
332
  }
32
333
  }
@@ -1,6 +1,8 @@
1
1
  import { MemoType } from "stellar-sdk";
2
2
  import { Optional } from "utility-types";
3
3
 
4
+ import { AuthToken } from "./auth";
5
+
4
6
  export interface AnchorServiceInfo {
5
7
  deposit: AssetInfoMap;
6
8
  withdraw: AssetInfoMap;
@@ -37,6 +39,7 @@ export interface ProcessingAnchorTransaction extends BaseTransaction {
37
39
  amount_out_asset?: string;
38
40
  amount_out: string;
39
41
  amount_fee_asset?: string;
42
+ quote_id?: string;
40
43
  amount_fee: string;
41
44
  completed_at?: string;
42
45
  stellar_transaction_id?: string;
@@ -60,6 +63,24 @@ export interface WithdrawTransaction extends ProcessingAnchorTransaction {
60
63
  withdraw_anchor_account: string;
61
64
  }
62
65
 
66
+ export type Sep6Transaction = DepositTransaction &
67
+ WithdrawTransaction & {
68
+ from?: string;
69
+ external_extra?: string;
70
+ external_extra_text?: string;
71
+ required_info_message?: string;
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
+ required_info_updates?: any;
74
+ required_customer_info_message?: string;
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ required_customer_info_updates?: any;
77
+ instructions?: {
78
+ value: string;
79
+ description: string;
80
+ };
81
+ };
82
+
83
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
63
84
  export interface ErrorTransaction
64
85
  extends Optional<DepositTransaction & WithdrawTransaction> {}
65
86
 
@@ -82,7 +103,7 @@ export interface Payment {
82
103
  }
83
104
 
84
105
  export type GetTransactionParams = {
85
- authToken: string;
106
+ authToken: AuthToken;
86
107
  id?: string;
87
108
  stellarTransactionId?: string;
88
109
  externalTransactionId?: string;
@@ -90,7 +111,7 @@ export type GetTransactionParams = {
90
111
  };
91
112
 
92
113
  export type GetTransactionsParams = {
93
- authToken: string;
114
+ authToken: AuthToken;
94
115
  assetCode: string;
95
116
  noOlderThan?: string;
96
117
  limit?: number;
@@ -1,4 +1,6 @@
1
- import { Keypair, Transaction } from "stellar-sdk";
1
+ import { Transaction } from "stellar-sdk";
2
+ import { decode } from "jws";
3
+
2
4
  import { WalletSigner } from "../Auth/WalletSigner";
3
5
  import { AccountKeypair } from "../Horizon/Account";
4
6
 
@@ -9,7 +11,39 @@ export type AuthenticateParams = {
9
11
  clientDomain?: string;
10
12
  };
11
13
 
12
- export type AuthToken = string;
14
+ export class AuthToken {
15
+ public token: string;
16
+ public issuer: string;
17
+ public issuedAt: string;
18
+ public expiresAt: string;
19
+ public clientDomain: string;
20
+ private principalAccount: string;
21
+
22
+ get account(): string {
23
+ return this.principalAccount.split(":")[0];
24
+ }
25
+
26
+ get memo(): string {
27
+ const split = this.principalAccount.split(":");
28
+ if (split.length !== 2) {
29
+ return null;
30
+ }
31
+ return split[1];
32
+ }
33
+
34
+ static from = (str: string): AuthToken => {
35
+ const authToken = new AuthToken();
36
+
37
+ const decoded = decode(str);
38
+ authToken.issuer = decoded.payload.iss;
39
+ authToken.principalAccount = decoded.payload.sub;
40
+ authToken.issuedAt = decoded.payload.iat;
41
+ authToken.expiresAt = decoded.payload.exp;
42
+ authToken.clientDomain = decoded.payload.client_domain;
43
+ authToken.token = str;
44
+ return authToken;
45
+ };
46
+ }
13
47
 
14
48
  export type ChallengeParams = {
15
49
  accountKp: AccountKeypair;
@@ -1,6 +1,6 @@
1
- import { Memo, Server, xdr, Transaction } from "stellar-sdk";
1
+ import { Memo, Horizon, Transaction } from "stellar-sdk";
2
2
  import { AccountKeypair } from "../Horizon/Account";
3
- import { TransactionBuilder } from "../Horizon/Transaction/TransactionBuilder";
3
+ import { SponsoringBuilder, TransactionBuilder } from "walletSdk/Horizon";
4
4
  import { StellarAssetId } from "../Asset";
5
5
 
6
6
  export enum NETWORK_URLS {
@@ -12,7 +12,7 @@ export type TransactionParams = {
12
12
  sourceAddress: AccountKeypair;
13
13
  baseFee?: number;
14
14
  memo?: Memo;
15
- timebounds?: Server.Timebounds | number;
15
+ timebounds?: Horizon.Server.Timebounds | number;
16
16
  };
17
17
 
18
18
  export type FeeBumpTransactionParams = {
@@ -25,8 +25,8 @@ export type SubmitWithFeeIncreaseParams = {
25
25
  sourceAddress: AccountKeypair;
26
26
  timeout: number;
27
27
  baseFeeIncrease: number;
28
- buildingFunction: (TransactionBuilder) => TransactionBuilder;
29
- signerFunction?: (Transaction) => Transaction;
28
+ buildingFunction: (builder: TransactionBuilder) => TransactionBuilder;
29
+ signerFunction?: (transaction: Transaction) => Transaction;
30
30
  baseFee?: number;
31
31
  memo?: Memo;
32
32
  maxFee?: number;
@@ -49,3 +49,5 @@ export type PathPayParams = {
49
49
  destMin?: string;
50
50
  sendMax?: string;
51
51
  };
52
+
53
+ export type CommonBuilder = TransactionBuilder | SponsoringBuilder;
@@ -1,6 +1,7 @@
1
- import { AxiosRequestConfig } from "axios";
2
- import { Server, Networks } from "stellar-sdk";
1
+ import { RawAxiosRequestHeaders } from "axios";
2
+ import { Networks } from "stellar-sdk";
3
3
  import { ApplicationConfiguration, StellarConfiguration } from "walletSdk";
4
+ import { RecoveryServerMap } from "./recovery";
4
5
 
5
6
  // Export types from root walletSdk/index.ts
6
7
  export type WalletParams = {
@@ -14,8 +15,8 @@ export type WalletAnchor = {
14
15
  language?: string;
15
16
  };
16
17
 
17
- export type WalletRecovery = {
18
- servers: Server[];
18
+ export type WalletRecoveryServers = {
19
+ servers: RecoveryServerMap;
19
20
  };
20
21
 
21
22
  export type ConfigParams = {
@@ -30,10 +31,22 @@ export type StellarConfigurationParams = {
30
31
  defaultTimeout?: number;
31
32
  };
32
33
 
34
+ export type AxiosErrorData = {
35
+ status?: number;
36
+ statusText?: string;
37
+ // eslint-disable-next-line
38
+ responseData?: any;
39
+ headers?: RawAxiosRequestHeaders;
40
+ };
41
+
33
42
  // Export all other types from walletSdk/Types.ts
34
43
  export * from "./anchor";
35
44
  export * from "./auth";
36
45
  export * from "./horizon";
46
+ export * from "./recovery";
47
+ export * from "./sep6";
48
+ export * from "./sep12";
37
49
  export * from "./sep24";
50
+ export * from "./sep38";
38
51
  export * from "./utils";
39
52
  export * from "./watcher";
@@ -0,0 +1,152 @@
1
+ import { Transaction } from "stellar-sdk";
2
+
3
+ import { WalletSigner } from "walletSdk/Auth";
4
+ import { AccountKeypair, PublicKeypair } from "walletSdk/Horizon";
5
+ import { AuthToken } from "./auth";
6
+ import { CommonBuilder } from "./horizon";
7
+
8
+ /**
9
+ * Configuration for recoverable wallet
10
+ * @param accountAddress Stellar address of the account that is registering
11
+ * @param deviceAddress Stellar address of the device that is added as a primary signer. It will
12
+ * replace the master key of [accountAddress]
13
+ * @param accountThreshold Low, medium, and high thresholds to set on the account
14
+ * @param accountIdentity A list of account identities to be registered with the recovery servers
15
+ * @param signerWeight Signer weight of the device and recovery keys to set
16
+ * @param sponsorAddress optional Stellar address of the account sponsoring this transaction
17
+ */
18
+ export type RecoverableWalletConfig = {
19
+ accountAddress: AccountKeypair;
20
+ deviceAddress: AccountKeypair;
21
+ accountThreshold: AccountThreshold;
22
+ accountIdentity: RecoveryIdentityMap;
23
+ signerWeight: SignerWeight;
24
+ sponsorAddress?: AccountKeypair;
25
+ builderExtra?: (builder: CommonBuilder) => CommonBuilder;
26
+ };
27
+
28
+ export type RecoverableWallet = {
29
+ transaction: Transaction;
30
+ signers: string[];
31
+ };
32
+
33
+ export type AccountSigner = {
34
+ address: AccountKeypair;
35
+ weight: number;
36
+ };
37
+
38
+ /**
39
+ * Account weights threshold
40
+ * @param low Low threshold weight
41
+ * @param medium Medium threshold weight
42
+ * @param high High threshold weight
43
+ */
44
+ export type AccountThreshold = {
45
+ low: number;
46
+ medium: number;
47
+ high: number;
48
+ };
49
+
50
+ export type SignerWeight = {
51
+ device: number;
52
+ recoveryServer: number;
53
+ };
54
+
55
+ /**
56
+ * Recovery server configuration
57
+ * @property {string} endpoint - Main endpoint (root domain) of SEP-30 recovery server. E.g. `https://testanchor.stellar.org`
58
+ * @property {string} authEndpoint - SEP-10 auth endpoint to be used. Should be in the format `<https://domain/auth>`. E.g. `https://testanchor.stellar.org/auth`
59
+ * @property {string} homeDomain - SEP-10 home domain. E.g. `testanchor.stellar.org`
60
+ * @property {WalletSigner} [walletSigner] - WalletSigner used to sign authentication
61
+ */
62
+ export type RecoveryServer = {
63
+ endpoint: string;
64
+ authEndpoint: string;
65
+ homeDomain: string;
66
+ walletSigner?: WalletSigner;
67
+ clientDomain?: string;
68
+ };
69
+
70
+ export type RecoveryServerKey = string;
71
+
72
+ export type RecoveryServerSigning = {
73
+ signerAddress: string;
74
+ authToken: AuthToken;
75
+ };
76
+
77
+ export type RecoveryServerSigningMap = {
78
+ [key: RecoveryServerKey]: RecoveryServerSigning;
79
+ };
80
+
81
+ export type RecoveryServerMap = {
82
+ [key: RecoveryServerKey]: RecoveryServer;
83
+ };
84
+
85
+ export type RecoveryAuthMap = {
86
+ [key: RecoveryServerKey]: AuthToken;
87
+ };
88
+
89
+ /**
90
+ * The role of the identity. This value is not used by the server and is stored and echoed back in
91
+ * responses as a way for a client to know conceptually who each identity represents
92
+ */
93
+ export enum RecoveryRole {
94
+ OWNER = "owner",
95
+ SENDER = "sender",
96
+ RECEIVER = "receiver",
97
+ }
98
+
99
+ export enum RecoveryType {
100
+ STELLAR_ADDRESS = "stellar_address",
101
+ PHONE_NUMBER = "phone_number",
102
+ EMAIL = "email",
103
+ }
104
+
105
+ export type RecoveryAccountAuthMethod = {
106
+ type: RecoveryType;
107
+ value: string;
108
+ };
109
+
110
+ export type RecoveryAccountIdentity = {
111
+ role: RecoveryRole;
112
+ authMethods: RecoveryAccountAuthMethod[];
113
+ };
114
+
115
+ export type RecoveryIdentityMap = {
116
+ [key: RecoveryServerKey]: RecoveryAccountIdentity[];
117
+ };
118
+
119
+ export type RecoveryAccountRole = {
120
+ role: RecoveryRole;
121
+ authenticated?: boolean;
122
+ };
123
+
124
+ export type RecoveryAccountSigner = {
125
+ key: string;
126
+ };
127
+
128
+ export type RecoveryAccount = {
129
+ address: string;
130
+ identities: RecoveryAccountRole[];
131
+ signers: RecoveryAccountSigner[];
132
+ };
133
+
134
+ export type RecoverableIdentity = {
135
+ role: string;
136
+ authenticated?: boolean;
137
+ };
138
+
139
+ export type RecoverableSigner = {
140
+ key: PublicKeypair;
141
+ addedAt?: Date;
142
+ };
143
+
144
+ export type RecoverableAccountInfo = {
145
+ address: PublicKeypair;
146
+ identities: RecoverableIdentity[];
147
+ signers: RecoverableSigner[];
148
+ };
149
+
150
+ export type RecoveryAccountInfoMap = {
151
+ [key: RecoveryServerKey]: RecoverableAccountInfo;
152
+ };