Skip to content

Commit

Permalink
feat: parse base64 and base58 requests and add signature to response
Browse files Browse the repository at this point in the history
  • Loading branch information
zoruka committed Aug 28, 2024
1 parent d4c6185 commit e9552ac
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions advanced/wallets/react-wallet-v2/src/lib/SolanaLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export default class SolanaLib {
const transaction = this.deserialize(params.transaction)
this.sign(transaction)

return { transaction: this.serialize(transaction) }
return {
transaction: this.serialize(transaction),
signature: bs58.encode(transaction.signatures[0])
}
}

public async signAndSendTransaction(
Expand Down Expand Up @@ -80,7 +83,14 @@ export default class SolanaLib {
}

private deserialize(transaction: string): VersionedTransaction {
return VersionedTransaction.deserialize(bs58.decode(transaction))
let bytes: Uint8Array
try {
bytes = bs58.decode(transaction)
} catch {
bytes = Buffer.from(transaction, 'base64')
}

return VersionedTransaction.deserialize(bytes)
}

private sign(transaction: VersionedTransaction) {
Expand All @@ -96,7 +106,10 @@ export namespace SolanaLib {

export type SignMessage = RPCRequest<{ message: string }, { signature: string }>

export type SignTransaction = RPCRequest<{ transaction: string }, { transaction: string }>
export type SignTransaction = RPCRequest<
{ transaction: string },
{ transaction: string; signature: string }
>

export type SignAndSendTransaction = RPCRequest<
{ transaction: string; options?: SendOptions },
Expand Down

0 comments on commit e9552ac

Please sign in to comment.