UNPKG

ic-websocket-js

Version:
18 lines 759 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeWsNonceTransform = makeWsNonceTransform; const agent_1 = require("@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. */ function makeWsNonceTransform(nonceFn = agent_1.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