-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Karim TAAM <karim.t2am@gmail.com> Co-authored-by: garyschulte <garyschulte@gmail.com>
- Loading branch information
1 parent
29021e8
commit 4ee5044
Showing
10 changed files
with
360 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Copyright Besu Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
plugins { | ||
id 'java-library' | ||
id 'maven-publish' | ||
id 'com.jfrog.artifactory' version '4.20.0' | ||
} | ||
|
||
dependencies { | ||
implementation 'net.java.dev.jna:jna:5.12.1' | ||
testImplementation 'net.java.dev.jna:jna:5.12.1' | ||
implementation 'org.apache.tuweni:tuweni-bytes:2.2.0' | ||
testImplementation 'junit:junit:4.13.2' | ||
testImplementation 'org.assertj:assertj-core:3.22.0' | ||
testImplementation 'org.mockito:mockito-core:4.4.0' | ||
} | ||
|
||
task macArmLibCopy(type: Copy) { | ||
from 'build/darwin-aarch64/lib/libmimc_jni.dylib' | ||
into 'build/resources/main/darwin-aarch64' | ||
} | ||
processResources.dependsOn macArmLibCopy | ||
|
||
task macLibCopy(type: Copy) { | ||
from 'build/darwin-x86-64/lib/libmimc_jni.dylib' | ||
into 'build/resources/main/darwin-x86-64' | ||
} | ||
processResources.dependsOn macLibCopy | ||
|
||
task linuxLibCopy(type: Copy) { | ||
from 'build/linux-gnu-x86_64/lib/libmimc_jni.so' | ||
into 'build/resources/main/linux-x86-64' | ||
} | ||
processResources.dependsOn linuxLibCopy | ||
|
||
task linuxArm64LibCopy(type: Copy) { | ||
from 'build/linux-gnu-aarch64/lib/libmimc_jni.so' | ||
into 'build/resources/main/linux-aarch64' | ||
} | ||
processResources.dependsOn linuxArm64LibCopy | ||
|
||
jar { | ||
archiveBaseName = 'besu-native-mimc' | ||
includeEmptyDirs = false | ||
manifest { | ||
attributes( | ||
'Specification-Title': archiveBaseName, | ||
'Specification-Version': project.version, | ||
'Implementation-Title': archiveBaseName, | ||
'Implementation-Version': project.version, | ||
'Automatic-Module-Name': 'org.hyperledger.besu.native.mimc' | ||
) | ||
} | ||
} | ||
|
||
task sourcesJar(type: Jar, dependsOn: classes) { | ||
archiveBaseName = 'besu-native-mimc' | ||
classifier = 'sources' | ||
from sourceSets.main.allSource | ||
} | ||
|
||
task javadocJar(type: Jar, dependsOn: javadoc) { | ||
archiveBaseName = 'besu-native-mimc' | ||
classifier = 'javadoc' | ||
from javadoc.destinationDir | ||
} | ||
|
||
|
||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
groupId "org.hyperledger.besu" | ||
artifactId "mimc" | ||
version "${project.version}" | ||
|
||
from components.java | ||
artifact sourcesJar | ||
artifact javadocJar | ||
|
||
pom { | ||
name = "Besu Native - ${project.name}" | ||
description = 'Mimc' | ||
url = 'http://github.com/hyperledger/besu-native' | ||
licenses { | ||
license { | ||
name = 'The Apache License, Version 2.0' | ||
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' | ||
} | ||
} | ||
scm { | ||
connection = 'scm:git:git://github.com/hyperledger/besu-native.git' | ||
developerConnection = 'scm:git:ssh://github.com/hyperledger/besu-native.git' | ||
url = 'https://github.com/hyperledger/besu-native' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
def artifactoryUser = project.hasProperty('artifactoryUser') ? project.property('artifactoryUser') : System.getenv('ARTIFACTORY_USER') | ||
def artifactoryKey = project.hasProperty('artifactoryApiKey') ? project.property('artifactoryApiKey') : System.getenv('ARTIFACTORY_KEY') | ||
def artifactoryRepo = System.getenv('ARTIFACTORY_REPO') ?: 'besu-maven' | ||
def artifactoryOrg = System.getenv('ARTIFACTORY_ORG') ?: 'hyperledger' | ||
|
||
artifactory { | ||
contextUrl = "https://hyperledger.jfrog.io/${artifactoryOrg}" | ||
publish { | ||
repository { | ||
repoKey = artifactoryRepo | ||
username = artifactoryUser | ||
password = artifactoryKey | ||
} | ||
defaults { | ||
publications('mavenJava') | ||
publishArtifacts = true | ||
publishPom = true | ||
} | ||
} | ||
} |
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,10 @@ | ||
module github.com/hyperledger/besu-native | ||
|
||
go 1.18 | ||
|
||
require github.com/consensys/gnark-crypto v0.9.1 | ||
|
||
require ( | ||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect | ||
golang.org/x/sys v0.2.0 // indirect | ||
) |
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,6 @@ | ||
github.com/consensys/gnark-crypto v0.9.1 h1:mru55qKdWl3E035hAoh1jj9d7hVnYY5pfb6tmovSmII= | ||
github.com/consensys/gnark-crypto v0.9.1/go.mod h1:a2DQL4+5ywF6safEeZFEPGRiiGbjzGFRUN2sg06VuU4= | ||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c= | ||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= | ||
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= | ||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
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,27 @@ | ||
package main | ||
|
||
|
||
|
||
import "C" | ||
import "unsafe" | ||
import ( | ||
"github.com/consensys/gnark-crypto/ecc/bn254/fr/mimc" | ||
) | ||
|
||
func MiMCHash(b []byte) []byte { | ||
hasher := mimc.NewMiMC() | ||
hasher.Write(b) | ||
return hasher.Sum(nil) | ||
} | ||
|
||
|
||
//export compute | ||
func compute(input *C.char, inputLength C.int, output *C.char) C.int { | ||
inputSlice := C.GoBytes(unsafe.Pointer(input), inputLength) | ||
outputSlice := (*[32]byte)(unsafe.Pointer(output))[:] | ||
hash := MiMCHash(inputSlice) | ||
copy(outputSlice, hash) | ||
return C.int(len(hash)) | ||
} | ||
|
||
func main() {} |
Oops, something went wrong.