Skip to content

Commit 2bdd5fa

Browse files
authored
feat(ipfs): add export and import key (#847)
1 parent 0a4eb3b commit 2bdd5fa

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

packages/clients/src/api/ipfs/v1alpha1/api.gen.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import {
1414
marshalCreatePinByCIDRequest,
1515
marshalCreatePinByURLRequest,
1616
marshalCreateVolumeRequest,
17+
marshalImportKeyNameRequest,
1718
marshalReplacePinRequest,
1819
marshalUpdateNameRequest,
1920
marshalUpdateVolumeRequest,
21+
unmarshalExportKeyNameResponse,
2022
unmarshalListNamesResponse,
2123
unmarshalListPinsResponse,
2224
unmarshalListVolumesResponse,
@@ -33,9 +35,12 @@ import type {
3335
DeleteNameRequest,
3436
DeletePinRequest,
3537
DeleteVolumeRequest,
38+
ExportKeyNameRequest,
39+
ExportKeyNameResponse,
3640
GetNameRequest,
3741
GetPinRequest,
3842
GetVolumeRequest,
43+
ImportKeyNameRequest,
3944
ListNamesRequest,
4045
ListNamesResponse,
4146
ListPinsRequest,
@@ -435,4 +440,32 @@ export class API extends ParentAPI {
435440
},
436441
unmarshalName,
437442
)
443+
444+
exportKeyName = (request: Readonly<ExportKeyNameRequest>) =>
445+
this.client.fetch<ExportKeyNameResponse>(
446+
{
447+
method: 'GET',
448+
path: `/ipfs/v1alpha1/regions/${validatePathParam(
449+
'region',
450+
request.region ?? this.client.settings.defaultRegion,
451+
)}/names/export-key/${validatePathParam('nameId', request.nameId)}`,
452+
},
453+
unmarshalExportKeyNameResponse,
454+
)
455+
456+
importKeyName = (request: Readonly<ImportKeyNameRequest>) =>
457+
this.client.fetch<Name>(
458+
{
459+
body: JSON.stringify(
460+
marshalImportKeyNameRequest(request, this.client.settings),
461+
),
462+
headers: jsonContentHeaders,
463+
method: 'POST',
464+
path: `/ipfs/v1alpha1/regions/${validatePathParam(
465+
'region',
466+
request.region ?? this.client.settings.defaultRegion,
467+
)}/names/import-key`,
468+
},
469+
unmarshalName,
470+
)
438471
}

packages/clients/src/api/ipfs/v1alpha1/index.gen.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ export type {
1010
DeleteNameRequest,
1111
DeletePinRequest,
1212
DeleteVolumeRequest,
13+
ExportKeyNameRequest,
14+
ExportKeyNameResponse,
1315
GetNameRequest,
1416
GetPinRequest,
1517
GetVolumeRequest,
18+
ImportKeyNameRequest,
1619
ListNamesRequest,
1720
ListNamesRequestOrderBy,
1821
ListNamesResponse,

packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type {
1111
CreatePinByCIDRequest,
1212
CreatePinByURLRequest,
1313
CreateVolumeRequest,
14+
ExportKeyNameResponse,
15+
ImportKeyNameRequest,
1416
ListNamesResponse,
1517
ListPinsResponse,
1618
ListVolumesResponse,
@@ -125,6 +127,23 @@ export const unmarshalVolume = (data: unknown) => {
125127
} as Volume
126128
}
127129

130+
export const unmarshalExportKeyNameResponse = (data: unknown) => {
131+
if (!isJSONObject(data)) {
132+
throw new TypeError(
133+
`Unmarshalling the type 'ExportKeyNameResponse' failed as data isn't a dictionary.`,
134+
)
135+
}
136+
137+
return {
138+
createdAt: unmarshalDate(data.created_at),
139+
nameId: data.name_id,
140+
privateKey: data.private_key,
141+
projectId: data.project_id,
142+
publicKey: data.public_key,
143+
updatedAt: unmarshalDate(data.updated_at),
144+
} as ExportKeyNameResponse
145+
}
146+
128147
export const unmarshalListNamesResponse = (data: unknown) => {
129148
if (!isJSONObject(data)) {
130149
throw new TypeError(
@@ -226,6 +245,15 @@ export const marshalCreateVolumeRequest = (
226245
project_id: request.projectId ?? defaults.defaultProjectId,
227246
})
228247

248+
export const marshalImportKeyNameRequest = (
249+
request: ImportKeyNameRequest,
250+
defaults: DefaultValues,
251+
): Record<string, unknown> => ({
252+
name: request.name,
253+
private_key: request.privateKey,
254+
project_id: request.projectId ?? defaults.defaultProjectId,
255+
})
256+
229257
export const marshalReplacePinRequest = (
230258
request: ReplacePinRequest,
231259
defaults: DefaultValues,

packages/clients/src/api/ipfs/v1alpha1/types.gen.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ export type PinStatus =
4545
| 'failed'
4646
| 'pinned'
4747

48+
export interface ExportKeyNameResponse {
49+
nameId: string
50+
projectId: string
51+
createdAt?: Date
52+
updatedAt?: Date
53+
publicKey: string
54+
privateKey: string
55+
}
56+
4857
export interface ListNamesResponse {
4958
names: Name[]
5059
totalCount: number
@@ -299,3 +308,23 @@ export type UpdateNameRequest = {
299308
tags?: string[]
300309
cid?: string
301310
}
311+
312+
export type ExportKeyNameRequest = {
313+
/**
314+
* Region to target. If none is passed will use default region from the
315+
* config.
316+
*/
317+
region?: Region
318+
nameId: string
319+
}
320+
321+
export type ImportKeyNameRequest = {
322+
/**
323+
* Region to target. If none is passed will use default region from the
324+
* config.
325+
*/
326+
region?: Region
327+
projectId?: string
328+
name: string
329+
privateKey: string
330+
}

0 commit comments

Comments
 (0)