1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | var tweetnacl_1 = __importDefault(require("tweetnacl"));
|
7 | function bytesToHex(bytes) {
|
8 | return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
9 | .toString('hex')
|
10 | .toUpperCase();
|
11 | }
|
12 | exports.bytesToHex = bytesToHex;
|
13 | function numberToHex(num) {
|
14 | return "0x" + num.toString(16);
|
15 | }
|
16 | exports.numberToHex = numberToHex;
|
17 | function hexToNumber(hex) {
|
18 | return parseInt(hex, 16);
|
19 | }
|
20 | exports.hexToNumber = hexToNumber;
|
21 | function bytesToHexAddr(bytes) {
|
22 | return '0x' + bytesToHex(bytes);
|
23 | }
|
24 | exports.bytesToHexAddr = bytesToHexAddr;
|
25 | function getGUID() {
|
26 | function s4() {
|
27 | return Math.floor((1 + Math.random()) * 0x10000)
|
28 | .toString(16)
|
29 | .substring(1);
|
30 | }
|
31 | return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
32 | }
|
33 | exports.getGUID = getGUID;
|
34 | exports.SIGNATURE_LENGTH = tweetnacl_1.default.sign.signatureLength;
|
35 | exports.PRIVATE_KEY_LENGTH = tweetnacl_1.default.sign.secretKeyLength;
|
36 | exports.PUBLIC_KEY_LENGTH = tweetnacl_1.default.sign.publicKeyLength;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function generatePrivateKey() {
|
42 | var pair = tweetnacl_1.default.sign.keyPair();
|
43 | return pair.secretKey;
|
44 | }
|
45 | exports.generatePrivateKey = generatePrivateKey;
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | function publicKeyFromPrivateKey(privateKey) {
|
52 | var pair = tweetnacl_1.default.sign.keyPair.fromSecretKey(privateKey);
|
53 | return pair.publicKey;
|
54 | }
|
55 | exports.publicKeyFromPrivateKey = publicKeyFromPrivateKey;
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | function sign(msg, privateKey) {
|
63 | var sigMsg = tweetnacl_1.default.sign(msg, privateKey);
|
64 | return sigMsg.slice(0, exports.SIGNATURE_LENGTH);
|
65 | }
|
66 | exports.sign = sign;
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | function Uint8ArrayToB64(bytes) {
|
73 | return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64');
|
74 | }
|
75 | exports.Uint8ArrayToB64 = Uint8ArrayToB64;
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | function B64ToUint8Array(s) {
|
82 | return Buffer.from(s, 'base64');
|
83 | }
|
84 | exports.B64ToUint8Array = B64ToUint8Array;
|
85 | function bufferToProtobufBytes(input) {
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | return input.constructor === Buffer ? new Uint8Array(input) : input;
|
93 | }
|
94 | exports.bufferToProtobufBytes = bufferToProtobufBytes;
|
95 |
|
\ | No newline at end of file |