Skip to content

Commit 1943a6d

Browse files
committed
feat: remove alias
1 parent b644cef commit 1943a6d

31 files changed

+614
-415
lines changed

packages/lib/offchainResolver-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dm3-lib-offchain-resolver-api",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"license": "MIT",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

packages/lib/offchainResolver-api/src/index.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
11
import axios from 'axios';
2-
import { Account, SignedUserProfile, formatAddress } from 'dm3-lib-profile';
3-
4-
function checkAccount(account: Account | undefined): Required<Account> {
5-
if (!account) {
6-
throw Error('No account');
7-
}
8-
if (!account.profile) {
9-
throw Error('Account has no profile.');
10-
}
11-
return account as Required<Account>;
12-
}
2+
import { SignedUserProfile, formatAddress } from 'dm3-lib-profile';
3+
import { ethers } from 'ethers';
134

145
/**
156
* claims a dm3.eth subdomain
16-
* @param account dm3 account
7+
* @param alias the ENS alias
178
* @param offchainResolverUrl The offchain resolver endpoint url
18-
* @param name The subdomain name
19-
* @param signedUserProfile The signed dm3 user profile
9+
* @param name The orignial ENS name
10+
* @param privateKey The owner private key
2011
*/
21-
2212
export async function claimSubdomain(
23-
account: Account,
13+
alias: string,
2414
offchainResolverUrl: string,
2515
name: string,
26-
signedUserProfile: SignedUserProfile,
16+
privateKey: string,
2717
): Promise<boolean> {
28-
const { ensName } = checkAccount(account);
29-
18+
const wallet = new ethers.Wallet(privateKey);
3019
const url = `${offchainResolverUrl}/profile/name`;
3120
const data = {
32-
signedUserProfile,
21+
alias,
3322
name,
34-
ensName,
23+
signature: await wallet.signMessage('alias: ' + alias),
24+
};
25+
26+
const { status } = await axios.post(url, data);
27+
return status === 200;
28+
}
29+
30+
/**
31+
* removes a dm3.eth subdomain
32+
* @param alias the ENS alias
33+
* @param offchainResolverUrl The offchain resolver endpoint url
34+
* @param privateKey The owner private key
35+
*/
36+
export async function removeAlias(
37+
alias: string,
38+
offchainResolverUrl: string,
39+
privateKey: string,
40+
): Promise<boolean> {
41+
const wallet = new ethers.Wallet(privateKey);
42+
const url = `${offchainResolverUrl}/profile/name`;
43+
const data = {
44+
name: alias,
45+
signature: await wallet.signMessage('remove: ' + alias),
3546
};
3647

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

packages/messenger-widget/src/components/ConfigureProfile/bl.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,13 @@ export const submitDm3UsernameClaim = async (
100100

101101
startLoader();
102102

103-
const signedProfile = await getUserProfile(
104-
state.connection.provider!,
105-
state.connection.account!.ensName,
106-
);
107-
108103
const ensName = dm3UserEnsName! + globalConfig.USER_ENS_SUBDOMAIN();
109104

110105
await claimSubdomain(
111-
state.connection.account!,
106+
dm3UserEnsName! + globalConfig.USER_ENS_SUBDOMAIN(),
112107
process.env.REACT_APP_RESOLVER_BACKEND as string,
113-
ensName,
114-
signedProfile!,
108+
state.connection.account!.ensName,
109+
state.userDb!.keys.signingKeyPair.privateKey,
115110
);
116111

117112
await createAlias(

packages/offchain-resolver/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "dm3-offchain-resolver",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"dependencies": {
77
"@prisma/client": "^4.15.0",
88
"body-parser": "^1.20.1",
9-
"dm3-lib-profile": "^0.2.0",
10-
"dm3-lib-shared": "^0.2.1",
9+
"dm3-lib-crypto": "workspace:^",
10+
"dm3-lib-profile": "workspace:^",
11+
"dm3-lib-shared": "workspace:^",
1112
"dotenv": "^16.0.3",
1213
"eslint": "^8.17.0",
1314
"ethers": "5.7.2",
@@ -18,6 +19,7 @@
1819
"siwe": "^2.1.4",
1920
"ts-node": "^10.8.1",
2021
"typescript": "^4.4.2",
22+
"uuid": "^9.0.0",
2123
"winston": "^3.8.1",
2224
"yaml": "^2.1.3"
2325
},

packages/offchain-resolver/src/http/handleCcipRequest/handler/handleAddr.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,5 @@ export async function handleAddr(db: IDatabase, request: any) {
1212
interceptResult,
1313
});
1414

15-
return (
16-
interceptResult ??
17-
(await db.getAddressByName(ethers.utils.namehash(name)))
18-
);
15+
return interceptResult ?? (await db.getProfileContainer(name));
1916
}

packages/offchain-resolver/src/http/handleCcipRequest/handler/resolveText.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export async function handleText(db: IDatabase, request: any) {
1717
throw Error(`${record} Record is not supported by this resolver`);
1818
}
1919

20-
const userProfile = await db.getUserProfile(name);
20+
const profileContainer = await db.getProfileContainer(name);
2121

22-
return userProfile
23-
? 'data:application/json,' + stringify(userProfile)
22+
return profileContainer
23+
? 'data:application/json,' + stringify(profileContainer.profile)
2424
: null;
2525
}

0 commit comments

Comments
 (0)