@bounded-sh/client 0.0.1
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 +298 -0
- package/dist/auth/hooks/useAuth.d.ts +8 -0
- package/dist/auth/index.d.ts +73 -0
- package/dist/auth/oidc-auth.d.ts +27 -0
- package/dist/auth/providers/email-auth-provider.d.ts +38 -0
- package/dist/auth/providers/guest-auth-provider.d.ts +14 -0
- package/dist/auth/providers/guest-keystore.d.ts +12 -0
- package/dist/auth/providers/mock-auth-provider.d.ts +49 -0
- package/dist/auth/providers/offchain-auth-provider.d.ts +56 -0
- package/dist/auth/providers/phantom-wallet-provider.d.ts +117 -0
- package/dist/auth/providers/privy-expo-provider.d.ts +115 -0
- package/dist/auth/providers/privy-wallet-provider.d.ts +80 -0
- package/dist/auth/providers/sol/sol-utils.d.ts +2 -0
- package/dist/auth/providers/solana-mobile-wallet-provider.d.ts +155 -0
- package/dist/auth/providers/transaction-utils.d.ts +10 -0
- package/dist/global.d.ts +13 -0
- package/dist/index-BHTfW8CV.esm.js +16091 -0
- package/dist/index-BHTfW8CV.esm.js.map +1 -0
- package/dist/index-C1VOdmRN.js +16130 -0
- package/dist/index-C1VOdmRN.js.map +1 -0
- package/dist/index-CT2j1oic.esm.js +16089 -0
- package/dist/index-CT2j1oic.esm.js.map +1 -0
- package/dist/index-VGx-869x.js +23572 -0
- package/dist/index-VGx-869x.js.map +1 -0
- package/dist/index-o5Hv9pfS.esm.js +23456 -0
- package/dist/index-o5Hv9pfS.esm.js.map +1 -0
- package/dist/index-sKqrgk0t.js +16132 -0
- package/dist/index-sKqrgk0t.js.map +1 -0
- package/dist/index.browser-BJZ7fYwv.js +5081 -0
- package/dist/index.browser-BJZ7fYwv.js.map +1 -0
- package/dist/index.browser-DaNhOhkQ.esm.js +4220 -0
- package/dist/index.browser-DaNhOhkQ.esm.js.map +1 -0
- package/dist/index.browser-DhAcjdpV.esm.js +5071 -0
- package/dist/index.browser-DhAcjdpV.esm.js.map +1 -0
- package/dist/index.browser-utVKQsEC.js +4225 -0
- package/dist/index.browser-utVKQsEC.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.esm.js +8 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/dist/index.native-B5IBOdv_.js +19684 -0
- package/dist/index.native-B5IBOdv_.js.map +1 -0
- package/dist/index.native-JPUkdHJj.esm.js +19565 -0
- package/dist/index.native-JPUkdHJj.esm.js.map +1 -0
- package/dist/index.native.d.ts +26 -0
- package/dist/index.native.esm.js +6 -0
- package/dist/index.native.esm.js.map +1 -0
- package/dist/index.native.js +98 -0
- package/dist/index.native.js.map +1 -0
- package/dist/phantom-wallet-provider-CDLyxrih.js +1466 -0
- package/dist/phantom-wallet-provider-CDLyxrih.js.map +1 -0
- package/dist/phantom-wallet-provider-DMlaSrAl.esm.js +1445 -0
- package/dist/phantom-wallet-provider-DMlaSrAl.esm.js.map +1 -0
- package/dist/platform.d.ts +81 -0
- package/dist/privy-wallet-provider-DiHHTDbZ.js +956 -0
- package/dist/privy-wallet-provider-DiHHTDbZ.js.map +1 -0
- package/dist/privy-wallet-provider-nR52lXzI.esm.js +933 -0
- package/dist/privy-wallet-provider-nR52lXzI.esm.js.map +1 -0
- package/dist/solana-mobile-wallet-provider-B4CeMMQd.esm.js +1460 -0
- package/dist/solana-mobile-wallet-provider-B4CeMMQd.esm.js.map +1 -0
- package/dist/solana-mobile-wallet-provider-BYMfFjZb.js +1481 -0
- package/dist/solana-mobile-wallet-provider-BYMfFjZb.js.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +100 -0
package/README.md
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
|
|
2
|
+
# Tarobase JS SDK
|
|
3
|
+
Tarobase is the web3 alternative to firebase. It is a powerful platform that simplifies the integration of hybrid on-chain actions and data for modern web and mobile applications.
|
|
4
|
+
|
|
5
|
+
Welcome to the **Tarobase JavaScript SDK**! This SDK allows you to interact with the Tarobase platform seamlessly from your JavaScript or TypeScript applications. Whether you're building a web app, a Node.js service, or a React Native application (support coming soon), the Tarobase JS SDK provides the tools you need.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Table of Contents
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
|
|
11
|
+
- [Getting Started](#getting-started)
|
|
12
|
+
|
|
13
|
+
- [Initialization](#initialization)
|
|
14
|
+
|
|
15
|
+
- [Authentication](#authentication)
|
|
16
|
+
|
|
17
|
+
- [Usage Examples](#usage-examples)
|
|
18
|
+
|
|
19
|
+
- [Initialize the SDK](#initialize-the-sdk)
|
|
20
|
+
|
|
21
|
+
- [Authenticate a User](#authenticate-a-user)
|
|
22
|
+
|
|
23
|
+
- [Get Current User](#get-current-user)
|
|
24
|
+
|
|
25
|
+
- [Set Data](#set-data)
|
|
26
|
+
|
|
27
|
+
- [On-Chain and Off-Chain Data](#on-chain-and-off-chain-data)
|
|
28
|
+
|
|
29
|
+
- [Subscribe](#subscribe)
|
|
30
|
+
|
|
31
|
+
- [Get Data](#get-data)
|
|
32
|
+
|
|
33
|
+
- [Counting, Aggregation, Search, and Joins](#counting-aggregation-search-and-joins)
|
|
34
|
+
|
|
35
|
+
- [Get Multiple Documents](#get-multiple-documents)
|
|
36
|
+
|
|
37
|
+
- [Additional Resources](#additional-resources)
|
|
38
|
+
|
|
39
|
+
- [React Native Support](#react-native-support)
|
|
40
|
+
|
|
41
|
+
- [Contributing](#contributing)
|
|
42
|
+
|
|
43
|
+
- [License](#license)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
Install the SDK via npm:
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install @tarobase/js-sdk
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
Or with Yarn:
|
|
58
|
+
```bash
|
|
59
|
+
yarn add @tarobase/js-sdk
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
## Getting Started
|
|
65
|
+
### Initialization
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
Before using the SDK, initialize it with your **Application ID**. You can obtain your `appId` by creating an application on the [Tarobase Console](https://console.tarobase.com). The console also allows you to configure your application's policies, including data storage preferences (on-chain or off-chain) and data schemas.
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { init } from '@tarobase/js-sdk';
|
|
74
|
+
|
|
75
|
+
init({appId: 'YOUR_APP_ID' });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Authentication
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
To authenticate users, use the `login` function:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
import { login } from '@tarobase/js-sdk';
|
|
85
|
+
|
|
86
|
+
// Start the login process
|
|
87
|
+
login();
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
You can also listen for authentication state changes:
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { onAuthStateChanged } from '@tarobase/js-sdk';
|
|
94
|
+
|
|
95
|
+
onAuthStateChanged((user) => {
|
|
96
|
+
if (user) {
|
|
97
|
+
console.log('User logged in:', user.address);
|
|
98
|
+
} else {
|
|
99
|
+
console.log('User logged out');
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Usage
|
|
107
|
+
|
|
108
|
+
### Get Current User
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
import { getCurrentUser } from '@tarobase/js-sdk';
|
|
113
|
+
|
|
114
|
+
const user = await getCurrentUser();
|
|
115
|
+
if (user) {
|
|
116
|
+
console.log('Current user:', user.address);
|
|
117
|
+
} else {
|
|
118
|
+
console.log('No user is currently logged in.');
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### Set Data
|
|
125
|
+
```typescript
|
|
126
|
+
import { set } from '@tarobase/js-sdk';
|
|
127
|
+
|
|
128
|
+
const path = 'path/to/data';
|
|
129
|
+
const data = { key: 'value' };
|
|
130
|
+
|
|
131
|
+
await set(path, data);
|
|
132
|
+
|
|
133
|
+
console.log(`Data set at ${path}`);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
#### On-Chain and Off-Chain Data
|
|
138
|
+
|
|
139
|
+
The `set` and `get` functions automatically handle whether data is stored **on-chain** or **off-chain** based on your application's policy configuration in the [Tarobase Console](https://console.tarobase.com).
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
**On-Chain Data:**
|
|
143
|
+
|
|
144
|
+
- If the data path corresponds to on-chain storage defined in your application policy, the `set` function will store data on-chain.
|
|
145
|
+
|
|
146
|
+
- The data must adhere to the `fields` schema defined in your Tarobase policy.
|
|
147
|
+
|
|
148
|
+
- Transactions are handled automatically, and users may be prompted to approve blockchain transactions.
|
|
149
|
+
|
|
150
|
+
**Off-Chain Data:**
|
|
151
|
+
|
|
152
|
+
- If the data path corresponds to off-chain storage, the `set` function will store data off-chain.
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
**Important:**
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
- Manage your data storage preferences and define policies at the [Tarobase Console](https://console.tarobase.com).
|
|
161
|
+
|
|
162
|
+
- Ensure that for on-chain data, the parameters you provide to `set` match the `fields` specified in your Tarobase policy.
|
|
163
|
+
|
|
164
|
+
- The policy also controls what can be `set` or `get` in your application.
|
|
165
|
+
|
|
166
|
+
- For information on how to form your policy specifically for your app's use-cases, view the policy docs [here](https://docs.tarobase.com/policies).
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
### Subscribe
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { subscribe } from '@tarobase/js-sdk';
|
|
173
|
+
|
|
174
|
+
// Subscribe to a single document
|
|
175
|
+
const unsubscribe = await subscribe('users/123/profile', {
|
|
176
|
+
onData: (data) => console.log('Data updated:', data),
|
|
177
|
+
onError: (e) => console.error(e.message),
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Subscribe to a filtered, live collection feed
|
|
181
|
+
await subscribe('orders', {
|
|
182
|
+
filter: { status: 'open', amount: { $gt: 100 } },
|
|
183
|
+
limit: 50,
|
|
184
|
+
onData: (orders) => console.log('Live open orders:', orders),
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Later, to stop receiving updates:
|
|
188
|
+
await unsubscribe();
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
### Get Data
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { get } from '@tarobase/js-sdk';
|
|
196
|
+
|
|
197
|
+
// Read a single document
|
|
198
|
+
const message = await get('messages/abc123');
|
|
199
|
+
|
|
200
|
+
// Query a collection with a structured filter, sort, limit, and cursor pagination
|
|
201
|
+
const recent = await get('messages', {
|
|
202
|
+
filter: { text: { $regex: '^f', $options: 'i' } }, // text starting with "f"
|
|
203
|
+
sort: { tarobase_created_at: -1 },
|
|
204
|
+
limit: 20,
|
|
205
|
+
// cursor: previousPage.nextCursor, // opaque keyset cursor (no numeric offset)
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
console.log('Messages:', recent);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`filter` uses MongoDB-style operators (`$gt`, `$gte`, `$lt`, `$lte`, `$ne`,
|
|
212
|
+
`$in`, `$nin`, `$all`, `$size`, `$elemMatch`, `$exists`, `$type`, `$regex`,
|
|
213
|
+
`$and`, `$or`, `$nor`) evaluated server-side. See the
|
|
214
|
+
[Querying reference](https://docs.tarobase.com/querying) for the full table.
|
|
215
|
+
|
|
216
|
+
> **Note:** The older natural-language `prompt` option is legacy and no longer
|
|
217
|
+
> filters results — always use the structured `filter` option above.
|
|
218
|
+
|
|
219
|
+
**Note:** Similar to `set`, the `get` and `subscribe` functions will automatically retrieve data from on-chain or off-chain storage based on your application's configuration.
|
|
220
|
+
|
|
221
|
+
### Counting, Aggregation, Search, and Joins
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { count, aggregate, queryAggregate, search, get } from '@tarobase/js-sdk';
|
|
225
|
+
|
|
226
|
+
// Count matching documents
|
|
227
|
+
const { value: openCount } = await count('orders', { filter: { status: 'open' } });
|
|
228
|
+
|
|
229
|
+
// Single scalar aggregate: count | uniqueCount | sum | avg | min | max
|
|
230
|
+
const { value: total } = await aggregate('orders', 'sum', { field: 'amount' });
|
|
231
|
+
|
|
232
|
+
// Grouped aggregation → one row per group
|
|
233
|
+
const byCategory = await queryAggregate('spend', { groupBy: ['category'], count: true, sum: ['amount'] });
|
|
234
|
+
|
|
235
|
+
// Full-text search (collection must declare `search: { fields: [...] }` in policy)
|
|
236
|
+
const docs = await search('orgs/o1/docs', 'quarterly report', { fields: ['title', 'body'] });
|
|
237
|
+
|
|
238
|
+
// Relationship join via `shape` (collection must declare `links` in policy)
|
|
239
|
+
const projects = await get('projects', { shape: { owner: {} } });
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Get Multiple Documents
|
|
243
|
+
|
|
244
|
+
Use `getMany` to efficiently fetch multiple documents in a single request:
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import { getMany } from '@tarobase/js-sdk';
|
|
248
|
+
|
|
249
|
+
// Fetch multiple documents at once (max 30 paths)
|
|
250
|
+
const results = await getMany([
|
|
251
|
+
'users/123/profile',
|
|
252
|
+
'users/456/profile',
|
|
253
|
+
'posts/789'
|
|
254
|
+
]);
|
|
255
|
+
|
|
256
|
+
// Each result contains: { path, data, error? }
|
|
257
|
+
results.forEach(result => {
|
|
258
|
+
if (result.error) {
|
|
259
|
+
console.log(`Error for ${result.path}: ${result.error.message}`);
|
|
260
|
+
} else {
|
|
261
|
+
console.log(`Data for ${result.path}:`, result.data);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
The `getMany` function:
|
|
267
|
+
- Accepts up to 30 document paths per request
|
|
268
|
+
- Returns results in the same order as the input paths
|
|
269
|
+
- Includes per-document error handling (NOT_FOUND, UNAUTHORIZED)
|
|
270
|
+
- Automatically caches successful fetches
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
### Additional Resources
|
|
276
|
+
For more comprehensive examples, detailed guides, and API references, please visit our documentation site:
|
|
277
|
+
|
|
278
|
+
- [Tarobase Documentation](https://docs.tarobase.com)
|
|
279
|
+
|
|
280
|
+
- Quickstart Guide
|
|
281
|
+
|
|
282
|
+
- [API Reference](https://docs.tarobase.com/api)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
### React Native Support
|
|
286
|
+
Support for **React Native** is coming soon! Stay tuned for updates, and feel free to check back on our [documentation site](https://docs.tarobase.com) for the latest information.
|
|
287
|
+
|
|
288
|
+
### Contributing
|
|
289
|
+
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
|
|
290
|
+
|
|
291
|
+
### License
|
|
292
|
+
This Tarobase JS SDK project is licensed under the MIT License.
|
|
293
|
+
|
|
294
|
+
* * * * *
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
Thank you for using the Tarobase JS SDK! If you have any questions or need further assistance, feel free to crete an issue.
|
|
298
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { AuthProvider, User, ClientConfig } from "@bounded-sh/core";
|
|
2
|
+
/**
|
|
3
|
+
* Clears the session if it was created before auth method tracking (legacy session).
|
|
4
|
+
* Returns true if the session was cleared, false if the session is compatible.
|
|
5
|
+
*
|
|
6
|
+
* Dispatches to the correct session manager based on the current auth method
|
|
7
|
+
* so both web (WebSessionManager) and RN (ReactNativeSessionManager) sessions
|
|
8
|
+
* are properly cleared.
|
|
9
|
+
*/
|
|
10
|
+
export declare function clearIncompatibleSession(): boolean;
|
|
11
|
+
export declare const SOLANA_DEVNET_RPC_URL = "https://idelle-8nxsep-fast-devnet.helius-rpc.com";
|
|
12
|
+
export declare const SOLANA_MAINNET_RPC_URL = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
|
|
13
|
+
export declare const SURFNET_RPC_URL = "https://surfpool.fly.dev";
|
|
14
|
+
export declare function getAuthProvider(config?: Partial<ClientConfig>): Promise<AuthProvider>;
|
|
15
|
+
/** Per-call overrides forwarded to the active auth provider's modal. */
|
|
16
|
+
export interface LoginOptions {
|
|
17
|
+
/** Override the modal theme just for this login call: 'light' or 'dark'. */
|
|
18
|
+
theme?: 'light' | 'dark';
|
|
19
|
+
/** Override the modal title just for this login call. */
|
|
20
|
+
modalTitle?: string;
|
|
21
|
+
/** Override the modal subtitle just for this login call. */
|
|
22
|
+
modalSubtitle?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Anonymous ("guest") sign-in: zero-friction auth backed by a device-local
|
|
26
|
+
* ed25519 keypair (no email, no wallet, no popup). The keypair is generated +
|
|
27
|
+
* persisted on the device; its public key becomes `@user.address`. Durable
|
|
28
|
+
* across reloads. Upgrade later by linking an email; transfer accounts via the
|
|
29
|
+
* ownership-as-data pattern. `init()` must have run first. Browser/RN only.
|
|
30
|
+
*/
|
|
31
|
+
export declare function signInAnonymously(): Promise<User | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Log in with Privy as a co-equal route — selectable at runtime alongside
|
|
34
|
+
* `login()` (email/wallet) and `signInAnonymously()`, without re-`init()`.
|
|
35
|
+
*
|
|
36
|
+
* On WEB it lazy-loads the @privy-io/react-auth-backed PrivyWalletProvider from
|
|
37
|
+
* `config.privyConfig`. On REACT NATIVE the host must have created a
|
|
38
|
+
* PrivyExpoProvider and bridged the Privy hooks via setPrivyMethods() (pass it as
|
|
39
|
+
* `config.privyExpoProvider` to init()) — RN can't construct it here because the
|
|
40
|
+
* Privy hooks live in the app's component tree.
|
|
41
|
+
*
|
|
42
|
+
* Either way the Privy Solana wallet signs the SIWS challenge, so the session is
|
|
43
|
+
* minted via the same wallet path as Phantom and shares the unified session store
|
|
44
|
+
* (web localStorage / RN storage) and identity model. `init()` must have run first.
|
|
45
|
+
*/
|
|
46
|
+
export declare function loginWithPrivy(options?: LoginOptions): Promise<User | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Send a 6-digit login code to `email` (Bounded Better Auth). Step 1 of the
|
|
49
|
+
* inline email flow — build your own email/code UI, or just call `login()` for
|
|
50
|
+
* the built-in modal. Works on web AND React Native (no DOM needed).
|
|
51
|
+
*/
|
|
52
|
+
export declare function sendEmailOtp(email: string): Promise<{
|
|
53
|
+
ok: true;
|
|
54
|
+
expiresInSeconds?: number;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Verify the `code` for `email`, establish the session, and return the user.
|
|
58
|
+
* Step 2 of the inline email flow. Coexists with signInAnonymously()/wallets.
|
|
59
|
+
*/
|
|
60
|
+
export declare function verifyEmailOtp(email: string, code: string): Promise<User | null>;
|
|
61
|
+
/**
|
|
62
|
+
* UPGRADE the current anonymous (guest) session by linking an email — Firebase
|
|
63
|
+
* `linkWithCredential` parity. Send the code first with `sendEmailOtp(email)`,
|
|
64
|
+
* then call `linkEmail(email, code)`. If the email is brand-new the guest's
|
|
65
|
+
* `@user.id` (and its data) is preserved; if the email already exists the user
|
|
66
|
+
* just signs into it (no merge). After it resolves, `getCurrentUser().isAnonymous`
|
|
67
|
+
* is `false`. Requires an active guest session (`signInAnonymously()` first).
|
|
68
|
+
*/
|
|
69
|
+
export declare function linkEmail(email: string, code: string): Promise<User | null>;
|
|
70
|
+
export declare function login(options?: LoginOptions): Promise<User | null>;
|
|
71
|
+
export declare function getCurrentAuthMethod(): string | null;
|
|
72
|
+
export declare function logout(): Promise<void>;
|
|
73
|
+
export { loginWithRedirect, linkWithRedirect, completeLoginFromRedirect, loginWithPopup, completeLoginInPopup } from './oidc-auth';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { User } from '@bounded-sh/core';
|
|
2
|
+
/** Start login: navigate the whole page to the hosted Bounded login. Returns after redirect
|
|
3
|
+
* to `redirectUri?code=...`, where you call completeLoginFromRedirect(). Web only. */
|
|
4
|
+
export declare function loginWithRedirect(opts: {
|
|
5
|
+
redirectUri: string;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
/** UPGRADE the current anonymous (guest) session by linking a SOCIAL/redirect login
|
|
8
|
+
* (e.g. Google) — Firebase `linkWithPopup`/redirect parity. Stashes the guest token,
|
|
9
|
+
* then runs the normal redirect login; `completeLoginFromRedirect()` on the callback
|
|
10
|
+
* page finishes the link automatically (if the social account is brand-new the guest's
|
|
11
|
+
* `@user.id` is preserved, else it stays separate). Requires an active guest session. */
|
|
12
|
+
export declare function linkWithRedirect(opts: {
|
|
13
|
+
redirectUri: string;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
/** Finish login on the redirect_uri page: exchange ?code= for a token (PKCE-verified), store
|
|
16
|
+
* the session, and return the User. Idempotent: returns null if there's no ?code= in the URL. */
|
|
17
|
+
export declare function completeLoginFromRedirect(): Promise<User | null>;
|
|
18
|
+
/** Popup variant: open the hosted login in a popup; resolves with the User once the popup's
|
|
19
|
+
* redirect_uri page posts the code back. The redirect_uri page must call completeLoginInPopup(). */
|
|
20
|
+
export declare function loginWithPopup(opts: {
|
|
21
|
+
redirectUri: string;
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
}): Promise<User>;
|
|
25
|
+
/** Call this on the redirect_uri page when login was opened via loginWithPopup(): posts the
|
|
26
|
+
* code back to the opener and closes. (For the redirect variant use completeLoginFromRedirect.) */
|
|
27
|
+
export declare function completeLoginInPopup(openerOrigin: string): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AuthProvider, User, TransactionResult, SolTransaction, EVMTransaction, SetOptions } from '@bounded-sh/core';
|
|
2
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
/** Send a login code to `email`. Step 1 of the inline email-OTP flow. */
|
|
4
|
+
export declare function sendEmailOtp(email: string): Promise<{
|
|
5
|
+
ok: true;
|
|
6
|
+
expiresInSeconds?: number;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Verify the code for `email` and establish the session. Step 2 of the flow.
|
|
10
|
+
* Stores the Bounded id token (the realtime bearer) and sets the current user.
|
|
11
|
+
*/
|
|
12
|
+
export declare function verifyEmailOtp(email: string, otp: string): Promise<User>;
|
|
13
|
+
/**
|
|
14
|
+
* UPGRADE an anonymous (guest) session by LINKING an email credential — Firebase
|
|
15
|
+
* `linkWithCredential` parity. The guest's `guestToken` is sent to the auth issuer
|
|
16
|
+
* which, IF the email is brand-new, makes the new account ADOPT the guest's id so
|
|
17
|
+
* `@user.id` is preserved and the guest's data carries over. If the email already
|
|
18
|
+
* exists, the user just signs into it (stays separate; `linked:false`). On success
|
|
19
|
+
* the upgraded session replaces the guest session and the user is no longer
|
|
20
|
+
* anonymous. `guestToken` is captured by the caller BEFORE switching auth methods.
|
|
21
|
+
*/
|
|
22
|
+
export declare function linkEmailWithGuest(email: string, otp: string, guestToken: string): Promise<{
|
|
23
|
+
user: User;
|
|
24
|
+
linked: boolean;
|
|
25
|
+
isNewAccount: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
export declare class EmailAuthProvider implements AuthProvider {
|
|
28
|
+
login(): Promise<User | null>;
|
|
29
|
+
restoreSession(): Promise<User | null>;
|
|
30
|
+
logout(): Promise<void>;
|
|
31
|
+
signMessage(_message: string): Promise<string>;
|
|
32
|
+
runTransaction(_evm?: EVMTransaction, _sol?: SolTransaction, _options?: SetOptions): Promise<TransactionResult>;
|
|
33
|
+
signTransaction(_t: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
34
|
+
signAndSubmitTransaction(): Promise<string>;
|
|
35
|
+
getNativeMethods(): Promise<any>;
|
|
36
|
+
}
|
|
37
|
+
declare const emailProviderSingleton: EmailAuthProvider;
|
|
38
|
+
export { emailProviderSingleton };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AuthProvider, User, TransactionResult, SolTransaction, EVMTransaction, SetOptions } from '@bounded-sh/core';
|
|
2
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
export declare class GuestAuthProvider implements AuthProvider {
|
|
4
|
+
login(): Promise<User | null>;
|
|
5
|
+
restoreSession(): Promise<User | null>;
|
|
6
|
+
logout(): Promise<void>;
|
|
7
|
+
/** Wipe the device key — the next login() is a brand-new guest identity. */
|
|
8
|
+
forgetGuest(): Promise<void>;
|
|
9
|
+
signMessage(message: string): Promise<string>;
|
|
10
|
+
runTransaction(_evm?: EVMTransaction, _sol?: SolTransaction, _options?: SetOptions): Promise<TransactionResult>;
|
|
11
|
+
signTransaction(_t: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
12
|
+
signAndSubmitTransaction(): Promise<string>;
|
|
13
|
+
getNativeMethods(): Promise<any>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface GuestKey {
|
|
2
|
+
/** base58 public key — the account address. */
|
|
3
|
+
address: string;
|
|
4
|
+
/** Sign a UTF-8 message; returns a base64 detached signature. */
|
|
5
|
+
sign(message: string): Promise<string>;
|
|
6
|
+
/** True when backed by a non-extractable WebCrypto key. */
|
|
7
|
+
nonExtractable: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Get (or create) this device's durable guest key. */
|
|
10
|
+
export declare function getGuestKey(): Promise<GuestKey>;
|
|
11
|
+
/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
|
|
12
|
+
export declare function clearGuestKey(): Promise<void>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AuthProvider, User, TransactionResult, SolTransaction, EVMTransaction } from '@bounded-sh/core';
|
|
2
|
+
import { SetOptions } from '@bounded-sh/core';
|
|
3
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
4
|
+
export declare const DEFAULT_TEST_ADDRESS = "HKbZbRR7jWWR5VRN8KFjvTCHEzJQgameYxKQxh2gPoof";
|
|
5
|
+
/**
|
|
6
|
+
* MockAuthProvider bypasses real wallet authentication for testing purposes.
|
|
7
|
+
* Uses session storage to simulate logged-in user, with fallback to default test address.
|
|
8
|
+
*
|
|
9
|
+
* This is enabled by passing mockAuth: true to init()
|
|
10
|
+
*/
|
|
11
|
+
export declare class MockAuthProvider implements AuthProvider {
|
|
12
|
+
/**
|
|
13
|
+
* Mock login - reads user from session storage or uses default test address
|
|
14
|
+
*/
|
|
15
|
+
login(): Promise<User | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Mock transaction - returns fake signature without actual blockchain interaction
|
|
18
|
+
* The real transaction will be handled by the backend using test headers
|
|
19
|
+
*/
|
|
20
|
+
runTransaction(evmTransactionData?: EVMTransaction, solTransactionData?: SolTransaction, options?: SetOptions): Promise<TransactionResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Mock message signing
|
|
23
|
+
*/
|
|
24
|
+
signMessage(message: string): Promise<string>;
|
|
25
|
+
signMessageMock(message: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Mock transaction signing - returns the transaction as-is (no actual signing)
|
|
28
|
+
*/
|
|
29
|
+
signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
30
|
+
/**
|
|
31
|
+
* Sign and submit transaction - not supported in mock environment.
|
|
32
|
+
* See the real providers (PhantomWalletProvider, SolanaKeypairProvider)
|
|
33
|
+
* for the full implementation with blockhash handling and feePayer support.
|
|
34
|
+
*/
|
|
35
|
+
signAndSubmitTransaction(_transaction: Transaction | VersionedTransaction, _feePayer?: any): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Restore session - only restores if user previously called login() explicitly.
|
|
38
|
+
* This prevents auto-login on first page load, but allows session persistence after login.
|
|
39
|
+
*/
|
|
40
|
+
restoreSession(): Promise<User | null>;
|
|
41
|
+
/**
|
|
42
|
+
* Mock logout - clears test user from session storage
|
|
43
|
+
*/
|
|
44
|
+
logout(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Get native wallet methods (not needed for mock auth)
|
|
47
|
+
*/
|
|
48
|
+
getNativeMethods(): Promise<any>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AuthProvider, User, TransactionResult, EVMTransaction, SolTransaction } from "@bounded-sh/core";
|
|
2
|
+
import { SetOptions } from "@bounded-sh/core";
|
|
3
|
+
import { Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
4
|
+
export interface OffchainAuthProviderConfig {
|
|
5
|
+
onSigningStart?: () => void;
|
|
6
|
+
onSigningComplete?: (signature: string) => void;
|
|
7
|
+
onSigningError?: (error: Error) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* OffchainAuthProvider wraps a real auth provider (e.g., Phantom) for the poofnet environment.
|
|
11
|
+
*
|
|
12
|
+
* For signMessageMock, this shows a custom confirmation modal and generates a mock signature.
|
|
13
|
+
* This is used for offchain transaction signing. For real wallet signing, use signMessage
|
|
14
|
+
* which delegates to the wrapped provider.
|
|
15
|
+
*/
|
|
16
|
+
export declare class OffchainAuthProvider implements AuthProvider {
|
|
17
|
+
private wrappedProvider;
|
|
18
|
+
private config;
|
|
19
|
+
private modalContainer;
|
|
20
|
+
constructor(wrappedProvider: AuthProvider, config?: OffchainAuthProviderConfig);
|
|
21
|
+
login(): Promise<User | null>;
|
|
22
|
+
logout(): Promise<void>;
|
|
23
|
+
restoreSession(): Promise<User | null>;
|
|
24
|
+
runTransaction(evmTransactionData?: EVMTransaction, solTransactionData?: SolTransaction, options?: SetOptions): Promise<TransactionResult>;
|
|
25
|
+
signTransaction(tx: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
26
|
+
/**
|
|
27
|
+
* Sign and submit transaction - not supported in poofnet environment.
|
|
28
|
+
* See the real providers (PhantomWalletProvider, SolanaKeypairProvider)
|
|
29
|
+
* for the full implementation with blockhash handling and feePayer support.
|
|
30
|
+
*/
|
|
31
|
+
signAndSubmitTransaction(_transaction: Transaction | VersionedTransaction, _feePayer?: any): Promise<string>;
|
|
32
|
+
getNativeMethods(): Promise<any>;
|
|
33
|
+
signMessage(message: string): Promise<string>;
|
|
34
|
+
signMessageMock(message: string): Promise<string>;
|
|
35
|
+
private showUnsupportedTransactionModal;
|
|
36
|
+
private getUnsupportedModalHTML;
|
|
37
|
+
private showTransactionModal;
|
|
38
|
+
private closeModal;
|
|
39
|
+
/**
|
|
40
|
+
* Escape a value for safe interpolation into an HTML string.
|
|
41
|
+
*
|
|
42
|
+
* Transaction messages are attacker-influenceable (they originate from
|
|
43
|
+
* server responses / app-supplied data), so every value derived from them
|
|
44
|
+
* MUST be escaped before being placed into innerHTML. Without this, a field
|
|
45
|
+
* key/value, path segment, document id, or raw message containing markup
|
|
46
|
+
* such as `<img src=x onerror=...>` would execute in the dApp origin and
|
|
47
|
+
* could exfiltrate the stored session (idToken/refreshToken).
|
|
48
|
+
*/
|
|
49
|
+
private escapeHtml;
|
|
50
|
+
private formatPath;
|
|
51
|
+
private formatFieldValue;
|
|
52
|
+
private getActionDescription;
|
|
53
|
+
private getModalHTML;
|
|
54
|
+
private getModalStyles;
|
|
55
|
+
private generateMockSignature;
|
|
56
|
+
}
|