- Add GETTING_STARTED.md with quick start guide and development modes - Add INSTALL.sh automated installation script - Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md - Add QUICK_REFERENCE.md for common commands - Add SETUP_GUIDE.md with detailed setup instructions - Update README.md with improved project overview - Add did-wallet app dependencies and node_modules
54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.PrivateKey = void 0;
|
|
var utils_1 = require("@noble/ciphers/utils");
|
|
var config_1 = require("../config");
|
|
var utils_2 = require("../utils");
|
|
var PublicKey_1 = require("./PublicKey");
|
|
var PrivateKey = /** @class */ (function () {
|
|
function PrivateKey(secret) {
|
|
var sk = secret === undefined ? (0, utils_2.getValidSecret)() : secret;
|
|
if (!(0, utils_2.isValidPrivateKey)(sk)) {
|
|
throw new Error("Invalid private key");
|
|
}
|
|
this.data = sk;
|
|
this.publicKey = new PublicKey_1.PublicKey((0, utils_2.getPublicKey)(sk));
|
|
}
|
|
PrivateKey.fromHex = function (hex) {
|
|
return new PrivateKey((0, utils_2.decodeHex)(hex));
|
|
};
|
|
Object.defineProperty(PrivateKey.prototype, "secret", {
|
|
get: function () {
|
|
// TODO: Uint8Array
|
|
return Buffer.from(this.data);
|
|
},
|
|
enumerable: false,
|
|
configurable: true
|
|
});
|
|
PrivateKey.prototype.toHex = function () {
|
|
return (0, utils_1.bytesToHex)(this.data);
|
|
};
|
|
PrivateKey.prototype.encapsulate = function (pk) {
|
|
var senderPoint;
|
|
var sharedPoint;
|
|
if ((0, config_1.isHkdfKeyCompressed)()) {
|
|
senderPoint = this.publicKey.compressed;
|
|
sharedPoint = this.multiply(pk, true);
|
|
}
|
|
else {
|
|
senderPoint = this.publicKey.uncompressed;
|
|
sharedPoint = this.multiply(pk, false);
|
|
}
|
|
return (0, utils_2.getSharedKey)(senderPoint, sharedPoint);
|
|
};
|
|
PrivateKey.prototype.multiply = function (pk, compressed) {
|
|
if (compressed === void 0) { compressed = false; }
|
|
return (0, utils_2.getSharedPoint)(this.data, pk.compressed, compressed);
|
|
};
|
|
PrivateKey.prototype.equals = function (other) {
|
|
return (0, utils_1.equalBytes)(this.data, other.data);
|
|
};
|
|
return PrivateKey;
|
|
}());
|
|
exports.PrivateKey = PrivateKey;
|