This repository has been archived by the owner on Jun 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2,137 changed files
with
363,011 additions
and
199 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,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/ |
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,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; |
Oops, something went wrong.