Skip to content

Commit

Permalink
add entity configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
balanza committed Aug 10, 2023
1 parent c44b2fd commit e3856f6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("CreateWalletInstanceAttestationHandler", async () => {
.setExpirationTime("2h")
.sign(josePrivateKey);

it("should return a 201 HTTP response", () => {
it("should return a 201 HTTP response", async () => {
const run = CreateWalletInstanceAttestationHandler({
input: pipe(H.request("https://wallet-provider.example.org"), (req) => ({
...req,
Expand All @@ -124,11 +124,16 @@ describe("CreateWalletInstanceAttestationHandler", async () => {
federationEntityMetadata,
signer,
});
expect(run()).resolves.toEqual(
const result = await run();

if (E.isLeft(result)) {
throw new Error(`Failed with error: ${result.left.message}`);
}

expect(result.right).toEqual(
expect.objectContaining({
right: expect.objectContaining({
statusCode: 201,
}),
statusCode: 201,
body: expect.any(String),
})
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import * as t from "io-ts";
import * as TE from "fp-ts/TaskEither";
import * as RTE from "fp-ts/ReaderTaskEither";
import { pipe } from "fp-ts/function";
import { sequenceS } from "fp-ts/lib/Apply";
import { sequenceS, sequenceT } from "fp-ts/lib/Apply";

import {
EntityConfigurationEnvironment,
FederationEntity,
getEntityConfiguration,
} from "./entity-configuration";
import { verifyWalletInstanceAttestationRequest } from "./wallet-instance-attestation-request";
import { LoA, getLoAUri } from "./wallet-provider";
Expand All @@ -29,6 +30,29 @@ export type WalletInstanceAttestationPayload = t.TypeOf<
typeof WalletInstanceAttestationPayload
>;

const composeTrustChain = ({
federationEntityMetadata,
signer,
}: EntityConfigurationEnvironment) => {
const walletProviderEntityStatement = pipe(
new EidasTrustAnchor(federationEntityMetadata),
(ta) => ta.getEntityStatement(),
TE.map(({ encoded }) => encoded)
);

const walletProviderEntityConfiguration = getEntityConfiguration()({
federationEntityMetadata,
signer,
});

return pipe(
sequenceT(TE.ApplicativePar)(
walletProviderEntityConfiguration,
walletProviderEntityStatement
)
);
};

// Build the JWT of the Wallet Instance Attestation given a Wallet Instance Attestation Request
export const createWalletInstanceAttestation =
(
Expand All @@ -46,11 +70,7 @@ export const createWalletInstanceAttestation =
signer.getSupportedSignAlgorithms(),
TE.fromEither
),
trustChain: pipe(
new EidasTrustAnchor(federationEntityMetadata),
(ta) => ta.getEntityStatement(),
TE.map(({ encoded }) => [encoded])
),
trustChain: composeTrustChain({ federationEntityMetadata, signer }),
}),
TE.chain(({ request, publicJwk, supportedSignAlgorithms, trustChain }) =>
pipe(
Expand Down

0 comments on commit e3856f6

Please sign in to comment.