mirror of https://codeberg.org/pzp/pzp-keypair.git
fix KeypairPublicSlice type
This commit is contained in:
parent
2f829a14f0
commit
6b8b96bd51
|
@ -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
|
||||||
|
|
|
@ -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])
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue