1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const bcrypto_1 = require("bcrypto");
|
4 | const __1 = require("..");
|
5 | const errors_1 = require("../errors");
|
6 | const managers_1 = require("../managers");
|
7 | const address_1 = require("./address");
|
8 | const keys_1 = require("./keys");
|
9 | class PublicKey {
|
10 | static fromPassphrase(passphrase) {
|
11 | return keys_1.Keys.fromPassphrase(passphrase).publicKey;
|
12 | }
|
13 | static fromWIF(wif, network) {
|
14 | return keys_1.Keys.fromWIF(wif, network).publicKey;
|
15 | }
|
16 | static fromMultiSignatureAsset(asset) {
|
17 | const { min, publicKeys } = asset;
|
18 | for (const publicKey of publicKeys) {
|
19 | if (!/^[0-9A-Fa-f]{66}$/.test(publicKey)) {
|
20 | throw new errors_1.PublicKeyError(publicKey);
|
21 | }
|
22 | }
|
23 | if (min < 1 || min > publicKeys.length) {
|
24 | throw new errors_1.InvalidMultiSignatureAssetError();
|
25 | }
|
26 | const minKey = PublicKey.fromPassphrase(__1.Utils.numberToHex(min));
|
27 | const keys = [minKey, ...publicKeys];
|
28 | return keys.reduce((previousValue, currentValue) => bcrypto_1.secp256k1
|
29 | .publicKeyAdd(Buffer.from(previousValue, "hex"), Buffer.from(currentValue, "hex"), true)
|
30 | .toString("hex"));
|
31 | }
|
32 | static validate(publicKey, networkVersion) {
|
33 | if (!networkVersion) {
|
34 | networkVersion = managers_1.configManager.get("network.pubKeyHash");
|
35 | }
|
36 | try {
|
37 | return address_1.Address.fromPublicKey(publicKey, networkVersion).length === 34;
|
38 | }
|
39 | catch (e) {
|
40 | return false;
|
41 | }
|
42 | }
|
43 | }
|
44 | exports.PublicKey = PublicKey;
|
45 |
|
\ | No newline at end of file |