diff --git a/packages/wallets/ghost/src/solana.ts b/packages/wallets/ghost/src/solana.ts index 6b0e4203..4bb4cd0c 100644 --- a/packages/wallets/ghost/src/solana.ts +++ b/packages/wallets/ghost/src/solana.ts @@ -1,6 +1,7 @@ // This is copied from @solana/wallet-standard-chains import type { IdentifierString } from '@wallet-standard/base'; +import type { Transaction, VersionedTransaction } from '@solana/web3.js'; /** Solana Mainnet (beta) cluster, e.g. https://api.mainnet-beta.solana.com */ export const SOLANA_MAINNET_CHAIN = 'solana:mainnet'; @@ -31,3 +32,9 @@ export type SolanaChain = (typeof SOLANA_CHAINS)[number]; export function isSolanaChain(chain: IdentifierString): chain is SolanaChain { return SOLANA_CHAINS.includes(chain as SolanaChain); } + +export function isVersionedTransaction( + transaction: Transaction | VersionedTransaction +): transaction is VersionedTransaction { + return 'version' in transaction; +} diff --git a/packages/wallets/ghost/src/wallet.ts b/packages/wallets/ghost/src/wallet.ts index ef5b06ed..e6099908 100644 --- a/packages/wallets/ghost/src/wallet.ts +++ b/packages/wallets/ghost/src/wallet.ts @@ -35,7 +35,7 @@ import bs58 from 'bs58'; import { GhostWalletAccount } from './account.js'; import { icon } from './icon.js'; import type { SolanaChain } from './solana.js'; -import { isSolanaChain, SOLANA_CHAINS } from './solana.js'; +import { isSolanaChain, isVersionedTransaction, SOLANA_CHAINS } from './solana.js'; import { bytesEqual } from './util.js'; import type { Ghost } from './window.js'; @@ -236,7 +236,16 @@ export class GhostWallet implements Wallet { const signedTransaction = await this.#ghost.signTransaction(VersionedTransaction.deserialize(transaction)); - outputs.push({ signedTransaction: signedTransaction.serialize() }); + const serializedTransaction = isVersionedTransaction(signedTransaction) + ? signedTransaction.serialize() + : new Uint8Array( + (signedTransaction as Transaction).serialize({ + requireAllSignatures: false, + verifySignatures: false, + }) + ); + + outputs.push({ signedTransaction: serializedTransaction }); } else if (inputs.length > 1) { let chain: SolanaChain | undefined = undefined; for (const input of inputs) { @@ -251,12 +260,23 @@ export class GhostWallet implements Wallet { } } - const transactions = inputs.map(({ transaction }) => Transaction.from(transaction)); + const transactions = inputs.map(({ transaction }) => VersionedTransaction.deserialize(transaction)); const signedTransactions = await this.#ghost.signAllTransactions(transactions); outputs.push( - ...signedTransactions.map((signedTransaction) => ({ signedTransaction: signedTransaction.serialize() })) + ...signedTransactions.map((signedTransaction) => { + const serializedTransaction = isVersionedTransaction(signedTransaction) + ? signedTransaction.serialize() + : new Uint8Array( + (signedTransaction as Transaction).serialize({ + requireAllSignatures: false, + verifySignatures: false, + }) + ); + + return { signedTransaction: serializedTransaction }; + }) ); }