|
|
@@ -7,13 +7,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
});
|
|
|
};
|
|
|
+var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
+ return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
+};
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
-const { generateKeyPair, createPublicKey, createPrivateKey, createHash, createSign } = require('crypto');
|
|
|
-const bs58 = require('bs58');
|
|
|
+const crypto_1 = require("crypto");
|
|
|
+const bs58_1 = __importDefault(require("bs58"));
|
|
|
class CryptoNode {
|
|
|
generateRsaKeyPair(bits) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- generateKeyPair('rsa', {
|
|
|
+ crypto_1.generateKeyPair('rsa', {
|
|
|
modulusLength: bits,
|
|
|
privateKeyEncoding: {
|
|
|
format: 'pem',
|
|
|
@@ -37,11 +40,11 @@ class CryptoNode {
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
- sign(privateKeyText, data) {
|
|
|
+ sign(privateKeyText, dataHexBytes) {
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
- const privateKey = createPrivateKey(privateKeyText);
|
|
|
- const sign = createSign('SHA256');
|
|
|
- sign.write(data);
|
|
|
+ const privateKey = crypto_1.createPrivateKey(privateKeyText);
|
|
|
+ const sign = crypto_1.createSign('SHA256');
|
|
|
+ sign.write(Buffer.from(dataHexBytes, 'hex'));
|
|
|
sign.end();
|
|
|
const signature = sign.sign(privateKey, 'hex');
|
|
|
return signature;
|
|
|
@@ -49,7 +52,8 @@ class CryptoNode {
|
|
|
}
|
|
|
importRsaKeyPair(serialized) {
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
- const { privateKey, publicKey } = JSON.parse(bs58.decode(serialized));
|
|
|
+ const decoded = bs58_1.default.decode(serialized);
|
|
|
+ const { privateKey, publicKey } = JSON.parse(decoded.toString('utf-8'));
|
|
|
return {
|
|
|
export: () => this.export(privateKey, publicKey),
|
|
|
getPublicHash: () => this.getPublicHash(publicKey),
|
|
|
@@ -59,28 +63,28 @@ class CryptoNode {
|
|
|
});
|
|
|
}
|
|
|
getPublicHash(publicKeyText) {
|
|
|
- const publicKey = createPublicKey(publicKeyText);
|
|
|
+ const publicKey = crypto_1.createPublicKey(publicKeyText);
|
|
|
const derBytes = publicKey.export({
|
|
|
+ format: 'der',
|
|
|
type: 'spki',
|
|
|
- format: 'der'
|
|
|
});
|
|
|
- const sha256 = createHash('sha256');
|
|
|
+ const sha256 = crypto_1.createHash('sha256');
|
|
|
sha256.update(derBytes);
|
|
|
- const pubHash = bs58.encode(sha256.digest());
|
|
|
+ const pubHash = bs58_1.default.encode(sha256.digest());
|
|
|
return pubHash;
|
|
|
}
|
|
|
getPublicKey(publicKeyText) {
|
|
|
- const publicKey = createPublicKey(publicKeyText);
|
|
|
+ const publicKey = crypto_1.createPublicKey(publicKeyText);
|
|
|
const derBytes = publicKey.export({
|
|
|
+ format: 'der',
|
|
|
type: 'spki',
|
|
|
- format: 'der'
|
|
|
});
|
|
|
return derBytes.toString('hex');
|
|
|
}
|
|
|
export(privateKey, publicKey) {
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
const jsonString = JSON.stringify({ privateKey, publicKey });
|
|
|
- return bs58.encode(Buffer.from(jsonString, 'utf-8'));
|
|
|
+ return bs58_1.default.encode(Buffer.from(jsonString, 'utf-8'));
|
|
|
});
|
|
|
}
|
|
|
}
|