var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { Time } from '../utils/time.js';
import { validateMessageSignatureIntegrity } from '../core/auth.js';
import { DwnError, DwnErrorCode } from '../core/dwn-error.js';
import { DwnInterfaceName, DwnMethodName, Message } from '../core/message.js';
export class PermissionsRevoke extends Message {
    static parse(message) {
        return __awaiter(this, void 0, void 0, function* () {
            yield validateMessageSignatureIntegrity(message.authorization.signature, message.descriptor);
            Time.validateTimestamp(message.descriptor.messageTimestamp);
            return new PermissionsRevoke(message);
        });
    }
    static create(options) {
        var _a;
        return __awaiter(this, void 0, void 0, function* () {
            const descriptor = {
                interface: DwnInterfaceName.Permissions,
                method: DwnMethodName.Revoke,
                messageTimestamp: (_a = options.messageTimestamp) !== null && _a !== void 0 ? _a : Time.getCurrentTimestamp(),
                permissionsGrantId: options.permissionsGrantId,
            };
            const authorization = yield Message.createAuthorization(descriptor, options.signer);
            const message = { descriptor, authorization };
            Message.validateJsonSchema(message);
            return new PermissionsRevoke(message);
        });
    }
    authorize(permissionsGrantMessage) {
        return __awaiter(this, void 0, void 0, function* () {
            if (this.author !== permissionsGrantMessage.descriptor.grantedFor) {
                // Until delegation is implemented, only the DWN owner may grant or revoke access to their DWN
                throw new DwnError(DwnErrorCode.PermissionsRevokeUnauthorizedRevoke, 'Only the DWN owner may revoke a grant');
            }
        });
    }
}
//# sourceMappingURL=permissions-revoke.js.map