import { FaceSolanaNearTransactionPayload, JsonRpcMethod } from '@haechi-labs/face-types'; import { PublicKey, Transaction } from '@solana/web3.js'; import { base58 } from 'ethers/lib/utils'; import { Internal } from '../Internal'; export class SolanaProvider { internal: Internal; constructor(internal: Internal) { this.internal = internal; } async getPublicKeys(): Promise { const addresses = await this.internal.getAddresses(); return addresses.map((address) => { return new PublicKey(base58.decode(address)); }); } async signAndSendTransaction(transaction: Transaction): Promise { const txPayload: FaceSolanaNearTransactionPayload = { serializedHex: transaction .serialize({ requireAllSignatures: false, verifySignatures: false, }) .toString('hex'), }; const result = await this.internal.sendRpc({ method: JsonRpcMethod.solana_sendTransaction, params: [txPayload], }); return result!; } }