import { describe, it, expect } from "vitest"; import { Keypair } from "@stellar/stellar-sdk"; import { verifyStellarSignature } from "../xlm"; import { ProofStatus, ProofTypes, SignatureProof } from "@notabene/javascript-sdk"; describe("verifyStellarSignature", () => { const createValidProof = (): SignatureProof => { const keypair = Keypair.fromSecret("SBKMCWGXNN6C6QMCXOUZFQ4DSCACRE4FKIIFQMBFORXLOATUUM7SH4SV"); const message = "test message"; const messageBuffer = Buffer.from(message, "utf-8"); const signature = keypair.sign(messageBuffer); return { address: `stellar:pubnet:${keypair.publicKey().toString()}`, attestation: message, proof: signature.toString("base64"), status: ProofStatus.PENDING, type: ProofTypes.XLM_ED25519, wallet_provider: "STELLAR", did: `did:pkh:stellar:pubnet:${keypair.publicKey().toString()}` }; }; it("should verify a valid Stellar signature", () => { const proof = createValidProof(); const result = verifyStellarSignature(proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("should fail for invalid signature", () => { const keypair1 = Keypair.random(); const keypair2 = Keypair.random(); const message = "test message"; const messageBuffer = Buffer.from(message, "utf-8"); const signature = keypair1.sign(messageBuffer); const proof: SignatureProof = { address: `stellar:pubnet:${keypair2.publicKey().toString()}`, attestation: message, proof: signature.toString("base64"), status: ProofStatus.PENDING, type: ProofTypes.XLM_ED25519, wallet_provider: "STELLAR", did: `did:pkh:stellar:pubnet:${keypair2.publicKey().toString()}` }; const result = verifyStellarSignature(proof); expect(result.status).toBe(ProofStatus.FAILED); }); it("should fail for non-xlm namespace", () => { const proof = { ...createValidProof(), address: "eip155:1:0x000000000000000000000000000000000000dead" // Different namespace } as SignatureProof; const result = verifyStellarSignature(proof); expect(result.status).toBe(ProofStatus.FAILED); }); it("should fail for malformed address", () => { const proof = { ...createValidProof(), address: "stellar:pubnet" } as unknown as SignatureProof; const result = verifyStellarSignature(proof); expect(result.status).toBe(ProofStatus.FAILED); }); it("should fail for invalid public key format", () => { const proof = { ...createValidProof(), address: "stellar:pubnet:not-a-valid-public-key" } as SignatureProof; const result = verifyStellarSignature(proof); expect(result.status).toBe(ProofStatus.FAILED); }); });