1- import { argon2id , hash , verify } from 'argon2'
1+ import * as argon2 from 'argon2'
22import { H3Event } from 'h3'
3- import { useRuntimeConfig } from '#app'
43import { Session } from '../../../../types'
54import { IpMissingFromSession , IpMismatch } from './exceptions'
5+ import { useRuntimeConfig } from '#imports'
66
77const argon2Options = {
88 // cryptographically-secure salt is generated automatically
9- type : argon2id , // resistant against GPU & tradeoff attacks
9+ type : argon2 . argon2id , // resistant against GPU & tradeoff attacks
1010 hashLength : 60
1111}
1212
@@ -17,14 +17,14 @@ const argon2Options = {
1717export const hashIpAddress = ( ip : string | undefined ) : Promise < string | undefined > =>
1818 ! ip
1919 ? Promise . resolve ( undefined )
20- : hash ( ip , argon2Options )
20+ : argon2 . hash ( ip , argon2Options )
2121
2222/**
2323 * Check that the given (raw) IP address and the hashed IP address match
2424 * @param ip string|undefined The IP address to verify
2525 * @param ipHash string|undefined The (hashed) IP address to test against
2626 */
27- export const ipAddressesMatch = ( ip : string | undefined , ipHash : string | undefined ) : Promise < boolean > => ( ! ip && ! ipHash ) ? Promise . resolve ( false ) : verify ( ipHash , ip , argon2Options )
27+ export const ipAddressesMatch = ( ip : string | undefined , ipHash : string | undefined ) : Promise < boolean > => ( ! ip && ! ipHash ) ? Promise . resolve ( false ) : argon2 . verify ( ipHash , ip , argon2Options )
2828
2929/**
3030 * Extract the IP address from an HTTP header
@@ -58,7 +58,7 @@ export const getRequestIpAddress = ({ req }: H3Event): string | undefined => {
5858 return req . socket . remoteAddress
5959}
6060
61- export const getHashedIpAddress = ( event : H3Event ) : Promise < string | undefined > => {
61+ export const getHashedIpAddress = ( event : H3Event ) : Promise < string | undefined > => {
6262 return hashIpAddress ( getRequestIpAddress ( event ) )
6363}
6464
0 commit comments