MCPcopy Create free account
hub / github.com/denoland/std / verifyMessage

Function verifyMessage

http/unstable_message_signatures.ts:921–1084  ·  view source on GitHub ↗
(
  message: Request | Response,
  keyLookup: (
    keyId: string,
    algorithm?: SignatureAlgorithm,
  ) => Promise<CryptoKey | null> | CryptoKey | null,
  options?: VerifyOptions,
)

Source from the content-addressed store, hash-verified

919 * @returns Array of verified signature results.
920 */
921export async function verifyMessage(
922 message: Request | Response,
923 keyLookup: (
924 keyId: string,
925 algorithm?: SignatureAlgorithm,
926 ) => Promise<CryptoKey | null> | CryptoKey | null,
927 options?: VerifyOptions,
928): Promise<VerifyResult[]> {
929 if (
930 options?.maxAge !== undefined &&
931 (!Number.isInteger(options.maxAge) || options.maxAge < 0)
932 ) {
933 throw new RangeError(
934 `maxAge must be a non-negative integer, got ${options.maxAge}`,
935 );
936 }
937
938 const sigInputHeader = message.headers.get("Signature-Input");
939 if (sigInputHeader === null) {
940 throw new TypeError('Missing "Signature-Input" header');
941 }
942 const sigHeader = message.headers.get("Signature");
943 if (sigHeader === null) {
944 throw new TypeError('Missing "Signature" header');
945 }
946
947 const sigInputDict = parseDictionary(sigInputHeader);
948 const sigDict = parseDictionary(sigHeader);
949
950 // Validate label consistency
951 for (const [label] of sigInputDict) {
952 if (!sigDict.has(label)) {
953 throw new TypeError(
954 `Label "${label}" found in Signature-Input but missing in Signature`,
955 );
956 }
957 }
958 for (const [label] of sigDict) {
959 if (!sigInputDict.has(label)) {
960 throw new TypeError(
961 `Label "${label}" found in Signature but missing in Signature-Input`,
962 );
963 }
964 }
965
966 const results: VerifyResult[] = [];
967 const now = Math.floor(Date.now() / 1000);
968
969 for (const [label, sigInputMember] of sigInputDict) {
970 // Filter by labels option
971 if (options?.labels && !options.labels.includes(label)) continue;
972
973 if (!isInnerList(sigInputMember)) {
974 throw new TypeError(
975 `Signature-Input member "${label}" is not an Inner List`,
976 );
977 }
978

Calls 15

parseDictionaryFunction · 0.90
isInnerListFunction · 0.90
isItemFunction · 0.90
parseSignatureInputFunction · 0.85
normalizeIdentifierFunction · 0.85
createSignatureBaseFunction · 0.85
inferAlgorithmFunction · 0.85
getSignParamsFunction · 0.85
floorMethod · 0.80
nowMethod · 0.80
includesMethod · 0.80

Tested by

no test coverage detected