ethersUtils.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {
  2. keccak256,
  3. sha256,
  4. toUtf8Bytes,
  5. toUtf8String,
  6. recoverAddress,
  7. SigningKey,
  8. AbiCoder,
  9. Signature,
  10. concat,
  11. id,
  12. Mnemonic,
  13. Wordlist,
  14. wordlists,
  15. HDNodeWallet as ethersHDNodeWallet,
  16. getBytes,
  17. computeHmac,
  18. } from 'ethers';
  19. import type { BytesLike, SignatureLike } from 'ethers';
  20. import { Interface } from './interface.js';
  21. const splitSignature = (sigBytes: SignatureLike) => Signature.from(sigBytes);
  22. const joinSignature = (splitSig: SignatureLike) => Signature.from(splitSig).serialized;
  23. const arrayify = (value: BytesLike) => getBytes(value);
  24. const FormatTypes = {
  25. sighash: 'sighash',
  26. minimal: 'minimal',
  27. full: 'full',
  28. json: 'json',
  29. };
  30. const isValidMnemonic = Mnemonic.isValidMnemonic;
  31. computeHmac.register((algorithm, key, data) => {
  32. return computeHmac._(algorithm, Buffer.from(key), Buffer.from(data));
  33. });
  34. export {
  35. keccak256,
  36. sha256,
  37. toUtf8Bytes,
  38. toUtf8String,
  39. recoverAddress,
  40. Signature,
  41. SigningKey,
  42. AbiCoder,
  43. Interface,
  44. FormatTypes,
  45. splitSignature,
  46. joinSignature,
  47. arrayify,
  48. ethersHDNodeWallet,
  49. concat,
  50. id,
  51. Mnemonic,
  52. Wordlist,
  53. wordlists,
  54. isValidMnemonic,
  55. };