@pooflabs/server 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 +259 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/providers/solana-keypair-provider.d.ts +18 -0
- package/dist/global.d.ts +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +10450 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +10410 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# @tarobase/server
|
|
2
|
+
|
|
3
|
+
Server SDK for Tarobase API - Node.js/Backend implementation. This package provides functionality for server-side applications to interact with the Tarobase API using Solana keypairs for authentication.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tarobase/server
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or using yarn:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
yarn add @tarobase/server
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- Server-side authentication using Solana keypairs
|
|
20
|
+
- In-memory session management (no cookies or local storage required)
|
|
21
|
+
- Support for all Tarobase data operations (get, set, query)
|
|
22
|
+
- Real-time subscriptions
|
|
23
|
+
- Transaction signing and execution
|
|
24
|
+
- TypeScript support
|
|
25
|
+
|
|
26
|
+
## Basic Usage
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { init, login, getCurrentUser, set, get } from '@tarobase/server';
|
|
30
|
+
import { Keypair } from '@solana/web3.js';
|
|
31
|
+
|
|
32
|
+
async function main() {
|
|
33
|
+
// Initialize the SDK
|
|
34
|
+
await init({
|
|
35
|
+
apiKey: 'your-api-key',
|
|
36
|
+
appId: 'your-app-id',
|
|
37
|
+
authMethod: 'solana-keypair'
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Create or load a Solana keypair
|
|
41
|
+
const keypair = Keypair.generate(); // or load from a file/secret
|
|
42
|
+
// Alternative: const keypair = "your-base58-encoded-private-key"
|
|
43
|
+
|
|
44
|
+
// Log in with the keypair
|
|
45
|
+
const user = await login(keypair);
|
|
46
|
+
if (!user) {
|
|
47
|
+
console.error('Login failed');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.log(`Logged in as: ${user.address}`);
|
|
52
|
+
|
|
53
|
+
// Set data
|
|
54
|
+
await set('todos/123', {
|
|
55
|
+
text: 'Buy milk',
|
|
56
|
+
completed: false,
|
|
57
|
+
created: new Date().toISOString()
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Get data
|
|
61
|
+
const todo = await get('todos/123');
|
|
62
|
+
console.log('Retrieved todo:', todo);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main().catch(console.error);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Advanced Usage
|
|
69
|
+
|
|
70
|
+
### Loading a Keypair from a Secret Key File
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { init, login, getCurrentUser } from '@tarobase/server';
|
|
74
|
+
import { Keypair } from '@solana/web3.js';
|
|
75
|
+
import * as fs from 'fs';
|
|
76
|
+
|
|
77
|
+
// Load keypair from file
|
|
78
|
+
const secretKeyString = fs.readFileSync('/path/to/keypair.json', 'utf8');
|
|
79
|
+
const secretKey = Uint8Array.from(JSON.parse(secretKeyString));
|
|
80
|
+
const keypair = Keypair.fromSecretKey(secretKey);
|
|
81
|
+
|
|
82
|
+
// Initialize and login
|
|
83
|
+
await init({ apiKey: 'your-api-key', appId: 'your-app-id' });
|
|
84
|
+
await login(keypair);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Using the SolanaKeypairProvider Directly
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { init, SolanaKeypairProvider, getAuthProvider } from '@tarobase/server';
|
|
91
|
+
import { Keypair } from '@solana/web3.js';
|
|
92
|
+
|
|
93
|
+
// Initialize the SDK
|
|
94
|
+
await init({
|
|
95
|
+
apiKey: 'your-api-key',
|
|
96
|
+
appId: 'your-app-id',
|
|
97
|
+
rpcUrl: 'https://api.mainnet-beta.solana.com'
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Get the auth provider (automatically created during init)
|
|
101
|
+
const provider = await getAuthProvider() as SolanaKeypairProvider;
|
|
102
|
+
|
|
103
|
+
// Or create a provider instance directly
|
|
104
|
+
// const provider = new SolanaKeypairProvider("https://api.mainnet-beta.solana.com");
|
|
105
|
+
|
|
106
|
+
// Set the keypair
|
|
107
|
+
provider.setKeypair(Keypair.generate());
|
|
108
|
+
|
|
109
|
+
// Login
|
|
110
|
+
const user = await provider.login();
|
|
111
|
+
|
|
112
|
+
// Sign a message
|
|
113
|
+
const signature = await provider.signMessage("Hello, world!");
|
|
114
|
+
|
|
115
|
+
// Run a transaction (example)
|
|
116
|
+
const txResult = await provider.runTransaction(undefined, {
|
|
117
|
+
appId: 'your-app-id',
|
|
118
|
+
txArgs: [{
|
|
119
|
+
setDocumentData: [{ path: 'todos/123', data: { text: 'New todo' } }],
|
|
120
|
+
deletePaths: [],
|
|
121
|
+
remainingAccounts: [],
|
|
122
|
+
idl: {}
|
|
123
|
+
}]
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Subscriptions
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { init, login, subscribe, unsubscribe } from '@tarobase/server';
|
|
131
|
+
import { Keypair } from '@solana/web3.js';
|
|
132
|
+
|
|
133
|
+
// Initialize and login
|
|
134
|
+
await init({ apiKey: 'your-api-key', appId: 'your-app-id' });
|
|
135
|
+
await login(Keypair.generate());
|
|
136
|
+
|
|
137
|
+
// Subscribe to changes
|
|
138
|
+
const unsubscribeFunc = await subscribe('todos', (data) => {
|
|
139
|
+
console.log('Todos updated:', data);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Later, unsubscribe when done
|
|
143
|
+
unsubscribeFunc();
|
|
144
|
+
// Or use the unsubscribe function
|
|
145
|
+
await unsubscribe('todos');
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## API Reference
|
|
149
|
+
|
|
150
|
+
### Configuration and Initialization
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
function init(config: Partial<ClientConfig>): Promise<void>;
|
|
154
|
+
function getConfig(): Promise<ClientConfig>;
|
|
155
|
+
function getSessionOptions(): SessionOptions;
|
|
156
|
+
function isInitialized(): boolean;
|
|
157
|
+
function waitForInitialization(): Promise<void>;
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Authentication
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
function login(keypair?: Keypair | string | Uint8Array): Promise<User | null>;
|
|
164
|
+
function logout(): Promise<void>;
|
|
165
|
+
function getCurrentUser(): User | null;
|
|
166
|
+
function getAuthProvider(): Promise<AuthProvider>;
|
|
167
|
+
function getIdToken(): Promise<string | null>;
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Data Operations
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
function get(path: string): Promise<any>;
|
|
174
|
+
function set(path: string, data: any, options?: SetOptions): Promise<any>;
|
|
175
|
+
function setMany(paths: { [key: string]: any }, options?: SetOptions): Promise<any>;
|
|
176
|
+
function setFile(path: string, file: File, metadata?: any): Promise<any>;
|
|
177
|
+
function getFiles(path: string): Promise<any>;
|
|
178
|
+
function runQuery(queryString: string, variables?: any): Promise<any>;
|
|
179
|
+
function runQueryMany(queryString: string, variables?: any): Promise<any>;
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Subscriptions
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
function subscribe(path: string, callback: (data: any) => void): Promise<() => void>;
|
|
186
|
+
function unsubscribe(path: string): Promise<void>;
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Solana Keypair Provider
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
class SolanaKeypairProvider implements AuthProvider {
|
|
193
|
+
constructor(networkUrl?: string);
|
|
194
|
+
|
|
195
|
+
setKeypair(keypair: Keypair | string | Uint8Array): void;
|
|
196
|
+
login(): Promise<User | null>;
|
|
197
|
+
logout(): Promise<void>;
|
|
198
|
+
signMessage(message: string): Promise<string>;
|
|
199
|
+
runTransaction(evmTransactionData?: EVMTransaction, solTransactionData?: SolTransaction, options?: SetOptions): Promise<TransactionResult>;
|
|
200
|
+
restoreSession(): Promise<User | null>;
|
|
201
|
+
getNativeMethods(): Promise<any>;
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Types
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
interface ClientConfig {
|
|
209
|
+
apiKey: string;
|
|
210
|
+
authMethod: 'solana-keypair' | string;
|
|
211
|
+
wsApiUrl: string;
|
|
212
|
+
apiUrl: string;
|
|
213
|
+
appId: string;
|
|
214
|
+
authApiUrl: string;
|
|
215
|
+
chain: string;
|
|
216
|
+
rpcUrl: string;
|
|
217
|
+
skipBackendInit: boolean;
|
|
218
|
+
useSessionStorage: boolean;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
interface User {
|
|
222
|
+
address: string;
|
|
223
|
+
provider: AuthProvider;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
interface SetOptions {
|
|
227
|
+
shouldSubmitTx?: boolean;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
interface TransactionResult {
|
|
231
|
+
transactionSignature?: string;
|
|
232
|
+
signedTransaction?: any;
|
|
233
|
+
blockNumber: number;
|
|
234
|
+
gasUsed: string;
|
|
235
|
+
data: any;
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Contributing
|
|
240
|
+
|
|
241
|
+
Please see the main repository for contribution guidelines.
|
|
242
|
+
|
|
243
|
+
## Key Differences from the Web SDK
|
|
244
|
+
|
|
245
|
+
This server-side SDK differs from the web SDK in several important ways:
|
|
246
|
+
|
|
247
|
+
1. **Authentication Method**: Uses Solana keypairs instead of browser wallets
|
|
248
|
+
2. **Storage Strategy**: Uses in-memory storage instead of localStorage/sessionStorage
|
|
249
|
+
3. **Environment**: Optimized for Node.js/backend environments rather than browsers
|
|
250
|
+
4. **Session Management**: Does not rely on browser-specific APIs
|
|
251
|
+
5. **Dependencies**: Excludes browser-specific libraries
|
|
252
|
+
|
|
253
|
+
## Part of the Tarobase SDK Family
|
|
254
|
+
|
|
255
|
+
This package is part of a family of modular SDKs:
|
|
256
|
+
|
|
257
|
+
- **@tarobase/core**: Core functionality shared between all SDKs
|
|
258
|
+
- **@tarobase/web**: Browser-focused SDK (identical to original js-sdk)
|
|
259
|
+
- **@tarobase/server**: Server-side SDK for backend applications
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Connection, Keypair } from '@solana/web3.js';
|
|
2
|
+
import type { AuthProvider, EVMTransaction, SolTransaction, TransactionResult, User, SetOptions } from '@tarobase/core';
|
|
3
|
+
export declare class SolanaKeypairProvider implements AuthProvider {
|
|
4
|
+
private readonly networkUrl;
|
|
5
|
+
private readonly connection;
|
|
6
|
+
private readonly keypair;
|
|
7
|
+
constructor(networkUrl?: string);
|
|
8
|
+
login(): Promise<User | null>;
|
|
9
|
+
restoreSession(): Promise<User | null>;
|
|
10
|
+
logout(): Promise<void>;
|
|
11
|
+
signMessage(message: string): Promise<string>;
|
|
12
|
+
runTransaction(_evm?: EVMTransaction, sol?: SolTransaction, opts?: SetOptions): Promise<TransactionResult>;
|
|
13
|
+
private runTransactionInner;
|
|
14
|
+
getNativeMethods(): Promise<{
|
|
15
|
+
keypair: Keypair;
|
|
16
|
+
connection: Connection;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
package/dist/global.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { init } from "./global";
|
|
2
|
+
export { getConfig } from '@tarobase/core';
|
|
3
|
+
export { getAuthProvider } from './auth';
|
|
4
|
+
export { get, set, setMany, setFile, getFiles, runQuery, runQueryMany } from '@tarobase/core';
|
|
5
|
+
export { subscribe } from '@tarobase/core';
|
|
6
|
+
export * from '@tarobase/core';
|
|
7
|
+
export { getIdToken } from '@tarobase/core';
|