This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: store document ID as a part of the document
* Store Document ID as a part of the document
- Loading branch information
Konstantin Shuplenkov
authored
Mar 3, 2020
1 parent
b13a9bb
commit 3d10a01
Showing
13 changed files
with
218 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const bs58 = require('bs58'); | ||
|
||
const hash = require('../util/hash'); | ||
|
||
/** | ||
* Generates document ID | ||
* | ||
* @param {string} contractId | ||
* @param {string} ownerId | ||
* @param {string} type | ||
* @param {string} entropy | ||
* @returns {string} | ||
*/ | ||
function generateDocumentId(contractId, ownerId, type, entropy) { | ||
return bs58.encode( | ||
hash(Buffer.concat([ | ||
bs58.decode(contractId), | ||
bs58.decode(ownerId), | ||
Buffer.from(type), | ||
bs58.decode(entropy), | ||
])), | ||
); | ||
} | ||
|
||
module.exports = generateDocumentId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const ConsensusError = require('./ConsensusError'); | ||
|
||
class InvalidDocumentIdError extends ConsensusError { | ||
/** | ||
* @param {RawDocument} rawDocument | ||
*/ | ||
constructor(rawDocument) { | ||
super('Invalid Document ID'); | ||
|
||
this.rawDocument = rawDocument; | ||
} | ||
|
||
/** | ||
* Get raw Document | ||
* | ||
* @return {RawDocument} | ||
*/ | ||
getRawDocument() { | ||
return this.rawDocument; | ||
} | ||
} | ||
|
||
module.exports = InvalidDocumentIdError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.