@mainsail/crypto-block 0.0.1-evm.5 → 0.0.1-evm.51
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 +23 -3
- package/distribution/block.d.ts.map +1 -1
- package/distribution/block.js +65 -9
- package/distribution/block.js.map +1 -1
- package/distribution/deserializer.d.ts +3 -4
- package/distribution/deserializer.d.ts.map +1 -1
- package/distribution/deserializer.js +47 -104
- package/distribution/deserializer.js.map +1 -1
- package/distribution/factory.d.ts +7 -4
- package/distribution/factory.d.ts.map +1 -1
- package/distribution/factory.js +84 -72
- package/distribution/factory.js.map +1 -1
- package/distribution/hash.factory.d.ts +7 -0
- package/distribution/hash.factory.d.ts.map +1 -0
- package/distribution/{id.factory.js → hash.factory.js} +11 -9
- package/distribution/hash.factory.js.map +1 -0
- package/distribution/index.d.ts +2 -6
- package/distribution/index.d.ts.map +1 -1
- package/distribution/index.js +2 -22
- package/distribution/index.js.map +1 -1
- package/distribution/schemas.d.ts +2 -2
- package/distribution/schemas.d.ts.map +1 -1
- package/distribution/schemas.js +77 -25
- package/distribution/schemas.js.map +1 -1
- package/distribution/serializer-schemas.d.ts +5 -0
- package/distribution/serializer-schemas.d.ts.map +1 -0
- package/distribution/serializer-schemas.js +57 -0
- package/distribution/serializer-schemas.js.map +1 -0
- package/distribution/serializer.d.ts +5 -8
- package/distribution/serializer.d.ts.map +1 -1
- package/distribution/serializer.js +13 -121
- package/distribution/serializer.js.map +1 -1
- package/distribution/service-provider.d.ts +5 -0
- package/distribution/service-provider.d.ts.map +1 -0
- package/distribution/service-provider.js +48 -0
- package/distribution/service-provider.js.map +1 -0
- package/package.json +27 -25
- package/distribution/id.factory.d.ts +0 -7
- 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
|
@@ -7,23 +7,25 @@ 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
|
+
import { Identifiers } from "@mainsail/constants";
|
|
10
11
|
import { inject, injectable } from "@mainsail/container";
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
let HashFactory = class HashFactory {
|
|
13
|
+
hashFactory;
|
|
14
|
+
serializer;
|
|
13
15
|
async make(data) {
|
|
14
|
-
return
|
|
16
|
+
return this.hashFactory.sha256(await this.serializer.serializeHeader(data)).toString("hex");
|
|
15
17
|
}
|
|
16
18
|
};
|
|
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":";;;;;;;;;AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGlD,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEN,WAAW,CAAgC;IAG3C,UAAU,CAAoC;IAExD,KAAK,CAAC,IAAI,CAAC,IAAqC;QACtD,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7F,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,11 +1,7 @@
|
|
|
1
|
-
import { Providers } from "@mainsail/kernel";
|
|
2
1
|
export * from "./deserializer.js";
|
|
3
2
|
export * from "./factory.js";
|
|
4
|
-
export * from "./
|
|
3
|
+
export * from "./hash.factory.js";
|
|
5
4
|
export * from "./schemas.js";
|
|
6
5
|
export * from "./serializer.js";
|
|
7
|
-
export * from "./
|
|
8
|
-
export declare class ServiceProvider extends Providers.ServiceProvider {
|
|
9
|
-
register(): Promise<void>;
|
|
10
|
-
}
|
|
6
|
+
export * from "./service-provider.js";
|
|
11
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
|
package/distribution/index.js
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
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
1
|
export * from "./deserializer.js";
|
|
10
2
|
export * from "./factory.js";
|
|
11
|
-
export * from "./
|
|
3
|
+
export * from "./hash.factory.js";
|
|
12
4
|
export * from "./schemas.js";
|
|
13
5
|
export * from "./serializer.js";
|
|
14
|
-
export * from "./
|
|
15
|
-
export class ServiceProvider extends Providers.ServiceProvider {
|
|
16
|
-
async register() {
|
|
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);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
6
|
+
export * from "./service-provider.js";
|
|
27
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AnySchemaObject } from "ajv";
|
|
2
|
-
export declare const schemas: Record<"block" | "
|
|
1
|
+
import type { AnySchemaObject } from "ajv";
|
|
2
|
+
export declare const schemas: Record<"block" | "blockHash" | "prefixedBlockHash" | "blockHeader" | "logsBloom" | "stateRoot" | "transactionsRoot", 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;
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAE3C,eAAO,MAAM,OAAO,EAAE,MAAM,CAC3B,OAAO,GAAG,WAAW,GAAG,mBAAmB,GAAG,aAAa,GAAG,WAAW,GAAG,WAAW,GAAG,kBAAkB,EAC5G,eAAe,CA8Gf,CAAC"}
|
package/distribution/schemas.js
CHANGED
|
@@ -5,47 +5,99 @@ 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
|
-
id: { $ref: "blockId" },
|
|
21
|
-
numberOfTransactions: { minimum: 0, type: "integer" },
|
|
22
|
-
payloadHash: { $ref: "hex" },
|
|
23
|
-
payloadLength: { minimum: 0, type: "integer" },
|
|
24
|
-
previousBlock: { $ref: "blockId" },
|
|
25
|
-
reward: { bignumber: { minimum: 0 } },
|
|
26
|
-
stateHash: { $ref: "hex" },
|
|
27
|
-
timestamp: { maximum: 2 ** 48 - 1, minimum: 0, type: "integer" },
|
|
28
|
-
totalAmount: { bignumber: { minimum: 0 } },
|
|
29
|
-
totalFee: { bignumber: { minimum: 0 } },
|
|
30
|
-
totalGasUsed: { minimum: 0, type: "integer" },
|
|
29
|
+
/* eslint-disable perfectionist/sort-objects */
|
|
30
|
+
hash: { $ref: "blockHash" },
|
|
31
31
|
version: { enum: [1] },
|
|
32
|
+
timestamp: { maximum: 2 ** 48 - 1, minimum: 0, type: "integer" },
|
|
33
|
+
number: { minimum: 0, type: "integer" },
|
|
34
|
+
round: { minimum: 0, type: "integer" },
|
|
35
|
+
parentHash: { $ref: "blockHash" },
|
|
36
|
+
stateRoot: { $ref: "stateRoot" },
|
|
37
|
+
logsBloom: { $ref: "logsBloom" },
|
|
38
|
+
transactionsCount: { minimum: 0, type: "integer" },
|
|
39
|
+
gasUsed: { minimum: 0, type: "integer" },
|
|
40
|
+
fee: { bigInt: { minimum: 0 } },
|
|
41
|
+
reward: { bigInt: { minimum: 0 } },
|
|
42
|
+
payloadSize: { minimum: 0, type: "integer" },
|
|
43
|
+
transactionsRoot: { $ref: "transactionsRoot" },
|
|
44
|
+
proposer: { $ref: "address" },
|
|
45
|
+
/* eslint-enable perfectionist/sort-objects */
|
|
32
46
|
},
|
|
33
47
|
required: [
|
|
34
|
-
"
|
|
48
|
+
"hash",
|
|
49
|
+
"version",
|
|
35
50
|
"timestamp",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
51
|
+
"number",
|
|
52
|
+
"round",
|
|
53
|
+
"parentHash",
|
|
54
|
+
"stateRoot",
|
|
55
|
+
"logsBloom",
|
|
56
|
+
"transactionsCount",
|
|
57
|
+
"gasUsed",
|
|
58
|
+
"fee",
|
|
42
59
|
"reward",
|
|
43
|
-
"
|
|
60
|
+
"payloadSize",
|
|
61
|
+
"transactionsRoot",
|
|
62
|
+
"proposer",
|
|
44
63
|
],
|
|
45
64
|
type: "object",
|
|
46
65
|
},
|
|
47
|
-
|
|
48
|
-
$id: "
|
|
66
|
+
logsBloom: {
|
|
67
|
+
$id: "logsBloom",
|
|
68
|
+
allOf: [
|
|
69
|
+
{
|
|
70
|
+
$ref: "hex",
|
|
71
|
+
maxLength: 512,
|
|
72
|
+
minLength: 512,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
type: "string",
|
|
76
|
+
},
|
|
77
|
+
prefixedBlockHash: {
|
|
78
|
+
$id: "prefixedBlockHash",
|
|
79
|
+
allOf: [
|
|
80
|
+
{
|
|
81
|
+
$ref: "prefixedQuantityHex",
|
|
82
|
+
maxLength: 66,
|
|
83
|
+
minLength: 66,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
type: "string",
|
|
87
|
+
},
|
|
88
|
+
stateRoot: {
|
|
89
|
+
$id: "stateRoot",
|
|
90
|
+
allOf: [
|
|
91
|
+
{
|
|
92
|
+
$ref: "hex",
|
|
93
|
+
maxLength: 64,
|
|
94
|
+
minLength: 64,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
type: "string",
|
|
98
|
+
},
|
|
99
|
+
transactionsRoot: {
|
|
100
|
+
$id: "transactionsRoot",
|
|
49
101
|
allOf: [
|
|
50
102
|
{
|
|
51
103
|
$ref: "hex",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Contracts } from "@mainsail/contracts";
|
|
2
|
+
export declare const blockHeaderSchema: Record<string, Contracts.Serializer.DeserializationSchema>;
|
|
3
|
+
export declare const transactionsSchema: Record<string, Contracts.Serializer.SerializationSchema>;
|
|
4
|
+
export declare const blockSchema: Record<string, Contracts.Serializer.SerializationSchema>;
|
|
5
|
+
//# sourceMappingURL=serializer-schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer-schemas.d.ts","sourceRoot":"","sources":["../source/serializer-schemas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,qBAAqB,CA4CxF,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,mBAAmB,CAIvF,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,mBAAmB,CAKhF,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const blockHeaderSchema = {
|
|
2
|
+
version: {
|
|
3
|
+
type: "uint8",
|
|
4
|
+
},
|
|
5
|
+
timestamp: {
|
|
6
|
+
type: "uint48",
|
|
7
|
+
},
|
|
8
|
+
number: {
|
|
9
|
+
type: "uint32",
|
|
10
|
+
},
|
|
11
|
+
round: {
|
|
12
|
+
type: "uint32",
|
|
13
|
+
},
|
|
14
|
+
parentHash: {
|
|
15
|
+
type: "hash",
|
|
16
|
+
},
|
|
17
|
+
stateRoot: {
|
|
18
|
+
type: "hash",
|
|
19
|
+
},
|
|
20
|
+
logsBloom: {
|
|
21
|
+
type: "hash",
|
|
22
|
+
size: 256,
|
|
23
|
+
},
|
|
24
|
+
transactionsCount: {
|
|
25
|
+
type: "uint16",
|
|
26
|
+
},
|
|
27
|
+
gasUsed: {
|
|
28
|
+
type: "uint32",
|
|
29
|
+
},
|
|
30
|
+
fee: {
|
|
31
|
+
type: "uint256",
|
|
32
|
+
},
|
|
33
|
+
reward: {
|
|
34
|
+
type: "uint256",
|
|
35
|
+
},
|
|
36
|
+
payloadSize: {
|
|
37
|
+
type: "uint32",
|
|
38
|
+
},
|
|
39
|
+
transactionsRoot: {
|
|
40
|
+
type: "hash",
|
|
41
|
+
},
|
|
42
|
+
proposer: {
|
|
43
|
+
type: "address",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
export const transactionsSchema = {
|
|
47
|
+
transactions: {
|
|
48
|
+
type: "transactions",
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
export const blockSchema = {
|
|
52
|
+
...blockHeaderSchema,
|
|
53
|
+
transactions: {
|
|
54
|
+
type: "transactions",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=serializer-schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer-schemas.js","sourceRoot":"","sources":["../source/serializer-schemas.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,iBAAiB,GAA+D;IAC5F,OAAO,EAAE;QACR,IAAI,EAAE,OAAO;KACb;IACD,SAAS,EAAE;QACV,IAAI,EAAE,QAAQ;KACd;IACD,MAAM,EAAE;QACP,IAAI,EAAE,QAAQ;KACd;IACD,KAAK,EAAE;QACN,IAAI,EAAE,QAAQ;KACd;IACD,UAAU,EAAE;QACX,IAAI,EAAE,MAAM;KACZ;IACD,SAAS,EAAE;QACV,IAAI,EAAE,MAAM;KACZ;IACD,SAAS,EAAE;QACV,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,GAAG;KACT;IACD,iBAAiB,EAAE;QAClB,IAAI,EAAE,QAAQ;KACd;IACD,OAAO,EAAE;QACR,IAAI,EAAE,QAAQ;KACd;IACD,GAAG,EAAE;QACJ,IAAI,EAAE,SAAS;KACf;IACD,MAAM,EAAE;QACP,IAAI,EAAE,SAAS;KACf;IACD,WAAW,EAAE;QACZ,IAAI,EAAE,QAAQ;KACd;IACD,gBAAgB,EAAE;QACjB,IAAI,EAAE,MAAM;KACZ;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,SAAS;KACf;CACD,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAA6D;IAC3F,YAAY,EAAE;QACb,IAAI,EAAE,cAAc;KACpB;CACD,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAA6D;IACpF,GAAG,iBAAiB;IACpB,YAAY,EAAE;QACb,IAAI,EAAE,cAAc;KACpB;CACD,CAAC"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import { Contracts } from "@mainsail/contracts";
|
|
1
|
+
import type { Contracts } from "@mainsail/contracts";
|
|
3
2
|
export declare class Serializer implements Contracts.Crypto.BlockSerializer {
|
|
4
3
|
private readonly serializer;
|
|
5
|
-
private readonly
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
serializeHeader(block: Contracts.Crypto.BlockDataSerializable): Promise<Buffer>;
|
|
10
|
-
serializeWithTransactions(block: Contracts.Crypto.BlockDataSerializable): Promise<Buffer>;
|
|
4
|
+
private readonly headerSize;
|
|
5
|
+
totalSize(block: Contracts.Crypto.BlockHeaderRaw): number;
|
|
6
|
+
serializeHeader(header: Contracts.Crypto.BlockHeaderRaw): Promise<Buffer>;
|
|
7
|
+
serializeWithTransactions(block: Contracts.Crypto.BlockSerializable): Promise<Buffer>;
|
|
11
8
|
}
|
|
12
9
|
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -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":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAOrD,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,cAAc,GAAG,MAAM;IAInD,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAQzE,yBAAyB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;CAOlG"}
|
|
@@ -7,146 +7,38 @@ 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
|
-
|
|
11
|
-
import { inject, injectable
|
|
12
|
-
import {
|
|
10
|
+
import { Identifiers } from "@mainsail/constants";
|
|
11
|
+
import { inject, injectable } from "@mainsail/container";
|
|
12
|
+
import { blockHeaderSchema, blockSchema } from "./serializer-schemas.js";
|
|
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
|
-
async serializeHeader(
|
|
34
|
-
return this.serializer.serialize(
|
|
19
|
+
async serializeHeader(header) {
|
|
20
|
+
return this.serializer.serialize(header, {
|
|
35
21
|
length: this.headerSize(),
|
|
22
|
+
schema: blockHeaderSchema,
|
|
36
23
|
skip: 0,
|
|
37
|
-
schema: {
|
|
38
|
-
version: {
|
|
39
|
-
type: "uint8",
|
|
40
|
-
},
|
|
41
|
-
timestamp: {
|
|
42
|
-
type: "uint48",
|
|
43
|
-
},
|
|
44
|
-
height: {
|
|
45
|
-
type: "uint32",
|
|
46
|
-
},
|
|
47
|
-
round: {
|
|
48
|
-
type: "uint32",
|
|
49
|
-
},
|
|
50
|
-
previousBlock: {
|
|
51
|
-
type: "hash",
|
|
52
|
-
},
|
|
53
|
-
stateHash: {
|
|
54
|
-
type: "hash",
|
|
55
|
-
},
|
|
56
|
-
numberOfTransactions: {
|
|
57
|
-
type: "uint16",
|
|
58
|
-
},
|
|
59
|
-
totalGasUsed: {
|
|
60
|
-
type: "uint32",
|
|
61
|
-
},
|
|
62
|
-
totalAmount: {
|
|
63
|
-
type: "uint256",
|
|
64
|
-
},
|
|
65
|
-
totalFee: {
|
|
66
|
-
type: "uint256",
|
|
67
|
-
},
|
|
68
|
-
reward: {
|
|
69
|
-
type: "uint256",
|
|
70
|
-
},
|
|
71
|
-
payloadLength: {
|
|
72
|
-
type: "uint32",
|
|
73
|
-
},
|
|
74
|
-
payloadHash: {
|
|
75
|
-
type: "hash",
|
|
76
|
-
},
|
|
77
|
-
generatorAddress: {
|
|
78
|
-
type: "address",
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
24
|
});
|
|
82
25
|
}
|
|
83
26
|
async serializeWithTransactions(block) {
|
|
84
27
|
return this.serializer.serialize(block, {
|
|
85
28
|
length: this.totalSize(block),
|
|
29
|
+
schema: blockSchema,
|
|
86
30
|
skip: 0,
|
|
87
|
-
schema: {
|
|
88
|
-
version: {
|
|
89
|
-
type: "uint8",
|
|
90
|
-
},
|
|
91
|
-
timestamp: {
|
|
92
|
-
type: "uint48",
|
|
93
|
-
},
|
|
94
|
-
height: {
|
|
95
|
-
type: "uint32",
|
|
96
|
-
},
|
|
97
|
-
round: {
|
|
98
|
-
type: "uint32",
|
|
99
|
-
},
|
|
100
|
-
previousBlock: {
|
|
101
|
-
type: "hash",
|
|
102
|
-
},
|
|
103
|
-
stateHash: {
|
|
104
|
-
type: "hash",
|
|
105
|
-
},
|
|
106
|
-
numberOfTransactions: {
|
|
107
|
-
type: "uint16",
|
|
108
|
-
},
|
|
109
|
-
totalGasUsed: {
|
|
110
|
-
type: "uint32",
|
|
111
|
-
},
|
|
112
|
-
totalAmount: {
|
|
113
|
-
type: "uint256",
|
|
114
|
-
},
|
|
115
|
-
totalFee: {
|
|
116
|
-
type: "uint256",
|
|
117
|
-
},
|
|
118
|
-
reward: {
|
|
119
|
-
type: "uint256",
|
|
120
|
-
},
|
|
121
|
-
payloadLength: {
|
|
122
|
-
type: "uint32",
|
|
123
|
-
},
|
|
124
|
-
payloadHash: {
|
|
125
|
-
type: "hash",
|
|
126
|
-
},
|
|
127
|
-
generatorAddress: {
|
|
128
|
-
type: "address",
|
|
129
|
-
},
|
|
130
|
-
transactions: {
|
|
131
|
-
type: "transactions",
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
31
|
});
|
|
135
32
|
}
|
|
136
33
|
};
|
|
137
34
|
__decorate([
|
|
138
35
|
inject(Identifiers.Cryptography.Serializer),
|
|
139
|
-
tagged("type", "wallet"),
|
|
140
36
|
__metadata("design:type", Object)
|
|
141
37
|
], Serializer.prototype, "serializer", void 0);
|
|
142
38
|
__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);
|
|
39
|
+
inject(Identifiers.Cryptography.Block.HeaderSize),
|
|
40
|
+
__metadata("design:type", Function)
|
|
41
|
+
], Serializer.prototype, "headerSize", void 0);
|
|
150
42
|
Serializer = __decorate([
|
|
151
43
|
injectable()
|
|
152
44
|
], Serializer);
|
|
@@ -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":";;;;;;;;;AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGlE,IAAM,UAAU,GAAhB,MAAM,UAAU;IAEL,UAAU,CAAmC;IAG7C,UAAU,CAAgB;IAEpC,SAAS,CAAC,KAAsC;QACtD,OAAO,IAAI,CAAC,UAAU,EAAE,GAAG,KAAK,CAAC,WAAW,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,MAAuC;QACnE,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE;YACxC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE;YACzB,MAAM,EAAE,iBAAiB;YACzB,IAAI,EAAE,CAAC;SACP,CAAC,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,yBAAyB,CAAC,KAAyC;QAC/E,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,EAAE;YACvC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC7B,MAAM,EAAE,WAAW;YACnB,IAAI,EAAE,CAAC;SACP,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAxBiB;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,CA0BtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-provider.d.ts","sourceRoot":"","sources":["../source/service-provider.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAQ7C,qBACa,eAAgB,SAAQ,SAAS,CAAC,eAAe;IAChD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAgCtC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { Identifiers } from "@mainsail/constants";
|
|
8
|
+
import { injectable } from "@mainsail/container";
|
|
9
|
+
import { Providers } from "@mainsail/kernel";
|
|
10
|
+
import { Deserializer } from "./deserializer.js";
|
|
11
|
+
import { BlockFactory } from "./factory.js";
|
|
12
|
+
import { HashFactory } from "./hash.factory.js";
|
|
13
|
+
import { schemas } from "./schemas.js";
|
|
14
|
+
import { Serializer } from "./serializer.js";
|
|
15
|
+
let ServiceProvider = class ServiceProvider extends Providers.ServiceProvider {
|
|
16
|
+
async register() {
|
|
17
|
+
this.app.bind(Identifiers.Cryptography.Block.HeaderSize).toConstantValue(() => {
|
|
18
|
+
const hashByteLength = this.app.get(Identifiers.Cryptography.Hash.Size.SHA256);
|
|
19
|
+
const generatorAddressByteLength = this.app.get(Identifiers.Cryptography.Identity.Address.Size);
|
|
20
|
+
return (1 + // version
|
|
21
|
+
6 + // timestamp
|
|
22
|
+
4 + // height
|
|
23
|
+
4 + // round
|
|
24
|
+
hashByteLength + // previousBlock
|
|
25
|
+
hashByteLength + // stateRoot
|
|
26
|
+
256 + // logsBloom
|
|
27
|
+
2 + // transactionsCount
|
|
28
|
+
4 + // totalGasUsed
|
|
29
|
+
32 + // totalFee
|
|
30
|
+
32 + // reward
|
|
31
|
+
4 + // payloadLength
|
|
32
|
+
hashByteLength + // payloadHash
|
|
33
|
+
generatorAddressByteLength);
|
|
34
|
+
});
|
|
35
|
+
this.app.bind(Identifiers.Cryptography.Block.Deserializer).to(Deserializer).inSingletonScope();
|
|
36
|
+
this.app.bind(Identifiers.Cryptography.Block.Factory).to(BlockFactory).inSingletonScope();
|
|
37
|
+
this.app.bind(Identifiers.Cryptography.Block.HashFactory).to(HashFactory).inSingletonScope();
|
|
38
|
+
this.app.bind(Identifiers.Cryptography.Block.Serializer).to(Serializer).inSingletonScope();
|
|
39
|
+
for (const schema of Object.values(schemas)) {
|
|
40
|
+
this.app.get(Identifiers.Cryptography.Validator).addSchema(schema);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
ServiceProvider = __decorate([
|
|
45
|
+
injectable()
|
|
46
|
+
], ServiceProvider);
|
|
47
|
+
export { ServiceProvider };
|
|
48
|
+
//# sourceMappingURL=service-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-provider.js","sourceRoot":"","sources":["../source/service-provider.ts"],"names":[],"mappings":";;;;;;AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,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;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGtC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,SAAS,CAAC,eAAe;IACtD,KAAK,CAAC,QAAQ;QACpB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE;YAC7E,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAS,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvF,MAAM,0BAA0B,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAS,WAAW,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAExG,OAAO,CACN,CAAC,GAAG,UAAU;gBACd,CAAC,GAAG,YAAY;gBAChB,CAAC,GAAG,SAAS;gBACb,CAAC,GAAG,QAAQ;gBACZ,cAAc,GAAG,gBAAgB;gBACjC,cAAc,GAAG,YAAY;gBAC7B,GAAG,GAAG,YAAY;gBAClB,CAAC,GAAG,oBAAoB;gBACxB,CAAC,GAAG,eAAe;gBACnB,EAAE,GAAG,WAAW;gBAChB,EAAE,GAAG,SAAS;gBACd,CAAC,GAAG,gBAAgB;gBACpB,cAAc,GAAG,cAAc;gBAC/B,0BAA0B,CAC1B,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAC/F,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,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"}
|