@pooflabs/server 0.0.2 → 0.0.3
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/dist/auth/providers/solana-keypair-provider.d.ts +2 -1
- package/dist/global.d.ts +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +32 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Connection, Keypair } from '@solana/web3.js';
|
|
1
|
+
import { Connection, Keypair, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
2
|
import type { AuthProvider, EVMTransaction, SolTransaction, TransactionResult, User, SetOptions } from '@pooflabs/core';
|
|
3
3
|
export declare class SolanaKeypairProvider implements AuthProvider {
|
|
4
4
|
private readonly networkUrl;
|
|
@@ -9,6 +9,7 @@ export declare class SolanaKeypairProvider implements AuthProvider {
|
|
|
9
9
|
restoreSession(): Promise<User | null>;
|
|
10
10
|
logout(): Promise<void>;
|
|
11
11
|
signMessage(message: string): Promise<string>;
|
|
12
|
+
signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
12
13
|
runTransaction(_evm?: EVMTransaction, sol?: SolTransaction, opts?: SetOptions): Promise<TransactionResult>;
|
|
13
14
|
private runTransactionInner;
|
|
14
15
|
getNativeMethods(): Promise<{
|
package/dist/global.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { ClientConfig } from '@pooflabs/core';
|
|
2
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
2
3
|
export declare function init(newConfig: Partial<ClientConfig>): Promise<void>;
|
|
4
|
+
export declare function signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { init } from "./global";
|
|
1
|
+
export { init, signTransaction } from "./global";
|
|
2
2
|
export { getConfig } from '@pooflabs/core';
|
|
3
3
|
export { getAuthProvider } from './auth';
|
|
4
4
|
export { get, set, setMany, setFile, getFiles, runQuery, runQueryMany, runExpression, runExpressionMany } from '@pooflabs/core';
|
package/dist/index.js
CHANGED
|
@@ -108,7 +108,6 @@ class WebSessionManager {
|
|
|
108
108
|
/* ---------- validate app-id ---------- */
|
|
109
109
|
const config = await getConfig();
|
|
110
110
|
if (sessionObj.appId && sessionObj.appId !== config.appId) {
|
|
111
|
-
console.warn("Session appId mismatch. Stored session belongs to a different app. Logging out.");
|
|
112
111
|
this.clearSession();
|
|
113
112
|
return null;
|
|
114
113
|
}
|
|
@@ -133,7 +132,6 @@ class WebSessionManager {
|
|
|
133
132
|
}
|
|
134
133
|
}
|
|
135
134
|
catch (err) {
|
|
136
|
-
console.error("Error decoding access token:", err);
|
|
137
135
|
return null;
|
|
138
136
|
}
|
|
139
137
|
return { address: sessionObj.address, session: sessionObj };
|
|
@@ -184,7 +182,6 @@ class WebSessionManager {
|
|
|
184
182
|
/* ---------- app-id guard ---------- */
|
|
185
183
|
const config = await getConfig();
|
|
186
184
|
if (sessionObj.appId && sessionObj.appId !== config.appId) {
|
|
187
|
-
console.warn("Session appId mismatch during token refresh. Logging out.");
|
|
188
185
|
this.clearSession();
|
|
189
186
|
return;
|
|
190
187
|
}
|
|
@@ -6277,7 +6274,8 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
|
|
|
6277
6274
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
6278
6275
|
tx.recentBlockhash = blockhash;
|
|
6279
6276
|
if (lutKey == null) {
|
|
6280
|
-
const
|
|
6277
|
+
const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
|
|
6278
|
+
const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, []);
|
|
6281
6279
|
const computeBudgetIxOptimized = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
6282
6280
|
units: computeUnits ? computeUnits * 1.2 : 1400000,
|
|
6283
6281
|
}); // 20% buffer
|
|
@@ -6287,7 +6285,8 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
|
|
|
6287
6285
|
const { value: table } = await connection.getAddressLookupTable(new web3_js.PublicKey(lutKey));
|
|
6288
6286
|
if (!table)
|
|
6289
6287
|
throw new Error('LUT not found after creation/extend');
|
|
6290
|
-
const
|
|
6288
|
+
const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
|
|
6289
|
+
const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, [table]);
|
|
6291
6290
|
const computeBudgetIxOptimized = web3_js.ComputeBudgetProgram.setComputeUnitLimit({
|
|
6292
6291
|
units: computeUnits ? computeUnits * 1.2 : 1400000,
|
|
6293
6292
|
}); // 20% buffer
|
|
@@ -6424,7 +6423,7 @@ function updateIdTokenAndAccessToken(idToken, accessToken) {
|
|
|
6424
6423
|
}
|
|
6425
6424
|
|
|
6426
6425
|
async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
6427
|
-
var _a, _b, _c, _d, _e, _f
|
|
6426
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6428
6427
|
const config = await getConfig();
|
|
6429
6428
|
async function executeRequest() {
|
|
6430
6429
|
const authHeader = await createAuthHeader(config.isServer);
|
|
@@ -6474,8 +6473,7 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
6474
6473
|
return { data: null, status: 404 };
|
|
6475
6474
|
}
|
|
6476
6475
|
if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) {
|
|
6477
|
-
|
|
6478
|
-
throw new Error((_j = (_h = error.response) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.message);
|
|
6476
|
+
throw new Error((_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.message);
|
|
6479
6477
|
}
|
|
6480
6478
|
throw error;
|
|
6481
6479
|
}
|
|
@@ -6516,8 +6514,6 @@ function init$1(newConfig) {
|
|
|
6516
6514
|
isInitialized = true;
|
|
6517
6515
|
resolve();
|
|
6518
6516
|
}).catch((error) => {
|
|
6519
|
-
console.error('Failed to authenticate with API key or fetch config for this app:', error);
|
|
6520
|
-
console.error('Please check your API key and try again.');
|
|
6521
6517
|
reject(new Error("Failed to initialize Tarobase app."));
|
|
6522
6518
|
});
|
|
6523
6519
|
});
|
|
@@ -6621,16 +6617,11 @@ async function get(path, opts = {}) {
|
|
|
6621
6617
|
// Helper to clean up expired cache entries
|
|
6622
6618
|
function cleanupExpiredCache() {
|
|
6623
6619
|
const now = Date.now();
|
|
6624
|
-
let removedCount = 0;
|
|
6625
6620
|
Object.keys(getCache).forEach(key => {
|
|
6626
6621
|
if (getCache[key] && getCache[key].expiresAt < now) {
|
|
6627
6622
|
delete getCache[key];
|
|
6628
|
-
removedCount++;
|
|
6629
6623
|
}
|
|
6630
6624
|
});
|
|
6631
|
-
if (removedCount > 0) {
|
|
6632
|
-
console.debug(`Cleaned up ${removedCount} expired cache entries`);
|
|
6633
|
-
}
|
|
6634
6625
|
lastCacheCleanup = now;
|
|
6635
6626
|
}
|
|
6636
6627
|
async function runQuery(absolutePath, queryName, queryArgs) {
|
|
@@ -6764,7 +6755,6 @@ async function setMany(many, options) {
|
|
|
6764
6755
|
}
|
|
6765
6756
|
}
|
|
6766
6757
|
catch (error) {
|
|
6767
|
-
console.error("Error setting data", error);
|
|
6768
6758
|
throw error;
|
|
6769
6759
|
}
|
|
6770
6760
|
async function handleSolanaTransaction(tx, authProvider, options) {
|
|
@@ -6881,9 +6871,7 @@ async function setFile(path, file) {
|
|
|
6881
6871
|
});
|
|
6882
6872
|
// 3) Check if the upload was successful
|
|
6883
6873
|
if (!uploadResponse.ok) {
|
|
6884
|
-
|
|
6885
|
-
const errorText = await uploadResponse.text();
|
|
6886
|
-
console.error('S3 Error Body:', errorText);
|
|
6874
|
+
await uploadResponse.text();
|
|
6887
6875
|
throw new Error(`Upload failed with status: ${uploadResponse.status}`);
|
|
6888
6876
|
}
|
|
6889
6877
|
// Optionally return the file's public URL or some confirmation
|
|
@@ -7571,10 +7559,9 @@ async function subscribe(path, subscriptionOptions) {
|
|
|
7571
7559
|
}
|
|
7572
7560
|
});
|
|
7573
7561
|
ws.addEventListener('error', (event) => {
|
|
7574
|
-
console.error(`WebSocket error for path: ${connectionKey}`, event);
|
|
7575
7562
|
notifyError(connectionKey, event);
|
|
7576
7563
|
});
|
|
7577
|
-
ws.addEventListener('close', (
|
|
7564
|
+
ws.addEventListener('close', () => {
|
|
7578
7565
|
// Connection will be recreated on next subscription if needed
|
|
7579
7566
|
});
|
|
7580
7567
|
return async () => await removeSubscription(connectionKey, subscriptionOptions);
|
|
@@ -7615,8 +7602,7 @@ async function removeSubscription(connectionKey, subscription) {
|
|
|
7615
7602
|
ws.addEventListener('close', () => {
|
|
7616
7603
|
resolve();
|
|
7617
7604
|
});
|
|
7618
|
-
ws.addEventListener('error', (
|
|
7619
|
-
console.error(`WebSocket closure error for connection: ${connectionKey}`, err);
|
|
7605
|
+
ws.addEventListener('error', () => {
|
|
7620
7606
|
resolve(); // Resolve even on error to avoid hanging
|
|
7621
7607
|
});
|
|
7622
7608
|
ws.close();
|
|
@@ -10261,6 +10247,18 @@ class SolanaKeypairProvider {
|
|
|
10261
10247
|
const sig = nacl.sign.detached(new TextEncoder().encode(message), this.keypair.secretKey);
|
|
10262
10248
|
return Buffer.from(sig).toString('base64');
|
|
10263
10249
|
}
|
|
10250
|
+
/* ----------------------------------------------------------- *
|
|
10251
|
+
* Sign transaction
|
|
10252
|
+
* ----------------------------------------------------------- */
|
|
10253
|
+
async signTransaction(transaction) {
|
|
10254
|
+
if (transaction instanceof web3_js.Transaction) {
|
|
10255
|
+
transaction.partialSign(this.keypair);
|
|
10256
|
+
}
|
|
10257
|
+
else if (transaction instanceof web3_js.VersionedTransaction) {
|
|
10258
|
+
transaction.sign([this.keypair]);
|
|
10259
|
+
}
|
|
10260
|
+
return transaction;
|
|
10261
|
+
}
|
|
10264
10262
|
/* ----------------------------------------------------------- *
|
|
10265
10263
|
* Transaction runner
|
|
10266
10264
|
* ----------------------------------------------------------- */
|
|
@@ -10414,6 +10412,7 @@ class SolanaKeypairProvider {
|
|
|
10414
10412
|
let currentAuthProvider = null;
|
|
10415
10413
|
const SOLANA_DEVNET_RPC_URL$1 = "https://api.devnet.solana.com";
|
|
10416
10414
|
const SOLANA_MAINNET_RPC_URL$1 = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
|
|
10415
|
+
const SURFNET_RPC_URL$1 = "https://surfpool.fly.dev";
|
|
10417
10416
|
async function getAuthProvider() {
|
|
10418
10417
|
var _a;
|
|
10419
10418
|
if (currentAuthProvider) {
|
|
@@ -10429,7 +10428,7 @@ async function getAuthProvider() {
|
|
|
10429
10428
|
rpcUrl = SOLANA_MAINNET_RPC_URL$1;
|
|
10430
10429
|
}
|
|
10431
10430
|
else {
|
|
10432
|
-
rpcUrl =
|
|
10431
|
+
rpcUrl = SURFNET_RPC_URL$1;
|
|
10433
10432
|
}
|
|
10434
10433
|
currentAuthProvider = await matchAuthProvider((_a = config.rpcUrl) !== null && _a !== void 0 ? _a : rpcUrl);
|
|
10435
10434
|
return currentAuthProvider;
|
|
@@ -10441,6 +10440,7 @@ async function matchAuthProvider(rpcUrl) {
|
|
|
10441
10440
|
let authProviderInstance = null;
|
|
10442
10441
|
const SOLANA_DEVNET_RPC_URL = "https://api.devnet.solana.com";
|
|
10443
10442
|
const SOLANA_MAINNET_RPC_URL = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
|
|
10443
|
+
const SURFNET_RPC_URL = "https://surfpool.fly.dev";
|
|
10444
10444
|
async function init(newConfig) {
|
|
10445
10445
|
var _a;
|
|
10446
10446
|
let defaultRpcUrl = '';
|
|
@@ -10451,11 +10451,17 @@ async function init(newConfig) {
|
|
|
10451
10451
|
defaultRpcUrl = SOLANA_MAINNET_RPC_URL;
|
|
10452
10452
|
}
|
|
10453
10453
|
else {
|
|
10454
|
-
defaultRpcUrl =
|
|
10454
|
+
defaultRpcUrl = SURFNET_RPC_URL;
|
|
10455
10455
|
}
|
|
10456
10456
|
authProviderInstance = await matchAuthProvider((_a = newConfig.rpcUrl) !== null && _a !== void 0 ? _a : defaultRpcUrl);
|
|
10457
10457
|
await init$1(Object.assign(Object.assign({}, newConfig), { authProvider: authProviderInstance, isServer: true }));
|
|
10458
10458
|
}
|
|
10459
|
+
async function signTransaction(transaction) {
|
|
10460
|
+
if (!authProviderInstance) {
|
|
10461
|
+
throw new Error('Auth provider not initialized. Please call init() first.');
|
|
10462
|
+
}
|
|
10463
|
+
return await authProviderInstance.signTransaction(transaction);
|
|
10464
|
+
}
|
|
10459
10465
|
|
|
10460
10466
|
exports.ServerSessionManager = ServerSessionManager;
|
|
10461
10467
|
exports.WebSessionManager = WebSessionManager;
|
|
@@ -10479,5 +10485,6 @@ exports.set = set;
|
|
|
10479
10485
|
exports.setFile = setFile;
|
|
10480
10486
|
exports.setMany = setMany;
|
|
10481
10487
|
exports.signSessionCreateMessage = signSessionCreateMessage;
|
|
10488
|
+
exports.signTransaction = signTransaction;
|
|
10482
10489
|
exports.subscribe = subscribe;
|
|
10483
10490
|
//# sourceMappingURL=index.js.map
|