import { describe, it, expect } from "vitest"; import { verifyProof } from "../index"; import { type DeclarationProof, type ScreenshotProof, type SignatureProof, ProofStatus, ProofTypes, } from "@notabene/javascript-sdk"; describe("verifyProof", () => { it("should verify a confirmed checkbox proof", async () => { const proof: DeclarationProof = { type: ProofTypes.SelfDeclaration, status: ProofStatus.PENDING, attestation: "I solemly swear", did: "did:example:123", address: "eip155:1:0x1234567890123456789012345678901234567890", confirmed: true, }; const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("should fail an unconfirmed checkbox proof", async () => { const proof: DeclarationProof = { type: ProofTypes.SelfDeclaration, status: ProofStatus.PENDING, attestation: "I solemly swear", did: "did:example:123", address: "eip155:1:0x1234567890123456789012345678901234567890", confirmed: false, }; const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.FAILED); }); it("should flag a screenshot proof with a URL", async () => { const proof: ScreenshotProof = { type: ProofTypes.Screenshot, status: ProofStatus.PENDING, did: "did:example:123", address: "eip155:1:0x1234567890123456789012345678901234567890", url: "https://example.com/screenshot.png", }; const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.FLAGGED); }); it("should fail a screenshot proof without a URL", async () => { const proof: ScreenshotProof = { type: ProofTypes.Screenshot, status: ProofStatus.PENDING, did: "did:example:123", address: "eip155:1:0x1234567890123456789012345678901234567890", url: "", }; const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.FAILED); }); it("should return the original proof for unknown proof types", async () => { const proof = { type: "UnknownProofType", status: ProofStatus.PENDING, did: "did:example:123", address: "eip155:1:0x1234567890123456789012345678901234567890", }; // @ts-expect-error proof type is not known const result = await verifyProof(proof); expect(result).toEqual(proof); }); describe("eip191", () => { const proof: SignatureProof = { type: ProofTypes.EIP191, address: "eip155:1:0x772f226b9cc93a2953dc5868864de72f90441caf", did: "did:pkh:eip155:1:0x772f226b9cc93a2953dc5868864de72f90441caf", attestation: "I agree", proof: "0xddd74ca17084728a167b6f99326b50a0ce4a1ce4f80a56da4a60b23b69637c624e6dfb2270de56caece9182200fe38791339cbf097586a4e06a9ef4bd298cc1800", status: ProofStatus.PENDING, wallet_provider: "MetaMask", }; it("should verify proof", async () => { const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("should fail if not invalid proof", async () => { const result = await verifyProof({ ...proof, proof: "0x", } as SignatureProof); expect(result.status).toBe(ProofStatus.FAILED); }); }); describe("solana", () => { const proof: SignatureProof = { type: ProofTypes.ED25519, status: ProofStatus.PENDING, did: "did:pkh:solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:3GgW39JvdBVCAdiK1mafeBcBKXJq8mee5woVoDARRnPq", address: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:3GgW39JvdBVCAdiK1mafeBcBKXJq8mee5woVoDARRnPq", attestation: "Test message", proof: "8dkeX3S+qisPkadV5QkmLWu2gbom/ljqlEwDAVuEV33HWZbSbPol+KV/zET4NLn8JBvSpu6JROJRg45WAIMPAQ==", wallet_provider: "Phantom", }; it("should verify proof", async () => { const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("should fail if not invalid proof", async () => { const result = await verifyProof({ ...proof, proof: "0x", } as SignatureProof); expect(result.status).toBe(ProofStatus.FAILED); }); }); describe("bitcoin", () => { const testnetProof: SignatureProof = { type: ProofTypes.BIP137, status: ProofStatus.PENDING, did: "did:pkh:bip122:000000000019d6689c085ae165831e93:tb1q0apvgsh48f3rmw224na3ye5rrg37fd796cm0xf", address: "bip122:000000000019d6689c085ae165831e93:tb1q0apvgsh48f3rmw224na3ye5rrg37fd796cm0xf", proof: "AkcwRAIgZHktoWuDR5A1F8WFlm0v3dIGCVfokUWbeR7XbsH5JYECIH0AylmIg+zOeId0TXi6p++1BJSnc3n8EqnpnTd64T8EASEDtJ0tfDgrGYO4OSuYjyiehIoY1dEUkPo8XZQJ3Yqo//8=", attestation: "I certify that the blockchain address tb1q0apvgsh48f3rmw224na3ye5rrg37fd796cm0xf belongs to did:pkh:bip122:000000000019d6689c085ae165831e93:tb1q0apvgsh48f3rmw224na3ye5rrg37fd796cm0xf on Tue, 29 Apr 2025 16:22:24 GMT", wallet_provider: "Manual Wallet Signature", }; const proof: SignatureProof = { type: ProofTypes.BIP137, status: ProofStatus.PENDING, address: "bip122:000000000019d6689c085ae165831e93:bc1qnf4kpa62dwhpwm0stsas5yv0skatt3v9s040p8", did: "did:pkh:bip122:000000000019d6689c085ae165831e93:bc1qnf4kpa62dwhpwm0stsas5yv0skatt3v9s040p8", attestation: "This is an example of a signed message.", proof: "J796FDv8f8w3syiaMSGoL6SAwPLRf6t13S+fYNjYA9EnJy3T0jZOY1eHBaGTBufOuW78FVFSwXKyUnrEjYOT9EU=", wallet_provider: "Phantom", }; const bip322Proof: SignatureProof = { did: "did:pkh:bip122:000000000019d6689c085ae165831e93:bc1qcxm70pg5yk9c8pupj93uys5azw5xpt6qeu2z0u", status: ProofStatus.PENDING, attestation: "I certify that bip122:000000000019d6689c085ae165831e93 account bc1qcxm70pg5yk9c8pupj93uys5azw5xpt6qeu2z0u belonged to did:key:z6Mket9c5r7VXswBGVrYX2t67hkh15D8CNpWJScX7ERKVWwD on Tue, 18 Feb 2025 18:29:27 GMT", address: "bip122:000000000019d6689c085ae165831e93:bc1qcxm70pg5yk9c8pupj93uys5azw5xpt6qeu2z0u", proof: "AkgwRQIhAIZlTevsH5hTsz8DOFT6hkNCNf+gBH8gjvRaI2x0T1YLAiAuzVHP+T05IO+URv/kJLjb0wDCiZwDA5DUiJPX4O7+aQEhAv9X2d9QIHF2C29QFUk5jWygaMbU3TAhzG+DfrgpI8EU", wallet_provider: "Phantom (Wallet Connect)", type: ProofTypes.BIP322, }; it("should verify segwit testnet proof", async () => { const result = await verifyProof(testnetProof); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("should verify proof", async () => { const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("should verify bip322 proof", async () => { const result = await verifyProof(bip322Proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("should fail if not invalid proof", async () => { const result = await verifyProof({ ...proof, proof: "0x", } as SignatureProof); expect(result.status).toBe(ProofStatus.FAILED); }); }); describe("TRON", () => { const proof: SignatureProof = { type: ProofTypes.TIP191, address: "tron:0x2b6653dc:TGLpk9KB2fsxSy3Yn8zLQywfFHSUtbx4tS", did: "did:pkh:tron:0x2b6653dc:TGLpk9KB2fsxSy3Yn8zLQywfFHSUtbx4tS", attestation: "I agree", proof: "0x65edeed02c254c7a39d255453aa48775576fdbcb8af2e9497bed31fa159451897320cf5feac42f87fa36aa0a5da9b24380712cc00809df989be8c4c6d42604e01b", status: ProofStatus.PENDING, wallet_provider: "MetaMask", }; it("should verify proof", async () => { const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("should fail if not invalid proof", async () => { const result = await verifyProof({ ...proof, proof: "0x", } as SignatureProof); expect(result.status).toBe(ProofStatus.FAILED); }); }); describe("XRPL", () => { const proof: SignatureProof = { type: ProofTypes.XRP_ED25519, address: "xrpl:1:rKnZzhH4YQCTVnAz16ea1Cgz5Ekhy83EHf", did: "did:pkh:xrpl:1:rKnZzhH4YQCTVnAz16ea1Cgz5Ekhy83EHf", attestation: "Ripple signature test", proof: "798DC8DB732CD3C6089BC2EE2B95C82B3474DA174E1985D8D3B70D5BFC6076AC3C152138B2825229EC97C82E135B0579C20C568E3791B32148D2B65AD35A8E03", status: ProofStatus.PENDING, wallet_provider: "XRPL", }; const publicKey = "EDD384BA2219B34C4F5FA1741FD658963EDB16213F66CFE1E220EB5B0B6B1A5913"; it("should verify proof", async () => { const response = await verifyProof(proof, publicKey); expect(response.status).toBe(ProofStatus.VERIFIED); }); it("should fail if not invalid proof", async () => { const result = await verifyProof( { ...proof, proof: "6C8D0F15631B6A653A0262C809CEFE2D6B2FD4515D66E55D3556BB079BCD1A6EA63DD8A924AC972E1BBD1383A6FD7A5932A75C479A9315D6A9D1309E0A00430E", } as SignatureProof, publicKey ); expect(result.status).toBe(ProofStatus.FAILED); }); it("should fail if not invalid public key", async () => { const result = await verifyProof( proof, "EDD384BA2219B34C4F5FA1741FD658963EDB16213F66CFE1E220EB5B0B6B1A5912" ); expect(result.status).toBe(ProofStatus.FAILED); }); }); describe("Stellar", () => { const proof: SignatureProof = { address: 'stellar:pubnet:GB4G3PJUA5NKFY5U4OJQGNZUL3QUPAJLMARNWXZNBKMGOUQJLPGXPOYG', attestation: 'test message', proof: 'Y8H4RDjxGsYSgDgLWsFN9i2vk/7cqc/nLejYK/MIElBcpeZxjn18qES92EuMMvkSIVnanRvTXSploOuHU9WCAQ==', status: ProofStatus.PENDING, type: ProofTypes.XLM_ED25519, wallet_provider: 'STELLAR', did: 'did:pkh:stellar:pubnet:GB4G3PJUA5NKFY5U4OJQGNZUL3QUPAJLMARNWXZNBKMGOUQJLPGXPOYG' }; it("should verify proof", async () => { const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("should fail if invalid proof", async () => { const result = await verifyProof({ ...proof, proof: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" } as SignatureProof); expect(result.status).toBe(ProofStatus.FAILED); }); it("should fail if invalid address format", async () => { const result = await verifyProof({ ...proof, address: "stellar:pubnet:not-a-valid-public-key" } as SignatureProof); expect(result.status).toBe(ProofStatus.FAILED); }); }); describe("SIWE", () => { const proof: SignatureProof = { address: "eip155:1:0xb5f28405d09746a20c7aa0399e5109f0c295b098", attestation: "localhost wants you to sign in with your **blockchain** account:\n0xb5f28405d09746a20c7aa0399e5109f0c295b098\n\nPlease sign this message to confirm your identity\n\nURI: http://localhost:8000\nVersion: 1\nChain ID: eip155:1\nNonce: 5389\nIssued At: 2025-05-22T09:28:38.992Z", proof: "0xf88efca56019b58d4523fa5b480fe549afd41d2d92a90e7b54126ca1d8a933fe4e5b3a507d1a2e9f28e6b9fab92d3fb288e946712903bbdafff4556694fc50f51b", did: "did:pkh:eip155:1:0xb5f28405d09746a20c7aa0399e5109f0c295b098", status: ProofStatus.PENDING, type: ProofTypes.EIP191, wallet_provider: "reown", }; it("should verify proof", async () => { const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); it("should fail if not valid proof", async () => { const result = await verifyProof({ ...proof, proof: "0x", } as SignatureProof); expect(result.status).toBe(ProofStatus.FAILED); }); }); describe("Concordium", () => { const proof: SignatureProof = { type: ProofTypes.CONCORDIUM, address: "ccd:9dd9ca4d19e9393877d2c44b70f89acb:3thVBVWVwz1oHb4ob2VgehUGF7zyAJHkm5UDW8NdQKFKCvFnoF", attestation: "I certify that\n\nccd:9dd9ca4d19e9393877d2c44b70f89acb account 3thVBVWVwz1oHb4ob2VgehUGF7zyAJHkm5UDW8NdQKFKCvFnoF\n\nbelonged to did:key:z6MksamQq4oVRktkeSDxs6pbixYFUaUca8xgCvnTVLQA5PC5\n\non Thu, 12 Jun 2025 09:20:01 GMT", proof: '{"0":{"0":"9b7263696072d4c5a0e060fec77bee5cb62ca9c8b674be864893f9d1dab75d28bf435efba9d4651ea1effdbd5b000f44d0d5be0fb10a11b3626a9a7be52e0d0d"}}', did: "did:key:z6MksamQq4oVRktkeSDxs6pbixYFUaUca8xgCvnTVLQA5PC5", status: ProofStatus.PENDING, wallet_provider: "Concordium Wallet", }; it("should verify proof", async () => { const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); }) describe("Cosmos", () => { const proof: SignatureProof = { type: ProofTypes.COSMOS, did: "did:pkh:cosmos:cosmoshub-4:cosmos1tzxpcdsszyfuj852msx85c24u37jd7rly8skc8", status: ProofStatus.PENDING, attestation: "I certify that\n\ncosmos:cosmoshub-4 account cosmos1tzxpcdsszyfuj852msx85c24u37jd7rly8skc8\n\nbelonged to did:key:z6MksamQq4oVRktkeSDxs6pbixYFUaUca8xgCvnTVLQA5PC5\n\non Mon, 14 Jul 2025 15:09:56 GMT", address: "cosmos:cosmoshub-4:cosmos1tzxpcdsszyfuj852msx85c24u37jd7rly8skc8", proof: "r0L+4864I3p2jPRBt8IAnhhvYmemMkKGg9fcKM0GOBIScgIpmyX/+ObPT/09VMSCzxlzZkH6LQGLNiD2sudAZw==", wallet_provider: "Keplr (Wallet Connect)", chainSpecificData: { pub_key: { type: "tendermint/PubKeySecp256k1", value: "Ak8k3jYgH4srYi1ygG0GWLrdbF7VwQgjiLqjifuJSsmU", }, } }; it("should verify proof", async () => { const result = await verifyProof(proof); expect(result.status).toBe(ProofStatus.VERIFIED); }); }); });