From 53c284a1be8ccfc085b18e4e4bf21e4bf342094e Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 9 Feb 2023 13:45:32 -0800 Subject: [PATCH 1/2] fix(key/gen): use correct key type casing see https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-key-gen fixes https://github.com/ipfs/js-kubo-rpc-client/issues/143 --- src/key/gen.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/key/gen.js b/src/key/gen.js index 18eaf08b5..1859a957a 100644 --- a/src/key/gen.js +++ b/src/key/gen.js @@ -4,7 +4,7 @@ import { toUrlSearchParams } from '../lib/to-url-search-params.js' /** @type {import('ipfs-core-types/src/key').GenOptions} */ const defaultOptions = { - type: 'Ed25519' + type: 'ed25519' } export const createGen = configure(api => { From 386ed656ec958eccedaf5a6a50e53e5b5c6030d3 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 9 Feb 2023 14:07:33 -0800 Subject: [PATCH 2/2] chore: ensure RPC key api matches kubo docs --- src/key/export.js | 2 +- src/key/gen.js | 4 ++-- 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, 36 insertions(+), 21 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 1859a957a..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' } 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 +}