@taprsvp/types
Version:
TypeScript types and interfaces for the Transaction Authorization Protocol (TAP)
87 lines • 3.52 kB
TypeScript
/**
* @fileoverview TAIP-12 Name Hashing Implementation
*
* This module provides utilities for generating SHA-256 hashes of participant names
* according to the TAIP-12 specification for privacy-preserving name matching.
*
* The implementation follows the exact normalization and hashing method used by
* VerifyVASP and GTR networks to ensure cross-platform compatibility.
*
* Enhanced to support IVMS101 originator/beneficiary structures for seamless
* integration with travel rule compliance systems.
*
* @see {@link https://github.com/TransactionAuthorizationProtocol/TAIPs/blob/main/TAIPs/taip-12.md | TAIP-12: Privacy-Preserving Name Matching}
*/
import type { Originator, Beneficiary } from 'ivms101';
/**
* Normalizes a name string for hashing according to TAIP-12 specification.
*
* The normalization process:
* 1. Removes ALL whitespace characters (spaces, tabs, newlines, etc.)
* 2. Converts all letters to uppercase
*
* This ensures consistent hashing across different systems and data formats.
*
* @param name - The name string to normalize
* @returns The normalized name string (uppercase, no whitespace)
*
* @example
* ```typescript
* normalizeForHashing("Alice Lee") // Returns "ALICELEE"
* normalizeForHashing(" Bob Smith ") // Returns "BOBSMITH"
* normalizeForHashing("maría garcía") // Returns "MARÍAGARCÍA"
* ```
*/
export declare function normalizeForHashing(name: string): string;
/**
* Generates a SHA-256 hash of a normalized name according to TAIP-12 specification.
*
* This function supports three input types:
* 1. String names (original functionality)
* 2. IVMS101 originator structures (extracts names from all persons)
* 3. IVMS101 beneficiary structures (extracts names from all persons)
*
* For IVMS101 structures with multiple persons, it combines all extracted names
* with spaces and then normalizes the result.
*
* The implementation uses runtime detection to support both browser and Node.js environments:
* - Uses Web Crypto API (`globalThis.crypto.subtle`) when available (browsers, Node.js 15+)
* - Falls back to Node.js built-in `crypto` module for older Node.js versions
*
* @param input - The name string or IVMS101 originator/beneficiary structure to hash
* @returns Promise that resolves to the SHA-256 hash as a lowercase hex string
* @throws Error if no crypto implementation is available
*
* @example
* ```typescript
* // String names (TAIP-12 test vectors)
* await generateNameHash("Alice Lee") // "b117f44426c9670da91b563db728cd0bc8bafa7d1a6bb5e764d1aad2ca25032e"
* await generateNameHash("Bob Smith") // "5432e86b4d4a3a2b4be57b713b12c5c576c88459fe1cfdd760fd6c99a0e06686"
*
* // IVMS101 originator
* const originator: IVMS101_2020.Originator = {
* originatorPersons: [
* {
* naturalPerson: {
* name: [{ primaryIdentifier: "Lee", secondaryIdentifier: "Alice", nameIdentifierType: "LEGL" }]
* }
* }
* ]
* };
* await generateNameHash(originator) // Same hash as "Alice Lee"
*
* // IVMS101 beneficiary
* const beneficiary: IVMS101_2020.Beneficiary = {
* beneficiaryPersons: [
* {
* legalPerson: {
* name: [{ legalPersonName: "Acme Corporation", legalPersonNameIdentifierType: "LEGL" }]
* }
* }
* ]
* };
* await generateNameHash(beneficiary) // Hash of "Acme Corporation"
* ```
*/
export declare function generateNameHash(input: string | Originator | Beneficiary): Promise<string>;
//# sourceMappingURL=nameHash.d.ts.map