Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
fix: wrong operationHash doesnt match did
Browse files Browse the repository at this point in the history
  • Loading branch information
gjgd committed Dec 16, 2019
1 parent 45d30c7 commit 46d3a5c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions packages/element-lib/src/sidetree-v2/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ const payloadToHash = (payload) => {
};

const getDidUniqueSuffix = (operation) => {
const decodedPayload = decodeJson(operation.payload);
const header = decodeJson(operation.protected);
switch (header.operation) {
case 'create':
return payloadToHash(decodedPayload);
return payloadToHash(operation.payload);
case 'update':
case 'recover':
case 'delete':
return decodedPayload.didUniqueSuffix;
return decodeJson(operation.payload).didUniqueSuffix;
default:
throw Error(`Cannot extract didUniqueSuffixe from: ${operation}`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/element-lib/src/sidetree-v2/protocol/resolve.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable arrow-body-style */
const { payloadToHash, verifyOperationSignature } = require('../func');
const { verifyOperationSignature } = require('../func');
const { isDidDocumentModelValid, isKeyValid } = require('../validation');

const isSignatureValid = async (didDocument, operation) => {
Expand Down Expand Up @@ -32,7 +32,7 @@ const create = async (state, operation, lastValidOperation) => {
await isSignatureValid(originalDidDocument, operation);
return {
...operation.decodedOperationPayload,
id: `did:elem:${payloadToHash(operation.decodedOperationPayload)}`,
id: `did:elem:${operation.operationHash}`,
};
};

Expand Down

0 comments on commit 46d3a5c

Please sign in to comment.