dpos-offline
Version:
Offline Signing Transactions for DPOS Blockchains
47 lines (46 loc) • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var toExport;
// tslint:disable no-var-requires
try {
var sodiumNative_1 = require('sodium-native');
if (typeof (sodiumNative_1) === 'undefined' || sodiumNative_1 === null) {
throw new Error('switch to JS implementation');
}
toExport = {
api: {
crypto_sign_seed_keypair: function (hash) {
var publicKey = Buffer.alloc(sodiumNative_1.crypto_sign_PUBLICKEYBYTES);
var secretKey = Buffer.alloc(sodiumNative_1.crypto_sign_SECRETKEYBYTES);
sodiumNative_1.crypto_sign_seed_keypair(publicKey, secretKey, hash);
return { secretKey: secretKey, publicKey: publicKey };
},
crypto_sign_detached: function (what, privKey) {
var signature = Buffer.alloc(sodiumNative_1.crypto_sign_BYTES);
sodiumNative_1.crypto_sign_detached(signature, what, privKey);
return signature;
},
crypto_sign_verify_detached: function (signature, what, publicKey) {
return sodiumNative_1.crypto_sign_verify_detached(signature, what, publicKey);
},
crypto_sign_open: function (signature, pubKey) {
var msg = Buffer.alloc(signature.length - sodiumNative_1.crypto_sign_BYTES);
var verified = sodiumNative_1.crypto_sign_open(msg, signature, pubKey);
if (!verified) {
return null;
}
return msg;
},
crypto_sign: function (what, privKey) {
var signature = Buffer.alloc(sodiumNative_1.crypto_sign_BYTES + what.length);
sodiumNative_1.crypto_sign(signature, what, privKey);
return signature;
},
},
};
}
catch (err) {
// Sodium does not exist.
toExport = require('../browser/sodium');
}
exports.ed25519 = toExport.api;