js-conflux-sdk
Version:
JavaScript Conflux Software Development Kit
105 lines • 3.59 kB
TypeScript
export = Message;
/** Class provide message sign utilities. */
declare class Message {
/**
* Signs the hash with the privateKey.
*
* @param {string|Buffer} privateKey - Private key used to sign message
* @param {string|Buffer} messageHash - The message hash need to be signed
* @return {string} The signature as hex string.
*
* @example
* > Message.sign(
'0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', // privateKey
'0x592fa743889fc7f92ac2a37bb1f5ba1daf2a5c84741ca0e0061d243a2e6707ba',
)
"0x6e913e2b76459f19ebd269b82b51a70e912e909b2f5c002312efc27bcc280f3c29134d382aad0dbd3f0ccc9f0eb8f1dbe3f90141d81574ebb6504156b0d7b95f01"
*/
static sign(privateKey: string | Buffer, messageHash: string | Buffer): string;
/**
* Recovers the signers publicKey from the signature.
*
* @param {string|Buffer} signature
* @param {string|Buffer} messageHash
* @return {string} The publicKey as hex string.
*
* @example
* > Message.recover(
'0x6e913e2b76459f19ebd269b82b51a70e912e909b2f5c002312efc27bcc280f3c29134d382aad0dbd3f0ccc9f0eb8f1dbe3f90141d81574ebb6504156b0d7b95f01',
'0x592fa743889fc7f92ac2a37bb1f5ba1daf2a5c84741ca0e0061d243a2e6707ba',
)
"0x4646ae5047316b4230d0086c8acec687f00b1cd9d1dc634f6cb358ac0a9a8ffffe77b4dd0a4bfb95851f3b7355c781dd60f8418fc8a65d14907aff47c903a559"
*/
static recover(signature: string | Buffer, messageHash: string | Buffer): string;
/**
* @param {string} message
* @return {Message}
*
* @example
* > msg = new Message('Hello World');
Message {
message: 'Hello World',
}
* > msg.sign('0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');
Message {
message: 'Hello World',
signature: '0x6e913e2b76459f19ebd269b82b51a70e912e909b2f5c002312efc27bcc280f3c29134d382aad0dbd3f0ccc9f0eb8f1dbe3f90141d81574ebb6504156b0d7b95f01'
}
* > msg.signature
"0x6e913e2b76459f19ebd269b82b51a70e912e909b2f5c002312efc27bcc280f3c29134d382aad0dbd3f0ccc9f0eb8f1dbe3f90141d81574ebb6504156b0d7b95f01"
* > msg.hash
"0x592fa743889fc7f92ac2a37bb1f5ba1daf2a5c84741ca0e0061d243a2e6707ba"
* > msg.from
"cfxtest:aasm4c231py7j34fghntcfkdt2nm9xv1tu6jd3r1s7"
* > msg.r
"0x6e913e2b76459f19ebd269b82b51a70e912e909b2f5c002312efc27bcc280f3c"
* > msg.s
"0x29134d382aad0dbd3f0ccc9f0eb8f1dbe3f90141d81574ebb6504156b0d7b95f"
* > msg.v
1
*/
constructor(message: string);
message: string;
/**
* Getter of message hash include signature.
*
* > Note: calculate every time.
*
* @return {string}
*/
get hash(): string;
/**
* Getter of sender address.
*
* > Note: calculate every time.
*
* @return {string|undefined} If ECDSA recover success return address, else return undefined.
*/
get from(): string;
/**
* Sign message and set 'r','s','v' and 'hash'.
*
* @param {string} privateKey - Private key hex string.
* @param {number} networkId - Network id of account
* @return {Message}
*/
sign(privateKey: string, networkId: number): Message;
signature: string;
networkId: number;
/**
* Get signatures r
* @return {string}
*/
get r(): string;
/**
* Get signatures s
* @return {string}
*/
get s(): string;
/**
* Get signatures v
* @return {number}
*/
get v(): number;
}
//# sourceMappingURL=Message.d.ts.map