Skip to content

Commit

Permalink
fix(key/gen): use correct key type casing (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki authored Feb 13, 2023
1 parent 1f382e7 commit 8b24a94
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/key/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions src/key/gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
2 changes: 1 addition & 1 deletion src/key/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
5 changes: 2 additions & 3 deletions src/key/index.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
13 changes: 0 additions & 13 deletions src/key/info.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/key/rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
29 changes: 29 additions & 0 deletions src/key/types.ts
Original file line number Diff line number Diff line change
@@ -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<OptionExtension = {}> {
export: (name: string, password: string, options?: AbortOptions & OptionExtension) => Promise<string>
gen: (name: string, options?: GenOptions & OptionExtension) => Promise<Key>
import: (name: string, pem: string, password: string, options?: AbortOptions & OptionExtension) => Promise<Key>
list: (options?: AbortOptions & OptionExtension) => Promise<Key[]>
rename: (oldName: string, newName: string, options?: AbortOptions & OptionExtension) => Promise<RenameKeyResult>
rm: (name: string, options?: AbortOptions & OptionExtension) => Promise<Key>
}

0 comments on commit 8b24a94

Please sign in to comment.