You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: deversify mutates Vrsn_1_0 and misreads hex version digits #423
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 10console.log(v===Vrsn_1_0);// truedeversify('KERI11JSON000000_');console.log(Vrsn_1_0.minor);// 1 — the shared default is now 1.1sizeify({v: 'KERI20JSON000000_',t: 'icp'});// no error, expected "unsupported version"
Activity