Skip to content

Commit

Permalink
VDR once deactivated is always deactivated
Browse files Browse the repository at this point in the history
  • Loading branch information
gerardsn committed Sep 23, 2024
1 parent 6a03263 commit 16975d9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
35 changes: 35 additions & 0 deletions vdr/didnuts/didstore/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,41 @@ func TestStore_Add(t *testing.T) {
require.NoError(t, err)
})
})

t.Run("once deactivated is always deactivated", func(t *testing.T) {
store := NewTestStore(t)

deactivate := create
deactivate.Controller = nil
deactivate.VerificationMethod = nil
txDeactivate := newTestTransaction(deactivate, txCreate.Ref)
update := did.Document{ID: testDID, Controller: []did.DID{testDID}, Service: []did.Service{{ID: ssi.MustParseURI("service")}}}
txUpdate := newTestTransaction(update, txDeactivate.Ref)

require.NoError(t, store.Add(create, txCreate))
require.NoError(t, store.Add(deactivate, txDeactivate))
require.NoError(t, store.Add(update, txUpdate))

t.Run("metadata ok", func(t *testing.T) {
err := store.db.ReadShelf(context.Background(), metadataShelf, func(reader stoabs.Reader) error {
for i := range []int{0, 1, 2} {
metaBytes, err := reader.Get(stoabs.BytesKey(fmt.Sprintf("%s%d", testDID.String(), i)))
if err != nil {
return err
}
metadata := documentMetadata{}
err = json.Unmarshal(metaBytes, &metadata)
if err != nil {
return err
}
assert.Equal(t, i > 0, metadata.Deactivated, "document version %d", i)
}
return nil
})
require.NoError(t, err)
})

})
}

func TestStore_Resolve(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion vdr/didnuts/didstore/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ func applyEvent(tx stoabs.WriteTx, latestMetadata *documentMetadata, nextEvent e
if err != nil {
return nil, nil, fmt.Errorf("read document failed: %w", err)
}
// create nextMetadata based on this event and some defaults.
// For the initial DID document this does not change. (latestMetadata = nil)
// For DID updates, applyDocument will make changes.
nextMetadata := documentMetadata{
Created: nextEvent.SigningTime,
Updated: nextEvent.SigningTime,
Expand Down Expand Up @@ -231,6 +234,7 @@ func applyDocument(tx stoabs.ReadTx, currentMeta *documentMetadata, newDoc did.D
newMeta.Version = currentMeta.Version + 1
newMeta.Created = currentMeta.Created
newMeta.PreviousHash = &currentMeta.Hash
newMeta.Deactivated = newMeta.Deactivated || currentMeta.Deactivated // once deactivated is always deactivated

unconsumed := map[string]struct{}{}
outer:
Expand Down Expand Up @@ -268,7 +272,6 @@ outer:
newDocBytes, _ := json.Marshal(newDoc)

newMeta.Hash = hash.SHA256Sum(newDocBytes)
newMeta.Deactivated = isDeactivated(newDoc)

return newDoc, newMeta, nil
}
Expand Down

0 comments on commit 16975d9

Please sign in to comment.