cesr-ts 0.8.0 → 0.9.1

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.
@@ -1,5 +1,6 @@
1
- import { b, b64ToInt, codeB2ToB64, codeB64ToB2, intToB64, nabSextets, sceil } from "../core/bytes.js";
1
+ import { b, b64ToInt, codeB2ToB64, codeB64ToB2, concatBytes, intToB64, nabSextets, sceil } from "../core/bytes.js";
2
2
  import { DeserializeError, ShortageError, UnknownCodeError } from "../core/errors.js";
3
+ import { CtrDexV2 } from "../tables/counter-codex.js";
3
4
  import { resolveCounterCodeNameTable, resolveCounterSizeTable } from "../tables/counter-version-registry.js";
4
5
  import { COUNTER_HARDS } from "../tables/counter.tables.generated.js";
5
6
  const COUNTER_BARDS = new Map([...COUNTER_HARDS.entries()].map(([code, hs]) => [
@@ -126,6 +127,38 @@ function encodeCounterFromFields(code, count, version) {
126
127
  version,
127
128
  };
128
129
  }
130
+ function semanticNameForCode(code, version) {
131
+ const nameTable = resolveCounterCodeNameTable(version);
132
+ return nameTable[code] ?? null;
133
+ }
134
+ function codeForSemanticName(name, version) {
135
+ const nameTable = resolveCounterCodeNameTable(version);
136
+ for (const [code, candidate] of Object.entries(nameTable)) {
137
+ if (candidate === name) {
138
+ return code;
139
+ }
140
+ }
141
+ return null;
142
+ }
143
+ function promoteCounterCodeForCount(code, count, version) {
144
+ const sizeTable = resolveCounterSizeTable(version);
145
+ const sizage = sizeTable.get(code);
146
+ if (!sizage) {
147
+ throw new UnknownCodeError(`Unsupported counter code for version: ${code}`);
148
+ }
149
+ if (count <= (64 ** sizage.ss) - 1) {
150
+ return code;
151
+ }
152
+ const name = semanticNameForCode(code, version);
153
+ if (!name || name.startsWith("Big")) {
154
+ throw new DeserializeError(`Invalid count=${count} for code=${code}`);
155
+ }
156
+ const bigCode = codeForSemanticName(`Big${name}`, version);
157
+ if (!bigCode) {
158
+ throw new DeserializeError(`Counter code=${code} has no Big${name} form.`);
159
+ }
160
+ return bigCode;
161
+ }
129
162
  /** Normalize the supported constructor variants into one shared counter payload. */
130
163
  function parseCounterInit(init) {
131
164
  const version = init.version ?? { major: 2, minor: 0 };
@@ -152,6 +185,34 @@ function parseCounterInit(init) {
152
185
  * payload groups and carry versioned code-name semantics.
153
186
  */
154
187
  export class Counter {
188
+ static makeGVC(version) {
189
+ return new Counter({
190
+ code: CtrDexV2.KERIACDCGenusVersion,
191
+ countB64: `${intToB64(version.major, 1)}${intToB64(version.minor, 2)}`,
192
+ version,
193
+ }).qb64b;
194
+ }
195
+ static enclose({ qb64 = undefined, qb2 = undefined, code = "AttachmentGroup", version = { major: 2, minor: 0 }, } = {}) {
196
+ const actualQb64 = typeof qb64 === "string" ? b(qb64) : qb64;
197
+ if (actualQb64 !== undefined && actualQb64 !== null) {
198
+ if (actualQb64.length % 4 !== 0) {
199
+ throw new DeserializeError(`Bad enclosed qb64 length=${actualQb64.length}`);
200
+ }
201
+ const count = actualQb64.length / 4;
202
+ const counterCode = promoteCounterCodeForCount(codeForSemanticName(code, version) ?? code, count, version);
203
+ return concatBytes(new Counter({ code: counterCode, count, version }).qb64b, actualQb64);
204
+ }
205
+ if (qb2 !== undefined && qb2 !== null) {
206
+ if (qb2.length % 3 !== 0) {
207
+ throw new DeserializeError(`Bad enclosed qb2 length=${qb2.length}`);
208
+ }
209
+ const count = qb2.length / 3;
210
+ const counterCode = promoteCounterCodeForCount(codeForSemanticName(code, version) ?? code, count, version);
211
+ return concatBytes(new Counter({ code: counterCode, count, version }).qb2, qb2);
212
+ }
213
+ const counterCode = promoteCounterCodeForCount(codeForSemanticName(code, version) ?? code, 0, version);
214
+ return new Counter({ code: counterCode, count: 0, version }).qb64b;
215
+ }
155
216
  constructor(init) {
156
217
  Object.defineProperty(this, "_code", {
157
218
  enumerable: true,
@@ -195,11 +256,7 @@ export class Counter {
195
256
  writable: true,
196
257
  value: void 0
197
258
  });
198
- const data = init instanceof Counter
199
- ? init.toCounterData()
200
- : isCounterData(init)
201
- ? init
202
- : parseCounterInit(init);
259
+ const data = init instanceof Counter ? init.toCounterData() : isCounterData(init) ? init : parseCounterInit(init);
203
260
  this._code = data.code;
204
261
  this._count = data.count;
205
262
  this._fullSize = data.fullSize;
@@ -287,7 +344,5 @@ export function parseCounterFromBinary(input, version) {
287
344
  }
288
345
  /** Parse counter using domain hint (`txt` or `bny`) and versioned codex tables. */
289
346
  export function parseCounter(input, version, cold) {
290
- return cold === "bny"
291
- ? parseCounterFromBinary(input, version)
292
- : parseCounterFromText(input, version);
347
+ return cold === "bny" ? parseCounterFromBinary(input, version) : parseCounterFromText(input, version);
293
348
  }
@@ -6,9 +6,9 @@
6
6
  * `src/version.ts` files by hand; edit this template instead.
7
7
  */
8
8
  /** Package semantic version copied from the owning package manifest. */
9
- export const PACKAGE_VERSION = "0.8.0";
9
+ export const PACKAGE_VERSION = "0.9.1";
10
10
  /** Optional build metadata stamp injected by release/CI workflows. */
11
- export const BUILD_METADATA = "build.8.5884299463b061ec0fe2847a35a28b4189dee3f8";
11
+ export const BUILD_METADATA = "build.12.8e87c5ce81dece1fb6ce6abbe904707a36a6b012";
12
12
  /** User-facing version string with build metadata appended when present. */
13
13
  export const DISPLAY_VERSION = BUILD_METADATA
14
14
  ? `${PACKAGE_VERSION}+${BUILD_METADATA}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cesr-ts",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "CESR parser, primitives, and annotation tooling for TypeScript/JavaScript",
5
5
  "homepage": "https://github.com/kentbull/keri-ts/tree/main/packages/cesr",
6
6
  "repository": {
@@ -45,7 +45,7 @@
45
45
  "@noble/hashes": "1.8.0",
46
46
  "cbor-x": "^1.6.0",
47
47
  "effection": "^3.6.0",
48
- "libsodium-wrappers": "^0.8.2"
48
+ "libsodium-wrappers": "0.8.4"
49
49
  },
50
50
  "_generatedBy": "dnt@dev"
51
51
  }
@@ -16,6 +16,12 @@ export interface CounterInit {
16
16
  qb2?: Uint8Array;
17
17
  version?: Versionage;
18
18
  }
19
+ export interface CounterEncloseInit {
20
+ qb64?: Uint8Array | string | null;
21
+ qb2?: Uint8Array | null;
22
+ code?: string;
23
+ version?: Versionage;
24
+ }
19
25
  interface CounterData {
20
26
  code: string;
21
27
  count: number;
@@ -39,6 +45,8 @@ export declare class Counter {
39
45
  protected readonly _qb64: string;
40
46
  protected readonly _name: string;
41
47
  protected readonly _version: Versionage;
48
+ static makeGVC(version: Versionage): Uint8Array;
49
+ static enclose({ qb64, qb2, code, version, }?: CounterEncloseInit): Uint8Array;
42
50
  constructor(init: Counter | CounterData | CounterInit);
43
51
  protected toCounterData(): CounterData;
44
52
  get code(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../../../src/src/primitives/counter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB;AAED,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,UAAU,CAAC;CACrB;AA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,YAAa,SAAQ,OAAO;IACvC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;gBAE1B,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,UAAU,EAAE;CAK5E;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,UAAU,GAClB,OAAO,CAET;AAED,kFAAkF;AAClF,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,UAAU,GAClB,OAAO,CAET;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAC1B,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC,GACrC,OAAO,CAET"}
@@ -6,9 +6,9 @@
6
6
  * `src/version.ts` files by hand; edit this template instead.
7
7
  */
8
8
  /** Package semantic version copied from the owning package manifest. */
9
- export declare const PACKAGE_VERSION = "0.8.0";
9
+ export declare const PACKAGE_VERSION = "0.9.1";
10
10
  /** Optional build metadata stamp injected by release/CI workflows. */
11
- export declare const BUILD_METADATA = "build.8.5884299463b061ec0fe2847a35a28b4189dee3f8";
11
+ export declare const BUILD_METADATA = "build.12.8e87c5ce81dece1fb6ce6abbe904707a36a6b012";
12
12
  /** User-facing version string with build metadata appended when present. */
13
13
  export declare const DISPLAY_VERSION: string;
14
14
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/src/version.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wEAAwE;AACxE,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,sEAAsE;AACtE,eAAO,MAAM,cAAc,qDAAqD,CAAC;AACjF,4EAA4E;AAC5E,eAAO,MAAM,eAAe,QAET,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/src/version.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wEAAwE;AACxE,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,sEAAsE;AACtE,eAAO,MAAM,cAAc,sDAAsD,CAAC;AAClF,4EAA4E;AAC5E,eAAO,MAAM,eAAe,QAET,CAAC"}