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 { DidKeyResolver } from '../../src/did/did-key-resolver.js';
import { DidResolver } from '../../src/did/did-resolver.js';
import { expect } from 'chai';
import { GeneralJwsSigner } from '../../src/jose/jws/general/signer.js';
import { GeneralJwsVerifier } from '../../src/jose/jws/general/verifier.js';
import { Jws } from '../../src/utils/jws.js';
import { signers } from '../../src/jose/algorithms/signing/signers.js';
import sinon from 'sinon';
const { secp256k1 } = signers;
describe('Jws', () => {
    describe('verifySignature', () => {
        if (process.env.TESTSOFF === 'true') {
            return;
        }
        it('create signature input', () => __awaiter(void 0, void 0, void 0, function* () {
            const bob = yield DidKeyResolver.generate();
            // console.log('create signature input bob', bob);
            const sig = Jws.createSignatureInput(bob);
            // console.log('sig', sig);
            expect(sig).to.not.be.undefined;
        }));
        it('returns true if signature is successfully verified', () => __awaiter(void 0, void 0, void 0, function* () {
            const { privateJwk, publicJwk } = yield secp256k1.generateKeyPair();
            const payloadBytes = new TextEncoder().encode('anyPayloadValue');
            const protectedHeader = { alg: 'ES256K', kid: 'did:key:alice#key1' };
            const signer = yield GeneralJwsSigner.create(payloadBytes, [{ privateJwk, protectedHeader }]);
            const jws = signer.getJws();
            console.log('jws', jws);
            const mockResolutionResult = {
                didResolutionMetadata: {},
                didDocument: {
                    verificationMethod: [{
                            id: 'did:key:alice#key1',
                            type: 'JsonWebKey2020',
                            controller: 'did:key:alice',
                            publicKeyJwk: publicJwk
                        }]
                },
                didDocumentMetadata: {}
            };
            const resolverStub = sinon.createStubInstance(DidResolver, {
                // @ts-ignore
                resolve: sinon.stub().withArgs('did:key:alice').resolves(mockResolutionResult)
            });
            const verifier = new GeneralJwsVerifier(jws);
            // console.log('verifier', verifier);
            const verificationResult = yield verifier.verify(resolverStub);
            console.log('verificationResult', verificationResult);
            expect(verificationResult.signers.length).to.equal(1);
            expect(verificationResult.signers).to.include('did:key:alice');
        }));
    });
});
//# sourceMappingURL=jws.spec.js.map