data.d.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * A [[HexString]] whose length is even, which ensures it is a valid
  3. * representation of binary data.
  4. */
  5. export type DataHexString = string;
  6. /**
  7. * A string which is prefixed with ``0x`` and followed by any number
  8. * of case-agnostic hexadecimal characters.
  9. *
  10. * It must match the regular expression ``/0x[0-9A-Fa-f]*\/``.
  11. */
  12. export type HexString = string;
  13. /**
  14. * An object that can be used to represent binary data.
  15. */
  16. export type BytesLike = DataHexString | Uint8Array;
  17. /**
  18. * Get a typed Uint8Array for %%value%%. If already a Uint8Array
  19. * the original %%value%% is returned; if a copy is required use
  20. * [[getBytesCopy]].
  21. *
  22. * @see: getBytesCopy
  23. */
  24. export declare function getBytes(value: BytesLike, name?: string): Uint8Array;
  25. /**
  26. * Get a typed Uint8Array for %%value%%, creating a copy if necessary
  27. * to prevent any modifications of the returned value from being
  28. * reflected elsewhere.
  29. *
  30. * @see: getBytes
  31. */
  32. export declare function getBytesCopy(value: BytesLike, name?: string): Uint8Array;
  33. /**
  34. * Returns true if %%value%% is a valid [[HexString]].
  35. *
  36. * If %%length%% is ``true`` or a //number//, it also checks that
  37. * %%value%% is a valid [[DataHexString]] of %%length%% (if a //number//)
  38. * bytes of data (e.g. ``0x1234`` is 2 bytes).
  39. */
  40. export declare function isHexString(value: any, length?: number | boolean): value is `0x${string}`;
  41. /**
  42. * Returns true if %%value%% is a valid representation of arbitrary
  43. * data (i.e. a valid [[DataHexString]] or a Uint8Array).
  44. */
  45. export declare function isBytesLike(value: any): value is BytesLike;
  46. /**
  47. * Returns a [[DataHexString]] representation of %%data%%.
  48. */
  49. export declare function hexlify(data: BytesLike): string;
  50. /**
  51. * Returns a [[DataHexString]] by concatenating all values
  52. * within %%data%%.
  53. */
  54. export declare function concat(datas: ReadonlyArray<BytesLike>): string;
  55. /**
  56. * Returns the length of %%data%%, in bytes.
  57. */
  58. export declare function dataLength(data: BytesLike): number;
  59. /**
  60. * Returns a [[DataHexString]] by slicing %%data%% from the %%start%%
  61. * offset to the %%end%% offset.
  62. *
  63. * By default %%start%% is 0 and %%end%% is the length of %%data%%.
  64. */
  65. export declare function dataSlice(data: BytesLike, start?: number, end?: number): string;
  66. /**
  67. * Return the [[DataHexString]] result by stripping all **leading**
  68. ** zero bytes from %%data%%.
  69. */
  70. export declare function stripZerosLeft(data: BytesLike): string;
  71. /**
  72. * Return the [[DataHexString]] of %%data%% padded on the **left**
  73. * to %%length%% bytes.
  74. *
  75. * If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is
  76. * thrown.
  77. *
  78. * This pads data the same as **values** are in Solidity
  79. * (e.g. ``uint128``).
  80. */
  81. export declare function zeroPadValue(data: BytesLike, length: number): string;
  82. /**
  83. * Return the [[DataHexString]] of %%data%% padded on the **right**
  84. * to %%length%% bytes.
  85. *
  86. * If %%data%% already exceeds %%length%%, a [[BufferOverrunError]] is
  87. * thrown.
  88. *
  89. * This pads data the same as **bytes** are in Solidity
  90. * (e.g. ``bytes16``).
  91. */
  92. export declare function zeroPadBytes(data: BytesLike, length: number): string;
  93. //# sourceMappingURL=data.d.ts.map