Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
major reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed May 4, 2023
2 parents f01da04 + 8624771 commit c74fa1c
Show file tree
Hide file tree
Showing 2,137 changed files with 363,011 additions and 199 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ build/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/.gcloudignore
/.gcloudignore

# This file is generated by npm as part of the build so son't commit it
src/main/resources/static/freenetorg.js
55 changes: 47 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
import org.gradle.api.tasks.Exec
import org.gradle.api.tasks.Copy

plugins {
id("maven-publish")
Expand All @@ -24,18 +26,21 @@ dependencies {

implementation("com.google.guava:guava:31.1-jre")

implementation("io.kweb:kweb-core:1.3.5")
implementation("io.kweb:kweb-core:1.4.1")

implementation("org.slf4j:slf4j-simple:2.0.5")

implementation("com.google.cloud:google-cloud-firestore:3.7.4")
implementation("com.google.cloud:google-cloud-firestore:3.9.1")

implementation("com.github.mfornos:humanize-slim:1.2.2")

implementation("io.github.microutils:kotlin-logging-jvm:3.0.4")
implementation("io.github.microutils:kotlin-logging:4.0.0-beta-2")

implementation("com.google.cloud:google-cloud-logging-logback:0.127.10-alpha")

implementation("org.kohsuke:github-api:1.313")
implementation("org.jsoup:jsoup:1.16.1")

implementation("org.kohsuke:github-api:1.314")
constraints {
implementation("com.fasterxml.jackson.core:jackson-databind:2.14.0-rc2") {
because("""
Expand All @@ -45,10 +50,11 @@ dependencies {
}
}

implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-cio:$ktor_version")
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
implementation("org.bouncycastle:bcprov-jdk15on:1.70")
implementation("io.ktor:ktor-client-core-jvm:2.3.0")
implementation("io.ktor:ktor-client-cio-jvm:2.3.0")
implementation("io.ktor:ktor-client-content-negotiation:2.3.0")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.0")

testImplementation(platform("org.junit:junit-bom:5.9.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
Expand All @@ -69,5 +75,38 @@ tasks {
include("org.eclipse.jetty.http.HttpFieldPreEncoder")
}
}
}

////////////////
/// NPM tasks
////////////////

tasks.register<Exec>("npmBuild") {
// Specify the working directory for the task (the subdirectory containing the npm project)
workingDir("js_npm")

// Define the command to run (use "cmd" and "/c" on Windows, "sh" and "-c" on Unix-based systems)
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
commandLine("cmd", "/c", "npm run build")
} else {
commandLine("sh", "-c", "npm run build")
}
}

// Define a custom Gradle task named "copyJsFile"
tasks.register<Copy>("copyJsToResources") {
// Specify the source file to copy
from("js_npm/dist/freenetorg.js")
// Specify the destination directory
into("src/main/resources/static")
}

// Make the "copyJsFile" task depend on the "npmBuild" task
tasks.named("copyJsToResources") {
dependsOn("npmBuild")
}

// Make the standard Gradle "build" task depend on the "copyKeygenToResources" task
tasks.named("build") {
dependsOn("copyJsToResources")
}
16 changes: 16 additions & 0 deletions js_npm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# .gitignore for npm project

# Ignore the node_modules directory
node_modules/

# Ignore the .env file, which may contain sensitive environment variables
.env

# Ignore the npm debug log file
npm-debug.log

# Ignore the distribution directory (if applicable)
dist/

# Ignore any build artifacts (if applicable)
build/
76 changes: 76 additions & 0 deletions js_npm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const crypto = require('crypto');
const bip39 = require('bip39');
const BlindSignature = require('blind-signatures');

// Generate an RSA key pair for Bob
const Bob = {
key: BlindSignature.keyGeneration({ b: 2048 }), // b: key-length
blinded: null,
unblinded: null,
message: null,
};

function generateMnemonic() {
// Generate a random seed (256 bits).
const seedSize = 32; // 256 bits
const seed = crypto.randomBytes(seedSize);

// Generate a BIP39 mnemonic phrase from the seed.
const mnemonic = bip39.entropyToMnemonic(seed.toString('hex'));

// Set the text of the HTML element with ID "key_mnemonic" to the generated mnemonic.
document.getElementById('key_mnemonic').textContent = mnemonic;

// Alice wants Bob to sign a message without revealing its contents.
const Alice = {
message: seed.toString('hex'),
N: null,
E: null,
r: null,
signed: null,
unblinded: null,
};

// Alice gets N and E variables from Bob's key
Alice.N = Bob.key.keyPair.n.toString();
Alice.E = Bob.key.keyPair.e.toString();

// Alice blinds the message
const { blinded, r } = BlindSignature.blind({
message: Alice.message,
N: Alice.N,
E: Alice.E,
});
Alice.r = r;

// Bob signs the blinded message
const signed = BlindSignature.sign({
blinded: blinded,
key: Bob.key,
});

// Alice unblinds the signed message
const unblinded = BlindSignature.unblind({
signed: signed,
N: Alice.N,
r: Alice.r,
});
Alice.unblinded = unblinded;

// Alice verifies the signature
const result = BlindSignature.verify({
unblinded: Alice.unblinded,
N: Alice.N,
E: Alice.E,
message: Alice.message,
});
if (result) {
console.log('Alice: Signatures verify!');
} else {
console.log('Alice: Invalid signature');
}

return { seed: '0x' + seed.toString('hex'), mnemonic: mnemonic };
}

window.generateMnemonic = generateMnemonic;
Loading

0 comments on commit c74fa1c

Please sign in to comment.