-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect signatures (+additional tests) (#48)
* Fix incorrect signatures * go back to initial screen
- Loading branch information
Showing
7 changed files
with
118 additions
and
21 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
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,20 @@ | ||
import blake from "blakejs"; | ||
|
||
const CID_PREFIX = Buffer.from([0x01, 0x71, 0xa0, 0xe4, 0x02, 0x20]); | ||
|
||
export function getCID(message) { | ||
const blakeCtx = blake.blake2bInit(32); | ||
blake.blake2bUpdate(blakeCtx, message); | ||
const hash = blake.blake2bFinal(blakeCtx); | ||
return Buffer.concat([CID_PREFIX, hash]); | ||
} | ||
|
||
export function getDigest(message) { | ||
// digest = blake2-256( prefix + blake2b-256(tx) ) | ||
|
||
const blakeCtx = blake.blake2bInit(32); | ||
blake.blake2bUpdate(blakeCtx, getCID(message)); | ||
return blake.blake2bFinal(blakeCtx); | ||
} | ||
|
||
module.exports = { getCID, getDigest }; |
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