From 93fafa250dfc78c44bdd59f327511b070469bab8 Mon Sep 17 00:00:00 2001 From: silverpill Date: Mon, 15 Aug 2022 20:30:55 +0000 Subject: [PATCH] Use current wallet address for generating identity proofs --- src/api/search.ts | 3 ++- src/api/users.ts | 15 ++++++++++++--- src/utils/did.ts | 3 +++ src/views/Profile.vue | 9 +++++++-- 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src/utils/did.ts diff --git a/src/api/search.ts b/src/api/search.ts index ac3f65f..30f98c9 100644 --- a/src/api/search.ts +++ b/src/api/search.ts @@ -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) { diff --git a/src/api/users.ts b/src/api/users.ts index b0f3a98..3368a41 100644 --- a/src/api/users.ts +++ b/src/api/users.ts @@ -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 { +export async function getIdentityClaim( + authToken: string, + walletAddress: string, +): Promise { 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 { 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() diff --git a/src/utils/did.ts b/src/utils/did.ts new file mode 100644 index 0000000..45bacb3 --- /dev/null +++ b/src/utils/did.ts @@ -0,0 +1,3 @@ +export function createDidFromEthereumAddress(address: string): string { + return `did:pkh:eip155:1:${address.toLowerCase()}` +} diff --git a/src/views/Profile.vue b/src/views/Profile.vue index 1683ce0..bf0927a 100644 --- a/src/views/Profile.vue +++ b/src/views/Profile.vue @@ -431,10 +431,15 @@ async function verifyEthereumAddress(): Promise { 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 }