Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(key/gen): use correct key type casing #145

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
}