signMessage
Calculates an Ethereum-specific signature in CIP-23 format: keccak256("\x19Conflux Signed Message:\n" + len(message) + message)).
- use
verifyMessageto verify the signature, - use
recoverMessageAddressto recover the signing address from a signature.
Usage
import { , } from "./config";
const = await .({
,
: "hello world",
});
Output: "0x7faf17ad6b7e74e4ec5fc47a9845d9cfe260c14b293308f6942ea202588073df4801eb7a2877ccb895bf42d57644c3818eded847bc03edd63fb36574df90699801"const = await .({
,
// Hex data representation of message.
: { : "0x68656c6c6f20776f726c64" },
});
Output: "0x7faf17ad6b7e74e4ec5fc47a9845d9cfe260c14b293308f6942ea202588073df4801eb7a2877ccb895bf42d57644c3818eded847bc03edd63fb36574df90699801"import { , } from 'cive'
import { } from 'cive/chains'
export const = ({
: ,
: (.!),
})
export const [] = await .();
↑ JSON-RPC Account // export const account = privateKeyToAccount(...)
↑ Local AccountAccount Hoisting
If you do not wish to pass an account to every signMessage, you can also hoist the Account on the Wallet Client (see config.ts).
import { walletClient } from "./config";
const signature = await walletClient.signMessage({
message: "hello world",
});
"0x7faf17ad6b7e74e4ec5fc47a9845d9cfe260c14b293308f6942ea202588073df4801eb7a2877ccb895bf42d57644c3818eded847bc03edd63fb36574df90699801"import { createWalletClient, custom } from "cive";
import "cive/window";
// Retrieve Account from an EIP-1193 Provider.
const [account] = await window.fluent!.request({
method: "cfx_requestAccounts",
});
export const walletClient = createWalletClient({
account,
transport: custom(window.fluent!),
});import { createWalletClient, http } from "cive";
import { privateKeyToAccount } from "cive/accounts";
export const walletClient = createWalletClient({
account: privateKeyToAccount("0x...", { networkId: mainnet.id }),
transport: http(),
});Returns
The signed message.
account
- Type:
Account | Address
Account to use for signing.
Accepts a JSON-RPC Account or Local Account (Private Key, etc).
const = await .({
: "cfx:...",
: "hello world",
});import { } from "cive/accounts";
const = await .({
: ("0x...", { : . }),
: "hello world",
});message
- Type:
string | { raw: Hex | ByteArray }
Message to sign.
By default, cive signs the UTF-8 representation of the message.
const = await .({
: "cfx:...",
: "hello world",
});JSON-RPC Methods
- JSON-RPC Accounts:
- Local Accounts
- Signs locally. No JSON-RPC request.