Skip to content

Commit

Permalink
chore(deps): export blake2b and ed25519 (#16)
Browse files Browse the repository at this point in the history
# Description

- What does this PR do?
Import ed25519 and blake2b from external repository
- Why are these changes needed?
We want to have as little js files (preferably just 1) which will be
imported.

Fixes LimeChain#527 

## Checklist:
- [x] I have read the [contributing
guidelines](https://github.com/LimeChain/Fruzhin/blob/dev/CONTRIBUTING.md).
- [x] My PR title matches the [Conventional Commits
spec](https://www.conventionalcommits.org/).
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
  • Loading branch information
ablax authored Sep 10, 2024
1 parent 1ffcd37 commit a82181a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 500 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static String getHandshake() {

@JSBody(params = {"handshake", "protocolId"}, script = "window.fruzhin.libp.getConnections().forEach(async (peer) => {" +
" let stream = await ItPbStream.pbStream(await window.fruzhin.libp.dialProtocol(peer.remotePeer, protocolId));" +
" stream.writeLP(window.fruzhin.ED25519.h2b(handshake));" +
" stream.writeLP(Ed25519.h2b(handshake));" +
"});")
public static native void sendHandshakeToAll(String handshake, String protocolId);

Expand All @@ -61,9 +61,9 @@ public static String getHandshake() {
" let subarr = msg.subarray();" +
" if(subarr.length === 69) {" +
" let handshake = announceExport.getHandshake();" +
" (await ItPbStream.pbStream(stream)).writeLP(window.fruzhin.ED25519.h2b(handshake));" +
" (await ItPbStream.pbStream(stream)).writeLP(Ed25519.h2b(handshake));" +
" } else if (subarr.length > 1) {" +
" announceExport.blockAnnounce(window.fruzhin.ED25519.b2h(subarr.slice(2)), connection.remotePeer.toString());" +
" announceExport.blockAnnounce(Ed25519.b2h(subarr.slice(2)), connection.remotePeer.toString());" +
" }" +
" }" +
" });" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static String getNeighbourMessage() {

@JSBody(params = {"handshake", "protocolId"}, script = "window.fruzhin.libp.getConnections().forEach(async (peer) => {" +
" let stream = await ItPbStream.pbStream(await window.fruzhin.libp.dialProtocol(peer.remotePeer, protocolId));" +
" stream.write(window.fruzhin.ED25519.h2b(handshake));" + "});")
" stream.write(Ed25519.h2b(handshake));" + "});")
public static native void sendHandshakeToAll(String handshake, String protocolId);

@JSBody(params = {"grandpaExport", "protocolId"}, script =
Expand All @@ -116,13 +116,13 @@ public static String getNeighbourMessage() {
" for await (const msg of source) {" + " let subarr = msg.subarray();" +
" if(subarr.length === 1) {" +
" let handshake = grandpaExport.getHandshake();" +
" (await ItPbStream.pbStream(stream)).writeLP(window.fruzhin.ED25519.h2b(handshake));" +
" (await ItPbStream.pbStream(stream)).writeLP(Ed25519.h2b(handshake));" +
" } else if (subarr.length > 1) {" +
" if(subarr.slice(1)[0] === 2) {" +
" let niehgbourMessage = grandpaExport.getNeighbourMessage();" +
" (await ItPbStream.pbStream(stream)).writeLP(window.fruzhin.ED25519.h2b(niehgbourMessage));" +
" (await ItPbStream.pbStream(stream)).writeLP(Ed25519.h2b(niehgbourMessage));" +
" }" +
" grandpaExport.handleMessage(window.fruzhin.ED25519.b2h(subarr.slice(1)), connection.remotePeer.toString());" +
" grandpaExport.handleMessage(Ed25519.b2h(subarr.slice(1)), connection.remotePeer.toString());" +
" }" + " }" + " });" + " });")
public static native void registerHandler(JSObject grandpaExport, String protocolId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static byte[] getDataToVerify(Precommit precommit, BigInteger authoritie
}

@JSBody(params = {"publicKeyHex", "signatureHex",
"messageHex"}, script = "return window.fruzhin.ED25519.verifyAsync(signatureHex, messageHex, publicKeyHex);")
"messageHex"}, script = "return Ed25519.verifyAsync(signatureHex, messageHex, publicKeyHex);")
public static native JSPromise<JSBoolean> verifyAsync(String publicKeyHex, String signatureHex,
String messageHex);
}
2 changes: 1 addition & 1 deletion src/main/java/com/limechain/utils/HashUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class HashUtils {

@JSBody(params = {"inputHex"}, script = "{" +
"let bytes = new Uint8Array([...inputHex.matchAll(/../g)].map(m => parseInt(m[0], 16)));" +
"return window.fruzhin.Blake2b.hash(bytes,undefined,32);" + "}")
"return Blake2B.hash(bytes,undefined,32);" + "}")
public static native JSString hashWithBlake2b(String inputHex);
}
167 changes: 0 additions & 167 deletions src/main/webapp/js/blake2b.js

This file was deleted.

Loading

0 comments on commit a82181a

Please sign in to comment.