import { logger } from "document-drive";
import { buildSignedAction } from "document-model/core";
export async function signOperation(operation, sign, documentId, document, reducer, user) {
    if (!user)
        return operation;
    if (!operation.action.context?.signer)
        return operation;
    if (!reducer) {
        logger.error(`Document model '${document.header.documentType}' does not have a reducer`);
        return operation;
    }
    const context = operation.action.context.signer;
    const signedOperation = await buildSignedAction(operation.action, reducer, document, context, sign);
    return signedOperation;
}
export function addActionContext(action, connectDid, user) {
    if (!user)
        return action;
    const signer = {
        app: {
            name: "Connect",
            key: connectDid || "",
        },
        user: {
            address: user.address,
            networkId: user.networkId,
            chainId: user.chainId,
        },
        signatures: [],
    };
    return {
        context: { signer },
        ...action,
    };
}
//# sourceMappingURL=signature.js.map