@@ -5,12 +5,19 @@ import {
5
5
isString
6
6
} from '@universalweb/acid' ;
7
7
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' ;
8
17
import { keychainGet , keychainSave } from '../utilities/certificate/keychain.js' ;
9
18
import { read , readStructured , write } from '../utilities/file.js' ;
10
19
import { blake3 } from '@noble/hashes/blake3' ;
11
20
import { currentCertificateVersion } from '../defaults.js' ;
12
- import { dilithium44 } from '../utilities/cryptoMiddleware/dilithium44.js' ;
13
- import { ed25519 } from '../utilities/cryptoMiddleware/ed25519.js' ;
14
21
import { x25519_kyber768Half_xchacha20 } from '../utilities/cryptoMiddleware/x25519_Kyber768Half_xChaCha.js' ;
15
22
const defaultEncryptionAlgorithm = 1 ;
16
23
const defaultSignatureAlgorithm = 1 ;
@@ -53,11 +60,9 @@ export class UWProfile {
53
60
}
54
61
async generateSignatureKeypair ( ) {
55
62
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 ;
61
66
}
62
67
async generateEncryptionKeypair ( ) {
63
68
const encryptionkeypair = await x25519_kyber768Half_xchacha20 . keypair ( ) ;
@@ -68,32 +73,23 @@ export class UWProfile {
68
73
await this . generateEncryptionKeypair ( ) ;
69
74
}
70
75
get ed25519PublicKey ( ) {
71
- return this . publicKey . slice ( 0 , 32 ) ;
76
+ return getEd25519PublicKey ( this . publicKey ) ;
72
77
}
73
78
get ed25519PrivateKey ( ) {
74
- return this . privateKey . slice ( 0 , 64 ) ;
79
+ return getEd25519PrivateKey ( this . privateKey ) ;
75
80
}
76
81
get dilithiumPublicKey ( ) {
77
- return this . publicKey . slice ( 32 ) ;
82
+ return getDilithiumPublicKey ( this . publicKey ) ;
78
83
}
79
84
get dilithiumPrivateKey ( ) {
80
- return this . privateKey . slice ( 64 ) ;
85
+ return getDilithiumPrivateKey ( this . privateKey ) ;
81
86
}
82
87
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 ) ;
88
89
return signature ;
89
90
}
90
91
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 ) ;
97
93
}
98
94
async hash ( message ) {
99
95
const hashedMessage = blake3 ( message ) ;
0 commit comments