@cubist-labs/cubesigner-sdk 0.1.77 → 0.2.15
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/dist/package.json +68 -0
- package/dist/src/api.d.ts +493 -0
- package/dist/src/api.js +1166 -0
- package/dist/src/client.d.ts +534 -10
- package/dist/src/client.js +355 -19
- package/dist/src/ethers/index.d.ts +34 -9
- package/dist/src/ethers/index.js +63 -19
- package/dist/src/index.d.ts +51 -70
- package/dist/src/index.js +83 -237
- package/dist/src/key.d.ts +35 -64
- package/dist/src/key.js +32 -96
- package/dist/src/mfa.d.ts +85 -14
- package/dist/src/mfa.js +146 -40
- package/dist/src/org.d.ts +42 -194
- package/dist/src/org.js +52 -336
- package/dist/src/paginator.js +1 -1
- package/dist/src/response.d.ts +101 -0
- package/dist/src/response.js +164 -0
- package/dist/src/role.d.ts +87 -83
- package/dist/src/role.js +79 -136
- package/dist/src/schema.d.ts +936 -28
- package/dist/src/schema.js +1 -1
- package/dist/src/schema_types.d.ts +109 -0
- package/dist/src/schema_types.js +3 -0
- package/dist/src/session/cognito_manager.d.ts +15 -3
- package/dist/src/session/cognito_manager.js +23 -5
- package/dist/src/session/session_manager.d.ts +1 -1
- package/dist/src/session/session_manager.js +3 -11
- package/dist/src/session/session_storage.js +1 -1
- package/dist/src/session/signer_session_manager.d.ts +10 -29
- package/dist/src/session/signer_session_manager.js +21 -80
- package/dist/src/signer_session.d.ts +15 -252
- package/dist/src/signer_session.js +25 -424
- package/dist/src/user_export.d.ts +52 -0
- package/dist/src/user_export.js +129 -0
- package/dist/src/util.d.ts +15 -0
- package/dist/src/util.js +33 -11
- package/package.json +13 -11
- package/src/api.ts +1395 -0
- package/src/client.ts +413 -12
- package/src/ethers/index.ts +74 -28
- package/src/index.ts +96 -273
- package/src/key.ts +36 -131
- package/src/{fido.ts → mfa.ts} +62 -38
- package/src/org.ts +54 -405
- package/src/response.ts +196 -0
- package/src/role.ts +113 -184
- package/src/schema.ts +936 -28
- package/src/schema_types.ts +110 -0
- package/src/session/cognito_manager.ts +33 -6
- package/src/session/session_manager.ts +2 -8
- package/src/session/signer_session_manager.ts +29 -110
- package/src/signer_session.ts +22 -597
- package/src/user_export.ts +116 -0
- package/src/util.ts +29 -10
package/src/index.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { envs, EnvInterface } from "./env";
|
|
2
|
-
import {
|
|
2
|
+
import { Client, OidcClient } from "./api";
|
|
3
|
+
import { CubeSignerClient } from "./client";
|
|
3
4
|
import { Org } from "./org";
|
|
4
5
|
import { JsonFileSessionStorage } from "./session/session_storage";
|
|
5
6
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
7
|
+
import {
|
|
8
|
+
SignerSessionStorage,
|
|
9
|
+
SignerSessionManager,
|
|
10
|
+
SignerSessionData,
|
|
11
|
+
} from "./session/signer_session_manager";
|
|
12
|
+
import { CubeSignerResponse } from "./response";
|
|
13
|
+
import { SignerSession } from "./signer_session";
|
|
8
14
|
import { CognitoSessionManager, CognitoSessionStorage } from "./session/cognito_manager";
|
|
9
|
-
import {
|
|
15
|
+
import { configDir } from "./util";
|
|
10
16
|
import * as path from "path";
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
17
|
+
import { MfaReceipt } from "./mfa";
|
|
18
|
+
import { name, version } from "./../package.json";
|
|
19
|
+
import { IdentityProof, MfaRequestInfo, RatchetConfig, UserInfo } from "./schema_types";
|
|
13
20
|
|
|
14
21
|
/** CubeSigner constructor options */
|
|
15
22
|
export interface CubeSignerOptions {
|
|
@@ -21,61 +28,43 @@ export interface CubeSignerOptions {
|
|
|
21
28
|
orgId?: string;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* CubeSigner client
|
|
33
|
+
*
|
|
34
|
+
* @deprecated Use {@link Org} or {@link CubeSignerClient} instead.
|
|
35
|
+
*/
|
|
36
|
+
export class CubeSigner {
|
|
37
|
+
readonly #env: EnvInterface;
|
|
38
|
+
readonly sessionMgr?: CognitoSessionManager | SignerSessionManager;
|
|
39
|
+
#csc?: CubeSignerClient;
|
|
32
40
|
|
|
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
41
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
42
|
+
* Underlying {@link CubeSignerClient} instance, if set; otherwise throws.
|
|
43
|
+
* @internal
|
|
56
44
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
get csc(): CubeSignerClient {
|
|
46
|
+
if (!this.#csc) {
|
|
47
|
+
throw new Error("CubeSignerClient is not set");
|
|
48
|
+
}
|
|
49
|
+
return this.#csc;
|
|
59
50
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** CubeSigner client */
|
|
63
|
-
export class CubeSigner {
|
|
64
|
-
readonly #env: EnvInterface;
|
|
65
|
-
readonly sessionMgr?: CognitoSessionManager | SignerSessionManager;
|
|
66
|
-
#orgId?: string;
|
|
67
51
|
|
|
68
52
|
/** @return {EnvInterface} The CubeSigner environment of this client */
|
|
69
53
|
get env(): EnvInterface {
|
|
70
54
|
return this.#env;
|
|
71
55
|
}
|
|
72
56
|
|
|
57
|
+
/** Organization ID */
|
|
58
|
+
get orgId() {
|
|
59
|
+
return this.csc.orgId;
|
|
60
|
+
}
|
|
61
|
+
|
|
73
62
|
/**
|
|
74
63
|
* Set the organization ID
|
|
75
64
|
* @param {string} orgId The new organization id.
|
|
76
65
|
*/
|
|
77
66
|
setOrgId(orgId: string) {
|
|
78
|
-
this.#
|
|
67
|
+
this.#csc = this.csc.withOrg(orgId);
|
|
79
68
|
}
|
|
80
69
|
|
|
81
70
|
/**
|
|
@@ -87,12 +76,8 @@ export class CubeSigner {
|
|
|
87
76
|
* @return {Promise<CubeSigner>} New CubeSigner instance
|
|
88
77
|
*/
|
|
89
78
|
static async loadManagementSession(storage?: CognitoSessionStorage): Promise<CubeSigner> {
|
|
90
|
-
const defaultFilePath = path.join(configDir(), "management-session.json");
|
|
91
|
-
const sessionMgr = await CognitoSessionManager.loadFromStorage(
|
|
92
|
-
storage ?? new JsonFileSessionStorage(defaultFilePath),
|
|
93
|
-
);
|
|
94
79
|
return new CubeSigner(<CubeSignerOptions>{
|
|
95
|
-
sessionMgr,
|
|
80
|
+
sessionMgr: await CognitoSessionManager.loadManagementSession(storage),
|
|
96
81
|
});
|
|
97
82
|
}
|
|
98
83
|
|
|
@@ -111,7 +96,7 @@ export class CubeSigner {
|
|
|
111
96
|
|
|
112
97
|
/**
|
|
113
98
|
* Create a new CubeSigner instance.
|
|
114
|
-
* @param {CubeSignerOptions} options The optional
|
|
99
|
+
* @param {CubeSignerOptions} options The optional configuration options for the CubeSigner instance.
|
|
115
100
|
*/
|
|
116
101
|
constructor(options?: CubeSignerOptions) {
|
|
117
102
|
let env = options?.env;
|
|
@@ -120,11 +105,21 @@ export class CubeSigner {
|
|
|
120
105
|
env = env ?? this.sessionMgr.env;
|
|
121
106
|
}
|
|
122
107
|
this.#env = env ?? envs["gamma"];
|
|
123
|
-
this.#
|
|
108
|
+
this.#csc = new CubeSignerClient(
|
|
109
|
+
// HACK: ignore that sessionMgr may be a CognitoSessionManager and pretend that it
|
|
110
|
+
// is a SignerSessionManager; that's fine because the CubeSignerClient will
|
|
111
|
+
// almost always just call `await token()` on it, which works in both cases.
|
|
112
|
+
//
|
|
113
|
+
// This is done here for backward compatibility reasons only; in the future,
|
|
114
|
+
// we should deprecate this class and people should start using `CubeSingerClient` directly.
|
|
115
|
+
options?.sessionMgr as unknown as SignerSessionManager,
|
|
116
|
+
options?.orgId,
|
|
117
|
+
);
|
|
124
118
|
}
|
|
125
119
|
|
|
126
120
|
/**
|
|
127
121
|
* Authenticate an OIDC user and create a new session manager for them.
|
|
122
|
+
*
|
|
128
123
|
* @param {string} oidcToken The OIDC token
|
|
129
124
|
* @param {string} orgId The id of the organization that the user is in
|
|
130
125
|
* @param {List<string>} scopes The scopes of the resulting session
|
|
@@ -149,17 +144,7 @@ export class CubeSigner {
|
|
|
149
144
|
* @return {Promise<UserInfo>} User information.
|
|
150
145
|
*/
|
|
151
146
|
async aboutMe(): Promise<UserInfo> {
|
|
152
|
-
|
|
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;
|
|
147
|
+
return await this.csc.userGet();
|
|
163
148
|
}
|
|
164
149
|
|
|
165
150
|
/**
|
|
@@ -170,12 +155,7 @@ export class CubeSigner {
|
|
|
170
155
|
* @return {Promise<MfaRequestInfo>} MFA request information
|
|
171
156
|
*/
|
|
172
157
|
async mfaGet(orgId: string, mfaId: string): Promise<MfaRequestInfo> {
|
|
173
|
-
|
|
174
|
-
await this.management()
|
|
175
|
-
).get("/v0/org/{org_id}/mfa/{mfa_id}", {
|
|
176
|
-
params: { path: { org_id: orgId, mfa_id: mfaId } },
|
|
177
|
-
});
|
|
178
|
-
return assertOk(resp);
|
|
158
|
+
return await this.csc.withOrg(orgId).mfaGet(mfaId);
|
|
179
159
|
}
|
|
180
160
|
|
|
181
161
|
/**
|
|
@@ -184,12 +164,7 @@ export class CubeSigner {
|
|
|
184
164
|
* @return {Promise<MfaRequestInfo[]>} The MFA requests.
|
|
185
165
|
*/
|
|
186
166
|
async mfaList(orgId: string): Promise<MfaRequestInfo[]> {
|
|
187
|
-
|
|
188
|
-
await this.management()
|
|
189
|
-
).get("/v0/org/{org_id}/mfa", {
|
|
190
|
-
params: { path: { org_id: orgId } },
|
|
191
|
-
});
|
|
192
|
-
return assertOk(resp).mfa_requests;
|
|
167
|
+
return await this.csc.withOrg(orgId).mfaList();
|
|
193
168
|
}
|
|
194
169
|
|
|
195
170
|
/**
|
|
@@ -200,158 +175,45 @@ export class CubeSigner {
|
|
|
200
175
|
* @return {Promise<MfaRequestInfo>} The result of the MFA request
|
|
201
176
|
*/
|
|
202
177
|
async mfaApprove(orgId: string, mfaId: string): Promise<MfaRequestInfo> {
|
|
203
|
-
|
|
204
|
-
await this.management()
|
|
205
|
-
).patch("/v0/org/{org_id}/mfa/{mfa_id}", {
|
|
206
|
-
params: { path: { org_id: orgId, mfa_id: mfaId } },
|
|
207
|
-
});
|
|
208
|
-
return assertOk(resp);
|
|
178
|
+
return await this.csc.withOrg(orgId).mfaApprove(mfaId);
|
|
209
179
|
}
|
|
210
180
|
|
|
211
|
-
/**
|
|
212
|
-
|
|
213
|
-
|
|
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);
|
|
181
|
+
/** Initiate adding a new FIDO device. MFA may be required. */
|
|
182
|
+
get addFidoStart() {
|
|
183
|
+
return this.csc.userRegisterFidoInit.bind(this.csc);
|
|
264
184
|
}
|
|
265
185
|
|
|
266
186
|
/**
|
|
267
187
|
* Creates a request to change user's TOTP. This request returns a new TOTP challenge
|
|
268
188
|
* that must be answered by calling `resetTotpComplete`
|
|
269
|
-
*
|
|
270
|
-
* @param {MfaReceipt} mfaReceipt MFA receipt to include in HTTP headers
|
|
271
189
|
*/
|
|
272
|
-
|
|
273
|
-
|
|
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);
|
|
190
|
+
get resetTotpStart() {
|
|
191
|
+
return this.csc.userResetTotpInit.bind(this.#csc);
|
|
297
192
|
}
|
|
298
193
|
|
|
299
194
|
/**
|
|
300
195
|
* 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.
|
|
196
|
+
* TOTP configuration will be updated to that of the TOTP challenge.he TOTP configuration from the challenge.
|
|
305
197
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
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);
|
|
198
|
+
get resetTotpComplete() {
|
|
199
|
+
return this.csc.userResetTotpComplete.bind(this.#csc);
|
|
319
200
|
}
|
|
320
201
|
|
|
321
202
|
/**
|
|
322
203
|
* Verifies a given TOTP code against the current user's TOTP configuration.
|
|
323
204
|
* Throws an error if the verification fails.
|
|
324
|
-
* @param {string} code Current TOTP code
|
|
325
205
|
*/
|
|
326
|
-
|
|
327
|
-
|
|
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
|
-
});
|
|
338
|
-
assertOk(resp);
|
|
206
|
+
get verifyTotp() {
|
|
207
|
+
return this.csc.userVerifyTotp.bind(this.#csc);
|
|
339
208
|
}
|
|
340
209
|
|
|
341
|
-
/**
|
|
210
|
+
/**
|
|
211
|
+
* Retrieve information about an organization.
|
|
342
212
|
* @param {string} orgId The ID or name of the organization.
|
|
343
213
|
* @return {Org} The organization.
|
|
344
|
-
|
|
345
|
-
async getOrg(orgId
|
|
346
|
-
|
|
347
|
-
await this.management()
|
|
348
|
-
).get("/v0/org/{org_id}", {
|
|
349
|
-
params: { path: { org_id: orgId } },
|
|
350
|
-
parseAs: "json",
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
const data = assertOk(resp);
|
|
354
|
-
return new Org(this, data);
|
|
214
|
+
*/
|
|
215
|
+
async getOrg(orgId?: string): Promise<Org> {
|
|
216
|
+
return new Org(this.csc.sessionMgr, orgId ?? this.csc.orgId);
|
|
355
217
|
}
|
|
356
218
|
|
|
357
219
|
/**
|
|
@@ -360,19 +222,14 @@ export class CubeSigner {
|
|
|
360
222
|
* @param {string} keyId - Key id
|
|
361
223
|
*/
|
|
362
224
|
async deleteKey(orgId: string, keyId: string) {
|
|
363
|
-
|
|
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);
|
|
225
|
+
await this.csc.withOrg(orgId).keyDelete(keyId);
|
|
370
226
|
}
|
|
371
227
|
|
|
372
|
-
/**
|
|
228
|
+
/**
|
|
229
|
+
* Get the management client.
|
|
373
230
|
* @return {Client} The client.
|
|
374
231
|
* @internal
|
|
375
|
-
|
|
232
|
+
*/
|
|
376
233
|
async management(): Promise<Client> {
|
|
377
234
|
if (!this.sessionMgr) {
|
|
378
235
|
throw new Error("No management session loaded");
|
|
@@ -387,12 +244,7 @@ export class CubeSigner {
|
|
|
387
244
|
* @return {Promise<IdentityProof>} Proof of authentication
|
|
388
245
|
*/
|
|
389
246
|
async proveIdentity(orgId: string): Promise<IdentityProof> {
|
|
390
|
-
|
|
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);
|
|
247
|
+
return await this.csc.withOrg(orgId).identityProve();
|
|
396
248
|
}
|
|
397
249
|
|
|
398
250
|
/**
|
|
@@ -403,17 +255,8 @@ export class CubeSigner {
|
|
|
403
255
|
* @return {Promise<IdentityProof>} Proof of authentication
|
|
404
256
|
*/
|
|
405
257
|
async oidcProveIdentity(oidcToken: string, orgId: string): Promise<IdentityProof> {
|
|
406
|
-
const
|
|
407
|
-
|
|
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);
|
|
258
|
+
const oidcClient = new OidcClient(this.#env, orgId, oidcToken);
|
|
259
|
+
return await oidcClient.identityProve();
|
|
417
260
|
}
|
|
418
261
|
|
|
419
262
|
/**
|
|
@@ -423,14 +266,7 @@ export class CubeSigner {
|
|
|
423
266
|
* @param {IdentityProof} identityProof The proof of authentication.
|
|
424
267
|
*/
|
|
425
268
|
async verifyIdentity(orgId: string, identityProof: IdentityProof) {
|
|
426
|
-
|
|
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);
|
|
269
|
+
await this.csc.withOrg(orgId).identityVerify(identityProof);
|
|
434
270
|
}
|
|
435
271
|
|
|
436
272
|
/**
|
|
@@ -440,7 +276,7 @@ export class CubeSigner {
|
|
|
440
276
|
* @param {List<string>} scopes The scopes of the resulting session
|
|
441
277
|
* @param {RatchetConfig} lifetimes Lifetimes of the new session.
|
|
442
278
|
* @param {MfaReceipt} mfaReceipt Optional MFA receipt (id + confirmation code)
|
|
443
|
-
* @return {Promise<
|
|
279
|
+
* @return {Promise<CubeSignerResponse<SignerSessionData>>} The session data.
|
|
444
280
|
*/
|
|
445
281
|
async oidcLogin(
|
|
446
282
|
oidcToken: string,
|
|
@@ -448,41 +284,16 @@ export class CubeSigner {
|
|
|
448
284
|
scopes: Array<string>,
|
|
449
285
|
lifetimes?: RatchetConfig,
|
|
450
286
|
mfaReceipt?: MfaReceipt,
|
|
451
|
-
): Promise<
|
|
452
|
-
const
|
|
453
|
-
|
|
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));
|
|
287
|
+
): Promise<CubeSignerResponse<SignerSessionData>> {
|
|
288
|
+
const oidcClient = new OidcClient(this.#env, orgId, oidcToken);
|
|
289
|
+
return await oidcClient.sessionCreate(scopes, lifetimes, mfaReceipt);
|
|
473
290
|
}
|
|
474
291
|
}
|
|
475
292
|
|
|
476
|
-
/**
|
|
477
|
-
export
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
/** Corresponding org ID */
|
|
481
|
-
mfaOrgId: string;
|
|
482
|
-
/** MFA confirmation code */
|
|
483
|
-
mfaConf: string;
|
|
484
|
-
}
|
|
485
|
-
|
|
293
|
+
/** API */
|
|
294
|
+
export * from "./api";
|
|
295
|
+
/** Client */
|
|
296
|
+
export * from "./client";
|
|
486
297
|
/** Organizations */
|
|
487
298
|
export * from "./org";
|
|
488
299
|
/** Keys */
|
|
@@ -492,9 +303,13 @@ export * from "./role";
|
|
|
492
303
|
/** Env */
|
|
493
304
|
export * from "./env";
|
|
494
305
|
/** Fido */
|
|
495
|
-
export * from "./
|
|
306
|
+
export * from "./mfa";
|
|
496
307
|
/** Pagination */
|
|
497
308
|
export * from "./paginator";
|
|
309
|
+
/** Response */
|
|
310
|
+
export * from "./response";
|
|
311
|
+
/** Types */
|
|
312
|
+
export * from "./schema_types";
|
|
498
313
|
/** Sessions */
|
|
499
314
|
export * from "./signer_session";
|
|
500
315
|
/** Session storage */
|
|
@@ -505,5 +320,13 @@ export * from "./session/session_manager";
|
|
|
505
320
|
export * from "./session/cognito_manager";
|
|
506
321
|
/** Signer session manager */
|
|
507
322
|
export * from "./session/signer_session_manager";
|
|
323
|
+
/** User-export decryption helper */
|
|
324
|
+
export { userExportDecrypt, userExportKeygen } from "./user_export";
|
|
508
325
|
/** Export ethers.js Signer */
|
|
509
326
|
export * as ethers from "./ethers";
|
|
327
|
+
|
|
328
|
+
/** CubeSigner SDK package name */
|
|
329
|
+
export const NAME: string = name;
|
|
330
|
+
|
|
331
|
+
/** CubeSigner SDK version */
|
|
332
|
+
export const VERSION: string = version;
|