import { verify } from "../verify" ; import sample from "../schema/sample-verifiable-credential.json" ; import batched from "../schema/batched-verifiable-credential-1.json" ; import { WrappedDocument } from "../../3.0/types" ; const sampleVerifiableCredential = sample as WrappedDocument ; const sampleBatchedVC = batched as WrappedDocument ; describe ( "signature" , ( ) => { describe ( "verify" , ( ) => { describe ( "documents without proofs" , ( ) => { test ( "returns true for documents with unaltered data" , ( ) => { expect ( verify ( sampleVerifiableCredential ) ) . toBe ( true ) ; } ) ; test ( "returns false for documents with altered value" , ( ) => { const verifiableCredential = { ... sampleVerifiableCredential , issuer : { id : "https://example.com" , name : "Fake Name" , } , } ; expect ( verify ( verifiableCredential ) ) . toBe ( false ) ; } ) ; test ( "returns false for documents with altered key" , ( ) => { const verifiableCredential = { ... sampleVerifiableCredential , issuer : { id : "https://example.com" , fakename : "DEMO STORE" , } , } ; expect ( verify ( verifiableCredential as any ) ) . toBe ( false ) ; } ) ; test ( "returns false for documents with additional data not part of salt" , ( ) => { const verifiableCredential = { ... sampleVerifiableCredential , credentialSubject : { ... sampleVerifiableCredential . credentialSubject , class : [ { type : "3" , effectiveDate : "2010-01-01T19:23:24Z" , } , { type : "3A" , effectiveDate : "2010-01-01T19:23:24Z" , } , { type : "2A" , effectiveDate : "2020-06-05T00:00:00Z" , } , ] , } , } ; expect ( verify ( verifiableCredential ) ) . toBe ( false ) ; } ) ; test ( "returns false for documents with missing data" , ( ) => { const verifiableCredential = { ... sampleVerifiableCredential , credentialSubject : { ... sampleVerifiableCredential . credentialSubject , class : [ { type : "3" , effectiveDate : "2010-01-01T19:23:24Z" , } , ] , } , } ; expect ( verify ( verifiableCredential ) ) . toBe ( false ) ; } ) ; } ) ; describe ( "documents with proofs" , ( ) => { test ( "returns true for documents with unaltered data" , ( ) => { const verifiableCredential = sampleBatchedVC ; expect ( verify ( verifiableCredential ) ) . toBe ( true ) ; } ) ; test ( "returns false for documents with altered value" , ( ) => { const verifiableCredential = { ... sampleBatchedVC , issuer : { id : "https://example.com" , name : "Fake Name" , } , } ; expect ( verify ( verifiableCredential ) ) . toBe ( false ) ; } ) ; test ( "returns false for documents with altered key" , ( ) => { const verifiableCredential = { ... sampleBatchedVC , issuer : { id : "https://example.com" , fakename : "DEMO STORE" , } , } ; expect ( verify ( verifiableCredential as any ) ) . toBe ( false ) ; } ) ; test ( "returns false for documents with additional data not part of salt" , ( ) => { const verifiableCredential = { ... sampleBatchedVC , credentialSubject : { ... sampleVerifiableCredential . credentialSubject , class : [ { type : "3" , effectiveDate : "2010-01-01T19:23:24Z" , } , { type : "3A" , effectiveDate : "2010-01-01T19:23:24Z" , } , { type : "2A" , effectiveDate : "2020-06-05T00:00:00Z" , } , ] , } , } ; expect ( verify ( verifiableCredential ) ) . toBe ( false ) ; } ) ; test ( "returns false for documents with missing data" , ( ) => { const verifiableCredential = { ... sampleBatchedVC , credentialSubject : { ... sampleVerifiableCredential . credentialSubject , class : [ { type : "3" , effectiveDate : "2010-01-01T19:23:24Z" , } , ] , } , } ; expect ( verify ( verifiableCredential ) ) . toBe ( false ) ; } ) ; test ( "returns false for documents with altered targetHash" , ( ) => { const verifiableCredential = { ... sampleBatchedVC , proof : { ... sampleBatchedVC . proof , targetHash : "81859d00caadd33f4100b7d37230684b953195786426a1be2c3bfea32b3c2a53" , } , } ; expect ( verify ( verifiableCredential ) ) . toBe ( false ) ; } ) ; test ( "returns false for documents with altered proofs" , ( ) => { const verifiableCredential = { ... sampleBatchedVC , proof : { ... sampleBatchedVC . proof , proofs : [ "964b066a78bfec3701760893090fa41bd0c86fb1328f2ba07293252a1a7d5531" ] , } , } ; expect ( verify ( verifiableCredential ) ) . toBe ( false ) ; } ) ; test ( "returns false for documents with missing proofs" , ( ) => { const verifiableCredential = { ... sampleBatchedVC , proof : { ... sampleBatchedVC . proof , proofs : [ ] , } , } ; expect ( verify ( verifiableCredential ) ) . toBe ( false ) ; } ) ; test ( "returns false for documents with altered merkleRoot" , ( ) => { const verifiableCredential = { ... sampleBatchedVC , proof : { ... sampleBatchedVC . proof , merkleRoot : "76eee8fc36924975c00420e463aab1a2e6b24fb8cfb81e8c789b2534da4b59a4" , } , } ; expect ( verify ( verifiableCredential ) ) . toBe ( false ) ; } ) ; } ) ; } ) ; } ) ;