UNPKG

@lit-protocol/auth-helpers

Version:

Advanced authentication utilities for managing blockchain resource permissions and capabilities within the Lit Protocol ecosystem. Built on top of SIWE (Sign-In with Ethereum) and SIWE-RECAP for robust authentication flows.

42 lines 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateAuthSig = void 0; const ethers_1 = require("ethers"); /** * Generate an AuthSig object using the signer. * * For more context: * We are only using authSig to generate session sigs. In a newer version, we will stop accepting * authSig all together from the node and will only accept session sigs. The address being * used here will be checksummed. * * @param signer the signer must have a "signMessage" method * @param toSign - the message to sign * @param address - (optional) the address of the signer * @returns */ const generateAuthSig = async ({ signer, toSign, address, algo, }) => { if (!signer?.signMessage) { throw new Error('signer does not have a signMessage method'); } const signature = await signer.signMessage(toSign); // If address is not provided, derive it from the signer if (!address) { address = await signer.getAddress(); } // checksum the address address = ethers_1.ethers.utils.getAddress(address); // If address is still not available, throw an error if (!address) { throw new Error('address is required'); } return { sig: signature, derivedVia: 'web3.eth.personal.sign', signedMessage: toSign, address: address, ...(algo && { algo }), }; }; exports.generateAuthSig = generateAuthSig; //# sourceMappingURL=generate-auth-sig.js.map