@pkmn/anon
TypeScript icon, indicating that this package has built-in type declarations

0.1.14 • Public • Published

@pkmn/anon

Test Status License npm version

Logic for anonymizing Pokémon Showdown teams and battle logs.

Installation

$ npm install @pkmn/anon

Usage

@pkmn/anon provides an Anonymizer class which can be used to anonymize teams or battle logs:

import {Anonymizer, Verifier} from '@pkmn/anon';
import {Generations} from '@pkmn/data';
import {Dex} from '@pkmn/dex';

const gens = new Generations(Dex);
const gen = gens.get(raw.format.startsWith('gen') ? +raw.format.charAt(3) : 6);

const verifier = new Verifier();
const anon = Anonymizer.anonymize(gen, raw, {verifier});
if (verifier.ok()) console.log(JSON.stringify(anon, null, 2));

By default, anonymization will replace player's usernames with 'Player 1' and 'Player 2' and Pokémon's nicknames with their species name (in addition to removing chat logs, timestamps, rating info, etc). Both anonymize and anonymizeTeam take a 'salt' option which will cause the Anonymizer to hash the usernames and nicknames with the salt instead - this mode allows for tracking the presence of a player or Pokémon accross multiple battle logs without revealing the true identities.

Anonymizer's methods also take an option 'verifier' parameter - a Verifier can be used to sanity check the log output and ensure no names have leaked out. This is almost always due to a false positive (often a Pokémon being nicknamed something which appears in the output logs in another location), but can be helpful in ensuring no PII gets leaked due to bugs or oversight.

CLI

The anonymize tool takes in a log as input and anonymizes it:

$ anonymize 2020-09/gen8ou/2020-09-25/gen8ou-2875469343.log

If there are potential leaks the warnings from the Verifier will be output instead. For anonymizing logs efficiently en masse, see @pkmn/logs and the smogon/anon workflow. The sample tool can be used to come up with a --formats flag for the workflow - the tool queries past usage stats reports to determine how many battles were present in a given month to be able to determine at what rates to sample at to end up with the desired number of logs for each format:

$ sample 100000 --formats=gen8ou,gen7ou --begin=2022-01 --end=2022-04

This produces --formats=gen8ou:0.019417382834173616,gen7ou:0.00402947392710268.

Browser

The recommended way of using @pkmn/anon in a web browser is to configure your bundler (Webpack, Rollup, Parcel, etc) to minimize it and package it with the rest of your application.

License

This package is distributed under the terms of the MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i @pkmn/anon

Weekly Downloads

1

Version

0.1.14

License

MIT

Unpacked Size

80.6 kB

Total Files

9

Last publish

Collaborators

  • kjscheibo