signature.d.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import type { BigNumberish, BytesLike } from "../utils/index.js";
  2. /**
  3. * A SignatureLike
  4. *
  5. * @_docloc: api/crypto:Signing
  6. */
  7. export type SignatureLike = Signature | string | {
  8. r: string;
  9. s: string;
  10. v: BigNumberish;
  11. yParity?: 0 | 1;
  12. yParityAndS?: string;
  13. } | {
  14. r: string;
  15. yParityAndS: string;
  16. yParity?: 0 | 1;
  17. s?: string;
  18. v?: number;
  19. } | {
  20. r: string;
  21. s: string;
  22. yParity: 0 | 1;
  23. v?: BigNumberish;
  24. yParityAndS?: string;
  25. };
  26. /**
  27. * A Signature @TODO
  28. *
  29. *
  30. * @_docloc: api/crypto:Signing
  31. */
  32. export declare class Signature {
  33. #private;
  34. /**
  35. * The ``r`` value for a signautre.
  36. *
  37. * This represents the ``x`` coordinate of a "reference" or
  38. * challenge point, from which the ``y`` can be computed.
  39. */
  40. get r(): string;
  41. set r(value: BytesLike);
  42. /**
  43. * The ``s`` value for a signature.
  44. */
  45. get s(): string;
  46. set s(_value: BytesLike);
  47. /**
  48. * The ``v`` value for a signature.
  49. *
  50. * Since a given ``x`` value for ``r`` has two possible values for
  51. * its correspondin ``y``, the ``v`` indicates which of the two ``y``
  52. * values to use.
  53. *
  54. * It is normalized to the values ``27`` or ``28`` for legacy
  55. * purposes.
  56. */
  57. get v(): 27 | 28;
  58. set v(value: BigNumberish);
  59. /**
  60. * The EIP-155 ``v`` for legacy transactions. For non-legacy
  61. * transactions, this value is ``null``.
  62. */
  63. get networkV(): null | bigint;
  64. /**
  65. * The chain ID for EIP-155 legacy transactions. For non-legacy
  66. * transactions, this value is ``null``.
  67. */
  68. get legacyChainId(): null | bigint;
  69. /**
  70. * The ``yParity`` for the signature.
  71. *
  72. * See ``v`` for more details on how this value is used.
  73. */
  74. get yParity(): 0 | 1;
  75. /**
  76. * The [[link-eip-2098]] compact representation of the ``yParity``
  77. * and ``s`` compacted into a single ``bytes32``.
  78. */
  79. get yParityAndS(): string;
  80. /**
  81. * The [[link-eip-2098]] compact representation.
  82. */
  83. get compactSerialized(): string;
  84. /**
  85. * The serialized representation.
  86. */
  87. get serialized(): string;
  88. /**
  89. * @private
  90. */
  91. constructor(guard: any, r: string, s: string, v: 27 | 28);
  92. /**
  93. * Returns a new identical [[Signature]].
  94. */
  95. clone(): Signature;
  96. /**
  97. * Returns a representation that is compatible with ``JSON.stringify``.
  98. */
  99. toJSON(): any;
  100. /**
  101. * Compute the chain ID from the ``v`` in a legacy EIP-155 transactions.
  102. *
  103. * @example:
  104. * Signature.getChainId(45)
  105. * //_result:
  106. *
  107. * Signature.getChainId(46)
  108. * //_result:
  109. */
  110. static getChainId(v: BigNumberish): bigint;
  111. /**
  112. * Compute the ``v`` for a chain ID for a legacy EIP-155 transactions.
  113. *
  114. * Legacy transactions which use [[link-eip-155]] hijack the ``v``
  115. * property to include the chain ID.
  116. *
  117. * @example:
  118. * Signature.getChainIdV(5, 27)
  119. * //_result:
  120. *
  121. * Signature.getChainIdV(5, 28)
  122. * //_result:
  123. *
  124. */
  125. static getChainIdV(chainId: BigNumberish, v: 27 | 28): bigint;
  126. /**
  127. * Compute the normalized legacy transaction ``v`` from a ``yParirty``,
  128. * a legacy transaction ``v`` or a legacy [[link-eip-155]] transaction.
  129. *
  130. * @example:
  131. * // The values 0 and 1 imply v is actually yParity
  132. * Signature.getNormalizedV(0)
  133. * //_result:
  134. *
  135. * // Legacy non-EIP-1559 transaction (i.e. 27 or 28)
  136. * Signature.getNormalizedV(27)
  137. * //_result:
  138. *
  139. * // Legacy EIP-155 transaction (i.e. >= 35)
  140. * Signature.getNormalizedV(46)
  141. * //_result:
  142. *
  143. * // Invalid values throw
  144. * Signature.getNormalizedV(5)
  145. * //_error:
  146. */
  147. static getNormalizedV(v: BigNumberish): 27 | 28;
  148. /**
  149. * Creates a new [[Signature]].
  150. *
  151. * If no %%sig%% is provided, a new [[Signature]] is created
  152. * with default values.
  153. *
  154. * If %%sig%% is a string, it is parsed.
  155. */
  156. static from(sig?: SignatureLike): Signature;
  157. }
  158. //# sourceMappingURL=signature.d.ts.map