### Install development dependencies
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Installs NPM modules needed for development.
```bash
$ npm install
```
--------------------------------
### Install with NPM
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Install TweetNaCl.js using the NPM package manager.
```bash
$ npm install tweetnacl
```
--------------------------------
### Install with Yarn
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Install TweetNaCl.js using the Yarn package manager.
```bash
$ yarn add tweetnacl
```
--------------------------------
### Symmetric encryption with secretbox
Source: https://github.com/dchest/tweetnacl-js/wiki/Examples
Uses tweetnacl's secretbox for symmetric encryption with a single shared key. Generates a random key and nonce, encrypts a JSON object, and decrypts it, throwing an error if decryption fails. The example logs the decrypted object and original object, which should be shallow equal.
```javascript
import { secretbox, randomBytes } from "tweetnacl";
import {
decodeUTF8,
encodeUTF8,
encodeBase64,
decodeBase64
} from "tweetnacl-util";
const newNonce = () => randomBytes(secretbox.nonceLength);
export const generateKey = () => encodeBase64(randomBytes(secretbox.keyLength));
export const encrypt = (json, key) => {
const keyUint8Array = decodeBase64(key);
const nonce = newNonce();
const messageUint8 = decodeUTF8(JSON.stringify(json));
const box = secretbox(messageUint8, nonce, keyUint8Array);
const fullMessage = new Uint8Array(nonce.length + box.length);
fullMessage.set(nonce);
fullMessage.set(box, nonce.length);
const base64FullMessage = encodeBase64(fullMessage);
return base64FullMessage;
};
export const decrypt = (messageWithNonce, key) => {
const keyUint8Array = decodeBase64(key);
const messageWithNonceAsUint8Array = decodeBase64(messageWithNonce);
const nonce = messageWithNonceAsUint8Array.slice(0, secretbox.nonceLength);
const message = messageWithNonceAsUint8Array.slice(
secretbox.nonceLength,
messageWithNonce.length
);
const decrypted = secretbox.open(message, nonce, keyUint8Array);
if (!decrypted) {
throw new Error("Could not decrypt message");
}
const base64DecryptedMessage = encodeUTF8(decrypted);
return JSON.parse(base64DecryptedMessage);
};
const key = generateKey();
const obj = { "hello": "world" };
const encrypted = encrypt(obj, key);
const decrypted = decrypt(encrypted, key);
console.log(decrypted, obj); // should be shallow equal
```
--------------------------------
### Webpack config to avoid Node shims for TweetNaCl.js and TweetNaCl-auth
Source: https://github.com/dchest/tweetnacl-js/wiki/Using-with-Webpack
Add loaders and noParse rules to your Webpack config to prevent parsing of TweetNaCl.js and TweetNaCl-auth, and to set up exports and imports correctly. Requires imports-loader and exports-loader packages to be installed.
```javascript
module.exports = {
// ...
module: {
loaders: [
{
test: /[\\\/]tweetnacl[\\\/]/,
loader: 'exports-loader?window.nacl!imports-loader?this=>window,module=>{},require=>false'
},
{
test: /[\\\/]tweetnacl-auth[\\\/]/,
loader: 'exports-loader?window.nacl.auth!imports-loader?this=>window,module=>{},require=>false'
}
],
noParse: [
/[\\\/]tweetnacl[\\\/]/,
/[\\\/]tweetnacl-auth[\\\/]/
]
}
```
--------------------------------
### nacl.box.open.after(box, nonce, sharedKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Same as `nacl.box.open`, but uses a shared key precomputed with `nacl.box.before`.
```APIDOC
## nacl.box.open.after(box, nonce, sharedKey)
### Description
Same as `nacl.box.open`, but uses a shared key precomputed with `nacl.box.before`.
### Method
Function call
### Endpoint
nacl.box.open.after(box, nonce, sharedKey)
### Parameters
#### Parameters
- **box** (Uint8Array) - Required - The encrypted and authenticated message.
- **nonce** (Uint8Array) - Required - The nonce used during encryption.
- **sharedKey** (Uint8Array) - Required - The precomputed shared key.
### Response
#### Success Response
Returns the original message, or `null` if authentication fails.
```
--------------------------------
### Build browser tests
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Prepares tests for browsers. After running, open test/browser/test.html or test/browser/test-fast.html to run them.
```bash
$ npm run build-test-browser
```
--------------------------------
### nacl.box.after(message, nonce, sharedKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Same as `nacl.box`, but uses a shared key precomputed with `nacl.box.before`.
```APIDOC
## nacl.box.after(message, nonce, sharedKey)
### Description
Same as `nacl.box`, but uses a shared key precomputed with `nacl.box.before`.
### Method
Function call
### Endpoint
nacl.box.after(message, nonce, sharedKey)
### Parameters
#### Parameters
- **message** (Uint8Array) - Required - The message to encrypt and authenticate.
- **nonce** (Uint8Array) - Required - A unique nonce for each distinct message for a key pair.
- **sharedKey** (Uint8Array) - Required - The precomputed shared key.
### Response
#### Success Response
Returns an encrypted and authenticated message, which is `nacl.box.overheadLength` longer than the original message.
```
--------------------------------
### Run benchmarks in Node.js
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Run benchmarks in Node.js. The first command runs the default benchmark, and the second runs benchmarks against the fast build by setting the NACL_SRC environment variable.
```bash
$ npm run bench
$ NACL_SRC=nacl-fast.min.js npm run bench
```
--------------------------------
### Run full Node.js test suite
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Runs the full test suite in Node.js, including comparing outputs of the JavaScript port to the original C version.
```bash
$ npm run test-node-all
```
--------------------------------
### nacl.box.before(theirPublicKey, mySecretKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Returns a precomputed shared key which can be used in `nacl.box.after` and `nacl.box.open.after`.
```APIDOC
## nacl.box.before(theirPublicKey, mySecretKey)
### Description
Returns a precomputed shared key which can be used in `nacl.box.after` and `nacl.box.open.after`.
### Method
Function call
### Endpoint
nacl.box.before(theirPublicKey, mySecretKey)
### Parameters
#### Parameters
- **theirPublicKey** (Uint8Array) - Required - The peer's public key.
- **mySecretKey** (Uint8Array) - Required - Our secret key.
### Response
#### Success Response
Returns a precomputed shared key.
```
--------------------------------
### Test fast minified version with NACL_SRC
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Runs tests in Node.js using the fast minified version by setting the NACL_SRC environment variable.
```bash
$ NACL_SRC=nacl-fast.min.js npm run test-node
```
--------------------------------
### Run tests in Node and Electron
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Runs tests in both Node and Electron.
```bash
$ npm test
```
--------------------------------
### nacl.box.open(box, nonce, theirPublicKey, mySecretKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Authenticates and decrypts the given box with peer's public key, our secret key, and the given nonce.
```APIDOC
## nacl.box.open(box, nonce, theirPublicKey, mySecretKey)
### Description
Authenticates and decrypts the given box with peer's public key, our secret key, and the given nonce.
### Method
Function call
### Endpoint
nacl.box.open(box, nonce, theirPublicKey, mySecretKey)
### Parameters
#### Parameters
- **box** (Uint8Array) - Required - The encrypted and authenticated message.
- **nonce** (Uint8Array) - Required - The nonce used during encryption.
- **theirPublicKey** (Uint8Array) - Required - The peer's public key.
- **mySecretKey** (Uint8Array) - Required - Our secret key.
### Response
#### Success Response
Returns the original message, or `null` if authentication fails.
```
--------------------------------
### Build minified versions
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Builds minified versions of the library. Tests use the minified version, so rebuild after changing nacl.js or nacl-fast.js.
```bash
$ npm run build
```
--------------------------------
### Run Node.js tests
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Runs tests in Node.js. By default tests use nacl.min.js; set NACL_SRC to test another version.
```bash
$ npm run test-node
```
--------------------------------
### nacl.sign.keyPair.fromSeed(seed)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Returns a signing key pair generated deterministically from a seed.
```APIDOC
## nacl.sign.keyPair.fromSeed(seed)
### Description
Returns a new signing key pair generated deterministically from a 32-byte seed. The seed must contain enough entropy to be secure. This method is not recommended for general use: instead, use `nacl.sign.keyPair` to generate a new key pair from a random seed.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
#### Parameters
- **seed** (Uint8Array) - Required - 32-byte seed
### Request Example
N/A
### Response
#### Success Response
- **publicKey** (Uint8Array) - 32-byte public key
- **secretKey** (Uint8Array) - 64-byte secret key
#### Response Example
{
"publicKey": "...",
"secretKey": "..."
}
```
--------------------------------
### nacl.secretbox.open(box, nonce, key)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Authenticates and decrypts the given secret box using the key and the nonce.
```APIDOC
## nacl.secretbox.open(box, nonce, key)
### Description
Authenticates and decrypts the given secret box using the key and the nonce.
### Method
Function call
### Endpoint
nacl.secretbox.open(box, nonce, key)
### Parameters
#### Parameters
- **box** (Uint8Array) - Required - The encrypted and authenticated message.
- **nonce** (Uint8Array) - Required - The nonce used during encryption.
- **key** (Uint8Array) - Required - The secret key.
### Response
#### Success Response
Returns the original message, or `null` if authentication fails.
```
--------------------------------
### nacl.sign.keyPair() return object
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Shows the structure of the object returned by nacl.sign.keyPair(), containing publicKey and secretKey as Uint8Array values.
```javascript
{
publicKey: ..., // Uint8Array with 32-byte public key
secretKey: ... // Uint8Array with 64-byte secret key
}
```
--------------------------------
### Check for failure after nacl.secretbox.open or nacl.box.open
Source: https://github.com/dchest/tweetnacl-js/blob/master/CHANGELOG.md
In v1.0.0-rc.1, nacl.secretbox.open, nacl.box.open, and nacl.box.after return null on failure instead of false. The first snippet is the correct check that continues to work; the second is a direct comparison with false that will no longer detect failure.
```javascript
if (!result) { ... }
```
```javascript
if (result == false) { ... }
```
--------------------------------
### nacl.sign.open(signedMessage, publicKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Verifies a signed message and returns the original message.
```APIDOC
## nacl.sign.open(signedMessage, publicKey)
### Description
Verifies the signed message and returns the message without signature. Returns `null` if verification failed.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
#### Parameters
- **signedMessage** (Uint8Array) - Required - Signed message
- **publicKey** (Uint8Array) - Required - 32-byte public key
### Request Example
N/A
### Response
#### Success Response
- **message** (Uint8Array) - Message without signature
#### Error Response
- **null** - If verification failed
#### Response Example
{
"message": "..."
}
```
--------------------------------
### nacl.sign.keyPair()
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Generates a new random signing key pair.
```APIDOC
## nacl.sign.keyPair()
### Description
Generates a new random key pair for signing and returns it as an object with `publicKey` and `secretKey` members.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
None
### Request Example
N/A
### Response
#### Success Response
- **publicKey** (Uint8Array) - 32-byte public key
- **secretKey** (Uint8Array) - 64-byte secret key
#### Response Example
{
"publicKey": "...",
"secretKey": "..."
}
```
--------------------------------
### nacl.verify(x, y)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Constant-time comparison of two arrays.
```APIDOC
## nacl.verify(x, y)
### Description
Compares `x` and `y` in constant time and returns `true` if their lengths are non-zero and equal, and their contents are equal. Returns `false` if either of the arguments has zero length, or arguments have different lengths, or their contents differ.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
#### Parameters
- **x** (Uint8Array) - Required - First array to compare
- **y** (Uint8Array) - Required - Second array to compare
### Request Example
N/A
### Response
#### Success Response
- **boolean** - `true` if equal, `false` otherwise
#### Response Example
{
"result": true
}
```
--------------------------------
### nacl.box.keyPair()
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Generates a new random key pair for box and returns it as an object with `publicKey` and `secretKey` members.
```APIDOC
## nacl.box.keyPair()
### Description
Generates a new random key pair for box and returns it as an object with `publicKey` and `secretKey` members.
### Method
Function call
### Endpoint
nacl.box.keyPair()
### Parameters
None
### Response
#### Success Response
- **publicKey** (Uint8Array) - 32-byte public key
- **secretKey** (Uint8Array) - 32-byte secret key
#### Response Example
{
"publicKey": "...",
"secretKey": "..."
}
```
--------------------------------
### nacl.box(message, nonce, theirPublicKey, mySecretKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Encrypts and authenticates message using peer's public key, our secret key, and the given nonce, which must be unique for each distinct message for a key pair.
```APIDOC
## nacl.box(message, nonce, theirPublicKey, mySecretKey)
### Description
Encrypts and authenticates message using peer's public key, our secret key, and the given nonce, which must be unique for each distinct message for a key pair.
### Method
Function call
### Endpoint
nacl.box(message, nonce, theirPublicKey, mySecretKey)
### Parameters
#### Parameters
- **message** (Uint8Array) - Required - The message to encrypt and authenticate.
- **nonce** (Uint8Array) - Required - A unique nonce for each distinct message for a key pair.
- **theirPublicKey** (Uint8Array) - Required - The peer's public key.
- **mySecretKey** (Uint8Array) - Required - Our secret key.
### Response
#### Success Response
Returns an encrypted and authenticated message, which is `nacl.box.overheadLength` longer than the original message.
```
--------------------------------
### nacl.sign.keyPair.fromSecretKey(secretKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Returns a signing key pair from a given secret key.
```APIDOC
## nacl.sign.keyPair.fromSecretKey(secretKey)
### Description
Returns a signing key pair with public key corresponding to the given 64-byte secret key. The secret key must have been generated by `nacl.sign.keyPair` or `nacl.sign.keyPair.fromSeed`.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
#### Parameters
- **secretKey** (Uint8Array) - Required - 64-byte secret key
### Request Example
N/A
### Response
#### Success Response
- **publicKey** (Uint8Array) - 32-byte public key
- **secretKey** (Uint8Array) - 64-byte secret key
#### Response Example
{
"publicKey": "...",
"secretKey": "..."
}
```
--------------------------------
### nacl.box.keyPair() return object
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Return value of nacl.box.keyPair(): an object with publicKey and secretKey members, each a 32-byte Uint8Array.
```javascript
{
publicKey: ..., // Uint8Array with 32-byte public key
secretKey: ... // Uint8Array with 32-byte secret key
}
```
--------------------------------
### Asymmetric encryption with box
Source: https://github.com/dchest/tweetnacl-js/wiki/Examples
Uses tweetnacl's box for asymmetric public key encryption. Generates two key pairs (pairA, pairB), computes shared keys with box.before, encrypts with pairA's secret key and pairB's public key, and decrypts with pairB's secret key and pairA's public key. Supports optional precomputed shared keys via box.after and box.open.after.
```tsx
import { box, randomBytes } from 'tweetnacl';
import {
decode as decodeUTF8,
encode as encodeUTF8,
} from "@stablelib/utf8";
import {
decode as decodeBase64,
encode as encodeBase64,
} from "@stablelib/base64";
const newNonce = () => randomBytes(box.nonceLength);
export const generateKeyPair = () => box.keyPair();
export const encrypt = (
secretOrSharedKey: Uint8Array,
json: any,
key?: Uint8Array
) => {
const nonce = newNonce();
const messageUint8 = encodeUTF8(JSON.stringify(json));
const encrypted = key
? box(messageUint8, nonce, key, secretOrSharedKey)
: box.after(messageUint8, nonce, secretOrSharedKey);
const fullMessage = new Uint8Array(nonce.length + encrypted.length);
fullMessage.set(nonce);
fullMessage.set(encrypted, nonce.length);
const base64FullMessage = encodeBase64(fullMessage);
return base64FullMessage;
};
export const decrypt = (
secretOrSharedKey: Uint8Array,
messageWithNonce: string,
key?: Uint8Array
) => {
const messageWithNonceAsUint8Array = decodeBase64(messageWithNonce);
const nonce = messageWithNonceAsUint8Array.slice(0, box.nonceLength);
const message = messageWithNonceAsUint8Array.slice(
box.nonceLength,
messageWithNonce.length
);
const decrypted = key
? box.open(message, nonce, key, secretOrSharedKey)
: box.open.after(message, nonce, secretOrSharedKey);
if (!decrypted) {
throw new Error('Could not decrypt message');
}
const base64DecryptedMessage = decodeUTF8(decrypted);
return JSON.parse(base64DecryptedMessage);
};
const obj = { hello: 'world' };
const pairA = generateKeyPair();
const pairB = generateKeyPair();
const sharedA = box.before(pairB.publicKey, pairA.secretKey);
const sharedB = box.before(pairA.publicKey, pairB.secretKey);
const encrypted = encrypt(sharedA, obj);
const decrypted = decrypt(sharedB, encrypted);
console.log(obj, encrypted, decrypted);
```
--------------------------------
### nacl.box.keyPair.fromSecretKey(secretKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Returns a key pair for box with public key corresponding to the given secret key.
```APIDOC
## nacl.box.keyPair.fromSecretKey(secretKey)
### Description
Returns a key pair for box with public key corresponding to the given secret key.
### Method
Function call
### Endpoint
nacl.box.keyPair.fromSecretKey(secretKey)
### Parameters
#### Parameters
- **secretKey** (Uint8Array) - Required - The secret key to derive the public key from.
### Response
#### Success Response
- **publicKey** (Uint8Array) - 32-byte public key
- **secretKey** (Uint8Array) - 32-byte secret key
```
--------------------------------
### nacl.secretbox(message, nonce, key)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Encrypts and authenticates message using the key and the nonce. The nonce must be unique for each distinct message for this key.
```APIDOC
## nacl.secretbox(message, nonce, key)
### Description
Encrypts and authenticates message using the key and the nonce. The nonce must be unique for each distinct message for this key.
### Method
Function call
### Endpoint
nacl.secretbox(message, nonce, key)
### Parameters
#### Parameters
- **message** (Uint8Array) - Required - The message to encrypt and authenticate.
- **nonce** (Uint8Array) - Required - A unique nonce for each distinct message for this key.
- **key** (Uint8Array) - Required - The secret key.
### Response
#### Success Response
Returns an encrypted and authenticated message, which is `nacl.secretbox.overheadLength` longer than the original message.
```
--------------------------------
### nacl.sign(message, secretKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Signs a message using the secret key and returns the signed message.
```APIDOC
## nacl.sign(message, secretKey)
### Description
Signs the message using the secret key and returns a signed message.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
#### Parameters
- **message** (Uint8Array) - Required - Message to sign
- **secretKey** (Uint8Array) - Required - 64-byte secret key
### Request Example
N/A
### Response
#### Success Response
- **signedMessage** (Uint8Array) - Signed message
#### Response Example
{
"signedMessage": "..."
}
```
--------------------------------
### Include tweetnacl-util-js after nacl.util removal
Source: https://github.com/dchest/tweetnacl-js/blob/master/CHANGELOG.md
In v0.14.0, nacl.util functions were removed. These two blocks show how to include the separate tweetnacl-util-js package: via script tags in HTML or via require in Node.js.
```html
```
```javascript
var nacl = require('tweetnacl');
nacl.util = require('tweetnacl-util');
```
--------------------------------
### nacl.randomBytes(length)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Generates cryptographically secure random bytes.
```APIDOC
## nacl.randomBytes(length)
### Description
Returns a `Uint8Array` of the given length containing random bytes of cryptographic quality.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
#### Parameters
- **length** (number) - Required - Number of random bytes to generate
### Request Example
N/A
### Response
#### Success Response
- **Uint8Array** - Random bytes
#### Response Example
{
"randomBytes": "..."
}
```
--------------------------------
### nacl.hash(message)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Computes the SHA-512 hash of a message.
```APIDOC
## nacl.hash(message)
### Description
Returns SHA-512 hash of the message.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
#### Parameters
- **message** (Uint8Array) - Required - Message to hash
### Request Example
N/A
### Response
#### Success Response
- **hash** (Uint8Array) - 64-byte SHA-512 hash
#### Response Example
{
"hash": "..."
}
```
--------------------------------
### Requiring TweetNaCl.js and TweetNaCl-auth after Webpack config
Source: https://github.com/dchest/tweetnacl-js/wiki/Using-with-Webpack
Use the packages normally with require after the Webpack configuration. The comment notes that 'tweetnacl/nacl-fast' can be used for the fast version.
```javascript
var nacl = require('tweetnacl') // or 'tweetnacl/nacl-fast' for fast version
var naclAuth = require('tweetnacl-auth')
```
--------------------------------
### nacl.scalarMult.base(n)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Multiplies an integer `n` by a standard group element and returns the resulting group element.
```APIDOC
## nacl.scalarMult.base(n)
### Description
Multiplies an integer `n` by a standard group element and returns the resulting group element.
### Method
Function call
### Endpoint
nacl.scalarMult.base(n)
### Parameters
#### Parameters
- **n** (Uint8Array) - Required - The integer scalar.
### Response
#### Success Response
Returns the resulting group element.
```
--------------------------------
### nacl.sign.detached.verify(message, signature, publicKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Verifies a detached signature for a message.
```APIDOC
## nacl.sign.detached.verify(message, signature, publicKey)
### Description
Verifies the signature for the message and returns `true` if verification succeeded or `false` if it failed.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
#### Parameters
- **message** (Uint8Array) - Required - Message to verify
- **signature** (Uint8Array) - Required - Signature
- **publicKey** (Uint8Array) - Required - 32-byte public key
### Request Example
N/A
### Response
#### Success Response
- **boolean** - `true` if verification succeeded, `false` otherwise
#### Response Example
{
"result": true
}
```
--------------------------------
### nacl.scalarMult(n, p)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Multiplies an integer `n` by a group element `p` and returns the resulting group element.
```APIDOC
## nacl.scalarMult(n, p)
### Description
Multiplies an integer `n` by a group element `p` and returns the resulting group element.
### Method
Function call
### Endpoint
nacl.scalarMult(n, p)
### Parameters
#### Parameters
- **n** (Uint8Array) - Required - The integer scalar.
- **p** (Uint8Array) - Required - The group element.
### Response
#### Success Response
Returns the resulting group element.
```
--------------------------------
### Custom PRNG with nacl.setPRNG
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Replaces the internal random byte generator with a custom implementation. The provided function must copy n random bytes into the array x. This completely replaces the default PRNG.
```javascript
nacl.setPRNG(function(x, n) {
// ... copy n random bytes into x ...
});
```
--------------------------------
### nacl.setPRNG(func)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Sets a custom random number generator.
```APIDOC
## nacl.setPRNG(func)
### Description
Replaces the internal random byte generator with the provided function. The function should copy `n` random bytes into `x`.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
#### Parameters
- **func** (function) - Required - Function that fills `x` with `n` random bytes
### Request Example
N/A
### Response
N/A
```
--------------------------------
### nacl.sign.detached(message, secretKey)
Source: https://github.com/dchest/tweetnacl-js/blob/master/README.md
Signs a message and returns a detached signature.
```APIDOC
## nacl.sign.detached(message, secretKey)
### Description
Signs the message using the secret key and returns a signature.
### Method
N/A (JavaScript function)
### Endpoint
N/A
### Parameters
#### Parameters
- **message** (Uint8Array) - Required - Message to sign
- **secretKey** (Uint8Array) - Required - 64-byte secret key
### Request Example
N/A
### Response
#### Success Response
- **signature** (Uint8Array) - Signature
#### Response Example
{
"signature": "..."
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.