feat: implement token verification

This commit is contained in:
jinhojang6 2024-10-21 02:12:32 +09:00
parent 39083da5f2
commit a50c7dd187
2 changed files with 23 additions and 1 deletions

6
constants/wallet.ts Normal file
View File

@ -0,0 +1,6 @@
export const WALLET_SIGN_MESSAGE_REQUEST = `Welcome to The Exit!
Please click to verify your wallet ownership and to sign into The Exit.
This request will not trigger a blockchain transaction or cost any gas fees.
`

View File

@ -4,6 +4,8 @@ import { truncateString } from '@/utils/general.utils'
import styled from '@emotion/styled'
import Link from 'next/link'
import React, { useState } from 'react'
import { api } from '../../../../common/api'
import { WALLET_SIGN_MESSAGE_REQUEST } from '../../../../constants/wallet'
import { Navbar } from '../Navbar'
declare global {
@ -27,7 +29,21 @@ const Header: React.FC<NavbarProps> = () => {
// DOCS: https://www.okx.com/web3/build/docs/sdks/chains/bitcoin/provider#connect
if (window.okxwallet) {
const result = await window.okxwallet.bitcoin.connect()
setWalletAddress(result.address)
const address = result.address
setWalletAddress(address)
const signature = await window.okxwallet.bitcoin.signMessage(
WALLET_SIGN_MESSAGE_REQUEST,
'bip322-simple',
)
const response = await api.post('/token/pair', {
address,
signature,
})
console.log('Token pair response:', response)
} else {
alert('No Bitcoin wallet found. Please install OKX Wallet.')
}