maths.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import type { BytesLike } from "./data.js";
  2. /**
  3. * Any type that can be used where a numeric value is needed.
  4. */
  5. export type Numeric = number | bigint;
  6. /**
  7. * Any type that can be used where a big number is needed.
  8. */
  9. export type BigNumberish = string | Numeric;
  10. /**
  11. * Convert %%value%% from a twos-compliment representation of %%width%%
  12. * bits to its value.
  13. *
  14. * If the highest bit is ``1``, the result will be negative.
  15. */
  16. export declare function fromTwos(_value: BigNumberish, _width: Numeric): bigint;
  17. /**
  18. * Convert %%value%% to a twos-compliment representation of
  19. * %%width%% bits.
  20. *
  21. * The result will always be positive.
  22. */
  23. export declare function toTwos(_value: BigNumberish, _width: Numeric): bigint;
  24. /**
  25. * Mask %%value%% with a bitmask of %%bits%% ones.
  26. */
  27. export declare function mask(_value: BigNumberish, _bits: Numeric): bigint;
  28. /**
  29. * Gets a BigInt from %%value%%. If it is an invalid value for
  30. * a BigInt, then an ArgumentError will be thrown for %%name%%.
  31. */
  32. export declare function getBigInt(value: BigNumberish, name?: string): bigint;
  33. /**
  34. * Returns %%value%% as a bigint, validating it is valid as a bigint
  35. * value and that it is positive.
  36. */
  37. export declare function getUint(value: BigNumberish, name?: string): bigint;
  38. export declare function toBigInt(value: BigNumberish | Uint8Array): bigint;
  39. /**
  40. * Gets a //number// from %%value%%. If it is an invalid value for
  41. * a //number//, then an ArgumentError will be thrown for %%name%%.
  42. */
  43. export declare function getNumber(value: BigNumberish, name?: string): number;
  44. /**
  45. * Converts %%value%% to a number. If %%value%% is a Uint8Array, it
  46. * is treated as Big Endian data. Throws if the value is not safe.
  47. */
  48. export declare function toNumber(value: BigNumberish | Uint8Array): number;
  49. /**
  50. * Converts %%value%% to a Big Endian hexstring, optionally padded to
  51. * %%width%% bytes.
  52. */
  53. export declare function toBeHex(_value: BigNumberish, _width?: Numeric): string;
  54. /**
  55. * Converts %%value%% to a Big Endian Uint8Array.
  56. */
  57. export declare function toBeArray(_value: BigNumberish): Uint8Array;
  58. /**
  59. * Returns a [[HexString]] for %%value%% safe to use as a //Quantity//.
  60. *
  61. * A //Quantity// does not have and leading 0 values unless the value is
  62. * the literal value `0x0`. This is most commonly used for JSSON-RPC
  63. * numeric values.
  64. */
  65. export declare function toQuantity(value: BytesLike | BigNumberish): string;
  66. //# sourceMappingURL=maths.d.ts.map