Documentation Index
Fetch the complete documentation index at: https://docs.getpara.com/llms.txt
Use this file to discover all available pages before exploring further.
Verify Ed25519 signatures to confirm that a message was signed by a specific Stellar address. Essential for authentication and ensuring data integrity.
Verify Signatures
import { useParaStellarSigner } from "@getpara/react-native-wallet/stellar";
import { Networks, StrKey } from "@stellar/stellar-sdk";
import { Text, Button } from "react-native";
import nacl from "tweetnacl";
function VerifySignature() {
const { stellarSigner, isLoading } = useParaStellarSigner({
networkPassphrase: Networks.PUBLIC,
});
const verifyMessage = async () => {
if (!stellarSigner) return;
const message = "Hello, Stellar!";
const messageBytes = Buffer.from(new TextEncoder().encode(message));
// Sign the message
const signature = await stellarSigner.signBytes(messageBytes);
// Extract the raw Ed25519 public key from the Stellar G-address
const publicKeyBytes = StrKey.decodeEd25519PublicKey(stellarSigner.address);
// Verify the signature using tweetnacl
const isValid = nacl.sign.detached.verify(
new Uint8Array(messageBytes),
new Uint8Array(signature),
publicKeyBytes
);
console.log("Message:", message);
console.log("Signature:", signature.toString("hex"));
console.log("Signature valid:", isValid);
console.log("Signer:", stellarSigner.address);
return isValid;
};
if (isLoading) return <Text>Loading...</Text>;
return <Button title="Sign & Verify Message" onPress={verifyMessage} />;
}
Install tweetnacl for Ed25519 signature verification: npm install tweetnacl. The StrKey.decodeEd25519PublicKey method from @stellar/stellar-sdk extracts the raw 32-byte public key from a Stellar G-address.
Next Steps