@cubist-labs/cubesigner-sdk 0.1.26 → 0.1.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -33
- package/dist/src/ethers/index.d.ts +25 -5
- package/dist/src/ethers/index.js +58 -16
- package/dist/src/fido.d.ts +76 -0
- package/dist/src/fido.js +148 -0
- package/dist/src/index.d.ts +148 -35
- package/dist/src/index.js +320 -53
- package/dist/src/key.d.ts +64 -8
- package/dist/src/key.js +91 -19
- package/dist/src/org.d.ts +98 -9
- package/dist/src/org.js +144 -29
- package/dist/src/paginator.d.ts +76 -0
- package/dist/src/paginator.js +99 -0
- package/dist/src/role.d.ts +20 -8
- package/dist/src/role.js +7 -5
- package/dist/src/schema.d.ts +2395 -393
- package/dist/src/schema.js +1 -1
- package/dist/src/session/cognito_manager.d.ts +59 -0
- package/dist/src/session/cognito_manager.js +111 -0
- package/dist/src/session/session_manager.d.ts +15 -0
- package/dist/src/session/session_manager.js +21 -2
- package/dist/src/session/session_storage.js +1 -1
- package/dist/src/session/signer_session_manager.d.ts +24 -12
- package/dist/src/session/signer_session_manager.js +45 -20
- package/dist/src/signer_session.d.ts +136 -38
- package/dist/src/signer_session.js +187 -80
- package/dist/src/util.d.ts +20 -0
- package/dist/src/util.js +31 -2
- package/package.json +12 -7
- package/src/ethers/index.ts +88 -16
- package/src/fido.ts +166 -0
- package/src/index.ts +366 -77
- package/src/key.ts +112 -16
- package/src/org.ts +200 -37
- package/src/paginator.ts +122 -0
- package/src/role.ts +24 -11
- package/src/schema.ts +2458 -449
- package/src/session/{management_session_manager.ts → cognito_manager.ts} +13 -15
- package/src/session/session_manager.ts +25 -1
- package/src/session/session_storage.ts +1 -1
- package/src/session/signer_session_manager.ts +57 -27
- package/src/signer_session.ts +266 -89
- package/src/util.ts +41 -0
- package/src/session/oidc_session_manager.ts +0 -193
package/src/index.ts
CHANGED
|
@@ -1,49 +1,94 @@
|
|
|
1
1
|
import { envs, EnvInterface } from "./env";
|
|
2
|
-
import { components, Client } from "./client";
|
|
2
|
+
import { components, Client, paths } from "./client";
|
|
3
3
|
import { Org } from "./org";
|
|
4
|
-
import { JsonFileSessionStorage
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
ManagementSessionStorage,
|
|
10
|
-
} from "./session/management_session_manager";
|
|
11
|
-
import { OidcSessionManager, OidcSessionStorage } from "./session/oidc_session_manager";
|
|
4
|
+
import { JsonFileSessionStorage } from "./session/session_storage";
|
|
5
|
+
|
|
6
|
+
import { SignerSessionStorage, SignerSessionManager } from "./session/signer_session_manager";
|
|
7
|
+
import { AcceptedResponse, MfaRequestInfo, SignResponse, SignerSession } from "./signer_session";
|
|
8
|
+
import { CognitoSessionManager, CognitoSessionStorage } from "./session/cognito_manager";
|
|
12
9
|
import { assertOk, configDir } from "./util";
|
|
13
10
|
import * as path from "path";
|
|
11
|
+
import createClient from "openapi-fetch";
|
|
12
|
+
import { AddFidoChallenge, ApiAddFidoChallenge, PublicKeyCredential } from "./fido";
|
|
14
13
|
|
|
15
14
|
/** CubeSigner constructor options */
|
|
16
15
|
export interface CubeSignerOptions {
|
|
17
16
|
/** The environment to use */
|
|
18
17
|
env?: EnvInterface;
|
|
19
18
|
/** The management authorization token */
|
|
20
|
-
sessionMgr?:
|
|
19
|
+
sessionMgr?: CognitoSessionManager | SignerSessionManager;
|
|
20
|
+
/** Optional organization id */
|
|
21
|
+
orgId?: string;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export type UserInfo = components["schemas"]["UserInfo"];
|
|
24
25
|
export type TotpInfo = components["responses"]["TotpInfo"]["content"]["application/json"];
|
|
25
26
|
export type ConfiguredMfa = components["schemas"]["ConfiguredMfa"];
|
|
27
|
+
export type RatchetConfig = components["schemas"]["RatchetConfig"];
|
|
28
|
+
export type IdentityProof = components["schemas"]["IdentityProof"];
|
|
29
|
+
|
|
30
|
+
type OidcAuthResponse =
|
|
31
|
+
paths["/v0/org/{org_id}/oidc"]["post"]["responses"]["200"]["content"]["application/json"];
|
|
32
|
+
|
|
33
|
+
/** TOTP challenge that must be answered before user's TOTP is updated */
|
|
34
|
+
export class TotpChallenge {
|
|
35
|
+
readonly #cs: CubeSigner;
|
|
36
|
+
readonly #totpInfo: TotpInfo;
|
|
37
|
+
/** The id of the challenge */
|
|
38
|
+
get totpId() {
|
|
39
|
+
return this.#totpInfo.totp_id;
|
|
40
|
+
}
|
|
41
|
+
/** The new TOTP configuration */
|
|
42
|
+
get totpUrl() {
|
|
43
|
+
return this.#totpInfo.totp_url;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @param {CubeSigner} cs Used when answering the challenge.
|
|
47
|
+
* @param {TotpInfo} totpInfo TOTP challenge information.
|
|
48
|
+
*/
|
|
49
|
+
constructor(cs: CubeSigner, totpInfo: TotpInfo) {
|
|
50
|
+
this.#cs = cs;
|
|
51
|
+
this.#totpInfo = totpInfo;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Answer the challenge with the code that corresponds to this `this.totpUrl`.
|
|
55
|
+
* @param {string} code 6-digit code that corresponds to this `this.totpUrl`.
|
|
56
|
+
*/
|
|
57
|
+
async answer(code: string) {
|
|
58
|
+
await this.#cs.resetTotpComplete(this.totpId, code);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
26
61
|
|
|
27
62
|
/** CubeSigner client */
|
|
28
63
|
export class CubeSigner {
|
|
29
64
|
readonly #env: EnvInterface;
|
|
30
|
-
readonly sessionMgr?:
|
|
65
|
+
readonly sessionMgr?: CognitoSessionManager | SignerSessionManager;
|
|
66
|
+
#orgId?: string;
|
|
31
67
|
|
|
32
68
|
/** @return {EnvInterface} The CubeSigner environment of this client */
|
|
33
69
|
get env(): EnvInterface {
|
|
34
70
|
return this.#env;
|
|
35
71
|
}
|
|
36
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Set the organization ID
|
|
75
|
+
* @param {string} orgId The new organization id.
|
|
76
|
+
*/
|
|
77
|
+
setOrgId(orgId: string) {
|
|
78
|
+
this.#orgId = orgId;
|
|
79
|
+
}
|
|
80
|
+
|
|
37
81
|
/**
|
|
38
82
|
* Loads an existing management session and creates a CubeSigner instance.
|
|
39
|
-
*
|
|
83
|
+
*
|
|
84
|
+
* @param {CognitoSessionStorage} storage Optional session storage to load
|
|
40
85
|
* the session from. If not specified, the management session from the config
|
|
41
86
|
* directory will be loaded.
|
|
42
87
|
* @return {Promise<CubeSigner>} New CubeSigner instance
|
|
43
88
|
*/
|
|
44
|
-
static async loadManagementSession(storage?:
|
|
89
|
+
static async loadManagementSession(storage?: CognitoSessionStorage): Promise<CubeSigner> {
|
|
45
90
|
const defaultFilePath = path.join(configDir(), "management-session.json");
|
|
46
|
-
const sessionMgr = await
|
|
91
|
+
const sessionMgr = await CognitoSessionManager.loadFromStorage(
|
|
47
92
|
storage ?? new JsonFileSessionStorage(defaultFilePath),
|
|
48
93
|
);
|
|
49
94
|
return new CubeSigner(<CubeSignerOptions>{
|
|
@@ -61,110 +106,235 @@ export class CubeSigner {
|
|
|
61
106
|
static async loadSignerSession(storage?: SignerSessionStorage): Promise<SignerSession> {
|
|
62
107
|
const defaultFilePath = path.join(configDir(), "signer-session.json");
|
|
63
108
|
const sss = storage ?? new JsonFileSessionStorage(defaultFilePath);
|
|
64
|
-
|
|
65
|
-
return await SignerSession.loadSignerSession(new CubeSigner({ env }), sss);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Loads a signer session from OIDC storage
|
|
70
|
-
* @param {OidcSessionStorage} storage The storage to load from
|
|
71
|
-
* @return {Promise<SignerSession>} New signer session
|
|
72
|
-
*/
|
|
73
|
-
static async loadOidcSession(storage: OidcSessionStorage): Promise<SignerSession> {
|
|
74
|
-
const env = (await storage.retrieve()).env;
|
|
75
|
-
return await SignerSession.loadOidcSession(new CubeSigner({ env }), storage);
|
|
109
|
+
return await SignerSession.loadSignerSession(sss);
|
|
76
110
|
}
|
|
77
111
|
|
|
78
112
|
/**
|
|
79
113
|
* Create a new CubeSigner instance.
|
|
80
|
-
* @param {CubeSignerOptions} options The options for the CubeSigner instance.
|
|
114
|
+
* @param {CubeSignerOptions} options The optional configuraiton options for the CubeSigner instance.
|
|
81
115
|
*/
|
|
82
|
-
constructor(options
|
|
83
|
-
let env = options
|
|
84
|
-
if (options
|
|
116
|
+
constructor(options?: CubeSignerOptions) {
|
|
117
|
+
let env = options?.env;
|
|
118
|
+
if (options?.sessionMgr) {
|
|
85
119
|
this.sessionMgr = options.sessionMgr;
|
|
86
120
|
env = env ?? this.sessionMgr.env;
|
|
87
121
|
}
|
|
88
122
|
this.#env = env ?? envs["gamma"];
|
|
123
|
+
this.#orgId = options?.orgId;
|
|
89
124
|
}
|
|
90
125
|
|
|
91
126
|
/**
|
|
92
|
-
* Authenticate an OIDC user and create a new
|
|
127
|
+
* Authenticate an OIDC user and create a new session manager for them.
|
|
93
128
|
* @param {string} oidcToken The OIDC token
|
|
94
129
|
* @param {string} orgId The id of the organization that the user is in
|
|
95
130
|
* @param {List<string>} scopes The scopes of the resulting session
|
|
96
|
-
* @param {
|
|
97
|
-
* @
|
|
131
|
+
* @param {RatchetConfig} lifetimes Lifetimes of the new session.
|
|
132
|
+
* @param {SignerSessionStorage?} storage Optional signer session storage (defaults to in-memory storage)
|
|
133
|
+
* @return {Promise<SignerSessionManager>} The signer session manager
|
|
98
134
|
*/
|
|
99
|
-
async
|
|
135
|
+
async oidcAuth(
|
|
100
136
|
oidcToken: string,
|
|
101
137
|
orgId: string,
|
|
102
138
|
scopes: Array<string>,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
oidcToken,
|
|
109
|
-
orgId,
|
|
110
|
-
scopes,
|
|
111
|
-
);
|
|
139
|
+
lifetimes?: RatchetConfig,
|
|
140
|
+
storage?: SignerSessionStorage,
|
|
141
|
+
): Promise<SignerSessionManager> {
|
|
142
|
+
const resp = await this.oidcLogin(oidcToken, orgId, scopes, lifetimes);
|
|
143
|
+
return await SignerSessionManager.createFromSessionInfo(this.env, orgId, resp.data(), storage);
|
|
112
144
|
}
|
|
113
145
|
|
|
114
146
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* @
|
|
118
|
-
* @param {List<string>} scopes The scopes of the resulting session
|
|
119
|
-
* @param {OidcSessionStorage} storage The signer session storage
|
|
120
|
-
* @return {Promise<SignerSession>} The signer session
|
|
147
|
+
* Retrieves information about the current user.
|
|
148
|
+
*
|
|
149
|
+
* @return {Promise<UserInfo>} User information.
|
|
121
150
|
*/
|
|
122
|
-
async
|
|
123
|
-
|
|
124
|
-
orgId
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
151
|
+
async aboutMe(): Promise<UserInfo> {
|
|
152
|
+
const client = await this.management();
|
|
153
|
+
const resp = this.#orgId
|
|
154
|
+
? await client.get("/v0/org/{org_id}/user/me", {
|
|
155
|
+
params: { path: { org_id: this.#orgId } },
|
|
156
|
+
parseAs: "json",
|
|
157
|
+
})
|
|
158
|
+
: await client.get("/v0/about_me", {
|
|
159
|
+
parseAs: "json",
|
|
160
|
+
});
|
|
161
|
+
const data = assertOk(resp);
|
|
162
|
+
return data;
|
|
130
163
|
}
|
|
131
164
|
|
|
132
|
-
/**
|
|
133
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Retrieves existing MFA request.
|
|
167
|
+
*
|
|
168
|
+
* @param {string} orgId Organization ID
|
|
169
|
+
* @param {string} mfaId MFA request ID
|
|
170
|
+
* @return {Promise<MfaRequestInfo>} MFA request information
|
|
171
|
+
*/
|
|
172
|
+
async mfaGet(orgId: string, mfaId: string): Promise<MfaRequestInfo> {
|
|
134
173
|
const resp = await (
|
|
135
174
|
await this.management()
|
|
136
|
-
).get("/v0/
|
|
137
|
-
|
|
175
|
+
).get("/v0/org/{org_id}/mfa/{mfa_id}", {
|
|
176
|
+
params: { path: { org_id: orgId, mfa_id: mfaId } },
|
|
138
177
|
});
|
|
139
|
-
|
|
140
|
-
return data;
|
|
178
|
+
return assertOk(resp);
|
|
141
179
|
}
|
|
142
180
|
|
|
143
181
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
182
|
+
* List pending MFA requests accessible to the current user.
|
|
183
|
+
* @param {string} orgId Organization ID
|
|
184
|
+
* @return {Promise<MfaRequestInfo[]>} The MFA requests.
|
|
146
185
|
*/
|
|
147
|
-
async
|
|
186
|
+
async mfaList(orgId: string): Promise<MfaRequestInfo[]> {
|
|
148
187
|
const resp = await (
|
|
149
188
|
await this.management()
|
|
150
|
-
).
|
|
151
|
-
|
|
189
|
+
).get("/v0/org/{org_id}/mfa", {
|
|
190
|
+
params: { path: { org_id: orgId } },
|
|
191
|
+
});
|
|
192
|
+
return assertOk(resp).mfa_requests;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Approve a pending MFA request.
|
|
197
|
+
*
|
|
198
|
+
* @param {string} orgId The org id of the MFA request
|
|
199
|
+
* @param {string} mfaId The id of the MFA request
|
|
200
|
+
* @return {Promise<MfaRequestInfo>} The result of the MFA request
|
|
201
|
+
*/
|
|
202
|
+
async mfaApprove(orgId: string, mfaId: string): Promise<MfaRequestInfo> {
|
|
203
|
+
const resp = await (
|
|
204
|
+
await this.management()
|
|
205
|
+
).patch("/v0/org/{org_id}/mfa/{mfa_id}", {
|
|
206
|
+
params: { path: { org_id: orgId, mfa_id: mfaId } },
|
|
152
207
|
});
|
|
153
208
|
return assertOk(resp);
|
|
154
209
|
}
|
|
155
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Initiate adding a new FIDO device. MFA may be required.
|
|
213
|
+
* @param {string} name The name of the new device.
|
|
214
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt to include in HTTP headers
|
|
215
|
+
* @return {Promise<SignResponse<AddFidoChallenge>>} A challenge that must be answered in order to complete FIDO registration.
|
|
216
|
+
*/
|
|
217
|
+
async addFidoStart(
|
|
218
|
+
name: string,
|
|
219
|
+
mfaReceipt?: MfaReceipt,
|
|
220
|
+
): Promise<SignResponse<AddFidoChallenge>> {
|
|
221
|
+
const orgId = this.#orgId || mfaReceipt?.mfaOrgId;
|
|
222
|
+
if (!orgId) {
|
|
223
|
+
throw new Error("Org ID must be set");
|
|
224
|
+
}
|
|
225
|
+
const addFidoFn = async (headers?: HeadersInit) => {
|
|
226
|
+
const client = await this.management();
|
|
227
|
+
const resp = await client.post("/v0/org/{org_id}/user/me/fido", {
|
|
228
|
+
headers,
|
|
229
|
+
params: { path: { org_id: orgId } },
|
|
230
|
+
body: { name },
|
|
231
|
+
parseAs: "json",
|
|
232
|
+
});
|
|
233
|
+
const x = assertOk(resp);
|
|
234
|
+
// TODO: add mapFn to SignResponse
|
|
235
|
+
if ((x as AcceptedResponse).accepted?.MfaRequired) {
|
|
236
|
+
return x as AcceptedResponse;
|
|
237
|
+
} else {
|
|
238
|
+
return new AddFidoChallenge(this, x as ApiAddFidoChallenge);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
return await SignResponse.create(addFidoFn, mfaReceipt);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Complete a previously initiated request to add a new FIDO device.
|
|
246
|
+
* @param {string} challengeId The ID of the challenge returned by the remote end.
|
|
247
|
+
* @param {PublicKeyCredential} credential The answer to the challenge.
|
|
248
|
+
*/
|
|
249
|
+
async addFidoComplete(challengeId: string, credential: PublicKeyCredential) {
|
|
250
|
+
const orgId = this.#orgId;
|
|
251
|
+
if (!orgId) {
|
|
252
|
+
throw new Error("Org ID must be set");
|
|
253
|
+
}
|
|
254
|
+
const client = await this.management();
|
|
255
|
+
const resp = await client.patch("/v0/org/{org_id}/user/me/fido", {
|
|
256
|
+
params: { path: { org_id: orgId } },
|
|
257
|
+
body: {
|
|
258
|
+
challenge_id: challengeId,
|
|
259
|
+
credential,
|
|
260
|
+
},
|
|
261
|
+
parseAs: "json",
|
|
262
|
+
});
|
|
263
|
+
assertOk(resp);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Creates a request to change user's TOTP. This request returns a new TOTP challenge
|
|
268
|
+
* that must be answered by calling `resetTotpComplete`
|
|
269
|
+
*
|
|
270
|
+
* @param {MfaReceipt} mfaReceipt MFA receipt to include in HTTP headers
|
|
271
|
+
*/
|
|
272
|
+
async resetTotpStart(mfaReceipt?: MfaReceipt): Promise<SignResponse<TotpChallenge>> {
|
|
273
|
+
const resetTotpFn = async (headers?: HeadersInit) => {
|
|
274
|
+
const orgId = this.#orgId || mfaReceipt?.mfaOrgId;
|
|
275
|
+
const client = await this.management();
|
|
276
|
+
const resp = orgId
|
|
277
|
+
? await client.post("/v0/org/{org_id}/user/me/totp", {
|
|
278
|
+
headers,
|
|
279
|
+
params: { path: { org_id: orgId } },
|
|
280
|
+
body: null,
|
|
281
|
+
parseAs: "json",
|
|
282
|
+
})
|
|
283
|
+
: await client.post("/v0/user/me/totp", {
|
|
284
|
+
headers,
|
|
285
|
+
body: null,
|
|
286
|
+
parseAs: "json",
|
|
287
|
+
});
|
|
288
|
+
const x = assertOk(resp);
|
|
289
|
+
// TODO: add mapFn to SignResponse
|
|
290
|
+
if ((x as AcceptedResponse).accepted?.MfaRequired) {
|
|
291
|
+
return x as AcceptedResponse;
|
|
292
|
+
} else {
|
|
293
|
+
return new TotpChallenge(this, x as TotpInfo);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
return await SignResponse.create(resetTotpFn, mfaReceipt);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Answer the TOTP challenge issued by `resetTotpStart`. If successful, user's
|
|
301
|
+
* TOTP configuration will be updated to that of the TOTP challenge.
|
|
302
|
+
*
|
|
303
|
+
* @param {string} totpId - The ID of the TOTP challenge
|
|
304
|
+
* @param {string} code - The TOTP code that should verify against the TOTP configuration from the challenge.
|
|
305
|
+
*/
|
|
306
|
+
async resetTotpComplete(totpId: string, code: string): Promise<void> {
|
|
307
|
+
const client = await this.management();
|
|
308
|
+
const resp = this.#orgId
|
|
309
|
+
? await client.patch("/v0/org/{org_id}/user/me/totp", {
|
|
310
|
+
parseAs: "json",
|
|
311
|
+
params: { path: { org_id: this.#orgId } },
|
|
312
|
+
body: { totp_id: totpId, code },
|
|
313
|
+
})
|
|
314
|
+
: await client.patch("/v0/user/me/totp", {
|
|
315
|
+
parseAs: "json",
|
|
316
|
+
body: { totp_id: totpId, code },
|
|
317
|
+
});
|
|
318
|
+
assertOk(resp);
|
|
319
|
+
}
|
|
320
|
+
|
|
156
321
|
/**
|
|
157
322
|
* Verifies a given TOTP code against the current user's TOTP configuration.
|
|
158
323
|
* Throws an error if the verification fails.
|
|
159
324
|
* @param {string} code Current TOTP code
|
|
160
325
|
*/
|
|
161
326
|
async verifyTotp(code: string) {
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
327
|
+
const client = await this.management();
|
|
328
|
+
const resp = this.#orgId
|
|
329
|
+
? await client.post("/v0/org/{org_id}/user/me/totp/verify", {
|
|
330
|
+
params: { path: { org_id: this.#orgId } },
|
|
331
|
+
body: { code },
|
|
332
|
+
parseAs: "json",
|
|
333
|
+
})
|
|
334
|
+
: await client.post("/v0/user/me/totp/verify", {
|
|
335
|
+
body: { code },
|
|
336
|
+
parseAs: "json",
|
|
337
|
+
});
|
|
168
338
|
assertOk(resp);
|
|
169
339
|
}
|
|
170
340
|
|
|
@@ -184,6 +354,21 @@ export class CubeSigner {
|
|
|
184
354
|
return new Org(this, data);
|
|
185
355
|
}
|
|
186
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Deletes a given key.
|
|
359
|
+
* @param {string} orgId - Organization id
|
|
360
|
+
* @param {string} keyId - Key id
|
|
361
|
+
*/
|
|
362
|
+
async deleteKey(orgId: string, keyId: string) {
|
|
363
|
+
const resp = await (
|
|
364
|
+
await this.management()
|
|
365
|
+
).del("/v0/org/{org_id}/keys/{key_id}", {
|
|
366
|
+
params: { path: { org_id: orgId, key_id: keyId } },
|
|
367
|
+
parseAs: "json",
|
|
368
|
+
});
|
|
369
|
+
assertOk(resp);
|
|
370
|
+
}
|
|
371
|
+
|
|
187
372
|
/** Get the management client.
|
|
188
373
|
* @return {Client} The client.
|
|
189
374
|
* @internal
|
|
@@ -194,6 +379,108 @@ export class CubeSigner {
|
|
|
194
379
|
}
|
|
195
380
|
return await this.sessionMgr.client();
|
|
196
381
|
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Obtain a proof of authentication.
|
|
385
|
+
*
|
|
386
|
+
* @param {string} orgId The id of the organization that the user is in
|
|
387
|
+
* @return {Promise<IdentityProof>} Proof of authentication
|
|
388
|
+
*/
|
|
389
|
+
async proveIdentity(orgId: string): Promise<IdentityProof> {
|
|
390
|
+
const client = await this.management();
|
|
391
|
+
const resp = await client.post("/v0/org/{org_id}/identity/prove", {
|
|
392
|
+
params: { path: { org_id: orgId } },
|
|
393
|
+
parseAs: "json",
|
|
394
|
+
});
|
|
395
|
+
return assertOk(resp);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Exchange an OIDC token for a proof of authentication.
|
|
400
|
+
*
|
|
401
|
+
* @param {string} oidcToken The OIDC token
|
|
402
|
+
* @param {string} orgId The id of the organization that the user is in
|
|
403
|
+
* @return {Promise<IdentityProof>} Proof of authentication
|
|
404
|
+
*/
|
|
405
|
+
async oidcProveIdentity(oidcToken: string, orgId: string): Promise<IdentityProof> {
|
|
406
|
+
const client = createClient<paths>({
|
|
407
|
+
baseUrl: this.env.SignerApiRoot,
|
|
408
|
+
headers: {
|
|
409
|
+
Authorization: oidcToken,
|
|
410
|
+
},
|
|
411
|
+
});
|
|
412
|
+
const resp = await client.post("/v0/org/{org_id}/identity/prove/oidc", {
|
|
413
|
+
params: { path: { org_id: orgId } },
|
|
414
|
+
parseAs: "json",
|
|
415
|
+
});
|
|
416
|
+
return assertOk(resp);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Checks if a given identity proof is valid.
|
|
421
|
+
*
|
|
422
|
+
* @param {string} orgId The id of the organization that the user is in.
|
|
423
|
+
* @param {IdentityProof} identityProof The proof of authentication.
|
|
424
|
+
*/
|
|
425
|
+
async verifyIdentity(orgId: string, identityProof: IdentityProof) {
|
|
426
|
+
const resp = await (
|
|
427
|
+
await this.management()
|
|
428
|
+
).post("/v0/org/{org_id}/identity/verify", {
|
|
429
|
+
params: { path: { org_id: orgId } },
|
|
430
|
+
body: identityProof,
|
|
431
|
+
parseAs: "json",
|
|
432
|
+
});
|
|
433
|
+
assertOk(resp);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Exchange an OIDC token for a CubeSigner session token.
|
|
438
|
+
* @param {string} oidcToken The OIDC token
|
|
439
|
+
* @param {string} orgId The id of the organization that the user is in
|
|
440
|
+
* @param {List<string>} scopes The scopes of the resulting session
|
|
441
|
+
* @param {RatchetConfig} lifetimes Lifetimes of the new session.
|
|
442
|
+
* @param {MfaReceipt} mfaReceipt Optional MFA receipt (id + confirmation code)
|
|
443
|
+
* @return {Promise<SignResponse<OidcAuthResponse>>} The session data.
|
|
444
|
+
*/
|
|
445
|
+
async oidcLogin(
|
|
446
|
+
oidcToken: string,
|
|
447
|
+
orgId: string,
|
|
448
|
+
scopes: Array<string>,
|
|
449
|
+
lifetimes?: RatchetConfig,
|
|
450
|
+
mfaReceipt?: MfaReceipt,
|
|
451
|
+
): Promise<SignResponse<OidcAuthResponse>> {
|
|
452
|
+
const client = createClient<paths>({
|
|
453
|
+
baseUrl: this.env.SignerApiRoot,
|
|
454
|
+
headers: {
|
|
455
|
+
Authorization: oidcToken,
|
|
456
|
+
},
|
|
457
|
+
});
|
|
458
|
+
const loginFn = async (headers?: HeadersInit) => {
|
|
459
|
+
const resp = await client.post("/v0/org/{org_id}/oidc", {
|
|
460
|
+
params: { path: { org_id: orgId } },
|
|
461
|
+
headers,
|
|
462
|
+
body: {
|
|
463
|
+
scopes,
|
|
464
|
+
tokens: lifetimes,
|
|
465
|
+
},
|
|
466
|
+
parseAs: "json",
|
|
467
|
+
});
|
|
468
|
+
return assertOk(resp);
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
const h1 = mfaReceipt ? SignResponse.getMfaHeaders(mfaReceipt) : undefined;
|
|
472
|
+
return new SignResponse(loginFn, await loginFn(h1));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** MFA receipt */
|
|
477
|
+
export interface MfaReceipt {
|
|
478
|
+
/** MFA request ID */
|
|
479
|
+
mfaId: string;
|
|
480
|
+
/** Corresponding org ID */
|
|
481
|
+
mfaOrgId: string;
|
|
482
|
+
/** MFA confirmation code */
|
|
483
|
+
mfaConf: string;
|
|
197
484
|
}
|
|
198
485
|
|
|
199
486
|
/** Organizations */
|
|
@@ -204,6 +491,10 @@ export * from "./key";
|
|
|
204
491
|
export * from "./role";
|
|
205
492
|
/** Env */
|
|
206
493
|
export * from "./env";
|
|
494
|
+
/** Fido */
|
|
495
|
+
export * from "./fido";
|
|
496
|
+
/** Pagination */
|
|
497
|
+
export * from "./paginator";
|
|
207
498
|
/** Sessions */
|
|
208
499
|
export * from "./signer_session";
|
|
209
500
|
/** Session storage */
|
|
@@ -211,9 +502,7 @@ export * from "./session/session_storage";
|
|
|
211
502
|
/** Session manager */
|
|
212
503
|
export * from "./session/session_manager";
|
|
213
504
|
/** Management session manager */
|
|
214
|
-
export * from "./session/
|
|
215
|
-
/** OIDC session manager */
|
|
216
|
-
export * from "./session/oidc_session_manager";
|
|
505
|
+
export * from "./session/cognito_manager";
|
|
217
506
|
/** Signer session manager */
|
|
218
507
|
export * from "./session/signer_session_manager";
|
|
219
508
|
/** Export ethers.js Signer */
|