import { Jws } from '../utils/jws.js';
import { Message } from './message.js';
/**
 * An abstract implementation of the `MessageInterface` interface.
 */
export class AbstractMessage {
    _message;
    get message() {
        return this._message;
    }
    _signer;
    get signer() {
        return this._signer;
    }
    _author;
    get author() {
        return this._author;
    }
    _signaturePayload;
    get signaturePayload() {
        return this._signaturePayload;
    }
    /**
     * If this message is signed by an author-delegate.
     */
    get isSignedByAuthorDelegate() {
        return Message.isSignedByAuthorDelegate(this._message);
    }
    constructor(message) {
        this._message = message;
        if (message.authorization !== undefined) {
            this._signer = Message.getSigner(message);
            // if the message authorization contains author delegated grant, the author would be the grantor of the grant
            // else the author would be the signer of the message
            if (message.authorization.authorDelegatedGrant === undefined) {
                this._author = this._signer;
            }
            else {
                this._author = Message.getSigner(message.authorization.authorDelegatedGrant);
            }
            this._signaturePayload = Jws.decodePlainObjectPayload(message.authorization.signature);
        }
    }
    /**
     * Called by `JSON.stringify(...)` automatically.
     */
    toJSON() {
        return this.message;
    }
}
//# sourceMappingURL=abstract-message.js.map