@zanii/core 0.5.3 → 0.5.4

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/README.md CHANGED
@@ -61,6 +61,7 @@ revocations, and on-chain anchor consistency.
61
61
 
62
62
  ## Changelog
63
63
 
64
+ - **0.5.4** — `signObject` / `verifySignedObject`: sign any statement as a did:key over its RFC 8785 bytes (used by the domain packages for device readings, reports and attestations).
64
65
  - **0.5.3** — protocol 1.3: `payloadBytes` encodes non-integer numbers as RFC 8785 specifies instead of refusing them; whole numbers beyond ±(2^53−1) stay refused.
65
66
  - **0.5.2** — optional `risk` level on receipts (`RISK_LEVELS`, `isRiskLevel`); session-close receipts (`SESSION_CLOSE_TARGET`, `isSessionClose`) reported by `verifyAuditBundle`; swarm receipt verification moved here so an honest swarm co-signer's audit bundle verifies; integers beyond ±(2^53−1) refused in payloads (protocol 1.2).
66
67
  - **0.4.0** — optional signature-covered `subject_tag` receipt field (per-subject auditability, `@zanii/subject`).
package/dist/index.d.ts CHANGED
@@ -9,4 +9,5 @@ export { createReceipt, receiptHash, hashPayload, payloadBytes, saltedPayloadHas
9
9
  export { createConfirmation, verifyConfirmation, type ActionConfirmation, } from './confirmation.js';
10
10
  export { createCoSignature, verifyCoSignature, type ReceiptCoSignature, } from './cosign.js';
11
11
  export { verifySwarmReceipt, type SwarmBody, type SwarmLedgerReceipt, type SwarmSignerEnvelope } from './swarm.js';
12
+ export { signObject, verifySignedObject, type SignedObject } from './signed.js';
12
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EACL,UAAU,EACV,QAA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AAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EACL,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,WAAW,EACX,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,WAAW,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,QAAQ,EACR,UAAU,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,QAAQ,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,aAAa,EACb,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,OAAO,EACZ,KAAK,YAAY,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,KAAK,kBAAkB,EAAE,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACnH,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -9,4 +9,5 @@ export { createReceipt, receiptHash, hashPayload, payloadBytes, saltedPayloadHas
9
9
  export { createConfirmation, verifyConfirmation, } from './confirmation.js';
10
10
  export { createCoSignature, verifyCoSignature, } from './cosign.js';
11
11
  export { verifySwarmReceipt } from './swarm.js';
12
+ export { signObject, verifySignedObject } from './signed.js';
12
13
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAgB,MAAM,WAAW,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EACL,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,WAAW,GAIZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,QAAQ,EACR,UAAU,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAuB,MAAM,UAAU,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,OAAO,GAIR,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,iBAAiB,GAOlB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,WAAW,EAGX,aAAa,EACb,sBAAsB,EACtB,kBAAkB,GAGnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAEnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAElB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAqE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAgB,MAAM,WAAW,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EACL,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,WAAW,GAIZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,QAAQ,EACR,UAAU,EACV,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAuB,MAAM,UAAU,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,cAAc,EACd,OAAO,GAIR,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,iBAAiB,GAOlB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,aAAa,EACb,WAAW,EACX,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,WAAW,EAGX,aAAa,EACb,sBAAsB,EACtB,kBAAkB,GAGnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAEnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,GAElB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAqE,MAAM,YAAY,CAAC;AACnH,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAqB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A signed statement of any shape: the `signer` (a did:key) signs the RFC 8785 bytes of
3
+ * the object without `sig`. The building block domain packages use for device readings,
4
+ * attestations, reports and the like, so each does not re-implement it.
5
+ */
6
+ export type SignedObject<T extends object> = T & {
7
+ signer: string;
8
+ sig: string;
9
+ };
10
+ /** Sign `obj` as `signer`. The key must belong to the signer's did:key. */
11
+ export declare function signObject<T extends object>(obj: T, privateKey: Uint8Array): SignedObject<T>;
12
+ /** Was this object signed by its `signer`, unchanged since? Never throws. */
13
+ export declare function verifySignedObject(obj: unknown): boolean;
14
+ //# sourceMappingURL=signed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signed.d.ts","sourceRoot":"","sources":["../src/signed.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,GAAG,YAAY,CAAC,CAAC,CAAC,CAK5F;AAED,6EAA6E;AAC7E,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAUxD"}
package/dist/signed.js ADDED
@@ -0,0 +1,26 @@
1
+ import { ed25519 } from '@noble/curves/ed25519';
2
+ import { canonicalBytes, decodeSig, encodeSig } from './encoding.js';
3
+ import { didFromPublicKey, publicKeyFromDid } from './keys.js';
4
+ /** Sign `obj` as `signer`. The key must belong to the signer's did:key. */
5
+ export function signObject(obj, privateKey) {
6
+ if ('sig' in obj)
7
+ throw new Error('signObject: the object already carries a sig');
8
+ const signer = didFromPublicKey(ed25519.getPublicKey(privateKey));
9
+ const unsigned = { ...obj, signer };
10
+ return { ...unsigned, sig: encodeSig(ed25519.sign(canonicalBytes(unsigned), privateKey)) };
11
+ }
12
+ /** Was this object signed by its `signer`, unchanged since? Never throws. */
13
+ export function verifySignedObject(obj) {
14
+ try {
15
+ if (!obj || typeof obj !== 'object')
16
+ return false;
17
+ const { sig, ...unsigned } = obj;
18
+ const pub = typeof unsigned.signer === 'string' ? publicKeyFromDid(unsigned.signer) : null;
19
+ const s = typeof sig === 'string' ? decodeSig(sig) : null;
20
+ return !!pub && !!s && ed25519.verify(s, canonicalBytes(unsigned), pub);
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
26
+ //# sourceMappingURL=signed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signed.js","sourceRoot":"","sources":["../src/signed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAS/D,2EAA2E;AAC3E,MAAM,UAAU,UAAU,CAAmB,GAAM,EAAE,UAAsB;IACzE,IAAI,KAAK,IAAI,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC;IAClE,MAAM,QAAQ,GAAG,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,CAAC;IACpC,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAG,EAAE,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC;AAC7F,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC7C,IAAI,CAAC;QACH,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAClD,MAAM,EAAE,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,GAA8B,CAAC;QAC5D,MAAM,GAAG,GAAG,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC3F,MAAM,CAAC,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1D,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;IAC1E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zanii/core",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Zanii protocol: verifiable identity, signed action receipts, Merkle transparency-log proofs. Pure, no I/O.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://ledger.zanii.agency",
package/src/index.ts CHANGED
@@ -75,3 +75,4 @@ export {
75
75
  type ReceiptCoSignature,
76
76
  } from './cosign.js';
77
77
  export { verifySwarmReceipt, type SwarmBody, type SwarmLedgerReceipt, type SwarmSignerEnvelope } from './swarm.js';
78
+ export { signObject, verifySignedObject, type SignedObject } from './signed.js';
package/src/signed.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { ed25519 } from '@noble/curves/ed25519';
2
+ import { canonicalBytes, decodeSig, encodeSig } from './encoding.js';
3
+ import { didFromPublicKey, publicKeyFromDid } from './keys.js';
4
+
5
+ /**
6
+ * A signed statement of any shape: the `signer` (a did:key) signs the RFC 8785 bytes of
7
+ * the object without `sig`. The building block domain packages use for device readings,
8
+ * attestations, reports and the like, so each does not re-implement it.
9
+ */
10
+ export type SignedObject<T extends object> = T & { signer: string; sig: string };
11
+
12
+ /** Sign `obj` as `signer`. The key must belong to the signer's did:key. */
13
+ export function signObject<T extends object>(obj: T, privateKey: Uint8Array): SignedObject<T> {
14
+ if ('sig' in obj) throw new Error('signObject: the object already carries a sig');
15
+ const signer = didFromPublicKey(ed25519.getPublicKey(privateKey));
16
+ const unsigned = { ...obj, signer };
17
+ return { ...unsigned, sig: encodeSig(ed25519.sign(canonicalBytes(unsigned), privateKey)) };
18
+ }
19
+
20
+ /** Was this object signed by its `signer`, unchanged since? Never throws. */
21
+ export function verifySignedObject(obj: unknown): boolean {
22
+ try {
23
+ if (!obj || typeof obj !== 'object') return false;
24
+ const { sig, ...unsigned } = obj as Record<string, unknown>;
25
+ const pub = typeof unsigned.signer === 'string' ? publicKeyFromDid(unsigned.signer) : null;
26
+ const s = typeof sig === 'string' ? decodeSig(sig) : null;
27
+ return !!pub && !!s && ed25519.verify(s, canonicalBytes(unsigned), pub);
28
+ } catch {
29
+ return false;
30
+ }
31
+ }