import { describe, it, expect } from "vitest"; import { verifyPersonalSignXRPL } from "../xrpl"; import { Wallet } from "xrpl"; import { sign } from "ripple-keypairs"; import { type SignatureProof, ProofStatus, ProofTypes, } from "@notabene/javascript-sdk"; describe("verifyPersonalSignXRPL", async () => { // Create test wallets using seed const xrp_ed25519 = Wallet.fromSeed("snoPBrXtMeMyMHUVTgbuqAfg1SUTb"); const message = "Ripple signature test"; function createXRPLProof(wallet: Wallet): SignatureProof { const messageHex = Buffer.from(message).toString("hex"); const signature = sign(messageHex, wallet.privateKey); return { type: ProofTypes.XRP_ED25519, address: `xrpl:1:${wallet.address}`, did: `did:pkh:xrpl:1:${wallet.address}`, attestation: message, proof: signature, status: ProofStatus.PENDING, wallet_provider: "XRPL", }; } function existingXRPLProof(): SignatureProof { return { type: ProofTypes.XRP_ED25519, proof: 'B080C34BCD2F1392420A5CB46C14772AC54841181CB3387A0793025C480A6A52292A869FB2B86B89EA33E096285F8CC45F5D35D4E29750BA8E127076CADF7906', address: `xrpl:1:rGWNp4P9DJpDNhPc7t9GeHoQb8SCKWBfYV`, did: `did:pkh:xrpl:1:rGWNp4P9DJpDNhPc7t9GeHoQb8SCKWBfYV`, status: ProofStatus.PENDING, wallet_provider: "XRPL", attestation: "I certify that\n\nxrpl:1 account rGWNp4P9DJpDNhPc7t9GeHoQb8SCKWBfYV\n\nbelonged to did:key:z6Mkq3vnQfZFLVe2UXBUTgonfEhzYr9QF7xvkSSpdt9LXeY6\n\non Thu, 06 Mar 2025 10:34:43 GMT" } } it("returns verified proof when valid existing XRPL proof", async () => { const proof = existingXRPLProof(); const result = await verifyPersonalSignXRPL(proof, undefined, true); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("returns verified proof when valid secp256k1 signature", async () => { const proof = createXRPLProof(xrp_ed25519); const result = await verifyPersonalSignXRPL( proof, xrp_ed25519.publicKey ); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("returns failed proof when invalid message", async () => { const proof = { ...createXRPLProof(xrp_ed25519), attestation: "evil text", }; const result = await verifyPersonalSignXRPL( proof, xrp_ed25519.publicKey ); expect(result.status).toBe(ProofStatus.FAILED); }); it("returns failed proof for non-XRPL address", async () => { const proof: SignatureProof = { type: ProofTypes.XRP_ED25519, did: `did:pkh:eip155:1:0x123`, wallet_provider: "XRPL", address: "eip155:1:0x123", attestation: "test message", proof: "signature", status: ProofStatus.PENDING, }; const result = await verifyPersonalSignXRPL( proof, xrp_ed25519.publicKey ); expect(result.status).toBe(ProofStatus.FAILED); }); });