buddy-reroll 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/companion.js CHANGED
@@ -35,11 +35,17 @@ function mulberry32(seed) {
35
35
  };
36
36
  }
37
37
 
38
- import { wyhash } from "./wyhash.js";
38
+ function fnv1a(str) {
39
+ let h = 2166136261;
40
+ for (let i = 0; i < str.length; i++) {
41
+ h ^= str.charCodeAt(i);
42
+ h = Math.imul(h, 16777619);
43
+ }
44
+ return h >>> 0;
45
+ }
39
46
 
40
47
  function hashString(value) {
41
- if (typeof Bun !== "undefined") return Number(BigInt(Bun.hash(value)) & 0xffffffffn);
42
- return Number(wyhash(0n, value) & 0xffffffffn);
48
+ return fnv1a(value);
43
49
  }
44
50
 
45
51
  function pick(rng, items) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "buddy-reroll",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Reroll your Claude Code buddy companion to any species/rarity/eye/hat/shiny combo",
5
5
  "type": "module",
6
6
  "bin": {
package/lib/wyhash.js DELETED
@@ -1,88 +0,0 @@
1
- // Wyhash v4.2 — Pure JavaScript implementation
2
- // Ported from @pencroff-lab/wyhash-ts (Apache-2.0)
3
- // https://github.com/pencroff-lab/wyhash-ts
4
- //
5
- // Produces identical output to Bun.hash() for string inputs.
6
-
7
- const secret = [
8
- 0xa0761d6478bd642fn,
9
- 0xe7037ed1a0b428dbn,
10
- 0x8ebc6af09c88c6e3n,
11
- 0x589965cc75374cc3n,
12
- ];
13
-
14
- function read(data, offset, bytes) {
15
- let result = 0n;
16
- for (let i = 0; i < bytes && offset + i < data.length; i++) {
17
- result |= BigInt(data[offset + i]) << (BigInt(i) * 8n);
18
- }
19
- return BigInt.asUintN(64, result);
20
- }
21
-
22
- function mum(a, b) {
23
- const x = a * b;
24
- return [BigInt.asUintN(64, x), BigInt.asUintN(64, x >> 64n)];
25
- }
26
-
27
- function mix(a, b) {
28
- const [aMul, bMul] = mum(a, b);
29
- return aMul ^ bMul;
30
- }
31
-
32
- function sum64(seed, input) {
33
- let a, b;
34
- let state0 = seed ^ mix(seed ^ secret[0], secret[1]);
35
- const len = input.length;
36
-
37
- if (len <= 16) {
38
- if (len >= 4) {
39
- const end = len - 4;
40
- const quarter = (len >> 3) << 2;
41
- a = (read(input, 0, 4) << 32n) | read(input, quarter, 4);
42
- b = (read(input, end, 4) << 32n) | read(input, end - quarter, 4);
43
- } else if (len > 0) {
44
- a = (BigInt(input[0]) << 16n) | (BigInt(input[len >> 1]) << 8n) | BigInt(input[len - 1]);
45
- b = 0n;
46
- } else {
47
- a = 0n;
48
- b = 0n;
49
- }
50
- } else {
51
- const state = [state0, state0, state0];
52
- let i = 0;
53
-
54
- if (len >= 48) {
55
- while (i + 48 < len) {
56
- for (let j = 0; j < 3; j++) {
57
- const aRound = read(input, i + 8 * (2 * j), 8);
58
- const bRound = read(input, i + 8 * (2 * j + 1), 8);
59
- state[j] = mix(aRound ^ secret[j + 1], bRound ^ state[j]);
60
- }
61
- i += 48;
62
- }
63
- state[0] ^= state[1] ^ state[2];
64
- }
65
-
66
- const remaining = input.subarray(i);
67
- let k = 0;
68
- while (k + 16 < remaining.length) {
69
- state[0] = mix(read(remaining, k, 8) ^ secret[1], read(remaining, k + 8, 8) ^ state[0]);
70
- k += 16;
71
- }
72
-
73
- a = read(input, len - 16, 8);
74
- b = read(input, len - 8, 8);
75
- state0 = state[0];
76
- }
77
-
78
- a ^= secret[1];
79
- b ^= state0;
80
- [a, b] = mum(a, b);
81
- return mix(a ^ secret[0] ^ BigInt(len), b ^ secret[1]);
82
- }
83
-
84
- const encoder = new TextEncoder();
85
-
86
- export function wyhash(seed, key) {
87
- return sum64(BigInt.asUintN(64, seed), encoder.encode(key));
88
- }
@@ -1,50 +0,0 @@
1
- import { describe, it, expect } from "bun:test";
2
- import { wyhash } from "./wyhash.js";
3
-
4
- describe("wyhash", () => {
5
- it("matches Bun.hash for empty string", () => {
6
- expect(wyhash(0n, "")).toBe(BigInt(Bun.hash("")));
7
- });
8
-
9
- it("matches Bun.hash for short strings", () => {
10
- const cases = ["a", "ab", "abc", "hello", "hello world"];
11
- for (const s of cases) {
12
- expect(wyhash(0n, s)).toBe(BigInt(Bun.hash(s)));
13
- }
14
- });
15
-
16
- it("matches Bun.hash for companion-realistic inputs", () => {
17
- const salts = ["friend-2026-401", "friend-2026-abc", "xxxxxxxxxxxxxxx"];
18
- const userIds = ["anon", "fd50b3fd-1234-5678-9abc-def012345678"];
19
- for (const uid of userIds) {
20
- for (const salt of salts) {
21
- const key = uid + salt;
22
- expect(wyhash(0n, key)).toBe(BigInt(Bun.hash(key)));
23
- }
24
- }
25
- });
26
-
27
- it("matches Bun.hash for long strings (>48 bytes)", () => {
28
- const long = "a".repeat(100);
29
- expect(wyhash(0n, long)).toBe(BigInt(Bun.hash(long)));
30
- });
31
-
32
- it("matches Bun.hash for unicode strings", () => {
33
- const cases = ["한글", "αβγδ", "🎮🐉✨"];
34
- for (const s of cases) {
35
- expect(wyhash(0n, s)).toBe(BigInt(Bun.hash(s)));
36
- }
37
- });
38
-
39
- it("returns bigint", () => {
40
- expect(typeof wyhash(0n, "test")).toBe("bigint");
41
- });
42
-
43
- it("is deterministic", () => {
44
- expect(wyhash(0n, "test")).toBe(wyhash(0n, "test"));
45
- });
46
-
47
- it("produces different output for different inputs", () => {
48
- expect(wyhash(0n, "hello")).not.toBe(wyhash(0n, "world"));
49
- });
50
- });