1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ecc = void 0;
|
4 | var eosjs_jssig_1 = require("./eosjs-jssig");
|
5 | var eosjs_key_conversions_1 = require("./eosjs-key-conversions");
|
6 | var eosjs_numeric_1 = require("./eosjs-numeric");
|
7 | exports.ecc = {
|
8 | initialize: function () { return console.error('Method deprecated'); },
|
9 | unsafeRandomKey: function () { return console.error('Method deprecated'); },
|
10 | randomKey: function (cpuEntropyBits, options) {
|
11 | if (options === void 0) { options = {}; }
|
12 | if (cpuEntropyBits !== undefined) {
|
13 | console.warn('Argument `cpuEntropyBits` is deprecated, ' +
|
14 | 'use the options argument instead');
|
15 | }
|
16 | var privateKey = eosjs_key_conversions_1.generateKeyPair(eosjs_numeric_1.KeyType.k1, options).privateKey;
|
17 | return Promise.resolve(privateKey.toLegacyString());
|
18 | },
|
19 | seedPrivate: function () { return console.error('Method deprecated'); },
|
20 | privateToPublic: function (key, pubkey_prefix) {
|
21 | if (pubkey_prefix !== undefined) {
|
22 | console.warn('Argument `pubkey_prefix` is deprecated, ' +
|
23 | 'keys prefixed with PUB_K1_/PUB_R1_/PUB_WA_ going forward');
|
24 | }
|
25 | var privateKey = eosjs_jssig_1.PrivateKey.fromString(key);
|
26 | var publicKey = privateKey.getPublicKey();
|
27 | return publicKey.toLegacyString();
|
28 | },
|
29 | isValidPublic: function (pubkey, pubkey_prefix) {
|
30 | if (pubkey_prefix !== undefined) {
|
31 | console.warn('Argument `pubkey_prefix` is deprecated, ' +
|
32 | 'keys prefixed with PUB_K1_/PUB_R1_/PUB_WA_ going forward');
|
33 | }
|
34 | try {
|
35 | var publicKey = eosjs_jssig_1.PublicKey.fromString(pubkey);
|
36 | return publicKey.isValid();
|
37 | }
|
38 | catch (_a) {
|
39 | return false;
|
40 | }
|
41 | },
|
42 | isValidPrivate: function (wif) {
|
43 | try {
|
44 | var privateKey = eosjs_jssig_1.PrivateKey.fromString(wif);
|
45 | return privateKey.isValid();
|
46 | }
|
47 | catch (_a) {
|
48 | return false;
|
49 | }
|
50 | },
|
51 | sign: function (data, privateKey, encoding) {
|
52 | if (encoding === void 0) { encoding = 'utf8'; }
|
53 | var privKey = typeof privateKey === 'string' ? eosjs_jssig_1.PrivateKey.fromString(privateKey) : privateKey;
|
54 | var signature = privKey.sign(data, true, encoding);
|
55 | return signature.toString();
|
56 | },
|
57 | signHash: function (dataSha256, privateKey, encoding) {
|
58 | if (encoding === void 0) { encoding = 'hex'; }
|
59 | var privKey = typeof privateKey === 'string' ? eosjs_jssig_1.PrivateKey.fromString(privateKey) : privateKey;
|
60 | var signature = privKey.sign(dataSha256, false, encoding);
|
61 | return signature.toString();
|
62 | },
|
63 | verify: function (signature, data, pubKey, encoding, hashData) {
|
64 | if (encoding === void 0) { encoding = 'utf8'; }
|
65 | if (hashData === void 0) { hashData = true; }
|
66 | var publicKey = typeof pubKey === 'string' ? eosjs_jssig_1.PublicKey.fromString(pubKey) : pubKey;
|
67 | var sig = eosjs_jssig_1.Signature.fromString(signature);
|
68 | return sig.verify(data, publicKey, hashData, encoding);
|
69 | },
|
70 | recover: function (signature, data, encoding) {
|
71 | if (encoding === void 0) { encoding = 'utf8'; }
|
72 | var sig = eosjs_jssig_1.Signature.fromString(signature);
|
73 | var publicKey = sig.recover(data, true, encoding);
|
74 | return publicKey.toLegacyString();
|
75 | },
|
76 | recoverHash: function (signature, dataSha256, encoding) {
|
77 | if (encoding === void 0) { encoding = 'hex'; }
|
78 | var sig = eosjs_jssig_1.Signature.fromString(signature);
|
79 | var publicKey = sig.recover(dataSha256, false, encoding);
|
80 | return publicKey.toLegacyString();
|
81 | },
|
82 | sha256: function (data, resultEncoding, encoding) {
|
83 | if (encoding !== undefined) {
|
84 | console.warn('Argument `encoding` is deprecated');
|
85 | }
|
86 | if (resultEncoding !== undefined) {
|
87 | console.warn('Argument `resultEncoding` is deprecated');
|
88 | }
|
89 | return require('./eosjs-key-conversions').sha256(data);
|
90 | }
|
91 | };
|
92 |
|
\ | No newline at end of file |