Skip to content

Commit

Permalink
fix: anoncreds w3c migration metadata (#1803)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Auer <[email protected]>
  • Loading branch information
auer-martin authored Mar 27, 2024
1 parent 15c62a8 commit 069c9c4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 069c9c4

Please sign in to comment.