@witnium-tech/witniumchain 0.10.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 +1827 -356
- package/dist/index.d.ts +1827 -356
- package/dist/index.js +72 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -120
- 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 });
|
|
@@ -273,43 +299,6 @@ var WitniumchainClient = class {
|
|
|
273
299
|
return this.req("GET", "/v1/orgs/me/users", { auth: "OrgApiKey" });
|
|
274
300
|
}
|
|
275
301
|
// ────────────────────────────────────────────────────────────────────────
|
|
276
|
-
// Admin (/v1/admin/organizations/*)
|
|
277
|
-
// ────────────────────────────────────────────────────────────────────────
|
|
278
|
-
createOrganization(body) {
|
|
279
|
-
return this.req("POST", "/v1/admin/organizations", {
|
|
280
|
-
auth: "AdminToken",
|
|
281
|
-
body
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
setOrgAccountType(id, body) {
|
|
285
|
-
return this.req(
|
|
286
|
-
"PATCH",
|
|
287
|
-
`/v1/admin/organizations/${encodeURIComponent(id)}/account-type`,
|
|
288
|
-
{ auth: "AdminToken", body }
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
verifyOrganization(id) {
|
|
292
|
-
return this.req(
|
|
293
|
-
"PATCH",
|
|
294
|
-
`/v1/admin/organizations/${encodeURIComponent(id)}/verify`,
|
|
295
|
-
{ auth: "AdminToken" }
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
rotateOrgApiKey(id) {
|
|
299
|
-
return this.req(
|
|
300
|
-
"POST",
|
|
301
|
-
`/v1/admin/organizations/${encodeURIComponent(id)}/rotate-key`,
|
|
302
|
-
{ auth: "AdminToken" }
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
adjustOrgCredits(id, body) {
|
|
306
|
-
return this.req(
|
|
307
|
-
"POST",
|
|
308
|
-
`/v1/admin/organizations/${encodeURIComponent(id)}/adjust-credits`,
|
|
309
|
-
{ auth: "AdminToken", body }
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
// ────────────────────────────────────────────────────────────────────────
|
|
313
302
|
// Delegated keys (/v1/users/me/delegated-keys/*)
|
|
314
303
|
// ────────────────────────────────────────────────────────────────────────
|
|
315
304
|
listDelegatedKeys(query) {
|
|
@@ -509,20 +498,34 @@ var WitniumchainClient = class {
|
|
|
509
498
|
auth: "SessionCookie"
|
|
510
499
|
});
|
|
511
500
|
}
|
|
512
|
-
|
|
513
|
-
|
|
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", {
|
|
514
508
|
auth: "SessionCookie",
|
|
515
509
|
body
|
|
516
510
|
});
|
|
511
|
+
if (this.accessTokenFromSession) {
|
|
512
|
+
this.accessToken = void 0;
|
|
513
|
+
this.accessTokenFromSession = false;
|
|
514
|
+
}
|
|
515
|
+
return res;
|
|
517
516
|
}
|
|
518
|
-
|
|
517
|
+
/** Step-up: 403 `mfa_step_up_failed` on a wrong proof, 429 `mfa_rate_limited`. */
|
|
518
|
+
disableTotp(body) {
|
|
519
519
|
return this.req("DELETE", "/v1/account/mfa/totp", {
|
|
520
|
-
auth: "SessionCookie"
|
|
520
|
+
auth: "SessionCookie",
|
|
521
|
+
body
|
|
521
522
|
});
|
|
522
523
|
}
|
|
523
|
-
|
|
524
|
+
/** Step-up: 403 `mfa_step_up_failed` on a wrong proof, 429 `mfa_rate_limited`. */
|
|
525
|
+
regenerateRecoveryCodes(body) {
|
|
524
526
|
return this.req("POST", "/v1/account/mfa/recovery-codes/regenerate", {
|
|
525
|
-
auth: "SessionCookie"
|
|
527
|
+
auth: "SessionCookie",
|
|
528
|
+
body
|
|
526
529
|
});
|
|
527
530
|
}
|
|
528
531
|
// ────────────────────────────────────────────────────────────────────────
|
|
@@ -1199,15 +1202,6 @@ var WitniumchainClient = class {
|
|
|
1199
1202
|
headers["authorization"] = `Bearer ${this.cfg.orgApiKey}`;
|
|
1200
1203
|
return;
|
|
1201
1204
|
}
|
|
1202
|
-
case "AdminToken": {
|
|
1203
|
-
if (!this.cfg.adminToken) {
|
|
1204
|
-
throw new Error(
|
|
1205
|
-
`WitniumchainClient: ${method} ${path} requires an admin token. Pass \`adminToken\` to the constructor.`
|
|
1206
|
-
);
|
|
1207
|
-
}
|
|
1208
|
-
headers["authorization"] = `Bearer ${this.cfg.adminToken}`;
|
|
1209
|
-
return;
|
|
1210
|
-
}
|
|
1211
1205
|
case "SignedRequest": {
|
|
1212
1206
|
if (!this.cfg.signedRequest) {
|
|
1213
1207
|
throw new Error(
|
|
@@ -1396,7 +1390,12 @@ var OrgMembers = class {
|
|
|
1396
1390
|
list() {
|
|
1397
1391
|
return this.client.listMembers();
|
|
1398
1392
|
}
|
|
1399
|
-
/**
|
|
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
|
+
*/
|
|
1400
1399
|
invite(body) {
|
|
1401
1400
|
return this.client.inviteMember(body);
|
|
1402
1401
|
}
|
|
@@ -1416,7 +1415,10 @@ var OrgMembers = class {
|
|
|
1416
1415
|
remove(userId) {
|
|
1417
1416
|
return this.client.removeMember(userId);
|
|
1418
1417
|
}
|
|
1419
|
-
/**
|
|
1418
|
+
/**
|
|
1419
|
+
* Re-send the invitation email to a pending member. Returns `{ email }`;
|
|
1420
|
+
* the fresh verify token is mailed, never returned.
|
|
1421
|
+
*/
|
|
1420
1422
|
resendInvite(userId) {
|
|
1421
1423
|
return this.client.resendMemberInvite(userId);
|
|
1422
1424
|
}
|
|
@@ -1440,14 +1442,18 @@ var MfaTotp = class {
|
|
|
1440
1442
|
* Confirm enrolment with the first user-supplied code. Returns the 10
|
|
1441
1443
|
* single-use recovery codes — show them to the user ONCE; the server never
|
|
1442
1444
|
* returns them again. Throws `WitniumchainApiError` with status 400 when
|
|
1443
|
-
* 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.
|
|
1444
1447
|
*/
|
|
1445
1448
|
confirm(code) {
|
|
1446
1449
|
return this.client.confirmTotp({ code });
|
|
1447
1450
|
}
|
|
1448
|
-
/**
|
|
1449
|
-
|
|
1450
|
-
|
|
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);
|
|
1451
1457
|
}
|
|
1452
1458
|
};
|
|
1453
1459
|
var MfaRecoveryCodes = class {
|
|
@@ -1458,9 +1464,10 @@ var MfaRecoveryCodes = class {
|
|
|
1458
1464
|
/**
|
|
1459
1465
|
* Issue a fresh set of 10 recovery codes, invalidating the prior ones.
|
|
1460
1466
|
* Same as `confirm` — codes are returned ONCE and never readable again.
|
|
1467
|
+
* Requires the user's current code or a recovery code.
|
|
1461
1468
|
*/
|
|
1462
|
-
regenerate() {
|
|
1463
|
-
return this.client.regenerateRecoveryCodes();
|
|
1469
|
+
regenerate(proof) {
|
|
1470
|
+
return this.client.regenerateRecoveryCodes(proof);
|
|
1464
1471
|
}
|
|
1465
1472
|
};
|
|
1466
1473
|
function sleep(ms) {
|
|
@@ -1494,60 +1501,6 @@ async function sha256Hex(input) {
|
|
|
1494
1501
|
return out;
|
|
1495
1502
|
}
|
|
1496
1503
|
|
|
1497
|
-
// src/admin-client.ts
|
|
1498
|
-
var WitniumchainAdminClient = class {
|
|
1499
|
-
inner;
|
|
1500
|
-
constructor(config) {
|
|
1501
|
-
if (!config.adminToken) {
|
|
1502
|
-
throw new Error("WitniumchainAdminClient: adminToken is required");
|
|
1503
|
-
}
|
|
1504
|
-
this.inner = new WitniumchainClient({
|
|
1505
|
-
baseUrl: config.baseUrl,
|
|
1506
|
-
adminToken: config.adminToken,
|
|
1507
|
-
timeout: config.timeout,
|
|
1508
|
-
fetch: config.fetch
|
|
1509
|
-
});
|
|
1510
|
-
}
|
|
1511
|
-
/**
|
|
1512
|
-
* Mint a new organisation. The returned `apiKey` is shown ONCE — the server
|
|
1513
|
-
* only retains its SHA-256 hash. Persist it before the response leaves
|
|
1514
|
-
* scope; there is no recovery path.
|
|
1515
|
-
*
|
|
1516
|
-
* @param body Organisation seed: name, email, optional accountType and
|
|
1517
|
-
* signup credit grant, optional skip-email-verification flag.
|
|
1518
|
-
*/
|
|
1519
|
-
createOrganization(body) {
|
|
1520
|
-
return this.inner.createOrganization(body);
|
|
1521
|
-
}
|
|
1522
|
-
/** Flip an org between `metered` (Stripe checkout + credit ledger) and `unlimited` (flat-fee). */
|
|
1523
|
-
setAccountType(orgId, accountType) {
|
|
1524
|
-
return this.inner.setOrgAccountType(orgId, { accountType });
|
|
1525
|
-
}
|
|
1526
|
-
/** Mark an org's email as verified. Prerequisite for the org to create users. */
|
|
1527
|
-
verifyEmail(orgId) {
|
|
1528
|
-
return this.inner.verifyOrganization(orgId);
|
|
1529
|
-
}
|
|
1530
|
-
/**
|
|
1531
|
-
* Rotate the org's API key. The previous `wcorg_live_…` is invalidated and
|
|
1532
|
-
* the new key is returned ONCE — same one-time-secret semantics as
|
|
1533
|
-
* {@link createOrganization}.
|
|
1534
|
-
*/
|
|
1535
|
-
rotateApiKey(orgId) {
|
|
1536
|
-
return this.inner.rotateOrgApiKey(orgId);
|
|
1537
|
-
}
|
|
1538
|
-
/**
|
|
1539
|
-
* Apply a signed credit delta to an org's ledger. Positive `delta` grants
|
|
1540
|
-
* credits (goodwill, migration backfill); negative claws them back.
|
|
1541
|
-
* Recorded as `reason: adjustment` with the supplied `note`.
|
|
1542
|
-
*
|
|
1543
|
-
* Use sparingly — this bypasses Stripe and should be auditable from the
|
|
1544
|
-
* `note` alone.
|
|
1545
|
-
*/
|
|
1546
|
-
adjustCredits(orgId, delta, note) {
|
|
1547
|
-
return this.inner.adjustOrgCredits(orgId, { delta, note });
|
|
1548
|
-
}
|
|
1549
|
-
};
|
|
1550
|
-
|
|
1551
1504
|
// src/chain-admin-client.ts
|
|
1552
1505
|
var WitniumchainChainAdminClient = class {
|
|
1553
1506
|
baseUrl;
|
|
@@ -1738,6 +1691,6 @@ function buildRevokeSigningKeyPayload(args) {
|
|
|
1738
1691
|
});
|
|
1739
1692
|
}
|
|
1740
1693
|
|
|
1741
|
-
export { DelegatedKeys, MfaNamespace, MfaRecoveryCodes, MfaTotp, OWNER_OP, OauthNamespace, OauthSessions, OrgMembers, OrgUsers, SigningKeys, Subscriptions,
|
|
1694
|
+
export { DelegatedKeys, MfaNamespace, MfaRecoveryCodes, MfaTotp, OWNER_OP, OauthNamespace, OauthSessions, OrgMembers, OrgUsers, SigningKeys, Subscriptions, WitniumchainApiError, WitniumchainChainAdminClient, WitniumchainClient, WitniumchainOrgClient, buildAddSigningKeyPayload, buildPausePayload, buildRevokeSigningKeyPayload, buildUnpausePayload, defaultVerifierStorage };
|
|
1742
1695
|
//# sourceMappingURL=index.mjs.map
|
|
1743
1696
|
//# sourceMappingURL=index.mjs.map
|