From 9c7e40010c9d9ad2601ad0dbb984092158f5298a Mon Sep 17 00:00:00 2001 From: devmosis Date: Tue, 6 Jan 2026 17:51:43 +0900 Subject: [PATCH 1/5] oko_attached: implement siws modal --- .../message_sig/make_message_sig_modal.tsx | 75 ++++- .../siws_sig/make_siws_signature_content.tsx | 127 +++++++++ .../index.tsx | 56 ++++ .../styles.module.scss | 10 + .../siws_risk_warning_box.module.scss | 28 ++ .../siws_sig/siws_risk_warning_box.tsx | 46 ++++ .../siws_sig/siws_sig_title_badge/index.tsx | 21 ++ .../siws_sig_title_badge/styles.module.scss | 14 + .../solana_siws_signature_content.module.scss | 49 ++++ .../modal_variants/sol/siws_message.ts | 258 ++++++++++++++++++ 10 files changed, 675 insertions(+), 9 deletions(-) create mode 100644 embed/oko_attached/src/components/modal_variants/sol/message_sig/siws_sig/make_siws_signature_content.tsx create mode 100644 embed/oko_attached/src/components/modal_variants/sol/message_sig/siws_sig/signer_address_or_email_for_siws/index.tsx create mode 100644 embed/oko_attached/src/components/modal_variants/sol/message_sig/siws_sig/signer_address_or_email_for_siws/styles.module.scss create mode 100644 embed/oko_attached/src/components/modal_variants/sol/message_sig/siws_sig/siws_risk_warning_box.module.scss create mode 100644 embed/oko_attached/src/components/modal_variants/sol/message_sig/siws_sig/siws_risk_warning_box.tsx create mode 100644 embed/oko_attached/src/components/modal_variants/sol/message_sig/siws_sig/siws_sig_title_badge/index.tsx create mode 100644 embed/oko_attached/src/components/modal_variants/sol/message_sig/siws_sig/siws_sig_title_badge/styles.module.scss create mode 100644 embed/oko_attached/src/components/modal_variants/sol/message_sig/siws_sig/solana_siws_signature_content.module.scss create mode 100644 embed/oko_attached/src/components/modal_variants/sol/siws_message.ts diff --git a/embed/oko_attached/src/components/modal_variants/sol/message_sig/make_message_sig_modal.tsx b/embed/oko_attached/src/components/modal_variants/sol/message_sig/make_message_sig_modal.tsx index a3b1eab16..c8e57a600 100644 --- a/embed/oko_attached/src/components/modal_variants/sol/message_sig/make_message_sig_modal.tsx +++ b/embed/oko_attached/src/components/modal_variants/sol/message_sig/make_message_sig_modal.tsx @@ -1,4 +1,4 @@ -import type { FC } from "react"; +import { useMemo, useState, type FC } from "react"; import type { MakeSolMessageSignData } from "@oko-wallet/oko-sdk-core"; import { XCloseIcon } from "@oko-wallet/oko-common-ui/icons/x_close"; import { Spacing } from "@oko-wallet/oko-common-ui/spacing"; @@ -10,6 +10,13 @@ import { DemoView } from "@oko-wallet-attached/components/modal_variants/common/ import { SignWithOkoBox } from "@oko-wallet-attached/components/sign_with_oko_box/sign_with_oko_box"; import { useMessageSigModal } from "./use_message_sig_modal"; import { SolanaMessageSignatureContent } from "./sol_message_signature_content"; +import { + getSiwsMessage, + verifySiwsMessage, +} from "@oko-wallet-attached/components/modal_variants/sol/siws_message"; +import { SolanaSiwsSignatureContent } from "@oko-wallet-attached/components/modal_variants/sol/message_sig/siws_sig/make_siws_signature_content"; +import { SiwsRiskWarningCheckBox } from "@oko-wallet-attached/components/modal_variants/sol/message_sig/siws_sig/siws_risk_warning_box"; +import { hexToUint8Array } from "@oko-wallet-attached/crypto/keygen_ed25519"; export interface MakeMessageSigModalProps { getIsAborted: () => boolean; @@ -22,12 +29,48 @@ export const MakeMessageSigModal: FC = ({ data, modalId, }) => { - const { onReject, onApprove, isLoading, isApproveEnabled, isDemo, theme } = - useMessageSigModal({ - getIsAborted, - data, - modalId, - }); + // Decode hex message to check for SIWS + const decodedMessage = useMemo(() => { + try { + const bytes = hexToUint8Array(data.payload.data.message); + return new TextDecoder().decode(bytes); + } catch { + return data.payload.data.message; + } + }, [data.payload.data.message]); + + const siwsMessage = getSiwsMessage(decodedMessage); + const isValidSiwsMessage = siwsMessage + ? verifySiwsMessage(siwsMessage, data.payload.origin) + : false; + const [isSiwsRiskWarningChecked, setIsSiwsRiskWarningChecked] = + useState(false); + + const { + onReject, + onApprove, + isLoading, + isApproveEnabled: isApproveEnabledOriginal, + isDemo, + theme, + } = useMessageSigModal({ + getIsAborted, + data, + modalId, + }); + + const isApproveEnabled = useMemo(() => { + if (siwsMessage && !isValidSiwsMessage) { + return isApproveEnabledOriginal && isSiwsRiskWarningChecked; + } + + return isApproveEnabledOriginal; + }, [ + isApproveEnabledOriginal, + isSiwsRiskWarningChecked, + siwsMessage, + isValidSiwsMessage, + ]); return (
@@ -37,10 +80,24 @@ export const MakeMessageSigModal: FC = ({
- + {!!siwsMessage ? ( + + ) : ( + + )}
- + + + {siwsMessage && !isValidSiwsMessage && ( + <> + + + + )}