11'use client' ;
22
3- import keccak from 'keccak ' ;
3+ import { keccak256 } from 'js-sha3 ' ;
44import {
55 SmartContract ,
66 Address ,
@@ -20,26 +20,19 @@ import { OperationInfoBox } from '@/app/(operations)/components/operations-ui/op
2020import { useTransaction } from '@useelven/core' ;
2121
2222const dnsScAddressForHerotag = ( herotag : string ) => {
23- const hashedHerotag = keccak ( 'keccak256' ) . update ( herotag ) . digest ( ) ;
24-
25- const initialAddress = Buffer . from ( Array ( 32 ) . fill ( 1 ) ) ;
26- const initialAddressSlice = Uint8Array . prototype . slice . call (
27- initialAddress ,
28- 0 ,
29- 30
30- ) ;
31- const scId = Uint8Array . prototype . slice . call ( hashedHerotag , 31 ) ;
32-
33- const deployer_pubkey = Buffer . concat ( [
34- initialAddressSlice ,
35- Buffer . from ( [ 0 , Buffer . from ( scId ) . readUIntBE ( 0 , 1 ) ] ) ,
36- ] ) ;
37-
23+ const hashedHerotagBuffer = keccak256 . arrayBuffer ( herotag ) ;
24+ const hashedHerotag = new Uint8Array ( hashedHerotagBuffer ) ;
25+ const initialAddress = new Uint8Array ( 32 ) . fill ( 1 ) ;
26+ const initialAddressSlice = initialAddress . slice ( 0 , 30 ) ;
27+ const scIdByte = hashedHerotag [ 31 ] ;
28+ const deployer_pubkey = new Uint8Array ( 32 ) ;
29+ deployer_pubkey . set ( initialAddressSlice , 0 ) ;
30+ deployer_pubkey [ 30 ] = 0 ;
31+ deployer_pubkey [ 31 ] = scIdByte ;
3832 const scAddress = SmartContract . computeAddress (
3933 new Address ( deployer_pubkey ) ,
4034 0
4135 ) ;
42-
4336 return scAddress ;
4437} ;
4538
@@ -72,13 +65,15 @@ export const Herotag = () => {
7265 } ) ;
7366
7467 const onSubmit = async ( { herotag } : z . infer < typeof formSchema > ) => {
75- const dnsScAddress = dnsScAddressForHerotag ( `${ herotag . trim ( ) } ` ) ;
68+ // TODO: the suffix will probably change in the future dns sc releases
69+ const fullHerotag = `${ herotag . trim ( ) } .elrond` ;
70+ const dnsScAddress = dnsScAddressForHerotag ( fullHerotag ) ;
7671
77- const args : TypedValue [ ] = [ BytesValue . fromUTF8 ( ` ${ herotag . trim ( ) } ` ) ] ;
72+ const args : TypedValue [ ] = [ BytesValue . fromUTF8 ( fullHerotag ) ] ;
7873
7974 // TODO: use modern tools for contract calls
8075 const data = new ContractCallPayloadBuilder ( )
81- . setFunction ( new ContractFunction ( 'SetUserName ' ) )
76+ . setFunction ( new ContractFunction ( 'register ' ) )
8277 . setArgs ( args )
8378 . build ( ) ;
8479
0 commit comments