antifraud-data-utils-ts 0.1.3 → 0.1.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/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.1.4 - 2026-10-18
8
+
9
+ - Add product-neutral DIDComm binary-attachment contracts for inline base64 and
10
+ protected `links + multihash` delivery without changing the canonical
11
+ Schema.org `DigitalDocument`/`MediaObject` business graph.
12
+ - Prove exact byte round-trip for a minimal synthetic PDF and reject empty or
13
+ incomplete attachments. No FHIR `DocumentReference` is introduced.
14
+
7
15
  ## 0.1.3 - 2026-10-17
8
16
 
9
17
  - Export one product-neutral confidential-document fixture so gateways, SDKs
package/README.md CHANGED
@@ -31,6 +31,8 @@ import {
31
31
  SchemaOrgContentIdentifierProfile,
32
32
  SchemaOrgDocumentResourceType,
33
33
  SchemaOrgQualificationClaim,
34
+ buildDidCommInlineBinaryAttachment,
35
+ buildDidCommLinkedBinaryAttachment,
34
36
  buildSchemaOrgConfidentialDocumentGraph,
35
37
  buildQualificationLedgerAnchor,
36
38
  defineProfessionalQualification,
@@ -80,6 +82,20 @@ builder verifies that the CID embeds a SHA3-384 digest matching the supplied
80
82
  digest, requires exact byte size, protected URL and media type, rejects
81
83
  duplicate resource identifiers and never accepts raw document bytes.
82
84
 
85
+ The document graph and the binary transport are deliberately separate.
86
+ Antifraud documents are always Schema.org `DigitalDocument` resources whose
87
+ concrete encodings are Schema.org `MediaObject` resources; they are never FHIR
88
+ `DocumentReference` resources. `buildDidCommInlineBinaryAttachment` carries a
89
+ bounded file as DIDComm `attachments[].data.base64`, while
90
+ `buildDidCommLinkedBinaryAttachment` carries the same governed `MediaObject`
91
+ through `attachments[].data.links` plus its multibase multihash. Both forms
92
+ preserve the Internet media type and exact byte count and work for PDF,
93
+ spreadsheet, word-processing, image, video or another governed media type.
94
+ DIDComm is the delivery transport and does not replace the Schema.org business
95
+ record or become the persistence model. See
96
+ [`docs/DIDCOMM_SCHEMA_ORG_ATTACHMENTS.md`](docs/DIDCOMM_SCHEMA_ORG_ATTACHMENTS.md)
97
+ and [GitHub issue #2](https://github.com/antifraudservices/antifraud-data-utils-ts/issues/2).
98
+
83
99
  Historical inputs may have used `identifier.additionalType` to name an
84
100
  identifier scheme. `normalizeSchemaOrgContentIdentifier` reads that legacy
85
101
  shape for migration, but canonical output uses `PropertyValue.propertyID`.
@@ -0,0 +1,36 @@
1
+ import { type SchemaOrgEvidenceMediaAttachment } from './schema-org-evidence.js';
2
+ export type DidCommInlineBinaryAttachment = Readonly<{
3
+ id: string;
4
+ media_type: string;
5
+ byte_count: number;
6
+ data: Readonly<{
7
+ base64: string;
8
+ }>;
9
+ }>;
10
+ export type DidCommLinkedBinaryAttachment = Readonly<{
11
+ id: string;
12
+ media_type: string;
13
+ byte_count: number;
14
+ data: Readonly<{
15
+ links: readonly [string];
16
+ hash: string;
17
+ }>;
18
+ }>;
19
+ export type DidCommBinaryAttachment = DidCommInlineBinaryAttachment | DidCommLinkedBinaryAttachment;
20
+ export type DidCommInlineBinaryAttachmentInput = Readonly<{
21
+ id: string;
22
+ mediaType: string;
23
+ bytes: Uint8Array;
24
+ }>;
25
+ /**
26
+ * Carries binary bytes inline in the DIDComm attachment transport layer.
27
+ * The Schema.org DigitalDocument/MediaObject graph remains the business model.
28
+ */
29
+ export declare function buildDidCommInlineBinaryAttachment(input: DidCommInlineBinaryAttachmentInput): DidCommInlineBinaryAttachment;
30
+ /**
31
+ * Projects one canonical Schema.org MediaObject encoding into a DIDComm
32
+ * attachment by reference. DIDComm carries the file; it does not replace the
33
+ * Schema.org business record or become its persistence model.
34
+ */
35
+ export declare function buildDidCommLinkedBinaryAttachment(mediaObject: SchemaOrgEvidenceMediaAttachment): DidCommLinkedBinaryAttachment;
36
+ //# sourceMappingURL=didcomm-binary-attachment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"didcomm-binary-attachment.d.ts","sourceRoot":"","sources":["../../src/identity-assurance/didcomm-binary-attachment.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,gCAAgC,EACtC,MAAM,0BAA0B,CAAA;AAEjC,MAAM,MAAM,6BAA6B,GAAG,QAAQ,CAAC;IACnD,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,QAAQ,CAAC;QACb,MAAM,EAAE,MAAM,CAAA;KACf,CAAC,CAAA;CACH,CAAC,CAAA;AAEF,MAAM,MAAM,6BAA6B,GAAG,QAAQ,CAAC;IACnD,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,QAAQ,CAAC;QACb,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAA;QACxB,IAAI,EAAE,MAAM,CAAA;KACb,CAAC,CAAA;CACH,CAAC,CAAA;AAEF,MAAM,MAAM,uBAAuB,GAC/B,6BAA6B,GAC7B,6BAA6B,CAAA;AAEjC,MAAM,MAAM,kCAAkC,GAAG,QAAQ,CAAC;IACxD,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,UAAU,CAAA;CAClB,CAAC,CAAA;AAiDF;;;GAGG;AACH,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,kCAAkC,GACxC,6BAA6B,CAe/B;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CAChD,WAAW,EAAE,gCAAgC,GAC5C,6BAA6B,CAqB/B"}
@@ -0,0 +1,92 @@
1
+ import { assertSha3_384EvidenceContentIdMatchesDigest, } from './identity-evidence.js';
2
+ import { projectEvidenceAttachmentToSchemaOrgMediaObject, } from './schema-org-evidence.js';
3
+ const BASE58BTC_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
4
+ function requireNonEmpty(value, field) {
5
+ const normalized = value.trim();
6
+ if (!normalized)
7
+ throw new TypeError(`${field} must not be empty`);
8
+ return normalized;
9
+ }
10
+ function requireMediaType(value) {
11
+ const mediaType = requireNonEmpty(value, 'DIDComm attachment mediaType');
12
+ if (!/^[^\s/]+\/[^\s/]+$/u.test(mediaType)) {
13
+ throw new TypeError('DIDComm attachment mediaType must be an Internet media type');
14
+ }
15
+ return mediaType;
16
+ }
17
+ function encodeBase64Url(bytes) {
18
+ let binary = '';
19
+ for (const byte of bytes)
20
+ binary += String.fromCharCode(byte);
21
+ return btoa(binary).replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/u, '');
22
+ }
23
+ function decodeBase64(value) {
24
+ try {
25
+ return Uint8Array.from(atob(value), character => character.charCodeAt(0));
26
+ }
27
+ catch {
28
+ throw new TypeError('Schema.org MediaObject digest must be base64 encoded');
29
+ }
30
+ }
31
+ function encodeBase58btc(bytes) {
32
+ let value = 0n;
33
+ for (const byte of bytes)
34
+ value = (value << 8n) | BigInt(byte);
35
+ let encoded = '';
36
+ while (value > 0n) {
37
+ const remainder = Number(value % 58n);
38
+ encoded = BASE58BTC_ALPHABET[remainder] + encoded;
39
+ value /= 58n;
40
+ }
41
+ for (const byte of bytes) {
42
+ if (byte !== 0)
43
+ break;
44
+ encoded = `1${encoded}`;
45
+ }
46
+ return `z${encoded}`;
47
+ }
48
+ /**
49
+ * Carries binary bytes inline in the DIDComm attachment transport layer.
50
+ * The Schema.org DigitalDocument/MediaObject graph remains the business model.
51
+ */
52
+ export function buildDidCommInlineBinaryAttachment(input) {
53
+ const id = requireNonEmpty(input.id, 'DIDComm attachment id');
54
+ const mediaType = requireMediaType(input.mediaType);
55
+ if (!(input.bytes instanceof Uint8Array) || input.bytes.byteLength === 0) {
56
+ throw new TypeError('DIDComm attachment bytes must not be empty');
57
+ }
58
+ return Object.freeze({
59
+ id,
60
+ media_type: mediaType,
61
+ byte_count: input.bytes.byteLength,
62
+ data: Object.freeze({
63
+ base64: encodeBase64Url(input.bytes),
64
+ }),
65
+ });
66
+ }
67
+ /**
68
+ * Projects one canonical Schema.org MediaObject encoding into a DIDComm
69
+ * attachment by reference. DIDComm carries the file; it does not replace the
70
+ * Schema.org business record or become its persistence model.
71
+ */
72
+ export function buildDidCommLinkedBinaryAttachment(mediaObject) {
73
+ projectEvidenceAttachmentToSchemaOrgMediaObject(mediaObject);
74
+ assertSha3_384EvidenceContentIdMatchesDigest(mediaObject.contentId, mediaObject.digest);
75
+ const digestBytes = decodeBase64(mediaObject.digest);
76
+ if (digestBytes.byteLength !== 48) {
77
+ throw new TypeError('Schema.org MediaObject SHA3-384 digest must contain 48 bytes');
78
+ }
79
+ const multihash = Uint8Array.from([0x15, 0x30, ...digestBytes]);
80
+ return Object.freeze({
81
+ id: requireNonEmpty(mediaObject.id, 'DIDComm attachment id'),
82
+ media_type: requireMediaType(mediaObject.mediaType),
83
+ byte_count: mediaObject.contentSize,
84
+ data: Object.freeze({
85
+ links: Object.freeze([
86
+ requireNonEmpty(mediaObject.contentUrl, 'DIDComm attachment contentUrl'),
87
+ ]),
88
+ hash: encodeBase58btc(multihash),
89
+ }),
90
+ });
91
+ }
92
+ //# sourceMappingURL=didcomm-binary-attachment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"didcomm-binary-attachment.js","sourceRoot":"","sources":["../../src/identity-assurance/didcomm-binary-attachment.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4CAA4C,GAC7C,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,+CAA+C,GAEhD,MAAM,0BAA0B,CAAA;AA+BjC,MAAM,kBAAkB,GAAG,4DAA4D,CAAA;AAEvF,SAAS,eAAe,CAAC,KAAa,EAAE,KAAa;IACnD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;IAC/B,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,SAAS,CAAC,GAAG,KAAK,oBAAo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AAW,CAAC,UAAU,KAAK,EAAE,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,8DAA8D,CAAC,CAAA;IACrF,CAAC;IACD,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,CAAC,CAAA;IAE/D,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,EAAE,EAAE,eAAe,CAAC,WAAW,CAAC,EAAE,EAAE,uBAAuB,CAAC;QAC5D,UAAU,EAAE,gBAAgB,CAAC,WAAW,CAAC,SAAS,CAAC;QACnD,UAAU,EAAE,WAAW,CAAC,WAAW;QACnC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;YAClB,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;gBACnB,eAAe,CAAC,WAAW,CAAC,UAAU,EAAE,+BAA+B,CAAC;aACzE,CAAsB;YACvB,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC;SACjC,CAAC;KACH,CAAC,CAAA;AACJ,CAAC"}
@@ -2,6 +2,7 @@ export * from './claim-proofs.js';
2
2
  export * from './confidential-document.js';
3
3
  export * from './converters.js';
4
4
  export * from './credential-issuance.js';
5
+ export * from './didcomm-binary-attachment.js';
5
6
  export * from './identity-evidence.js';
6
7
  export * from './professional-qualification.js';
7
8
  export * from './schema-org-evidence.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity-assurance/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,0BAA0B,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,2BAA2B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity-assurance/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,0BAA0B,CAAA;AACxC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,0BAA0B,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,2BAA2B,CAAA"}
@@ -2,6 +2,7 @@ export * from './claim-proofs.js';
2
2
  export * from './confidential-document.js';
3
3
  export * from './converters.js';
4
4
  export * from './credential-issuance.js';
5
+ export * from './didcomm-binary-attachment.js';
5
6
  export * from './identity-evidence.js';
6
7
  export * from './professional-qualification.js';
7
8
  export * from './schema-org-evidence.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity-assurance/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,0BAA0B,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,2BAA2B,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity-assurance/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,0BAA0B,CAAA;AACxC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,0BAA0B,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,2BAA2B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antifraud-data-utils-ts",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Product-neutral identity verification, evidence and attestation data contracts",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",