@owf/mdoc 0.7.0 → 0.7.1-alpha-20260804091211
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/dist/index.d.mts +1 -6
- package/dist/index.mjs +60 -56
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CborStructure, CoseKey, CoseKey as CoseKey$1, CoseKeyDecodedStructure, CoseKeyEncodedStructure, CoseKeyOptions, Curve, DataItem, DateOnly, DecodedStructureType, DigestAlgorithm, EncodedStructureType, KeyOps, KeyType, Mac0, Mac0 as Mac0$1, Mac0Context, Mac0DecodedStructure, Mac0EncodedStructure, Mac0Options, MacAlgorithm, ProtectedHeaders, ProtectedHeaders as ProtectedHeaders$1, RegisteredCwtClaimKey, RegisteredCwtClaimKey as RegisteredCwtClaimKey$1, RegisteredCwtHeaderClaimKey, Sign1, Sign1 as Sign1$1, Sign1Context, Sign1DecodedStructure, Sign1EncodedStructure, Sign1Options, SignatureAlgorithm, SignatureAlgorithm as SignatureAlgorithm$1, TypedMap, UnprotectedHeaders, cborDecode, cborEncode } from "@owf/cose";
|
|
2
2
|
import { StatusListCwt, StatusListInfo, StatusListInfo as StatusListInfo$1, StatusListInfoOptions } from "@owf/token-status-list";
|
|
3
3
|
import z, { z as z$1 } from "zod";
|
|
4
|
-
|
|
5
4
|
//#region src/context.d.ts
|
|
6
5
|
type MaybePromise<T> = Promise<T> | T;
|
|
7
6
|
interface MdocContext {
|
|
@@ -971,11 +970,7 @@ declare class IssuerAuth extends Sign1$1 {
|
|
|
971
970
|
*
|
|
972
971
|
* @todo return the full verified chain for audit / compliance.
|
|
973
972
|
*/
|
|
974
|
-
verifyStatus({
|
|
975
|
-
now,
|
|
976
|
-
checkFreshness,
|
|
977
|
-
trustedStatusCertificates
|
|
978
|
-
}: {
|
|
973
|
+
verifyStatus({ now, checkFreshness, trustedStatusCertificates }: {
|
|
979
974
|
now?: Date;
|
|
980
975
|
checkFreshness?: boolean;
|
|
981
976
|
trustedStatusCertificates?: Uint8Array[];
|
package/dist/index.mjs
CHANGED
|
@@ -1111,7 +1111,8 @@ var DeviceAuth = class extends CborStructure {
|
|
|
1111
1111
|
return this.structure.get("deviceMac");
|
|
1112
1112
|
}
|
|
1113
1113
|
async verify(options, ctx) {
|
|
1114
|
-
const
|
|
1114
|
+
const verificationCallback = options.verificationCallback ?? defaultVerificationCallback;
|
|
1115
|
+
const onCheck = onCategoryCheck(verificationCallback, "DEVICE_AUTH");
|
|
1115
1116
|
const { deviceKey } = options.document.issuerSigned.issuerAuth.mobileSecurityObject.deviceKeyInfo;
|
|
1116
1117
|
const deviceMac = this.structure.get("deviceMac");
|
|
1117
1118
|
const deviceSignature = this.structure.get("deviceSignature");
|
|
@@ -1335,7 +1336,8 @@ var ReaderAuthentication = class extends CborStructure {
|
|
|
1335
1336
|
var ReaderAuth = class extends Sign1$1 {
|
|
1336
1337
|
async verify(options, ctx) {
|
|
1337
1338
|
const readerAuthentication = options.readerAuthentication instanceof ReaderAuthentication ? options.readerAuthentication : new ReaderAuthentication(options.readerAuthentication);
|
|
1338
|
-
const
|
|
1339
|
+
const verificationCallback = options.verificationCallback ?? defaultVerificationCallback;
|
|
1340
|
+
const onCheck = onCategoryCheck(verificationCallback, "READER_AUTH");
|
|
1339
1341
|
onCheck({
|
|
1340
1342
|
status: await this.verifySignature({
|
|
1341
1343
|
key: await ctx.x509.getPublicKey({
|
|
@@ -1743,7 +1745,8 @@ var IdentifierListCwt = class IdentifierListCwt {
|
|
|
1743
1745
|
if (!cwt.payload) throw new Error("IdentifierList CWT has no payload");
|
|
1744
1746
|
const decoded = cborDecode$1(cwt.payload, { unwrapTopLevelDataItem: false });
|
|
1745
1747
|
if (decoded.has(StatusListCwtClaimKey.StatusList)) throw new Error("IdentifierList CWT must not contain a StatusList claim (ISO 18013-5 § 12.3.6.4)");
|
|
1746
|
-
|
|
1748
|
+
const payload = IdentifierListCwtPayload.fromEncodedStructure(decoded);
|
|
1749
|
+
return new IdentifierListCwt(cwt, payload);
|
|
1747
1750
|
}
|
|
1748
1751
|
static async fetch(uri, ctx) {
|
|
1749
1752
|
const response = await (ctx.fetch ?? fetch)(uri, { headers: { Accept: "application/identifierlist+cwt" } });
|
|
@@ -2485,62 +2488,63 @@ var DeviceResponse = class DeviceResponse extends CborStructure {
|
|
|
2485
2488
|
if (useMac === useSignature) throw new EitherSignatureOrMacMustBeProvidedError();
|
|
2486
2489
|
const signingKey = useSignature ? options.signature?.signingKey : options.mac?.signingKey;
|
|
2487
2490
|
if (!signingKey) throw new Error("Signing key is missing");
|
|
2488
|
-
const
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2491
|
+
const documents = await Promise.all(options.deviceRequest.docRequests.map(async (docRequest) => {
|
|
2492
|
+
const issuerSigned = findIssuerSigned(options.issuerSigned, docRequest.itemsRequest.docType);
|
|
2493
|
+
const disclosedIssuerNamespace = limitDisclosureToDeviceRequestNameSpaces(issuerSigned, docRequest);
|
|
2494
|
+
const docType = docRequest.itemsRequest.docType;
|
|
2495
|
+
const deviceNamespaces = options.deviceNamespaces ?? DeviceNamespaces.create({ deviceNamespaces: /* @__PURE__ */ new Map() });
|
|
2496
|
+
const deviceAuthenticationBytes = DeviceAuthentication.create({
|
|
2497
|
+
sessionTranscript: options.sessionTranscript,
|
|
2498
|
+
docType,
|
|
2499
|
+
deviceNamespaces
|
|
2500
|
+
}).encode({ asDataItem: true });
|
|
2501
|
+
const unprotectedHeaders = UnprotectedHeaders$1.create({});
|
|
2502
|
+
if (signingKey.keyId) unprotectedHeaders.headers?.set(RegisteredCwtHeaderClaimKey$1.KeyId, stringToBytes(signingKey.keyId));
|
|
2503
|
+
const protectedHeaders = ProtectedHeaders$1.create({ protectedHeaders: /* @__PURE__ */ new Map([[RegisteredCwtHeaderClaimKey$1.Algorithm, signingKey.algorithm]]) });
|
|
2504
|
+
const deviceAuthOptions = {};
|
|
2505
|
+
if (useSignature) deviceAuthOptions.deviceSignature = await DeviceSignature.create({
|
|
2506
|
+
unprotectedHeaders,
|
|
2507
|
+
protectedHeaders,
|
|
2508
|
+
payload: null
|
|
2509
|
+
}).sign({
|
|
2510
|
+
signingKey,
|
|
2511
|
+
detachedPayload: deviceAuthenticationBytes
|
|
2512
|
+
}, { sign: ctx.cose.sign1.sign });
|
|
2513
|
+
else {
|
|
2514
|
+
const ephemeralKey = options.mac?.ephemeralKey;
|
|
2515
|
+
if (!ephemeralKey) throw new Error("Ephemeral key is missing");
|
|
2516
|
+
const deviceMac = DeviceMac.create({
|
|
2507
2517
|
protectedHeaders,
|
|
2518
|
+
unprotectedHeaders,
|
|
2508
2519
|
payload: null
|
|
2509
|
-
}).sign({
|
|
2510
|
-
signingKey,
|
|
2511
|
-
detachedPayload: deviceAuthenticationBytes
|
|
2512
|
-
}, { sign: ctx.cose.sign1.sign });
|
|
2513
|
-
else {
|
|
2514
|
-
const ephemeralKey = options.mac?.ephemeralKey;
|
|
2515
|
-
if (!ephemeralKey) throw new Error("Ephemeral key is missing");
|
|
2516
|
-
const deviceMac = DeviceMac.create({
|
|
2517
|
-
protectedHeaders,
|
|
2518
|
-
unprotectedHeaders,
|
|
2519
|
-
payload: null
|
|
2520
|
-
});
|
|
2521
|
-
const macKey = await deviceMac.createDeviceMacKey({
|
|
2522
|
-
publicKey: ephemeralKey,
|
|
2523
|
-
privateKey: signingKey,
|
|
2524
|
-
sessionTranscript: options.sessionTranscript
|
|
2525
|
-
}, ctx);
|
|
2526
|
-
await deviceMac.authenticate({
|
|
2527
|
-
key: macKey,
|
|
2528
|
-
detachedPayload: deviceAuthenticationBytes
|
|
2529
|
-
}, ctx.cose.mac0);
|
|
2530
|
-
deviceAuthOptions.deviceMac = deviceMac;
|
|
2531
|
-
}
|
|
2532
|
-
return Document.create({
|
|
2533
|
-
docType,
|
|
2534
|
-
issuerSigned: IssuerSigned.create({
|
|
2535
|
-
issuerNamespaces: disclosedIssuerNamespace,
|
|
2536
|
-
issuerAuth: issuerSigned.issuerAuth
|
|
2537
|
-
}),
|
|
2538
|
-
deviceSigned: DeviceSigned.create({
|
|
2539
|
-
deviceNamespaces,
|
|
2540
|
-
deviceAuth: DeviceAuth.create(deviceAuthOptions)
|
|
2541
|
-
})
|
|
2542
2520
|
});
|
|
2543
|
-
|
|
2521
|
+
const macKey = await deviceMac.createDeviceMacKey({
|
|
2522
|
+
publicKey: ephemeralKey,
|
|
2523
|
+
privateKey: signingKey,
|
|
2524
|
+
sessionTranscript: options.sessionTranscript
|
|
2525
|
+
}, ctx);
|
|
2526
|
+
await deviceMac.authenticate({
|
|
2527
|
+
key: macKey,
|
|
2528
|
+
detachedPayload: deviceAuthenticationBytes
|
|
2529
|
+
}, ctx.cose.mac0);
|
|
2530
|
+
deviceAuthOptions.deviceMac = deviceMac;
|
|
2531
|
+
}
|
|
2532
|
+
return Document.create({
|
|
2533
|
+
docType,
|
|
2534
|
+
issuerSigned: IssuerSigned.create({
|
|
2535
|
+
issuerNamespaces: disclosedIssuerNamespace,
|
|
2536
|
+
issuerAuth: issuerSigned.issuerAuth
|
|
2537
|
+
}),
|
|
2538
|
+
deviceSigned: DeviceSigned.create({
|
|
2539
|
+
deviceNamespaces,
|
|
2540
|
+
deviceAuth: DeviceAuth.create(deviceAuthOptions)
|
|
2541
|
+
})
|
|
2542
|
+
});
|
|
2543
|
+
}));
|
|
2544
|
+
const map = new TypedMap([
|
|
2545
|
+
["version", "1.0"],
|
|
2546
|
+
["status", 0],
|
|
2547
|
+
["documents", documents]
|
|
2544
2548
|
]);
|
|
2545
2549
|
return DeviceResponse.fromDecodedStructure(map);
|
|
2546
2550
|
}
|