@witnium-tech/witniumchain 0.11.0 → 0.12.0
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/FRONTEND-INTEGRATION.md +34 -8
- package/README.md +15 -5
- package/dist/index.d.mts +2033 -573
- package/dist/index.d.ts +2033 -573
- package/dist/index.js +72 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -177,9 +177,10 @@ var WitniumchainClient = class {
|
|
|
177
177
|
* the contract with the caller's client-generated `ownerPublicKey` +
|
|
178
178
|
* `initialSigningPublicKey`. Witnium never sees the private bytes.
|
|
179
179
|
*
|
|
180
|
-
* Returns `{ orgId, userId, contractAddress, contractVersion
|
|
181
|
-
*
|
|
182
|
-
*
|
|
180
|
+
* Returns `{ orgId, userId, contractAddress, contractVersion }`. The
|
|
181
|
+
* email-verify link is mailed to `adminEmail` and never returned, so there
|
|
182
|
+
* is nothing to render. If the mail cannot be sent, nothing is created and
|
|
183
|
+
* the call fails with a 502; retry it.
|
|
183
184
|
*/
|
|
184
185
|
createOrg(body) {
|
|
185
186
|
return this.req("POST", "/v1/orgs", { auth: "Public", body });
|
|
@@ -237,11 +238,36 @@ var WitniumchainClient = class {
|
|
|
237
238
|
query: { token }
|
|
238
239
|
});
|
|
239
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Password login. Check `status`: `'authenticated'` means the session
|
|
243
|
+
* cookie is set. `'mfa_required'` means NO session exists yet: the server
|
|
244
|
+
* set a short-lived challenge cookie, and {@link loginMfa} must follow with
|
|
245
|
+
* the user's TOTP or recovery code.
|
|
246
|
+
*/
|
|
240
247
|
login(body) {
|
|
241
248
|
return this.req("POST", "/v1/auth/login", { auth: "Public", body });
|
|
242
249
|
}
|
|
243
|
-
|
|
244
|
-
|
|
250
|
+
/**
|
|
251
|
+
* Second step of an MFA login, after `login()` returned `'mfa_required'`.
|
|
252
|
+
* Relies on the challenge cookie from that call (`credentials: 'include'`).
|
|
253
|
+
* 401 `mfa_code_invalid`: wrong or reused code, the user may retry.
|
|
254
|
+
* 401 `mfa_challenge_invalid`: expired or used up, start again at `login()`.
|
|
255
|
+
* 429 `mfa_rate_limited`: the body carries `retryAfterSeconds`.
|
|
256
|
+
*/
|
|
257
|
+
loginMfa(body) {
|
|
258
|
+
return this.req("POST", "/v1/auth/login/mfa", { auth: "Public", body });
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* End the first-party session. The cached bearer token is dropped even when
|
|
262
|
+
* the request fails, so a logged-out tab never keeps the previous user's
|
|
263
|
+
* token.
|
|
264
|
+
*/
|
|
265
|
+
async logout() {
|
|
266
|
+
try {
|
|
267
|
+
return await this.req("POST", "/v1/auth/logout", { auth: "Public" });
|
|
268
|
+
} finally {
|
|
269
|
+
this.signOut();
|
|
270
|
+
}
|
|
245
271
|
}
|
|
246
272
|
forgotPassword(body) {
|
|
247
273
|
return this.req("POST", "/v1/auth/forgot-password", { auth: "Public", body });
|
|
@@ -474,20 +500,34 @@ var WitniumchainClient = class {
|
|
|
474
500
|
auth: "SessionCookie"
|
|
475
501
|
});
|
|
476
502
|
}
|
|
477
|
-
|
|
478
|
-
|
|
503
|
+
/**
|
|
504
|
+
* Confirming bumps the user's security epoch server-side, which ends every
|
|
505
|
+
* session-minted access token. A cached one is dropped so the next bearer
|
|
506
|
+
* call mints a fresh token.
|
|
507
|
+
*/
|
|
508
|
+
async confirmTotp(body) {
|
|
509
|
+
const res = await this.req("POST", "/v1/account/mfa/totp/confirm", {
|
|
479
510
|
auth: "SessionCookie",
|
|
480
511
|
body
|
|
481
512
|
});
|
|
513
|
+
if (this.accessTokenFromSession) {
|
|
514
|
+
this.accessToken = void 0;
|
|
515
|
+
this.accessTokenFromSession = false;
|
|
516
|
+
}
|
|
517
|
+
return res;
|
|
482
518
|
}
|
|
483
|
-
|
|
519
|
+
/** Step-up: 403 `mfa_step_up_failed` on a wrong proof, 429 `mfa_rate_limited`. */
|
|
520
|
+
disableTotp(body) {
|
|
484
521
|
return this.req("DELETE", "/v1/account/mfa/totp", {
|
|
485
|
-
auth: "SessionCookie"
|
|
522
|
+
auth: "SessionCookie",
|
|
523
|
+
body
|
|
486
524
|
});
|
|
487
525
|
}
|
|
488
|
-
|
|
526
|
+
/** Step-up: 403 `mfa_step_up_failed` on a wrong proof, 429 `mfa_rate_limited`. */
|
|
527
|
+
regenerateRecoveryCodes(body) {
|
|
489
528
|
return this.req("POST", "/v1/account/mfa/recovery-codes/regenerate", {
|
|
490
|
-
auth: "SessionCookie"
|
|
529
|
+
auth: "SessionCookie",
|
|
530
|
+
body
|
|
491
531
|
});
|
|
492
532
|
}
|
|
493
533
|
// ────────────────────────────────────────────────────────────────────────
|
|
@@ -1352,7 +1392,12 @@ var OrgMembers = class {
|
|
|
1352
1392
|
list() {
|
|
1353
1393
|
return this.client.listMembers();
|
|
1354
1394
|
}
|
|
1355
|
-
/**
|
|
1395
|
+
/**
|
|
1396
|
+
* Invite a member by email (default role `member`). `inviteEmailSent` says
|
|
1397
|
+
* whether the invitation (with the verify link) was mailed; the token is
|
|
1398
|
+
* never returned. A 502 means the membership was recorded but the mail
|
|
1399
|
+
* failed; retry.
|
|
1400
|
+
*/
|
|
1356
1401
|
invite(body) {
|
|
1357
1402
|
return this.client.inviteMember(body);
|
|
1358
1403
|
}
|
|
@@ -1372,7 +1417,10 @@ var OrgMembers = class {
|
|
|
1372
1417
|
remove(userId) {
|
|
1373
1418
|
return this.client.removeMember(userId);
|
|
1374
1419
|
}
|
|
1375
|
-
/**
|
|
1420
|
+
/**
|
|
1421
|
+
* Re-send the invitation email to a pending member. Returns `{ email }`;
|
|
1422
|
+
* the fresh verify token is mailed, never returned.
|
|
1423
|
+
*/
|
|
1376
1424
|
resendInvite(userId) {
|
|
1377
1425
|
return this.client.resendMemberInvite(userId);
|
|
1378
1426
|
}
|
|
@@ -1396,14 +1444,18 @@ var MfaTotp = class {
|
|
|
1396
1444
|
* Confirm enrolment with the first user-supplied code. Returns the 10
|
|
1397
1445
|
* single-use recovery codes — show them to the user ONCE; the server never
|
|
1398
1446
|
* returns them again. Throws `WitniumchainApiError` with status 400 when
|
|
1399
|
-
* the code is invalid or the enrolment is already confirmed.
|
|
1447
|
+
* the code is invalid or the enrolment is already confirmed. Signs the
|
|
1448
|
+
* user out of every other device and connected app.
|
|
1400
1449
|
*/
|
|
1401
1450
|
confirm(code) {
|
|
1402
1451
|
return this.client.confirmTotp({ code });
|
|
1403
1452
|
}
|
|
1404
|
-
/**
|
|
1405
|
-
|
|
1406
|
-
|
|
1453
|
+
/**
|
|
1454
|
+
* Disable TOTP, wiping both the secret and all recovery codes. Requires the
|
|
1455
|
+
* user's current code or a recovery code.
|
|
1456
|
+
*/
|
|
1457
|
+
disable(proof) {
|
|
1458
|
+
return this.client.disableTotp(proof);
|
|
1407
1459
|
}
|
|
1408
1460
|
};
|
|
1409
1461
|
var MfaRecoveryCodes = class {
|
|
@@ -1414,9 +1466,10 @@ var MfaRecoveryCodes = class {
|
|
|
1414
1466
|
/**
|
|
1415
1467
|
* Issue a fresh set of 10 recovery codes, invalidating the prior ones.
|
|
1416
1468
|
* Same as `confirm` — codes are returned ONCE and never readable again.
|
|
1469
|
+
* Requires the user's current code or a recovery code.
|
|
1417
1470
|
*/
|
|
1418
|
-
regenerate() {
|
|
1419
|
-
return this.client.regenerateRecoveryCodes();
|
|
1471
|
+
regenerate(proof) {
|
|
1472
|
+
return this.client.regenerateRecoveryCodes(proof);
|
|
1420
1473
|
}
|
|
1421
1474
|
};
|
|
1422
1475
|
function sleep(ms) {
|