@@ -69,14 +69,16 @@ export class NamedGroup extends Enum {
6969 * @returns {Function } The key generation function.
7070 */
7171 get keyGen ( ) {
72+ if ( this . #keyGen) return this . #keyGen
7273 switch ( this . name ) {
73- case "SECP256R1" : return p256 ;
74- case "SECP384R1" : return p384 ;
75- case "SECP521R1" : return p521 ;
76- case "X25519 " : return x25519 ;
77- case "X448" : return x448 ;
78- default : return x25519 ;
74+ case "SECP256R1" : this . #keyGen = p256 ; break ;
75+ case "SECP384R1" : this . #keyGen = p384 ; break ;
76+ case "SECP521R1" : this . #keyGen = p521 ; break ;
77+ case "X448 " : this . #keyGen = x448 ; break ;
78+ case "X25519" :
79+ default : this . #keyGen = x25519 ; break ;
7980 }
81+ return this . #keyGen
8082 }
8183
8284 /**
@@ -90,16 +92,20 @@ export class NamedGroup extends Enum {
9092 return this . #privateKey
9193 }
9294
95+ set privateKey ( key ) { this . #privateKey = key }
96+
9397 /**
9498 * Gets the public key associated with the NamedGroup.
9599 *
96100 * @returns {Uint8Array } The public key.
97101 */
98- get publicKey ( ) {
99- if ( this . #publicKey) return this . #publicKey;
102+ get publicKey ( ) {
103+ if ( this . #publicKey) return this . #publicKey;
100104 this . #publicKey = this . keyGen ?. getPublicKey ( this . privateKey ) ;
101105 return this . #publicKey;
102- }
106+ }
107+
108+ set publicKey ( key ) { this . #publicKey = key }
103109
104110 /**
105111 * Computes the shared key with a peer's public key.
@@ -146,7 +152,7 @@ export class KeyExchange extends Constrained {
146152 * Represents a key share entry.
147153 */
148154export class KeyShareEntry extends Struct {
149-
155+
150156 static from ( array ) {
151157 const copy = Uint8Array . from ( array ) ;
152158 const group = NamedGroup . from ( copy . subarray ( 0 , 2 ) ) ;
0 commit comments