@ngraveio/ur-blockchain-commons
Version:
A JS implementation of Uniform Resources(UR) Registry specification from Blockchain Commons.
53 lines (51 loc) • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ECKey = void 0;
const bc_ur_1 = require("@ngraveio/bc-ur");
class ECKey extends (0, bc_ur_1.registryItemFactory)({
tag: 40306,
URType: 'eckey',
keyMap: {
curve: 1,
isPrivate: 2,
data: 3,
},
CDDL: `
tagged-eckey = #6.40306(eckey)
eckey = {
? curve: uint .default 0,
? is-private: bool .default false,
data: bytes
}
curve = 1
is-private = 2
data = 3
`,
}) {
constructor(input) {
// Pass a data object
super(input);
this.getCurve = () => this.data.curve || 0;
this.getIsPrivate = () => this.data.isPrivate || false;
this.getData = () => this.data.data;
this.data = input;
}
verifyInput(input) {
const errors = [];
if (input.data == undefined || !(input.data instanceof Uint8Array)) {
errors.push(new Error('data must be a Buffer or Uint8Array'));
}
if (input.curve !== undefined && typeof input.curve !== 'number') {
errors.push(new Error('curve must be a number'));
}
if (input.isPrivate !== undefined && typeof input.isPrivate !== 'boolean') {
errors.push(new Error('isPrivate must be a boolean'));
}
return {
valid: errors.length === 0,
reasons: errors.length > 0 ? errors : undefined,
};
}
}
exports.ECKey = ECKey;
//# sourceMappingURL=ECKey.js.map