( options: CreateSignatureBaseOptions, )
| 703 | * @returns The signature base string. |
| 704 | */ |
| 705 | export function createSignatureBase( |
| 706 | options: CreateSignatureBaseOptions, |
| 707 | ): string { |
| 708 | const { message, params, request: relatedRequest } = options; |
| 709 | const components = params.components.map(normalizeIdentifier); |
| 710 | |
| 711 | const seen = new Set<string>(); |
| 712 | const lines: string[] = []; |
| 713 | const parsedUrl: { value?: URL } = {}; |
| 714 | const relatedParsedUrl: { value?: URL } = {}; |
| 715 | for (const id of components) { |
| 716 | if (id.name === "@signature-params") { |
| 717 | throw new TypeError( |
| 718 | `"@signature-params" must not be listed in covered components`, |
| 719 | ); |
| 720 | } |
| 721 | if (id.name !== id.name.toLowerCase()) { |
| 722 | throw new TypeError( |
| 723 | `Component name "${id.name}" must be lowercase`, |
| 724 | ); |
| 725 | } |
| 726 | const serializedId = serializeComponentIdentifier(id); |
| 727 | if (seen.has(serializedId)) { |
| 728 | throw new TypeError( |
| 729 | `Duplicate component identifier ${serializedId} in covered components`, |
| 730 | ); |
| 731 | } |
| 732 | seen.add(serializedId); |
| 733 | const value = resolveComponentValue( |
| 734 | id, |
| 735 | message, |
| 736 | parsedUrl, |
| 737 | relatedRequest, |
| 738 | relatedParsedUrl, |
| 739 | ); |
| 740 | lines.push(`${serializedId}: ${value}`); |
| 741 | } |
| 742 | |
| 743 | const sigParamsValue = buildSignatureParamsValue(components, params); |
| 744 | lines.push(`"@signature-params": ${sigParamsValue}`); |
| 745 | |
| 746 | return lines.join("\n"); |
| 747 | } |
| 748 | |
| 749 | // ============================================================================= |
| 750 | // Input Validation |
no test coverage detected