Skip to content

Commit

Permalink
feat: remove alias
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-ko committed Aug 28, 2023
1 parent b644cef commit 1943a6d
Show file tree
Hide file tree
Showing 31 changed files with 614 additions and 415 deletions.
2 changes: 1 addition & 1 deletion packages/lib/offchainResolver-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dm3-lib-offchain-resolver-api",
"version": "0.2.4",
"version": "0.2.5",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
53 changes: 32 additions & 21 deletions packages/lib/offchainResolver-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
import axios from 'axios';
import { Account, SignedUserProfile, formatAddress } from 'dm3-lib-profile';

function checkAccount(account: Account | undefined): Required<Account> {
if (!account) {
throw Error('No account');
}
if (!account.profile) {
throw Error('Account has no profile.');
}
return account as Required<Account>;
}
import { SignedUserProfile, formatAddress } from 'dm3-lib-profile';
import { ethers } from 'ethers';

/**
* claims a dm3.eth subdomain
* @param account dm3 account
* @param alias the ENS alias
* @param offchainResolverUrl The offchain resolver endpoint url
* @param name The subdomain name
* @param signedUserProfile The signed dm3 user profile
* @param name The orignial ENS name
* @param privateKey The owner private key
*/

export async function claimSubdomain(
account: Account,
alias: string,
offchainResolverUrl: string,
name: string,
signedUserProfile: SignedUserProfile,
privateKey: string,
): Promise<boolean> {
const { ensName } = checkAccount(account);

const wallet = new ethers.Wallet(privateKey);
const url = `${offchainResolverUrl}/profile/name`;
const data = {
signedUserProfile,
alias,
name,
ensName,
signature: await wallet.signMessage('alias: ' + alias),
};

const { status } = await axios.post(url, data);
return status === 200;
}

/**
* removes a dm3.eth subdomain
* @param alias the ENS alias
* @param offchainResolverUrl The offchain resolver endpoint url
* @param privateKey The owner private key
*/
export async function removeAlias(
alias: string,
offchainResolverUrl: string,
privateKey: string,
): Promise<boolean> {
const wallet = new ethers.Wallet(privateKey);
const url = `${offchainResolverUrl}/profile/name`;
const data = {
name: alias,
signature: await wallet.signMessage('remove: ' + alias),
};

const { status } = await axios.post(url, data);
Expand Down
11 changes: 3 additions & 8 deletions packages/messenger-widget/src/components/ConfigureProfile/bl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,13 @@ export const submitDm3UsernameClaim = async (

startLoader();

const signedProfile = await getUserProfile(
state.connection.provider!,
state.connection.account!.ensName,
);

const ensName = dm3UserEnsName! + globalConfig.USER_ENS_SUBDOMAIN();

await claimSubdomain(
state.connection.account!,
dm3UserEnsName! + globalConfig.USER_ENS_SUBDOMAIN(),
process.env.REACT_APP_RESOLVER_BACKEND as string,
ensName,
signedProfile!,
state.connection.account!.ensName,
state.userDb!.keys.signingKeyPair.privateKey,
);

await createAlias(
Expand Down
8 changes: 5 additions & 3 deletions packages/offchain-resolver/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "dm3-offchain-resolver",
"version": "0.2.0",
"version": "0.2.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
"@prisma/client": "^4.15.0",
"body-parser": "^1.20.1",
"dm3-lib-profile": "^0.2.0",
"dm3-lib-shared": "^0.2.1",
"dm3-lib-crypto": "workspace:^",
"dm3-lib-profile": "workspace:^",
"dm3-lib-shared": "workspace:^",
"dotenv": "^16.0.3",
"eslint": "^8.17.0",
"ethers": "5.7.2",
Expand All @@ -18,6 +19,7 @@
"siwe": "^2.1.4",
"ts-node": "^10.8.1",
"typescript": "^4.4.2",
"uuid": "^9.0.0",
"winston": "^3.8.1",
"yaml": "^2.1.3"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@ export async function handleAddr(db: IDatabase, request: any) {
interceptResult,
});

return (
interceptResult ??
(await db.getAddressByName(ethers.utils.namehash(name)))
);
return interceptResult ?? (await db.getProfileContainer(name));
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export async function handleText(db: IDatabase, request: any) {
throw Error(`${record} Record is not supported by this resolver`);
}

const userProfile = await db.getUserProfile(name);
const profileContainer = await db.getProfileContainer(name);

return userProfile
? 'data:application/json,' + stringify(userProfile)
return profileContainer
? 'data:application/json,' + stringify(profileContainer.profile)
: null;
}
Loading

0 comments on commit 1943a6d

Please sign in to comment.