ethers.js/lib.esm/crypto/signature.d.ts

158 lines
4.1 KiB
TypeScript
Raw Normal View History

2022-11-30 23:44:23 +03:00
import type { BigNumberish, BytesLike } from "../utils/index.js";
2023-02-13 06:14:26 +03:00
/**
* A SignatureLike
*
* @_docloc: api/crypto:Signing
*/
2023-02-02 12:05:47 +03:00
export type SignatureLike = Signature | string | {
2022-09-05 23:57:11 +03:00
r: string;
s: string;
v: BigNumberish;
yParity?: 0 | 1;
yParityAndS?: string;
} | {
r: string;
yParityAndS: string;
yParity?: 0 | 1;
s?: string;
v?: number;
} | {
r: string;
s: string;
yParity: 0 | 1;
v?: BigNumberish;
yParityAndS?: string;
};
2022-11-30 23:44:23 +03:00
/**
* A Signature @TODO
2023-02-13 06:14:26 +03:00
*
*
* @_docloc: api/crypto:Signing
2022-11-30 23:44:23 +03:00
*/
export declare class Signature {
2022-09-05 23:57:11 +03:00
#private;
2022-11-30 23:44:23 +03:00
/**
* The ``r`` value for a signautre.
*
* This represents the ``x`` coordinate of a "reference" or
* challenge point, from which the ``y`` can be computed.
*/
2022-09-05 23:57:11 +03:00
get r(): string;
set r(value: BytesLike);
2022-11-30 23:44:23 +03:00
/**
* The ``s`` value for a signature.
*/
2022-09-05 23:57:11 +03:00
get s(): string;
2022-11-30 23:44:23 +03:00
set s(_value: BytesLike);
/**
* The ``v`` value for a signature.
*
* Since a given ``x`` value for ``r`` has two possible values for
* its correspondin ``y``, the ``v`` indicates which of the two ``y``
* values to use.
*
* It is normalized to the values ``27`` or ``28`` for legacy
* purposes.
*/
2022-09-05 23:57:11 +03:00
get v(): 27 | 28;
set v(value: BigNumberish);
2022-11-30 23:44:23 +03:00
/**
* The EIP-155 ``v`` for legacy transactions. For non-legacy
* transactions, this value is ``null``.
*/
2022-09-05 23:57:11 +03:00
get networkV(): null | bigint;
2022-11-30 23:44:23 +03:00
/**
* The chain ID for EIP-155 legacy transactions. For non-legacy
* transactions, this value is ``null``.
*/
2022-09-05 23:57:11 +03:00
get legacyChainId(): null | bigint;
2022-11-30 23:44:23 +03:00
/**
* The ``yParity`` for the signature.
*
* See ``v`` for more details on how this value is used.
*/
2022-09-05 23:57:11 +03:00
get yParity(): 0 | 1;
2022-11-30 23:44:23 +03:00
/**
* The [[link-eip-2098]] compact representation of the ``yParity``
* and ``s`` compacted into a single ``bytes32``.
*/
2022-09-05 23:57:11 +03:00
get yParityAndS(): string;
2022-11-30 23:44:23 +03:00
/**
* The [[link-eip-2098]] compact representation.
*/
2022-09-05 23:57:11 +03:00
get compactSerialized(): string;
2022-11-30 23:44:23 +03:00
/**
* The serialized representation.
*/
2022-09-05 23:57:11 +03:00
get serialized(): string;
2022-11-30 23:44:23 +03:00
/**
* @private
*/
2022-09-05 23:57:11 +03:00
constructor(guard: any, r: string, s: string, v: 27 | 28);
2022-11-30 23:44:23 +03:00
/**
* Returns a new identical [[Signature]].
*/
2022-09-05 23:57:11 +03:00
clone(): Signature;
2022-11-30 23:44:23 +03:00
/**
* Returns a representation that is compatible with ``JSON.stringify``.
*/
2022-09-05 23:57:11 +03:00
toJSON(): any;
2022-11-30 23:44:23 +03:00
/**
2022-12-10 02:24:58 +03:00
* Compute the chain ID from the ``v`` in a legacy EIP-155 transactions.
*
* @example:
* Signature.getChainId(45)
* //_result:
*
* Signature.getChainId(46)
* //_result:
2022-11-30 23:44:23 +03:00
*/
2022-09-05 23:57:11 +03:00
static getChainId(v: BigNumberish): bigint;
2022-11-30 23:44:23 +03:00
/**
2022-12-10 02:24:58 +03:00
* Compute the ``v`` for a chain ID for a legacy EIP-155 transactions.
*
* Legacy transactions which use [[link-eip-155]] hijack the ``v``
* property to include the chain ID.
*
* @example:
* Signature.getChainIdV(5, 27)
* //_result:
*
* Signature.getChainIdV(5, 28)
* //_result:
*
2022-11-30 23:44:23 +03:00
*/
2022-09-05 23:57:11 +03:00
static getChainIdV(chainId: BigNumberish, v: 27 | 28): bigint;
2022-11-30 23:44:23 +03:00
/**
2022-12-10 02:24:58 +03:00
* Compute the normalized legacy transaction ``v`` from a ``yParirty``,
* a legacy transaction ``v`` or a legacy [[link-eip-155]] transaction.
*
* @example:
* // The values 0 and 1 imply v is actually yParity
* Signature.getNormalizedV(0)
* //_result:
*
* // Legacy non-EIP-1559 transaction (i.e. 27 or 28)
* Signature.getNormalizedV(27)
* //_result:
*
* // Legacy EIP-155 transaction (i.e. >= 35)
* Signature.getNormalizedV(46)
* //_result:
*
* // Invalid values throw
* Signature.getNormalizedV(5)
* //_error:
2022-11-30 23:44:23 +03:00
*/
2022-09-05 23:57:11 +03:00
static getNormalizedV(v: BigNumberish): 27 | 28;
2022-11-30 23:44:23 +03:00
/**
* Creates a new [[Signature]].
*
* If no %%sig%% is provided, a new [[Signature]] is created
* with default values.
*
* If %%sig%% is a string, it is parsed.
*/
2022-10-20 12:03:32 +03:00
static from(sig?: SignatureLike): Signature;
2022-09-05 23:57:11 +03:00
}
//# sourceMappingURL=signature.d.ts.map