From 6b8b96bd511647a1902c37db02d10c6468841876 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Sun, 25 Jun 2023 17:09:29 +0300 Subject: [PATCH] fix KeypairPublicSlice type --- lib/curves/ed25519.js | 3 +++ lib/curves/index.js | 15 ++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/curves/ed25519.js b/lib/curves/ed25519.js index 4a482e2..e6b4077 100644 --- a/lib/curves/ed25519.js +++ b/lib/curves/ed25519.js @@ -5,8 +5,10 @@ const base58 = require('bs58') /** * @typedef {import('.').Keypair} Keypair + * @typedef {import('.').Curve} Curve * @typedef {import('.').KeypairPublicSlice} KeypairPublicSlice * @typedef {import('.').KeypairPrivateSlice} KeypairPrivateSlice + * * @typedef {Buffer | Uint8Array} B4A */ @@ -14,6 +16,7 @@ const SEEDBYTES = sodium.crypto_sign_SEEDBYTES const PUBLICKEYBYTES = sodium.crypto_sign_PUBLICKEYBYTES const SECRETKEYBYTES = sodium.crypto_sign_SECRETKEYBYTES +/** @type {Curve} */ const ed25519 = { /** * @param {(string | B4A)=} seed diff --git a/lib/curves/index.js b/lib/curves/index.js index c572ff3..cb60a4f 100644 --- a/lib/curves/index.js +++ b/lib/curves/index.js @@ -17,31 +17,28 @@ const curves = { * _private?: B4A, * }} Keypair * - * @typedef {(Pick & {_public: never}) | - * (Pick & {public: never}) - * } KeypairPublicSlice + * @typedef {Pick} KeypairPublicSlice * - * @typedef {(Pick & {_private: never}) | - * (Pick & {private: never}) - * } KeypairPrivateSlice + * @typedef {Pick} KeypairPrivateSlice * * @typedef {{ * generate: (seed?: B4A | string) => Keypair, * toJSON: (keypair: Keypair, opts?: {indented?: boolean}) => string, - * sign: (keypair: KeypairPrivateSlice, message: B4A) => B4A, - * verify: (keypair: KeypairPublicSlice, message: B4A, sig: B4A) => boolean, + * sign: (keypair: KeypairPrivateSlice, message: B4A) => string, + * verify: (keypair: KeypairPublicSlice, sig: string, message: B4A) => boolean, * }} Curve */ /** * @param {CurveName} curveName + * @returns {Curve} */ function getCurve(curveName) { if (!curves[curveName]) { // prettier-ignore throw new Error(`Unknown curve "${curveName}" out of available "${Object.keys(curves).join(',')}"`) } - return curves[curveName] + return /** @type {Curve} */ (curves[curveName]) } /**