fix KeypairPublicSlice type

This commit is contained in:
Andre Staltz 2023-06-25 17:09:29 +03:00
parent 2f829a14f0
commit 6b8b96bd51
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 9 additions and 9 deletions

View File

@ -5,8 +5,10 @@ const base58 = require('bs58')
/** /**
* @typedef {import('.').Keypair} Keypair * @typedef {import('.').Keypair} Keypair
* @typedef {import('.').Curve} Curve
* @typedef {import('.').KeypairPublicSlice} KeypairPublicSlice * @typedef {import('.').KeypairPublicSlice} KeypairPublicSlice
* @typedef {import('.').KeypairPrivateSlice} KeypairPrivateSlice * @typedef {import('.').KeypairPrivateSlice} KeypairPrivateSlice
*
* @typedef {Buffer | Uint8Array} B4A * @typedef {Buffer | Uint8Array} B4A
*/ */
@ -14,6 +16,7 @@ const SEEDBYTES = sodium.crypto_sign_SEEDBYTES
const PUBLICKEYBYTES = sodium.crypto_sign_PUBLICKEYBYTES const PUBLICKEYBYTES = sodium.crypto_sign_PUBLICKEYBYTES
const SECRETKEYBYTES = sodium.crypto_sign_SECRETKEYBYTES const SECRETKEYBYTES = sodium.crypto_sign_SECRETKEYBYTES
/** @type {Curve} */
const ed25519 = { const ed25519 = {
/** /**
* @param {(string | B4A)=} seed * @param {(string | B4A)=} seed

View File

@ -17,31 +17,28 @@ const curves = {
* _private?: B4A, * _private?: B4A,
* }} Keypair * }} Keypair
* *
* @typedef {(Pick<Keypair, 'curve' | 'public'> & {_public: never}) | * @typedef {Pick<Keypair, 'curve' | 'public' | '_public'>} KeypairPublicSlice
* (Pick<Keypair, 'curve' | '_public'> & {public: never})
* } KeypairPublicSlice
* *
* @typedef {(Pick<Keypair, 'curve' | 'private'> & {_private: never}) | * @typedef {Pick<Keypair, 'curve' | 'private' | '_private'>} KeypairPrivateSlice
* (Pick<Keypair, 'curve' | '_private'> & {private: never})
* } KeypairPrivateSlice
* *
* @typedef {{ * @typedef {{
* generate: (seed?: B4A | string) => Keypair, * generate: (seed?: B4A | string) => Keypair,
* toJSON: (keypair: Keypair, opts?: {indented?: boolean}) => string, * toJSON: (keypair: Keypair, opts?: {indented?: boolean}) => string,
* sign: (keypair: KeypairPrivateSlice, message: B4A) => B4A, * sign: (keypair: KeypairPrivateSlice, message: B4A) => string,
* verify: (keypair: KeypairPublicSlice, message: B4A, sig: B4A) => boolean, * verify: (keypair: KeypairPublicSlice, sig: string, message: B4A) => boolean,
* }} Curve * }} Curve
*/ */
/** /**
* @param {CurveName} curveName * @param {CurveName} curveName
* @returns {Curve}
*/ */
function getCurve(curveName) { function getCurve(curveName) {
if (!curves[curveName]) { if (!curves[curveName]) {
// prettier-ignore // prettier-ignore
throw new Error(`Unknown curve "${curveName}" out of available "${Object.keys(curves).join(',')}"`) throw new Error(`Unknown curve "${curveName}" out of available "${Object.keys(curves).join(',')}"`)
} }
return curves[curveName] return /** @type {Curve} */ (curves[curveName])
} }
/** /**