allouis / lamport-ots Goto Github PK
View Code? Open in Web Editor NEW๐ Lamport One-Time Signatures in JavaScript ๐
License: Mozilla Public License 2.0
๐ Lamport One-Time Signatures in JavaScript ๐
License: Mozilla Public License 2.0
Hey! Thanks so much for making this awesome library. It does exactly what's needed without any fluff.
I'm in a situation where I want to give the public key and signature to someone as a string and then allow them to use those strings to verify the message at a later date. Here's the code I have so far:
function isVerified(part, inputText) {
return lamportSHA256.verify(inputText, stringToUint8Array(part.signature), stringToPublicKey(part.publicKey));
}
function uint8ArrayToString(array) {
return JSON.stringify(Array.from(array));
}
function stringToUint8Array(arrayString) {
return new Uint8Array(JSON.parse(arrayString));
}
function publicKeyToString(publicKey) {
console.log("publicKeyToString");
const result = []
publicKey.forEach((keyArray) => {
result.push(uint8ArrayToString(keyArray));
})
return JSON.stringify(result)
}
function stringToPublicKey(pubKeyString) {
const stringList = JSON.parse(pubKeyString);
const result = [];
stringList.forEach((keyString) => {
result.push(stringToUint8Array(keyString));
})
return result;
}
function generateSignature(inputText) {
const {publicKey, privateKey} = lamportSHA256.keys();
const signature = lamportSHA256.sign(inputText, privateKey);
return {publicKey: publicKeyToString(publicKey), signature: uint8ArrayToString(signature)};
}
However, I keep getting this error:
TypeError: readChunk(...).equals is not a function
verify/<
node_modules/lamport-ots/index.js:63
60 | const verify = (input, sig, key) => {
61 | const msg = hash(input)
62 | return bitsForBuffer(msg).reduce((valid, bit, idx) => {
> 63 | return valid && readChunk(key[bit], idx).equals(
| ^ 64 | hash(readChunk(sig, idx))
65 | )
66 | }, true)
verify
node_modules/lamport-ots/index.js:62
59 |
60 | const verify = (input, sig, key) => {
61 | const msg = hash(input)
> 62 | return bitsForBuffer(msg).reduce((valid, bit, idx) => {
| ^ 63 | return valid && readChunk(key[bit], idx).equals(
64 | hash(readChunk(sig, idx))
65 | )
isVerified
src/utils/cryptography.js:8
5 | // try {
6 | const pk = stringToPublicKey(part.validationData.publicKey)
7 | console.log(pk);
> 8 | return lamportSHA256.verify(inputText, stringToUint8Array(part.validationData.signature), pk);
| ^ 9 | // } catch {
10 | // return false;
11 | // }
I'm not sure what I'm missing. When I switch to not converting to a string and back, it all works seamlessly. Even converting just the signature to a string and back seems to work fine. It's just the public key I'm struggling with. Maybe it's not actually an array of uint8Arrays? Would love some guidance here.
Thanks so much!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.