oca_package
Version:
The wrapper of OCA bundle to generate OCA Package at ADC
51 lines (50 loc) • 1.85 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const extensions_js_1 = __importDefault(require("./oca_extensions/extensions.js"));
// import { saidify, verify } from 'saidify';
const saidify_1 = require("saidify");
class OcaPackage {
constructor(extension_input_json, oca_bundle) {
this.extensions_box = new extensions_js_1.default(extension_input_json, oca_bundle);
this.oca_bundle = oca_bundle;
}
Saidifying() {
const [, sad] = (0, saidify_1.saidify)(this.toJSON());
return sad;
}
Said() {
const [said] = (0, saidify_1.saidify)(this.toJSON());
return said;
}
toJSON() {
try {
return {
d: '',
type: 'oca_package/1.0',
oca_bundle: this.oca_bundle,
extensions: this.extensions_box.buildExtensionsBox,
};
}
catch (error) {
throw new Error(`Failed to parse Extension JSON: ${error}`);
}
}
GenerateOcaPackage() {
return JSON.stringify(this.Saidifying());
}
/**
* Verifies the OCA package against a digest.
* @param oca_package - The OCA package to verify.
* @param digest - The digest to verify against.
* @returns {boolean} - Returns true if the verification is successful, otherwise false.
*/
VerifyOcaPackage(oca_package, digest) {
const label = 'd';
// prefixed is set to true this avoid d = '' to be considered as a valid self-addressing data
return (0, saidify_1.verify)(oca_package, digest, label, saidify_1.SAIDDex.Blake3_256, saidify_1.Serials.JSON, true);
}
}
exports.default = OcaPackage;
;