mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-13 08:03:09 +02:00
c2370a1be6
* chore: Add the SPDX information to each file Add copyright and licensing information as defined in version 3.0 of the REUSE Specification. * tweak format --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
19 lines
639 B
TypeScript
19 lines
639 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import IPCIDR from 'ip-cidr';
|
|
|
|
export function getIpHash(ip: string): string {
|
|
try {
|
|
// because a single person may control many IPv6 addresses,
|
|
// only a /64 subnet prefix of any IP will be taken into account.
|
|
// (this means for IPv4 the entire address is used)
|
|
const prefix = IPCIDR.createAddress(ip).mask(64);
|
|
return 'ip-' + BigInt('0b' + prefix).toString(36);
|
|
} catch (e) {
|
|
const prefix = IPCIDR.createAddress(ip.replace(/:[0-9]+$/, '')).mask(64);
|
|
return 'ip-' + BigInt('0b' + prefix).toString(36);
|
|
}
|
|
}
|