@covia/covia-sdk 1.19.0 → 1.19.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.
- package/dist/index.js +20 -2
- package/dist/index.mjs +20 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3661,6 +3661,21 @@ function asCoviaError(error) {
|
|
|
3661
3661
|
const message = error instanceof Error ? error.message : String(error);
|
|
3662
3662
|
return new CoviaError(message);
|
|
3663
3663
|
}
|
|
3664
|
+
function canonicalDidFromDocument(didDoc) {
|
|
3665
|
+
const akas = didDoc.alsoKnownAs;
|
|
3666
|
+
if (Array.isArray(akas)) {
|
|
3667
|
+
const keyDid = akas.find((a) => typeof a === "string" && a.startsWith("did:key:"));
|
|
3668
|
+
if (keyDid) return keyDid;
|
|
3669
|
+
}
|
|
3670
|
+
const methods = didDoc.verificationMethod;
|
|
3671
|
+
if (Array.isArray(methods)) {
|
|
3672
|
+
for (const method of methods) {
|
|
3673
|
+
const multibase = method?.publicKeyMultibase;
|
|
3674
|
+
if (typeof multibase === "string" && multibase.length > 0) return `did:key:${multibase}`;
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
return void 0;
|
|
3678
|
+
}
|
|
3664
3679
|
function assertVenueIdentity(expectedDid, actualDid, baseUrl) {
|
|
3665
3680
|
if (expectedDid && actualDid && expectedDid !== actualDid) {
|
|
3666
3681
|
throw new VenueIdentityChangedError(expectedDid, actualDid, baseUrl);
|
|
@@ -3787,12 +3802,14 @@ var Venue = class _Venue {
|
|
|
3787
3802
|
if (typeof venueId === "string") {
|
|
3788
3803
|
let candidates;
|
|
3789
3804
|
let expectedDid;
|
|
3805
|
+
let requestedWebDid;
|
|
3790
3806
|
if (venueId.startsWith("did:web:")) {
|
|
3791
|
-
expectedDid = venueId;
|
|
3792
3807
|
const didDoc = await resolver.resolve(venueId);
|
|
3793
3808
|
if (!didDoc.didDocument) {
|
|
3794
3809
|
throw new CoviaError("Invalid DID document");
|
|
3795
3810
|
}
|
|
3811
|
+
expectedDid = canonicalDidFromDocument(didDoc.didDocument);
|
|
3812
|
+
requestedWebDid = venueId;
|
|
3796
3813
|
const endpoint = didDoc.didDocument.service?.find((service) => service.type === "Covia.API.v1")?.serviceEndpoint;
|
|
3797
3814
|
if (typeof endpoint !== "string") {
|
|
3798
3815
|
throw new CoviaError("No (string) endpoint found for DID");
|
|
@@ -3813,7 +3830,8 @@ var Venue = class _Venue {
|
|
|
3813
3830
|
if (!data.did) {
|
|
3814
3831
|
throw new CoviaError(`Venue status at ${statusUrl} did not include a DID`);
|
|
3815
3832
|
}
|
|
3816
|
-
|
|
3833
|
+
const required = expectedDid ?? (data.did.startsWith("did:web:") ? requestedWebDid : void 0);
|
|
3834
|
+
assertVenueIdentity(required, data.did, baseUrl);
|
|
3817
3835
|
return new _Venue({
|
|
3818
3836
|
baseUrl,
|
|
3819
3837
|
venueId: data.did,
|
package/dist/index.mjs
CHANGED
|
@@ -3659,6 +3659,21 @@ function asCoviaError(error) {
|
|
|
3659
3659
|
const message = error instanceof Error ? error.message : String(error);
|
|
3660
3660
|
return new CoviaError(message);
|
|
3661
3661
|
}
|
|
3662
|
+
function canonicalDidFromDocument(didDoc) {
|
|
3663
|
+
const akas = didDoc.alsoKnownAs;
|
|
3664
|
+
if (Array.isArray(akas)) {
|
|
3665
|
+
const keyDid = akas.find((a) => typeof a === "string" && a.startsWith("did:key:"));
|
|
3666
|
+
if (keyDid) return keyDid;
|
|
3667
|
+
}
|
|
3668
|
+
const methods = didDoc.verificationMethod;
|
|
3669
|
+
if (Array.isArray(methods)) {
|
|
3670
|
+
for (const method of methods) {
|
|
3671
|
+
const multibase = method?.publicKeyMultibase;
|
|
3672
|
+
if (typeof multibase === "string" && multibase.length > 0) return `did:key:${multibase}`;
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
return void 0;
|
|
3676
|
+
}
|
|
3662
3677
|
function assertVenueIdentity(expectedDid, actualDid, baseUrl) {
|
|
3663
3678
|
if (expectedDid && actualDid && expectedDid !== actualDid) {
|
|
3664
3679
|
throw new VenueIdentityChangedError(expectedDid, actualDid, baseUrl);
|
|
@@ -3785,12 +3800,14 @@ var Venue = class _Venue {
|
|
|
3785
3800
|
if (typeof venueId === "string") {
|
|
3786
3801
|
let candidates;
|
|
3787
3802
|
let expectedDid;
|
|
3803
|
+
let requestedWebDid;
|
|
3788
3804
|
if (venueId.startsWith("did:web:")) {
|
|
3789
|
-
expectedDid = venueId;
|
|
3790
3805
|
const didDoc = await resolver.resolve(venueId);
|
|
3791
3806
|
if (!didDoc.didDocument) {
|
|
3792
3807
|
throw new CoviaError("Invalid DID document");
|
|
3793
3808
|
}
|
|
3809
|
+
expectedDid = canonicalDidFromDocument(didDoc.didDocument);
|
|
3810
|
+
requestedWebDid = venueId;
|
|
3794
3811
|
const endpoint = didDoc.didDocument.service?.find((service) => service.type === "Covia.API.v1")?.serviceEndpoint;
|
|
3795
3812
|
if (typeof endpoint !== "string") {
|
|
3796
3813
|
throw new CoviaError("No (string) endpoint found for DID");
|
|
@@ -3811,7 +3828,8 @@ var Venue = class _Venue {
|
|
|
3811
3828
|
if (!data.did) {
|
|
3812
3829
|
throw new CoviaError(`Venue status at ${statusUrl} did not include a DID`);
|
|
3813
3830
|
}
|
|
3814
|
-
|
|
3831
|
+
const required = expectedDid ?? (data.did.startsWith("did:web:") ? requestedWebDid : void 0);
|
|
3832
|
+
assertVenueIdentity(required, data.did, baseUrl);
|
|
3815
3833
|
return new _Venue({
|
|
3816
3834
|
baseUrl,
|
|
3817
3835
|
venueId: data.did,
|