diff --git a/src/handler/chains/secrets/utils/listenForLockEvents.ts b/src/handler/chains/secrets/utils/listenForLockEvents.ts index e91df43..6baad51 100644 --- a/src/handler/chains/secrets/utils/listenForLockEvents.ts +++ b/src/handler/chains/secrets/utils/listenForLockEvents.ts @@ -4,6 +4,7 @@ import type { EventBuilder } from "../../../event-builder"; import { tryRerunningFailed } from "../../../poller/utils"; import type { LockEventIter, LogInstance } from "../../../types"; import { useMutexAndRelease } from "../../../utils"; +import { convertStringToHexToNumb } from "../../../utils/token-id-conversion"; import type { SecretProviderFetch } from "../types"; const CHAIN_IDENT = "SECRET"; @@ -38,7 +39,7 @@ export default async function listenForLockEvents( ? lastBlock + blockChunks : latestBlockNumber; - const query = `message.contract_address = '${bridge}' AND tx.height >= ${lastBlock} AND tx.height < ${latestBlock}`; + const query = `message.contract_address = '${bridge}' AND tx.height >= ${lastBlock} AND tx.height <= ${latestBlock}`; const logs = await useMutexAndRelease( fetchProvider, async (c) => await c.query.txsQuery(query), @@ -76,10 +77,15 @@ export default async function listenForLockEvents( token_amount: tokenAmount, // amount of nfts to be transfered ( 1 in 721 case ) nft_type: nftType, // Sigular or multiple ( 721 / 1155) source_chain: sourceChain, // Source chain of NFT + metadata_uri: metadataUri, // Source chain of NFT } = parsedLog; + let convertedTokenId = tokenId; + if (sourceChain === "SECRET") { + convertedTokenId = convertStringToHexToNumb(tokenId); + } await cb( await builder.nftLocked( - tokenId, + convertedTokenId, destinationChain, destinationUserAddress, sourceNftContractAddress, @@ -88,7 +94,7 @@ export default async function listenForLockEvents( sourceChain, log.transactionHash, CHAIN_IDENT, - "", + metadataUri, ), ); } diff --git a/src/handler/chains/secrets/utils/signClaimData.ts b/src/handler/chains/secrets/utils/signClaimData.ts index 7dae3ec..a86a06b 100644 --- a/src/handler/chains/secrets/utils/signClaimData.ts +++ b/src/handler/chains/secrets/utils/signClaimData.ts @@ -2,15 +2,20 @@ import { sha256 } from "@noble/hashes/sha256"; import * as secp256k1 from "@noble/secp256k1"; import type { TNftTransferDetailsObject } from "../../../types"; +import { convertNumbToHexToString } from "../../../utils/token-id-conversion"; export default async function signClaimData( data: TNftTransferDetailsObject, privateKey: string, pubk: string, ) { + let convertedTokenId = data.tokenId; + if (data.sourceChain === "SECRET") { + convertedTokenId = convertNumbToHexToString(data.tokenId); + } const messageHash = sha256( [ - data.tokenId, + convertedTokenId, data.sourceChain, data.destinationChain, data.destinationUserAddress, diff --git a/src/handler/utils/token-id-conversion.ts b/src/handler/utils/token-id-conversion.ts new file mode 100644 index 0000000..bd06f0a --- /dev/null +++ b/src/handler/utils/token-id-conversion.ts @@ -0,0 +1,15 @@ +export const convertStringToHexToNumb = (str: string) => { + const hex = Array.from(str) + .map((char) => char.charCodeAt(0).toString(16).padStart(2, "0")) + .join(""); + const numb = BigInt(`0x${hex}`); + return numb.toString(); +}; +export const convertNumbToHexToString = (num: string) => { + const numberToBigInt = BigInt(num); + const hex = numberToBigInt.toString(16) as string; + const string = (hex.match(/.{1,2}/g) || []) + .map((byte) => String.fromCharCode(Number.parseInt(byte, 16))) + .join(""); + return string; +};