@johnhenry/browsermesh-primitives 0.0.3 → 0.2.0

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/README.md CHANGED
@@ -25,7 +25,7 @@ Every other package in this monorepo depends on `browsermesh-primitives` directl
25
25
 
26
26
  ## Provenance
27
27
 
28
- Previously maintained as an independent, standalone repository and published to npm, unscoped, as `browsermesh-primitives@0.1.1` (initial release `0.1.0`, 2026-03-15), with its own CI already wired up (tests, CodeQL, dependency review). Imported into the `@johnhenry/browsermesh` monorepo via `git subtree` -- preserving its full commit history -- and rescoped to `@johnhenry/browsermesh-primitives`; the version restarts at `0.0.0` per family convention.
28
+ Previously maintained as an independent, standalone repository and published to npm, unscoped, as `browsermesh-primitives@0.1.1` (initial release `0.2.0`, 2026-03-15), with its own CI already wired up (tests, CodeQL, dependency review). Imported into the `@johnhenry/browsermesh` monorepo via `git subtree` -- preserving its full commit history -- and rescoped to `@johnhenry/browsermesh-primitives`; the version restarts at `0.0.0` per family convention.
29
29
 
30
30
  ## Install
31
31
 
@@ -61,7 +61,10 @@ console.log(identity.podId) // base64url-encoded SHA-256 of public key
61
61
  // Sign and verify data
62
62
  const data = new TextEncoder().encode('hello mesh')
63
63
  const sig = await identity.sign(data)
64
- const ok = await PodIdentity.verify(identity.keyPair.publicKey, data, sig)
64
+ // Argument order is (publicKey, signature, data) -- same as crypto.subtle.verify.
65
+ // BREAKING in 0.2.0: earlier versions took (publicKey, data, signature); the old
66
+ // order now throws a TypeError instead of silently returning false.
67
+ const ok = await PodIdentity.verify(identity.keyPair.publicKey, sig, data)
65
68
 
66
69
  // CRDTs -- merge state across peers
67
70
  const clockA = new VectorClock()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnhenry/browsermesh-primitives",
3
- "version": "0.0.3",
3
+ "version": "0.2.0",
4
4
  "description": "Shared primitives for browser mesh networking — wire format, identity (Ed25519), CRDTs, capabilities, trust model, and ACL engine",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
package/src/identity.mjs CHANGED
@@ -159,12 +159,40 @@ export class PodIdentity {
159
159
  /**
160
160
  * Verify a signature against a public key.
161
161
  *
162
+ * Argument order is `(publicKey, signature, data)`, the same as WebCrypto's
163
+ * `crypto.subtle.verify('Ed25519', publicKey, signature, data)`.
164
+ *
165
+ * BREAKING (primitives 0.2.0): releases before this took
166
+ * `(publicKey, data, signature)`. A guard throws a TypeError when the old
167
+ * order is detected (Ed25519 signatures are exactly 64 bytes) rather than
168
+ * silently returning false.
169
+ *
162
170
  * @param {CryptoKey} publicKey - Ed25519 public key
171
+ * @param {BufferSource} signature - Signature to verify (64 bytes)
163
172
  * @param {BufferSource} data - Original data
164
- * @param {BufferSource} signature - Signature to verify
165
173
  * @returns {Promise<boolean>}
166
174
  */
167
- static async verify(publicKey, data, signature) {
175
+ static async verify(publicKey, signature, data) {
176
+ if (
177
+ byteLengthOf(signature) !== ED25519_SIGNATURE_BYTES &&
178
+ byteLengthOf(data) === ED25519_SIGNATURE_BYTES
179
+ ) {
180
+ throw new TypeError(
181
+ 'PodIdentity.verify: argument order changed to (publicKey, signature, data) ' +
182
+ 'in this version (previously (publicKey, data, signature)); ' +
183
+ 'the signature argument is not 64 bytes but the data argument is'
184
+ );
185
+ }
168
186
  return crypto.subtle.verify('Ed25519', publicKey, signature, data);
169
187
  }
170
188
  }
189
+
190
+ const ED25519_SIGNATURE_BYTES = 64;
191
+
192
+ /**
193
+ * @param {BufferSource} v
194
+ * @returns {number}
195
+ */
196
+ function byteLengthOf(v) {
197
+ return v && typeof v.byteLength === 'number' ? v.byteLength : -1;
198
+ }
package/src/index.d.ts CHANGED
@@ -43,6 +43,17 @@ export declare class PodIdentity {
43
43
  constructor(opts: { keyPair: CryptoKeyPair; podId: string });
44
44
  static generate(): Promise<PodIdentity>;
45
45
  sign(data: BufferSource): Promise<Uint8Array>;
46
+ /**
47
+ * Argument order is (publicKey, signature, data), matching WebCrypto.
48
+ * BREAKING in 0.2.0: previously (publicKey, data, signature). Throws a
49
+ * TypeError if the old order is detected (64-byte data, non-64-byte signature).
50
+ */
51
+ static verify(publicKey: CryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>;
52
+ /**
53
+ * Positional form, kept for compatibility. WARNING: order is
54
+ * (publicKey, DATA, SIGNATURE) -- unlike WebCrypto/wsh (key, signature, data)
55
+ * and raijin (message, signature, key). Prefer the object form.
56
+ */
46
57
  static verify(publicKey: CryptoKey, data: BufferSource, signature: BufferSource): Promise<boolean>;
47
58
  }
48
59