credo-near-module
Version:
NEAR Module for Credo SSI Agent
43 lines (42 loc) • 2.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateSpecCompliantPayload = validateSpecCompliantPayload;
var sdk_1 = require("@cheqd/sdk");
function validateSpecCompliantPayload(didDocument) {
var _a;
// id is required, validated on both compile and runtime
if (!didDocument.id && !didDocument.id.startsWith("did:near:"))
return { valid: false, error: "id is required" };
// verificationMethod is required
if (!didDocument.verificationMethod)
return { valid: false, error: "verificationMethod is required" };
// verificationMethod must be an array
if (!Array.isArray(didDocument.verificationMethod))
return { valid: false, error: "verificationMethod must be an array" };
// verificationMethod must be not be empty
if (!didDocument.verificationMethod.length)
return { valid: false, error: "verificationMethod must be not be empty" };
// verificationMethod types must be supported
var isValidVerificationMethod = didDocument.verificationMethod.every(function (vm) {
switch (vm.type) {
case sdk_1.VerificationMethods.Ed255192020:
return vm.publicKeyMultibase != null;
case sdk_1.VerificationMethods.JWK:
return vm.publicKeyJwk != null;
case sdk_1.VerificationMethods.Ed255192018:
return vm.publicKeyBase58 != null;
default:
return false;
}
});
if (!isValidVerificationMethod)
return { valid: false, error: "verificationMethod publicKey is Invalid" };
var isValidService = didDocument.service
? (_a = didDocument === null || didDocument === void 0 ? void 0 : didDocument.service) === null || _a === void 0 ? void 0 : _a.every(function (s) {
return (s === null || s === void 0 ? void 0 : s.serviceEndpoint) && (s === null || s === void 0 ? void 0 : s.id) && (s === null || s === void 0 ? void 0 : s.type);
})
: true;
if (!isValidService)
return { valid: false, error: "Service is Invalid" };
return { valid: true };
}