diff --git a/packages/solana/src/account.ts b/packages/solana/src/account.ts index 1b33b3f4..258def2b 100644 --- a/packages/solana/src/account.ts +++ b/packages/solana/src/account.ts @@ -28,6 +28,7 @@ export class SOLAccount extends Account { constructor(publicKey: PublicKey, walletOrKeypair: Keypair | MessageSigner) { super(publicKey.toString()) + if (walletOrKeypair instanceof Keypair) { this.keypair = walletOrKeypair this.isKeypair = true @@ -54,18 +55,25 @@ export class SOLAccount extends Account { const buffer = message.getVerificationBuffer() let signature + let publicKey: string // as Base58 if (this.wallet) { const signed = await this.wallet.signMessage(buffer) - if (signed instanceof Uint8Array) signature = signed - else signature = signed.signature + signature = signed instanceof Uint8Array ? signed : signed.signature + publicKey = this.wallet.publicKey.toBase58() } else if (this.keypair) { - signature = base58.encode(nacl.sign.detached(buffer, this.keypair.secretKey)) + signature = nacl.sign.detached(buffer, this.keypair.secretKey) + publicKey = this.keypair.publicKey.toBase58() } else { throw new Error('Cannot sign message') } - const signatureObj = JSON.stringify({ signature, publicKey: this.address }) + signature = base58.encode(signature) + + const signatureObj = JSON.stringify({ + signature, + publicKey: publicKey, + }) if (verifySolana(buffer, signatureObj)) return signatureObj throw new Error('Cannot proof the integrity of the signature') diff --git a/packages/solana/src/verify.ts b/packages/solana/src/verify.ts index ff329ccd..ba674b5d 100644 --- a/packages/solana/src/verify.ts +++ b/packages/solana/src/verify.ts @@ -1,5 +1,5 @@ import { SignableMessage } from '@aleph-sdk/account' -import bs58 from 'bs58' +import base58 from 'bs58' import nacl from 'tweetnacl' /** @@ -20,7 +20,7 @@ export function verifySolana(message: Uint8Array | SignableMessage, serializedSi const { signature, publicKey } = JSON.parse(serializedSignature) try { - return nacl.sign.detached.verify(message, bs58.decode(signature), bs58.decode(publicKey)) + return nacl.sign.detached.verify(message, base58.decode(signature), base58.decode(publicKey)) } catch (e: unknown) { return false }