did-sdk-js
Version:
js sdk for did and vc according to mcps did spec
34 lines • 1.65 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.publicCompress = exports.publicDecompress = void 0;
const ecurve_1 = require("ecurve");
const BigInteger = require("bigi");
const sm2Curve = getSM2Curve();
function getSM2Curve() {
let curve = {
p: "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",
a: "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",
b: "28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",
n: "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",
h: "01",
Gx: "32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7",
Gy: "BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0",
};
let p = new BigInteger(curve.p, 16, null);
let a = new BigInteger(curve.a, 16, null);
let b = new BigInteger(curve.b, 16, null);
let n = new BigInteger(curve.n, 16, null);
let h = new BigInteger(curve.h, 16, null);
let Gx = new BigInteger(curve.Gx, 16, null);
let Gy = new BigInteger(curve.Gy, 16, null);
return new ecurve_1.Curve(p, a, b, Gx, Gy, n, h);
}
function publicDecompress(compressedPub) {
return ecurve_1.Point.decodeFrom(sm2Curve, Buffer.from(compressedPub, "hex")).getEncoded(false).toString("hex");
}
exports.publicDecompress = publicDecompress;
function publicCompress(uncompressedPub) {
return ecurve_1.Point.decodeFrom(sm2Curve, Buffer.from(uncompressedPub, "hex")).getEncoded(true).toString("hex");
}
exports.publicCompress = publicCompress;
//# sourceMappingURL=sm2.js.map
;