Skip to content

Commit

Permalink
Disable signature verification on login
Browse files Browse the repository at this point in the history
  • Loading branch information
r-czajkowski committed Sep 25, 2024
1 parent 7576045 commit e32336e
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions dapp/src/hooks/useSignMessageAndCreateSession.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { OrangeKitConnector } from "#/types"
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { acreApi, orangeKit } from "#/utils"
import { generateNonce } from "@orangekit/sign-in-with-wallet"
import { useCallback } from "react"
import { useSignMessage } from "wagmi"

Expand All @@ -8,43 +10,41 @@ function useSignMessageAndCreateSession() {

const signMessageAndCreateSession = useCallback(
async (connectedConnector: OrangeKitConnector, btcAddress: string) => {
let session = await acreApi.getSession()
const hasSessionAddress = "address" in session

const isSessionAddressEqual = hasSessionAddress
? (session as { address: string }).address === btcAddress
: false

if (hasSessionAddress && isSessionAddressEqual) {
return
}

if (hasSessionAddress && !isSessionAddressEqual) {
// Delete session.
await acreApi.deleteSession()
// Ask for nonce to create new session.
session = await acreApi.getSession()
}

if (!("nonce" in session)) {
throw new Error("Session nonce not available")
}

const message = orangeKit.createSignInWithWalletMessage(
btcAddress,
session.nonce,
)

// const session = await acreApi.getSession()
// const hasSessionAddress = "address" in session

// const isSessionAddressEqual = hasSessionAddress
// ? (session as { address: string }).address === btcAddress
// : false

// if (hasSessionAddress && isSessionAddressEqual) {
// return
// }

// if (hasSessionAddress && !isSessionAddressEqual) {
// // Delete session.
// await acreApi.deleteSession()
// // Ask for nonce to create new session.
// session = await acreApi.getSession()
// }

// if (!("nonce" in session)) {
// throw new Error("Session nonce not available")
// }
const nonce = generateNonce()
const message = orangeKit.createSignInWithWalletMessage(btcAddress, nonce)

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const signedMessage = await signMessageAsync({
message,
connector: orangeKit.typeConversionToConnector(connectedConnector),
})

const publicKey = await connectedConnector
.getBitcoinProvider()
.getPublicKey()
// const publicKey = await connectedConnector
// .getBitcoinProvider()
// .getPublicKey()

await acreApi.createSession(message, signedMessage, publicKey)
// await acreApi.createSession(message, signedMessage, publicKey)
},
[signMessageAsync],
)
Expand Down

0 comments on commit e32336e

Please sign in to comment.