UNPKG

xiot-core-xcp-ts

Version:
43 lines (42 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.XcpClientCipherProductImpl = void 0; const XcpAuthenticationType_1 = require("../common/XcpAuthenticationType"); const mipher_ts_1 = require("mipher-ts"); class XcpClientCipherProductImpl { constructor(deviceType, getter, serverLTPK) { this.deviceType = deviceType; this.getter = getter; this.serverLTPK = serverLTPK; this.algorithm = 'RSA-SHA256'; } getAuthenticationType() { return XcpAuthenticationType_1.XcpAuthenticationType.DEVICE_TYPE; } sign(info) { const keypair = this.getter.getTypeKeyPair(this.deviceType); const ed25519 = new mipher_ts_1.Ed25519(); return new Promise((resolve, reject) => { const res = ed25519.sign(info, keypair.sk, keypair.pk); if (!res) { reject('sign error'); } else { resolve(res); } }); } verify(info, signature) { const ed25519 = new mipher_ts_1.Ed25519(); return new Promise((resolve, reject) => { const res = ed25519.verify(info, this.serverLTPK, signature); if (!res) { reject('verify error'); } else { resolve(res); } }); } } exports.XcpClientCipherProductImpl = XcpClientCipherProductImpl;