@mainsail/crypto-block 0.0.1-evm.3 → 0.0.1-evm.31
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 +4 -3
- package/distribution/deserializer.d.ts.map +1 -1
- package/distribution/deserializer.js +121 -98
- 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
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;A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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"}
|
|
@@ -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,MAAM,CAAC,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,OAAO,GAGhB;IACH,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,qBAAqB,EAAE;gBAC1C,QAAQ,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE;gBAC1C,IAAI,EAAE,OAAO;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,SAAS,EAAE;QACV,GAAG,EAAE,WAAW;QAChB,KAAK,EAAE;YACN;gBACC,IAAI,EAAE,KAAK;gBACX,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;aACb;SACD;QACD,IAAI,EAAE,QAAQ;KACd;IACD,WAAW,EAAE;QACZ,GAAG,EAAE,aAAa;QAClB,UAAU,EAAE;YACX,GAAG,EAAE,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE;YAClC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE;YACxC,IAAI,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YAC3B,SAAS,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YAChC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE;YACvC,UAAU,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YACjC,WAAW,E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
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;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M,EAAE;oBACP,IAAI,EAAE,QAAQ;iBACd;gBACD,KAAK,EAAE;oBACN,IAAI,EAAE,QAAQ;iBACd;gBACD,UAAU,EAAE;oBACX,IAAI,EAAE,MAAM;iBACZ;gBACD,SAAS,EAAE;oBACV,IAAI,EAAE,MAAM;iBACZ;gBACD,SAAS,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.31",
|
|
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/container": "0.0.1-evm.
|
|
16
|
-
"@mainsail/contracts": "0.0.1-evm.
|
|
17
|
-
"@mainsail/
|
|
18
|
-
"@mainsail/
|
|
19
|
-
"@mainsail/
|
|
14
|
+
"ajv": "8.17.1",
|
|
15
|
+
"@mainsail/container": "0.0.1-evm.31",
|
|
16
|
+
"@mainsail/contracts": "0.0.1-evm.31",
|
|
17
|
+
"@mainsail/kernel": "0.0.1-evm.31",
|
|
18
|
+
"@mainsail/utils": "0.0.1-evm.31",
|
|
19
|
+
"@mainsail/crypto-transaction": "0.0.1-evm.31"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@types/lodash.clone": "
|
|
23
|
-
"lodash.
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"@mainsail/crypto-
|
|
28
|
-
"@mainsail/crypto-
|
|
29
|
-
"@mainsail/crypto-
|
|
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.31",
|
|
28
|
+
"@mainsail/crypto-address-keccak256": "0.0.1-evm.31",
|
|
29
|
+
"@mainsail/crypto-config": "0.0.1-evm.31",
|
|
30
|
+
"@mainsail/crypto-consensus-bls12-381": "0.0.1-evm.31",
|
|
31
|
+
"@mainsail/crypto-hash-bcrypto": "0.0.1-evm.31",
|
|
32
|
+
"@mainsail/crypto-signature-ecdsa": "0.0.1-evm.31",
|
|
33
|
+
"@mainsail/crypto-key-pair-ecdsa": "0.0.1-evm.31",
|
|
34
|
+
"@mainsail/crypto-transaction-evm-call": "0.0.1-evm.31",
|
|
35
|
+
"@mainsail/crypto-wif": "0.0.1-evm.31",
|
|
36
|
+
"@mainsail/serializer": "0.0.1-evm.31",
|
|
37
|
+
"@mainsail/crypto-validation": "0.0.1-evm.31",
|
|
38
|
+
"@mainsail/validation": "0.0.1-evm.31"
|
|
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,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