From 8b24a94a1683922778e0fe212ac49d2a5cc62c7e Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 13 Feb 2023 00:43:07 -0800 Subject: [PATCH] fix(key/gen): use correct key type casing (#145) --- src/key/export.js | 2 +- src/key/gen.js | 6 +++--- src/key/import.js | 2 +- src/key/index.js | 5 ++--- src/key/info.js | 13 ------------- src/key/rename.js | 2 +- src/key/types.ts | 29 +++++++++++++++++++++++++++++ 7 files changed, 37 insertions(+), 22 deletions(-) delete mode 100644 src/key/info.js create mode 100644 src/key/types.ts diff --git a/src/key/export.js b/src/key/export.js index 132551328..09a3e64ce 100644 --- a/src/key/export.js +++ b/src/key/export.js @@ -3,7 +3,7 @@ import errCode from 'err-code' export const createExport = configure(api => { /** - * @type {import('../types').KeyAPI["export"]} + * @type {import('./types.js').KeyAPI['export']} */ const exportKey = async (name, password, options = {}) => { throw errCode(new Error('Not implemented'), 'ERR_NOT_IMPLEMENTED') diff --git a/src/key/gen.js b/src/key/gen.js index 18eaf08b5..d0b5e1b7d 100644 --- a/src/key/gen.js +++ b/src/key/gen.js @@ -2,14 +2,14 @@ import { objectToCamel } from '../lib/object-to-camel.js' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** @type {import('ipfs-core-types/src/key').GenOptions} */ +/** @type {import('./types.js').GenOptions} */ const defaultOptions = { - type: 'Ed25519' + type: 'ed25519' } export const createGen = configure(api => { /** - * @type {import('../types').KeyAPI["gen"]} + * @type {import('./types.js').KeyAPI['gen']} */ async function gen (name, options = defaultOptions) { const res = await api.post('key/gen', { diff --git a/src/key/import.js b/src/key/import.js index fc3f35bfe..035e17a4d 100644 --- a/src/key/import.js +++ b/src/key/import.js @@ -4,7 +4,7 @@ import { toUrlSearchParams } from '../lib/to-url-search-params.js' export const createImport = configure(api => { /** - * @type {import('../types').KeyAPI["import"]} + * @type {import('./types.js').KeyAPI['import']} */ async function importKey (name, pem, password, options = {}) { const res = await api.post('key/import', { diff --git a/src/key/index.js b/src/key/index.js index db7bb0839..648087334 100644 --- a/src/key/index.js +++ b/src/key/index.js @@ -1,20 +1,19 @@ import { createExport } from './export.js' import { createGen } from './gen.js' import { createImport } from './import.js' -import { createInfo } from './info.js' import { createList } from './list.js' import { createRename } from './rename.js' import { createRm } from './rm.js' /** - * @param {import('../types').Options} config + * @param {import('../types.js').Options} config + * @returns {import('./types.js').KeyAPI} */ export function createKey (config) { return { export: createExport(config), gen: createGen(config), import: createImport(config), - info: createInfo(config), list: createList(config), rename: createRename(config), rm: createRm(config) diff --git a/src/key/info.js b/src/key/info.js deleted file mode 100644 index 62d7529af..000000000 --- a/src/key/info.js +++ /dev/null @@ -1,13 +0,0 @@ -import { configure } from '../lib/configure.js' -import errCode from 'err-code' - -export const createInfo = configure(api => { - /** - * @type {import('../types').KeyAPI["info"]} - */ - const info = async (name, options = {}) => { - throw errCode(new Error('Not implemented'), 'ERR_NOT_IMPLEMENTED') - } - - return info -}) diff --git a/src/key/rename.js b/src/key/rename.js index c2397825f..ce2b0ddef 100644 --- a/src/key/rename.js +++ b/src/key/rename.js @@ -4,7 +4,7 @@ import { toUrlSearchParams } from '../lib/to-url-search-params.js' export const createRename = configure(api => { /** - * @type {import('../types').KeyAPI["rename"]} + * @type {import('./types.js').KeyAPI['rename']} */ async function rename (oldName, newName, options = {}) { const res = await api.post('key/rename', { diff --git a/src/key/types.ts b/src/key/types.ts new file mode 100644 index 000000000..2bed31961 --- /dev/null +++ b/src/key/types.ts @@ -0,0 +1,29 @@ +import type { AbortOptions } from '../types' + +export type KeyType = 'ed25519' | 'rsa' + +export interface Key { + id: string + name: string +} + +export interface GenOptions extends AbortOptions { + type: KeyType + size?: number +} + +export interface RenameKeyResult { + id: string + was: string + now: string + overwrite: boolean +} + +export interface KeyAPI { + export: (name: string, password: string, options?: AbortOptions & OptionExtension) => Promise + gen: (name: string, options?: GenOptions & OptionExtension) => Promise + import: (name: string, pem: string, password: string, options?: AbortOptions & OptionExtension) => Promise + list: (options?: AbortOptions & OptionExtension) => Promise + rename: (oldName: string, newName: string, options?: AbortOptions & OptionExtension) => Promise + rm: (name: string, options?: AbortOptions & OptionExtension) => Promise +}