summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/internal')
-rw-r--r--ext/node/polyfills/internal/crypto/diffiehellman.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/ext/node/polyfills/internal/crypto/diffiehellman.ts b/ext/node/polyfills/internal/crypto/diffiehellman.ts
index da7907734..6058433ba 100644
--- a/ext/node/polyfills/internal/crypto/diffiehellman.ts
+++ b/ext/node/polyfills/internal/crypto/diffiehellman.ts
@@ -9,6 +9,7 @@ import {
op_node_dh_generate2,
op_node_ecdh_compute_public_key,
op_node_ecdh_compute_secret,
+ op_node_ecdh_encode_pubkey,
op_node_ecdh_generate_keys,
op_node_gen_prime,
} from "ext:core/ops";
@@ -1239,7 +1240,7 @@ export class ECDH {
format: ECDHKeyFormat = "uncompressed",
): Buffer | string {
this.#pubbuf = Buffer.alloc(
- format.trim() == "compressed"
+ format == "compressed"
? this.#curve.publicKeySizeCompressed
: this.#curve.publicKeySize,
);
@@ -1269,12 +1270,17 @@ export class ECDH {
getPublicKey(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
getPublicKey(
encoding?: BinaryToTextEncoding,
- _format?: ECDHKeyFormat,
+ format: ECDHKeyFormat = "uncompressed",
): Buffer | string {
+ const pubbuf = Buffer.from(op_node_ecdh_encode_pubkey(
+ this.#curve.name,
+ this.#pubbuf,
+ format == "compressed",
+ ));
if (encoding !== undefined) {
- return this.#pubbuf.toString(encoding);
+ return pubbuf.toString(encoding);
}
- return this.#pubbuf;
+ return pubbuf;
}
setPrivateKey(privateKey: ArrayBufferView): void;