@witnium-tech/witniumchain 0.9.0 → 0.11.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 +30 -0
- package/dist/index.d.mts +116 -68
- package/dist/index.d.ts +116 -68
- package/dist/index.js +99 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -115
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/FRONTEND-INTEGRATION.md
CHANGED
|
@@ -118,6 +118,36 @@ await client.login({ email, password }); // sets wac_session cookie
|
|
|
118
118
|
In a browser the `wac_session` cookie is set automatically (the SDK uses
|
|
119
119
|
`credentials: 'include'`). Server-side callers must capture + replay the cookie.
|
|
120
120
|
|
|
121
|
+
### Cookie-only dashboard → bearer calls (automatic, no OAuth needed)
|
|
122
|
+
|
|
123
|
+
You do **not** need to run the OAuth code flow to call the operational API
|
|
124
|
+
(delegated keys, witness writes, chain reads). After `login()`, just call them:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
await client.login({ email, password }); // sets wac_session
|
|
128
|
+
await client.listDelegatedKeys(); // ← works; SDK mints a bearer token
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
How: those endpoints are bearer-only (they never accept the ambient cookie, so
|
|
132
|
+
there's **no CSRF surface** even with `SameSite=None`). On the first such call
|
|
133
|
+
the SDK transparently exchanges the session cookie for a short-lived access
|
|
134
|
+
token via `POST /v1/auth/access-token`, caches it, and re-mints on a 401. You
|
|
135
|
+
never see the token unless you want it:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
const { accessToken, expiresAt } = await client.exchangeSessionForToken(); // optional pre-warm
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Requirements: in the browser the `wac_session` cookie rides automatically
|
|
142
|
+
(`credentials: 'include'`). Node/SSR callers pass `sessionCookie: '<value>'` to
|
|
143
|
+
the constructor. If there's no valid session, the call throws a descriptive
|
|
144
|
+
"requires an OAuth access token … or provide `sessionCookie`" error — that's
|
|
145
|
+
your cue to send the user back to login.
|
|
146
|
+
|
|
147
|
+
This is the recommended path for a first-party dashboard. Reach for the full
|
|
148
|
+
OAuth flow below only when the dashboard is itself a registered OAuth client
|
|
149
|
+
(e.g. third-party apps, or you want long-lived refresh tokens).
|
|
150
|
+
|
|
121
151
|
### Magic-link sign-in
|
|
122
152
|
|
|
123
153
|
`beginOAuthLogin` / passwordless paths exist; see the SDK's `OauthNamespace`
|
package/dist/index.d.mts
CHANGED
|
@@ -242,6 +242,76 @@ interface paths$1 {
|
|
|
242
242
|
patch?: never;
|
|
243
243
|
trace?: never;
|
|
244
244
|
};
|
|
245
|
+
"/v1/auth/access-token": {
|
|
246
|
+
parameters: {
|
|
247
|
+
query?: never;
|
|
248
|
+
header?: never;
|
|
249
|
+
path?: never;
|
|
250
|
+
cookie?: never;
|
|
251
|
+
};
|
|
252
|
+
get?: never;
|
|
253
|
+
put?: never;
|
|
254
|
+
/**
|
|
255
|
+
* Exchange the session cookie for a bearer access token
|
|
256
|
+
* @description A logged-in (wac_session) user mints a short-lived OAuth-equivalent access token to call the bearer-only operational API (delegated keys, witness writes, chain reads). Keeps those endpoints off the ambient cookie (no CSRF surface). Same claim shape as an OAuth user token.
|
|
257
|
+
*/
|
|
258
|
+
post: {
|
|
259
|
+
parameters: {
|
|
260
|
+
query?: never;
|
|
261
|
+
header?: never;
|
|
262
|
+
path?: never;
|
|
263
|
+
cookie?: never;
|
|
264
|
+
};
|
|
265
|
+
requestBody?: never;
|
|
266
|
+
responses: {
|
|
267
|
+
/** @description Success */
|
|
268
|
+
200: {
|
|
269
|
+
headers: {
|
|
270
|
+
[name: string]: unknown;
|
|
271
|
+
};
|
|
272
|
+
content: {
|
|
273
|
+
"application/json": {
|
|
274
|
+
accessToken: string;
|
|
275
|
+
/** @enum {string} */
|
|
276
|
+
tokenType: "Bearer";
|
|
277
|
+
expiresIn: number;
|
|
278
|
+
expiresAt: string;
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
/** @description Unauthorized — authentication required or invalid */
|
|
283
|
+
401: {
|
|
284
|
+
headers: {
|
|
285
|
+
[name: string]: unknown;
|
|
286
|
+
};
|
|
287
|
+
content: {
|
|
288
|
+
"application/json": {
|
|
289
|
+
/**
|
|
290
|
+
* @description HTTP status code
|
|
291
|
+
* @example 400
|
|
292
|
+
*/
|
|
293
|
+
statusCode?: number;
|
|
294
|
+
/**
|
|
295
|
+
* @description Short error label
|
|
296
|
+
* @example Bad Request
|
|
297
|
+
*/
|
|
298
|
+
error?: string;
|
|
299
|
+
/**
|
|
300
|
+
* @description Human-readable error message. Validation errors from `ZodError.flatten()` may be returned as an array.
|
|
301
|
+
* @example Validation failed
|
|
302
|
+
*/
|
|
303
|
+
message: string | string[];
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
delete?: never;
|
|
310
|
+
options?: never;
|
|
311
|
+
head?: never;
|
|
312
|
+
patch?: never;
|
|
313
|
+
trace?: never;
|
|
314
|
+
};
|
|
245
315
|
"/v1/auth/login": {
|
|
246
316
|
parameters: {
|
|
247
317
|
query?: never;
|
|
@@ -10296,14 +10366,6 @@ type SetMemberRoleRequest = Req<'/v1/orgs/me/members/{userId}/role', 'put'>;
|
|
|
10296
10366
|
type SetMemberRoleResponse = Res<'/v1/orgs/me/members/{userId}/role', 'put'>;
|
|
10297
10367
|
type RemoveMemberResponse = Res<'/v1/orgs/me/members/{userId}', 'delete'>;
|
|
10298
10368
|
type ResendInviteResponse = Res<'/v1/orgs/me/members/{userId}/resend-invite', 'post'>;
|
|
10299
|
-
type CreateOrganizationRequest = Req<'/v1/admin/organizations', 'post'>;
|
|
10300
|
-
type CreateOrganizationResponse = Res<'/v1/admin/organizations', 'post'>;
|
|
10301
|
-
type SetAccountTypeRequest = Req<'/v1/admin/organizations/{id}/account-type', 'patch'>;
|
|
10302
|
-
type SetAccountTypeResponse = Res<'/v1/admin/organizations/{id}/account-type', 'patch'>;
|
|
10303
|
-
type VerifyOrganizationResponse = Res<'/v1/admin/organizations/{id}/verify', 'patch'>;
|
|
10304
|
-
type RotateApiKeyResponse = Res<'/v1/admin/organizations/{id}/rotate-key', 'post'>;
|
|
10305
|
-
type AdjustCreditsRequest = Req<'/v1/admin/organizations/{id}/adjust-credits', 'post'>;
|
|
10306
|
-
type AdjustCreditsResponse = Res<'/v1/admin/organizations/{id}/adjust-credits', 'post'>;
|
|
10307
10369
|
type ListDelegatedKeysResponse = Res<'/v1/users/me/delegated-keys', 'get'>;
|
|
10308
10370
|
type PrepareDelegatedKeyRequest = Req<'/v1/users/me/delegated-keys', 'post'>;
|
|
10309
10371
|
type PreparedDelegatedKeyResponse = Res<'/v1/users/me/delegated-keys', 'post'>;
|
|
@@ -10364,10 +10426,11 @@ type DashboardWitnessesResponse = ChainRes<'/v5/dashboard/witnesses', 'get'>;
|
|
|
10364
10426
|
*
|
|
10365
10427
|
* Covers both accounts (identity / billing / OAuth / delegated keys / witness
|
|
10366
10428
|
* writes via the metered v5 proxy) and chain-api read surfaces (contract
|
|
10367
|
-
* info / witness lookup / wallet balance / dashboards).
|
|
10368
|
-
* clients layer on top — `WitniumchainClient` (end-user)
|
|
10369
|
-
* `WitniumchainOrgClient` (org admin)
|
|
10370
|
-
*
|
|
10429
|
+
* info / witness lookup / wallet balance / dashboards). Two convenience
|
|
10430
|
+
* clients layer on top — `WitniumchainClient` (end-user) and
|
|
10431
|
+
* `WitniumchainOrgClient` (org admin) — with helpers for signup,
|
|
10432
|
+
* subscriptions, and delegated-key provisioning. The sysadmin surface lives in
|
|
10433
|
+
* the separate PRIVATE `@witnium/chain-admin-sdk` package, not here.
|
|
10371
10434
|
*
|
|
10372
10435
|
* Stripe surface is intentionally Checkout + Customer Portal ONLY. Witnium is
|
|
10373
10436
|
* not a marketplace, so there is no Stripe Connect onboarding.
|
|
@@ -10379,7 +10442,6 @@ type DashboardWitnessesResponse = ChainRes<'/v5/dashboard/witnesses', 'get'>;
|
|
|
10379
10442
|
* - sessionCookie — `wac_session` value for browser-cookie routes.
|
|
10380
10443
|
* - accessToken — OAuth Bearer JWT for end-user API.
|
|
10381
10444
|
* - orgApiKey — `wcorg_live_…` for org admin.
|
|
10382
|
-
* - adminToken — sysadmin token.
|
|
10383
10445
|
* - signedRequest — Ed25519 signer for SDK signed-request routes
|
|
10384
10446
|
* (witnesses propose/sign/finalize/revoke). The SDK
|
|
10385
10447
|
* does the canonical-message construction; you supply
|
|
@@ -10505,8 +10567,6 @@ interface WitniumchainClientConfig {
|
|
|
10505
10567
|
verifierStorage?: PkceVerifierStorage;
|
|
10506
10568
|
/** Organisation API key (`wcorg_live_…`). */
|
|
10507
10569
|
orgApiKey?: string;
|
|
10508
|
-
/** System-admin token (`Authorization: Bearer <ADMIN_TOKEN>`). */
|
|
10509
|
-
adminToken?: string;
|
|
10510
10570
|
/** Ed25519 signer for SDK signed-request routes (witness write ops). */
|
|
10511
10571
|
signedRequest?: SignedRequestSigner;
|
|
10512
10572
|
/** Per-request timeout in milliseconds. Default 30000. */
|
|
@@ -10580,6 +10640,8 @@ declare class WitniumchainClient {
|
|
|
10580
10640
|
private readonly verifierStorage;
|
|
10581
10641
|
private discoveryCache;
|
|
10582
10642
|
private refreshInFlight;
|
|
10643
|
+
private accessTokenFromSession;
|
|
10644
|
+
private sessionExchangeInFlight;
|
|
10583
10645
|
/** Subscriptions / billing helpers. See {@link Subscriptions}. */
|
|
10584
10646
|
readonly subscriptions: Subscriptions;
|
|
10585
10647
|
/** Delegated-key namespace including the one-call {@link DelegatedKeys.provision} flow. */
|
|
@@ -10629,11 +10691,6 @@ declare class WitniumchainClient {
|
|
|
10629
10691
|
getMyOrg(): Promise<PublicOrgResponse>;
|
|
10630
10692
|
createOrgUser(body: CreateUserRequest): Promise<CreateUserResponse>;
|
|
10631
10693
|
listOrgUsers(): Promise<ListUsersResponse>;
|
|
10632
|
-
createOrganization(body: CreateOrganizationRequest): Promise<CreateOrganizationResponse>;
|
|
10633
|
-
setOrgAccountType(id: string, body: SetAccountTypeRequest): Promise<SetAccountTypeResponse>;
|
|
10634
|
-
verifyOrganization(id: string): Promise<VerifyOrganizationResponse>;
|
|
10635
|
-
rotateOrgApiKey(id: string): Promise<RotateApiKeyResponse>;
|
|
10636
|
-
adjustOrgCredits(id: string, body: AdjustCreditsRequest): Promise<AdjustCreditsResponse>;
|
|
10637
10694
|
listDelegatedKeys(query?: {
|
|
10638
10695
|
contractAddress?: string;
|
|
10639
10696
|
active?: 'true' | 'false';
|
|
@@ -10754,6 +10811,41 @@ declare class WitniumchainClient {
|
|
|
10754
10811
|
* instead of retrying with a now-invalid token.
|
|
10755
10812
|
*/
|
|
10756
10813
|
refreshAccessToken(): Promise<OAuthTokenSnapshot>;
|
|
10814
|
+
/**
|
|
10815
|
+
* Exchange the logged-in session (the `wac_session` cookie) for a short-lived
|
|
10816
|
+
* bearer access token and cache it as the client's `accessToken`.
|
|
10817
|
+
*
|
|
10818
|
+
* This is the SDK side of the session→token model (accounts'
|
|
10819
|
+
* `POST /v1/auth/access-token`): the dashboard authenticates with the
|
|
10820
|
+
* cookie, but the operational API (delegated keys, witness writes, chain
|
|
10821
|
+
* reads) is bearer-only — no endpoint accepts the ambient cookie, so there's
|
|
10822
|
+
* no CSRF surface even with `SameSite=None`. The minted token is
|
|
10823
|
+
* byte-compatible with an OAuth user token (same signing key, `iss`, `aud`,
|
|
10824
|
+
* scope + org/role/contracts claims), so every `BearerJWT` route accepts it.
|
|
10825
|
+
*
|
|
10826
|
+
* Callers rarely invoke this directly — {@link applyAuth} mints transparently
|
|
10827
|
+
* on the first `BearerJWT` call when no token is set and re-mints on a 401.
|
|
10828
|
+
* It's exposed so a dashboard can pre-warm the token right after login.
|
|
10829
|
+
*
|
|
10830
|
+
* Requires a session: either `sessionCookie` on the constructor (Node) or an
|
|
10831
|
+
* ambient `wac_session` cookie carried by the browser (`credentials:
|
|
10832
|
+
* 'include'`). Throws {@link WitniumchainApiError} (401) when there's no
|
|
10833
|
+
* valid session.
|
|
10834
|
+
*/
|
|
10835
|
+
exchangeSessionForToken(): Promise<OAuthTokenSnapshot>;
|
|
10836
|
+
/**
|
|
10837
|
+
* Best-effort transparent mint for the `BearerJWT` path: if no access token
|
|
10838
|
+
* is cached, try the session exchange (single-flight). Swallows failure so
|
|
10839
|
+
* the caller in {@link applyAuth} surfaces the actionable "no token / no
|
|
10840
|
+
* session" guidance rather than a raw 401 from the exchange endpoint.
|
|
10841
|
+
*/
|
|
10842
|
+
private ensureSessionAccessToken;
|
|
10843
|
+
/**
|
|
10844
|
+
* Obtain a fresh access token for a 401-retry, picking the right mechanism:
|
|
10845
|
+
* an OAuth refresh when a refresh credential exists, else a session re-mint
|
|
10846
|
+
* for a session-exchanged token. Returns true when a fresh token is in hand.
|
|
10847
|
+
*/
|
|
10848
|
+
private reauthenticateForRetry;
|
|
10757
10849
|
/**
|
|
10758
10850
|
* End the OAuth session.
|
|
10759
10851
|
*
|
|
@@ -10968,50 +11060,6 @@ declare class MfaRecoveryCodes {
|
|
|
10968
11060
|
regenerate(): Promise<RecoveryCodesRegenerateResponse>;
|
|
10969
11061
|
}
|
|
10970
11062
|
|
|
10971
|
-
interface WitniumchainAdminClientConfig {
|
|
10972
|
-
/** Base URL, e.g. `https://auth.witniumchain.com`. Trailing slash optional. */
|
|
10973
|
-
baseUrl: string;
|
|
10974
|
-
/** System-admin token (`Authorization: Bearer <ADMIN_TOKEN>`). */
|
|
10975
|
-
adminToken: string;
|
|
10976
|
-
/** Per-request timeout in milliseconds. Default 30000. */
|
|
10977
|
-
timeout?: number;
|
|
10978
|
-
/** Alternate fetch implementation (e.g. for tests). Default `globalThis.fetch`. */
|
|
10979
|
-
fetch?: typeof fetch;
|
|
10980
|
-
}
|
|
10981
|
-
type AccountType = 'metered' | 'unlimited';
|
|
10982
|
-
declare class WitniumchainAdminClient {
|
|
10983
|
-
private readonly inner;
|
|
10984
|
-
constructor(config: WitniumchainAdminClientConfig);
|
|
10985
|
-
/**
|
|
10986
|
-
* Mint a new organisation. The returned `apiKey` is shown ONCE — the server
|
|
10987
|
-
* only retains its SHA-256 hash. Persist it before the response leaves
|
|
10988
|
-
* scope; there is no recovery path.
|
|
10989
|
-
*
|
|
10990
|
-
* @param body Organisation seed: name, email, optional accountType and
|
|
10991
|
-
* signup credit grant, optional skip-email-verification flag.
|
|
10992
|
-
*/
|
|
10993
|
-
createOrganization(body: CreateOrganizationRequest): Promise<CreateOrganizationResponse>;
|
|
10994
|
-
/** Flip an org between `metered` (Stripe checkout + credit ledger) and `unlimited` (flat-fee). */
|
|
10995
|
-
setAccountType(orgId: string, accountType: AccountType): Promise<SetAccountTypeResponse>;
|
|
10996
|
-
/** Mark an org's email as verified. Prerequisite for the org to create users. */
|
|
10997
|
-
verifyEmail(orgId: string): Promise<VerifyOrganizationResponse>;
|
|
10998
|
-
/**
|
|
10999
|
-
* Rotate the org's API key. The previous `wcorg_live_…` is invalidated and
|
|
11000
|
-
* the new key is returned ONCE — same one-time-secret semantics as
|
|
11001
|
-
* {@link createOrganization}.
|
|
11002
|
-
*/
|
|
11003
|
-
rotateApiKey(orgId: string): Promise<RotateApiKeyResponse>;
|
|
11004
|
-
/**
|
|
11005
|
-
* Apply a signed credit delta to an org's ledger. Positive `delta` grants
|
|
11006
|
-
* credits (goodwill, migration backfill); negative claws them back.
|
|
11007
|
-
* Recorded as `reason: adjustment` with the supplied `note`.
|
|
11008
|
-
*
|
|
11009
|
-
* Use sparingly — this bypasses Stripe and should be auditable from the
|
|
11010
|
-
* `note` alone.
|
|
11011
|
-
*/
|
|
11012
|
-
adjustCredits(orgId: string, delta: number, note?: string): Promise<AdjustCreditsResponse>;
|
|
11013
|
-
}
|
|
11014
|
-
|
|
11015
11063
|
type Body<T> = T extends {
|
|
11016
11064
|
content: {
|
|
11017
11065
|
'application/json': infer J;
|
|
@@ -11078,13 +11126,13 @@ declare class WitniumchainChainAdminClient {
|
|
|
11078
11126
|
* Wraps the three `/v1/orgs/me/*` routes that org admins use to read their
|
|
11079
11127
|
* own org profile and manage their users. This is the client B2B2C apps and
|
|
11080
11128
|
* customer-admin dashboards consume — auth is the `wcorg_live_…` API key
|
|
11081
|
-
* minted
|
|
11082
|
-
* a subsequent `rotateApiKey`.
|
|
11129
|
+
* minted by the sysadmin admin SDK or returned by a subsequent `rotateApiKey`.
|
|
11083
11130
|
*
|
|
11084
11131
|
* The surface is intentionally minimal — the underlying API only exposes
|
|
11085
11132
|
* profile read + user create + user list. Anything more powerful (provision
|
|
11086
11133
|
* credits, change account type, verify email) requires the sysadmin
|
|
11087
|
-
* `
|
|
11134
|
+
* `ADMIN_TOKEN` and lives in the PRIVATE `@witnium/chain-admin-sdk` package,
|
|
11135
|
+
* never in this public SDK.
|
|
11088
11136
|
*/
|
|
11089
11137
|
|
|
11090
11138
|
interface WitniumchainOrgClientConfig {
|
|
@@ -11202,4 +11250,4 @@ declare function buildRevokeSigningKeyPayload(args: {
|
|
|
11202
11250
|
key: string;
|
|
11203
11251
|
}): string;
|
|
11204
11252
|
|
|
11205
|
-
export { type AccountResponse, type
|
|
11253
|
+
export { type AccountResponse, type paths$1 as AccountsPaths, type AddSigningKeyRequest$1 as AddSigningKeyRequest, type AddSigningKeyResponse, type BeginOAuthLoginArgs, type BeginOAuthLoginResult, type paths as ChainPaths, type CheckoutRequest, type CheckoutResponse, type CreateOrgRequest, type CreateOrgResponse, type CreateUserRequest, type CreateUserResponse, DelegatedKeys, type FinalizeWitnessResponse, type ForgotPasswordRequest, type ForgotPasswordResponse, type GetWitnessResponse, type HealthLiveResponse, type HealthReadyResponse, type InviteMemberRequest, type InviteMemberResponse, type LedgerResponse, type ListDelegatedKeysResponse, type ListOauthSessionsResponse, type ListUsersResponse, type LoginRequest, type LoginResponse, type LogoutResponse, type MembersListResponse, MfaNamespace, MfaRecoveryCodes, MfaTotp, type OAuthTokenSnapshot, OWNER_OP, OauthNamespace, OauthSessions, OrgMembers, OrgUsers, type OwnerOpName, type OwnerSigner, type PauseRequest$1 as PauseRequest, type PauseResponse, type PkceVerifierStorage, type PortalResponse, type PrepareDelegatedKeyRequest, type PreparedDelegatedKeyResponse, type ProposeWitnessRequest, type ProposeWitnessResponse, type ProvisionContractRequest, type ProvisionContractResponse, type ProvisionDelegatedKeyArgs, type ProvisionDelegatedKeyResult, type PublicOrgResponse, type RecoveryCodesRegenerateResponse, type ReissueProvisioningTokenResponse, type RemoveMemberResponse, type ResendInviteResponse, type ResetAccountResponse, type ResetPasswordRequest, type ResetPasswordResponse, type RevokeDelegatedKeyResponse, type RevokeSigningKeyRequest$1 as RevokeSigningKeyRequest, type RevokeSigningKeyResponse, type RevokeWitnessRequest, type RevokeWitnessResponse, type SetMemberRoleRequest, type SetMemberRoleResponse, type SignRequest, type SignResponse, type SignWitnessRequest, type SignWitnessResponse, type SignedRequestSigner, SigningKeys, type SignupRequest, type SignupResponse, type SubmitDelegatedKeyRequest, type SubmitDelegatedKeyResponse, Subscriptions, type SuspendMemberResponse, type TotpConfirmRequest, type TotpConfirmResponse, type TotpDisableResponse, type TotpEnrollResponse, type UnpauseRequest, type UnpauseResponse, type VerifyEmailResponse, WitniumchainApiError, WitniumchainChainAdminClient, type WitniumchainChainAdminClientConfig, WitniumchainClient, type WitniumchainClientConfig, WitniumchainOrgClient, type WitniumchainOrgClientConfig, buildAddSigningKeyPayload, buildPausePayload, buildRevokeSigningKeyPayload, buildUnpausePayload, defaultVerifierStorage };
|
package/dist/index.d.ts
CHANGED
|
@@ -242,6 +242,76 @@ interface paths$1 {
|
|
|
242
242
|
patch?: never;
|
|
243
243
|
trace?: never;
|
|
244
244
|
};
|
|
245
|
+
"/v1/auth/access-token": {
|
|
246
|
+
parameters: {
|
|
247
|
+
query?: never;
|
|
248
|
+
header?: never;
|
|
249
|
+
path?: never;
|
|
250
|
+
cookie?: never;
|
|
251
|
+
};
|
|
252
|
+
get?: never;
|
|
253
|
+
put?: never;
|
|
254
|
+
/**
|
|
255
|
+
* Exchange the session cookie for a bearer access token
|
|
256
|
+
* @description A logged-in (wac_session) user mints a short-lived OAuth-equivalent access token to call the bearer-only operational API (delegated keys, witness writes, chain reads). Keeps those endpoints off the ambient cookie (no CSRF surface). Same claim shape as an OAuth user token.
|
|
257
|
+
*/
|
|
258
|
+
post: {
|
|
259
|
+
parameters: {
|
|
260
|
+
query?: never;
|
|
261
|
+
header?: never;
|
|
262
|
+
path?: never;
|
|
263
|
+
cookie?: never;
|
|
264
|
+
};
|
|
265
|
+
requestBody?: never;
|
|
266
|
+
responses: {
|
|
267
|
+
/** @description Success */
|
|
268
|
+
200: {
|
|
269
|
+
headers: {
|
|
270
|
+
[name: string]: unknown;
|
|
271
|
+
};
|
|
272
|
+
content: {
|
|
273
|
+
"application/json": {
|
|
274
|
+
accessToken: string;
|
|
275
|
+
/** @enum {string} */
|
|
276
|
+
tokenType: "Bearer";
|
|
277
|
+
expiresIn: number;
|
|
278
|
+
expiresAt: string;
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
/** @description Unauthorized — authentication required or invalid */
|
|
283
|
+
401: {
|
|
284
|
+
headers: {
|
|
285
|
+
[name: string]: unknown;
|
|
286
|
+
};
|
|
287
|
+
content: {
|
|
288
|
+
"application/json": {
|
|
289
|
+
/**
|
|
290
|
+
* @description HTTP status code
|
|
291
|
+
* @example 400
|
|
292
|
+
*/
|
|
293
|
+
statusCode?: number;
|
|
294
|
+
/**
|
|
295
|
+
* @description Short error label
|
|
296
|
+
* @example Bad Request
|
|
297
|
+
*/
|
|
298
|
+
error?: string;
|
|
299
|
+
/**
|
|
300
|
+
* @description Human-readable error message. Validation errors from `ZodError.flatten()` may be returned as an array.
|
|
301
|
+
* @example Validation failed
|
|
302
|
+
*/
|
|
303
|
+
message: string | string[];
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
delete?: never;
|
|
310
|
+
options?: never;
|
|
311
|
+
head?: never;
|
|
312
|
+
patch?: never;
|
|
313
|
+
trace?: never;
|
|
314
|
+
};
|
|
245
315
|
"/v1/auth/login": {
|
|
246
316
|
parameters: {
|
|
247
317
|
query?: never;
|
|
@@ -10296,14 +10366,6 @@ type SetMemberRoleRequest = Req<'/v1/orgs/me/members/{userId}/role', 'put'>;
|
|
|
10296
10366
|
type SetMemberRoleResponse = Res<'/v1/orgs/me/members/{userId}/role', 'put'>;
|
|
10297
10367
|
type RemoveMemberResponse = Res<'/v1/orgs/me/members/{userId}', 'delete'>;
|
|
10298
10368
|
type ResendInviteResponse = Res<'/v1/orgs/me/members/{userId}/resend-invite', 'post'>;
|
|
10299
|
-
type CreateOrganizationRequest = Req<'/v1/admin/organizations', 'post'>;
|
|
10300
|
-
type CreateOrganizationResponse = Res<'/v1/admin/organizations', 'post'>;
|
|
10301
|
-
type SetAccountTypeRequest = Req<'/v1/admin/organizations/{id}/account-type', 'patch'>;
|
|
10302
|
-
type SetAccountTypeResponse = Res<'/v1/admin/organizations/{id}/account-type', 'patch'>;
|
|
10303
|
-
type VerifyOrganizationResponse = Res<'/v1/admin/organizations/{id}/verify', 'patch'>;
|
|
10304
|
-
type RotateApiKeyResponse = Res<'/v1/admin/organizations/{id}/rotate-key', 'post'>;
|
|
10305
|
-
type AdjustCreditsRequest = Req<'/v1/admin/organizations/{id}/adjust-credits', 'post'>;
|
|
10306
|
-
type AdjustCreditsResponse = Res<'/v1/admin/organizations/{id}/adjust-credits', 'post'>;
|
|
10307
10369
|
type ListDelegatedKeysResponse = Res<'/v1/users/me/delegated-keys', 'get'>;
|
|
10308
10370
|
type PrepareDelegatedKeyRequest = Req<'/v1/users/me/delegated-keys', 'post'>;
|
|
10309
10371
|
type PreparedDelegatedKeyResponse = Res<'/v1/users/me/delegated-keys', 'post'>;
|
|
@@ -10364,10 +10426,11 @@ type DashboardWitnessesResponse = ChainRes<'/v5/dashboard/witnesses', 'get'>;
|
|
|
10364
10426
|
*
|
|
10365
10427
|
* Covers both accounts (identity / billing / OAuth / delegated keys / witness
|
|
10366
10428
|
* writes via the metered v5 proxy) and chain-api read surfaces (contract
|
|
10367
|
-
* info / witness lookup / wallet balance / dashboards).
|
|
10368
|
-
* clients layer on top — `WitniumchainClient` (end-user)
|
|
10369
|
-
* `WitniumchainOrgClient` (org admin)
|
|
10370
|
-
*
|
|
10429
|
+
* info / witness lookup / wallet balance / dashboards). Two convenience
|
|
10430
|
+
* clients layer on top — `WitniumchainClient` (end-user) and
|
|
10431
|
+
* `WitniumchainOrgClient` (org admin) — with helpers for signup,
|
|
10432
|
+
* subscriptions, and delegated-key provisioning. The sysadmin surface lives in
|
|
10433
|
+
* the separate PRIVATE `@witnium/chain-admin-sdk` package, not here.
|
|
10371
10434
|
*
|
|
10372
10435
|
* Stripe surface is intentionally Checkout + Customer Portal ONLY. Witnium is
|
|
10373
10436
|
* not a marketplace, so there is no Stripe Connect onboarding.
|
|
@@ -10379,7 +10442,6 @@ type DashboardWitnessesResponse = ChainRes<'/v5/dashboard/witnesses', 'get'>;
|
|
|
10379
10442
|
* - sessionCookie — `wac_session` value for browser-cookie routes.
|
|
10380
10443
|
* - accessToken — OAuth Bearer JWT for end-user API.
|
|
10381
10444
|
* - orgApiKey — `wcorg_live_…` for org admin.
|
|
10382
|
-
* - adminToken — sysadmin token.
|
|
10383
10445
|
* - signedRequest — Ed25519 signer for SDK signed-request routes
|
|
10384
10446
|
* (witnesses propose/sign/finalize/revoke). The SDK
|
|
10385
10447
|
* does the canonical-message construction; you supply
|
|
@@ -10505,8 +10567,6 @@ interface WitniumchainClientConfig {
|
|
|
10505
10567
|
verifierStorage?: PkceVerifierStorage;
|
|
10506
10568
|
/** Organisation API key (`wcorg_live_…`). */
|
|
10507
10569
|
orgApiKey?: string;
|
|
10508
|
-
/** System-admin token (`Authorization: Bearer <ADMIN_TOKEN>`). */
|
|
10509
|
-
adminToken?: string;
|
|
10510
10570
|
/** Ed25519 signer for SDK signed-request routes (witness write ops). */
|
|
10511
10571
|
signedRequest?: SignedRequestSigner;
|
|
10512
10572
|
/** Per-request timeout in milliseconds. Default 30000. */
|
|
@@ -10580,6 +10640,8 @@ declare class WitniumchainClient {
|
|
|
10580
10640
|
private readonly verifierStorage;
|
|
10581
10641
|
private discoveryCache;
|
|
10582
10642
|
private refreshInFlight;
|
|
10643
|
+
private accessTokenFromSession;
|
|
10644
|
+
private sessionExchangeInFlight;
|
|
10583
10645
|
/** Subscriptions / billing helpers. See {@link Subscriptions}. */
|
|
10584
10646
|
readonly subscriptions: Subscriptions;
|
|
10585
10647
|
/** Delegated-key namespace including the one-call {@link DelegatedKeys.provision} flow. */
|
|
@@ -10629,11 +10691,6 @@ declare class WitniumchainClient {
|
|
|
10629
10691
|
getMyOrg(): Promise<PublicOrgResponse>;
|
|
10630
10692
|
createOrgUser(body: CreateUserRequest): Promise<CreateUserResponse>;
|
|
10631
10693
|
listOrgUsers(): Promise<ListUsersResponse>;
|
|
10632
|
-
createOrganization(body: CreateOrganizationRequest): Promise<CreateOrganizationResponse>;
|
|
10633
|
-
setOrgAccountType(id: string, body: SetAccountTypeRequest): Promise<SetAccountTypeResponse>;
|
|
10634
|
-
verifyOrganization(id: string): Promise<VerifyOrganizationResponse>;
|
|
10635
|
-
rotateOrgApiKey(id: string): Promise<RotateApiKeyResponse>;
|
|
10636
|
-
adjustOrgCredits(id: string, body: AdjustCreditsRequest): Promise<AdjustCreditsResponse>;
|
|
10637
10694
|
listDelegatedKeys(query?: {
|
|
10638
10695
|
contractAddress?: string;
|
|
10639
10696
|
active?: 'true' | 'false';
|
|
@@ -10754,6 +10811,41 @@ declare class WitniumchainClient {
|
|
|
10754
10811
|
* instead of retrying with a now-invalid token.
|
|
10755
10812
|
*/
|
|
10756
10813
|
refreshAccessToken(): Promise<OAuthTokenSnapshot>;
|
|
10814
|
+
/**
|
|
10815
|
+
* Exchange the logged-in session (the `wac_session` cookie) for a short-lived
|
|
10816
|
+
* bearer access token and cache it as the client's `accessToken`.
|
|
10817
|
+
*
|
|
10818
|
+
* This is the SDK side of the session→token model (accounts'
|
|
10819
|
+
* `POST /v1/auth/access-token`): the dashboard authenticates with the
|
|
10820
|
+
* cookie, but the operational API (delegated keys, witness writes, chain
|
|
10821
|
+
* reads) is bearer-only — no endpoint accepts the ambient cookie, so there's
|
|
10822
|
+
* no CSRF surface even with `SameSite=None`. The minted token is
|
|
10823
|
+
* byte-compatible with an OAuth user token (same signing key, `iss`, `aud`,
|
|
10824
|
+
* scope + org/role/contracts claims), so every `BearerJWT` route accepts it.
|
|
10825
|
+
*
|
|
10826
|
+
* Callers rarely invoke this directly — {@link applyAuth} mints transparently
|
|
10827
|
+
* on the first `BearerJWT` call when no token is set and re-mints on a 401.
|
|
10828
|
+
* It's exposed so a dashboard can pre-warm the token right after login.
|
|
10829
|
+
*
|
|
10830
|
+
* Requires a session: either `sessionCookie` on the constructor (Node) or an
|
|
10831
|
+
* ambient `wac_session` cookie carried by the browser (`credentials:
|
|
10832
|
+
* 'include'`). Throws {@link WitniumchainApiError} (401) when there's no
|
|
10833
|
+
* valid session.
|
|
10834
|
+
*/
|
|
10835
|
+
exchangeSessionForToken(): Promise<OAuthTokenSnapshot>;
|
|
10836
|
+
/**
|
|
10837
|
+
* Best-effort transparent mint for the `BearerJWT` path: if no access token
|
|
10838
|
+
* is cached, try the session exchange (single-flight). Swallows failure so
|
|
10839
|
+
* the caller in {@link applyAuth} surfaces the actionable "no token / no
|
|
10840
|
+
* session" guidance rather than a raw 401 from the exchange endpoint.
|
|
10841
|
+
*/
|
|
10842
|
+
private ensureSessionAccessToken;
|
|
10843
|
+
/**
|
|
10844
|
+
* Obtain a fresh access token for a 401-retry, picking the right mechanism:
|
|
10845
|
+
* an OAuth refresh when a refresh credential exists, else a session re-mint
|
|
10846
|
+
* for a session-exchanged token. Returns true when a fresh token is in hand.
|
|
10847
|
+
*/
|
|
10848
|
+
private reauthenticateForRetry;
|
|
10757
10849
|
/**
|
|
10758
10850
|
* End the OAuth session.
|
|
10759
10851
|
*
|
|
@@ -10968,50 +11060,6 @@ declare class MfaRecoveryCodes {
|
|
|
10968
11060
|
regenerate(): Promise<RecoveryCodesRegenerateResponse>;
|
|
10969
11061
|
}
|
|
10970
11062
|
|
|
10971
|
-
interface WitniumchainAdminClientConfig {
|
|
10972
|
-
/** Base URL, e.g. `https://auth.witniumchain.com`. Trailing slash optional. */
|
|
10973
|
-
baseUrl: string;
|
|
10974
|
-
/** System-admin token (`Authorization: Bearer <ADMIN_TOKEN>`). */
|
|
10975
|
-
adminToken: string;
|
|
10976
|
-
/** Per-request timeout in milliseconds. Default 30000. */
|
|
10977
|
-
timeout?: number;
|
|
10978
|
-
/** Alternate fetch implementation (e.g. for tests). Default `globalThis.fetch`. */
|
|
10979
|
-
fetch?: typeof fetch;
|
|
10980
|
-
}
|
|
10981
|
-
type AccountType = 'metered' | 'unlimited';
|
|
10982
|
-
declare class WitniumchainAdminClient {
|
|
10983
|
-
private readonly inner;
|
|
10984
|
-
constructor(config: WitniumchainAdminClientConfig);
|
|
10985
|
-
/**
|
|
10986
|
-
* Mint a new organisation. The returned `apiKey` is shown ONCE — the server
|
|
10987
|
-
* only retains its SHA-256 hash. Persist it before the response leaves
|
|
10988
|
-
* scope; there is no recovery path.
|
|
10989
|
-
*
|
|
10990
|
-
* @param body Organisation seed: name, email, optional accountType and
|
|
10991
|
-
* signup credit grant, optional skip-email-verification flag.
|
|
10992
|
-
*/
|
|
10993
|
-
createOrganization(body: CreateOrganizationRequest): Promise<CreateOrganizationResponse>;
|
|
10994
|
-
/** Flip an org between `metered` (Stripe checkout + credit ledger) and `unlimited` (flat-fee). */
|
|
10995
|
-
setAccountType(orgId: string, accountType: AccountType): Promise<SetAccountTypeResponse>;
|
|
10996
|
-
/** Mark an org's email as verified. Prerequisite for the org to create users. */
|
|
10997
|
-
verifyEmail(orgId: string): Promise<VerifyOrganizationResponse>;
|
|
10998
|
-
/**
|
|
10999
|
-
* Rotate the org's API key. The previous `wcorg_live_…` is invalidated and
|
|
11000
|
-
* the new key is returned ONCE — same one-time-secret semantics as
|
|
11001
|
-
* {@link createOrganization}.
|
|
11002
|
-
*/
|
|
11003
|
-
rotateApiKey(orgId: string): Promise<RotateApiKeyResponse>;
|
|
11004
|
-
/**
|
|
11005
|
-
* Apply a signed credit delta to an org's ledger. Positive `delta` grants
|
|
11006
|
-
* credits (goodwill, migration backfill); negative claws them back.
|
|
11007
|
-
* Recorded as `reason: adjustment` with the supplied `note`.
|
|
11008
|
-
*
|
|
11009
|
-
* Use sparingly — this bypasses Stripe and should be auditable from the
|
|
11010
|
-
* `note` alone.
|
|
11011
|
-
*/
|
|
11012
|
-
adjustCredits(orgId: string, delta: number, note?: string): Promise<AdjustCreditsResponse>;
|
|
11013
|
-
}
|
|
11014
|
-
|
|
11015
11063
|
type Body<T> = T extends {
|
|
11016
11064
|
content: {
|
|
11017
11065
|
'application/json': infer J;
|
|
@@ -11078,13 +11126,13 @@ declare class WitniumchainChainAdminClient {
|
|
|
11078
11126
|
* Wraps the three `/v1/orgs/me/*` routes that org admins use to read their
|
|
11079
11127
|
* own org profile and manage their users. This is the client B2B2C apps and
|
|
11080
11128
|
* customer-admin dashboards consume — auth is the `wcorg_live_…` API key
|
|
11081
|
-
* minted
|
|
11082
|
-
* a subsequent `rotateApiKey`.
|
|
11129
|
+
* minted by the sysadmin admin SDK or returned by a subsequent `rotateApiKey`.
|
|
11083
11130
|
*
|
|
11084
11131
|
* The surface is intentionally minimal — the underlying API only exposes
|
|
11085
11132
|
* profile read + user create + user list. Anything more powerful (provision
|
|
11086
11133
|
* credits, change account type, verify email) requires the sysadmin
|
|
11087
|
-
* `
|
|
11134
|
+
* `ADMIN_TOKEN` and lives in the PRIVATE `@witnium/chain-admin-sdk` package,
|
|
11135
|
+
* never in this public SDK.
|
|
11088
11136
|
*/
|
|
11089
11137
|
|
|
11090
11138
|
interface WitniumchainOrgClientConfig {
|
|
@@ -11202,4 +11250,4 @@ declare function buildRevokeSigningKeyPayload(args: {
|
|
|
11202
11250
|
key: string;
|
|
11203
11251
|
}): string;
|
|
11204
11252
|
|
|
11205
|
-
export { type AccountResponse, type
|
|
11253
|
+
export { type AccountResponse, type paths$1 as AccountsPaths, type AddSigningKeyRequest$1 as AddSigningKeyRequest, type AddSigningKeyResponse, type BeginOAuthLoginArgs, type BeginOAuthLoginResult, type paths as ChainPaths, type CheckoutRequest, type CheckoutResponse, type CreateOrgRequest, type CreateOrgResponse, type CreateUserRequest, type CreateUserResponse, DelegatedKeys, type FinalizeWitnessResponse, type ForgotPasswordRequest, type ForgotPasswordResponse, type GetWitnessResponse, type HealthLiveResponse, type HealthReadyResponse, type InviteMemberRequest, type InviteMemberResponse, type LedgerResponse, type ListDelegatedKeysResponse, type ListOauthSessionsResponse, type ListUsersResponse, type LoginRequest, type LoginResponse, type LogoutResponse, type MembersListResponse, MfaNamespace, MfaRecoveryCodes, MfaTotp, type OAuthTokenSnapshot, OWNER_OP, OauthNamespace, OauthSessions, OrgMembers, OrgUsers, type OwnerOpName, type OwnerSigner, type PauseRequest$1 as PauseRequest, type PauseResponse, type PkceVerifierStorage, type PortalResponse, type PrepareDelegatedKeyRequest, type PreparedDelegatedKeyResponse, type ProposeWitnessRequest, type ProposeWitnessResponse, type ProvisionContractRequest, type ProvisionContractResponse, type ProvisionDelegatedKeyArgs, type ProvisionDelegatedKeyResult, type PublicOrgResponse, type RecoveryCodesRegenerateResponse, type ReissueProvisioningTokenResponse, type RemoveMemberResponse, type ResendInviteResponse, type ResetAccountResponse, type ResetPasswordRequest, type ResetPasswordResponse, type RevokeDelegatedKeyResponse, type RevokeSigningKeyRequest$1 as RevokeSigningKeyRequest, type RevokeSigningKeyResponse, type RevokeWitnessRequest, type RevokeWitnessResponse, type SetMemberRoleRequest, type SetMemberRoleResponse, type SignRequest, type SignResponse, type SignWitnessRequest, type SignWitnessResponse, type SignedRequestSigner, SigningKeys, type SignupRequest, type SignupResponse, type SubmitDelegatedKeyRequest, type SubmitDelegatedKeyResponse, Subscriptions, type SuspendMemberResponse, type TotpConfirmRequest, type TotpConfirmResponse, type TotpDisableResponse, type TotpEnrollResponse, type UnpauseRequest, type UnpauseResponse, type VerifyEmailResponse, WitniumchainApiError, WitniumchainChainAdminClient, type WitniumchainChainAdminClientConfig, WitniumchainClient, type WitniumchainClientConfig, WitniumchainOrgClient, type WitniumchainOrgClientConfig, buildAddSigningKeyPayload, buildPausePayload, buildRevokeSigningKeyPayload, buildUnpausePayload, defaultVerifierStorage };
|