namillum
Version:
Bubble Protocol SDK
59 lines (52 loc) • 1.55 kB
text/typescript
// Copyright (C) 2018 Zilliqa
//
// This file is part of zilliqa-js
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import * as schnorr from "./schnorr";
import { Buffer } from "buffer"; /* tslint:disable:no-unused-variable */
import { Signature } from "./signature";
/**
* sign
*
* @param {string} hash - hex-encoded hash of the data to be signed
*
* @returns {string} the signature
*/
export const sign = (
msg: Buffer,
privateKey: string,
pubKey: string
): string => {
const sig = schnorr.sign(
msg,
Buffer.from(privateKey, "hex"),
Buffer.from(pubKey, "hex")
);
let r = sig.r.toString("hex");
let s = sig.s.toString("hex");
while (r.length < 64) {
r = "0" + r;
}
while (s.length < 64) {
s = "0" + s;
}
return r + s;
};
export { schnorr, Signature };
export * from "./util";
export * from "./keystore";
export * from "./random";
export * from "./types";
export * from "./bech32";