1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.transactionID = exports.sha512Half = exports.Sha512Half = void 0;
|
4 | const hash_prefixes_1 = require("./hash-prefixes");
|
5 | const createHash = require("create-hash");
|
6 | const hash_256_1 = require("./types/hash-256");
|
7 | const binary_serializer_1 = require("./serdes/binary-serializer");
|
8 | const buffer_1 = require("buffer/");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | class Sha512Half extends binary_serializer_1.BytesList {
|
14 | constructor() {
|
15 | super(...arguments);
|
16 | this.hash = createHash('sha512');
|
17 | }
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | static put(bytes) {
|
25 | return new Sha512Half().put(bytes);
|
26 | }
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | put(bytes) {
|
34 | this.hash.update(bytes);
|
35 | return this;
|
36 | }
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 | finish256() {
|
43 | return buffer_1.Buffer.from(this.hash.digest().slice(0, 32));
|
44 | }
|
45 | |
46 |
|
47 |
|
48 |
|
49 |
|
50 | finish() {
|
51 | return new hash_256_1.Hash256(this.finish256());
|
52 | }
|
53 | }
|
54 | exports.Sha512Half = Sha512Half;
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | function sha512Half(...args) {
|
62 | const hash = new Sha512Half();
|
63 | args.forEach((a) => hash.put(a));
|
64 | return hash.finish256();
|
65 | }
|
66 | exports.sha512Half = sha512Half;
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | function transactionID(serialized) {
|
74 | return new hash_256_1.Hash256(sha512Half(hash_prefixes_1.HashPrefix.transactionID, serialized));
|
75 | }
|
76 | exports.transactionID = transactionID;
|
77 |
|
\ | No newline at end of file |