UNPKG

@peculiar/webcrypto

Version:
29 lines (28 loc) • 882 B
/** * Copyright (c) 2019-2026, Peculiar Ventures * SPDX-License-Identifier: MIT */ import { Ed25519CryptoKey } from "./crypto_key.js"; import * as core from "webcrypto-core"; import crypto from "node:crypto"; import { AsnConvert } from "@peculiar/asn1-schema"; import { pem } from "@peculiar/utils/pem"; // src/mechs/ed25519/private_key.ts var Ed25519PrivateKey = class extends Ed25519CryptoKey { type = "private"; toJWK() { const pubJwk = crypto.createPublicKey({ key: this.data, format: "pem" }).export({ format: "jwk" }); const raw = pem.decodeFirst(this.data.toString()); const pkcs8 = AsnConvert.parse(raw, core.asn1.PrivateKeyInfo); const d = AsnConvert.parse(pkcs8.privateKey, core.asn1.EdPrivateKey).value; return { ...super.toJWK(), ...pubJwk, d: Buffer.from(new Uint8Array(d)).toString("base64url") }; } }; export { Ed25519PrivateKey };