@leofcoin/binary 0.0.0-stage → 1.0.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.
Files changed (2) hide show
  1. package/README.md +47 -2
  2. package/package.json +31 -4
package/README.md CHANGED
@@ -1,3 +1,48 @@
1
- # Temporary Holding Version
1
+ # @leofcoin/binary
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@leofcoin/binary` is a dependency-free shared implementation of unsigned
4
+ base-128 integers and length-prefixed byte frames. Numeric values retain the
5
+ existing wire bytes. No chain field, codec identifier, hash algorithm or supply
6
+ representation changes as part of this migration.
7
+
8
+ It is independent of `@leofcoin/codecs`, which remains the registry of codec
9
+ identifiers. This package does not import or re-export that registry.
10
+
11
+ ```js
12
+ import { BinaryReader, BinaryWriter, varUintLength } from '@leofcoin/binary'
13
+
14
+ const signature = new Uint8Array(64)
15
+ const writer = new BinaryWriter(varUintLength(1) + varUintLength(129) + signature.length)
16
+ writer.writeVarUint(1).writeVarUint(129).writeBytes(signature)
17
+ const reader = new BinaryReader(writer.finish())
18
+ const version = reader.readVarUint()
19
+ const codec = reader.readVarUint()
20
+ const decodedSignature = reader.readBytes(reader.remaining)
21
+ ```
22
+
23
+ - `writeVarUint` / `readVarUint`: unsigned safe-integer Numbers, at most 8 bytes.
24
+ - `writeVarBigInt` / `readVarBigInt`: unsigned BigInts through `2^256-1`, at most 37 bytes.
25
+ - `writeFrame` / `readFrame`: Number length prefix plus bytes. A failed operation
26
+ does not advance the cursor. Writes check capacity before changing bytes.
27
+ - `encodeFrames` / `decodeFrames`: a sequence of those frames; optional raw prefix
28
+ bytes on encode, corresponding prefix length on decode. Encoding allocates one
29
+ output buffer, without allocating a varint array for every field. Decoding is
30
+ iterative, so many fields do not exhaust the call stack.
31
+
32
+ Readers return **views**, not copies; modifying a view modifies the input buffer.
33
+ `writer.finish()` likewise returns a view. Use `finish(true)` to retain an
34
+ independent copy before resetting/reusing a writer. Writers have fixed capacity;
35
+ the caller supplies the capacity or an existing Uint8Array. There is no hidden
36
+ buffer growth or mutable process-global `.bytes` state.
37
+
38
+ New reader calls reject padded/non-canonical integers by default. Existing block
39
+ validator framing explicitly uses `canonical: false` to preserve legacy padded
40
+ prefix acceptance. Tightening that consensus rule needs a separate protocol
41
+ decision. Overflow and truncated fields still fail closed. `decodeFrames` accepts
42
+ an optional `maxFrames` policy; network size/membership limits remain the caller's
43
+ responsibility. BigInt support does not automatically migrate existing fields.
44
+
45
+ Checks: `npm test -w @leofcoin/binary`, `npm test -w @leofcoin/messages`.
46
+ Benchmark: `node test/bench/binary-codec.js`. It compares the actual installed
47
+ legacy framing packages and verifies equal bytes before measuring. Results are
48
+ local CPU timings, not blockchain throughput or transport latency claims.
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "@leofcoin/binary",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Dependency-free binary Reader/Writer, unsigned varints and byte framing",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "import": "./exports/index.js",
13
+ "types": "./exports/index.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "exports",
18
+ "README.md"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc6 -p tsconfig.json",
22
+ "test": "node --test"
23
+ },
24
+ "devDependencies": {
25
+ "@typescript/native": "npm:typescript@^7.0.2",
26
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/leofcoin/monorepo.git",
31
+ "directory": "packages/binary"
32
+ }
33
+ }