Skip to content

Bug: deversify mutates Vrsn_1_0 and misreads hex version digits #423

Open

Description

@dhh1128

Version: 0.4.1 (main at e24c41d)

Environment: any (reproduced on Linux, Node 24)

Expected behavior

deversify should return the version it parsed without changing anything else, and should decode the version digits as hex, which is how VEREX matches them and how versify writes them. sizeify should reject a version string other than 1.0, as its unsupported version guard intends.

Actual behavior

There are two bugs in deversify (src/keri/core/core.ts).

First, it does const version = Vrsn_1_0;, writes the parsed major and minor into that object, and returns it. Vrsn_1_0 is the module-wide constant that versify, Serder and the event builders use as their default version, so after a non-1.0 version string is parsed, all of those defaults carry the parsed version until a 1.0 string is parsed again. The same aliasing disables the guard in sizeify (src/keri/core/serder.ts), which checks if (version != Vrsn_1_0). That is a reference comparison against the object deversify just returned, so it is always false, and a KERI11JSON… or KERI20JSON… body passes it.

Second, it decodes the digits with unary + (+match[2], +match[3]). VEREX matches [0-9a-f], as keripy's VEREX1 does, so a digit from a to f becomes NaN. versify encodes with toString(16), which means the two functions do not round-trip. The CESR stream parser added in #413 had the same digit problem and reads them as hex now.

Steps to reproduce

import { deversify, Vrsn_1_0 } from './src/keri/core/core.ts';
import { sizeify } from './src/keri/core/serder.ts';

const [, , v] = deversify('KERI1aJSON000000_');
console.log(v.minor);            // NaN, expected 10
console.log(v === Vrsn_1_0);     // true

deversify('KERI11JSON000000_');
console.log(Vrsn_1_0.minor);     // 1 — the shared default is now 1.1

sizeify({ v: 'KERI20JSON000000_', t: 'icp' });  // no error, expected "unsupported version"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions