@mainsail/crypto-block 0.0.1-evm.3 → 0.0.1-evm.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/distribution/block.d.ts.map +1 -1
- package/distribution/block.js +1 -1
- package/distribution/block.js.map +1 -1
- package/distribution/deserializer.d.ts +2 -3
- package/distribution/deserializer.d.ts.map +1 -1
- package/distribution/deserializer.js +91 -97
- package/distribution/deserializer.js.map +1 -1
- package/distribution/factory.d.ts +1 -2
- package/distribution/factory.d.ts.map +1 -1
- package/distribution/factory.js +46 -54
- package/distribution/factory.js.map +1 -1
- package/distribution/{id.factory.d.ts → hash.factory.d.ts} +2 -2
- package/distribution/hash.factory.d.ts.map +1 -0
- package/distribution/{id.factory.js → hash.factory.js} +9 -7
- package/distribution/hash.factory.js.map +1 -0
- package/distribution/index.d.ts +1 -2
- package/distribution/index.d.ts.map +1 -1
- package/distribution/index.js +34 -8
- package/distribution/index.js.map +1 -1
- package/distribution/schemas.d.ts +1 -1
- package/distribution/schemas.d.ts.map +1 -1
- package/distribution/schemas.js +52 -26
- package/distribution/schemas.js.map +1 -1
- package/distribution/serializer.d.ts +1 -4
- package/distribution/serializer.d.ts.map +1 -1
- package/distribution/serializer.js +31 -50
- package/distribution/serializer.js.map +1 -1
- package/package.json +27 -24
- package/distribution/id.factory.d.ts.map +0 -1
- package/distribution/id.factory.js.map +0 -1
- package/distribution/verifier.d.ts +0 -8
- package/distribution/verifier.d.ts.map +0 -1
- package/distribution/verifier.js +0 -116
- package/distribution/verifier.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,UAAU,cAAc;IACvB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;CAC7C;AAED,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,UAAU,cAAc;IACvB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;CAC7C;AAED,eAAO,MAAM,SAAS,GAAI,oCAAoC,cAAc,KAAG,SAAS,CAAC,MAAM,CAAC,KAS7F,CAAC"}
|
package/distribution/block.js
CHANGED
|
@@ -3,7 +3,7 @@ export const sealBlock = ({ data, serialized, transactions }) => Object.seal({
|
|
|
3
3
|
header: data,
|
|
4
4
|
serialized,
|
|
5
5
|
transactions: transactions.map((transaction, index) => {
|
|
6
|
-
transaction.data.
|
|
6
|
+
transaction.data.transactionIndex = index;
|
|
7
7
|
return transaction;
|
|
8
8
|
}),
|
|
9
9
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.js","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAkB,EAA0B,EAAE,CACvG,MAAM,CAAC,IAAI,CAAC;IACX,IAAI;IACJ,MAAM,EAAE,IAAI;IACZ,UAAU;IACV,YAAY,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;QACrD,WAAW,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAkB,EAA0B,EAAE,CACvG,MAAM,CAAC,IAAI,CAAC;IACX,IAAI;IACJ,MAAM,EAAE,IAAI;IACZ,UAAU;IACV,YAAY,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;QACrD,WAAW,CAAC,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;QAC1C,OAAO,WAAW,CAAC;IACpB,CAAC,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { Contracts } from "@mainsail/contracts";
|
|
3
2
|
export declare class Deserializer implements Contracts.Crypto.BlockDeserializer {
|
|
4
3
|
#private;
|
|
5
|
-
private readonly
|
|
4
|
+
private readonly hashFactory;
|
|
6
5
|
private readonly transactionFactory;
|
|
7
6
|
private readonly serializer;
|
|
8
|
-
private readonly
|
|
7
|
+
private readonly headerSize;
|
|
9
8
|
deserializeHeader(serialized: Buffer): Promise<Contracts.Crypto.BlockHeader>;
|
|
10
9
|
deserializeWithTransactions(serialized: Buffer): Promise<Contracts.Crypto.BlockWithTransactions>;
|
|
11
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAsB,MAAM,qBAAqB,CAAC;AAMpE,qBACa,YAAa,YAAW,SAAS,CAAC,MAAM,CAAC,iBAAiB;;IAEtE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAG3C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAsB;IAGzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAG9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAE9B,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC;IAU5E,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,qBAAqB,CAAC;CA0G7G"}
|
|
@@ -7,122 +7,116 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var _Deserializer_instances, _Deserializer_deserializeBufferHeader, _Deserializer_deserializeTransactions;
|
|
16
10
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
17
11
|
import { inject, injectable } from "@mainsail/container";
|
|
18
12
|
import { Contracts, Identifiers } from "@mainsail/contracts";
|
|
19
13
|
import { TransactionFactory } from "@mainsail/crypto-transaction";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { IDFactory } from "./id.factory.js";
|
|
14
|
+
import { ByteBuffer, sleep } from "@mainsail/utils";
|
|
15
|
+
import { HashFactory } from "./hash.factory.js";
|
|
23
16
|
let Deserializer = class Deserializer {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
hashFactory;
|
|
18
|
+
transactionFactory;
|
|
19
|
+
serializer;
|
|
20
|
+
headerSize;
|
|
27
21
|
async deserializeHeader(serialized) {
|
|
28
22
|
const buffer = ByteBuffer.fromBuffer(serialized);
|
|
29
|
-
const header = await
|
|
30
|
-
header.
|
|
23
|
+
const header = await this.#deserializeBufferHeader(buffer);
|
|
24
|
+
header.hash = await this.hashFactory.make(header);
|
|
31
25
|
return header;
|
|
32
26
|
}
|
|
33
27
|
async deserializeWithTransactions(serialized) {
|
|
34
28
|
const buffer = ByteBuffer.fromBuffer(serialized);
|
|
35
|
-
const block = await
|
|
29
|
+
const block = await this.#deserializeBufferHeader(buffer);
|
|
36
30
|
let transactions = [];
|
|
37
31
|
if (buffer.getRemainderLength() > 0) {
|
|
38
|
-
transactions = await
|
|
32
|
+
transactions = await this.#deserializeTransactions(block, buffer);
|
|
39
33
|
}
|
|
40
|
-
block.
|
|
34
|
+
block.hash = await this.hashFactory.make(block);
|
|
41
35
|
return { data: block, transactions };
|
|
42
36
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
37
|
+
async #deserializeBufferHeader(buffer) {
|
|
38
|
+
const block = {};
|
|
39
|
+
await this.serializer.deserialize(buffer, block, {
|
|
40
|
+
length: this.headerSize(),
|
|
41
|
+
schema: {
|
|
42
|
+
version: {
|
|
43
|
+
type: "uint8",
|
|
44
|
+
},
|
|
45
|
+
timestamp: {
|
|
46
|
+
type: "uint48",
|
|
47
|
+
},
|
|
48
|
+
number: {
|
|
49
|
+
type: "uint32",
|
|
50
|
+
},
|
|
51
|
+
round: {
|
|
52
|
+
type: "uint32",
|
|
53
|
+
},
|
|
54
|
+
parentHash: {
|
|
55
|
+
type: "hash",
|
|
56
|
+
},
|
|
57
|
+
stateRoot: {
|
|
58
|
+
type: "hash",
|
|
59
|
+
},
|
|
60
|
+
logsBloom: {
|
|
61
|
+
type: "hash",
|
|
62
|
+
size: 256,
|
|
63
|
+
},
|
|
64
|
+
transactionsCount: {
|
|
65
|
+
type: "uint16",
|
|
66
|
+
},
|
|
67
|
+
gasUsed: {
|
|
68
|
+
type: "uint32",
|
|
69
|
+
},
|
|
70
|
+
fee: {
|
|
71
|
+
type: "uint256",
|
|
72
|
+
},
|
|
73
|
+
reward: {
|
|
74
|
+
type: "uint256",
|
|
75
|
+
},
|
|
76
|
+
payloadSize: {
|
|
77
|
+
type: "uint32",
|
|
78
|
+
},
|
|
79
|
+
transactionsRoot: {
|
|
80
|
+
type: "hash",
|
|
81
|
+
},
|
|
82
|
+
proposer: {
|
|
83
|
+
type: "address",
|
|
84
|
+
},
|
|
73
85
|
},
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
type: "uint32",
|
|
85
|
-
},
|
|
86
|
-
payloadHash: {
|
|
87
|
-
type: "hash",
|
|
88
|
-
},
|
|
89
|
-
generatorAddress: {
|
|
90
|
-
type: "address",
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
return block;
|
|
95
|
-
};
|
|
96
|
-
_Deserializer_deserializeTransactions = async function _Deserializer_deserializeTransactions(block, buf) {
|
|
97
|
-
await this.serializer.deserialize(buf, block, {
|
|
98
|
-
length: block.payloadLength,
|
|
99
|
-
schema: {
|
|
100
|
-
transactions: {
|
|
101
|
-
type: "transactions",
|
|
86
|
+
});
|
|
87
|
+
return block;
|
|
88
|
+
}
|
|
89
|
+
async #deserializeTransactions(block, buf) {
|
|
90
|
+
await this.serializer.deserialize(buf, block, {
|
|
91
|
+
length: block.payloadSize,
|
|
92
|
+
schema: {
|
|
93
|
+
transactions: {
|
|
94
|
+
type: "transactions",
|
|
95
|
+
},
|
|
102
96
|
},
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
});
|
|
98
|
+
/**
|
|
99
|
+
* After unpacking we need to turn the transactions into DTOs!
|
|
100
|
+
*
|
|
101
|
+
* We keep this behaviour out of the (de)serialiser because it
|
|
102
|
+
* is very specific to this bit of code in this specific class.
|
|
103
|
+
*/
|
|
104
|
+
const transactions = [];
|
|
105
|
+
for (let index = 0; index < block.transactions.length; index++) {
|
|
106
|
+
if (index % 20 === 0) {
|
|
107
|
+
await sleep(0);
|
|
108
|
+
}
|
|
109
|
+
const transaction = await this.transactionFactory.fromBytes(block.transactions[index]);
|
|
110
|
+
transactions.push(transaction);
|
|
111
|
+
block.transactions[index] = transaction.data;
|
|
115
112
|
}
|
|
116
|
-
|
|
117
|
-
transactions.push(transaction);
|
|
118
|
-
block.transactions[index] = transaction.data;
|
|
113
|
+
return transactions;
|
|
119
114
|
}
|
|
120
|
-
return transactions;
|
|
121
115
|
};
|
|
122
116
|
__decorate([
|
|
123
|
-
inject(Identifiers.Cryptography.Block.
|
|
124
|
-
__metadata("design:type",
|
|
125
|
-
], Deserializer.prototype, "
|
|
117
|
+
inject(Identifiers.Cryptography.Block.HashFactory),
|
|
118
|
+
__metadata("design:type", HashFactory)
|
|
119
|
+
], Deserializer.prototype, "hashFactory", void 0);
|
|
126
120
|
__decorate([
|
|
127
121
|
inject(Identifiers.Cryptography.Transaction.Factory),
|
|
128
122
|
__metadata("design:type", TransactionFactory)
|
|
@@ -132,9 +126,9 @@ __decorate([
|
|
|
132
126
|
__metadata("design:type", Object)
|
|
133
127
|
], Deserializer.prototype, "serializer", void 0);
|
|
134
128
|
__decorate([
|
|
135
|
-
inject(Identifiers.Cryptography.Block.
|
|
136
|
-
__metadata("design:type",
|
|
137
|
-
], Deserializer.prototype, "
|
|
129
|
+
inject(Identifiers.Cryptography.Block.HeaderSize),
|
|
130
|
+
__metadata("design:type", Function)
|
|
131
|
+
], Deserializer.prototype, "headerSize", void 0);
|
|
138
132
|
Deserializer = __decorate([
|
|
139
133
|
injectable()
|
|
140
134
|
], Deserializer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserializer.js","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deserializer.js","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gDAAgD;AAChD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAS,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGzC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEP,WAAW,CAAe;IAG1B,kBAAkB,CAAsB;IAGxC,UAAU,CAAmC;IAG7C,UAAU,CAAgB;IAEpC,KAAK,CAAC,iBAAiB,CAAC,UAAkB;QAChD,MAAM,MAAM,GAAe,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAE7D,MAAM,MAAM,GAA8C,MAAM,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC;QAEtG,MAAM,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAElD,OAAO,MAAM,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,2BAA2B,CAAC,UAAkB;QAC1D,MAAM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,CAAC;8BACf,kBAAkB;wDAAC;AAGxC;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC;;gDACkB;AAG7C;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;gDACP;AAX/B,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CAiIxB"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { Contracts, Utils } from "@mainsail/contracts";
|
|
3
2
|
export declare class BlockFactory implements Contracts.Crypto.BlockFactory {
|
|
4
3
|
#private;
|
|
5
4
|
private readonly serializer;
|
|
6
5
|
private readonly deserializer;
|
|
7
|
-
private readonly
|
|
6
|
+
private readonly hashFactory;
|
|
8
7
|
private readonly validator;
|
|
9
8
|
make(data: Utils.Mutable<Contracts.Crypto.BlockDataSerializable>, transactions: Contracts.Crypto.Transaction[]): Promise<Contracts.Crypto.Block>;
|
|
10
9
|
fromHex(hex: string): Promise<Contracts.Crypto.Block>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA2B,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAMhF,qBACa,YAAa,YAAW,SAAS,CAAC,MAAM,CAAC,YAAY;;IAEjE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAG/D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsC;IAGnE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAG3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAE3C,IAAI,CAChB,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,qBAAqB,CAAC,EAC3D,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,GAC1C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAYrB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAIrD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAIxD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAgB3E,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;CA8DxF"}
|
package/distribution/factory.js
CHANGED
|
@@ -7,23 +7,18 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
11
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var _BlockFactory_instances, _BlockFactory_fromSerialized, _BlockFactory_applySchema;
|
|
16
10
|
import { inject, injectable } from "@mainsail/container";
|
|
17
11
|
import { Contracts, Exceptions, Identifiers } from "@mainsail/contracts";
|
|
18
12
|
import { BigNumber } from "@mainsail/utils";
|
|
19
13
|
import { sealBlock } from "./block.js";
|
|
20
|
-
import {
|
|
14
|
+
import { HashFactory } from "./hash.factory.js";
|
|
21
15
|
let BlockFactory = class BlockFactory {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
serializer;
|
|
17
|
+
deserializer;
|
|
18
|
+
hashFactory;
|
|
19
|
+
validator;
|
|
25
20
|
async make(data, transactions) {
|
|
26
|
-
const block = { ...data,
|
|
21
|
+
const block = { ...data, hash: await this.hashFactory.make(data) };
|
|
27
22
|
const serialized = await this.serializer.serializeWithTransactions(data);
|
|
28
23
|
return sealBlock({
|
|
29
24
|
data: block,
|
|
@@ -32,73 +27,70 @@ let BlockFactory = class BlockFactory {
|
|
|
32
27
|
});
|
|
33
28
|
}
|
|
34
29
|
async fromHex(hex) {
|
|
35
|
-
return
|
|
30
|
+
return this.#fromSerialized(Buffer.from(hex, "hex"));
|
|
36
31
|
}
|
|
37
32
|
async fromBytes(buff) {
|
|
38
|
-
return
|
|
33
|
+
return this.#fromSerialized(buff);
|
|
39
34
|
}
|
|
40
35
|
async fromJson(json) {
|
|
41
36
|
// @ts-ignore
|
|
42
37
|
const data = { ...json };
|
|
43
|
-
data.
|
|
44
|
-
data.totalFee = BigNumber.make(data.totalFee);
|
|
38
|
+
data.fee = BigNumber.make(data.fee);
|
|
45
39
|
data.reward = BigNumber.make(data.reward);
|
|
46
40
|
if (data.transactions) {
|
|
47
41
|
for (const transaction of data.transactions) {
|
|
48
|
-
transaction.
|
|
49
|
-
transaction.fee = BigNumber.make(transaction.fee);
|
|
42
|
+
transaction.value = BigNumber.make(transaction.value);
|
|
50
43
|
transaction.nonce = BigNumber.make(transaction.nonce);
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
46
|
return this.fromData(data);
|
|
54
47
|
}
|
|
55
48
|
async fromData(data) {
|
|
56
|
-
await
|
|
49
|
+
await this.#applySchema(data);
|
|
57
50
|
const serialized = await this.serializer.serializeWithTransactions(data);
|
|
58
51
|
return sealBlock({
|
|
59
52
|
...(await this.deserializer.deserializeWithTransactions(serialized)),
|
|
60
53
|
serialized: serialized.toString("hex"),
|
|
61
54
|
});
|
|
62
55
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
serialized: serialized.toString("hex"),
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
_BlockFactory_applySchema = async function _BlockFactory_applySchema(data) {
|
|
77
|
-
const result = this.validator.validate("block", data);
|
|
78
|
-
if (!result.error) {
|
|
79
|
-
return result.value;
|
|
56
|
+
async #fromSerialized(serialized) {
|
|
57
|
+
const deserialized = await this.deserializer.deserializeWithTransactions(serialized);
|
|
58
|
+
const validated = await this.#applySchema(deserialized.data);
|
|
59
|
+
if (validated) {
|
|
60
|
+
deserialized.data = validated;
|
|
61
|
+
}
|
|
62
|
+
return sealBlock({
|
|
63
|
+
...deserialized,
|
|
64
|
+
serialized: serialized.toString("hex"),
|
|
65
|
+
});
|
|
80
66
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
fatal = true;
|
|
67
|
+
async #applySchema(data) {
|
|
68
|
+
const result = this.validator.validate("block", data);
|
|
69
|
+
if (!result.error) {
|
|
70
|
+
return result.value;
|
|
86
71
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
72
|
+
for (const error of result.errors ?? []) {
|
|
73
|
+
let fatal = false;
|
|
74
|
+
const match = error.instancePath.match(/\.transactions\[(\d+)]/);
|
|
75
|
+
if (match === null) {
|
|
76
|
+
fatal = true;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
const txIndex = match[1];
|
|
80
|
+
if (data.transactions) {
|
|
81
|
+
const tx = data.transactions[txIndex];
|
|
82
|
+
if (tx.id === undefined) {
|
|
83
|
+
fatal = true;
|
|
84
|
+
}
|
|
93
85
|
}
|
|
94
86
|
}
|
|
87
|
+
if (fatal) {
|
|
88
|
+
throw new Exceptions.BlockSchemaError(data.number, `Invalid data${error.instancePath ? " at " + error.instancePath : ""}: ` +
|
|
89
|
+
`${error.message}: ${JSON.stringify(error.data)}`);
|
|
90
|
+
}
|
|
95
91
|
}
|
|
96
|
-
|
|
97
|
-
throw new Exceptions.BlockSchemaError(data.height, `Invalid data${error.instancePath ? " at " + error.instancePath : ""}: ` +
|
|
98
|
-
`${error.message}: ${JSON.stringify(error.data)}`);
|
|
99
|
-
}
|
|
92
|
+
return result.value;
|
|
100
93
|
}
|
|
101
|
-
return result.value;
|
|
102
94
|
};
|
|
103
95
|
__decorate([
|
|
104
96
|
inject(Identifiers.Cryptography.Block.Serializer),
|
|
@@ -109,9 +101,9 @@ __decorate([
|
|
|
109
101
|
__metadata("design:type", Object)
|
|
110
102
|
], BlockFactory.prototype, "deserializer", void 0);
|
|
111
103
|
__decorate([
|
|
112
|
-
inject(Identifiers.Cryptography.Block.
|
|
113
|
-
__metadata("design:type",
|
|
114
|
-
], BlockFactory.prototype, "
|
|
104
|
+
inject(Identifiers.Cryptography.Block.HashFactory),
|
|
105
|
+
__metadata("design:type", HashFactory)
|
|
106
|
+
], BlockFactory.prototype, "hashFactory", void 0);
|
|
115
107
|
__decorate([
|
|
116
108
|
inject(Identifiers.Cryptography.Validator),
|
|
117
109
|
__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAS,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MA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AAW,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC;8BACpB,WAAW;iDAAC;AAG1B;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC;;+CACa;AAX5C,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CAkHxB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Contracts } from "@mainsail/contracts";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class HashFactory {
|
|
3
3
|
private readonly hashFactory;
|
|
4
4
|
private readonly serializer;
|
|
5
5
|
make(data: Contracts.Crypto.BlockDataSerializable): Promise<string>;
|
|
6
6
|
}
|
|
7
|
-
//# sourceMappingURL=
|
|
7
|
+
//# sourceMappingURL=hash.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.factory.d.ts","sourceRoot":"","sources":["../source/hash.factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAE7D,qBACa,WAAW;IAEvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgC;IAG5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAElD,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;CAGhF"}
|
|
@@ -9,7 +9,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { inject, injectable } from "@mainsail/container";
|
|
11
11
|
import { Contracts, Identifiers } from "@mainsail/contracts";
|
|
12
|
-
let
|
|
12
|
+
let HashFactory = class HashFactory {
|
|
13
|
+
hashFactory;
|
|
14
|
+
serializer;
|
|
13
15
|
async make(data) {
|
|
14
16
|
return (await this.hashFactory.sha256(await this.serializer.serializeHeader(data))).toString("hex");
|
|
15
17
|
}
|
|
@@ -17,13 +19,13 @@ let IDFactory = class IDFactory {
|
|
|
17
19
|
__decorate([
|
|
18
20
|
inject(Identifiers.Cryptography.Hash.Factory),
|
|
19
21
|
__metadata("design:type", Object)
|
|
20
|
-
],
|
|
22
|
+
], HashFactory.prototype, "hashFactory", void 0);
|
|
21
23
|
__decorate([
|
|
22
24
|
inject(Identifiers.Cryptography.Block.Serializer),
|
|
23
25
|
__metadata("design:type", Object)
|
|
24
|
-
],
|
|
25
|
-
|
|
26
|
+
], HashFactory.prototype, "serializer", void 0);
|
|
27
|
+
HashFactory = __decorate([
|
|
26
28
|
injectable()
|
|
27
|
-
],
|
|
28
|
-
export {
|
|
29
|
-
//# sourceMappingURL=
|
|
29
|
+
], HashFactory);
|
|
30
|
+
export { HashFactory };
|
|
31
|
+
//# sourceMappingURL=hash.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.factory.js","sourceRoot":"","sources":["../source/hash.factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGtD,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEN,WAAW,CAAgC;IAG3C,UAAU,CAAoC;IAExD,KAAK,CAAC,IAAI,CAAC,IAA4C;QAC7D,OAAO,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrG,CAAC;CACD,CAAA;AARiB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;;gDACc;AAG3C;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;+CACa;AALnD,WAAW;IADvB,UAAU,EAAE;GACA,WAAW,CAUvB"}
|
package/distribution/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Providers } from "@mainsail/kernel";
|
|
2
2
|
export * from "./deserializer.js";
|
|
3
3
|
export * from "./factory.js";
|
|
4
|
-
export * from "./
|
|
4
|
+
export * from "./hash.factory.js";
|
|
5
5
|
export * from "./schemas.js";
|
|
6
6
|
export * from "./serializer.js";
|
|
7
|
-
export * from "./verifier.js";
|
|
8
7
|
export declare class ServiceProvider extends Providers.ServiceProvider {
|
|
9
8
|
register(): Promise<void>;
|
|
10
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAQ7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAEhC,qBACa,eAAgB,SAAQ,SAAS,CAAC,eAAe;IAChD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAgCtC"}
|
package/distribution/index.js
CHANGED
|
@@ -1,27 +1,53 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { injectable } from "@mainsail/container";
|
|
1
8
|
import { Identifiers } from "@mainsail/contracts";
|
|
2
9
|
import { Providers } from "@mainsail/kernel";
|
|
3
10
|
import { Deserializer } from "./deserializer.js";
|
|
4
11
|
import { BlockFactory } from "./factory.js";
|
|
5
|
-
import {
|
|
12
|
+
import { HashFactory } from "./hash.factory.js";
|
|
6
13
|
import { schemas } from "./schemas.js";
|
|
7
14
|
import { Serializer } from "./serializer.js";
|
|
8
|
-
import { Verifier } from "./verifier.js";
|
|
9
15
|
export * from "./deserializer.js";
|
|
10
16
|
export * from "./factory.js";
|
|
11
|
-
export * from "./
|
|
17
|
+
export * from "./hash.factory.js";
|
|
12
18
|
export * from "./schemas.js";
|
|
13
19
|
export * from "./serializer.js";
|
|
14
|
-
|
|
15
|
-
export class ServiceProvider extends Providers.ServiceProvider {
|
|
20
|
+
let ServiceProvider = class ServiceProvider extends Providers.ServiceProvider {
|
|
16
21
|
async register() {
|
|
22
|
+
this.app.bind(Identifiers.Cryptography.Block.HeaderSize).toConstantValue(() => {
|
|
23
|
+
const hashByteLength = this.app.get(Identifiers.Cryptography.Hash.Size.SHA256);
|
|
24
|
+
const generatorAddressByteLength = this.app.get(Identifiers.Cryptography.Identity.Address.Size);
|
|
25
|
+
return (1 + // version
|
|
26
|
+
6 + // timestamp
|
|
27
|
+
4 + // height
|
|
28
|
+
4 + // round
|
|
29
|
+
hashByteLength + // previousBlock
|
|
30
|
+
hashByteLength + // stateRoot
|
|
31
|
+
256 + // logsBloom
|
|
32
|
+
2 + // transactionsCount
|
|
33
|
+
4 + // totalGasUsed
|
|
34
|
+
32 + // totalFee
|
|
35
|
+
32 + // reward
|
|
36
|
+
4 + // payloadLength
|
|
37
|
+
hashByteLength + // payloadHash
|
|
38
|
+
generatorAddressByteLength);
|
|
39
|
+
});
|
|
17
40
|
this.app.bind(Identifiers.Cryptography.Block.Deserializer).to(Deserializer).inSingletonScope();
|
|
18
41
|
this.app.bind(Identifiers.Cryptography.Block.Factory).to(BlockFactory).inSingletonScope();
|
|
19
|
-
this.app.bind(Identifiers.Cryptography.Block.
|
|
42
|
+
this.app.bind(Identifiers.Cryptography.Block.HashFactory).to(HashFactory).inSingletonScope();
|
|
20
43
|
this.app.bind(Identifiers.Cryptography.Block.Serializer).to(Serializer).inSingletonScope();
|
|
21
|
-
this.app.bind(Identifiers.Cryptography.Block.Verifier).to(Verifier).inSingletonScope();
|
|
22
44
|
for (const schema of Object.values(schemas)) {
|
|
23
45
|
this.app.get(Identifiers.Cryptography.Validator).addSchema(schema);
|
|
24
46
|
}
|
|
25
47
|
}
|
|
26
|
-
}
|
|
48
|
+
};
|
|
49
|
+
ServiceProvider = __decorate([
|
|
50
|
+
injectable()
|
|
51
|
+
], ServiceProvider);
|
|
52
|
+
export { ServiceProvider };
|
|
27
53
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAa,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;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AC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAC1F,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAC7F,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAE3F,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,IAAI,CAAC,GAAG,CAAC,GAAG,CAA6B,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAChG,CAAC;IACF,CAAC;CACD,CAAA;AAjCY,eAAe;IAD3B,UAAU,EAAE;GACA,eAAe,CAiC3B"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AnySchemaObject } from "ajv";
|
|
2
|
-
export declare const schemas: Record<"block" | "
|
|
2
|
+
export declare const schemas: Record<"block" | "blockHash" | "prefixedBlockHash" | "blockHeader" | "logsBloom", AnySchemaObject>;
|
|
3
3
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAEtC,eAAO,MAAM,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAEtC,eAAO,MAAM,OAAO,EAAE,MAAM,CAC3B,OAAO,GAAG,WAAW,GAAG,mBAAmB,GAAG,aAAa,GAAG,WAAW,EACzE,eAAe,CAoFf,CAAC"}
|
package/distribution/schemas.js
CHANGED
|
@@ -5,52 +5,78 @@ export const schemas = {
|
|
|
5
5
|
properties: {
|
|
6
6
|
transactions: {
|
|
7
7
|
$ref: "transactions",
|
|
8
|
-
maxItems: { $data: "1/
|
|
9
|
-
minItems: { $data: "1/
|
|
8
|
+
maxItems: { $data: "1/transactionsCount" },
|
|
9
|
+
minItems: { $data: "1/transactionsCount" },
|
|
10
10
|
type: "array",
|
|
11
11
|
},
|
|
12
12
|
},
|
|
13
13
|
type: "object",
|
|
14
14
|
},
|
|
15
|
+
blockHash: {
|
|
16
|
+
$id: "blockHash",
|
|
17
|
+
allOf: [
|
|
18
|
+
{
|
|
19
|
+
$ref: "hex",
|
|
20
|
+
maxLength: 64,
|
|
21
|
+
minLength: 64,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
type: "string",
|
|
25
|
+
},
|
|
15
26
|
blockHeader: {
|
|
16
27
|
$id: "blockHeader",
|
|
17
28
|
properties: {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
fee: { bignumber: { minimum: 0 } },
|
|
30
|
+
gasUsed: { minimum: 0, type: "integer" },
|
|
31
|
+
hash: { $ref: "blockHash" },
|
|
32
|
+
logsBloom: { $ref: "logsBloom" },
|
|
33
|
+
number: { minimum: 0, type: "integer" },
|
|
34
|
+
parentHash: { $ref: "blockHash" },
|
|
35
|
+
payloadSize: { minimum: 0, type: "integer" },
|
|
36
|
+
proposer: { $ref: "address" },
|
|
25
37
|
reward: { bignumber: { minimum: 0 } },
|
|
26
|
-
|
|
38
|
+
stateRoot: { $ref: "hex" },
|
|
27
39
|
timestamp: { maximum: 2 ** 48 - 1, minimum: 0, type: "integer" },
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
totalGasUsed: { minimum: 0, type: "integer" },
|
|
40
|
+
transactionsCount: { minimum: 0, type: "integer" },
|
|
41
|
+
transactionsRoot: { $ref: "hex" },
|
|
31
42
|
version: { enum: [1] },
|
|
32
43
|
},
|
|
33
44
|
required: [
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
45
|
+
"fee",
|
|
46
|
+
"gasUsed",
|
|
47
|
+
"hash",
|
|
48
|
+
"logsBloom",
|
|
49
|
+
"number",
|
|
50
|
+
"parentHash",
|
|
51
|
+
"payloadSize",
|
|
52
|
+
"proposer",
|
|
42
53
|
"reward",
|
|
43
|
-
"
|
|
54
|
+
"stateRoot",
|
|
55
|
+
"timestamp",
|
|
56
|
+
"transactionsCount",
|
|
57
|
+
"transactionsRoot",
|
|
58
|
+
"version",
|
|
44
59
|
],
|
|
45
60
|
type: "object",
|
|
46
61
|
},
|
|
47
|
-
|
|
48
|
-
$id: "
|
|
62
|
+
logsBloom: {
|
|
63
|
+
$id: "logsBloom",
|
|
49
64
|
allOf: [
|
|
50
65
|
{
|
|
51
66
|
$ref: "hex",
|
|
52
|
-
maxLength:
|
|
53
|
-
minLength:
|
|
67
|
+
maxLength: 512,
|
|
68
|
+
minLength: 512,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
type: "string",
|
|
72
|
+
},
|
|
73
|
+
prefixedBlockHash: {
|
|
74
|
+
$id: "prefixedBlockHash",
|
|
75
|
+
allOf: [
|
|
76
|
+
{
|
|
77
|
+
$ref: "prefixedQuantityHex",
|
|
78
|
+
maxLength: 66,
|
|
79
|
+
minLength: 66,
|
|
54
80
|
},
|
|
55
81
|
],
|
|
56
82
|
type: "string",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAEA,MAA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E,EAAE,IAAI,EAAE,KAAK,EAAE;YAC1B,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE;YAChE,iBAAiB,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE;YAClD,gBAAgB,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;YACjC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;SACtB;QACD,QAAQ,EAAE;YACT,KAAK;YACL,SAAS;YACT,MAAM;YACN,WAAW;YACX,QAAQ;YACR,YAAY;YACZ,aAAa;YACb,UAAU;YACV,QAAQ;YACR,WAAW;YACX,WAAW;YACX,mBAAmB;YACnB,kBAAkB;YAClB,SAAS;SACT;QACD,IAAI,EAAE,QAAQ;KACd;IACD,SAAS,EAAE;QACV,GAAG,EAAE,WAAW;QAChB,KAAK,EAAE;YACN;gBACC,IAAI,EAAE,KAAK;gBACX,SAAS,EAAE,GAAG;gBACd,SAAS,EAAE,GAAG;aACd;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,iBAAiB,EAAE;QAClB,GAAG,EAAE,mBAAmB;QACxB,KAAK,EAAE;YACN;gBACC,IAAI,EAAE,qBAAqB;gBAC3B,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;CACD,CAAC"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { Contracts } from "@mainsail/contracts";
|
|
3
2
|
export declare class Serializer implements Contracts.Crypto.BlockSerializer {
|
|
4
3
|
private readonly serializer;
|
|
5
|
-
private readonly
|
|
6
|
-
private readonly generatorAddressByteLength;
|
|
7
|
-
headerSize(): number;
|
|
4
|
+
private readonly headerSize;
|
|
8
5
|
totalSize(block: Contracts.Crypto.BlockDataSerializable): number;
|
|
9
6
|
serializeHeader(block: Contracts.Crypto.BlockDataSerializable): Promise<Buffer>;
|
|
10
7
|
serializeWithTransactions(block: Contracts.Crypto.BlockDataSerializable): Promise<Buffer>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../source/serializer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../source/serializer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAE7D,qBACa,UAAW,YAAW,SAAS,CAAC,MAAM,CAAC,eAAe;IAElE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAG9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAEpC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,qBAAqB,GAAG,MAAM;IAI1D,eAAe,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;IAmD/E,yBAAyB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;CAqDtG"}
|
|
@@ -8,27 +8,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
11
|
-
import { inject, injectable
|
|
11
|
+
import { inject, injectable } from "@mainsail/container";
|
|
12
12
|
import { Contracts, Identifiers } from "@mainsail/contracts";
|
|
13
13
|
let Serializer = class Serializer {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
6 + // timestamp
|
|
17
|
-
4 + // height
|
|
18
|
-
4 + // round
|
|
19
|
-
this.hashByteLength + // previousBlock
|
|
20
|
-
this.hashByteLength + // stateHash
|
|
21
|
-
2 + // numberOfTransactions
|
|
22
|
-
4 + // totalGasUsed
|
|
23
|
-
32 + // totalAmount
|
|
24
|
-
32 + // totalFee
|
|
25
|
-
32 + // reward
|
|
26
|
-
4 + // payloadLength
|
|
27
|
-
this.hashByteLength + // payloadHash
|
|
28
|
-
this.generatorAddressByteLength);
|
|
29
|
-
}
|
|
14
|
+
serializer;
|
|
15
|
+
headerSize;
|
|
30
16
|
totalSize(block) {
|
|
31
|
-
return this.headerSize() + block.
|
|
17
|
+
return this.headerSize() + block.payloadSize;
|
|
32
18
|
}
|
|
33
19
|
async serializeHeader(block) {
|
|
34
20
|
return this.serializer.serialize(block, {
|
|
@@ -41,40 +27,40 @@ let Serializer = class Serializer {
|
|
|
41
27
|
timestamp: {
|
|
42
28
|
type: "uint48",
|
|
43
29
|
},
|
|
44
|
-
|
|
30
|
+
number: {
|
|
45
31
|
type: "uint32",
|
|
46
32
|
},
|
|
47
33
|
round: {
|
|
48
34
|
type: "uint32",
|
|
49
35
|
},
|
|
50
|
-
|
|
36
|
+
parentHash: {
|
|
37
|
+
type: "hash",
|
|
38
|
+
},
|
|
39
|
+
stateRoot: {
|
|
51
40
|
type: "hash",
|
|
52
41
|
},
|
|
53
|
-
|
|
42
|
+
logsBloom: {
|
|
54
43
|
type: "hash",
|
|
55
44
|
},
|
|
56
|
-
|
|
45
|
+
transactionsCount: {
|
|
57
46
|
type: "uint16",
|
|
58
47
|
},
|
|
59
|
-
|
|
48
|
+
gasUsed: {
|
|
60
49
|
type: "uint32",
|
|
61
50
|
},
|
|
62
|
-
|
|
63
|
-
type: "uint256",
|
|
64
|
-
},
|
|
65
|
-
totalFee: {
|
|
51
|
+
fee: {
|
|
66
52
|
type: "uint256",
|
|
67
53
|
},
|
|
68
54
|
reward: {
|
|
69
55
|
type: "uint256",
|
|
70
56
|
},
|
|
71
|
-
|
|
57
|
+
payloadSize: {
|
|
72
58
|
type: "uint32",
|
|
73
59
|
},
|
|
74
|
-
|
|
60
|
+
transactionsRoot: {
|
|
75
61
|
type: "hash",
|
|
76
62
|
},
|
|
77
|
-
|
|
63
|
+
proposer: {
|
|
78
64
|
type: "address",
|
|
79
65
|
},
|
|
80
66
|
},
|
|
@@ -91,40 +77,40 @@ let Serializer = class Serializer {
|
|
|
91
77
|
timestamp: {
|
|
92
78
|
type: "uint48",
|
|
93
79
|
},
|
|
94
|
-
|
|
80
|
+
number: {
|
|
95
81
|
type: "uint32",
|
|
96
82
|
},
|
|
97
83
|
round: {
|
|
98
84
|
type: "uint32",
|
|
99
85
|
},
|
|
100
|
-
|
|
86
|
+
parentHash: {
|
|
101
87
|
type: "hash",
|
|
102
88
|
},
|
|
103
|
-
|
|
89
|
+
stateRoot: {
|
|
104
90
|
type: "hash",
|
|
105
91
|
},
|
|
106
|
-
|
|
92
|
+
logsBloom: {
|
|
93
|
+
type: "hash",
|
|
94
|
+
},
|
|
95
|
+
transactionsCount: {
|
|
107
96
|
type: "uint16",
|
|
108
97
|
},
|
|
109
|
-
|
|
98
|
+
gasUsed: {
|
|
110
99
|
type: "uint32",
|
|
111
100
|
},
|
|
112
|
-
|
|
113
|
-
type: "uint256",
|
|
114
|
-
},
|
|
115
|
-
totalFee: {
|
|
101
|
+
fee: {
|
|
116
102
|
type: "uint256",
|
|
117
103
|
},
|
|
118
104
|
reward: {
|
|
119
105
|
type: "uint256",
|
|
120
106
|
},
|
|
121
|
-
|
|
107
|
+
payloadSize: {
|
|
122
108
|
type: "uint32",
|
|
123
109
|
},
|
|
124
|
-
|
|
110
|
+
transactionsRoot: {
|
|
125
111
|
type: "hash",
|
|
126
112
|
},
|
|
127
|
-
|
|
113
|
+
proposer: {
|
|
128
114
|
type: "address",
|
|
129
115
|
},
|
|
130
116
|
transactions: {
|
|
@@ -136,17 +122,12 @@ let Serializer = class Serializer {
|
|
|
136
122
|
};
|
|
137
123
|
__decorate([
|
|
138
124
|
inject(Identifiers.Cryptography.Serializer),
|
|
139
|
-
tagged("type", "wallet"),
|
|
140
125
|
__metadata("design:type", Object)
|
|
141
126
|
], Serializer.prototype, "serializer", void 0);
|
|
142
127
|
__decorate([
|
|
143
|
-
inject(Identifiers.Cryptography.
|
|
144
|
-
__metadata("design:type",
|
|
145
|
-
], Serializer.prototype, "
|
|
146
|
-
__decorate([
|
|
147
|
-
inject(Identifiers.Cryptography.Identity.Address.Size),
|
|
148
|
-
__metadata("design:type", Number)
|
|
149
|
-
], Serializer.prototype, "generatorAddressByteLength", void 0);
|
|
128
|
+
inject(Identifiers.Cryptography.Block.HeaderSize),
|
|
129
|
+
__metadata("design:type", Function)
|
|
130
|
+
], Serializer.prototype, "headerSize", void 0);
|
|
150
131
|
Serializer = __decorate([
|
|
151
132
|
injectable()
|
|
152
133
|
], Serializer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../source/serializer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gDAAgD;AAChD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../source/serializer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gDAAgD;AAChD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGtD,IAAM,UAAU,GAAhB,MAAM,UAAU;IAEL,UAAU,CAAmC;IAG7C,UAAU,CAAgB;IAEpC,SAAS,CAAC,KAA6C;QAC7D,OAAO,IAAI,CAAC,UAAU,EAAE,GAAG,KAAK,CAAC,WAAW,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,KAA6C;QACzE,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAyC,KAAK,EAAE;YAC/E,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE;YACzB,IAAI,EAAE,CAAC;YACP,MAAM,EAAE;gB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,EAAE;oBACV,IAAI,EAAE,MAAM;iBACZ;gBACD,iBAAiB,EAAE;oBAClB,IAAI,EAAE,QAAQ;iBACd;gBACD,OAAO,EAAE;oBACR,IAAI,EAAE,QAAQ;iBACd;gBACD,GAAG,EAAE;oBACJ,IAAI,EAAE,SAAS;iBACf;gBACD,MAAM,EAAE;oBACP,IAAI,EAAE,SAAS;iBACf;gBACD,WAAW,EAAE;oBACZ,IAAI,EAAE,QAAQ;iBACd;gBACD,gBAAgB,EAAE;oBACjB,IAAI,EAAE,MAAM;iBACZ;gBACD,QAAQ,EAAE;oBACT,IAAI,EAAE,SAAS;iBACf;gBACD,YAAY,EAAE;oBACb,IAAI,EAAE,cAAc;iBACpB;aACD;SACD,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAjHiB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC;;8CACkB;AAG7C;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;8CACP;AAL/B,UAAU;IADtB,UAAU,EAAE;GACA,UAAU,CAmHtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mainsail/crypto-block",
|
|
3
|
-
"version": "0.0.1-evm.
|
|
3
|
+
"version": "0.0.1-evm.30",
|
|
4
4
|
"description": "Block utilities for the Mainsail blockchain",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"contributors": [],
|
|
@@ -11,39 +11,42 @@
|
|
|
11
11
|
"/distribution"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"ajv": "8.
|
|
15
|
-
"@mainsail/
|
|
16
|
-
"@mainsail/
|
|
17
|
-
"@mainsail/
|
|
18
|
-
"@mainsail/
|
|
19
|
-
"@mainsail/utils": "0.0.1-evm.
|
|
14
|
+
"ajv": "8.17.1",
|
|
15
|
+
"@mainsail/contracts": "0.0.1-evm.30",
|
|
16
|
+
"@mainsail/crypto-transaction": "0.0.1-evm.30",
|
|
17
|
+
"@mainsail/kernel": "0.0.1-evm.30",
|
|
18
|
+
"@mainsail/container": "0.0.1-evm.30",
|
|
19
|
+
"@mainsail/utils": "0.0.1-evm.30"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@types/lodash.clone": "
|
|
23
|
-
"lodash.
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"@mainsail/crypto-
|
|
28
|
-
"@mainsail/crypto-
|
|
29
|
-
"@mainsail/crypto-hash-bcrypto": "0.0.1-evm.
|
|
30
|
-
"@mainsail/crypto-
|
|
31
|
-
"@mainsail/crypto-
|
|
32
|
-
"@mainsail/crypto-
|
|
33
|
-
"@mainsail/
|
|
34
|
-
"@mainsail/
|
|
35
|
-
"@mainsail/crypto-
|
|
22
|
+
"@types/lodash.clone": "4.5.9",
|
|
23
|
+
"@types/lodash.clonedeep": "4.5.9",
|
|
24
|
+
"lodash.clone": "4.5.0",
|
|
25
|
+
"lodash.clonedeep": "4.5.0",
|
|
26
|
+
"uvu": "0.5.6",
|
|
27
|
+
"@mainsail/crypto-address-base58": "0.0.1-evm.30",
|
|
28
|
+
"@mainsail/crypto-address-keccak256": "0.0.1-evm.30",
|
|
29
|
+
"@mainsail/crypto-hash-bcrypto": "0.0.1-evm.30",
|
|
30
|
+
"@mainsail/crypto-key-pair-ecdsa": "0.0.1-evm.30",
|
|
31
|
+
"@mainsail/crypto-consensus-bls12-381": "0.0.1-evm.30",
|
|
32
|
+
"@mainsail/crypto-config": "0.0.1-evm.30",
|
|
33
|
+
"@mainsail/crypto-signature-ecdsa": "0.0.1-evm.30",
|
|
34
|
+
"@mainsail/crypto-transaction-evm-call": "0.0.1-evm.30",
|
|
35
|
+
"@mainsail/crypto-validation": "0.0.1-evm.30",
|
|
36
|
+
"@mainsail/serializer": "0.0.1-evm.30",
|
|
37
|
+
"@mainsail/validation": "0.0.1-evm.30",
|
|
38
|
+
"@mainsail/crypto-wif": "0.0.1-evm.30"
|
|
36
39
|
},
|
|
37
40
|
"engines": {
|
|
38
41
|
"node": ">=20.x"
|
|
39
42
|
},
|
|
40
43
|
"scripts": {
|
|
41
|
-
"build": "
|
|
44
|
+
"build": "tsc -b",
|
|
42
45
|
"build:watch": "pnpm run clean && tsc -w",
|
|
43
|
-
"clean": "del distribution",
|
|
46
|
+
"clean": "del distribution && del tsconfig.tsbuildinfo",
|
|
44
47
|
"release": "pnpm publish --access public",
|
|
45
48
|
"test": "pnpm run uvu source .test.ts",
|
|
46
|
-
"test:coverage": "c8 pnpm run test",
|
|
49
|
+
"test:coverage": "c8 -r=text -r=lcov --all pnpm run test",
|
|
47
50
|
"test:coverage:html": "c8 -r html --all pnpm run test",
|
|
48
51
|
"test:file": "pnpm run uvu source",
|
|
49
52
|
"uvu": "tsx --tsconfig ../../tsconfig.test.json ./node_modules/uvu/bin.js"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"id.factory.d.ts","sourceRoot":"","sources":["../source/id.factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAE7D,qBACa,SAAS;IAErB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgC;IAG5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAElD,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;CAGhF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"id.factory.js","sourceRoot":"","sources":["../source/id.factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGtD,IAAM,SAAS,GAAf,MAAM,SAAS;IAOd,KAAK,CAAC,IAAI,CAAC,IAA4C;QAC7D,OAAO,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrG,CAAC;CACD,CAAA;AARiB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;;8CACc;AAG3C;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;6CACa;AALnD,SAAS;IADrB,UAAU,EAAE;GACA,SAAS,CAUrB"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Contracts } from "@mainsail/contracts";
|
|
2
|
-
export declare class Verifier implements Contracts.Crypto.BlockVerifier {
|
|
3
|
-
private readonly configuration;
|
|
4
|
-
private readonly serializer;
|
|
5
|
-
private readonly hashFactory;
|
|
6
|
-
verify(block: Contracts.Crypto.Block): Promise<Contracts.Crypto.BlockVerification>;
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=verifier.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"verifier.d.ts","sourceRoot":"","sources":["../source/verifier.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAsB,MAAM,qBAAqB,CAAC;AAGpE,qBACa,QAAS,YAAW,SAAS,CAAC,MAAM,CAAC,aAAa;IAE9D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;IAGhE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAG/D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgC;IAE/C,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC;CAsH/F"}
|
package/distribution/verifier.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { inject, injectable } from "@mainsail/container";
|
|
11
|
-
import { Contracts, Identifiers } from "@mainsail/contracts";
|
|
12
|
-
import { BigNumber } from "@mainsail/utils";
|
|
13
|
-
let Verifier = class Verifier {
|
|
14
|
-
async verify(block) {
|
|
15
|
-
const blockData = block.data;
|
|
16
|
-
const result = {
|
|
17
|
-
containsMultiSignatures: false,
|
|
18
|
-
errors: [],
|
|
19
|
-
verified: false,
|
|
20
|
-
};
|
|
21
|
-
try {
|
|
22
|
-
const constants = this.configuration.getMilestone(blockData.height);
|
|
23
|
-
if (blockData.height === 0 &&
|
|
24
|
-
blockData.previousBlock !== "0000000000000000000000000000000000000000000000000000000000000000") {
|
|
25
|
-
result.errors.push("Genesis block has invalid previous block");
|
|
26
|
-
}
|
|
27
|
-
if (blockData.height !== 0 && !blockData.previousBlock) {
|
|
28
|
-
result.errors.push("Invalid previous block");
|
|
29
|
-
}
|
|
30
|
-
if (!blockData.reward.isEqualTo(constants.reward)) {
|
|
31
|
-
result.errors.push(["Invalid block reward:", blockData.reward, "expected:", constants.reward].join(" "));
|
|
32
|
-
}
|
|
33
|
-
if (blockData.version !== constants.block.version) {
|
|
34
|
-
result.errors.push("Invalid block version");
|
|
35
|
-
}
|
|
36
|
-
const headerSize = this.serializer.headerSize();
|
|
37
|
-
const totalSize = headerSize + block.header.payloadLength;
|
|
38
|
-
if (totalSize > constants.block.maxPayload) {
|
|
39
|
-
result.errors.push(`Payload is too large: ${totalSize} > ${constants.block.maxPayload}`);
|
|
40
|
-
}
|
|
41
|
-
if (totalSize !== Buffer.byteLength(block.serialized, "hex")) {
|
|
42
|
-
result.errors.push("Serialized payload size mismatch");
|
|
43
|
-
}
|
|
44
|
-
if (blockData.totalGasUsed > constants.block.maxGasLimit && blockData.height > 0) {
|
|
45
|
-
result.errors.push(`Total gas used ${blockData.totalGasUsed} exceeds max gas limit ${constants.block.maxGasLimit}`);
|
|
46
|
-
}
|
|
47
|
-
if (block.transactions.length !== blockData.numberOfTransactions) {
|
|
48
|
-
result.errors.push("Invalid number of transactions");
|
|
49
|
-
}
|
|
50
|
-
if (block.transactions.length > constants.block.maxTransactions && blockData.height > 0) {
|
|
51
|
-
result.errors.push("Transactions length is too high");
|
|
52
|
-
}
|
|
53
|
-
// Checking if transactions of the block adds up to block values.
|
|
54
|
-
const appliedTransactions = {};
|
|
55
|
-
let totalAmount = BigNumber.ZERO;
|
|
56
|
-
let totalFee = BigNumber.ZERO;
|
|
57
|
-
// The initial payload length takes the overhead for each serialized transaction into account
|
|
58
|
-
// which is a uint16 per transaction to store the individual length.
|
|
59
|
-
let totalPayloadLength = block.transactions.length * 2;
|
|
60
|
-
const payloadBuffers = [];
|
|
61
|
-
for (const transaction of block.transactions) {
|
|
62
|
-
if (!transaction || !transaction.id) {
|
|
63
|
-
throw new Error();
|
|
64
|
-
}
|
|
65
|
-
const bytes = Buffer.from(transaction.id, "hex");
|
|
66
|
-
if (appliedTransactions[transaction.id]) {
|
|
67
|
-
result.errors.push(`Encountered duplicate transaction: ${transaction.id}`);
|
|
68
|
-
}
|
|
69
|
-
if (transaction.data.expiration &&
|
|
70
|
-
transaction.data.expiration > 0 &&
|
|
71
|
-
transaction.data.expiration <= blockData.height) {
|
|
72
|
-
result.errors.push(`Encountered expired transaction: ${transaction.id}`);
|
|
73
|
-
}
|
|
74
|
-
appliedTransactions[transaction.id] = transaction.data;
|
|
75
|
-
totalAmount = totalAmount.plus(transaction.data.amount);
|
|
76
|
-
totalFee = totalFee.plus(transaction.data.fee);
|
|
77
|
-
totalPayloadLength += transaction.serialized.byteLength;
|
|
78
|
-
payloadBuffers.push(bytes);
|
|
79
|
-
}
|
|
80
|
-
if (!totalAmount.isEqualTo(blockData.totalAmount)) {
|
|
81
|
-
result.errors.push("Invalid total amount");
|
|
82
|
-
}
|
|
83
|
-
if (!totalFee.isEqualTo(blockData.totalFee)) {
|
|
84
|
-
result.errors.push("Invalid total fee");
|
|
85
|
-
}
|
|
86
|
-
if (totalPayloadLength !== blockData.payloadLength) {
|
|
87
|
-
result.errors.push("Invalid payload length");
|
|
88
|
-
}
|
|
89
|
-
if ((await this.hashFactory.sha256(payloadBuffers)).toString("hex") !== blockData.payloadHash) {
|
|
90
|
-
result.errors.push("Invalid payload hash");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
result.errors.push(error);
|
|
95
|
-
}
|
|
96
|
-
result.verified = result.errors.length === 0;
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
__decorate([
|
|
101
|
-
inject(Identifiers.Cryptography.Configuration),
|
|
102
|
-
__metadata("design:type", Object)
|
|
103
|
-
], Verifier.prototype, "configuration", void 0);
|
|
104
|
-
__decorate([
|
|
105
|
-
inject(Identifiers.Cryptography.Block.Serializer),
|
|
106
|
-
__metadata("design:type", Object)
|
|
107
|
-
], Verifier.prototype, "serializer", void 0);
|
|
108
|
-
__decorate([
|
|
109
|
-
inject(Identifiers.Cryptography.Hash.Factory),
|
|
110
|
-
__metadata("design:type", Object)
|
|
111
|
-
], Verifier.prototype, "hashFactory", void 0);
|
|
112
|
-
Verifier = __decorate([
|
|
113
|
-
injectable()
|
|
114
|
-
], Verifier);
|
|
115
|
-
export { Verifier };
|
|
116
|
-
//# sourceMappingURL=verifier.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"verifier.js","sourceRoot":"","sources":["../source/verifier.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAS,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGrC,IAAM,QAAQ,GAAd,MAAM,QAAQ;IAUb,KAAK,CAAC,MAAM,CAAC,KAA6B;QAChD,MAAM,SAAS,GAA+B,KAAK,CAAC,IAAI,CAAC;QACzD,MAAM,MAAM,GAAsD;YACjE,uBAAuB,EAAE,KAAK;YAC9B,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,KAAK;SACf,CAAC;QAEF,IAAI,CAAC;YACJ,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAEpE,IACC,SAAS,CAAC,MAAM,KAAK,CAAC;gBACtB,SAAS,CAAC,aAAa,KAAK,kEAAkE,EAC7F,CAAC;gBACF,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;YAChE,CAAC;YAED,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC;gBACxD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;YAC9C,CAAC;YAED,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;gBACnD,MAAM,CAAC,MAAM,CAAC,IAAI,CACjB,CAAC,uBAAuB,EAAE,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,C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