diff --git a/package-lock.json b/package-lock.json index 5453e3374..90d0f4d42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6708,11 +6708,11 @@ } }, "node_modules/@toruslabs/solana-embed": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/@toruslabs/solana-embed/-/solana-embed-0.3.2.tgz", - "integrity": "sha512-yY0sTAi++lOM/kJ6tpR3/mRXqqpqrHNnm1PL/1Zkj1Tpnt+SmlPPp9ivveLXK+1vRLtha2UpjRk1KdsG+QJGyg==", + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@toruslabs/solana-embed/-/solana-embed-0.3.3.tgz", + "integrity": "sha512-Edw0p1oNNG+fk+3XIZZiIiwdi75lgtOpCjIK7G7PbR3ygJPVgM7e6L0MCOVNkX0LSJTc5HJFi9E0MiAf4cG7UQ==", "dependencies": { - "@solana/web3.js": "^1.36.0", + "@solana/web3.js": "^1.63.1", "@toruslabs/base-controllers": "^2.2.6", "@toruslabs/http-helpers": "^3.2.0", "@toruslabs/openlogin-jrpc": "^2.6.0", @@ -28788,7 +28788,7 @@ "version": "4.4.0", "license": "ISC", "dependencies": { - "@toruslabs/solana-embed": "^0.3.2", + "@toruslabs/solana-embed": "^0.3.3", "@web3auth/base": "^4.4.0", "@web3auth/base-provider": "^4.4.0", "@web3auth/base-solana-adapter": "^4.4.0", @@ -33896,11 +33896,11 @@ } }, "@toruslabs/solana-embed": { - "version": "0.3.2", - "resolved": "https://registry.npmjs.org/@toruslabs/solana-embed/-/solana-embed-0.3.2.tgz", - "integrity": "sha512-yY0sTAi++lOM/kJ6tpR3/mRXqqpqrHNnm1PL/1Zkj1Tpnt+SmlPPp9ivveLXK+1vRLtha2UpjRk1KdsG+QJGyg==", + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@toruslabs/solana-embed/-/solana-embed-0.3.3.tgz", + "integrity": "sha512-Edw0p1oNNG+fk+3XIZZiIiwdi75lgtOpCjIK7G7PbR3ygJPVgM7e6L0MCOVNkX0LSJTc5HJFi9E0MiAf4cG7UQ==", "requires": { - "@solana/web3.js": "^1.36.0", + "@solana/web3.js": "^1.63.1", "@toruslabs/base-controllers": "^2.2.6", "@toruslabs/http-helpers": "^3.2.0", "@toruslabs/openlogin-jrpc": "^2.6.0", @@ -35037,7 +35037,7 @@ "@web3auth/torus-solana-adapter": { "version": "file:packages/adapters/torus-solana-adapter", "requires": { - "@toruslabs/solana-embed": "^0.3.2", + "@toruslabs/solana-embed": "^0.3.3", "@web3auth/base": "^4.4.0", "@web3auth/base-provider": "^4.4.0", "@web3auth/base-solana-adapter": "^4.4.0", diff --git a/packages/adapters/torus-solana-adapter/package.json b/packages/adapters/torus-solana-adapter/package.json index f1d26608a..369b9cf16 100644 --- a/packages/adapters/torus-solana-adapter/package.json +++ b/packages/adapters/torus-solana-adapter/package.json @@ -35,7 +35,7 @@ "@babel/runtime": "^7.x" }, "dependencies": { - "@toruslabs/solana-embed": "^0.3.2", + "@toruslabs/solana-embed": "^0.3.3", "@web3auth/base": "^4.4.0", "@web3auth/base-provider": "^4.4.0", "@web3auth/base-solana-adapter": "^4.4.0", diff --git a/packages/providers/solana-provider/src/interface.ts b/packages/providers/solana-provider/src/interface.ts index ddb27be68..285b7dbba 100644 --- a/packages/providers/solana-provider/src/interface.ts +++ b/packages/providers/solana-provider/src/interface.ts @@ -1,4 +1,4 @@ -import type { Transaction } from "@solana/web3.js"; +import type { Transaction, VersionedTransaction } from "@solana/web3.js"; import type Solflare from "@solflare-wallet/sdk"; import type { SafeEventEmitter } from "@toruslabs/openlogin-jrpc"; import { RequestArguments } from "@web3auth/base"; @@ -6,11 +6,13 @@ import BN from "bn.js"; import { InjectedProvider } from "./providers"; +export type TransactionOrVersionedTransaction = Transaction | VersionedTransaction; + export interface ISolanaWallet { publicKey?: { toBytes(): Uint8Array }; - signAndSendTransaction(transaction: Transaction): Promise<{ signature: string }>; - signTransaction?(transaction: Transaction): Promise; - signAllTransactions?(transactions: Transaction[]): Promise; + signAndSendTransaction(transaction: T): Promise<{ signature: string }>; + signTransaction?(transaction: T): Promise; + signAllTransactions?(transactions: T[]): Promise; signMessage(message: Uint8Array, display?: string): Promise; request(args: RequestArguments): Promise; } @@ -18,9 +20,9 @@ export interface ISolanaWallet { export interface IPhantomWalletProvider extends SafeEventEmitter { isConnected: boolean; publicKey?: { toBytes(): Uint8Array }; - signAndSendTransaction(transaction: Transaction): Promise<{ signature: string }>; - signTransaction?(transaction: Transaction): Promise; - signAllTransactions?(transactions: Transaction[]): Promise; + signAndSendTransaction(transaction: T): Promise<{ signature: string }>; + signTransaction?(transaction: T): Promise; + signAllTransactions?(transactions: T[]): Promise; signMessage(message: Uint8Array): Promise<{ signature: Uint8Array; publicKey: BN }>; request(args: RequestArguments): Promise; _handleDisconnect(...args: unknown[]): void; @@ -31,9 +33,9 @@ export interface IPhantomWalletProvider extends SafeEventEmitter { export interface IBaseWalletProvider { publicKey?: { toBytes(): Uint8Array }; signMessage?(message: Uint8Array, display?: "hex" | "utf8"): Promise<{ signature: Uint8Array; publicKey: BN }>; - signTransaction?(transaction: Transaction): Promise; - signAllTransactions?(transactions: Transaction[]): Promise; - signAndSendTransaction?(transaction: Transaction): Promise<{ signature: string }>; + signTransaction?(transaction: T): Promise; + signAllTransactions?(transactions: T[]): Promise; + signAndSendTransaction?(transaction: T): Promise<{ signature: string }>; } // NOTE: solflare types fo sign message is broken. @@ -67,8 +69,8 @@ export interface ISlopeProvider extends SafeEventEmitter { } export interface ITorusWalletProvider extends InjectedProvider { - sendTransaction(transaction: Transaction): Promise; - signTransaction(transaction: Transaction): Promise; - signAllTransactions(transactions: Transaction[]): Promise; + sendTransaction(transaction: T): Promise; + signTransaction(transaction: T): Promise; + signAllTransactions(transactions: T[]): Promise; signMessage(data: Uint8Array): Promise; } diff --git a/packages/providers/solana-provider/src/providers/injectedProviders/base/providerHandlers.ts b/packages/providers/solana-provider/src/providers/injectedProviders/base/providerHandlers.ts index b461a7840..61f739fac 100644 --- a/packages/providers/solana-provider/src/providers/injectedProviders/base/providerHandlers.ts +++ b/packages/providers/solana-provider/src/providers/injectedProviders/base/providerHandlers.ts @@ -1,9 +1,8 @@ -import { Transaction } from "@solana/web3.js"; import { JRPCRequest } from "@toruslabs/openlogin-jrpc"; import bs58 from "bs58"; import { ethErrors } from "eth-rpc-errors"; -import { IBaseWalletProvider } from "../../../interface"; +import { IBaseWalletProvider, TransactionOrVersionedTransaction } from "../../../interface"; import { IProviderHandlers } from "../../../rpc/solanaRpcMiddlewares"; export const getBaseProviderHandlers = (injectedProvider: IBaseWalletProvider): IProviderHandlers => { @@ -18,7 +17,7 @@ export const getBaseProviderHandlers = (injectedProvider: IBaseWalletProvider): getSecretKey: async () => { throw ethErrors.rpc.methodNotSupported(); }, - signTransaction: async (req: JRPCRequest<{ message: Transaction }>): Promise => { + signTransaction: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction }>): Promise => { const transaction = await injectedProvider.signTransaction(req.params.message); return transaction; }, @@ -26,14 +25,14 @@ export const getBaseProviderHandlers = (injectedProvider: IBaseWalletProvider): const sigData = await injectedProvider.signMessage(req.params.message, req.params.display); return sigData.signature; }, - signAllTransactions: async (req: JRPCRequest<{ message: Transaction[] }>): Promise => { + signAllTransactions: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction[] }>): Promise => { if (!req.params?.message || !req.params?.message.length) { throw ethErrors.rpc.invalidParams("message"); } const transaction = await injectedProvider.signAllTransactions(req.params.message); return transaction; }, - signAndSendTransaction: async (req: JRPCRequest<{ message: Transaction }>): Promise<{ signature: string }> => { + signAndSendTransaction: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction }>): Promise<{ signature: string }> => { const txRes = await injectedProvider.signAndSendTransaction(req.params.message); return { signature: txRes.signature }; }, diff --git a/packages/providers/solana-provider/src/providers/injectedProviders/slope/providerHandlers.ts b/packages/providers/solana-provider/src/providers/injectedProviders/slope/providerHandlers.ts index e53bb8202..6544acc24 100644 --- a/packages/providers/solana-provider/src/providers/injectedProviders/slope/providerHandlers.ts +++ b/packages/providers/solana-provider/src/providers/injectedProviders/slope/providerHandlers.ts @@ -1,12 +1,15 @@ -import { Connection, PublicKey, Transaction } from "@solana/web3.js"; +import { Connection, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js"; import { JRPCRequest } from "@toruslabs/openlogin-jrpc"; import { CustomChainConfig, SafeEventEmitterProvider } from "@web3auth/base"; import bs58 from "bs58"; import { ethErrors } from "eth-rpc-errors"; -import { ISlopeProvider } from "../../../interface"; +import { ISlopeProvider, TransactionOrVersionedTransaction } from "../../../interface"; import { IProviderHandlers } from "../../../rpc/solanaRpcMiddlewares"; +const isVersionTransction = (transaction: TransactionOrVersionedTransaction) => + (transaction as VersionedTransaction).version !== undefined || transaction instanceof VersionedTransaction; + export const getSlopeHandlers = (injectedProvider: ISlopeProvider, getProviderEngineProxy: () => SafeEventEmitterProvider): IProviderHandlers => { const providerHandlers: IProviderHandlers = { requestAccounts: async () => { @@ -23,11 +26,16 @@ export const getSlopeHandlers = (injectedProvider: ISlopeProvider, getProviderEn getSecretKey: async () => { throw ethErrors.rpc.methodNotSupported(); }, - signTransaction: async (req: JRPCRequest<{ message: Transaction }>): Promise => { + signTransaction: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction }>): Promise => { const txMessage = req.params.message; if (!txMessage) throw ethErrors.rpc.invalidRequest({ message: "Invalid transaction message" }); - const { data } = await injectedProvider.signTransaction(bs58.encode(txMessage.serializeMessage())); + + const message = isVersionTransction(txMessage) + ? (txMessage as VersionedTransaction).message.serialize() + : (txMessage as Transaction).serializeMessage(); + const { data } = await injectedProvider.signTransaction(bs58.encode(message)); if (!data.publicKey || !data.signature) throw new Error("Invalid signature from slope wallet"); + const publicKey = new PublicKey(data.publicKey); const signature = bs58.decode(data.signature); txMessage.addSignature(publicKey, Buffer.from(signature)); @@ -37,12 +45,16 @@ export const getSlopeHandlers = (injectedProvider: ISlopeProvider, getProviderEn const response = await injectedProvider.signMessage(req.params.message); return bs58.decode(response.data.signature); }, - signAndSendTransaction: async (req: JRPCRequest<{ message: Transaction }>): Promise<{ signature: string }> => { + signAndSendTransaction: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction }>): Promise<{ signature: string }> => { const provider = getProviderEngineProxy(); if (!provider) throw ethErrors.provider.custom({ message: "Provider is not initialized", code: 4902 }); const txMessage = req.params.message; if (!txMessage) throw ethErrors.rpc.invalidRequest({ message: "Invalid transaction message" }); - const { data } = await injectedProvider.signTransaction(bs58.encode(txMessage.serializeMessage())); + + const message = isVersionTransction(txMessage) + ? (txMessage as VersionedTransaction).message.serialize() + : (txMessage as Transaction).serializeMessage(); + const { data } = await injectedProvider.signTransaction(bs58.encode(message)); if (!data.publicKey || !data.signature) throw new Error("Invalid signature from slope wallet"); const publicKey = new PublicKey(data.publicKey); const signature = bs58.decode(data.signature); @@ -52,7 +64,7 @@ export const getSlopeHandlers = (injectedProvider: ISlopeProvider, getProviderEn const res = await conn.sendRawTransaction(txMessage.serialize()); return { signature: res }; }, - signAllTransactions: async (req: JRPCRequest<{ message: Transaction[] }>): Promise => { + signAllTransactions: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction[] }>): Promise => { if (!req.params?.message || !req.params?.message.length) { throw ethErrors.rpc.invalidParams("message"); } @@ -63,7 +75,9 @@ export const getSlopeHandlers = (injectedProvider: ISlopeProvider, getProviderEn const unsignedTx = []; for (let i = 0; i < length; i++) { - unsignedTx.push(bs58.encode(req.params.message[i].serializeMessage())); + const item = allTxns[i]; + const message = isVersionTransction(item) ? (item as VersionedTransaction).message.serialize() : (item as Transaction).serializeMessage(); + unsignedTx.push(bs58.encode(message)); } const { msg, data } = await injectedProvider.signAllTransactions(unsignedTx); diff --git a/packages/providers/solana-provider/src/providers/injectedProviders/solflare/providerHandlers.ts b/packages/providers/solana-provider/src/providers/injectedProviders/solflare/providerHandlers.ts index 8764163d2..d5d5cd8dd 100644 --- a/packages/providers/solana-provider/src/providers/injectedProviders/solflare/providerHandlers.ts +++ b/packages/providers/solana-provider/src/providers/injectedProviders/solflare/providerHandlers.ts @@ -1,17 +1,20 @@ -import { Connection, Transaction } from "@solana/web3.js"; +import { Connection } from "@solana/web3.js"; import { JRPCRequest } from "@toruslabs/openlogin-jrpc"; import { CustomChainConfig, SafeEventEmitterProvider } from "@web3auth/base"; import { ethErrors } from "eth-rpc-errors"; -import { IBaseWalletProvider, SolflareWallet } from "../../../interface"; +import { IBaseWalletProvider, SolflareWallet, TransactionOrVersionedTransaction } from "../../../interface"; import { IProviderHandlers } from "../../../rpc/solanaRpcMiddlewares"; import { getBaseProviderHandlers } from "../base/providerHandlers"; export const getSolflareHandlers = (injectedProvider: SolflareWallet, getProviderEngineProxy: () => SafeEventEmitterProvider): IProviderHandlers => { const solflareProviderHandlers = getBaseProviderHandlers(injectedProvider as IBaseWalletProvider); - solflareProviderHandlers.signAndSendTransaction = async (req: JRPCRequest<{ message: Transaction }>): Promise<{ signature: string }> => { + solflareProviderHandlers.signAndSendTransaction = async ( + req: JRPCRequest<{ message: TransactionOrVersionedTransaction }> + ): Promise<{ signature: string }> => { const provider = getProviderEngineProxy(); if (!provider) throw ethErrors.provider.custom({ message: "Provider is not initialized", code: 4902 }); + const transaction = await injectedProvider.signTransaction(req.params.message); const chainConfig = (await provider.request({ method: "solana_provider_config", params: [] })) as CustomChainConfig; const conn = new Connection(chainConfig.rpcTarget); diff --git a/packages/providers/solana-provider/src/providers/injectedProviders/torus/providerHandlers.ts b/packages/providers/solana-provider/src/providers/injectedProviders/torus/providerHandlers.ts index 8318aebe6..de1c53e9c 100644 --- a/packages/providers/solana-provider/src/providers/injectedProviders/torus/providerHandlers.ts +++ b/packages/providers/solana-provider/src/providers/injectedProviders/torus/providerHandlers.ts @@ -1,8 +1,7 @@ -import { Transaction } from "@solana/web3.js"; import { JRPCRequest } from "@toruslabs/openlogin-jrpc"; import { ethErrors } from "eth-rpc-errors"; -import { ITorusWalletProvider } from "../../../interface"; +import { ITorusWalletProvider, TransactionOrVersionedTransaction } from "../../../interface"; import { IProviderHandlers } from "../../../rpc/solanaRpcMiddlewares"; export const getTorusHandlers = (injectedProvider: ITorusWalletProvider): IProviderHandlers => { @@ -37,7 +36,7 @@ export const getTorusHandlers = (injectedProvider: ITorusWalletProvider): IProvi return message; }, - signTransaction: async (req: JRPCRequest<{ message: Transaction }>): Promise => { + signTransaction: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction }>): Promise => { if (!req.params?.message) { throw ethErrors.rpc.invalidParams("message"); } @@ -46,7 +45,7 @@ export const getTorusHandlers = (injectedProvider: ITorusWalletProvider): IProvi return response; }, - signAndSendTransaction: async (req: JRPCRequest<{ message: Transaction }>): Promise<{ signature: string }> => { + signAndSendTransaction: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction }>): Promise<{ signature: string }> => { if (!req.params?.message) { throw ethErrors.rpc.invalidParams("message"); } @@ -55,7 +54,7 @@ export const getTorusHandlers = (injectedProvider: ITorusWalletProvider): IProvi return { signature: response }; }, - signAllTransactions: async (req: JRPCRequest<{ message: Transaction[] }>): Promise => { + signAllTransactions: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction[] }>): Promise => { if (!req.params?.message || !req.params?.message.length) { throw ethErrors.rpc.invalidParams("message"); } diff --git a/packages/providers/solana-provider/src/providers/privateKeyProvider/solanaPrivateKeyUtils.ts b/packages/providers/solana-provider/src/providers/privateKeyProvider/solanaPrivateKeyUtils.ts index 4037f437e..680361c3a 100644 --- a/packages/providers/solana-provider/src/providers/privateKeyProvider/solanaPrivateKeyUtils.ts +++ b/packages/providers/solana-provider/src/providers/privateKeyProvider/solanaPrivateKeyUtils.ts @@ -1,10 +1,11 @@ -import { Keypair, Transaction } from "@solana/web3.js"; +import { Keypair, VersionedTransaction } from "@solana/web3.js"; import { JRPCRequest } from "@toruslabs/openlogin-jrpc"; import nacl from "@toruslabs/tweetnacl-js"; import { SafeEventEmitterProvider, WalletInitializationError } from "@web3auth/base"; import bs58 from "bs58"; import { ethErrors } from "eth-rpc-errors"; +import { TransactionOrVersionedTransaction } from "../../interface"; import { IProviderHandlers } from "../../rpc/solanaRpcMiddlewares"; export async function getProviderHandlers({ @@ -28,12 +29,16 @@ export async function getProviderHandlers({ getPrivateKey: async () => privKey, getSecretKey: async () => bs58.encode(keyPair.secretKey), - signTransaction: async (req: JRPCRequest<{ message: Transaction }>): Promise => { + signTransaction: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction }>): Promise => { if (!req.params?.message) { throw ethErrors.rpc.invalidParams("message"); } const transaction = req.params.message; - transaction.partialSign(keyPair); + if ((transaction as VersionedTransaction).version !== undefined || transaction instanceof VersionedTransaction) { + (transaction as VersionedTransaction).sign([keyPair]); + } else { + transaction.partialSign(keyPair); + } return transaction; }, @@ -45,7 +50,7 @@ export async function getProviderHandlers({ return signedMsg; }, - signAndSendTransaction: async (req: JRPCRequest<{ message: Transaction }>): Promise<{ signature: string }> => { + signAndSendTransaction: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction }>): Promise<{ signature: string }> => { if (!req.params?.message) { throw ethErrors.rpc.invalidParams("message"); } @@ -53,16 +58,19 @@ export async function getProviderHandlers({ if (!_providerEngineProxy) throw ethErrors.provider.custom({ message: "Provider is not initialized", code: 4902 }); const transaction = req.params.message; - transaction.sign(keyPair); - + if ((transaction as VersionedTransaction).version !== undefined || transaction instanceof VersionedTransaction) { + (transaction as VersionedTransaction).sign([keyPair]); + } else { + transaction.partialSign(keyPair); + } const sig = await _providerEngineProxy.request({ method: "sendTransaction", - params: [bs58.encode(transaction.serialize())], + params: [Buffer.from(transaction.serialize()).toString("base64"), { encoding: "base64" }], }); return { signature: sig }; }, - signAllTransactions: async (req: JRPCRequest<{ message: Transaction[] }>): Promise => { + signAllTransactions: async (req: JRPCRequest<{ message: TransactionOrVersionedTransaction[] }>): Promise => { if (!req.params?.message || !req.params?.message.length) { throw ethErrors.rpc.invalidParams("message"); } @@ -70,7 +78,11 @@ export async function getProviderHandlers({ const txns = req.params?.message; for (const tx of txns || []) { const transaction = tx; - transaction.partialSign(keyPair); + if ((transaction as VersionedTransaction).version !== undefined || transaction instanceof VersionedTransaction) { + (transaction as VersionedTransaction).sign([keyPair]); + } else { + transaction.partialSign(keyPair); + } } return txns; }, diff --git a/packages/providers/solana-provider/src/rpc/solanaRpcMiddlewares.ts b/packages/providers/solana-provider/src/rpc/solanaRpcMiddlewares.ts index f9c998155..f3d27dbcc 100644 --- a/packages/providers/solana-provider/src/rpc/solanaRpcMiddlewares.ts +++ b/packages/providers/solana-provider/src/rpc/solanaRpcMiddlewares.ts @@ -1,13 +1,14 @@ -import type { Transaction } from "@solana/web3.js"; import { createAsyncMiddleware, JRPCMiddleware, JRPCRequest, mergeMiddleware } from "@toruslabs/openlogin-jrpc"; +import { TransactionOrVersionedTransaction } from "../interface"; + export interface IProviderHandlers { requestAccounts: (req: JRPCRequest) => Promise; getAccounts: (req: JRPCRequest) => Promise; getPrivateKey: (req: JRPCRequest) => Promise; - signTransaction: (req: JRPCRequest<{ message: Transaction }>) => Promise; - signAllTransactions: (req: JRPCRequest<{ message: Transaction[] }>) => Promise; - signAndSendTransaction: (req: JRPCRequest<{ message: Transaction }>) => Promise<{ signature: string }>; + signTransaction: (req: JRPCRequest<{ message: TransactionOrVersionedTransaction }>) => Promise; + signAllTransactions: (req: JRPCRequest<{ message: TransactionOrVersionedTransaction[] }>) => Promise; + signAndSendTransaction: (req: JRPCRequest<{ message: TransactionOrVersionedTransaction }>) => Promise<{ signature: string }>; getSecretKey: (req: JRPCRequest) => Promise; signMessage: (req: JRPCRequest<{ message: Uint8Array; display?: string }>) => Promise; } @@ -66,9 +67,18 @@ export function createSolanaMiddleware(providerHandlers: IProviderHandlers): JRP return mergeMiddleware([ createRequestAccountsMiddleware({ requestAccounts }), createGetAccountsMiddleware({ getAccounts }), - createGenericJRPCMiddleware<{ message: Transaction }, Transaction>("signTransaction", signTransaction), - createGenericJRPCMiddleware<{ message: Transaction }, { signature: string }>("signAndSendTransaction", signAndSendTransaction), - createGenericJRPCMiddleware<{ message: Transaction[] }, Transaction[]>("signAllTransactions", signAllTransactions), + createGenericJRPCMiddleware<{ message: TransactionOrVersionedTransaction }, TransactionOrVersionedTransaction>( + "signTransaction", + signTransaction + ), + createGenericJRPCMiddleware<{ message: TransactionOrVersionedTransaction }, { signature: string }>( + "signAndSendTransaction", + signAndSendTransaction + ), + createGenericJRPCMiddleware<{ message: TransactionOrVersionedTransaction[] }, TransactionOrVersionedTransaction[]>( + "signAllTransactions", + signAllTransactions + ), createGenericJRPCMiddleware<{ message: Uint8Array }, Uint8Array>("signMessage", signMessage), createGenericJRPCMiddleware("solanaPrivateKey", getPrivateKey), createGenericJRPCMiddleware("private_key", getPrivateKey), diff --git a/packages/providers/solana-provider/src/solanaWallet.ts b/packages/providers/solana-provider/src/solanaWallet.ts index 5fbb2eac3..1ddb7f6c5 100644 --- a/packages/providers/solana-provider/src/solanaWallet.ts +++ b/packages/providers/solana-provider/src/solanaWallet.ts @@ -1,7 +1,6 @@ -import { Transaction } from "@solana/web3.js"; import { RequestArguments, SafeEventEmitterProvider } from "@web3auth/base"; -import { ISolanaWallet } from "./interface"; +import { ISolanaWallet, TransactionOrVersionedTransaction } from "./interface"; export class SolanaWallet implements ISolanaWallet { public provider: SafeEventEmitterProvider; @@ -18,7 +17,7 @@ export class SolanaWallet implements ISolanaWallet { return accounts; } - public async signAndSendTransaction(transaction: Transaction): Promise<{ signature: string }> { + public async signAndSendTransaction(transaction: T): Promise<{ signature: string }> { const { signature } = await this.provider.request<{ signature: string }>({ method: "signAndSendTransaction", params: { @@ -28,24 +27,24 @@ export class SolanaWallet implements ISolanaWallet { return { signature }; } - public async signTransaction(transaction: Transaction): Promise { - const signedTransaction = (await this.provider.request({ + public async signTransaction(transaction: T): Promise { + const signedTransaction = await this.provider.request({ method: "signTransaction", params: { message: transaction, }, - })) as Transaction; - return signedTransaction; + }); + return signedTransaction as T; } - public async signAllTransactions(transactions: Transaction[]): Promise { - const signedTransactions = (await this.provider.request({ + public async signAllTransactions(transactions: T[]): Promise { + const signedTransactions = await this.provider.request({ method: "signAllTransactions", params: { message: transactions, }, - })) as Transaction[]; - return signedTransactions; + }); + return signedTransactions as T[]; } public async signMessage(data: Uint8Array): Promise {