cosmology-tech / cosmos-kit

Universal wallet connector for the Cosmos ⚛️
https://cosmology.zone/products/cosmos-kit
BSD 3-Clause Clear License
183 stars 130 forks source link

Web3Auth Package Signer BigInt Problems #488

Closed chalabi2 closed 2 months ago

chalabi2 commented 3 months ago

Summary

In the web3auth extension directory the hashObject Signing a transaction errors when a message contains bigIntValues because they cannot be serialized.

Error

Failed to broadcast: TypeError: BigInt value can't be serialized in JSON
    hashObject utils.js:67
    signDirect signer.js:68
    signDirect signingstargateclient.js:282
    sign signingstargateclient.js:230
    tx useTx.tsx:84
    handleConfirm ConfirmationForm.tsx:89

Reproduce

Working solution

Simply check if there are any bigInt values in the hashObject

export const hashObject = (object) => {
    const replacer = (_, value) => {
      if (typeof value === 'bigint') {
        return value.toString();
      }
      return value;
    };

    return Buffer.from(sha256(toUtf8(JSON.stringify(object, replacer))));
  };
chalabi2 commented 3 months ago

489 is a potential fix