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