diff --git a/apps/demo_web/src/components/widgets/login_widget/login_default_view.tsx b/apps/demo_web/src/components/widgets/login_widget/login_default_view.tsx index 92d73a9ec..2cc2715e0 100644 --- a/apps/demo_web/src/components/widgets/login_widget/login_default_view.tsx +++ b/apps/demo_web/src/components/widgets/login_widget/login_default_view.tsx @@ -10,7 +10,7 @@ import { TelegramIcon } from "@oko-wallet/oko-common-ui/icons/telegram_icon"; import { XIcon } from "@oko-wallet/oko-common-ui/icons/x_icon"; import { AppleIcon } from "@oko-wallet/oko-common-ui/icons/apple_icon"; import { MailboxIcon } from "@oko-wallet/oko-common-ui/icons/mailbox"; -import { OkoLogoWithNameIcon } from "@oko-wallet-common-ui/icons/oko_logo_with_name_icon"; +import { OkoLogoWithNameIcon } from "@oko-wallet/oko-common-ui/icons/oko_logo_with_name_icon"; import styles from "./login_widget.module.scss"; import type { LoginMethod } from "@oko-wallet-demo-web/types/login"; @@ -30,67 +30,29 @@ export const LoginDefaultView: FC = ({ - {/* @TODO: remove comment after other socials are implemented for production */} - {/* */} - - - - {/* @TODO: remove dividerRow after email login is implemented for production */} -
-
- - Coming soon - -
-
-
- {/* @TODO: remove emailLoginMethod after email login is implemented for production */} -
- - - -
+ + + - - - - -
- - - - - - ); -}; diff --git a/apps/demo_web/src/state/user_info.ts b/apps/demo_web/src/state/user_info.ts index 2e16aaca7..e6bdfd843 100644 --- a/apps/demo_web/src/state/user_info.ts +++ b/apps/demo_web/src/state/user_info.ts @@ -33,10 +33,10 @@ export const useUserInfoState = create( setUserInfo: (info) => { set({ authType: info.authType, - email: info.email, + email: info.email ?? null, publicKey: info.publicKey, name: info.name ?? null, - isSignedIn: !!(info.email && info.publicKey), + isSignedIn: !!info.publicKey, }); }, clearUserInfo: () => { diff --git a/backend/openapi/src/tss/user.ts b/backend/openapi/src/tss/user.ts index f69640dc8..d861292a5 100644 --- a/backend/openapi/src/tss/user.ts +++ b/backend/openapi/src/tss/user.ts @@ -19,15 +19,18 @@ export const SignInResponseSchema = registry.register( }), user: z .object({ - email: z.string().openapi({ - description: "User email address", - }), wallet_id: z.string().openapi({ description: "Unique wallet identifier", }), public_key: z.string().openapi({ description: "Public key in hex format", }), + user_identifier: z.string().openapi({ + description: "User identifier", + }), + email: z.string().nullable().openapi({ + description: "User email address (nullable)", + }), name: z.string().nullable().openapi({ description: "User name (nullable) Only for OAuth providers that support it", diff --git a/backend/tss_api/src/api/keygen/index.test.ts b/backend/tss_api/src/api/keygen/index.test.ts index 0169bef6e..b69ac51a4 100644 --- a/backend/tss_api/src/api/keygen/index.test.ts +++ b/backend/tss_api/src/api/keygen/index.test.ts @@ -91,6 +91,7 @@ describe("keygen_test", () => { const keygenRequest: KeygenRequest = { auth_type: "google", + user_identifier: "test@test.com", email: "test@test.com", keygen_2, }; @@ -196,6 +197,7 @@ describe("keygen_test", () => { const keygenRequest: KeygenRequest = { auth_type: "google", + user_identifier: "test@test.com", email: "test@test.com", keygen_2: { public_key: keygen_outputs[Participant.P1].public_key, @@ -237,6 +239,7 @@ describe("keygen_test", () => { const keygenRequest: KeygenRequest = { auth_type: "google", + user_identifier: "test@test.com", email: "test@test.com", keygen_2: { public_key: keygen_outputs[Participant.P1].public_key, @@ -274,6 +277,7 @@ describe("keygen_test", () => { const keygenRequest: KeygenRequest = { auth_type: "google", + user_identifier: "test@test.com", email: "test@test.com", keygen_2: { public_key: keygen_outputs[Participant.P1].public_key, @@ -313,6 +317,7 @@ describe("keygen_test", () => { const keygenRequest: KeygenRequest = { auth_type: "google", + user_identifier: "test@test.com", email: "test@test.com", keygen_2: { public_key: keygen_outputs[Participant.P1].public_key, diff --git a/backend/tss_api/src/api/keygen/index.ts b/backend/tss_api/src/api/keygen/index.ts index 370a86434..85feb4340 100644 --- a/backend/tss_api/src/api/keygen/index.ts +++ b/backend/tss_api/src/api/keygen/index.ts @@ -34,9 +34,13 @@ export async function runKeygen( encryptionSecret: string, ): Promise> { try { - const { auth_type, email, keygen_2, name } = keygenRequest; + const { auth_type, user_identifier, keygen_2, email, name } = keygenRequest; - const getUserRes = await getUserByEmailAndAuthType(db, email, auth_type); + const getUserRes = await getUserByEmailAndAuthType( + db, + user_identifier, + auth_type, + ); if (getUserRes.success === false) { return { success: false, @@ -69,7 +73,7 @@ export async function runKeygen( }; } } else { - const createUserRes = await createUser(db, email, auth_type); + const createUserRes = await createUser(db, user_identifier, auth_type); if (createUserRes.success === false) { return { success: false, @@ -123,7 +127,7 @@ export async function runKeygen( const activeKSNodes = getActiveKSNodesRes.data; const checkKeyshareFromKSNodesRes = await checkKeyShareFromKSNodes( - email, + user_identifier, publicKeyBytes, activeKSNodes, auth_type, @@ -200,7 +204,7 @@ export async function runKeygen( const tokenResult = generateUserToken({ wallet_id: wallet.wallet_id, - email: email, + email: user_identifier, jwt_config: jwtConfig, }); @@ -217,9 +221,10 @@ export async function runKeygen( data: { token: tokenResult.data.token, user: { - email: email, wallet_id: wallet.wallet_id, public_key: keygen_2.public_key, + user_identifier: user_identifier, + email: email ?? null, name: name ?? null, }, }, diff --git a/backend/tss_api/src/api/presign/index.test.ts b/backend/tss_api/src/api/presign/index.test.ts index 2e2aea8f9..299e2a10b 100644 --- a/backend/tss_api/src/api/presign/index.test.ts +++ b/backend/tss_api/src/api/presign/index.test.ts @@ -135,6 +135,7 @@ async function setUpTssStage(pool: Pool) { const keygenRequest: KeygenRequest = { auth_type: "google", + user_identifier: email, email: email, keygen_2, }; diff --git a/backend/tss_api/src/api/sign/index.test.ts b/backend/tss_api/src/api/sign/index.test.ts index 7b26d8b00..a4808d505 100644 --- a/backend/tss_api/src/api/sign/index.test.ts +++ b/backend/tss_api/src/api/sign/index.test.ts @@ -138,6 +138,7 @@ async function setUpTssStage(pool: Pool) { const keygenRequest: KeygenRequest = { auth_type: "google", + user_identifier: email, email: email, keygen_2, }; diff --git a/backend/tss_api/src/api/user/index.ts b/backend/tss_api/src/api/user/index.ts index b11828fc4..d051e2860 100644 --- a/backend/tss_api/src/api/user/index.ts +++ b/backend/tss_api/src/api/user/index.ts @@ -32,16 +32,21 @@ import { checkKeyShareFromKSNodes } from "@oko-wallet-tss-api/api/ks_node"; export async function signIn( db: Pool, - email: string, + user_identifier: string, auth_type: AuthType, jwt_config: { secret: string; expires_in: string; }, + email?: string, name?: string, ): Promise> { try { - const getUserRes = await getUserByEmailAndAuthType(db, email, auth_type); + const getUserRes = await getUserByEmailAndAuthType( + db, + user_identifier, + auth_type, + ); if (getUserRes.success === false) { return { success: false, @@ -53,7 +58,7 @@ export async function signIn( return { success: false, code: "USER_NOT_FOUND", - msg: `User not found: ${email} (auth_type: ${auth_type})`, + msg: `User not found: ${user_identifier} (auth_type: ${auth_type})`, }; } @@ -96,9 +101,10 @@ export async function signIn( data: { token: tokenResult.data.token, user: { - email: getUserRes.data.email, wallet_id: walletRes.data.wallet_id, public_key: walletRes.data.public_key.toString("hex"), + user_identifier: user_identifier, + email: email ?? null, name: name ?? null, }, }, diff --git a/backend/tss_api/src/middleware/auth0_auth/index.ts b/backend/tss_api/src/middleware/auth0_auth/index.ts index c982aaad4..c4783f980 100644 --- a/backend/tss_api/src/middleware/auth0_auth/index.ts +++ b/backend/tss_api/src/middleware/auth0_auth/index.ts @@ -56,6 +56,8 @@ export async function auth0AuthMiddleware( res.locals.oauth_user = { type: "auth0" as AuthType, + // in auth0, use email as identifier + user_identifier: result.data.email, email: result.data.email, }; diff --git a/backend/tss_api/src/middleware/discord_auth/index.ts b/backend/tss_api/src/middleware/discord_auth/index.ts index d3e6ad5a5..5b15ca0ad 100644 --- a/backend/tss_api/src/middleware/discord_auth/index.ts +++ b/backend/tss_api/src/middleware/discord_auth/index.ts @@ -48,8 +48,9 @@ export async function discordAuthMiddleware( res.locals.oauth_user = { type: "discord" as AuthType, - // in discord, use discord id as email with prefix - email: `discord_${result.data.id}`, + // in discord, use discord id as identifier with prefix + user_identifier: `discord_${result.data.id}`, + email: result.data.email, name: result.data.username, }; diff --git a/backend/tss_api/src/middleware/google_auth/index.ts b/backend/tss_api/src/middleware/google_auth/index.ts index 961f26a5b..e4c0a85b8 100644 --- a/backend/tss_api/src/middleware/google_auth/index.ts +++ b/backend/tss_api/src/middleware/google_auth/index.ts @@ -49,9 +49,9 @@ export async function googleAuthMiddleware( res.locals.oauth_user = { type: "google" as AuthType, - // in google, use google sub as email with prefix - email: `google_${result.data.sub}`, - name: result.data.email, + // in google, use google sub as identifier with prefix + user_identifier: `google_${result.data.sub}`, + email: result.data.email, }; next(); diff --git a/backend/tss_api/src/middleware/telegram_auth/index.ts b/backend/tss_api/src/middleware/telegram_auth/index.ts index 6db7c027f..8c40a1d29 100644 --- a/backend/tss_api/src/middleware/telegram_auth/index.ts +++ b/backend/tss_api/src/middleware/telegram_auth/index.ts @@ -63,8 +63,8 @@ export async function telegramAuthMiddleware( res.locals.oauth_user = { type: "telegram" as AuthType, - // in telegram, use telegram id as email with prefix - email: `telegram_${userInfo.id}`, + // in telegram, use telegram id as identifier with prefix + user_identifier: `telegram_${userInfo.id}`, name: userInfo.username, }; diff --git a/backend/tss_api/src/middleware/types.ts b/backend/tss_api/src/middleware/types.ts index 003174ed0..a3c10cc2f 100644 --- a/backend/tss_api/src/middleware/types.ts +++ b/backend/tss_api/src/middleware/types.ts @@ -6,8 +6,10 @@ export interface OAuthBody { export interface OAuthUser { type: AuthType; - email: string; - // `x` is username, `telegram` is username + user_identifier: string; + // google, auth0, discord + email?: string; + // x, telegram, discord name?: string; } diff --git a/backend/tss_api/src/middleware/x_auth/index.ts b/backend/tss_api/src/middleware/x_auth/index.ts index c8de151d3..aa10eff8b 100644 --- a/backend/tss_api/src/middleware/x_auth/index.ts +++ b/backend/tss_api/src/middleware/x_auth/index.ts @@ -48,8 +48,8 @@ export async function xAuthMiddleware( res.locals.oauth_user = { type: "x" as AuthType, - // in x, use x id as email with prefix - email: `x_${result.data.id}`, + // in x, use x id as email identifier with prefix + user_identifier: `x_${result.data.id}`, name: result.data.username, }; diff --git a/backend/tss_api/src/routes/keygen.test.ts b/backend/tss_api/src/routes/keygen.test.ts index e7b4a0cba..56067a274 100644 --- a/backend/tss_api/src/routes/keygen.test.ts +++ b/backend/tss_api/src/routes/keygen.test.ts @@ -35,6 +35,7 @@ const mockOauthMiddleware = jest.fn((req: any, res: any, next: any) => { } res.locals.oauth_user = { type: req.body.auth_type, + user_identifier: "test@example.com", email: "test@example.com", name: "Test User", sub: "test123", @@ -125,6 +126,7 @@ describe("keygen_route_test", () => { data: { token: "test_token", user: { + user_identifier: "test@example.com", email: "test@example.com", wallet_id: "test_wallet_id", public_key: "test_public_key", @@ -153,6 +155,7 @@ describe("keygen_route_test", () => { }, { auth_type: "google", + user_identifier: "test@example.com", email: "test@example.com", keygen_2: testKeygenBody.keygen_2, name: "Test User", @@ -190,6 +193,7 @@ describe("keygen_route_test", () => { }, { auth_type: "google", + user_identifier: "test@example.com", email: "test@example.com", keygen_2: testKeygenBody.keygen_2, name: "Test User", diff --git a/backend/tss_api/src/routes/keygen.ts b/backend/tss_api/src/routes/keygen.ts index 05c7cc84f..c4b539af2 100644 --- a/backend/tss_api/src/routes/keygen.ts +++ b/backend/tss_api/src/routes/keygen.ts @@ -88,13 +88,14 @@ export function setKeygenRoutes(router: Router) { const state = req.app.locals; const oauthUser = res.locals.oauth_user; const auth_type = oauthUser.type as AuthType; + const user_identifier = oauthUser.user_identifier; const body = req.body; - if (!oauthUser?.email) { + if (!user_identifier) { res.status(401).json({ success: false, code: "UNAUTHORIZED", - msg: "User email not found", + msg: "User identifier not found", }); return; } @@ -109,8 +110,9 @@ export function setKeygenRoutes(router: Router) { jwtConfig, { auth_type, - email: oauthUser.email.toLowerCase(), + user_identifier, keygen_2: body.keygen_2, + email: oauthUser.email, name: oauthUser.name, }, state.encryption_secret, diff --git a/backend/tss_api/src/routes/user.test.ts b/backend/tss_api/src/routes/user.test.ts index b47d4c136..40d804338 100644 --- a/backend/tss_api/src/routes/user.test.ts +++ b/backend/tss_api/src/routes/user.test.ts @@ -43,9 +43,9 @@ const mockOauthMiddleware = jest.fn((req: any, res: any, next: any) => { } res.locals.oauth_user = { type: req.body.auth_type, + user_identifier: "test@example.com", email: "test@example.com", name: "Test User", - sub: "test123", }; next(); }); diff --git a/backend/tss_api/src/routes/user.ts b/backend/tss_api/src/routes/user.ts index 8a8c2abb1..0450c2907 100644 --- a/backend/tss_api/src/routes/user.ts +++ b/backend/tss_api/src/routes/user.ts @@ -191,8 +191,9 @@ export function setUserRoutes(router: Router) { const state = req.app.locals; const oauthUser = res.locals.oauth_user; const auth_type = oauthUser.type as AuthType; + const user_identifier = oauthUser.user_identifier; - if (!oauthUser?.email) { + if (!user_identifier) { res.status(401).json({ success: false, code: "UNAUTHORIZED", @@ -201,16 +202,15 @@ export function setUserRoutes(router: Router) { return; } - const userEmail = oauthUser.email.toLowerCase(); - const signInRes = await signIn( state.db, - userEmail, + user_identifier, auth_type, { secret: state.jwt_secret, expires_in: state.jwt_expires_in, }, + oauthUser.email, oauthUser.name, ); if (signInRes.success === false) { @@ -413,13 +413,14 @@ export function setUserRoutes(router: Router) { const state = req.app.locals; const oauthUser = res.locals.oauth_user; const auth_type = oauthUser.type as AuthType; + const user_identifier = oauthUser.user_identifier; const { public_key, reshared_key_shares } = req.body; - if (!oauthUser?.email) { + if (!user_identifier) { res.status(401).json({ success: false, code: "UNAUTHORIZED", - msg: "User email not found", + msg: "User identifier not found", }); return; } @@ -445,7 +446,7 @@ export function setUserRoutes(router: Router) { const reshareRes = await updateWalletKSNodesForReshare( state.db, - oauthUser.email.toLowerCase(), + user_identifier, auth_type, publicKeyRes.data, reshared_key_shares, diff --git a/common/oko_types/src/tss/keygen.ts b/common/oko_types/src/tss/keygen.ts index 8371e5e71..d230b7519 100644 --- a/common/oko_types/src/tss/keygen.ts +++ b/common/oko_types/src/tss/keygen.ts @@ -4,8 +4,9 @@ import type { AuthType, OAuthRequest } from "../auth"; export interface KeygenRequest { auth_type: AuthType; - email: string; + user_identifier: string; keygen_2: KeygenOutput; + email?: string; name?: string; } diff --git a/common/oko_types/src/user/index.ts b/common/oko_types/src/user/index.ts index 44da76999..4e53b9a7a 100644 --- a/common/oko_types/src/user/index.ts +++ b/common/oko_types/src/user/index.ts @@ -29,9 +29,10 @@ export interface CheckEmailResponse { export interface SignInResponse { token: string; user: { - email: string; wallet_id: string; public_key: string; + user_identifier: string; + email: string | null; name: string | null; }; } diff --git a/embed/oko_attached/src/store/app.ts b/embed/oko_attached/src/store/app.ts index ebd3d540d..d8519557c 100644 --- a/embed/oko_attached/src/store/app.ts +++ b/embed/oko_attached/src/store/app.ts @@ -9,7 +9,7 @@ interface WalletState { authType: AuthType; walletId: string; publicKey: string; - email: string; + email: string | null; name: string | null; } diff --git a/embed/oko_attached/src/window_msgs/get_auth_type.ts b/embed/oko_attached/src/window_msgs/get_auth_type.ts new file mode 100644 index 000000000..aa808afb0 --- /dev/null +++ b/embed/oko_attached/src/window_msgs/get_auth_type.ts @@ -0,0 +1,31 @@ +import type { OkoWalletMsgGetAuthTypeAck } from "@oko-wallet/oko-sdk-core"; + +import { OKO_SDK_TARGET } from "./target"; +import { useAppState } from "@oko-wallet-attached/store/app"; +import type { MsgEventContext } from "./types"; + +export async function handleGetAuthType(ctx: MsgEventContext) { + const { port, hostOrigin } = ctx; + const wallet = useAppState.getState().getWallet(hostOrigin); + + let payload: OkoWalletMsgGetAuthTypeAck["payload"]; + if (wallet?.authType) { + payload = { + success: true, + data: wallet.authType, + }; + } else { + payload = { + success: false, + err: "No auth type found", + }; + } + + const ack: OkoWalletMsgGetAuthTypeAck = { + target: OKO_SDK_TARGET, + msg_type: "get_auth_type_ack", + payload, + }; + + port.postMessage(ack); +} diff --git a/embed/oko_attached/src/window_msgs/get_wallet_info.ts b/embed/oko_attached/src/window_msgs/get_wallet_info.ts index 076ceb082..a79cab35f 100644 --- a/embed/oko_attached/src/window_msgs/get_wallet_info.ts +++ b/embed/oko_attached/src/window_msgs/get_wallet_info.ts @@ -15,7 +15,7 @@ export async function handleGetWalletInfo(ctx: MsgEventContext) { data: { authType: wallet.authType, publicKey: wallet.publicKey, - email: wallet.email, + email: wallet.email ?? null, name: wallet.name ?? null, }, }; diff --git a/embed/oko_attached/src/window_msgs/index.ts b/embed/oko_attached/src/window_msgs/index.ts index 82b08ad29..440c2a161 100644 --- a/embed/oko_attached/src/window_msgs/index.ts +++ b/embed/oko_attached/src/window_msgs/index.ts @@ -9,6 +9,7 @@ import { handleSignOut } from "./sign_out"; import { handleGetEmail } from "./get_email"; import { handleGetName } from "./get_name"; import { handleGetWalletInfo } from "./get_wallet_info"; +import { handleGetAuthType } from "./get_auth_type"; import { handleGetCosmosChain } from "./get_cosmos_chain_info"; import { handleOAuthInfoPass } from "./oauth_info_pass"; import { handleGetEthChain } from "./get_eth_chain_info"; @@ -72,6 +73,11 @@ export function makeMsgHandler() { break; } + case "get_auth_type": { + await handleGetAuthType(ctx); + break; + } + case "open_modal": { await handleOpenModal(ctx, message); break; diff --git a/embed/oko_attached/src/window_msgs/oauth_info_pass/index.ts b/embed/oko_attached/src/window_msgs/oauth_info_pass/index.ts index 371214b84..a50ca087b 100644 --- a/embed/oko_attached/src/window_msgs/oauth_info_pass/index.ts +++ b/embed/oko_attached/src/window_msgs/oauth_info_pass/index.ts @@ -120,7 +120,7 @@ export async function handleOAuthInfoPass( authType, walletId: signInResult.walletId, publicKey: signInResult.publicKey, - email: userIdentifier, + email: signInResult.email, name: signInResult.name, }); diff --git a/embed/oko_attached/src/window_msgs/oauth_info_pass/user.ts b/embed/oko_attached/src/window_msgs/oauth_info_pass/user.ts index 178c20d27..0624d8f37 100644 --- a/embed/oko_attached/src/window_msgs/oauth_info_pass/user.ts +++ b/embed/oko_attached/src/window_msgs/oauth_info_pass/user.ts @@ -139,6 +139,7 @@ export async function handleExistingUser( jwtToken: signInResp.token, keyshare_1: keyshare_1_res.data, isNewUser: false, + email: signInResp.user.email ?? null, name: signInResp.user.name ?? null, }, }; @@ -180,6 +181,7 @@ user pk: ${signInResp.user.public_key}`, jwtToken: signInResp.token, keyshare_1: keyshare_1_res.data, isNewUser: false, + email: signInResp.user.email ?? null, name: signInResp.user.name ?? null, }, }; @@ -279,6 +281,7 @@ export async function handleNewUser( jwtToken: reqKeygenRes.data.token, keyshare_1: keygen_1.tss_private_share.toHex(), isNewUser: true, + email: reqKeygenRes.data.user.email ?? null, name: reqKeygenRes.data.user.name ?? null, }, }; @@ -385,6 +388,7 @@ export async function handleReshare( jwtToken: signInResp.token, keyshare_1: keyshare_1_res.data, isNewUser: false, + email: signInResp.user.email ?? null, name: signInResp.user.name ?? null, }, }; diff --git a/embed/oko_attached/src/window_msgs/types.ts b/embed/oko_attached/src/window_msgs/types.ts index 66591a1eb..aa7109b84 100644 --- a/embed/oko_attached/src/window_msgs/types.ts +++ b/embed/oko_attached/src/window_msgs/types.ts @@ -68,4 +68,5 @@ export interface UserSignInResult { keyshare_1: string; isNewUser: boolean; name: string | null; + email: string | null; } diff --git a/sdk/oko_sdk_core/src/methods/get_auth_type.ts b/sdk/oko_sdk_core/src/methods/get_auth_type.ts new file mode 100644 index 000000000..2c117aa35 --- /dev/null +++ b/sdk/oko_sdk_core/src/methods/get_auth_type.ts @@ -0,0 +1,22 @@ +import type { OkoWalletInterface } from "@oko-wallet-sdk-core/types"; +import type { AuthType } from "@oko-wallet/oko-types/auth"; +import { OKO_ATTACHED_TARGET } from "@oko-wallet-sdk-core/window_msg/target"; + +export async function getAuthType( + this: OkoWalletInterface, +): Promise { + await this.waitUntilInitialized; + + const res = await this.sendMsgToIframe({ + target: OKO_ATTACHED_TARGET, + msg_type: "get_auth_type", + payload: null, + }); + + if (res.msg_type === "get_auth_type_ack" && res.payload.success) { + return res.payload.data; + } + + return null; +} + diff --git a/sdk/oko_sdk_core/src/methods/sign_in/index.ts b/sdk/oko_sdk_core/src/methods/sign_in/index.ts index 284d4797d..9baf573cd 100644 --- a/sdk/oko_sdk_core/src/methods/sign_in/index.ts +++ b/sdk/oko_sdk_core/src/methods/sign_in/index.ts @@ -39,14 +39,14 @@ export async function signIn(this: OkoWalletInterface, type: SignInType) { return; } - if (walletInfo.publicKey && walletInfo.email) { + if (walletInfo.authType && walletInfo.publicKey) { console.log("[oko] emit CORE__accountsChanged"); this.eventEmitter.emit({ type: "CORE__accountsChanged", authType: walletInfo.authType, - email: walletInfo.email, publicKey: walletInfo.publicKey, + email: walletInfo.email, name: walletInfo.name, }); } diff --git a/sdk/oko_sdk_core/src/oko.ts b/sdk/oko_sdk_core/src/oko.ts index 59fcb66ec..85b426dd1 100644 --- a/sdk/oko_sdk_core/src/oko.ts +++ b/sdk/oko_sdk_core/src/oko.ts @@ -7,6 +7,7 @@ import { getPublicKey } from "./methods/get_public_key"; import { getEmail } from "./methods/get_email"; import { getName } from "./methods/get_name"; import { getWalletInfo } from "./methods/get_wallet_info"; +import { getAuthType } from "./methods/get_auth_type"; import { closeModal } from "./methods/close_modal"; import { on } from "./methods/on"; import type { OkoWalletInterface } from "./types"; @@ -26,6 +27,7 @@ ptype.signOut = signOut; ptype.getPublicKey = getPublicKey; ptype.getEmail = getEmail; ptype.getName = getName; +ptype.getAuthType = getAuthType; ptype.getWalletInfo = getWalletInfo; ptype.on = on; diff --git a/sdk/oko_sdk_core/src/types/msg/index.ts b/sdk/oko_sdk_core/src/types/msg/index.ts index 000e9b745..6e3b4abba 100644 --- a/sdk/oko_sdk_core/src/types/msg/index.ts +++ b/sdk/oko_sdk_core/src/types/msg/index.ts @@ -149,7 +149,7 @@ export type OkoWalletMsgGetNameAck = { export type WalletInfo = { authType: AuthType; publicKey: string; - email: string; + email: string | null; name: string | null; }; @@ -165,6 +165,18 @@ export type OkoWalletMsgGetWalletInfoAck = { payload: Result; }; +export type OkoWalletMsgGetAuthType = { + target: "oko_attached"; + msg_type: "get_auth_type"; + payload: null; +}; + +export type OkoWalletMsgGetAuthTypeAck = { + target: "oko_sdk"; + msg_type: "get_auth_type_ack"; + payload: Result; +}; + export type OkoWalletMsgGetCosmosChainInfo = { target: "oko_attached"; msg_type: "get_cosmos_chain_info"; @@ -230,6 +242,8 @@ export type OkoWalletMsg = | OkoWalletMsgGetNameAck | OkoWalletMsgGetWalletInfo | OkoWalletMsgGetWalletInfoAck + | OkoWalletMsgGetAuthType + | OkoWalletMsgGetAuthTypeAck | OkoWalletMsgGetCosmosChainInfo | OkoWalletMsgGetCosmosChainInfoAck | OkoWalletMsgGetEthChainInfo diff --git a/sdk/oko_sdk_core/src/types/oko_wallet.ts b/sdk/oko_sdk_core/src/types/oko_wallet.ts index d527dca2a..a9c24a1e0 100644 --- a/sdk/oko_sdk_core/src/types/oko_wallet.ts +++ b/sdk/oko_sdk_core/src/types/oko_wallet.ts @@ -43,6 +43,7 @@ export interface OkoWalletInterface { getEmail: () => Promise; getName: () => Promise; getWalletInfo: () => Promise; + getAuthType: () => Promise; startEmailSignIn: (email: string) => Promise; completeEmailSignIn: (email: string, code: string) => Promise; on: (handlerDef: OkoWalletCoreEventHandler2) => void;