@pollar/core 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,205 @@
1
+ # @pollar/core
2
+
3
+ Core SDK for [Pollar](https://pollar.xyz) — authentication and transaction utilities for Stellar-based applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @pollar/core
9
+ # or
10
+ pnpm add @pollar/core
11
+ # or
12
+ yarn add @pollar/core
13
+ ```
14
+
15
+ ## Overview
16
+
17
+ `@pollar/core` provides the `PollarClient` class and utilities to:
18
+
19
+ - Authenticate users via **Google**, **GitHub**, **Email (OTP)**, or **Stellar wallets** (Freighter, Albedo)
20
+ - Build and submit Stellar transactions
21
+ - Fetch Stellar account balances
22
+ - React to real-time authentication state changes
23
+
24
+ ## Quick Start
25
+
26
+ ```ts
27
+ import { PollarClient } from '@pollar/core';
28
+
29
+ const client = new PollarClient({ apiKey: 'your-api-key' });
30
+
31
+ // Listen to state changes
32
+ client.onStateChange((entry) => {
33
+ console.log(entry.var, entry.code, entry.status);
34
+ });
35
+
36
+ // Login with email
37
+ const { cancelLogin } = client.login({ provider: 'email', email: 'user@example.com' });
38
+
39
+ // Verify the OTP code sent to the user
40
+ await client.verifyEmailCode(clientSessionId, '123456');
41
+ ```
42
+
43
+ ## API Reference
44
+
45
+ ### `new PollarClient(config)`
46
+
47
+ | Option | Type | Required | Description |
48
+ | --------------- | -------- | -------- | -------------------------------------------------- |
49
+ | `apiKey` | `string` | Yes | Your Pollar API key |
50
+ | `baseUrl` | `string` | No | Override the default API endpoint |
51
+ | `stellarNetwork`| `'mainnet' \| 'testnet'` | No | Target Stellar network (default: `testnet`) |
52
+
53
+ ---
54
+
55
+ ### Authentication
56
+
57
+ #### `client.login(options)`
58
+
59
+ Initiates a login flow. Returns `{ cancelLogin }` to abort the flow at any point.
60
+
61
+ ```ts
62
+ // Social providers
63
+ client.login({ provider: 'google' });
64
+ client.login({ provider: 'github' });
65
+
66
+ // Email OTP
67
+ client.login({ provider: 'email', email: 'user@example.com' });
68
+
69
+ // Stellar wallet
70
+ import { WalletType } from '@pollar/core';
71
+ client.login({ provider: 'wallet', type: WalletType.FREIGHTER });
72
+ client.login({ provider: 'wallet', type: WalletType.ALBEDO });
73
+ ```
74
+
75
+ #### `client.verifyEmailCode(clientSessionId, code)`
76
+
77
+ Submits the OTP code for email authentication. Use `clientSessionId` received from the `EMAIL_AUTH_START_SUCCESS` state event.
78
+
79
+ #### `client.logout()`
80
+
81
+ Clears the current session from memory and storage.
82
+
83
+ #### `client.isAuthenticated()`
84
+
85
+ Returns `true` if a valid session with a wallet public key is present.
86
+
87
+ ---
88
+
89
+ ### Transactions
90
+
91
+ #### `client.buildTx(operation, params, options?)`
92
+
93
+ Builds a Stellar transaction via the Pollar API.
94
+
95
+ ```ts
96
+ await client.buildTx('payment', {
97
+ destination: 'G...',
98
+ amount: '10',
99
+ asset: 'XLM',
100
+ });
101
+ ```
102
+
103
+ #### `client.submitTx(signedXdr)`
104
+
105
+ Submits a signed XDR transaction to the network.
106
+
107
+ ```ts
108
+ await client.submitTx(signedXdr);
109
+ ```
110
+
111
+ ---
112
+
113
+ ### State
114
+
115
+ #### `client.onStateChange(callback)`
116
+
117
+ Subscribe to state changes. Returns an unsubscribe function.
118
+
119
+ ```ts
120
+ const unsubscribe = client.onStateChange((entry) => {
121
+ // entry.var — 'authentication' | 'transaction' | 'network'
122
+ // entry.code — granular event code (see STATE_VAR_CODES)
123
+ // entry.status — 'NONE' | 'LOADING' | 'SUCCESS' | 'ERROR'
124
+ // entry.data — optional payload
125
+ // entry.level — 'info' | 'warn' | 'error'
126
+ // entry.ts — timestamp (ms)
127
+ });
128
+
129
+ // Unsubscribe
130
+ unsubscribe();
131
+ ```
132
+
133
+ All state codes are available via `STATE_VAR_CODES`:
134
+
135
+ ```ts
136
+ import { STATE_VAR_CODES } from '@pollar/core';
137
+
138
+ // STATE_VAR_CODES.authentication.EMAIL_AUTH_START_SUCCESS
139
+ // STATE_VAR_CODES.transaction.BUILD_TRANSACTION_SUCCESS
140
+ // STATE_VAR_CODES.network.NETWORK_UPDATED
141
+ ```
142
+
143
+ ---
144
+
145
+ ### `StellarClient`
146
+
147
+ Lightweight client to query Stellar account balances via Horizon.
148
+
149
+ ```ts
150
+ import { StellarClient } from '@pollar/core';
151
+
152
+ const stellar = new StellarClient('testnet');
153
+ // or: new StellarClient({ horizonUrl: 'https://horizon.stellar.org' })
154
+
155
+ const result = await stellar.getBalances('GABC...');
156
+
157
+ if (result.success) {
158
+ console.log(result.balances);
159
+ // [{ asset: 'XLM', balance: '100.0000000' }, ...]
160
+ } else {
161
+ console.error(result.errorCode); // 'ACCOUNT_NOT_FOUND' | 'HORIZON_ERROR' | 'NETWORK_ERROR'
162
+ }
163
+ ```
164
+
165
+ ---
166
+
167
+ ### Wallet Adapters
168
+
169
+ For direct wallet interaction outside the login flow:
170
+
171
+ ```ts
172
+ import { FreighterAdapter, AlbedoAdapter } from '@pollar/core';
173
+
174
+ const adapter = new FreighterAdapter();
175
+ const available = await adapter.isAvailable();
176
+ if (available) {
177
+ const { publicKey } = await adapter.connect();
178
+ }
179
+ ```
180
+
181
+ ## TypeScript
182
+
183
+ `@pollar/core` is written in TypeScript and ships full type declarations.
184
+
185
+ Key exported types:
186
+
187
+ ```ts
188
+ import type {
189
+ PollarClientConfig,
190
+ PollarLoginOptions,
191
+ PollarState,
192
+ PollarStateEntry,
193
+ StateAuthenticationCodes,
194
+ StateTransactionCodes,
195
+ StateNetworkCodes,
196
+ StateVarCodes,
197
+ StellarNetwork,
198
+ StellarBalance,
199
+ GetBalancesResult,
200
+ } from '@pollar/core';
201
+ ```
202
+
203
+ ## License
204
+
205
+ MIT
package/dist/index.d.mts CHANGED
@@ -234,7 +234,7 @@ interface paths {
234
234
  patch?: never;
235
235
  trace?: never;
236
236
  };
237
- "/tx/submit": {
237
+ "/tx/sign-and-send": {
238
238
  parameters: {
239
239
  query?: never;
240
240
  header?: never;
@@ -247,7 +247,7 @@ interface paths {
247
247
  * Submit signed transaction
248
248
  * @description Submits a signed transaction envelope to the Stellar network.
249
249
  */
250
- post: operations["postTxSubmit"];
250
+ post: operations["postTxSignAndSend"];
251
251
  delete?: never;
252
252
  options?: never;
253
253
  head?: never;
@@ -1084,7 +1084,7 @@ interface operations {
1084
1084
  content: {
1085
1085
  "application/json": {
1086
1086
  /** @enum {string} */
1087
- network: "testnet" | "mainnet";
1087
+ network: "testnet" | "public";
1088
1088
  publicKey: string;
1089
1089
  /** @constant */
1090
1090
  operation: "payment";
@@ -1125,7 +1125,7 @@ interface operations {
1125
1125
  content: {
1126
1126
  "application/json": {
1127
1127
  /** @constant */
1128
- code: "SDK_TX_BUILD";
1128
+ code: "SDK_TX_BUILT";
1129
1129
  /** @constant */
1130
1130
  success: true;
1131
1131
  content: {
@@ -1168,7 +1168,7 @@ interface operations {
1168
1168
  };
1169
1169
  };
1170
1170
  };
1171
- /** @description Horizon error */
1171
+ /** @description Transaction build error */
1172
1172
  502: {
1173
1173
  headers: {
1174
1174
  [name: string]: unknown;
@@ -1183,14 +1183,22 @@ interface operations {
1183
1183
  };
1184
1184
  };
1185
1185
  };
1186
- postTxSubmit: {
1186
+ postTxSignAndSend: {
1187
1187
  parameters: {
1188
1188
  query?: never;
1189
1189
  header?: never;
1190
1190
  path?: never;
1191
1191
  cookie?: never;
1192
1192
  };
1193
- requestBody?: never;
1193
+ requestBody?: {
1194
+ content: {
1195
+ "application/json": {
1196
+ /** @enum {string} */
1197
+ network: "testnet" | "public";
1198
+ signedXdr: string;
1199
+ };
1200
+ };
1201
+ };
1194
1202
  responses: {
1195
1203
  /** @description Submit result (PENDING | SUCCESS | FAILED) */
1196
1204
  200: {
@@ -1244,7 +1252,7 @@ interface operations {
1244
1252
  getTxStatus: {
1245
1253
  parameters: {
1246
1254
  query: {
1247
- network: "testnet" | "mainnet";
1255
+ network: "testnet" | "public";
1248
1256
  hash: string;
1249
1257
  };
1250
1258
  header?: never;
@@ -1316,6 +1324,7 @@ declare const StateStatus: {
1316
1324
  };
1317
1325
  type StateStatus = (typeof StateStatus)[keyof typeof StateStatus];
1318
1326
  declare const PollarStateVar: {
1327
+ readonly NETWORK: "network";
1319
1328
  readonly AUTHENTICATION: "authentication";
1320
1329
  readonly TRANSACTION: "transaction";
1321
1330
  };
@@ -1346,6 +1355,7 @@ declare const STATE_VAR_CODES: {
1346
1355
  readonly FETCH_SESSION_START: "FETCH_SESSION_START";
1347
1356
  readonly FETCH_SESSION_SUCCESS: "FETCH_SESSION_SUCCESS";
1348
1357
  readonly FETCH_SESSION_ERROR: "FETCH_SESSION_ERROR";
1358
+ readonly NO_RESTORED_SESSION: "NO_RESTORED_SESSION";
1349
1359
  readonly RESTORED_SESSION_SUCCESS: "RESTORED_SESSION_SUCCESS";
1350
1360
  readonly RESTORED_SESSION_ERROR: "RESTORED_SESSION_ERROR";
1351
1361
  readonly SESSION_STORED: "SESSION_STORED";
@@ -1363,12 +1373,13 @@ declare const STATE_VAR_CODES: {
1363
1373
  readonly BUILD_TRANSACTION_START: "BUILD_TRANSACTION_START";
1364
1374
  readonly BUILD_TRANSACTION_SUCCESS: "BUILD_TRANSACTION_SUCCESS";
1365
1375
  readonly BUILD_TRANSACTION_ERROR: "BUILD_TRANSACTION_ERROR";
1366
- readonly SIGN_TRANSACTION_START: "SIGN_TRANSACTION_START";
1367
- readonly SIGN_TRANSACTION_SUCCESS: "SIGN_TRANSACTION_SUCCESS";
1368
- readonly SIGN_TRANSACTION_ERROR: "SIGN_TRANSACTION_ERROR";
1369
- readonly SEND_TRANSACTION_START: "SEND_TRANSACTION_START";
1370
- readonly SEND_TRANSACTION_SUCCESS: "SEND_TRANSACTION_SUCCESS";
1371
- readonly SEND_TRANSACTION_ERROR: "SEND_TRANSACTION_ERROR";
1376
+ readonly SIGN_SEND_TRANSACTION_START: "SIGN_SEND_TRANSACTION_START";
1377
+ readonly SIGN_SEND_TRANSACTION_SUCCESS: "SIGN_SEND_TRANSACTION_SUCCESS";
1378
+ readonly SIGN_SEND_TRANSACTION_ERROR: "SIGN_SEND_TRANSACTION_ERROR";
1379
+ };
1380
+ readonly network: {
1381
+ readonly NONE: "NONE";
1382
+ readonly NETWORK_UPDATED: "NETWORK_UPDATED";
1372
1383
  };
1373
1384
  };
1374
1385
 
@@ -1433,19 +1444,10 @@ interface PollarClientConfig {
1433
1444
  baseUrl?: string;
1434
1445
  apiKey: string;
1435
1446
  }
1436
- type SubmitTxResult = {
1437
- success: true;
1438
- hash: string;
1439
- status: 'PENDING' | 'SUCCESS' | 'FAILED';
1440
- resultCode?: string;
1441
- message?: string;
1442
- } | {
1443
- success: false;
1444
- error: string;
1445
- };
1446
- type TxBuildResponse = paths['/tx/build']['post']['responses'][200]['content']['application/json'];
1447
1447
  type TxBuildBody = NonNullable<paths['/tx/build']['post']['requestBody']>['content']['application/json'];
1448
- type TxBuildResponseError = paths['/tx/build']['post']['responses'][400 | 401 | 502]['content']['application/json'];
1448
+ type TxBuildResponse = paths['/tx/build']['post']['responses'][200]['content']['application/json'];
1449
+ type TxSignAndSendBody = NonNullable<paths['/tx/sign-and-send']['post']['requestBody']>['content']['application/json'];
1450
+ type TxSignSendResponse = paths['/tx/sign-and-send']['post']['responses'][200]['content']['application/json'];
1449
1451
  type PollarLoginOptions = {
1450
1452
  provider: 'google';
1451
1453
  } | {
@@ -1457,11 +1459,13 @@ type PollarLoginOptions = {
1457
1459
  provider: 'wallet';
1458
1460
  type: WalletType;
1459
1461
  };
1462
+ type NetworkCodes = (typeof STATE_VAR_CODES)[typeof PollarStateVar.NETWORK];
1463
+ type StateNetworkCodes = NetworkCodes[keyof (typeof STATE_VAR_CODES)[typeof PollarStateVar.NETWORK]];
1460
1464
  type AuthenticationCodes = (typeof STATE_VAR_CODES)[typeof PollarStateVar.AUTHENTICATION];
1461
1465
  type StateAuthenticationCodes = AuthenticationCodes[keyof (typeof STATE_VAR_CODES)[typeof PollarStateVar.AUTHENTICATION]];
1462
1466
  type TransactionCodes = (typeof STATE_VAR_CODES)[typeof PollarStateVar.TRANSACTION];
1463
1467
  type StateTransactionCodes = TransactionCodes[keyof (typeof STATE_VAR_CODES)[typeof PollarStateVar.TRANSACTION]];
1464
- type StateVarCodes = StateAuthenticationCodes | StateTransactionCodes;
1468
+ type StateVarCodes = StateNetworkCodes | StateAuthenticationCodes | StateTransactionCodes;
1465
1469
  interface PollarStateEntry {
1466
1470
  var: PollarStateVar;
1467
1471
  code: StateVarCodes;
@@ -1531,8 +1535,9 @@ declare class PollarClient {
1531
1535
  };
1532
1536
  onStateChange(cb: (state: PollarStateEntry) => void): () => void;
1533
1537
  verifyEmailCode(clientSessionId: string, code: string): Promise<void>;
1538
+ getNetwork(): "testnet" | "public";
1534
1539
  buildTx(operation: TxBuildBody['operation'], params: TxBuildBody['params'], options?: TxBuildBody['options']): Promise<void>;
1535
- submitTx(signedXdr: string): Promise<SubmitTxResult>;
1540
+ submitTx(signedXdr: string): Promise<void>;
1536
1541
  logout(): void;
1537
1542
  private _readStore;
1538
1543
  private _storeSession;
@@ -1565,4 +1570,4 @@ declare class StellarClient {
1565
1570
  getBalances(publicKey: string): Promise<GetBalancesResult>;
1566
1571
  }
1567
1572
 
1568
- export { AlbedoAdapter, type ConnectWalletResponse, FreighterAdapter, type GetBalancesResult, type PollarApiClient, type PollarApplicationConfigContent, type PollarApplicationConfigResponse, PollarClient, type PollarClientConfig, type PollarLoginOptions, type PollarState, type PollarStateEntry, PollarStateVar, STATE_VAR_CODES, type SignAuthEntryOptions, type SignAuthEntryResponse, type SignTransactionOptions, type SignTransactionResponse, type StateAuthenticationCodes, StateStatus, type StateTransactionCodes, type StateVarCodes, type StellarBalance, StellarClient, type StellarClientConfig, type StellarNetwork, type SubmitTxResult, type TxBuildBody, type TxBuildResponse, type TxBuildResponseError, type WalletAdapter, WalletType, isValidSession, type paths as pollarPaths };
1573
+ export { AlbedoAdapter, type ConnectWalletResponse, FreighterAdapter, type GetBalancesResult, type PollarApiClient, type PollarApplicationConfigContent, type PollarApplicationConfigResponse, PollarClient, type PollarClientConfig, type PollarLoginOptions, type PollarState, type PollarStateEntry, PollarStateVar, STATE_VAR_CODES, type SignAuthEntryOptions, type SignAuthEntryResponse, type SignTransactionOptions, type SignTransactionResponse, type StateAuthenticationCodes, type StateNetworkCodes, StateStatus, type StateTransactionCodes, type StateVarCodes, type StellarBalance, StellarClient, type StellarClientConfig, type StellarNetwork, type TxBuildBody, type TxBuildResponse, type TxSignAndSendBody, type TxSignSendResponse, type WalletAdapter, WalletType, isValidSession, type paths as pollarPaths };
package/dist/index.d.ts CHANGED
@@ -234,7 +234,7 @@ interface paths {
234
234
  patch?: never;
235
235
  trace?: never;
236
236
  };
237
- "/tx/submit": {
237
+ "/tx/sign-and-send": {
238
238
  parameters: {
239
239
  query?: never;
240
240
  header?: never;
@@ -247,7 +247,7 @@ interface paths {
247
247
  * Submit signed transaction
248
248
  * @description Submits a signed transaction envelope to the Stellar network.
249
249
  */
250
- post: operations["postTxSubmit"];
250
+ post: operations["postTxSignAndSend"];
251
251
  delete?: never;
252
252
  options?: never;
253
253
  head?: never;
@@ -1084,7 +1084,7 @@ interface operations {
1084
1084
  content: {
1085
1085
  "application/json": {
1086
1086
  /** @enum {string} */
1087
- network: "testnet" | "mainnet";
1087
+ network: "testnet" | "public";
1088
1088
  publicKey: string;
1089
1089
  /** @constant */
1090
1090
  operation: "payment";
@@ -1125,7 +1125,7 @@ interface operations {
1125
1125
  content: {
1126
1126
  "application/json": {
1127
1127
  /** @constant */
1128
- code: "SDK_TX_BUILD";
1128
+ code: "SDK_TX_BUILT";
1129
1129
  /** @constant */
1130
1130
  success: true;
1131
1131
  content: {
@@ -1168,7 +1168,7 @@ interface operations {
1168
1168
  };
1169
1169
  };
1170
1170
  };
1171
- /** @description Horizon error */
1171
+ /** @description Transaction build error */
1172
1172
  502: {
1173
1173
  headers: {
1174
1174
  [name: string]: unknown;
@@ -1183,14 +1183,22 @@ interface operations {
1183
1183
  };
1184
1184
  };
1185
1185
  };
1186
- postTxSubmit: {
1186
+ postTxSignAndSend: {
1187
1187
  parameters: {
1188
1188
  query?: never;
1189
1189
  header?: never;
1190
1190
  path?: never;
1191
1191
  cookie?: never;
1192
1192
  };
1193
- requestBody?: never;
1193
+ requestBody?: {
1194
+ content: {
1195
+ "application/json": {
1196
+ /** @enum {string} */
1197
+ network: "testnet" | "public";
1198
+ signedXdr: string;
1199
+ };
1200
+ };
1201
+ };
1194
1202
  responses: {
1195
1203
  /** @description Submit result (PENDING | SUCCESS | FAILED) */
1196
1204
  200: {
@@ -1244,7 +1252,7 @@ interface operations {
1244
1252
  getTxStatus: {
1245
1253
  parameters: {
1246
1254
  query: {
1247
- network: "testnet" | "mainnet";
1255
+ network: "testnet" | "public";
1248
1256
  hash: string;
1249
1257
  };
1250
1258
  header?: never;
@@ -1316,6 +1324,7 @@ declare const StateStatus: {
1316
1324
  };
1317
1325
  type StateStatus = (typeof StateStatus)[keyof typeof StateStatus];
1318
1326
  declare const PollarStateVar: {
1327
+ readonly NETWORK: "network";
1319
1328
  readonly AUTHENTICATION: "authentication";
1320
1329
  readonly TRANSACTION: "transaction";
1321
1330
  };
@@ -1346,6 +1355,7 @@ declare const STATE_VAR_CODES: {
1346
1355
  readonly FETCH_SESSION_START: "FETCH_SESSION_START";
1347
1356
  readonly FETCH_SESSION_SUCCESS: "FETCH_SESSION_SUCCESS";
1348
1357
  readonly FETCH_SESSION_ERROR: "FETCH_SESSION_ERROR";
1358
+ readonly NO_RESTORED_SESSION: "NO_RESTORED_SESSION";
1349
1359
  readonly RESTORED_SESSION_SUCCESS: "RESTORED_SESSION_SUCCESS";
1350
1360
  readonly RESTORED_SESSION_ERROR: "RESTORED_SESSION_ERROR";
1351
1361
  readonly SESSION_STORED: "SESSION_STORED";
@@ -1363,12 +1373,13 @@ declare const STATE_VAR_CODES: {
1363
1373
  readonly BUILD_TRANSACTION_START: "BUILD_TRANSACTION_START";
1364
1374
  readonly BUILD_TRANSACTION_SUCCESS: "BUILD_TRANSACTION_SUCCESS";
1365
1375
  readonly BUILD_TRANSACTION_ERROR: "BUILD_TRANSACTION_ERROR";
1366
- readonly SIGN_TRANSACTION_START: "SIGN_TRANSACTION_START";
1367
- readonly SIGN_TRANSACTION_SUCCESS: "SIGN_TRANSACTION_SUCCESS";
1368
- readonly SIGN_TRANSACTION_ERROR: "SIGN_TRANSACTION_ERROR";
1369
- readonly SEND_TRANSACTION_START: "SEND_TRANSACTION_START";
1370
- readonly SEND_TRANSACTION_SUCCESS: "SEND_TRANSACTION_SUCCESS";
1371
- readonly SEND_TRANSACTION_ERROR: "SEND_TRANSACTION_ERROR";
1376
+ readonly SIGN_SEND_TRANSACTION_START: "SIGN_SEND_TRANSACTION_START";
1377
+ readonly SIGN_SEND_TRANSACTION_SUCCESS: "SIGN_SEND_TRANSACTION_SUCCESS";
1378
+ readonly SIGN_SEND_TRANSACTION_ERROR: "SIGN_SEND_TRANSACTION_ERROR";
1379
+ };
1380
+ readonly network: {
1381
+ readonly NONE: "NONE";
1382
+ readonly NETWORK_UPDATED: "NETWORK_UPDATED";
1372
1383
  };
1373
1384
  };
1374
1385
 
@@ -1433,19 +1444,10 @@ interface PollarClientConfig {
1433
1444
  baseUrl?: string;
1434
1445
  apiKey: string;
1435
1446
  }
1436
- type SubmitTxResult = {
1437
- success: true;
1438
- hash: string;
1439
- status: 'PENDING' | 'SUCCESS' | 'FAILED';
1440
- resultCode?: string;
1441
- message?: string;
1442
- } | {
1443
- success: false;
1444
- error: string;
1445
- };
1446
- type TxBuildResponse = paths['/tx/build']['post']['responses'][200]['content']['application/json'];
1447
1447
  type TxBuildBody = NonNullable<paths['/tx/build']['post']['requestBody']>['content']['application/json'];
1448
- type TxBuildResponseError = paths['/tx/build']['post']['responses'][400 | 401 | 502]['content']['application/json'];
1448
+ type TxBuildResponse = paths['/tx/build']['post']['responses'][200]['content']['application/json'];
1449
+ type TxSignAndSendBody = NonNullable<paths['/tx/sign-and-send']['post']['requestBody']>['content']['application/json'];
1450
+ type TxSignSendResponse = paths['/tx/sign-and-send']['post']['responses'][200]['content']['application/json'];
1449
1451
  type PollarLoginOptions = {
1450
1452
  provider: 'google';
1451
1453
  } | {
@@ -1457,11 +1459,13 @@ type PollarLoginOptions = {
1457
1459
  provider: 'wallet';
1458
1460
  type: WalletType;
1459
1461
  };
1462
+ type NetworkCodes = (typeof STATE_VAR_CODES)[typeof PollarStateVar.NETWORK];
1463
+ type StateNetworkCodes = NetworkCodes[keyof (typeof STATE_VAR_CODES)[typeof PollarStateVar.NETWORK]];
1460
1464
  type AuthenticationCodes = (typeof STATE_VAR_CODES)[typeof PollarStateVar.AUTHENTICATION];
1461
1465
  type StateAuthenticationCodes = AuthenticationCodes[keyof (typeof STATE_VAR_CODES)[typeof PollarStateVar.AUTHENTICATION]];
1462
1466
  type TransactionCodes = (typeof STATE_VAR_CODES)[typeof PollarStateVar.TRANSACTION];
1463
1467
  type StateTransactionCodes = TransactionCodes[keyof (typeof STATE_VAR_CODES)[typeof PollarStateVar.TRANSACTION]];
1464
- type StateVarCodes = StateAuthenticationCodes | StateTransactionCodes;
1468
+ type StateVarCodes = StateNetworkCodes | StateAuthenticationCodes | StateTransactionCodes;
1465
1469
  interface PollarStateEntry {
1466
1470
  var: PollarStateVar;
1467
1471
  code: StateVarCodes;
@@ -1531,8 +1535,9 @@ declare class PollarClient {
1531
1535
  };
1532
1536
  onStateChange(cb: (state: PollarStateEntry) => void): () => void;
1533
1537
  verifyEmailCode(clientSessionId: string, code: string): Promise<void>;
1538
+ getNetwork(): "testnet" | "public";
1534
1539
  buildTx(operation: TxBuildBody['operation'], params: TxBuildBody['params'], options?: TxBuildBody['options']): Promise<void>;
1535
- submitTx(signedXdr: string): Promise<SubmitTxResult>;
1540
+ submitTx(signedXdr: string): Promise<void>;
1536
1541
  logout(): void;
1537
1542
  private _readStore;
1538
1543
  private _storeSession;
@@ -1565,4 +1570,4 @@ declare class StellarClient {
1565
1570
  getBalances(publicKey: string): Promise<GetBalancesResult>;
1566
1571
  }
1567
1572
 
1568
- export { AlbedoAdapter, type ConnectWalletResponse, FreighterAdapter, type GetBalancesResult, type PollarApiClient, type PollarApplicationConfigContent, type PollarApplicationConfigResponse, PollarClient, type PollarClientConfig, type PollarLoginOptions, type PollarState, type PollarStateEntry, PollarStateVar, STATE_VAR_CODES, type SignAuthEntryOptions, type SignAuthEntryResponse, type SignTransactionOptions, type SignTransactionResponse, type StateAuthenticationCodes, StateStatus, type StateTransactionCodes, type StateVarCodes, type StellarBalance, StellarClient, type StellarClientConfig, type StellarNetwork, type SubmitTxResult, type TxBuildBody, type TxBuildResponse, type TxBuildResponseError, type WalletAdapter, WalletType, isValidSession, type paths as pollarPaths };
1573
+ export { AlbedoAdapter, type ConnectWalletResponse, FreighterAdapter, type GetBalancesResult, type PollarApiClient, type PollarApplicationConfigContent, type PollarApplicationConfigResponse, PollarClient, type PollarClientConfig, type PollarLoginOptions, type PollarState, type PollarStateEntry, PollarStateVar, STATE_VAR_CODES, type SignAuthEntryOptions, type SignAuthEntryResponse, type SignTransactionOptions, type SignTransactionResponse, type StateAuthenticationCodes, type StateNetworkCodes, StateStatus, type StateTransactionCodes, type StateVarCodes, type StellarBalance, StellarClient, type StellarClientConfig, type StellarNetwork, type TxBuildBody, type TxBuildResponse, type TxSignAndSendBody, type TxSignSendResponse, type WalletAdapter, WalletType, isValidSession, type paths as pollarPaths };
package/dist/index.js CHANGED
@@ -660,6 +660,7 @@ var StateStatus = {
660
660
  ERROR: "ERROR"
661
661
  };
662
662
  var PollarStateVar = {
663
+ NETWORK: "network",
663
664
  AUTHENTICATION: "authentication",
664
665
  TRANSACTION: "transaction"
665
666
  };
@@ -689,6 +690,7 @@ var STATE_VAR_CODES = {
689
690
  FETCH_SESSION_START: "FETCH_SESSION_START",
690
691
  FETCH_SESSION_SUCCESS: "FETCH_SESSION_SUCCESS",
691
692
  FETCH_SESSION_ERROR: "FETCH_SESSION_ERROR",
693
+ NO_RESTORED_SESSION: "NO_RESTORED_SESSION",
692
694
  RESTORED_SESSION_SUCCESS: "RESTORED_SESSION_SUCCESS",
693
695
  RESTORED_SESSION_ERROR: "RESTORED_SESSION_ERROR",
694
696
  SESSION_STORED: "SESSION_STORED",
@@ -706,12 +708,13 @@ var STATE_VAR_CODES = {
706
708
  BUILD_TRANSACTION_START: "BUILD_TRANSACTION_START",
707
709
  BUILD_TRANSACTION_SUCCESS: "BUILD_TRANSACTION_SUCCESS",
708
710
  BUILD_TRANSACTION_ERROR: "BUILD_TRANSACTION_ERROR",
709
- SIGN_TRANSACTION_START: "SIGN_TRANSACTION_START",
710
- SIGN_TRANSACTION_SUCCESS: "SIGN_TRANSACTION_SUCCESS",
711
- SIGN_TRANSACTION_ERROR: "SIGN_TRANSACTION_ERROR",
712
- SEND_TRANSACTION_START: "SEND_TRANSACTION_START",
713
- SEND_TRANSACTION_SUCCESS: "SEND_TRANSACTION_SUCCESS",
714
- SEND_TRANSACTION_ERROR: "SEND_TRANSACTION_ERROR"
711
+ SIGN_SEND_TRANSACTION_START: "SIGN_SEND_TRANSACTION_START",
712
+ SIGN_SEND_TRANSACTION_SUCCESS: "SIGN_SEND_TRANSACTION_SUCCESS",
713
+ SIGN_SEND_TRANSACTION_ERROR: "SIGN_SEND_TRANSACTION_ERROR"
714
+ },
715
+ network: {
716
+ NONE: "NONE",
717
+ NETWORK_UPDATED: "NETWORK_UPDATED"
715
718
  }
716
719
  };
717
720
 
@@ -1263,6 +1266,7 @@ var PollarClient = class {
1263
1266
  this._session = null;
1264
1267
  this._stateListeners = /* @__PURE__ */ new Set();
1265
1268
  this._state = {
1269
+ network: [],
1266
1270
  authentication: [],
1267
1271
  transaction: []
1268
1272
  };
@@ -1290,6 +1294,9 @@ var PollarClient = class {
1290
1294
  this._readStore();
1291
1295
  }
1292
1296
  });
1297
+ this._emitState("network", STATE_VAR_CODES.network.NETWORK_UPDATED, "info", StateStatus.SUCCESS, {
1298
+ network: "testnet"
1299
+ });
1293
1300
  }
1294
1301
  isAuthenticated() {
1295
1302
  return !!this._session?.wallet?.publicKey;
@@ -1369,13 +1376,16 @@ var PollarClient = class {
1369
1376
  );
1370
1377
  }
1371
1378
  }
1379
+ getNetwork() {
1380
+ return this._state.network.at(-1)?.data?.network === "public" ? "public" : "testnet";
1381
+ }
1372
1382
  async buildTx(operation, params, options) {
1373
1383
  if (!this._session?.wallet?.publicKey) {
1374
1384
  this._emitState("transaction", STATE_VAR_CODES.transaction.BUILD_TRANSACTION_ERROR_NO_WALLET, "error", StateStatus.ERROR);
1375
1385
  return;
1376
1386
  }
1377
1387
  const body = {
1378
- network: "testnet",
1388
+ network: this.getNetwork(),
1379
1389
  publicKey: this._session?.wallet?.publicKey,
1380
1390
  operation,
1381
1391
  params,
@@ -1384,7 +1394,6 @@ var PollarClient = class {
1384
1394
  try {
1385
1395
  this._emitState("transaction", STATE_VAR_CODES.transaction.BUILD_TRANSACTION_START, "info", StateStatus.LOADING);
1386
1396
  const response = await this._api.POST("/tx/build", { body });
1387
- console.log({ response });
1388
1397
  if (!emitResponse(
1389
1398
  PollarStateVar.TRANSACTION,
1390
1399
  response,
@@ -1403,19 +1412,28 @@ var PollarClient = class {
1403
1412
  }
1404
1413
  }
1405
1414
  async submitTx(signedXdr) {
1415
+ const body = {
1416
+ network: this.getNetwork(),
1417
+ signedXdr
1418
+ };
1406
1419
  try {
1407
- console.info("[PollarClient] Submitting signed transaction");
1408
- const { data, error } = await this._api.POST("/tx/submit", { body: { signedXdr } });
1409
- if (error || !data?.success) {
1410
- const msg = error?.message ?? data?.error ?? "Failed to submit transaction";
1411
- console.warn("[PollarClient] submitTx error \u2014", msg);
1412
- return { success: false, error: msg };
1420
+ this._emitState("transaction", STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_START, "info", StateStatus.LOADING);
1421
+ const response = await this._api.POST("/tx/sign-and-send", { body });
1422
+ if (!emitResponse(
1423
+ PollarStateVar.TRANSACTION,
1424
+ response,
1425
+ { code: STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_SUCCESS, status: StateStatus.SUCCESS },
1426
+ STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_ERROR,
1427
+ this._emitState.bind(this)
1428
+ )) {
1429
+ return;
1413
1430
  }
1414
- return { success: true, ...data.content };
1415
- } catch (err) {
1416
- const msg = err instanceof Error ? err.message : "Network error";
1417
- console.warn("[PollarClient] submitTx network error \u2014", msg);
1418
- return { success: false, error: msg };
1431
+ } catch (error) {
1432
+ this._emitState("transaction", STATE_VAR_CODES.transaction.SIGN_SEND_TRANSACTION_ERROR, "error", StateStatus.ERROR, {
1433
+ body,
1434
+ error
1435
+ });
1436
+ return;
1419
1437
  }
1420
1438
  }
1421
1439
  logout() {
@@ -1438,7 +1456,7 @@ var PollarClient = class {
1438
1456
  );
1439
1457
  console.info("[PollarClient] Session restored from storage");
1440
1458
  } else {
1441
- this._emitState("authentication", STATE_VAR_CODES.authentication.RESTORED_SESSION_SUCCESS, "warn", StateStatus.ERROR);
1459
+ this._emitState("authentication", STATE_VAR_CODES.authentication.NO_RESTORED_SESSION, "info", StateStatus.NONE);
1442
1460
  console.info("[PollarClient] Session NO restored from storage");
1443
1461
  }
1444
1462
  }
@@ -1459,6 +1477,7 @@ var PollarClient = class {
1459
1477
  this._session = null;
1460
1478
  removeStorage();
1461
1479
  this._state = {
1480
+ network: [],
1462
1481
  authentication: [],
1463
1482
  transaction: []
1464
1483
  };