Skip to content

Commit

Permalink
fix herotags
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Oct 13, 2024
1 parent 4e7032f commit abfbe29
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 52 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### [0.14.4](https://github.com/xdevguild/buildo.dev/releases/tag/v0.14.4) (2024-10-13)
- fix Herotags (DNS) - works only on the mainnet

### [0.14.3](https://github.com/xdevguild/buildo.dev/releases/tag/v0.14.3) (2024-07-06)
- improve transaction status UI
- update dependencies
Expand Down
35 changes: 15 additions & 20 deletions app/(operations)/general-operations/herotag/components/herotag.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import keccak from 'keccak';
import { keccak256 } from 'js-sha3';
import {
SmartContract,
Address,
Expand All @@ -20,26 +20,19 @@ import { OperationInfoBox } from '@/app/(operations)/components/operations-ui/op
import { useTransaction } from '@useelven/core';

const dnsScAddressForHerotag = (herotag: string) => {
const hashedHerotag = keccak('keccak256').update(herotag).digest();

const initialAddress = Buffer.from(Array(32).fill(1));
const initialAddressSlice = Uint8Array.prototype.slice.call(
initialAddress,
0,
30
);
const scId = Uint8Array.prototype.slice.call(hashedHerotag, 31);

const deployer_pubkey = Buffer.concat([
initialAddressSlice,
Buffer.from([0, Buffer.from(scId).readUIntBE(0, 1)]),
]);

const hashedHerotagBuffer = keccak256.arrayBuffer(herotag);
const hashedHerotag = new Uint8Array(hashedHerotagBuffer);
const initialAddress = new Uint8Array(32).fill(1);
const initialAddressSlice = initialAddress.slice(0, 30);
const scIdByte = hashedHerotag[31];
const deployer_pubkey = new Uint8Array(32);
deployer_pubkey.set(initialAddressSlice, 0);
deployer_pubkey[30] = 0;
deployer_pubkey[31] = scIdByte;
const scAddress = SmartContract.computeAddress(
new Address(deployer_pubkey),
0
);

return scAddress;
};

Expand Down Expand Up @@ -72,13 +65,15 @@ export const Herotag = () => {
});

const onSubmit = async ({ herotag }: z.infer<typeof formSchema>) => {
const dnsScAddress = dnsScAddressForHerotag(`${herotag.trim()}`);
// TODO: the suffix will probably change in the future dns sc releases
const fullHerotag = `${herotag.trim()}.elrond`;
const dnsScAddress = dnsScAddressForHerotag(fullHerotag);

const args: TypedValue[] = [BytesValue.fromUTF8(`${herotag.trim()}`)];
const args: TypedValue[] = [BytesValue.fromUTF8(fullHerotag)];

// TODO: use modern tools for contract calls
const data = new ContractCallPayloadBuilder()
.setFunction(new ContractFunction('SetUserName'))
.setFunction(new ContractFunction('register'))
.setArgs(args)
.build();

Expand Down
4 changes: 2 additions & 2 deletions lib/operations-menu-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export const operationsMenuConfig: Record<
path: '/general-operations/account-storage',
},
{
title: 'Set a herotag',
title: 'Set a herotag (DNS) [Mainnet only]',
description:
'Create a herotag and assign it to your address (transaction fees applied)',
'Create a herotag (DNS name for your address) and assign it to your address (transaction fees applied). Works only on the Mainnet.',
path: '/general-operations/herotag',
},
{
Expand Down
35 changes: 8 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "buildo.dev",
"version": "0.14.3",
"version": "0.14.4",
"author": "Julian Ćwirko <julian.io>",
"license": "MIT",
"homepage": "https://www.buildo.dev",
Expand Down Expand Up @@ -39,7 +39,7 @@
"buffer": "6.0.3",
"class-variance-authority": "0.7.0",
"clsx": "2.1.1",
"keccak": "3.0.4",
"js-sha3": "^0.9.3",
"lucide-react": "0.400.0",
"next": "14.2.4",
"next-themes": "0.3.0",
Expand All @@ -53,7 +53,6 @@
"zod": "3.23.8"
},
"devDependencies": {
"@types/keccak": "3.0.4",
"@types/node": "20.14.10",
"@types/qrcode": "1.5.5",
"@types/react": "18.3.3",
Expand Down

0 comments on commit abfbe29

Please sign in to comment.