UNPKG

ic-websocket-js

Version:
15 lines 629 B
import { makeNonce } from '@dfinity/agent'; /** * Create a Nonce transform, which takes a function that returns a Buffer, and adds it * as the nonce to every call requests. * @param nonceFn A function that returns a buffer. By default uses a semi-random method. */ export function makeWsNonceTransform(nonceFn = makeNonce) { return async (request) => { // Nonce only needs to be inserted into the body for async calls, to prevent replay attacks. if (request.endpoint === "call" /* Endpoint.Call */) { request.message.nonce = nonceFn(); } }; } //# sourceMappingURL=transforms.js.map