@smartledger/bsv 9.1.1 → 9.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/bsv.d.ts CHANGED
@@ -1421,12 +1421,62 @@ declare module '@smartledger/bsv' {
1421
1421
  export function getClaimSchemaNames(): string[];
1422
1422
  export function getClaimSchema(schemaName: string): object;
1423
1423
  export function createClaimTemplate(schemaName: string): object;
1424
- /** Returns the canonical JSON STRING, not an object. */
1425
- export function canonicalizeClaim(claim: object): string;
1426
- export function hashClaim(claim: object): string;
1424
+ /**
1425
+ * Returns the canonical JSON STRING, not an object.
1426
+ *
1427
+ * Omitting `canonicalization` selects the legacy sorted-key form and emits a
1428
+ * deprecation notice; the default becomes `'jcs'` in 10.0.0. Pass one explicitly
1429
+ * to pin the behaviour across that change.
1430
+ *
1431
+ * For anything that is not an existing LTP claim, use `@smartledger/bsv/jcs`
1432
+ * directly — it is RFC 8785 and has no legacy mode.
1433
+ */
1434
+ export function canonicalizeClaim(claim: object, canonicalization?: JcsCanonicalization): string;
1435
+ export function hashClaim(claim: object, canonicalization?: JcsCanonicalization): string;
1427
1436
  export function addCustomClaimSchema(name: string, schema: object): void;
1428
1437
 
1438
+ /** Canonicalization forms understood by the LTP claim hashers. */
1439
+ export type JcsCanonicalization = 'jcs' | 'legacy';
1440
+
1441
+ /**
1442
+ * RFC 8785 JSON Canonicalization Scheme. Also available as the subpath export
1443
+ * `@smartledger/bsv/jcs`, which is the form to prefer in new code.
1444
+ */
1445
+ export namespace JCS {
1446
+ /**
1447
+ * Serialize a value as RFC 8785 canonical JSON.
1448
+ *
1449
+ * Throws on non-finite numbers, bigint, circular structures, and values with
1450
+ * no JSON representation, rather than coercing them — a canonicalizer that
1451
+ * silently serializes a different document than the one supplied defeats its
1452
+ * own purpose.
1453
+ */
1454
+ function stringify(value: any): string;
1455
+ }
1456
+
1429
1457
  // Shamir convenience wrappers (also available on bsv.Shamir directly)
1430
1458
  // Shamir secret sharing is exposed as `bsv.Shamir.split` / `.combine` / `.verifyShare`
1431
1459
  // (see `crypto.Shamir` above) — there are no top-level splitSecret/reconstructSecret helpers.
1460
+ }
1461
+
1462
+ /**
1463
+ * RFC 8785 (JSON Canonicalization Scheme).
1464
+ *
1465
+ * Two independent implementations produce identical bytes for the same value, which
1466
+ * is the property that makes a hash or a signature meaningful to a party who did not
1467
+ * produce it. Prefer this over `bsv.canonicalizeClaim` in new code: that one carries
1468
+ * a legacy mode this does not.
1469
+ */
1470
+ declare module '@smartledger/bsv/jcs' {
1471
+ /**
1472
+ * Serialize a value as RFC 8785 canonical JSON.
1473
+ *
1474
+ * Object keys sort by UTF-16 code unit, applied during serialization rather than
1475
+ * by rebuilding an object — rebuilding lets V8 reorder integer-like keys ahead of
1476
+ * the sort, producing `{"2":…,"10":…}` where the RFC requires `{"10":…,"2":…}`.
1477
+ *
1478
+ * Throws on non-finite numbers, bigint, circular structures, and values with no
1479
+ * JSON representation.
1480
+ */
1481
+ export function stringify(value: any): string;
1432
1482
  }