@pooflabs/web 0.0.35 → 0.0.36

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.
@@ -11940,6 +11940,11 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
11940
11940
  if (_overrides === null || _overrides === void 0 ? void 0 : _overrides.headers) {
11941
11941
  Object.assign(headers, _overrides.headers);
11942
11942
  }
11943
+ // Signal to backend that client supports offchain transaction signing
11944
+ if (typeof window !== "undefined" &&
11945
+ window.TAROBASE_SUPPORTS_OFFCHAIN_SIGNING) {
11946
+ headers["X-Supports-Offchain-Signing"] = "true";
11947
+ }
11943
11948
  const requestConfig = {
11944
11949
  method,
11945
11950
  url: `${config.apiUrl}${urlPath.startsWith("/") ? urlPath : `/${urlPath}`}`,
@@ -12322,7 +12327,6 @@ async function setMany(many, options) {
12322
12327
  return transactionResult;
12323
12328
  }
12324
12329
  async function handleOffchainTransaction(tx, authProvider, options) {
12325
- var _a, _b, _c, _d, _e;
12326
12330
  const config = await getConfig();
12327
12331
  // 1. Sign the transaction message using the auth provider
12328
12332
  const signature = await authProvider.signMessage(tx.message);
@@ -12339,19 +12343,10 @@ async function setMany(many, options) {
12339
12343
  };
12340
12344
  }
12341
12345
  // 4. Submit to RPC endpoint
12342
- // Use appId from headers if provided, otherwise fallback to config.appId
12343
- const appId = ((_b = (_a = options === null || options === void 0 ? void 0 : options._overrides) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['x-app-id']) || ((_d = (_c = options === null || options === void 0 ? void 0 : options._overrides) === null || _c === void 0 ? void 0 : _c.headers) === null || _d === void 0 ? void 0 : _d['X-App-Id']) || config.appId;
12344
- const rpcUrl = `${config.apiUrl}/app/${appId}/rpc`;
12345
- // Build headers, applying overrides if provided
12346
- const headers = {
12347
- 'Content-Type': 'application/json',
12348
- };
12349
- if ((_e = options === null || options === void 0 ? void 0 : options._overrides) === null || _e === void 0 ? void 0 : _e.headers) {
12350
- Object.assign(headers, options._overrides.headers);
12351
- }
12346
+ const rpcUrl = `${config.apiUrl}/app/${config.appId}/rpc`;
12352
12347
  const rpcResponse = await fetch(rpcUrl, {
12353
12348
  method: 'POST',
12354
- headers,
12349
+ headers: { 'Content-Type': 'application/json' },
12355
12350
  body: JSON.stringify({
12356
12351
  jsonrpc: '2.0',
12357
12352
  id: 1,
@@ -12657,7 +12652,7 @@ async function loadDependencies() {
12657
12652
  const [reactModule, reactDomModule, phantomModule] = await Promise.all([
12658
12653
  import('react'),
12659
12654
  import('react-dom/client'),
12660
- Promise.resolve().then(function () { return require('./index-BLvoqeoa.js'); })
12655
+ Promise.resolve().then(function () { return require('./index-Bfy2Olqg.js'); })
12661
12656
  ]);
12662
12657
  React$1 = reactModule;
12663
12658
  ReactDOM$1 = reactDomModule;
@@ -30214,6 +30209,10 @@ class PrivyWalletProvider {
30214
30209
  this.pendingLogin = null;
30215
30210
  // This is used to store the pending transaction until the wallet is connected for workaround for the wallet not being connected after login completion
30216
30211
  this.pendingTransaction = null;
30212
+ // This is used to store pending signTransaction calls until the wallet is connected
30213
+ this.pendingSignTransaction = null;
30214
+ // This is used to store pending signMessage calls until the wallet is connected
30215
+ this.pendingSignMessage = null;
30217
30216
  this.networkUrl = networkUrl;
30218
30217
  if (typeof window === 'undefined') {
30219
30218
  throw new Error('PrivyWalletProvider can only be instantiated in a browser environment');
@@ -30240,9 +30239,11 @@ class PrivyWalletProvider {
30240
30239
  if (networkUrl != null) {
30241
30240
  if (networkUrl.includes('mainnet')) {
30242
30241
  mainnetUrl = networkUrl;
30242
+ this.chainId = 'solana:mainnet';
30243
30243
  }
30244
30244
  else if (networkUrl.includes('devnet')) {
30245
30245
  devnetUrl = networkUrl;
30246
+ this.chainId = 'solana:devnet';
30246
30247
  }
30247
30248
  }
30248
30249
  if (!this.privyConfig.config.solana) {
@@ -30303,6 +30304,30 @@ class PrivyWalletProvider {
30303
30304
  }
30304
30305
  that.pendingTransaction = null;
30305
30306
  }
30307
+ // If there's a pending signTransaction, execute it now
30308
+ if (that.pendingSignTransaction) {
30309
+ const { transaction, resolve, reject } = that.pendingSignTransaction;
30310
+ try {
30311
+ const result = await that.signTransaction(transaction);
30312
+ resolve(result);
30313
+ }
30314
+ catch (error) {
30315
+ reject(error);
30316
+ }
30317
+ that.pendingSignTransaction = null;
30318
+ }
30319
+ // If there's a pending signMessage, execute it now
30320
+ if (that.pendingSignMessage) {
30321
+ const { message, resolve, reject } = that.pendingSignMessage;
30322
+ try {
30323
+ const result = await that.signMessage(message);
30324
+ resolve(result);
30325
+ }
30326
+ catch (error) {
30327
+ reject(error);
30328
+ }
30329
+ that.pendingSignMessage = null;
30330
+ }
30306
30331
  },
30307
30332
  onError: (error) => {
30308
30333
  // Only log errors that aren't user-initiated cancellations
@@ -30313,6 +30338,14 @@ class PrivyWalletProvider {
30313
30338
  that.pendingTransaction.reject(error);
30314
30339
  that.pendingTransaction = null;
30315
30340
  }
30341
+ if (that.pendingSignTransaction) {
30342
+ that.pendingSignTransaction.reject(error);
30343
+ that.pendingSignTransaction = null;
30344
+ }
30345
+ if (that.pendingSignMessage) {
30346
+ that.pendingSignMessage.reject(error);
30347
+ that.pendingSignMessage = null;
30348
+ }
30316
30349
  }
30317
30350
  });
30318
30351
  const { login } = privyImports.useLogin({
@@ -30618,19 +30651,47 @@ class PrivyWalletProvider {
30618
30651
  let session = await WebSessionManager.getSession();
30619
30652
  let sessionAddress = session === null || session === void 0 ? void 0 : session.address;
30620
30653
  let privyWallet = privyWallets === null || privyWallets === void 0 ? void 0 : privyWallets.find((wallet) => wallet.address === sessionAddress);
30621
- // If there's already a pending transaction, throw an error to prevent overlapping calls
30622
- if (this.pendingTransaction) {
30654
+ // If there's already a pending sign transaction, throw an error to prevent overlapping calls
30655
+ if (this.pendingSignTransaction) {
30623
30656
  throw new Error("Oops... something went wrong. Please try again.");
30624
30657
  }
30625
- if (!privyWallet) {
30626
- throw new Error("Wallet is not connected");
30658
+ // If wallet not connected, trigger connection and queue the signing
30659
+ if (!privyWallets || privyWallets.length === 0 || !privyWallet) {
30660
+ return new Promise((resolve, reject) => {
30661
+ this.pendingSignTransaction = {
30662
+ resolve,
30663
+ reject,
30664
+ transaction
30665
+ };
30666
+ this.privyMethods.connectWallet();
30667
+ // Set a timeout to reject the promise if connection takes too long
30668
+ setTimeout(() => {
30669
+ if (this.pendingSignTransaction) {
30670
+ this.pendingSignTransaction.reject(new Error("Wallet connection timed out"));
30671
+ this.pendingSignTransaction = null;
30672
+ }
30673
+ }, 30000); // 30 seconds timeout
30674
+ });
30627
30675
  }
30628
30676
  const serializedForSign = transaction.serialize({ requireAllSignatures: false, verifySignatures: false });
30629
- return await ((_b = this.privyMethods) === null || _b === void 0 ? void 0 : _b.signTransaction({
30677
+ const result = await ((_b = this.privyMethods) === null || _b === void 0 ? void 0 : _b.signTransaction({
30630
30678
  transaction: serializedForSign,
30631
30679
  wallet: privyWallet,
30632
30680
  chain: this.chainId
30633
30681
  }));
30682
+ // Privy returns { signedTransaction: Uint8Array }, unwrap and deserialize to match interface
30683
+ const signedBytes = (result === null || result === void 0 ? void 0 : result.signedTransaction) || result;
30684
+ if (signedBytes instanceof Uint8Array || Buffer.isBuffer(signedBytes)) {
30685
+ // Try to deserialize as VersionedTransaction first, fall back to legacy Transaction
30686
+ try {
30687
+ return web3_js.VersionedTransaction.deserialize(signedBytes);
30688
+ }
30689
+ catch (_c) {
30690
+ return web3_js.Transaction.from(signedBytes);
30691
+ }
30692
+ }
30693
+ // If already a Transaction object, return as-is
30694
+ return signedBytes;
30634
30695
  }
30635
30696
  catch (error) {
30636
30697
  throw new Error(`Failed to sign and send serialized transaction: ${error.message}`);
@@ -30641,8 +30702,27 @@ class PrivyWalletProvider {
30641
30702
  await this.ensureReady();
30642
30703
  const session = await WebSessionManager.getSession();
30643
30704
  let sessionAddress = session === null || session === void 0 ? void 0 : session.address;
30705
+ // If there's already a pending sign message, throw an error to prevent overlapping calls
30706
+ if (this.pendingSignMessage) {
30707
+ throw new Error("Oops... something went wrong. Please try again.");
30708
+ }
30709
+ // If no wallets connected, trigger wallet connection and queue the signing
30644
30710
  if (!((_a = this.privyMethods) === null || _a === void 0 ? void 0 : _a.wallets) || this.privyMethods.wallets.length === 0) {
30645
- throw new Error("User is not logged in ");
30711
+ return new Promise((resolve, reject) => {
30712
+ this.pendingSignMessage = {
30713
+ resolve,
30714
+ reject,
30715
+ message
30716
+ };
30717
+ this.privyMethods.connectWallet();
30718
+ // Set a timeout to reject the promise if connection takes too long
30719
+ setTimeout(() => {
30720
+ if (this.pendingSignMessage) {
30721
+ this.pendingSignMessage.reject(new Error("Wallet connection timed out"));
30722
+ this.pendingSignMessage = null;
30723
+ }
30724
+ }, 30000); // 30 seconds timeout
30725
+ });
30646
30726
  }
30647
30727
  let privyWallet = this.privyMethods.wallets.find((wallet) => wallet.address === sessionAddress);
30648
30728
  if (!privyWallet) {
@@ -31645,4 +31725,4 @@ exports.setMany = setMany;
31645
31725
  exports.signSessionCreateMessage = signSessionCreateMessage;
31646
31726
  exports.subscribe = subscribe;
31647
31727
  exports.useAuth = useAuth;
31648
- //# sourceMappingURL=index-7EM1gtmw.js.map
31728
+ //# sourceMappingURL=index-BwuRyd6v.js.map