powSolve
Finds a 64 bit nonce that matches the specified difficulty. This function generates hashes using the supplied data, optional data identifier and timestamp. When a hash is found that satisfies the specified difficulty, this becomes the nonce that is returned. The powVerify
function can be used to verify a nonce.
info
This function can be used to prevent form spamming.
Signature
powSolve(
data: Instance | Context | {
exportables: Export.IExportables;
actionables: Export.IActionables | undefined;
},
difficulty: number,
id?: string,
length: 8 | 16 | 24 | 32,
timeout?: number,
timestamp: number,
timestampResolution: "seconds" | "milliseconds"
): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
data | Instance | Context | object | No | Specifies the data to find the nonce for. If an Instance or Context is supplied, the data is automatically retrieved. It is also possible to supply the data directly using the exportables and actionables functions from the export module. |
difficulty | number | No | Specifies the difficulty (a good average starting difficulty is 10 ). |
id | string | Yes | Optional identifier for the data. |
length | 8 | 16 | 24 | 32 | Yes | Specifies the nonce length (default is 16 ). |
timeout | number | Yes | Specifies a timeout in milliseconds (disabled by default). |
timestamp | number | Yes | Specifies the timestamp to use as the number of milliseconds since the ECMAScript epoch (default is the current time). |
timestampResolution | "seconds" | "milliseconds" | Yes | Specifies if the timestamp has seconds or milliseconds resolution. |
Return value
Returns the nonce hash string.
caution
This function throws an error if the work is not completed successfully.