Skip to content

feat(ipfs): add export and import key #847

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

Merged
merged 1 commit into from
Sep 8, 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
33 changes: 33 additions & 0 deletions packages/clients/src/api/ipfs/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import {
marshalCreatePinByCIDRequest,
marshalCreatePinByURLRequest,
marshalCreateVolumeRequest,
marshalImportKeyNameRequest,
marshalReplacePinRequest,
marshalUpdateNameRequest,
marshalUpdateVolumeRequest,
unmarshalExportKeyNameResponse,
unmarshalListNamesResponse,
unmarshalListPinsResponse,
unmarshalListVolumesResponse,
Expand All @@ -33,9 +35,12 @@ import type {
DeleteNameRequest,
DeletePinRequest,
DeleteVolumeRequest,
ExportKeyNameRequest,
ExportKeyNameResponse,
GetNameRequest,
GetPinRequest,
GetVolumeRequest,
ImportKeyNameRequest,
ListNamesRequest,
ListNamesResponse,
ListPinsRequest,
Expand Down Expand Up @@ -435,4 +440,32 @@ export class API extends ParentAPI {
},
unmarshalName,
)

exportKeyName = (request: Readonly<ExportKeyNameRequest>) =>
this.client.fetch<ExportKeyNameResponse>(
{
method: 'GET',
path: `/ipfs/v1alpha1/regions/${validatePathParam(
'region',
request.region ?? this.client.settings.defaultRegion,
)}/names/export-key/${validatePathParam('nameId', request.nameId)}`,
},
unmarshalExportKeyNameResponse,
)

importKeyName = (request: Readonly<ImportKeyNameRequest>) =>
this.client.fetch<Name>(
{
body: JSON.stringify(
marshalImportKeyNameRequest(request, this.client.settings),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/ipfs/v1alpha1/regions/${validatePathParam(
'region',
request.region ?? this.client.settings.defaultRegion,
)}/names/import-key`,
},
unmarshalName,
)
}
3 changes: 3 additions & 0 deletions packages/clients/src/api/ipfs/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ export type {
DeleteNameRequest,
DeletePinRequest,
DeleteVolumeRequest,
ExportKeyNameRequest,
ExportKeyNameResponse,
GetNameRequest,
GetPinRequest,
GetVolumeRequest,
ImportKeyNameRequest,
ListNamesRequest,
ListNamesRequestOrderBy,
ListNamesResponse,
Expand Down
28 changes: 28 additions & 0 deletions packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {
CreatePinByCIDRequest,
CreatePinByURLRequest,
CreateVolumeRequest,
ExportKeyNameResponse,
ImportKeyNameRequest,
ListNamesResponse,
ListPinsResponse,
ListVolumesResponse,
Expand Down Expand Up @@ -125,6 +127,23 @@ export const unmarshalVolume = (data: unknown) => {
} as Volume
}

export const unmarshalExportKeyNameResponse = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'ExportKeyNameResponse' failed as data isn't a dictionary.`,
)
}

return {
createdAt: unmarshalDate(data.created_at),
nameId: data.name_id,
privateKey: data.private_key,
projectId: data.project_id,
publicKey: data.public_key,
updatedAt: unmarshalDate(data.updated_at),
} as ExportKeyNameResponse
}

export const unmarshalListNamesResponse = (data: unknown) => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -226,6 +245,15 @@ export const marshalCreateVolumeRequest = (
project_id: request.projectId ?? defaults.defaultProjectId,
})

export const marshalImportKeyNameRequest = (
request: ImportKeyNameRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
name: request.name,
private_key: request.privateKey,
project_id: request.projectId ?? defaults.defaultProjectId,
})

export const marshalReplacePinRequest = (
request: ReplacePinRequest,
defaults: DefaultValues,
Expand Down
29 changes: 29 additions & 0 deletions packages/clients/src/api/ipfs/v1alpha1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ export type PinStatus =
| 'failed'
| 'pinned'

export interface ExportKeyNameResponse {
nameId: string
projectId: string
createdAt?: Date
updatedAt?: Date
publicKey: string
privateKey: string
}

export interface ListNamesResponse {
names: Name[]
totalCount: number
Expand Down Expand Up @@ -299,3 +308,23 @@ export type UpdateNameRequest = {
tags?: string[]
cid?: string
}

export type ExportKeyNameRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
nameId: string
}

export type ImportKeyNameRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
projectId?: string
name: string
privateKey: string
}