(authCode: string)
| 105 | } |
| 106 | |
| 107 | export function parseAuthCode(authCode: string): { |
| 108 | fingerprintId: string |
| 109 | expiresAt: string |
| 110 | receivedHash: string |
| 111 | } { |
| 112 | const normalizedAuthCode = authCode.trim() |
| 113 | const hashSeparatorIndex = normalizedAuthCode.lastIndexOf('.') |
| 114 | const expiresSeparatorIndex = normalizedAuthCode.lastIndexOf( |
| 115 | '.', |
| 116 | hashSeparatorIndex - 1, |
| 117 | ) |
| 118 | |
| 119 | if (hashSeparatorIndex === -1 || expiresSeparatorIndex === -1) { |
| 120 | const legacyMatch = normalizedAuthCode.match( |
| 121 | /^(?<fingerprintId>.+)-(?<expiresAt>\d+)-(?<receivedHash>[a-f0-9]{64})$/i, |
| 122 | ) |
| 123 | if (legacyMatch?.groups) { |
| 124 | return { |
| 125 | fingerprintId: legacyMatch.groups.fingerprintId, |
| 126 | expiresAt: legacyMatch.groups.expiresAt, |
| 127 | receivedHash: legacyMatch.groups.receivedHash, |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | return { fingerprintId: '', expiresAt: '', receivedHash: '' } |
| 132 | } |
| 133 | |
| 134 | const fingerprintId = normalizedAuthCode.slice(0, expiresSeparatorIndex) |
| 135 | const expiresAt = normalizedAuthCode.slice( |
| 136 | expiresSeparatorIndex + 1, |
| 137 | hashSeparatorIndex, |
| 138 | ) |
| 139 | const receivedHash = normalizedAuthCode.slice(hashSeparatorIndex + 1) |
| 140 | |
| 141 | return { fingerprintId, expiresAt, receivedHash } |
| 142 | } |
| 143 | |
| 144 | export function validateAuthCode( |
| 145 | receivedHash: string, |
no outgoing calls
no test coverage detected