GrapeBaBa / sui4j

Sui4j is a robust, reactive, type safe Java library for working with Smart Contracts on the @MystenLabs/sui network.

Home Page:https://grapebaba.github.io/sui4j/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to calculate transaction hash

qinheqing opened this issue · comments

commented

How to calculate transactionDigest in the ‘sui_dryRunTransactionBlock’ API? Can you provide me with some help?

commented
export function hashTypedData(typeTag: string, data: Uint8Array): Uint8Array {
  const typeTagBytes = Array.from(`${typeTag}::`).map((e) => e.charCodeAt(0));

  const dataWithTag = new Uint8Array(typeTagBytes.length + data.length);
  dataWithTag.set(typeTagBytes);
  dataWithTag.set(data, typeTagBytes.length);

  return blake2b(dataWithTag, { dkLen: 32 });
}

  /**
   * Generate transaction digest.
   *
   * @param bytes BCS serialized transaction data
   * @returns transaction digest.
   */
  static getDigestFromBytes(bytes: Uint8Array) {
    const hash = hashTypedData('TransactionData', bytes);
    return toB58(hash);
  }

Found it roughly, I will try to implement it