|
| 1 | +import _JB from 'json-bigint'; |
| 2 | + |
| 3 | +import { |
| 4 | + PrivateVerificationAuditRecord, |
| 5 | + VerifiablePresentationRequestV1, |
| 6 | + VerifiablePresentationV1, |
| 7 | + VerificationAuditRecord, |
| 8 | +} from '../../../src/index.ts'; |
| 9 | + |
| 10 | +const JSONBig = _JB({ alwaysParseAsBig: true, useNativeBigInt: true }); |
| 11 | + |
| 12 | +const PRESENTATION_REQUEST = VerifiablePresentationRequestV1.fromJSON({ |
| 13 | + requestContext: { |
| 14 | + type: 'ConcordiumContextInformationV1', |
| 15 | + given: [ |
| 16 | + { label: 'Nonce', context: '00010203' }, |
| 17 | + { label: 'ConnectionID', context: '0102010201020102010201020102010201020102010201020102010201020102' }, |
| 18 | + { label: 'ContextString', context: 'Wine payment' }, |
| 19 | + ], |
| 20 | + requested: ['BlockHash', 'ResourceID'], |
| 21 | + }, |
| 22 | + credentialStatements: [ |
| 23 | + { |
| 24 | + idQualifier: { |
| 25 | + type: 'sci', |
| 26 | + issuers: [ |
| 27 | + { index: 2101n, subindex: 0n }, |
| 28 | + { index: 1337n, subindex: 42n }, |
| 29 | + ] as any, |
| 30 | + }, |
| 31 | + statement: [ |
| 32 | + { type: 'AttributeInRange', attributeTag: 'b', lower: 80n, upper: 1237n } as any, |
| 33 | + { type: 'AttributeInSet', attributeTag: 'c', set: ['aa', 'ff', 'zz'] }, |
| 34 | + ], |
| 35 | + }, |
| 36 | + { |
| 37 | + idQualifier: { type: 'id', issuers: [0, 1, 2] }, |
| 38 | + statement: [{ type: 'RevealAttribute', attributeTag: 'firstName' }], |
| 39 | + }, |
| 40 | + ], |
| 41 | + transactionRef: '0102030401020304010203040102030401020304010203040102030401020304', |
| 42 | +}); |
| 43 | + |
| 44 | +const PRESENTATION = VerifiablePresentationV1.fromJSON({ |
| 45 | + presentationContext: { |
| 46 | + type: 'ConcordiumContextInformationV1', |
| 47 | + given: [ |
| 48 | + { label: 'Nonce', context: '00010203' }, |
| 49 | + { label: 'ConnectionID', context: '0102010201020102010201020102010201020102010201020102010201020102' }, |
| 50 | + { label: 'ContextString', context: 'Wine payment' }, |
| 51 | + ], |
| 52 | + requested: [ |
| 53 | + { label: 'BlockHash', context: '0101010101010101010101010101010101010101010101010101010101010101' }, |
| 54 | + { label: 'ResourceID', context: 'https://compliant.shop' }, |
| 55 | + ], |
| 56 | + }, |
| 57 | + verifiableCredential: [ |
| 58 | + { |
| 59 | + type: ['VerifiableCredential', 'ConcordiumVerifiableCredentialV1', 'ConcordiumIDBasedCredential'], |
| 60 | + proof: { |
| 61 | + type: 'ConcordiumZKProofV4', |
| 62 | + createdAt: '2025-10-17T13:14:14.292Z', |
| 63 | + proofValue: |
| 64 | + '01020102010201020102010201020102010201020102010201020102010201020102010201020102010201020102010201020102010201020102010201020102', |
| 65 | + }, |
| 66 | + issuer: 'ccd:testnet:idp:0', |
| 67 | + credentialSubject: { |
| 68 | + statement: [ |
| 69 | + { attributeTag: 'dob', lower: '81', type: 'AttributeInRange', upper: '1231' }, |
| 70 | + { attributeTag: 'firstName', type: 'RevealAttribute' }, |
| 71 | + ], |
| 72 | + id: '123456123456123456123456123456123456123456123456', |
| 73 | + }, |
| 74 | + }, |
| 75 | + ], |
| 76 | + proof: { created: '2025-10-17T13:14:14.290Z', proofValue: [], type: 'ConcordiumWeakLinkingProofV1' }, |
| 77 | +}); |
| 78 | + |
| 79 | +const PRIVATE_RECORD = PrivateVerificationAuditRecord.create('VERY unique ID', PRESENTATION_REQUEST, PRESENTATION); |
| 80 | +const PUBLIC_RECORD = PrivateVerificationAuditRecord.toPublic(PRIVATE_RECORD, 'some public info?'); |
| 81 | + |
| 82 | +describe('PrivateVerificationAuditRecord', () => { |
| 83 | + it('completes JSON roundtrip', () => { |
| 84 | + const json = JSONBig.stringify(PRIVATE_RECORD); |
| 85 | + const roundtrip = PrivateVerificationAuditRecord.fromJSON(JSONBig.parse(json)); |
| 86 | + expect(roundtrip).toEqual(PRIVATE_RECORD); |
| 87 | + }); |
| 88 | + |
| 89 | + it('creates expected public record', () => { |
| 90 | + const publicAuditRecord = PrivateVerificationAuditRecord.toPublic(PRIVATE_RECORD, 'some public info?'); |
| 91 | + const expected: VerificationAuditRecord.Type = VerificationAuditRecord.fromJSON({ |
| 92 | + hash: 'fcce3a7222e09bc86f0b4e0186501ff360c5a0abce88b8d1df2aaf7aa3ef8d78', |
| 93 | + info: 'some public info?', |
| 94 | + }); |
| 95 | + expect(publicAuditRecord).toEqual(expected); |
| 96 | + }); |
| 97 | +}); |
| 98 | + |
| 99 | +describe('VerificationAuditRecord', () => { |
| 100 | + it('completes JSON roundtrip', () => { |
| 101 | + const json = JSONBig.stringify(PUBLIC_RECORD); |
| 102 | + const roundtrip = VerificationAuditRecord.fromJSON(JSONBig.parse(json)); |
| 103 | + expect(roundtrip).toEqual(PUBLIC_RECORD); |
| 104 | + }); |
| 105 | + |
| 106 | + it('computes the anchor as expected', () => { |
| 107 | + const anchor = VerificationAuditRecord.createAnchor(PUBLIC_RECORD, 'anchor info'); |
| 108 | + const decoded = VerificationAuditRecord.decodeAnchor(anchor); |
| 109 | + const expected: VerificationAuditRecord.AnchorData = { |
| 110 | + type: 'CCDVAA', |
| 111 | + version: 1, |
| 112 | + hash: PUBLIC_RECORD.hash, |
| 113 | + public: 'anchor info', |
| 114 | + }; |
| 115 | + expect(decoded).toEqual(expected); |
| 116 | + }); |
| 117 | +}); |
0 commit comments