@mainsail/crypto-block 0.0.1-alpha.9 → 0.0.1-evm.10
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.js +1 -5
- package/distribution/block.js.map +1 -1
- package/distribution/deserializer.d.ts +1 -1
- package/distribution/deserializer.d.ts.map +1 -1
- package/distribution/deserializer.js +31 -24
- package/distribution/deserializer.js.map +1 -1
- package/distribution/factory.d.ts +2 -2
- package/distribution/factory.d.ts.map +1 -1
- package/distribution/factory.js +29 -29
- package/distribution/factory.js.map +1 -1
- package/distribution/id.factory.js +7 -10
- package/distribution/id.factory.js.map +1 -1
- package/distribution/index.d.ts +6 -7
- package/distribution/index.d.ts.map +1 -1
- package/distribution/index.js +22 -43
- package/distribution/index.js.map +1 -1
- package/distribution/schemas.d.ts.map +1 -1
- package/distribution/schemas.js +7 -6
- package/distribution/schemas.js.map +1 -1
- package/distribution/serializer.d.ts +2 -2
- package/distribution/serializer.d.ts.map +1 -1
- package/distribution/serializer.js +38 -28
- package/distribution/serializer.js.map +1 -1
- package/distribution/verifier.d.ts.map +1 -1
- package/distribution/verifier.js +34 -27
- package/distribution/verifier.js.map +1 -1
- package/package.json +21 -13
package/distribution/block.js
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.sealBlock = void 0;
|
4
|
-
const sealBlock = ({ data, serialized, transactions }) => Object.seal({
|
1
|
+
export const sealBlock = ({ data, serialized, transactions }) => Object.seal({
|
5
2
|
data,
|
6
3
|
header: data,
|
7
4
|
serialized,
|
@@ -10,5 +7,4 @@ const sealBlock = ({ data, serialized, transactions }) => Object.seal({
|
|
10
7
|
return transaction;
|
11
8
|
}),
|
12
9
|
});
|
13
|
-
exports.sealBlock = sealBlock;
|
14
10
|
//# sourceMappingURL=block.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"block.js","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"
|
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,QAAQ,GAAG,KAAK,CAAC;QAClC,OAAO,WAAW,CAAC;IACpB,CAAC,CAAC;CACF,CAAC,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAsB,MAAM,qBAAqB,CAAC;
|
1
|
+
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAsB,MAAM,qBAAqB,CAAC;AAOpE,qBACa,YAAa,YAAW,SAAS,CAAC,MAAM,CAAC,iBAAiB;;IAEtE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAa;IAGvC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAsB;IAGzD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAG9D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAoC;IAEvD,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;CAyG7G"}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
@@ -14,26 +13,25 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
14
13
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
15
14
|
};
|
16
15
|
var _Deserializer_instances, _Deserializer_deserializeBufferHeader, _Deserializer_deserializeTransactions;
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
-
exports.Deserializer = void 0;
|
19
16
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
import { inject, injectable } from "@mainsail/container";
|
18
|
+
import { Contracts, Identifiers } from "@mainsail/contracts";
|
19
|
+
import { TransactionFactory } from "@mainsail/crypto-transaction";
|
20
|
+
import { Utils as AppUtils } from "@mainsail/kernel";
|
21
|
+
import { ByteBuffer } from "@mainsail/utils";
|
22
|
+
import { IDFactory } from "./id.factory.js";
|
25
23
|
let Deserializer = class Deserializer {
|
26
24
|
constructor() {
|
27
25
|
_Deserializer_instances.add(this);
|
28
26
|
}
|
29
27
|
async deserializeHeader(serialized) {
|
30
|
-
const buffer =
|
28
|
+
const buffer = ByteBuffer.fromBuffer(serialized);
|
31
29
|
const header = await __classPrivateFieldGet(this, _Deserializer_instances, "m", _Deserializer_deserializeBufferHeader).call(this, buffer);
|
32
30
|
header.id = await this.idFactory.make(header);
|
33
31
|
return header;
|
34
32
|
}
|
35
33
|
async deserializeWithTransactions(serialized) {
|
36
|
-
const buffer =
|
34
|
+
const buffer = ByteBuffer.fromBuffer(serialized);
|
37
35
|
const block = await __classPrivateFieldGet(this, _Deserializer_instances, "m", _Deserializer_deserializeBufferHeader).call(this, buffer);
|
38
36
|
let transactions = [];
|
39
37
|
if (buffer.getRemainderLength() > 0) {
|
@@ -43,7 +41,6 @@ let Deserializer = class Deserializer {
|
|
43
41
|
return { data: block, transactions };
|
44
42
|
}
|
45
43
|
};
|
46
|
-
exports.Deserializer = Deserializer;
|
47
44
|
_Deserializer_instances = new WeakSet();
|
48
45
|
_Deserializer_deserializeBufferHeader = async function _Deserializer_deserializeBufferHeader(buffer) {
|
49
46
|
const block = {};
|
@@ -65,17 +62,23 @@ _Deserializer_deserializeBufferHeader = async function _Deserializer_deserialize
|
|
65
62
|
previousBlock: {
|
66
63
|
type: "hash",
|
67
64
|
},
|
65
|
+
stateHash: {
|
66
|
+
type: "hash",
|
67
|
+
},
|
68
68
|
numberOfTransactions: {
|
69
69
|
type: "uint16",
|
70
70
|
},
|
71
|
+
totalGasUsed: {
|
72
|
+
type: "uint32",
|
73
|
+
},
|
71
74
|
totalAmount: {
|
72
|
-
type: "
|
75
|
+
type: "uint256",
|
73
76
|
},
|
74
77
|
totalFee: {
|
75
|
-
type: "
|
78
|
+
type: "uint256",
|
76
79
|
},
|
77
80
|
reward: {
|
78
|
-
type: "
|
81
|
+
type: "uint256",
|
79
82
|
},
|
80
83
|
payloadLength: {
|
81
84
|
type: "uint32",
|
@@ -83,8 +86,8 @@ _Deserializer_deserializeBufferHeader = async function _Deserializer_deserialize
|
|
83
86
|
payloadHash: {
|
84
87
|
type: "hash",
|
85
88
|
},
|
86
|
-
|
87
|
-
type: "
|
89
|
+
generatorAddress: {
|
90
|
+
type: "address",
|
88
91
|
},
|
89
92
|
},
|
90
93
|
});
|
@@ -107,6 +110,9 @@ _Deserializer_deserializeTransactions = async function _Deserializer_deserialize
|
|
107
110
|
*/
|
108
111
|
const transactions = [];
|
109
112
|
for (let index = 0; index < block.transactions.length; index++) {
|
113
|
+
if (index % 20 === 0) {
|
114
|
+
await AppUtils.sleep(0);
|
115
|
+
}
|
110
116
|
const transaction = await this.transactionFactory.fromBytes(block.transactions[index]);
|
111
117
|
transactions.push(transaction);
|
112
118
|
block.transactions[index] = transaction.data;
|
@@ -114,22 +120,23 @@ _Deserializer_deserializeTransactions = async function _Deserializer_deserialize
|
|
114
120
|
return transactions;
|
115
121
|
};
|
116
122
|
__decorate([
|
117
|
-
|
118
|
-
__metadata("design:type",
|
123
|
+
inject(Identifiers.Cryptography.Block.IDFactory),
|
124
|
+
__metadata("design:type", IDFactory)
|
119
125
|
], Deserializer.prototype, "idFactory", void 0);
|
120
126
|
__decorate([
|
121
|
-
|
122
|
-
__metadata("design:type",
|
127
|
+
inject(Identifiers.Cryptography.Transaction.Factory),
|
128
|
+
__metadata("design:type", TransactionFactory)
|
123
129
|
], Deserializer.prototype, "transactionFactory", void 0);
|
124
130
|
__decorate([
|
125
|
-
|
131
|
+
inject(Identifiers.Cryptography.Serializer),
|
126
132
|
__metadata("design:type", Object)
|
127
133
|
], Deserializer.prototype, "serializer", void 0);
|
128
134
|
__decorate([
|
129
|
-
|
135
|
+
inject(Identifiers.Cryptography.Block.Serializer),
|
130
136
|
__metadata("design:type", Object)
|
131
137
|
], Deserializer.prototype, "blockSerializer", void 0);
|
132
|
-
|
133
|
-
|
138
|
+
Deserializer = __decorate([
|
139
|
+
injectable()
|
134
140
|
], Deserializer);
|
141
|
+
export { Deserializer };
|
135
142
|
//# sourceMappingURL=deserializer.js.map
|
@@ -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,OAA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C;QAChE,IAAI,KAAK,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzB,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAQ,CAAC,CAAC;QAE9F,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAE/B,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC;IAC9C,CAAC;IAED,OAAO,YAAY,CAAC;AACrB,CAAC;AA7HgB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC;8BACpB,SAAS;+CAAC;AAGtB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,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;;qDACkB;AAXxD,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CAgIxB"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/// <reference types="node" />
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
2
2
|
import { Contracts, Utils } from "@mainsail/contracts";
|
3
3
|
export declare class BlockFactory implements Contracts.Crypto.BlockFactory {
|
4
4
|
#private;
|
@@ -6,7 +6,7 @@ export declare class BlockFactory implements Contracts.Crypto.BlockFactory {
|
|
6
6
|
private readonly deserializer;
|
7
7
|
private readonly idFactory;
|
8
8
|
private readonly validator;
|
9
|
-
make(data: Utils.Mutable<Contracts.Crypto.BlockDataSerializable
|
9
|
+
make(data: Utils.Mutable<Contracts.Crypto.BlockDataSerializable>, transactions: Contracts.Crypto.Transaction[]): Promise<Contracts.Crypto.Block>;
|
10
10
|
fromHex(hex: string): Promise<Contracts.Crypto.Block>;
|
11
11
|
fromBytes(buff: Buffer): Promise<Contracts.Crypto.Block>;
|
12
12
|
fromJson(json: Contracts.Crypto.BlockJson): Promise<Contracts.Crypto.Block>;
|
@@ -1 +1 @@
|
|
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,SAAS,CAAa;IAGvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAE3C,IAAI,
|
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,SAAS,CAAa;IAGvC,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;IAiB3E,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;CA8DxF"}
|
package/distribution/factory.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
@@ -14,21 +13,23 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
14
13
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
15
14
|
};
|
16
15
|
var _BlockFactory_instances, _BlockFactory_fromSerialized, _BlockFactory_applySchema;
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
const block_1 = require("./block");
|
23
|
-
const id_factory_1 = require("./id.factory");
|
16
|
+
import { inject, injectable } from "@mainsail/container";
|
17
|
+
import { Contracts, Exceptions, Identifiers } from "@mainsail/contracts";
|
18
|
+
import { BigNumber } from "@mainsail/utils";
|
19
|
+
import { sealBlock } from "./block.js";
|
20
|
+
import { IDFactory } from "./id.factory.js";
|
24
21
|
let BlockFactory = class BlockFactory {
|
25
22
|
constructor() {
|
26
23
|
_BlockFactory_instances.add(this);
|
27
24
|
}
|
28
|
-
async make(data) {
|
29
|
-
const block = data;
|
30
|
-
|
31
|
-
return
|
25
|
+
async make(data, transactions) {
|
26
|
+
const block = { ...data, id: await this.idFactory.make(data) };
|
27
|
+
const serialized = await this.serializer.serializeWithTransactions(data);
|
28
|
+
return sealBlock({
|
29
|
+
data: block,
|
30
|
+
serialized: serialized.toString("hex"),
|
31
|
+
transactions,
|
32
|
+
});
|
32
33
|
}
|
33
34
|
async fromHex(hex) {
|
34
35
|
return __classPrivateFieldGet(this, _BlockFactory_instances, "m", _BlockFactory_fromSerialized).call(this, Buffer.from(hex, "hex"));
|
@@ -39,14 +40,13 @@ let BlockFactory = class BlockFactory {
|
|
39
40
|
async fromJson(json) {
|
40
41
|
// @ts-ignore
|
41
42
|
const data = { ...json };
|
42
|
-
data.totalAmount =
|
43
|
-
data.totalFee =
|
44
|
-
data.reward =
|
43
|
+
data.totalAmount = BigNumber.make(data.totalAmount);
|
44
|
+
data.totalFee = BigNumber.make(data.totalFee);
|
45
|
+
data.reward = BigNumber.make(data.reward);
|
45
46
|
if (data.transactions) {
|
46
47
|
for (const transaction of data.transactions) {
|
47
|
-
transaction.
|
48
|
-
transaction.
|
49
|
-
transaction.nonce = utils_1.BigNumber.make(transaction.nonce);
|
48
|
+
transaction.value = BigNumber.make(transaction.value);
|
49
|
+
transaction.nonce = BigNumber.make(transaction.nonce);
|
50
50
|
}
|
51
51
|
}
|
52
52
|
return this.fromData(data);
|
@@ -54,13 +54,12 @@ let BlockFactory = class BlockFactory {
|
|
54
54
|
async fromData(data) {
|
55
55
|
await __classPrivateFieldGet(this, _BlockFactory_instances, "m", _BlockFactory_applySchema).call(this, data);
|
56
56
|
const serialized = await this.serializer.serializeWithTransactions(data);
|
57
|
-
return
|
57
|
+
return sealBlock({
|
58
58
|
...(await this.deserializer.deserializeWithTransactions(serialized)),
|
59
59
|
serialized: serialized.toString("hex"),
|
60
60
|
});
|
61
61
|
}
|
62
62
|
};
|
63
|
-
exports.BlockFactory = BlockFactory;
|
64
63
|
_BlockFactory_instances = new WeakSet();
|
65
64
|
_BlockFactory_fromSerialized = async function _BlockFactory_fromSerialized(serialized) {
|
66
65
|
const deserialized = await this.deserializer.deserializeWithTransactions(serialized);
|
@@ -68,7 +67,7 @@ _BlockFactory_fromSerialized = async function _BlockFactory_fromSerialized(seria
|
|
68
67
|
if (validated) {
|
69
68
|
deserialized.data = validated;
|
70
69
|
}
|
71
|
-
return
|
70
|
+
return sealBlock({
|
72
71
|
...deserialized,
|
73
72
|
serialized: serialized.toString("hex"),
|
74
73
|
});
|
@@ -94,29 +93,30 @@ _BlockFactory_applySchema = async function _BlockFactory_applySchema(data) {
|
|
94
93
|
}
|
95
94
|
}
|
96
95
|
if (fatal) {
|
97
|
-
throw new
|
96
|
+
throw new Exceptions.BlockSchemaError(data.height, `Invalid data${error.instancePath ? " at " + error.instancePath : ""}: ` +
|
98
97
|
`${error.message}: ${JSON.stringify(error.data)}`);
|
99
98
|
}
|
100
99
|
}
|
101
100
|
return result.value;
|
102
101
|
};
|
103
102
|
__decorate([
|
104
|
-
|
103
|
+
inject(Identifiers.Cryptography.Block.Serializer),
|
105
104
|
__metadata("design:type", Object)
|
106
105
|
], BlockFactory.prototype, "serializer", void 0);
|
107
106
|
__decorate([
|
108
|
-
|
107
|
+
inject(Identifiers.Cryptography.Block.Deserializer),
|
109
108
|
__metadata("design:type", Object)
|
110
109
|
], BlockFactory.prototype, "deserializer", void 0);
|
111
110
|
__decorate([
|
112
|
-
|
113
|
-
__metadata("design:type",
|
111
|
+
inject(Identifiers.Cryptography.Block.IDFactory),
|
112
|
+
__metadata("design:type", IDFactory)
|
114
113
|
], BlockFactory.prototype, "idFactory", void 0);
|
115
114
|
__decorate([
|
116
|
-
|
115
|
+
inject(Identifiers.Cryptography.Validator),
|
117
116
|
__metadata("design:type", Object)
|
118
117
|
], BlockFactory.prototype, "validator", void 0);
|
119
|
-
|
120
|
-
|
118
|
+
BlockFactory = __decorate([
|
119
|
+
injectable()
|
121
120
|
], BlockFactory);
|
121
|
+
export { BlockFactory };
|
122
122
|
//# sourceMappingURL=factory.js.map
|
@@ -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,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGrC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAAlB;;IAmHP,CAAC;IAtGO,KAAK,CAAC,IAAI,CAChB,IAA2D,EAC3D,YAA4C;QAE5C,MAAM,KAAK,GAA+B,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAE3F,MAAM,UAAU,GAAW,MAAM,IAAI,CAAC,UAAU,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC;QAEjF,OAAO,SAAS,CAAC;YAChB,IAAI,EAAE,KAAK;YACX,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC;YACtC,YAAY;SACZ,CAAC,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,GAAW;QAC/B,OAAO,uBAAA,IAAI,6DAAgB,MAApB,IAAI,EAAiB,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IACtD,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,IAAY;QAClC,OAAO,uBAAA,IAAI,6DAAgB,MAApB,IAAI,EAAiB,IAAI,CAAC,CAAC;IACnC,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CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,IAAI;gBACvE,GAAG,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAClD,CAAC;QACH,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC;AACrB,CAAC;AAhHgB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;gDACa;AAG9C;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC;;kDACe;AAGlD;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC;8BACpB,SAAS;+CAAC;AAGtB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC;;+CACa;AAX5C,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CAmHxB"}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
@@ -8,25 +7,23 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10
9
|
};
|
11
|
-
|
12
|
-
|
13
|
-
const container_1 = require("@mainsail/container");
|
14
|
-
const contracts_1 = require("@mainsail/contracts");
|
10
|
+
import { inject, injectable } from "@mainsail/container";
|
11
|
+
import { Contracts, Identifiers } from "@mainsail/contracts";
|
15
12
|
let IDFactory = class IDFactory {
|
16
13
|
async make(data) {
|
17
14
|
return (await this.hashFactory.sha256(await this.serializer.serializeHeader(data))).toString("hex");
|
18
15
|
}
|
19
16
|
};
|
20
|
-
exports.IDFactory = IDFactory;
|
21
17
|
__decorate([
|
22
|
-
|
18
|
+
inject(Identifiers.Cryptography.Hash.Factory),
|
23
19
|
__metadata("design:type", Object)
|
24
20
|
], IDFactory.prototype, "hashFactory", void 0);
|
25
21
|
__decorate([
|
26
|
-
|
22
|
+
inject(Identifiers.Cryptography.Block.Serializer),
|
27
23
|
__metadata("design:type", Object)
|
28
24
|
], IDFactory.prototype, "serializer", void 0);
|
29
|
-
|
30
|
-
|
25
|
+
IDFactory = __decorate([
|
26
|
+
injectable()
|
31
27
|
], IDFactory);
|
28
|
+
export { IDFactory };
|
32
29
|
//# sourceMappingURL=id.factory.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"id.factory.js","sourceRoot":"","sources":["../source/id.factory.ts"],"names":[],"mappings":"
|
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"}
|
package/distribution/index.d.ts
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
import { Providers } from "@mainsail/kernel";
|
2
|
-
export * from "./deserializer";
|
3
|
-
export * from "./factory";
|
4
|
-
export * from "./id.factory";
|
5
|
-
export * from "./schemas";
|
6
|
-
export * from "./serializer";
|
7
|
-
export * from "./verifier";
|
2
|
+
export * from "./deserializer.js";
|
3
|
+
export * from "./factory.js";
|
4
|
+
export * from "./id.factory.js";
|
5
|
+
export * from "./schemas.js";
|
6
|
+
export * from "./serializer.js";
|
7
|
+
export * from "./verifier.js";
|
8
8
|
export declare class ServiceProvider extends Providers.ServiceProvider {
|
9
9
|
register(): Promise<void>;
|
10
|
-
requiredByWorker(): boolean;
|
11
10
|
}
|
12
11
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAS7C,cAAc,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAS7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAE9B,qBAAa,eAAgB,SAAQ,SAAS,CAAC,eAAe;IAChD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAWtC"}
|
package/distribution/index.js
CHANGED
@@ -1,48 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports.ServiceProvider = void 0;
|
18
|
-
const contracts_1 = require("@mainsail/contracts");
|
19
|
-
const kernel_1 = require("@mainsail/kernel");
|
20
|
-
const deserializer_1 = require("./deserializer");
|
21
|
-
const factory_1 = require("./factory");
|
22
|
-
const id_factory_1 = require("./id.factory");
|
23
|
-
const schemas_1 = require("./schemas");
|
24
|
-
const serializer_1 = require("./serializer");
|
25
|
-
const verifier_1 = require("./verifier");
|
26
|
-
__exportStar(require("./deserializer"), exports);
|
27
|
-
__exportStar(require("./factory"), exports);
|
28
|
-
__exportStar(require("./id.factory"), exports);
|
29
|
-
__exportStar(require("./schemas"), exports);
|
30
|
-
__exportStar(require("./serializer"), exports);
|
31
|
-
__exportStar(require("./verifier"), exports);
|
32
|
-
class ServiceProvider extends kernel_1.Providers.ServiceProvider {
|
1
|
+
import { Identifiers } from "@mainsail/contracts";
|
2
|
+
import { Providers } from "@mainsail/kernel";
|
3
|
+
import { Deserializer } from "./deserializer.js";
|
4
|
+
import { BlockFactory } from "./factory.js";
|
5
|
+
import { IDFactory } from "./id.factory.js";
|
6
|
+
import { schemas } from "./schemas.js";
|
7
|
+
import { Serializer } from "./serializer.js";
|
8
|
+
import { Verifier } from "./verifier.js";
|
9
|
+
export * from "./deserializer.js";
|
10
|
+
export * from "./factory.js";
|
11
|
+
export * from "./id.factory.js";
|
12
|
+
export * from "./schemas.js";
|
13
|
+
export * from "./serializer.js";
|
14
|
+
export * from "./verifier.js";
|
15
|
+
export class ServiceProvider extends Providers.ServiceProvider {
|
33
16
|
async register() {
|
34
|
-
this.app.bind(
|
35
|
-
this.app.bind(
|
36
|
-
this.app.bind(
|
37
|
-
this.app.bind(
|
38
|
-
this.app.bind(
|
39
|
-
for (const schema of Object.values(
|
40
|
-
this.app.get(
|
17
|
+
this.app.bind(Identifiers.Cryptography.Block.Deserializer).to(Deserializer).inSingletonScope();
|
18
|
+
this.app.bind(Identifiers.Cryptography.Block.Factory).to(BlockFactory).inSingletonScope();
|
19
|
+
this.app.bind(Identifiers.Cryptography.Block.IDFactory).to(IDFactory).inSingletonScope();
|
20
|
+
this.app.bind(Identifiers.Cryptography.Block.Serializer).to(Serializer).inSingletonScope();
|
21
|
+
this.app.bind(Identifiers.Cryptography.Block.Verifier).to(Verifier).inSingletonScope();
|
22
|
+
for (const schema of Object.values(schemas)) {
|
23
|
+
this.app.get(Identifiers.Cryptography.Validator).addSchema(schema);
|
41
24
|
}
|
42
25
|
}
|
43
|
-
requiredByWorker() {
|
44
|
-
return true;
|
45
|
-
}
|
46
26
|
}
|
47
|
-
exports.ServiceProvider = ServiceProvider;
|
48
27
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"
|
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,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAE9B,MAAM,OAAO,eAAgB,SAAQ,SAAS,CAAC,eAAe;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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,CAAC,OAAO,GAAG,SAAS,GAAG,aAAa,EAAE,eAAe,CAyDhF,CAAC"}
|
package/distribution/schemas.js
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.schemas = void 0;
|
4
|
-
exports.schemas = {
|
1
|
+
export const schemas = {
|
5
2
|
block: {
|
6
3
|
$id: "block",
|
7
4
|
$ref: "blockHeader",
|
@@ -18,7 +15,7 @@ exports.schemas = {
|
|
18
15
|
blockHeader: {
|
19
16
|
$id: "blockHeader",
|
20
17
|
properties: {
|
21
|
-
|
18
|
+
generatorAddress: { $ref: "address" },
|
22
19
|
height: { minimum: 0, type: "integer" },
|
23
20
|
id: { $ref: "blockId" },
|
24
21
|
numberOfTransactions: { minimum: 0, type: "integer" },
|
@@ -26,9 +23,11 @@ exports.schemas = {
|
|
26
23
|
payloadLength: { minimum: 0, type: "integer" },
|
27
24
|
previousBlock: { $ref: "blockId" },
|
28
25
|
reward: { bignumber: { minimum: 0 } },
|
26
|
+
stateHash: { $ref: "hex" },
|
29
27
|
timestamp: { maximum: 2 ** 48 - 1, minimum: 0, type: "integer" },
|
30
28
|
totalAmount: { bignumber: { minimum: 0 } },
|
31
29
|
totalFee: { bignumber: { minimum: 0 } },
|
30
|
+
totalGasUsed: { minimum: 0, type: "integer" },
|
32
31
|
version: { enum: [1] },
|
33
32
|
},
|
34
33
|
required: [
|
@@ -36,10 +35,12 @@ exports.schemas = {
|
|
36
35
|
"timestamp",
|
37
36
|
"previousBlock",
|
38
37
|
"height",
|
38
|
+
"stateHash",
|
39
|
+
"totalGasUsed",
|
39
40
|
"totalAmount",
|
40
41
|
"totalFee",
|
41
42
|
"reward",
|
42
|
-
"
|
43
|
+
"generatorAddress",
|
43
44
|
],
|
44
45
|
type: "object",
|
45
46
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,OAAO,GAAiE;IACpF,KAAK,EAAE;QACN,GAAG,EAAE,OAAO;QACZ,IAAI,EAAE,aAAa;QACnB,UAAU,EAAE;YACX,YAAY,EAAE;gBACb,IAAI,EAAE,cAAc;gBACpB,QAAQ,EAAE,EAAE,KAAK,EAAE,wBAAwB,EAAE;gBAC7C,QAAQ,EAAE,EAAE,KAAK,EAAE,wBAAwB,EAAE;gBAC7C,IAAI,EAAE,OAAO;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,WAAW,EAAE;QACZ,GAAG,EAAE,aAAa;QAClB,UAAU,EAAE;YACX,gBAAgB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;YACrC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE;YACvC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;YACvB,oBAAoB,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE;YACrD,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;YAC5B,aAAa,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE;YAC9C,aAAa,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;YAClC,MAAM,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE;YACrC,SAAS,EAAE,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,WAAW,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE;YAC1C,QAAQ,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE;YACvC,YAAY,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE;YAC7C,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;SACtB;QACD,QAAQ,EAAE;YACT,IAAI;YACJ,WAAW;YACX,eAAe;YACf,QAAQ;YACR,WAAW;YACX,cAAc;YACd,aAAa;YACb,UAAU;YACV,QAAQ;YACR,kBAAkB;SAClB;QACD,IAAI,EAAE,QAAQ;KACd;IACD,OAAO,EAAE;QACR,GAAG,EAAE,SAAS;QACd,KAAK,EAAE;YACN;gBACC,IAAI,EAAE,KAAK;gBACX,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;CACD,CAAC"}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
/// <reference types="node" />
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
2
2
|
import { Contracts } from "@mainsail/contracts";
|
3
3
|
export declare class Serializer implements Contracts.Crypto.BlockSerializer {
|
4
4
|
private readonly serializer;
|
5
5
|
private readonly hashByteLength;
|
6
|
-
private readonly
|
6
|
+
private readonly generatorAddressByteLength;
|
7
7
|
headerSize(): number;
|
8
8
|
totalSize(block: Contracts.Crypto.BlockDataSerializable): number;
|
9
9
|
serializeHeader(block: Contracts.Crypto.BlockDataSerializable): Promise<Buffer>;
|
@@ -1 +1 @@
|
|
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;IAGlE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAG9D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;
|
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;IAGlE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAG9D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;IAGzC,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAU;IAE9C,UAAU,IAAI,MAAM;IAmBpB,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"}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
@@ -8,11 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10
9
|
};
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.Serializer = void 0;
|
13
10
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
14
|
-
|
15
|
-
|
11
|
+
import { inject, injectable, tagged } from "@mainsail/container";
|
12
|
+
import { Contracts, Identifiers } from "@mainsail/contracts";
|
16
13
|
let Serializer = class Serializer {
|
17
14
|
headerSize() {
|
18
15
|
return (1 + // version
|
@@ -20,13 +17,15 @@ let Serializer = class Serializer {
|
|
20
17
|
4 + // height
|
21
18
|
4 + // round
|
22
19
|
this.hashByteLength + // previousBlock
|
20
|
+
this.hashByteLength + // stateHash
|
23
21
|
2 + // numberOfTransactions
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
4 + // totalGasUsed
|
23
|
+
32 + // totalAmount
|
24
|
+
32 + // totalFee
|
25
|
+
32 + // reward
|
27
26
|
4 + // payloadLength
|
28
27
|
this.hashByteLength + // payloadHash
|
29
|
-
this.
|
28
|
+
this.generatorAddressByteLength);
|
30
29
|
}
|
31
30
|
totalSize(block) {
|
32
31
|
return this.headerSize() + block.payloadLength;
|
@@ -51,17 +50,23 @@ let Serializer = class Serializer {
|
|
51
50
|
previousBlock: {
|
52
51
|
type: "hash",
|
53
52
|
},
|
53
|
+
stateHash: {
|
54
|
+
type: "hash",
|
55
|
+
},
|
54
56
|
numberOfTransactions: {
|
55
57
|
type: "uint16",
|
56
58
|
},
|
59
|
+
totalGasUsed: {
|
60
|
+
type: "uint32",
|
61
|
+
},
|
57
62
|
totalAmount: {
|
58
|
-
type: "
|
63
|
+
type: "uint256",
|
59
64
|
},
|
60
65
|
totalFee: {
|
61
|
-
type: "
|
66
|
+
type: "uint256",
|
62
67
|
},
|
63
68
|
reward: {
|
64
|
-
type: "
|
69
|
+
type: "uint256",
|
65
70
|
},
|
66
71
|
payloadLength: {
|
67
72
|
type: "uint32",
|
@@ -69,8 +74,8 @@ let Serializer = class Serializer {
|
|
69
74
|
payloadHash: {
|
70
75
|
type: "hash",
|
71
76
|
},
|
72
|
-
|
73
|
-
type: "
|
77
|
+
generatorAddress: {
|
78
|
+
type: "address",
|
74
79
|
},
|
75
80
|
},
|
76
81
|
});
|
@@ -95,17 +100,23 @@ let Serializer = class Serializer {
|
|
95
100
|
previousBlock: {
|
96
101
|
type: "hash",
|
97
102
|
},
|
103
|
+
stateHash: {
|
104
|
+
type: "hash",
|
105
|
+
},
|
98
106
|
numberOfTransactions: {
|
99
107
|
type: "uint16",
|
100
108
|
},
|
109
|
+
totalGasUsed: {
|
110
|
+
type: "uint32",
|
111
|
+
},
|
101
112
|
totalAmount: {
|
102
|
-
type: "
|
113
|
+
type: "uint256",
|
103
114
|
},
|
104
115
|
totalFee: {
|
105
|
-
type: "
|
116
|
+
type: "uint256",
|
106
117
|
},
|
107
118
|
reward: {
|
108
|
-
type: "
|
119
|
+
type: "uint256",
|
109
120
|
},
|
110
121
|
payloadLength: {
|
111
122
|
type: "uint32",
|
@@ -113,8 +124,8 @@ let Serializer = class Serializer {
|
|
113
124
|
payloadHash: {
|
114
125
|
type: "hash",
|
115
126
|
},
|
116
|
-
|
117
|
-
type: "
|
127
|
+
generatorAddress: {
|
128
|
+
type: "address",
|
118
129
|
},
|
119
130
|
transactions: {
|
120
131
|
type: "transactions",
|
@@ -123,22 +134,21 @@ let Serializer = class Serializer {
|
|
123
134
|
});
|
124
135
|
}
|
125
136
|
};
|
126
|
-
exports.Serializer = Serializer;
|
127
137
|
__decorate([
|
128
|
-
|
129
|
-
|
138
|
+
inject(Identifiers.Cryptography.Serializer),
|
139
|
+
tagged("type", "wallet"),
|
130
140
|
__metadata("design:type", Object)
|
131
141
|
], Serializer.prototype, "serializer", void 0);
|
132
142
|
__decorate([
|
133
|
-
|
143
|
+
inject(Identifiers.Cryptography.Hash.Size.SHA256),
|
134
144
|
__metadata("design:type", Number)
|
135
145
|
], Serializer.prototype, "hashByteLength", void 0);
|
136
146
|
__decorate([
|
137
|
-
|
138
|
-
(0, container_1.tagged)("type", "wallet"),
|
147
|
+
inject(Identifiers.Cryptography.Identity.Address.Size),
|
139
148
|
__metadata("design:type", Number)
|
140
|
-
], Serializer.prototype, "
|
141
|
-
|
142
|
-
|
149
|
+
], Serializer.prototype, "generatorAddressByteLength", void 0);
|
150
|
+
Serializer = __decorate([
|
151
|
+
injectable()
|
143
152
|
], Serializer);
|
153
|
+
export { Serializer };
|
144
154
|
//# sourceMappingURL=serializer.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../source/serializer.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../source/serializer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,gDAAgD;AAChD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGtD,IAAM,UAAU,GAAhB,MAAM,UAAU;IAWf,UAAU;QAChB,OAAO,CACN,CAAC,GAAG,UAAU;YACd,CAAC,GAAG,YAAY;YAChB,CAAC,GAAG,SAAS;YACb,CAAC,GAAG,QAAQ;YACZ,IAAI,CAAC,cAAc,GAAG,gBAAgB;YACtC,IAAI,CAAC,cAAc,GAAG,YAAY;YAClC,CAAC,GAAG,uBAAuB;YAC3B,CAAC,GAAG,eAAe;YACnB,EAAE,GAAG,cAAc;YACnB,EAAE,GAAG,WAAW;YAChB,EAAE,GAAG,SAAS;YACd,CAAC,GAAG,gBAAgB;YACpB,IAAI,CAAC,cAAc,GAAG,cAAc;YACpC,IAAI,CAAC,0BAA0B,CAC/B,CAAC;IACH,CAAC;IAEM,SAAS,CAAC,KAA6C;QAC7D,OAAO,IAAI,CAAC,UAAU,EAAE,GAAG,KAAK,CAAC,aAAa,CAAC;IAChD,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,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AAS,CAAC,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC;
|
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;CAuH/F"}
|
package/distribution/verifier.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
"use strict";
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
@@ -8,11 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10
9
|
};
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
const contracts_1 = require("@mainsail/contracts");
|
15
|
-
const utils_1 = require("@mainsail/utils");
|
10
|
+
import { inject, injectable } from "@mainsail/container";
|
11
|
+
import { Contracts, Identifiers } from "@mainsail/contracts";
|
12
|
+
import { BigNumber } from "@mainsail/utils";
|
16
13
|
let Verifier = class Verifier {
|
17
14
|
async verify(block) {
|
18
15
|
const blockData = block.data;
|
@@ -36,9 +33,16 @@ let Verifier = class Verifier {
|
|
36
33
|
if (blockData.version !== constants.block.version) {
|
37
34
|
result.errors.push("Invalid block version");
|
38
35
|
}
|
39
|
-
const
|
40
|
-
|
41
|
-
|
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}`);
|
42
46
|
}
|
43
47
|
if (block.transactions.length !== blockData.numberOfTransactions) {
|
44
48
|
result.errors.push("Invalid number of transactions");
|
@@ -48,11 +52,11 @@ let Verifier = class Verifier {
|
|
48
52
|
}
|
49
53
|
// Checking if transactions of the block adds up to block values.
|
50
54
|
const appliedTransactions = {};
|
51
|
-
let totalAmount =
|
52
|
-
let totalFee =
|
55
|
+
let totalAmount = BigNumber.ZERO;
|
56
|
+
let totalFee = BigNumber.ZERO;
|
53
57
|
// The initial payload length takes the overhead for each serialized transaction into account
|
54
|
-
// which is a
|
55
|
-
let totalPayloadLength =
|
58
|
+
// which is a uint16 per transaction to store the individual length.
|
59
|
+
let totalPayloadLength = block.transactions.length * 2;
|
56
60
|
const payloadBuffers = [];
|
57
61
|
for (const transaction of block.transactions) {
|
58
62
|
if (!transaction || !transaction.id) {
|
@@ -62,15 +66,18 @@ let Verifier = class Verifier {
|
|
62
66
|
if (appliedTransactions[transaction.id]) {
|
63
67
|
result.errors.push(`Encountered duplicate transaction: ${transaction.id}`);
|
64
68
|
}
|
65
|
-
if (
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
// if (
|
70
|
+
// transaction.data.expiration &&
|
71
|
+
// transaction.data.expiration > 0 &&
|
72
|
+
// transaction.data.expiration <= blockData.height
|
73
|
+
// ) {
|
74
|
+
// result.errors.push(`Encountered expired transaction: ${transaction.id}`);
|
75
|
+
// }
|
70
76
|
appliedTransactions[transaction.id] = transaction.data;
|
71
|
-
totalAmount = totalAmount.plus(transaction.data.
|
72
|
-
|
73
|
-
|
77
|
+
totalAmount = totalAmount.plus(transaction.data.value);
|
78
|
+
// TODO: total fee should refer to consumed gas instead?
|
79
|
+
totalFee = totalFee.plus(transaction.data.gasPrice);
|
80
|
+
totalPayloadLength += transaction.serialized.byteLength;
|
74
81
|
payloadBuffers.push(bytes);
|
75
82
|
}
|
76
83
|
if (!totalAmount.isEqualTo(blockData.totalAmount)) {
|
@@ -93,20 +100,20 @@ let Verifier = class Verifier {
|
|
93
100
|
return result;
|
94
101
|
}
|
95
102
|
};
|
96
|
-
exports.Verifier = Verifier;
|
97
103
|
__decorate([
|
98
|
-
|
104
|
+
inject(Identifiers.Cryptography.Configuration),
|
99
105
|
__metadata("design:type", Object)
|
100
106
|
], Verifier.prototype, "configuration", void 0);
|
101
107
|
__decorate([
|
102
|
-
|
108
|
+
inject(Identifiers.Cryptography.Block.Serializer),
|
103
109
|
__metadata("design:type", Object)
|
104
110
|
], Verifier.prototype, "serializer", void 0);
|
105
111
|
__decorate([
|
106
|
-
|
112
|
+
inject(Identifiers.Cryptography.Hash.Factory),
|
107
113
|
__metadata("design:type", Object)
|
108
114
|
], Verifier.prototype, "hashFactory", void 0);
|
109
|
-
|
110
|
-
|
115
|
+
Verifier = __decorate([
|
116
|
+
injectable()
|
111
117
|
], Verifier);
|
118
|
+
export { Verifier };
|
112
119
|
//# sourceMappingURL=verifier.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"verifier.js","sourceRoot":"","sources":["../source/verifier.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"verif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block",
|
3
|
-
"version": "0.0.1-
|
3
|
+
"version": "0.0.1-evm.10",
|
4
4
|
"description": "Block utilities for the Mainsail blockchain",
|
5
5
|
"license": "GPL-3.0-only",
|
6
6
|
"contributors": [],
|
7
|
+
"type": "module",
|
7
8
|
"main": "distribution/index.js",
|
8
9
|
"types": "distribution/index.d.ts",
|
9
10
|
"files": [
|
@@ -11,21 +12,27 @@
|
|
11
12
|
],
|
12
13
|
"dependencies": {
|
13
14
|
"ajv": "8.12.0",
|
14
|
-
"@mainsail/
|
15
|
-
"@mainsail/kernel": "0.0.1-
|
16
|
-
"@mainsail/
|
17
|
-
"@mainsail/
|
18
|
-
"@mainsail/utils": "0.0.1-
|
15
|
+
"@mainsail/contracts": "0.0.1-evm.10",
|
16
|
+
"@mainsail/kernel": "0.0.1-evm.10",
|
17
|
+
"@mainsail/crypto-transaction": "0.0.1-evm.10",
|
18
|
+
"@mainsail/container": "0.0.1-evm.10",
|
19
|
+
"@mainsail/utils": "0.0.1-evm.10"
|
19
20
|
},
|
20
21
|
"devDependencies": {
|
21
22
|
"@types/lodash.clone": "^4.5.9",
|
22
23
|
"lodash.clone": "^4.5.0",
|
23
24
|
"uvu": "^0.5.6",
|
24
|
-
"@mainsail/crypto-address-
|
25
|
-
"@mainsail/crypto-config": "0.0.1-
|
26
|
-
"@mainsail/crypto-
|
27
|
-
"@mainsail/
|
28
|
-
"@mainsail/crypto-
|
25
|
+
"@mainsail/crypto-address-keccak256": "0.0.1-evm.10",
|
26
|
+
"@mainsail/crypto-config": "0.0.1-evm.10",
|
27
|
+
"@mainsail/crypto-consensus-bls12-381": "0.0.1-evm.10",
|
28
|
+
"@mainsail/crypto-hash-bcrypto": "0.0.1-evm.10",
|
29
|
+
"@mainsail/crypto-signature-ecdsa": "0.0.1-evm.10",
|
30
|
+
"@mainsail/crypto-validation": "0.0.1-evm.10",
|
31
|
+
"@mainsail/crypto-key-pair-ecdsa": "0.0.1-evm.10",
|
32
|
+
"@mainsail/crypto-transaction-evm-call": "0.0.1-evm.10",
|
33
|
+
"@mainsail/serializer": "0.0.1-evm.10",
|
34
|
+
"@mainsail/validation": "0.0.1-evm.10",
|
35
|
+
"@mainsail/crypto-wif": "0.0.1-evm.10"
|
29
36
|
},
|
30
37
|
"engines": {
|
31
38
|
"node": ">=20.x"
|
@@ -35,9 +42,10 @@
|
|
35
42
|
"build:watch": "pnpm run clean && tsc -w",
|
36
43
|
"clean": "del distribution",
|
37
44
|
"release": "pnpm publish --access public",
|
38
|
-
"test": "
|
45
|
+
"test": "pnpm run uvu source .test.ts",
|
39
46
|
"test:coverage": "c8 pnpm run test",
|
40
47
|
"test:coverage:html": "c8 -r html --all pnpm run test",
|
41
|
-
"test:file": "
|
48
|
+
"test:file": "pnpm run uvu source",
|
49
|
+
"uvu": "tsx --tsconfig ../../tsconfig.test.json ./node_modules/uvu/bin.js"
|
42
50
|
}
|
43
51
|
}
|