Skip to content

Commit 7ccc2ad

Browse files
committed
UW Profile/VIAt Wallet Updates dedicated encryption middleware
1 parent a5dcf56 commit 7ccc2ad

File tree

4 files changed

+4990
-26
lines changed

4 files changed

+4990
-26
lines changed

UWProfile/index.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ import {
55
isString
66
} from '@universalweb/acid';
77
import { decode, encode } from '#utilities/serialize';
8+
import {
9+
getDilithiumPrivateKey,
10+
getDilithiumPublicKey,
11+
getEd25519PrivateKey,
12+
getEd25519PublicKey,
13+
sign,
14+
signatureKeypair,
15+
verifySignature
16+
} from '../utilities/cryptoMiddleware/dilithium44_ed25519.js';
817
import { keychainGet, keychainSave } from '../utilities/certificate/keychain.js';
918
import { read, readStructured, write } from '../utilities/file.js';
1019
import { blake3 } from '@noble/hashes/blake3';
1120
import { currentCertificateVersion } from '../defaults.js';
12-
import { dilithium44 } from '../utilities/cryptoMiddleware/dilithium44.js';
13-
import { ed25519 } from '../utilities/cryptoMiddleware/ed25519.js';
1421
import { x25519_kyber768Half_xchacha20 } from '../utilities/cryptoMiddleware/x25519_Kyber768Half_xChaCha.js';
1522
const defaultEncryptionAlgorithm = 1;
1623
const defaultSignatureAlgorithm = 1;
@@ -53,11 +60,9 @@ export class UWProfile {
5360
}
5461
async generateSignatureKeypair() {
5562
this.version = currentCertificateVersion;
56-
const ed25519NewKeypair = await ed25519.signatureKeypair();
57-
const dilithiumNewKeypair = await dilithium44.signatureKeypair();
58-
console.log(ed25519NewKeypair.publicKey, ed25519NewKeypair.privateKey);
59-
this.publicKey = Buffer.concat([ed25519NewKeypair.publicKey, dilithiumNewKeypair.publicKey]);
60-
this.privateKey = Buffer.concat([ed25519NewKeypair.privateKey, dilithiumNewKeypair.privateKey]);
63+
await signatureKeypair(this);
64+
console.log(this.publicKey, this.privateKey);
65+
return this;
6166
}
6267
async generateEncryptionKeypair() {
6368
const encryptionkeypair = await x25519_kyber768Half_xchacha20.keypair();
@@ -68,32 +73,23 @@ export class UWProfile {
6873
await this.generateEncryptionKeypair();
6974
}
7075
get ed25519PublicKey() {
71-
return this.publicKey.slice(0, 32);
76+
return getEd25519PublicKey(this.publicKey);
7277
}
7378
get ed25519PrivateKey() {
74-
return this.privateKey.slice(0, 64);
79+
return getEd25519PrivateKey(this.privateKey);
7580
}
7681
get dilithiumPublicKey() {
77-
return this.publicKey.slice(32);
82+
return getDilithiumPublicKey(this.publicKey);
7883
}
7984
get dilithiumPrivateKey() {
80-
return this.privateKey.slice(64);
85+
return getDilithiumPrivateKey(this.privateKey);
8186
}
8287
async sign(message) {
83-
const ed25519Signature = await ed25519.signDetached(message, this.ed25519PrivateKey);
84-
console.log(ed25519Signature.length);
85-
const dilithiumSignature = await dilithium44.sign(message, this.dilithiumPrivateKey);
86-
console.log(dilithiumSignature.length);
87-
const signature = Buffer.concat([ed25519Signature, dilithiumSignature]);
88+
const signature = await sign(message, this.privateKey);
8889
return signature;
8990
}
9091
async verifySignature(signature, message) {
91-
const ed25519Signature = signature.slice(0, 64);
92-
const dilithiumSignature = signature.slice(64);
93-
const ed25519Verify = ed25519.verifySignatureDetached(ed25519Signature, this.ed25519PublicKey, message);
94-
const dilithiumVerify = await dilithium44.verifySignature(dilithiumSignature, this.dilithiumPublicKey, message);
95-
console.log(ed25519Verify, dilithiumVerify);
96-
return (ed25519Verify === dilithiumVerify) ? ed25519Verify : false;
92+
return verifySignature(signature, message, this.publicKey);
9793
}
9894
async hash(message) {
9995
const hashedMessage = blake3(message);

0 commit comments

Comments
 (0)