File

src/verifier/resolver/trust/trustlist-jwt.service.ts

Index

Methods

Constructor

constructor(httpService: HttpService)
Parameters :
Name Type Optional
httpService HttpService No

Methods

fetchJwt
fetchJwt(url: string, timeoutMs: number)
Parameters :
Name Type Optional Default value
url string No
timeoutMs number No 4000
Returns : Promise<string>
verifyTrustListJwt
verifyTrustListJwt(_ref: RulebookTrustListRef, _jwt: string)

Hook to verify JWT signature/authenticity. You can wire your existing JWT verification logic here.

Parameters :
Name Type Optional
_ref RulebookTrustListRef No
_jwt string No
Returns : Promise<void>
import { HttpService } from "@nestjs/axios";
import { Injectable } from "@nestjs/common";
import { firstValueFrom } from "rxjs";
import { RulebookTrustListRef } from "./types";

export type DecodedJwt = { header: any; payload: any; signature: string };
@Injectable()
export class TrustListJwtService {
    constructor(private readonly httpService: HttpService) {}

    fetchJwt(url: string, timeoutMs = 4000): Promise<string> {
        const ctrl = new AbortController();
        const t = setTimeout(() => ctrl.abort(), timeoutMs);
        return firstValueFrom(
            this.httpService.get(url, {
                signal: ctrl.signal,
                responseType: "text",
            }),
        )
            .then((res) => res.data)
            .finally(() => clearTimeout(t));
    }

    /**
     * Hook to verify JWT signature/authenticity.
     * You can wire your existing JWT verification logic here.
     */
    verifyTrustListJwt(
        _ref: RulebookTrustListRef,
        _jwt: string,
    ): Promise<void> {
        //TODO: implement verifiction logic
        // out of scope - assume verified
        return Promise.resolve();
    }
}

results matching ""

    No results matching ""