1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const hash_1 = require("../crypto/hash");
|
4 | const managers_1 = require("../managers");
|
5 | const utils_1 = require("../utils");
|
6 | const validation_1 = require("../validation");
|
7 | const types_1 = require("./types");
|
8 | const utils_2 = require("./utils");
|
9 | class Verifier {
|
10 | static verify(data) {
|
11 | if (utils_1.isException(data)) {
|
12 | return true;
|
13 | }
|
14 | if (data.type >= 4 && data.type <= 99 && !managers_1.configManager.getMilestone().aip11) {
|
15 | return false;
|
16 | }
|
17 | return Verifier.verifyHash(data);
|
18 | }
|
19 | static verifySecondSignature(transaction, publicKey) {
|
20 | const secondSignature = transaction.secondSignature || transaction.signSignature;
|
21 | if (!secondSignature) {
|
22 | return false;
|
23 | }
|
24 | const hash = utils_2.Utils.toHash(transaction, { excludeSecondSignature: true });
|
25 | if (transaction.version === 2) {
|
26 | return hash_1.Hash.verifySchnorr(hash, secondSignature, publicKey);
|
27 | }
|
28 | else {
|
29 | return hash_1.Hash.verifyECDSA(hash, secondSignature, publicKey);
|
30 | }
|
31 | }
|
32 | static verifyHash(data) {
|
33 | const { signature, senderPublicKey } = data;
|
34 | if (!signature) {
|
35 | return false;
|
36 | }
|
37 | const hash = utils_2.Utils.toHash(data, {
|
38 | excludeSignature: true,
|
39 | excludeSecondSignature: true,
|
40 | });
|
41 | if (data.version === 2) {
|
42 | return hash_1.Hash.verifySchnorr(hash, signature, senderPublicKey);
|
43 | }
|
44 | else {
|
45 | return hash_1.Hash.verifyECDSA(hash, signature, senderPublicKey);
|
46 | }
|
47 | }
|
48 | static verifySchema(data, strict = true) {
|
49 | const { $id } = types_1.TransactionTypeFactory.get(data.type).getSchema();
|
50 | return validation_1.validator.validate(strict ? `${$id}Strict` : `${$id}`, data);
|
51 | }
|
52 | }
|
53 | exports.Verifier = Verifier;
|
54 |
|
\ | No newline at end of file |