33 lines
743 B
JavaScript
33 lines
743 B
JavaScript
![]() |
import { Keypair, Transaction, VersionedTransaction } from "@solana/web3.js"
|
||
|
import bs58 from "bs58"
|
||
|
|
||
|
export const keypair = Keypair.generate()
|
||
|
|
||
|
console.log(keypair.publicKey.toString())
|
||
|
console.log(bs58.encode(keypair.secretKey))
|
||
|
|
||
|
export class Wallet {
|
||
|
constructor(signer) {
|
||
|
this._signer = signer
|
||
|
}
|
||
|
|
||
|
async signTransaction(tx) {
|
||
|
if (tx instanceof Transaction) {
|
||
|
tx.sign(this._signer)
|
||
|
} else if (tx instanceof VersionedTransaction) {
|
||
|
tx.sign([this._signer])
|
||
|
} else {
|
||
|
throw new Error("Unsupported transaction type")
|
||
|
}
|
||
|
return tx
|
||
|
}
|
||
|
|
||
|
async signAllTransactions(txs) {
|
||
|
return Promise.all(txs.map(tx => this.signTransaction(tx)))
|
||
|
}
|
||
|
|
||
|
get publicKey() {
|
||
|
return this._signer.publicKey
|
||
|
}
|
||
|
}
|