@stellar/typescript-wallet-sdk 1.0.0-alpha.2 → 1.0.0-beta.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 (67) hide show
  1. package/lib/bundle.js +1979 -259
  2. package/lib/bundle.js.map +1 -1
  3. package/lib/index.d.ts +25 -0
  4. package/lib/walletSdk/Exceptions/index.d.ts +22 -0
  5. package/lib/walletSdk/Types/anchor.d.ts +148 -0
  6. package/lib/walletSdk/Types/auth.d.ts +34 -0
  7. package/lib/walletSdk/Types/horizon.d.ts +4 -0
  8. package/lib/walletSdk/Types/index.d.ts +32 -0
  9. package/lib/walletSdk/Types/interactive.d.ts +27 -0
  10. package/lib/walletSdk/Types/utils.d.ts +77 -0
  11. package/lib/walletSdk/Types/watcher.d.ts +30 -0
  12. package/lib/walletSdk/Utils/camelToSnakeCase.d.ts +2 -0
  13. package/lib/walletSdk/Utils/index.d.ts +3 -0
  14. package/lib/walletSdk/Utils/toml.d.ts +3 -0
  15. package/lib/walletSdk/Utils/url.d.ts +1 -0
  16. package/lib/walletSdk/Watcher/Types.d.ts +65 -0
  17. package/lib/walletSdk/Watcher/index.d.ts +33 -0
  18. package/lib/walletSdk/anchor/Types.d.ts +75 -0
  19. package/lib/walletSdk/anchor/index.d.ts +65 -9
  20. package/lib/walletSdk/auth/WalletSigner.d.ts +4 -0
  21. package/lib/walletSdk/auth/index.d.ts +18 -6
  22. package/lib/walletSdk/exception/index.d.ts +9 -0
  23. package/lib/walletSdk/horizon/Account.d.ts +18 -0
  24. package/lib/walletSdk/horizon/AccountService.d.ts +8 -0
  25. package/lib/walletSdk/horizon/Stellar.d.ts +5 -1
  26. package/lib/walletSdk/horizon/index.d.ts +3 -0
  27. package/lib/walletSdk/index.d.ts +18 -18
  28. package/lib/walletSdk/interactive/index.d.ts +11 -11
  29. package/lib/walletSdk/recovery/index.d.ts +18 -0
  30. package/lib/walletSdk/util/camelToSnakeCase.d.ts +2 -0
  31. package/lib/walletSdk/util/sleep.d.ts +1 -0
  32. package/package.json +12 -6
  33. package/src/index.ts +39 -1
  34. package/src/walletSdk/Anchor/index.ts +252 -27
  35. package/src/walletSdk/Auth/WalletSigner.ts +27 -3
  36. package/src/walletSdk/Auth/index.ts +87 -32
  37. package/src/walletSdk/Exceptions/index.ts +51 -0
  38. package/src/walletSdk/Horizon/Account.ts +50 -0
  39. package/src/walletSdk/Horizon/AccountService.ts +19 -0
  40. package/src/walletSdk/Horizon/Stellar.ts +15 -0
  41. package/src/walletSdk/Horizon/index.ts +3 -0
  42. package/src/walletSdk/Interactive/index.ts +126 -0
  43. package/src/walletSdk/Recovery/index.ts +37 -0
  44. package/src/walletSdk/Types/anchor.ts +174 -0
  45. package/src/walletSdk/Types/auth.ts +42 -0
  46. package/src/walletSdk/{horizon/constants.ts → Types/horizon.ts} +1 -1
  47. package/src/walletSdk/Types/index.ts +40 -0
  48. package/src/walletSdk/Types/interactive.ts +36 -0
  49. package/src/walletSdk/Types/utils.ts +77 -0
  50. package/src/walletSdk/Types/watcher.ts +34 -0
  51. package/src/walletSdk/Utils/camelToSnakeCase.ts +13 -0
  52. package/src/walletSdk/Utils/index.ts +3 -0
  53. package/src/walletSdk/Utils/toml.ts +103 -0
  54. package/src/walletSdk/{util → Utils}/url.ts +1 -1
  55. package/src/walletSdk/Watcher/index.ts +367 -0
  56. package/src/walletSdk/index.ts +103 -58
  57. package/test/account.test.ts +30 -0
  58. package/test/fixtures/TransactionsResponse.ts +230 -0
  59. package/test/wallet.test.ts +1719 -0
  60. package/src/walletSdk/exception/index.ts +0 -27
  61. package/src/walletSdk/horizon/Account.ts +0 -0
  62. package/src/walletSdk/horizon/AccountService.ts +0 -0
  63. package/src/walletSdk/horizon/Stellar.ts +0 -6
  64. package/src/walletSdk/interactive/index.ts +0 -103
  65. package/src/walletSdk/recovery/Recovery.ts +0 -6
  66. package/src/walletSdk/toml/index.ts +0 -179
  67. package/test/index.test.ts +0 -73
@@ -1,16 +1,72 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { Config } from "walletSdk";
1
3
  import { Auth } from "../Auth";
2
- import { Interactive } from "../interactive";
3
- import { TomlInfo } from "../toml";
4
+ import { Interactive } from "../Interactive";
5
+ import { AnchorServiceInfo, AnchorTransaction, GetTransactionParams, GetTransactionsParams, TomlInfo } from "../Types";
6
+ import { Watcher } from "../Watcher";
7
+ type AnchorParams = {
8
+ cfg: Config;
9
+ homeDomain: string;
10
+ httpClient: AxiosInstance;
11
+ language: string;
12
+ };
4
13
  export declare class Anchor {
14
+ language: string;
15
+ private cfg;
5
16
  private homeDomain;
6
17
  private httpClient;
7
- private cfg;
8
- constructor(cfg: any, homeDomain: string, httpClient: any);
9
- getInfo(): Promise<TomlInfo>;
18
+ private toml;
19
+ constructor(params: AnchorParams);
20
+ getInfo(shouldRefresh?: boolean): Promise<TomlInfo>;
10
21
  auth(): Promise<Auth>;
11
22
  interactive(): Interactive;
12
- getServicesInfo(): Promise<any>;
13
- getTransaction(): void;
14
- getTransactionForAsset(): void;
15
- getHistory(): void;
23
+ watcher(): Watcher;
24
+ getServicesInfo(lang?: string): Promise<AnchorServiceInfo>;
25
+ /**
26
+ * Get single transaction's current status and details. One of the [id], [stellarTransactionId],
27
+ * [externalTransactionId] must be provided.
28
+ *
29
+ * @param authToken auth token of the account authenticated with the anchor
30
+ * @param id transaction ID
31
+ * @param stellarTransactionId stellar transaction ID
32
+ * @param externalTransactionId external transaction ID
33
+ * @return transaction object
34
+ * @throws [MissingTransactionIdError] if none of the id params is provided
35
+ * @throws [InvalidTransactionResponseError] if Anchor returns an invalid transaction
36
+ * @throws [ServerRequestFailedError] if server request fails
37
+ */
38
+ getTransactionBy({ authToken, id, stellarTransactionId, externalTransactionId, lang, }: GetTransactionParams): Promise<AnchorTransaction>;
39
+ /**
40
+ * Get account's transactions specified by asset and other params.
41
+ *
42
+ * @param authToken auth token of the account authenticated with the anchor
43
+ * @param assetCode target asset to query for
44
+ * @param noOlderThan response should contain transactions starting on or after this date & time
45
+ * @param limit response should contain at most 'limit' transactions
46
+ * @param kind kind of transaction that is desired. E.g.: 'deposit', 'withdrawal'
47
+ * @param pagingId response should contain transactions starting prior to this ID (exclusive)
48
+ * @param lang desired language (localization), it can also accept locale in the format 'en-US'
49
+ * @return list of transactions as requested by the client, sorted in time-descending order
50
+ * @throws [InvalidTransactionsResponseError] if Anchor returns an invalid response
51
+ * @throws [ServerRequestFailedError] if server request fails
52
+ */
53
+ getTransactionsForAsset({ authToken, assetCode, noOlderThan, limit, kind, pagingId, lang, }: GetTransactionsParams): Promise<AnchorTransaction[]>;
54
+ /**
55
+ * Get all successfully finished (either completed or refunded) account transactions for specified
56
+ * asset. Optional field implementation depends on anchor.
57
+ *
58
+ * @param authToken auth token of the account authenticated with the anchor
59
+ * @param assetCode target asset to query for
60
+ * @param noOlderThan response should contain transactions starting on or after this date & time
61
+ * @param limit response should contain at most 'limit' transactions
62
+ * @param kind kind of transaction that is desired. E.g.: 'deposit', 'withdrawal'
63
+ * @param pagingId response should contain transactions starting prior to this ID (exclusive)
64
+ * @param lang desired language (localization), it can also accept locale in the format 'en-US'
65
+ * @return list of filtered transactions that achieved a final state (completed or refunded)
66
+ * @throws [AssetNotSupportedError] if asset is not supported by the anchor
67
+ * @throws [InvalidTransactionsResponseError] if Anchor returns an invalid response
68
+ * @throws [ServerRequestFailedError] if server request fails
69
+ */
70
+ getHistory({ authToken, assetCode, noOlderThan, limit, kind, pagingId, lang, }: GetTransactionsParams): Promise<AnchorTransaction[]>;
16
71
  }
72
+ 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): Transaction;
2
6
  }
3
7
  export declare const DefaultSigner: WalletSigner;
@@ -1,9 +1,21 @@
1
- import { Keypair } from "stellar-sdk";
1
+ import { AxiosInstance } from "axios";
2
+ import { Config } from "walletSdk";
3
+ import { AuthenticateParams, AuthToken } from "../Types";
4
+ export { WalletSigner, DefaultSigner } from "./WalletSigner";
5
+ type AuthParams = {
6
+ cfg: Config;
7
+ webAuthEndpoint: string;
8
+ homeDomain: string;
9
+ httpClient: AxiosInstance;
10
+ };
2
11
  export declare class Auth {
12
+ private cfg;
3
13
  private webAuthEndpoint;
4
- constructor(webAuthEndpoint: any);
5
- authenticate(accountKp: Keypair, memoId?: string, clientDomain?: string): Promise<any>;
6
- challenge(accountKp: Keypair, memoId?: string, clientDomain?: string): Promise<any>;
7
- sign(accountKp: Keypair, challengeTx: any, network: any): any;
8
- getToken(signedTx: any): Promise<any>;
14
+ private homeDomain;
15
+ private httpClient;
16
+ constructor(params: AuthParams);
17
+ authenticate({ accountKp, walletSigner, memoId, clientDomain, }: AuthenticateParams): Promise<AuthToken>;
18
+ private challenge;
19
+ private sign;
20
+ private getToken;
9
21
  }
@@ -10,3 +10,12 @@ export declare class InvalidMemoError extends Error {
10
10
  export declare class ClientDomainWithMemoError extends Error {
11
11
  constructor();
12
12
  }
13
+ export declare class MissingTransactionIdError extends Error {
14
+ constructor();
15
+ }
16
+ export declare class InvalidTransactionResponseError extends Error {
17
+ constructor(transactionResponse: any);
18
+ }
19
+ export declare class InvalidTransactionsResponseError extends Error {
20
+ constructor(transactionsResponse: any);
21
+ }
@@ -0,0 +1,18 @@
1
+ import { Keypair, Transaction, FeeBumpTransaction } from "stellar-sdk";
2
+ declare class AccountKeypair {
3
+ keypair: Keypair;
4
+ constructor(keypair: Keypair);
5
+ get publicKey(): string;
6
+ toString(): string;
7
+ }
8
+ export declare class PublicKeypair extends AccountKeypair {
9
+ constructor(keypair: Keypair);
10
+ static fromPublicKey: (publicKey: string) => PublicKeypair;
11
+ }
12
+ export declare class SigningKeypair extends AccountKeypair {
13
+ constructor(keypair: Keypair);
14
+ static fromSecret: (secretKey: string) => SigningKeypair;
15
+ get secretKey(): string;
16
+ sign(transaction: Transaction | FeeBumpTransaction): Transaction | FeeBumpTransaction;
17
+ }
18
+ export {};
@@ -0,0 +1,8 @@
1
+ import { Config } from "walletSdk";
2
+ import { SigningKeypair } from "./Account";
3
+ export declare class AccountService {
4
+ private server;
5
+ private network;
6
+ constructor(cfg: Config);
7
+ createKeypair(): SigningKeypair;
8
+ }
@@ -1,3 +1,7 @@
1
+ import { Config } from "walletSdk";
2
+ import { AccountService } from "./AccountService";
1
3
  export declare class Stellar {
2
- constructor(cfg: any);
4
+ private cfg;
5
+ constructor(cfg: Config);
6
+ account(): AccountService;
3
7
  }
@@ -0,0 +1,3 @@
1
+ export { PublicKeypair, SigningKeypair } from "./Account";
2
+ export { AccountService } from "./AccountService";
3
+ export { Stellar } from "./Stellar";
@@ -1,24 +1,25 @@
1
+ import { AxiosInstance, AxiosRequestConfig } from "axios";
1
2
  import { Networks, Server } from "stellar-sdk";
2
3
  import { Anchor } from "./Anchor";
3
- import { WalletSigner } from "./Auth/WalletSigner";
4
- import { Stellar } from "./horizon/Stellar";
5
- import { Recovery } from "./recovery/Recovery";
6
- interface ClientConfigFn {
7
- }
8
- interface ClientConfig {
9
- }
10
- declare class HttpClient {
11
- }
4
+ import { WalletSigner } from "./Auth";
5
+ import { Stellar } from "./Horizon";
6
+ import { Recovery } from "./Recovery";
7
+ import { ConfigParams, StellarConfigurationParams, WalletAnchor, WalletParams, WalletRecovery } from "./Types";
12
8
  export declare class Wallet {
13
9
  private cfg;
14
- private clients;
10
+ private language;
15
11
  static TestNet: () => Wallet;
16
12
  static MainNet: () => Wallet;
17
- constructor(stellarConfiguration: StellarConfiguration, applicationConfiguration?: ApplicationConfiguration);
18
- anchor(homeDomain: string, httpClientConfig?: ClientConfigFn): Anchor;
13
+ constructor({ stellarConfiguration, applicationConfiguration, language }: WalletParams);
14
+ anchor({ homeDomain, httpClientConfig, language }: WalletAnchor): Anchor;
19
15
  stellar(): Stellar;
20
- recover(servers: any, httpClientConfig: any): Recovery;
21
- getClient(httpClientConfig?: any): any;
16
+ recovery({ servers, httpClientConfig }: WalletRecovery): Recovery;
17
+ getClient(httpClientConfig?: AxiosRequestConfig): AxiosInstance;
18
+ }
19
+ export declare class Config {
20
+ stellar: StellarConfiguration;
21
+ app: ApplicationConfiguration;
22
+ constructor({ stellarConfiguration, applicationConfiguration }: ConfigParams);
22
23
  }
23
24
  export declare class StellarConfiguration {
24
25
  server: Server;
@@ -27,11 +28,10 @@ export declare class StellarConfiguration {
27
28
  baseFee: number;
28
29
  static TestNet: () => StellarConfiguration;
29
30
  static MainNet: () => StellarConfiguration;
30
- constructor(network: any, horizonUrl: any, baseFee?: number);
31
+ constructor({ network, horizonUrl, baseFee }: StellarConfigurationParams);
31
32
  }
32
33
  export declare class ApplicationConfiguration {
33
34
  defaultSigner: WalletSigner;
34
- defaultClient: HttpClient;
35
- constructor(defaultSigner?: WalletSigner, defaultCliengConfig?: ClientConfig);
35
+ defaultClient: AxiosInstance;
36
+ constructor(defaultSigner?: WalletSigner);
36
37
  }
37
- export {};
@@ -1,16 +1,16 @@
1
- type ExtraFields = {
2
- [key: string]: string;
1
+ import { AxiosInstance } from "axios";
2
+ import { Anchor } from "../Anchor";
3
+ import { InteractivePostParams, InteractivePostResponse } from "../Types";
4
+ type InteractiveParams = {
5
+ anchor: Anchor;
6
+ httpClient: AxiosInstance;
3
7
  };
4
- export declare enum FLOW_TYPE {
5
- DEPOSIT = "deposit",
6
- WITHDRAW = "withdraw"
7
- }
8
8
  export declare class Interactive {
9
- private homeDomain;
10
9
  private anchor;
11
- constructor(homeDomain: any, anchor: any);
12
- deposit(accountAddress: string, assetCode: string, authToken: string, extraFields?: ExtraFields, fundsAccountAddress?: string): Promise<any>;
13
- withdraw(accountAddress: string, assetCode: string, authToken: string, extraFields?: ExtraFields, fundsAccountAddress?: string): Promise<any>;
14
- flow(accountAddress: string, assetCode: string, authToken: string, type: string, extraFields?: ExtraFields, fundsAccountAddress?: string): Promise<any>;
10
+ private httpClient;
11
+ constructor(params: InteractiveParams);
12
+ deposit({ accountAddress, assetCode, authToken, lang, extraFields, fundsAccountAddress, }: InteractivePostParams): Promise<InteractivePostResponse>;
13
+ withdraw({ accountAddress, assetCode, authToken, lang, extraFields, fundsAccountAddress, }: InteractivePostParams): Promise<InteractivePostResponse>;
14
+ private flow;
15
15
  }
16
16
  export {};
@@ -0,0 +1,18 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { Server } from "stellar-sdk";
3
+ import { Config } from "walletSdk";
4
+ import { Stellar } from "../Horizon";
5
+ type RecoveryParams = {
6
+ cfg: Config;
7
+ stellar: Stellar;
8
+ httpClient: AxiosInstance;
9
+ servers: Server[];
10
+ };
11
+ export declare class Recovery {
12
+ private cfg;
13
+ private stellar;
14
+ private httpClient;
15
+ private servers;
16
+ constructor(params: RecoveryParams);
17
+ }
18
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const camelToSnakeCaseKey: (key: string) => string;
2
+ export declare const camelToSnakeCaseObject: (obj: any) => {};
@@ -0,0 +1 @@
1
+ export declare function sleep(delay: number): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar/typescript-wallet-sdk",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-beta.0",
4
4
  "engines": {
5
5
  "node": ">=18"
6
6
  },
@@ -14,23 +14,29 @@
14
14
  "@stellar/prettier-config": "^1.0.1",
15
15
  "@stellar/tsconfig": "^1.0.2",
16
16
  "@types/jest": "^29.4.0",
17
+ "@types/lodash": "^4.14.194",
18
+ "@types/sinon": "^10.0.15",
17
19
  "babel-jest": "^29.4.1",
18
20
  "eslint": "^8.33.0",
19
21
  "jest": "^29.4.1",
22
+ "sinon": "^15.1.0",
20
23
  "ts-jest": "^29.0.5",
24
+ "ts-loader": "^9.4.2",
21
25
  "tslib": "^2.5.0",
22
- "typescript": "^5.0.4"
26
+ "typescript": "^5.0.4",
27
+ "webpack": "^5.83.1",
28
+ "webpack-cli": "^5.1.1"
23
29
  },
24
30
  "dependencies": {
25
- "axios": "^1.3.2",
31
+ "axios": "^1.4.0",
26
32
  "https-browserify": "^1.0.0",
33
+ "lodash": "^4.17.21",
34
+ "query-string": "^7.1.3",
27
35
  "stellar-sdk": "^10.4.1",
28
36
  "stream-http": "^3.2.0",
29
- "ts-loader": "^9.4.2",
30
37
  "url": "^0.11.0",
31
38
  "util": "^0.12.5",
32
- "webpack": "^5.83.1",
33
- "webpack-cli": "^5.1.1"
39
+ "utility-types": "^3.10.0"
34
40
  },
35
41
  "scripts": {
36
42
  "prepare": "yarn build",
package/src/index.ts CHANGED
@@ -1,6 +1,44 @@
1
+ /**
2
+ * Types
3
+ */
4
+ import * as Types from "./walletSdk/Types";
5
+ export { Types };
6
+
7
+ /**
8
+ * Classes
9
+ */
10
+ export {
11
+ Wallet,
12
+ Config,
13
+ StellarConfiguration,
14
+ ApplicationConfiguration
15
+ } from "./walletSdk";
16
+ export { Anchor } from "./walletSdk/Anchor";
17
+ export { Auth, WalletSigner, DefaultSigner } from "./walletSdk/Auth";
18
+ export {
19
+ PublicKeypair,
20
+ SigningKeypair,
21
+ AccountService,
22
+ Stellar
23
+ } from "./walletSdk/Horizon";
24
+ export { Interactive } from "./walletSdk/Interactive";
25
+ export { Recovery } from "./walletSdk/Recovery";
26
+ export { Watcher } from "./walletSdk/Watcher";
27
+
28
+ /**
29
+ * Utils
30
+ */
31
+ import * as Utils from "./walletSdk/Utils";
32
+ export { Utils };
33
+
34
+ /**
35
+ * Exceptions
36
+ */
37
+ import * as Exceptions from "./walletSdk/Exceptions";
38
+ export { Exceptions };
39
+
1
40
  import * as walletSdk from "./walletSdk";
2
41
  import { Keypair } from "stellar-sdk";
3
-
4
42
  // TODO - figure out why Keypair used in parent codebase throws error
5
43
  export { walletSdk, Keypair };
6
44
  export default { walletSdk };