Use current wallet address for generating identity proofs
This commit is contained in:
parent
b455645173
commit
93fafa250d
4 changed files with 24 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
|||
import { BACKEND_URL } from "@/constants"
|
||||
|
||||
import { createDidFromEthereumAddress } from "@/utils/did"
|
||||
import { http } from "./common"
|
||||
import { Post } from "./posts"
|
||||
import { Profile } from "./users"
|
||||
|
@ -32,7 +33,7 @@ export async function searchProfileByEthereumAddress(
|
|||
const url = `${BACKEND_URL}/api/v1/accounts/search_did`
|
||||
const response = await http(url, {
|
||||
method: "GET",
|
||||
queryParams: { did: `did:pkh:eip155:1:${walletAddress.toLowerCase()}` },
|
||||
queryParams: { did: createDidFromEthereumAddress(walletAddress) },
|
||||
})
|
||||
const data = await response.json()
|
||||
if (response.status !== 200) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { BACKEND_URL } from "@/constants"
|
||||
import { createDidFromEthereumAddress } from "@/utils/did"
|
||||
import { PAGE_SIZE, http } from "./common"
|
||||
|
||||
export interface ProfileField {
|
||||
|
@ -174,21 +175,29 @@ export async function updateProfile(
|
|||
}
|
||||
}
|
||||
|
||||
export async function getIdentityClaim(authToken: string): Promise<string> {
|
||||
export async function getIdentityClaim(
|
||||
authToken: string,
|
||||
walletAddress: string,
|
||||
): Promise<string> {
|
||||
const url = `${BACKEND_URL}/api/v1/accounts/identity_proof`
|
||||
const response = await http(url, { authToken })
|
||||
const queryParams = { did: createDidFromEthereumAddress(walletAddress) }
|
||||
const response = await http(url, { authToken, queryParams })
|
||||
const data = await response.json()
|
||||
return data.claim
|
||||
}
|
||||
|
||||
export async function createIdentityProof(
|
||||
authToken: string,
|
||||
walletAddress: string,
|
||||
signature: string,
|
||||
): Promise<User> {
|
||||
const url = `${BACKEND_URL}/api/v1/accounts/identity_proof`
|
||||
const response = await http(url, {
|
||||
method: "POST",
|
||||
json: { signature: signature.replace(/0x/, "") },
|
||||
json: {
|
||||
did: createDidFromEthereumAddress(walletAddress),
|
||||
signature: signature.replace(/0x/, ""),
|
||||
},
|
||||
authToken,
|
||||
})
|
||||
const data = await response.json()
|
||||
|
|
3
src/utils/did.ts
Normal file
3
src/utils/did.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function createDidFromEthereumAddress(address: string): string {
|
||||
return `did:pkh:eip155:1:${address.toLowerCase()}`
|
||||
}
|
|
@ -431,10 +431,15 @@ async function verifyEthereumAddress(): Promise<void> {
|
|||
if (!signer) {
|
||||
return
|
||||
}
|
||||
const walletAddress = await signer.getAddress()
|
||||
const authToken = ensureAuthToken()
|
||||
const message = await getIdentityClaim(authToken)
|
||||
const message = await getIdentityClaim(authToken, walletAddress)
|
||||
const signature = await getWalletSignature(signer, message)
|
||||
const user = await createIdentityProof(authToken, signature)
|
||||
const user = await createIdentityProof(
|
||||
authToken,
|
||||
walletAddress,
|
||||
signature,
|
||||
)
|
||||
setCurrentUser(user)
|
||||
profile.identity_proofs = user.identity_proofs
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue