@dynamic-labs/waas-svm 4.83.0 → 4.83.2-alpha.0

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/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.83.0";
6
+ var version = "4.83.2-alpha.0";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.83.0";
2
+ var version = "4.83.2-alpha.0";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/waas-svm",
3
- "version": "4.83.0",
3
+ "version": "4.83.2-alpha.0",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -18,19 +18,19 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
- "@dynamic-labs/sdk-api-core": "0.0.964",
22
- "@dynamic-labs/embedded-wallet-solana": "4.83.0",
21
+ "@dynamic-labs/sdk-api-core": "0.0.985",
22
+ "@dynamic-labs/embedded-wallet-solana": "4.83.2-alpha.0",
23
23
  "@solana/web3.js": "1.98.1",
24
24
  "eventemitter3": "5.0.1",
25
25
  "bs58": "5.0.0",
26
- "@dynamic-labs/assert-package-version": "4.83.0",
27
- "@dynamic-labs/logger": "4.83.0",
28
- "@dynamic-labs/rpc-providers": "4.83.0",
29
- "@dynamic-labs/solana-core": "4.83.0",
30
- "@dynamic-labs/types": "4.83.0",
31
- "@dynamic-labs/utils": "4.83.0",
32
- "@dynamic-labs/waas": "4.83.0",
33
- "@dynamic-labs/wallet-connector-core": "4.83.0"
26
+ "@dynamic-labs/assert-package-version": "4.83.2-alpha.0",
27
+ "@dynamic-labs/logger": "4.83.2-alpha.0",
28
+ "@dynamic-labs/rpc-providers": "4.83.2-alpha.0",
29
+ "@dynamic-labs/solana-core": "4.83.2-alpha.0",
30
+ "@dynamic-labs/types": "4.83.2-alpha.0",
31
+ "@dynamic-labs/utils": "4.83.2-alpha.0",
32
+ "@dynamic-labs/waas": "4.83.2-alpha.0",
33
+ "@dynamic-labs/wallet-connector-core": "4.83.2-alpha.0"
34
34
  },
35
35
  "peerDependencies": {}
36
36
  }
@@ -191,12 +191,21 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
191
191
  });
192
192
  }
193
193
  internalSignTransaction(transaction_1) {
194
- return _tslib.__awaiter(this, arguments, void 0, function* (transaction, { parentTraceId, startTime, } = {}) {
194
+ return _tslib.__awaiter(this, arguments, void 0, function* (transaction, { parentTraceId, startTime, overrideBlockhash, } = {}) {
195
195
  var _a, _b, _c;
196
196
  const traceId = parentTraceId || this.generateTraceId();
197
197
  const effectiveStartTime = startTime || Date.now();
198
198
  // Attempt to sponsor the transaction before signing
199
199
  const txToSign = yield this.maybeSponsorTransaction(transaction);
200
+ if (overrideBlockhash) {
201
+ if (solanaCore.isVersionedTransaction(txToSign)) {
202
+ txToSign.message.recentBlockhash = overrideBlockhash.blockhash;
203
+ }
204
+ else {
205
+ txToSign.recentBlockhash = overrideBlockhash.blockhash;
206
+ txToSign.lastValidBlockHeight = overrideBlockhash.lastValidBlockHeight;
207
+ }
208
+ }
200
209
  const walletClient = yield this.instrumentAsync({
201
210
  context: { chainName: 'SVM', startTime: effectiveStartTime, traceId },
202
211
  fn: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.getWaasWalletClient(); }),
@@ -343,16 +352,25 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
343
352
  }
344
353
  internalSignAndSendTransaction(transaction_1, options_1) {
345
354
  return _tslib.__awaiter(this, arguments, void 0, function* (transaction, options, { parentTraceId, startTime, } = {}) {
355
+ var _a;
346
356
  const traceId = parentTraceId || this.generateTraceId();
347
357
  const effectiveStartTime = startTime || Date.now();
348
358
  if (!this.activeAccountAddress) {
349
359
  throw new Error('Active account address is required');
350
360
  }
351
361
  const connection = this.getWalletClient();
362
+ // Refresh the blockhash right before signing so the tx is submitted with
363
+ // a fresh validity window AND so confirmTransaction's expiration check
364
+ // operates on the same blockhash that's embedded in the tx.
365
+ // Use 'finalized' so the blockhash is recognized by every RPC node
366
+ // (a 'confirmed' blockhash may not yet have propagated to the simulating
367
+ // node, which surfaces as "Blockhash not found" at sendRawTransaction).
368
+ const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash('finalized');
352
369
  const signedTransaction = yield this.instrumentAsync({
353
370
  context: { chainName: 'SVM', startTime: effectiveStartTime, traceId },
354
371
  fn: () => _tslib.__awaiter(this, void 0, void 0, function* () {
355
372
  return this.internalSignTransaction(transaction, {
373
+ overrideBlockhash: { blockhash, lastValidBlockHeight },
356
374
  parentTraceId: traceId,
357
375
  startTime: effectiveStartTime,
358
376
  });
@@ -380,49 +398,53 @@ class DynamicWaasSVMConnector extends waas.withDynamicWaas(solanaCore.SolanaWall
380
398
  operation: 'internalSignAndSendTransaction',
381
399
  resource: 'sendRawTransaction',
382
400
  });
383
- // Listen for transaction confirmation with timeout
384
401
  const confirmationStartTime = Date.now();
385
- return new Promise((resolve, reject) => {
386
- var _a;
387
- const timeout = setTimeout(() => {
388
- const timeoutTotalElapsed = Date.now() - confirmationStartTime;
389
- this.instrument(`[internalSignAndSendTransaction] Transaction timed out - total: ${timeoutTotalElapsed}ms`, {
390
- key: 'internalSignAndSendTransaction-transactionTimedOut',
402
+ try {
403
+ const confirmationResult = yield connection.confirmTransaction({
404
+ blockhash,
405
+ lastValidBlockHeight,
406
+ signature,
407
+ }, (_a = options === null || options === void 0 ? void 0 : options.preflightCommitment) !== null && _a !== void 0 ? _a : 'confirmed');
408
+ const confirmationEndTime = Date.now();
409
+ const confirmationStepElapsed = confirmationEndTime - confirmationStartTime;
410
+ const confirmationTotalElapsed = confirmationEndTime - effectiveStartTime;
411
+ if (confirmationResult.value.err) {
412
+ logger.logger.error(`[internalSignAndSendTransaction] Transaction failed - total: ${confirmationTotalElapsed}ms, step: ${confirmationStepElapsed}ms`, {
413
+ accountAddress: this.activeAccountAddress,
414
+ error: confirmationResult.value.err,
415
+ key: 'internalSignAndSendTransaction-transactionFailed',
391
416
  rpcUrl: connection.rpcEndpoint,
392
- time: timeoutTotalElapsed,
417
+ stepTime: confirmationStepElapsed,
418
+ time: confirmationTotalElapsed,
393
419
  traceId,
394
420
  });
395
- reject(new Error('Transaction timed out'));
396
- }, 60000);
397
- connection.onSignature(signature, (result) => {
398
- clearTimeout(timeout);
399
- const confirmationEndTime = Date.now();
400
- const confirmationStepElapsed = confirmationEndTime - confirmationStartTime;
401
- const confirmationTotalElapsed = confirmationEndTime - effectiveStartTime;
402
- if (result.err) {
403
- logger.logger.error(`[internalSignAndSendTransaction] Transaction failed - total: ${confirmationTotalElapsed}ms, step: ${confirmationStepElapsed}ms`, {
404
- accountAddress: this.activeAccountAddress,
405
- error: result.err,
406
- key: 'internalSignAndSendTransaction-transactionFailed',
407
- rpcUrl: connection.rpcEndpoint,
408
- stepTime: confirmationStepElapsed,
409
- time: confirmationTotalElapsed,
410
- traceId,
411
- });
412
- reject(new Error(`Transaction failed: ${result.err}`));
413
- }
414
- else {
415
- this.instrument(`[internalSignAndSendTransaction] Transaction confirmed - total: ${confirmationTotalElapsed}ms, step: ${confirmationStepElapsed}ms`, {
416
- key: 'internalSignAndSendTransaction-transactionSuccess',
417
- rpcUrl: connection.rpcEndpoint,
418
- stepTime: confirmationStepElapsed,
419
- time: confirmationTotalElapsed,
420
- traceId,
421
- });
422
- resolve(signature);
423
- }
424
- }, (_a = options === null || options === void 0 ? void 0 : options.preflightCommitment) !== null && _a !== void 0 ? _a : 'confirmed');
425
- });
421
+ throw new utils.TransactionFailedError(confirmationResult.value.err);
422
+ }
423
+ this.instrument(`[internalSignAndSendTransaction] Transaction confirmed - total: ${confirmationTotalElapsed}ms, step: ${confirmationStepElapsed}ms`, {
424
+ key: 'internalSignAndSendTransaction-transactionSuccess',
425
+ rpcUrl: connection.rpcEndpoint,
426
+ stepTime: confirmationStepElapsed,
427
+ time: confirmationTotalElapsed,
428
+ traceId,
429
+ });
430
+ }
431
+ catch (error) {
432
+ if (error instanceof utils.TransactionFailedError) {
433
+ throw error;
434
+ }
435
+ const timeoutTotalElapsed = Date.now() - confirmationStartTime;
436
+ logger.logger.error(`[internalSignAndSendTransaction] Confirmation timed out - total: ${timeoutTotalElapsed}ms`, {
437
+ accountAddress: this.activeAccountAddress,
438
+ error,
439
+ key: 'internalSignAndSendTransaction-confirmationTimedOut',
440
+ rpcUrl: connection.rpcEndpoint,
441
+ signature,
442
+ time: timeoutTotalElapsed,
443
+ traceId,
444
+ });
445
+ throw new utils.TransactionConfirmationTimeoutError(signature);
446
+ }
447
+ return signature;
426
448
  });
427
449
  }
428
450
  signAndSendTransaction(transaction, options) {
@@ -186,9 +186,13 @@ export declare class DynamicWaasSVMConnector extends DynamicWaasSVMConnector_bas
186
186
  startTime?: number;
187
187
  }): Promise<string>;
188
188
  signMessage(message: string): Promise<string>;
189
- internalSignTransaction<T extends Transaction | VersionedTransaction>(transaction: T, { parentTraceId, startTime, }?: {
189
+ internalSignTransaction<T extends Transaction | VersionedTransaction>(transaction: T, { parentTraceId, startTime, overrideBlockhash, }?: {
190
190
  parentTraceId?: string;
191
191
  startTime?: number;
192
+ overrideBlockhash?: {
193
+ blockhash: string;
194
+ lastValidBlockHeight: number;
195
+ };
192
196
  }): Promise<Transaction | VersionedTransaction>;
193
197
  signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<Transaction | VersionedTransaction>;
194
198
  internalSignAllTransactions<T extends Transaction | VersionedTransaction>(transactions: T[]): Promise<(Transaction | VersionedTransaction)[]>;
@@ -4,7 +4,7 @@ import { PublicKey } from '@solana/web3.js';
4
4
  import { sponsorSolanaTransaction } from '@dynamic-labs/embedded-wallet-solana';
5
5
  import { MFAAction, TokenScope } from '@dynamic-labs/sdk-api-core';
6
6
  import { SolanaWalletConnector, isVersionedTransaction, SolanaUiTransaction } from '@dynamic-labs/solana-core';
7
- import { DynamicError } from '@dynamic-labs/utils';
7
+ import { DynamicError, TransactionFailedError, TransactionConfirmationTimeoutError } from '@dynamic-labs/utils';
8
8
  import { withDynamicWaas } from '@dynamic-labs/waas';
9
9
  import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
10
10
  import { logger } from '../../utils/logger.js';
@@ -187,12 +187,21 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
187
187
  });
188
188
  }
189
189
  internalSignTransaction(transaction_1) {
190
- return __awaiter(this, arguments, void 0, function* (transaction, { parentTraceId, startTime, } = {}) {
190
+ return __awaiter(this, arguments, void 0, function* (transaction, { parentTraceId, startTime, overrideBlockhash, } = {}) {
191
191
  var _a, _b, _c;
192
192
  const traceId = parentTraceId || this.generateTraceId();
193
193
  const effectiveStartTime = startTime || Date.now();
194
194
  // Attempt to sponsor the transaction before signing
195
195
  const txToSign = yield this.maybeSponsorTransaction(transaction);
196
+ if (overrideBlockhash) {
197
+ if (isVersionedTransaction(txToSign)) {
198
+ txToSign.message.recentBlockhash = overrideBlockhash.blockhash;
199
+ }
200
+ else {
201
+ txToSign.recentBlockhash = overrideBlockhash.blockhash;
202
+ txToSign.lastValidBlockHeight = overrideBlockhash.lastValidBlockHeight;
203
+ }
204
+ }
196
205
  const walletClient = yield this.instrumentAsync({
197
206
  context: { chainName: 'SVM', startTime: effectiveStartTime, traceId },
198
207
  fn: () => __awaiter(this, void 0, void 0, function* () { return this.getWaasWalletClient(); }),
@@ -339,16 +348,25 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
339
348
  }
340
349
  internalSignAndSendTransaction(transaction_1, options_1) {
341
350
  return __awaiter(this, arguments, void 0, function* (transaction, options, { parentTraceId, startTime, } = {}) {
351
+ var _a;
342
352
  const traceId = parentTraceId || this.generateTraceId();
343
353
  const effectiveStartTime = startTime || Date.now();
344
354
  if (!this.activeAccountAddress) {
345
355
  throw new Error('Active account address is required');
346
356
  }
347
357
  const connection = this.getWalletClient();
358
+ // Refresh the blockhash right before signing so the tx is submitted with
359
+ // a fresh validity window AND so confirmTransaction's expiration check
360
+ // operates on the same blockhash that's embedded in the tx.
361
+ // Use 'finalized' so the blockhash is recognized by every RPC node
362
+ // (a 'confirmed' blockhash may not yet have propagated to the simulating
363
+ // node, which surfaces as "Blockhash not found" at sendRawTransaction).
364
+ const { blockhash, lastValidBlockHeight } = yield connection.getLatestBlockhash('finalized');
348
365
  const signedTransaction = yield this.instrumentAsync({
349
366
  context: { chainName: 'SVM', startTime: effectiveStartTime, traceId },
350
367
  fn: () => __awaiter(this, void 0, void 0, function* () {
351
368
  return this.internalSignTransaction(transaction, {
369
+ overrideBlockhash: { blockhash, lastValidBlockHeight },
352
370
  parentTraceId: traceId,
353
371
  startTime: effectiveStartTime,
354
372
  });
@@ -376,49 +394,53 @@ class DynamicWaasSVMConnector extends withDynamicWaas(SolanaWalletConnector) {
376
394
  operation: 'internalSignAndSendTransaction',
377
395
  resource: 'sendRawTransaction',
378
396
  });
379
- // Listen for transaction confirmation with timeout
380
397
  const confirmationStartTime = Date.now();
381
- return new Promise((resolve, reject) => {
382
- var _a;
383
- const timeout = setTimeout(() => {
384
- const timeoutTotalElapsed = Date.now() - confirmationStartTime;
385
- this.instrument(`[internalSignAndSendTransaction] Transaction timed out - total: ${timeoutTotalElapsed}ms`, {
386
- key: 'internalSignAndSendTransaction-transactionTimedOut',
398
+ try {
399
+ const confirmationResult = yield connection.confirmTransaction({
400
+ blockhash,
401
+ lastValidBlockHeight,
402
+ signature,
403
+ }, (_a = options === null || options === void 0 ? void 0 : options.preflightCommitment) !== null && _a !== void 0 ? _a : 'confirmed');
404
+ const confirmationEndTime = Date.now();
405
+ const confirmationStepElapsed = confirmationEndTime - confirmationStartTime;
406
+ const confirmationTotalElapsed = confirmationEndTime - effectiveStartTime;
407
+ if (confirmationResult.value.err) {
408
+ logger.error(`[internalSignAndSendTransaction] Transaction failed - total: ${confirmationTotalElapsed}ms, step: ${confirmationStepElapsed}ms`, {
409
+ accountAddress: this.activeAccountAddress,
410
+ error: confirmationResult.value.err,
411
+ key: 'internalSignAndSendTransaction-transactionFailed',
387
412
  rpcUrl: connection.rpcEndpoint,
388
- time: timeoutTotalElapsed,
413
+ stepTime: confirmationStepElapsed,
414
+ time: confirmationTotalElapsed,
389
415
  traceId,
390
416
  });
391
- reject(new Error('Transaction timed out'));
392
- }, 60000);
393
- connection.onSignature(signature, (result) => {
394
- clearTimeout(timeout);
395
- const confirmationEndTime = Date.now();
396
- const confirmationStepElapsed = confirmationEndTime - confirmationStartTime;
397
- const confirmationTotalElapsed = confirmationEndTime - effectiveStartTime;
398
- if (result.err) {
399
- logger.error(`[internalSignAndSendTransaction] Transaction failed - total: ${confirmationTotalElapsed}ms, step: ${confirmationStepElapsed}ms`, {
400
- accountAddress: this.activeAccountAddress,
401
- error: result.err,
402
- key: 'internalSignAndSendTransaction-transactionFailed',
403
- rpcUrl: connection.rpcEndpoint,
404
- stepTime: confirmationStepElapsed,
405
- time: confirmationTotalElapsed,
406
- traceId,
407
- });
408
- reject(new Error(`Transaction failed: ${result.err}`));
409
- }
410
- else {
411
- this.instrument(`[internalSignAndSendTransaction] Transaction confirmed - total: ${confirmationTotalElapsed}ms, step: ${confirmationStepElapsed}ms`, {
412
- key: 'internalSignAndSendTransaction-transactionSuccess',
413
- rpcUrl: connection.rpcEndpoint,
414
- stepTime: confirmationStepElapsed,
415
- time: confirmationTotalElapsed,
416
- traceId,
417
- });
418
- resolve(signature);
419
- }
420
- }, (_a = options === null || options === void 0 ? void 0 : options.preflightCommitment) !== null && _a !== void 0 ? _a : 'confirmed');
421
- });
417
+ throw new TransactionFailedError(confirmationResult.value.err);
418
+ }
419
+ this.instrument(`[internalSignAndSendTransaction] Transaction confirmed - total: ${confirmationTotalElapsed}ms, step: ${confirmationStepElapsed}ms`, {
420
+ key: 'internalSignAndSendTransaction-transactionSuccess',
421
+ rpcUrl: connection.rpcEndpoint,
422
+ stepTime: confirmationStepElapsed,
423
+ time: confirmationTotalElapsed,
424
+ traceId,
425
+ });
426
+ }
427
+ catch (error) {
428
+ if (error instanceof TransactionFailedError) {
429
+ throw error;
430
+ }
431
+ const timeoutTotalElapsed = Date.now() - confirmationStartTime;
432
+ logger.error(`[internalSignAndSendTransaction] Confirmation timed out - total: ${timeoutTotalElapsed}ms`, {
433
+ accountAddress: this.activeAccountAddress,
434
+ error,
435
+ key: 'internalSignAndSendTransaction-confirmationTimedOut',
436
+ rpcUrl: connection.rpcEndpoint,
437
+ signature,
438
+ time: timeoutTotalElapsed,
439
+ traceId,
440
+ });
441
+ throw new TransactionConfirmationTimeoutError(signature);
442
+ }
443
+ return signature;
422
444
  });
423
445
  }
424
446
  signAndSendTransaction(transaction, options) {