From 30e6b5b8c1f22a357b775941ed00ada4348f9316 Mon Sep 17 00:00:00 2001 From: Martin Auer Date: Wed, 27 Mar 2024 11:03:30 +0100 Subject: [PATCH] fix: anoncreds w3c migration metadata Signed-off-by: Martin Auer --- .../w3cCredentialRecordMigration.test.ts | 81 +++++++++++-------- .../0.4-0.5/anonCredsCredentialRecord.ts | 4 + 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/packages/anoncreds/src/updates/0.4-0.5/__tests__/w3cCredentialRecordMigration.test.ts b/packages/anoncreds/src/updates/0.4-0.5/__tests__/w3cCredentialRecordMigration.test.ts index 226e868edd..2e45785729 100644 --- a/packages/anoncreds/src/updates/0.4-0.5/__tests__/w3cCredentialRecordMigration.test.ts +++ b/packages/anoncreds/src/updates/0.4-0.5/__tests__/w3cCredentialRecordMigration.test.ts @@ -220,43 +220,46 @@ async function testMigration( if (!registerCredentialDefinitionReturn.credentialDefinitionState.credentialDefinitionId) throw new CredoError('Registering Credential Definition Failed') - const records = [ - new AnonCredsCredentialRecord({ - credential: { - schema_id: schemaId, - cred_def_id: registerCredentialDefinitionReturn.credentialDefinitionState.credentialDefinitionId, - values: { - name: { - raw: 'John', - encoded: '76355713903561865866741292988746191972523015098789458240077478826513114743258', - }, - age: { raw: '25', encoded: '25' }, - }, - signature: { - p_credential: { - m_2: '96181142928573619139692730181044468294945970900261235940698944149443005219418', - a: '95552886901127172841432400616361951122825637102065915900211722444153579891548765880931308692457984326066263506661706967742637168349111737200116541217341739027256190535822337883555402874901690699603230292607481206740216276736875319709356355255797288879451730329296366840213920367976178079664448005608079197649139477441385127107355597906058676699377491628047651331689288017597714832563994968230904723400034478518535411493372596211553797813567090114739752408151368926090849149021350138796163980103411453098000223493524437564062789271302371287568506870484060911412715559140166845310368136412863128732929561146328431066870', - e: '259344723055062059907025491480697571938277889515152306249728583105665800713306759149981690559193987143012367913206299323899696942213235956742929837794489002147266183999965799605813', - v: '8070312275110314663750247899433202850238560575163878956819342967827136399370879736823043902982634515009588016797203155246614708232573921376646871743359587732590693401587607271972304303322060390310307460889523961550612965021232979808509508502354241838342542729225461467834597352210800168107201638861601487760961526713355932504366874557170337152964069325172574449356691055377568302458374147949937789910094307449082152173580675507028369533914480926873196435808261915052547630680304620062203647948590064800546491641963412948122135194369131128319694594446518925913583118382698018169919523769679141724867515604189334120099773703979769794325694804992635522127820413717601811493634024617930397944903746555691677663850240187799372670069559074549528342288602574968520156320273386872799429362106185458798531573424651644586691950218', - }, - r_credential: null, + const anonCredsRecord = new AnonCredsCredentialRecord({ + credential: { + schema_id: schemaId, + cred_def_id: registerCredentialDefinitionReturn.credentialDefinitionState.credentialDefinitionId, + values: { + name: { + raw: 'John', + encoded: '76355713903561865866741292988746191972523015098789458240077478826513114743258', }, - signature_correctness_proof: { - se: '22707379000451320101568757017184696744124237924783723059712360528872398590682272715197914336834321599243107036831239336605987281577690130807752876870302232265860540101807563741012022740942625464987934377354684266599492895835685698819662114798915664525092894122648542269399563759087759048742378622062870244156257780544523627249100818371255142174054148531811440128609220992508274170196108004985441276737673328642493312249112077836369109453214857237693701603680205115444482751700483514317558743227403858290707747986550689265796031162549838465391957776237071049436590886476581821857234951536091662216488995258175202055258', - c: '86499530658088050169174214946559930902913340880816576251403968391737698128027', + age: { raw: '25', encoded: '25' }, + }, + signature: { + p_credential: { + m_2: '96181142928573619139692730181044468294945970900261235940698944149443005219418', + a: '95552886901127172841432400616361951122825637102065915900211722444153579891548765880931308692457984326066263506661706967742637168349111737200116541217341739027256190535822337883555402874901690699603230292607481206740216276736875319709356355255797288879451730329296366840213920367976178079664448005608079197649139477441385127107355597906058676699377491628047651331689288017597714832563994968230904723400034478518535411493372596211553797813567090114739752408151368926090849149021350138796163980103411453098000223493524437564062789271302371287568506870484060911412715559140166845310368136412863128732929561146328431066870', + e: '259344723055062059907025491480697571938277889515152306249728583105665800713306759149981690559193987143012367913206299323899696942213235956742929837794489002147266183999965799605813', + v: '8070312275110314663750247899433202850238560575163878956819342967827136399370879736823043902982634515009588016797203155246614708232573921376646871743359587732590693401587607271972304303322060390310307460889523961550612965021232979808509508502354241838342542729225461467834597352210800168107201638861601487760961526713355932504366874557170337152964069325172574449356691055377568302458374147949937789910094307449082152173580675507028369533914480926873196435808261915052547630680304620062203647948590064800546491641963412948122135194369131128319694594446518925913583118382698018169919523769679141724867515604189334120099773703979769794325694804992635522127820413717601811493634024617930397944903746555691677663850240187799372670069559074549528342288602574968520156320273386872799429362106185458798531573424651644586691950218', }, - rev_reg_id: undefined, + r_credential: null, + }, + signature_correctness_proof: { + se: '22707379000451320101568757017184696744124237924783723059712360528872398590682272715197914336834321599243107036831239336605987281577690130807752876870302232265860540101807563741012022740942625464987934377354684266599492895835685698819662114798915664525092894122648542269399563759087759048742378622062870244156257780544523627249100818371255142174054148531811440128609220992508274170196108004985441276737673328642493312249112077836369109453214857237693701603680205115444482751700483514317558743227403858290707747986550689265796031162549838465391957776237071049436590886476581821857234951536091662216488995258175202055258', + c: '86499530658088050169174214946559930902913340880816576251403968391737698128027', }, - credentialId: 'myCredentialId', - credentialRevocationId: undefined, - linkSecretId: 'linkSecretId', - issuerId, - schemaIssuerId, - schemaName: 'schemaName', - schemaVersion: 'schemaVersion', - methodName: 'methodName', - }), - ] + rev_reg_id: undefined, + }, + credentialId: 'myCredentialId', + credentialRevocationId: undefined, + linkSecretId: 'linkSecretId', + issuerId, + schemaIssuerId, + schemaName: 'schemaName', + schemaVersion: 'schemaVersion', + methodName: 'methodName', + }) + + anonCredsRecord.metadata.set('custom', { + key: 'value', + }) + const records = [anonCredsRecord] mockFunction(anonCredsRepo.getAll).mockResolvedValue(records) @@ -280,6 +283,16 @@ async function testMigration( expect(anonCredsRepo.getAll).toHaveBeenCalledTimes(1) expect(anonCredsRepo.getAll).toHaveBeenCalledWith(agent.context) expect(w3cRepo.save).toHaveBeenCalledTimes(1) + expect(w3cRepo.save).toHaveBeenCalledWith( + agent.context, + expect.objectContaining({ + metadata: expect.objectContaining({ + data: expect.objectContaining({ + custom: { key: 'value' }, + }), + }), + }) + ) expect(w3cRepo.update).toHaveBeenCalledTimes(1) expect(anonCredsRepo.delete).toHaveBeenCalledTimes(1) diff --git a/packages/anoncreds/src/updates/0.4-0.5/anonCredsCredentialRecord.ts b/packages/anoncreds/src/updates/0.4-0.5/anonCredsCredentialRecord.ts index 4003abbe40..24e0459a24 100644 --- a/packages/anoncreds/src/updates/0.4-0.5/anonCredsCredentialRecord.ts +++ b/packages/anoncreds/src/updates/0.4-0.5/anonCredsCredentialRecord.ts @@ -96,6 +96,10 @@ async function migrateLegacyToW3cCredential(agentContext: AgentContext, legacyRe credential: w3cJsonLdCredential, }) + for (const [key, meta] of Object.entries(legacyRecord.metadata.data)) { + w3cCredentialRecord.metadata.set(key, meta) + } + const anonCredsTags = getW3cRecordAnonCredsTags({ w3cCredentialRecord, schemaId: qualifiedSchemaId,