@baliola/auth-sdk 0.2.0 → 0.4.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/CHANGELOG.md +10 -0
- package/README.md +24 -0
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +1 -1
- package/dist/{client-BcyoQ5Cj.js → client-CX3XFmOA.js} +27 -0
- package/dist/{index-G-gqveGn.d.ts → index-B2RuGLX_.d.ts} +29 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +1 -1
- package/dist/wallet/index.d.ts +19 -0
- package/dist/wallet/index.js +34 -0
- package/package.json +9 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@baliola/auth-sdk` are documented here.
|
|
4
4
|
|
|
5
|
+
## 0.4.0
|
|
6
|
+
|
|
7
|
+
- feat(sdk): add `auth.getProfile()` → `GET /profile`. Returns `{ account, profile }` where `account` carries the **live** account status (read from the database, not the token) and `profile` is the account's profile record (`displayName`, `avatarUrl`, `primaryEmail`, `primaryPhone`) or `null` when none exists yet. New exported types: `Profile`, `ProfileResult`.
|
|
8
|
+
- Server-side context: baliola-auth is re-scoped to a pure identity provider. The `/modules`, `/api-keys/*`, and `/admin/api-keys/*` endpoints are removed (metering/billing move to the Baliola Console backend), and the `GET /profile` response no longer carries `moduleAccess`. The SDK never called any of those endpoints, so there are no SDK-side removals.
|
|
9
|
+
|
|
10
|
+
## 0.3.0
|
|
11
|
+
|
|
12
|
+
- feat(sdk): add the custodial wallet namespace — `auth.wallet.getAddress()` (`GET /auth/wallet`, provisioned on first read) and `auth.wallet.signHash(hash)` (`POST /auth/wallet/sign`).
|
|
13
|
+
- feat(sdk): add `createRemoteSigner` under the `./wallet` subpath — a viem-compatible account whose `signMessage({ raw })` delegates to `POST /auth/wallet/sign`, so the custodial private key never leaves baliola-auth.
|
|
14
|
+
|
|
5
15
|
## 0.2.0
|
|
6
16
|
|
|
7
17
|
Distribution change and clean-ups; no method-level API changes.
|
package/README.md
CHANGED
|
@@ -95,6 +95,30 @@ auth.emailPassword.changePassword({ currentPassword, newPassword });
|
|
|
95
95
|
auth.google.login({ idToken }); // → AuthSession
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
+
### Custodial wallet (smart-account signer)
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { createAuthClient } from '@baliola/auth-sdk';
|
|
102
|
+
import { createRemoteSigner } from '@baliola/auth-sdk/wallet';
|
|
103
|
+
import { toSmartAccount } from '@baliola/smart-account-sdk';
|
|
104
|
+
|
|
105
|
+
const auth = createAuthClient({ baseUrl });
|
|
106
|
+
await auth.emailOtp.verifyLoginCode({ email, code }); // authenticated session
|
|
107
|
+
|
|
108
|
+
const owner = await createRemoteSigner(auth); // viem LocalAccount, signs server-side
|
|
109
|
+
const account = await toSmartAccount({ owner, chain: 'macTestnet' });
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The private key never leaves baliola-auth; `owner.signMessage({ raw })` calls `POST /auth/wallet/sign`.
|
|
113
|
+
|
|
114
|
+
### Profile (identity read)
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const { account, profile } = await auth.getProfile(); // GET /profile (authenticated)
|
|
118
|
+
// account = { id, email, status } — status is live, not a token-time snapshot
|
|
119
|
+
// profile = { displayName, avatarUrl, primaryEmail, primaryPhone } | null
|
|
120
|
+
```
|
|
121
|
+
|
|
98
122
|
### Session lifecycle
|
|
99
123
|
|
|
100
124
|
```ts
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as GoogleNamespace, c as
|
|
2
|
-
export { AuthClient, AuthFetchInit, CreateAuthClientOptions, EmailOtpNamespace, EmailPasswordNamespace, GoogleNamespace, ProactiveRefreshConfig, SubscribeOptions, createAuthClient };
|
|
1
|
+
import { a as GoogleNamespace, c as WalletNamespace, f as AuthFetchInit, i as EmailPasswordNamespace, l as createAuthClient, n as CreateAuthClientOptions, o as ProactiveRefreshConfig, r as EmailOtpNamespace, s as SubscribeOptions, t as AuthClient } from "../index-B2RuGLX_.js";
|
|
2
|
+
export { AuthClient, AuthFetchInit, CreateAuthClientOptions, EmailOtpNamespace, EmailPasswordNamespace, GoogleNamespace, ProactiveRefreshConfig, SubscribeOptions, WalletNamespace, createAuthClient };
|
package/dist/client/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createAuthClient } from "../client-
|
|
1
|
+
import { t as createAuthClient } from "../client-CX3XFmOA.js";
|
|
2
2
|
export { createAuthClient };
|
|
@@ -135,6 +135,28 @@ function createMethods(ctx) {
|
|
|
135
135
|
body: withClientId({ idToken: input.idToken })
|
|
136
136
|
}));
|
|
137
137
|
},
|
|
138
|
+
async getWalletAddress() {
|
|
139
|
+
return ctx.transport.request({
|
|
140
|
+
path: "/auth/wallet",
|
|
141
|
+
method: "GET",
|
|
142
|
+
authMode: "bearer+session"
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
async signWalletHash(hash) {
|
|
146
|
+
return ctx.transport.request({
|
|
147
|
+
path: "/auth/wallet/sign",
|
|
148
|
+
method: "POST",
|
|
149
|
+
authMode: "bearer+session",
|
|
150
|
+
body: { hash }
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
async getProfile() {
|
|
154
|
+
return ctx.transport.request({
|
|
155
|
+
path: "/profile",
|
|
156
|
+
method: "GET",
|
|
157
|
+
authMode: "bearer+session"
|
|
158
|
+
});
|
|
159
|
+
},
|
|
138
160
|
async logoutRequest() {
|
|
139
161
|
await ctx.transport.request({
|
|
140
162
|
path: "/auth/logout",
|
|
@@ -460,6 +482,11 @@ function createAuthClient(options) {
|
|
|
460
482
|
await setSession(session);
|
|
461
483
|
return session;
|
|
462
484
|
} },
|
|
485
|
+
wallet: {
|
|
486
|
+
getAddress: async () => (await methods.getWalletAddress()).address,
|
|
487
|
+
signHash: async (hash) => (await methods.signWalletHash(hash)).signature
|
|
488
|
+
},
|
|
489
|
+
getProfile: () => methods.getProfile(),
|
|
463
490
|
async refresh() {
|
|
464
491
|
return transport.refreshSession();
|
|
465
492
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as ResendCodeResult, l as SendLoginCodeResult, n as AuthSession, r as ErrorHandler, s as RegisterResult, u as SessionChangeHandler } from "./session-Cs_P7ojF.js";
|
|
1
|
+
import { c as ResendCodeResult, l as SendLoginCodeResult, n as AuthSession, r as ErrorHandler, s as RegisterResult, t as Account, u as SessionChangeHandler } from "./session-Cs_P7ojF.js";
|
|
2
2
|
import { n as SessionStore } from "./sessionStore-BDdEpbL8.js";
|
|
3
3
|
import { a as RegisterInput, c as SendLoginCodeInput, d as VerifyRegistrationCodeInput, i as LoginWithPasswordInput, l as SetPasswordInput, n as ChangePasswordInput, o as ResendLoginCodeInput, r as LoginWithGoogleInput, s as ResendRegistrationCodeInput, u as VerifyLoginCodeInput } from "./requests-eTORIjY5.js";
|
|
4
4
|
|
|
@@ -26,6 +26,20 @@ type AuthFetchInit = RequestInit & {
|
|
|
26
26
|
disableRefresh?: boolean;
|
|
27
27
|
};
|
|
28
28
|
//#endregion
|
|
29
|
+
//#region src/types/profile.d.ts
|
|
30
|
+
/** The account's profile record; every field is user-editable and nullable. */
|
|
31
|
+
type Profile = {
|
|
32
|
+
displayName: string | null;
|
|
33
|
+
avatarUrl: string | null;
|
|
34
|
+
primaryEmail: string | null;
|
|
35
|
+
primaryPhone: string | null;
|
|
36
|
+
};
|
|
37
|
+
/** Result of `auth.getProfile` — identity read for the token holder. */
|
|
38
|
+
type ProfileResult = {
|
|
39
|
+
/** `status` is the live account status, not a token-time snapshot. */account: Account; /** `null` when the account has no profile row yet. */
|
|
40
|
+
profile: Profile | null;
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
29
43
|
//#region src/client/index.d.ts
|
|
30
44
|
type ProactiveRefreshConfig = false | {
|
|
31
45
|
/** Refresh proactively if `expiresAt - now < leadTimeMs`. Defaults to 60_000 (60s). */leadTimeMs?: number;
|
|
@@ -119,10 +133,23 @@ type EmailPasswordNamespace = {
|
|
|
119
133
|
type GoogleNamespace = {
|
|
120
134
|
login(input: LoginWithGoogleInput): Promise<AuthSession>;
|
|
121
135
|
};
|
|
136
|
+
/** Custodial wallet (Console tier). */
|
|
137
|
+
type WalletNamespace = {
|
|
138
|
+
/** The account's custodial EOA address (provisioned on first read). */getAddress(): Promise<string>; /** Sign a 32-byte userOp hash; returns a 65-byte recoverable signature. */
|
|
139
|
+
signHash(hash: string): Promise<string>;
|
|
140
|
+
};
|
|
122
141
|
type AuthClient = {
|
|
123
142
|
emailOtp: EmailOtpNamespace;
|
|
124
143
|
emailPassword: EmailPasswordNamespace;
|
|
125
144
|
google: GoogleNamespace;
|
|
145
|
+
wallet: WalletNamespace;
|
|
146
|
+
/**
|
|
147
|
+
* Fetch the token holder's identity: account (id, email, live status) plus
|
|
148
|
+
* its profile record (`profile: null` when none exists yet).
|
|
149
|
+
*
|
|
150
|
+
* @throws AuthError on 401 (missing/expired session) and other API errors.
|
|
151
|
+
*/
|
|
152
|
+
getProfile(): Promise<ProfileResult>;
|
|
126
153
|
refresh(): Promise<AuthSession>;
|
|
127
154
|
logout(): Promise<void>;
|
|
128
155
|
getSession(): AuthSession | null;
|
|
@@ -139,4 +166,4 @@ type AuthClient = {
|
|
|
139
166
|
};
|
|
140
167
|
declare function createAuthClient(options: CreateAuthClientOptions): AuthClient;
|
|
141
168
|
//#endregion
|
|
142
|
-
export { GoogleNamespace as a,
|
|
169
|
+
export { GoogleNamespace as a, WalletNamespace as c, ProfileResult as d, AuthFetchInit as f, EmailPasswordNamespace as i, createAuthClient as l, CreateAuthClientOptions as n, ProactiveRefreshConfig as o, EmailOtpNamespace as r, SubscribeOptions as s, AuthClient as t, Profile as u };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { a as OtpInfo, c as ResendCodeResult, i as ErrorSource, l as SendLoginCodeResult, n as AuthSession, o as Project, r as ErrorHandler, s as RegisterResult, t as Account, u as SessionChangeHandler } from "./session-Cs_P7ojF.js";
|
|
2
|
-
import { a as GoogleNamespace, c as
|
|
2
|
+
import { a as GoogleNamespace, c as WalletNamespace, d as ProfileResult, f as AuthFetchInit, i as EmailPasswordNamespace, l as createAuthClient, n as CreateAuthClientOptions, o as ProactiveRefreshConfig, r as EmailOtpNamespace, s as SubscribeOptions, t as AuthClient, u as Profile } from "./index-B2RuGLX_.js";
|
|
3
3
|
import { i as memoryStore, n as SessionStore, r as localStorageStore, t as LocalStorageStoreOptions } from "./sessionStore-BDdEpbL8.js";
|
|
4
4
|
import { a as RegisterInput, c as SendLoginCodeInput, d as VerifyRegistrationCodeInput, i as LoginWithPasswordInput, l as SetPasswordInput, n as ChangePasswordInput, o as ResendLoginCodeInput, r as LoginWithGoogleInput, s as ResendRegistrationCodeInput, t as CaptchaArgs, u as VerifyLoginCodeInput } from "./requests-eTORIjY5.js";
|
|
5
5
|
import { _ as authErrorFromFetchFailure, a as EmailAlreadyHasPasswordError, c as InvalidPasswordError, d as NoPasswordSetError, f as NoPendingOtpError, g as ResendCooldownError, h as RateLimitedError, i as CaptchaFailedError, l as MaxAttemptsError, m as OtpInvalidError, n as AuthError, o as InvalidCredentialsError, p as OtpExpiredError, r as AuthErrorInit, s as InvalidEmailError, t as AccountSuspendedError, u as MaxResendsError, v as authErrorFromResponse } from "./authError-C5g5jP5l.js";
|
|
6
6
|
import { n as AccessTokenPayloadProject, t as AccessTokenPayload } from "./tokens-BXrPLi5B.js";
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
//#region src/types/wallet.d.ts
|
|
9
|
+
type WalletAddressResult = {
|
|
10
|
+
address: string;
|
|
11
|
+
isActive: boolean;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
};
|
|
14
|
+
type SignHashResult = {
|
|
15
|
+
signature: string;
|
|
16
|
+
address: string;
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { type AccessTokenPayload, type AccessTokenPayloadProject, type Account, AccountSuspendedError, type AuthClient, AuthError, type AuthErrorInit, type AuthFetchInit, type AuthSession, type CaptchaArgs, CaptchaFailedError, type ChangePasswordInput, type CreateAuthClientOptions, EmailAlreadyHasPasswordError, type EmailOtpNamespace, type EmailPasswordNamespace, type ErrorHandler, type ErrorSource, type GoogleNamespace, InvalidCredentialsError, InvalidEmailError, InvalidPasswordError, type LocalStorageStoreOptions, type LoginWithGoogleInput, type LoginWithPasswordInput, MaxAttemptsError, MaxResendsError, NoPasswordSetError, NoPendingOtpError, OtpExpiredError, type OtpInfo, OtpInvalidError, type ProactiveRefreshConfig, type Profile, type ProfileResult, type Project, RateLimitedError, type RegisterInput, type RegisterResult, type ResendCodeResult, ResendCooldownError, type ResendLoginCodeInput, type ResendRegistrationCodeInput, type SendLoginCodeInput, type SendLoginCodeResult, type SessionChangeHandler, type SessionStore, type SetPasswordInput, type SignHashResult, type SubscribeOptions, type VerifyLoginCodeInput, type VerifyRegistrationCodeInput, type WalletAddressResult, type WalletNamespace, authErrorFromFetchFailure, authErrorFromResponse, createAuthClient, localStorageStore, memoryStore };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createAuthClient } from "./client-
|
|
1
|
+
import { t as createAuthClient } from "./client-CX3XFmOA.js";
|
|
2
2
|
import { _ as authErrorFromResponse, a as InvalidCredentialsError, c as MaxAttemptsError, d as NoPendingOtpError, f as OtpExpiredError, g as authErrorFromFetchFailure, h as ResendCooldownError, i as EmailAlreadyHasPasswordError, l as MaxResendsError, m as RateLimitedError, n as AuthError, o as InvalidEmailError, p as OtpInvalidError, r as CaptchaFailedError, s as InvalidPasswordError, t as AccountSuspendedError, u as NoPasswordSetError } from "./authError-DbEZJnC4.js";
|
|
3
3
|
import { n as memoryStore, t as localStorageStore } from "./sessionStore-DD6lON9W.js";
|
|
4
4
|
export { AccountSuspendedError, AuthError, CaptchaFailedError, EmailAlreadyHasPasswordError, InvalidCredentialsError, InvalidEmailError, InvalidPasswordError, MaxAttemptsError, MaxResendsError, NoPasswordSetError, NoPendingOtpError, OtpExpiredError, OtpInvalidError, RateLimitedError, ResendCooldownError, authErrorFromFetchFailure, authErrorFromResponse, createAuthClient, localStorageStore, memoryStore };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as AuthClient } from "../index-B2RuGLX_.js";
|
|
2
|
+
import { LocalAccount } from "viem";
|
|
3
|
+
|
|
4
|
+
//#region src/wallet/index.d.ts
|
|
5
|
+
/** The account's custodial wallet address. */
|
|
6
|
+
declare function getAddress(auth: AuthClient): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Build a viem `LocalAccount` backed by the server-side custodial signer. Drop
|
|
9
|
+
* it into the smart-account SDK as `toSmartAccount({ owner })`. Only
|
|
10
|
+
* `signMessage` is supported — the smart-account SDK signs userOps via
|
|
11
|
+
* `signMessage({ raw })`; `signTransaction`/`signTypedData` are not custodial
|
|
12
|
+
* operations and throw.
|
|
13
|
+
*
|
|
14
|
+
* @param auth An authenticated AuthClient.
|
|
15
|
+
* @returns A viem LocalAccount whose signing is performed by baliola-auth.
|
|
16
|
+
*/
|
|
17
|
+
declare function createRemoteSigner(auth: AuthClient): Promise<LocalAccount>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createRemoteSigner, getAddress };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { toAccount } from "viem/accounts";
|
|
2
|
+
//#region src/wallet/index.ts
|
|
3
|
+
/** The account's custodial wallet address. */
|
|
4
|
+
async function getAddress(auth) {
|
|
5
|
+
return auth.wallet.getAddress();
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Build a viem `LocalAccount` backed by the server-side custodial signer. Drop
|
|
9
|
+
* it into the smart-account SDK as `toSmartAccount({ owner })`. Only
|
|
10
|
+
* `signMessage` is supported — the smart-account SDK signs userOps via
|
|
11
|
+
* `signMessage({ raw })`; `signTransaction`/`signTypedData` are not custodial
|
|
12
|
+
* operations and throw.
|
|
13
|
+
*
|
|
14
|
+
* @param auth An authenticated AuthClient.
|
|
15
|
+
* @returns A viem LocalAccount whose signing is performed by baliola-auth.
|
|
16
|
+
*/
|
|
17
|
+
async function createRemoteSigner(auth) {
|
|
18
|
+
return toAccount({
|
|
19
|
+
address: await auth.wallet.getAddress(),
|
|
20
|
+
async signMessage({ message }) {
|
|
21
|
+
const raw = typeof message === "object" && message !== null && "raw" in message ? message.raw : message;
|
|
22
|
+
const hash = typeof raw === "string" ? raw : `0x${Buffer.from(raw).toString("hex")}`;
|
|
23
|
+
return await auth.wallet.signHash(hash);
|
|
24
|
+
},
|
|
25
|
+
async signTransaction() {
|
|
26
|
+
throw new Error("baliola remote signer: signTransaction is not supported");
|
|
27
|
+
},
|
|
28
|
+
async signTypedData() {
|
|
29
|
+
throw new Error("baliola remote signer: signTypedData is not supported");
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { createRemoteSigner, getAddress };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baliola/auth-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Client SDK for Baliola Auth",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Baliola Development Team",
|
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"./types": {
|
|
30
30
|
"types": "./dist/types/index.d.ts",
|
|
31
31
|
"import": "./dist/types/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./wallet": {
|
|
34
|
+
"types": "./dist/wallet/index.d.ts",
|
|
35
|
+
"import": "./dist/wallet/index.js"
|
|
32
36
|
}
|
|
33
37
|
},
|
|
34
38
|
"files": [
|
|
@@ -48,13 +52,15 @@
|
|
|
48
52
|
},
|
|
49
53
|
"scripts": {
|
|
50
54
|
"build": "tsdown",
|
|
51
|
-
"typecheck": "
|
|
55
|
+
"typecheck": "bash scripts/typecheck.sh",
|
|
52
56
|
"test": "bun test test/unit",
|
|
53
57
|
"prepublishOnly": "bun run build"
|
|
54
58
|
},
|
|
59
|
+
"peerDependencies": { "viem": "^2.47.6" },
|
|
55
60
|
"devDependencies": {
|
|
56
61
|
"@types/bun": "latest",
|
|
57
62
|
"tsdown": "^0.21.10",
|
|
58
|
-
"typescript": "^5.7.0"
|
|
63
|
+
"typescript": "^5.7.0",
|
|
64
|
+
"viem": "^2.47.6"
|
|
59
65
|
}
|
|
60
66
|
}
|