1 # tesid: JavaScript package for Textualised Encrypted Sequential Identifiers
3 This package implements the TESID scheme for producing short, human-friendly,
4 cryptographically-secure pseudorandom strings out of sequential identifiers.
6 See <https://chrismorgan.info/tesid/> for more information about TESID.
8 A simple demonstration:
11 import { TESIDCoder } from "tesid";
13 const secretKey = "000102030405060708090a0b0c0d0e0f";
14 const coder = new TESIDCoder(secretKey);
16 console.assert(coder.encode(0n) == "w2ej");
17 console.assert(coder.encode(1n) == "w6um");
18 console.assert(coder.encode(2n) == "x45g");
19 console.assert(coder.encode(2n**20n - 1) == "atcw");
20 console.assert(coder.encode(2n**20n) == "8qwm6y");
21 console.assert(coder.encode(2n**30n - 1) == "3eipc7");
22 console.assert(coder.encode(2n**30n) == "n3md95r4");
23 console.assert(coder.encode(2n**100n - 1) == "ia2bvpjaiju7g5uaxn5t");
24 // And coder.encode(2n**100n) would throw RangeError.
26 console.assert(coder.decode("w2ej") == 0);
30 // And with the most convenient form of type discrimination, here using TypeScript features:
31 // (You can also do all this through TESIDCoder, but it’s less convenient.)
32 import { TypedTESIDCoder } from "tesid";
39 const typedCoder = new TypedTESIDCoder(coder, 256, Type);
41 console.assert(typedCoder.encode(Type.A, 0) == "w2ej");
42 console.assert(typedCoder.encode(Type.B, 0) == "w6um");
43 console.assert(typedCoder.encode(Type.C, 0) == "x45g");
44 console.assert(typedCoder.encode(Type.A, 1) == "dh2h");
45 console.assert(typedCoder.encode(Type.B, 1) == "a6xy");
46 console.assert(typedCoder.encode(Type.C, 1) == "7xgj");
47 console.assert(typedCoder.decode(Type.A, "w2ej") == 0);
48 // typedCoder.decode(Type.B, "w2ej") would throw RangeError.
49 console.assert(typedCoder.splitDecode("w2ej").id == 0);
50 console.assert(typedCoder.splitDecode("w2ej").discriminant == Type.A);
53 This implementation is done as a single file with encryption and base conversion inlined for performance and code size.
54 Minified with Terser with all functionality retained, it’s
1680 bytes (
915 gzipped with zopfli).
55 (Stripped to its bones—no TypedTESIDCoder, no splitDecode, no sparsity or discriminant, and slightly worse error reporting—it’s under
1200/
700.)
57 Type definitions and documentation are provided in tesid.d.ts.
61 **Authorship:**
[Chris Morgan](https://chrismorgan.info/) is the author and maintainer of this library.
63 **Licensing:** this library is distributed under the terms of the
64 [Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0) and the
65 [ISC License](https://opensource.org/licenses/ISC), at your choice.
66 See [COPYRIGHT](COPYRIGHT) for details.