@mainsail/crypto-messages 0.0.1-evm.5 → 0.0.1-evm.50
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/deserializer.d.ts +2 -7
- package/distribution/deserializer.d.ts.map +1 -1
- package/distribution/deserializer.js +19 -102
- package/distribution/deserializer.js.map +1 -1
- package/distribution/factory.d.ts +4 -16
- package/distribution/factory.d.ts.map +1 -1
- package/distribution/factory.js +31 -132
- package/distribution/factory.js.map +1 -1
- package/distribution/index.d.ts +1 -6
- package/distribution/index.d.ts.map +1 -1
- package/distribution/index.js +1 -34
- package/distribution/index.js.map +1 -1
- package/distribution/message.d.ts +17 -0
- package/distribution/message.d.ts.map +1 -0
- package/distribution/message.js +53 -0
- package/distribution/message.js.map +1 -0
- package/distribution/schemas.d.ts +2 -2
- package/distribution/schemas.d.ts.map +1 -1
- package/distribution/schemas.js +9 -58
- package/distribution/schemas.js.map +1 -1
- package/distribution/serializer-schemas.d.ts +4 -0
- package/distribution/serializer-schemas.d.ts.map +1 -0
- package/distribution/serializer-schemas.js +34 -0
- package/distribution/serializer-schemas.js.map +1 -0
- package/distribution/serializer.d.ts +3 -10
- package/distribution/serializer.d.ts.map +1 -1
- package/distribution/serializer.js +20 -171
- package/distribution/serializer.js.map +1 -1
- package/distribution/service-provider.d.ts +6 -0
- package/distribution/service-provider.d.ts.map +1 -0
- package/distribution/service-provider.js +31 -0
- package/distribution/service-provider.js.map +1 -0
- package/package.json +28 -24
- package/distribution/keywords.d.ts +0 -7
- package/distribution/keywords.d.ts.map +0 -1
- package/distribution/keywords.js +0 -80
- package/distribution/keywords.js.map +0 -1
- package/distribution/precommit.d.ts +0 -19
- package/distribution/precommit.d.ts.map +0 -1
- package/distribution/precommit.js +0 -79
- package/distribution/precommit.js.map +0 -1
- package/distribution/prevote.d.ts +0 -19
- package/distribution/prevote.d.ts.map +0 -1
- package/distribution/prevote.js +0 -79
- package/distribution/prevote.js.map +0 -1
- package/distribution/proposal.d.ts +0 -24
- package/distribution/proposal.d.ts.map +0 -1
- package/distribution/proposal.js +0 -122
- package/distribution/proposal.js.map +0 -1
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { Contracts } from "@mainsail/contracts";
|
|
1
|
+
import type { Contracts } from "@mainsail/contracts";
|
|
3
2
|
export declare class Deserializer implements Contracts.Crypto.MessageDeserializer {
|
|
4
3
|
private readonly serializer;
|
|
5
|
-
|
|
6
|
-
deserializeProposal(serialized: Buffer): Promise<Contracts.Crypto.ProposalData>;
|
|
7
|
-
deserializePrecommit(serialized: Buffer): Promise<Contracts.Crypto.PrecommitData>;
|
|
8
|
-
deserializePrevote(serialized: Buffer): Promise<Contracts.Crypto.PrevoteData>;
|
|
9
|
-
deserializeLockProof(serialized: Buffer): Promise<Contracts.Crypto.AggregatedSignature>;
|
|
4
|
+
deserializeMessage(serialized: Buffer): Promise<Contracts.Crypto.MessageData>;
|
|
10
5
|
}
|
|
11
6
|
//# sourceMappingURL=deserializer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deserializer.d.ts","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AASrD,qBACa,YAAa,YAAW,SAAS,CAAC,MAAM,CAAC,mBAAmB;IAExE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAEjD,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC;CAsB1F"}
|
|
@@ -7,117 +7,34 @@ 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
|
-
|
|
10
|
+
import { Identifiers } from "@mainsail/constants";
|
|
11
11
|
import { inject, injectable } from "@mainsail/container";
|
|
12
|
-
import {
|
|
13
|
-
import { ByteBuffer } from "@mainsail/utils";
|
|
12
|
+
import { MessageDeserializationError } from "@mainsail/exceptions";
|
|
13
|
+
import { ByteBuffer, ensureError } from "@mainsail/utils";
|
|
14
|
+
import { schema } from "./serializer-schemas.js";
|
|
14
15
|
let Deserializer = class Deserializer {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
serializer;
|
|
17
|
+
async deserializeMessage(serialized) {
|
|
17
18
|
const buffer = ByteBuffer.fromBuffer(serialized);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type: "uint8",
|
|
32
|
-
},
|
|
33
|
-
signature: {
|
|
34
|
-
type: "consensusSignature",
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
return proposal;
|
|
39
|
-
}
|
|
40
|
-
async deserializePrecommit(serialized) {
|
|
41
|
-
const precommit = {};
|
|
42
|
-
const buffer = ByteBuffer.fromBuffer(serialized);
|
|
43
|
-
await this.serializer.deserialize(buffer, precommit, {
|
|
44
|
-
schema: {
|
|
45
|
-
type: {
|
|
46
|
-
type: "uint8",
|
|
47
|
-
},
|
|
48
|
-
height: {
|
|
49
|
-
type: "uint32",
|
|
50
|
-
},
|
|
51
|
-
round: {
|
|
52
|
-
type: "uint32",
|
|
53
|
-
},
|
|
54
|
-
blockId: {
|
|
55
|
-
type: "blockId",
|
|
56
|
-
optional: true,
|
|
57
|
-
},
|
|
58
|
-
validatorIndex: {
|
|
59
|
-
type: "uint8",
|
|
60
|
-
},
|
|
61
|
-
signature: {
|
|
62
|
-
type: "consensusSignature",
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
return precommit;
|
|
67
|
-
}
|
|
68
|
-
async deserializePrevote(serialized) {
|
|
69
|
-
const prevote = {};
|
|
70
|
-
const buffer = ByteBuffer.fromBuffer(serialized);
|
|
71
|
-
await this.serializer.deserialize(buffer, prevote, {
|
|
72
|
-
schema: {
|
|
73
|
-
type: {
|
|
74
|
-
type: "uint8",
|
|
75
|
-
},
|
|
76
|
-
height: {
|
|
77
|
-
type: "uint32",
|
|
78
|
-
},
|
|
79
|
-
round: {
|
|
80
|
-
type: "uint32",
|
|
81
|
-
},
|
|
82
|
-
blockId: {
|
|
83
|
-
type: "blockId",
|
|
84
|
-
optional: true,
|
|
85
|
-
},
|
|
86
|
-
validatorIndex: {
|
|
87
|
-
type: "uint8",
|
|
88
|
-
},
|
|
89
|
-
signature: {
|
|
90
|
-
type: "consensusSignature",
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
return prevote;
|
|
95
|
-
}
|
|
96
|
-
async deserializeLockProof(serialized) {
|
|
97
|
-
const buffer = ByteBuffer.fromBuffer(serialized);
|
|
98
|
-
const commit = {};
|
|
99
|
-
await this.serializer.deserialize(buffer, commit, {
|
|
100
|
-
length: this.messageSerializer.lockProofSize(),
|
|
101
|
-
schema: {
|
|
102
|
-
signature: {
|
|
103
|
-
type: "consensusSignature",
|
|
104
|
-
},
|
|
105
|
-
validators: {
|
|
106
|
-
type: "validatorSet",
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
return commit;
|
|
19
|
+
try {
|
|
20
|
+
const result = await this.serializer.deserialize(buffer, {}, {
|
|
21
|
+
schema,
|
|
22
|
+
});
|
|
23
|
+
if (buffer.getRemainderLength() === 0) {
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (rawError) {
|
|
28
|
+
const error = ensureError(rawError);
|
|
29
|
+
throw new MessageDeserializationError(error instanceof Error ? error.message : "");
|
|
30
|
+
}
|
|
31
|
+
throw new MessageDeserializationError(`${buffer.getRemainderLength()} bytes remaining`);
|
|
111
32
|
}
|
|
112
33
|
};
|
|
113
34
|
__decorate([
|
|
114
35
|
inject(Identifiers.Cryptography.Serializer),
|
|
115
36
|
__metadata("design:type", Object)
|
|
116
37
|
], Deserializer.prototype, "serializer", void 0);
|
|
117
|
-
__decorate([
|
|
118
|
-
inject(Identifiers.Cryptography.Message.Serializer),
|
|
119
|
-
__metadata("design:type", Object)
|
|
120
|
-
], Deserializer.prototype, "messageSerializer", void 0);
|
|
121
38
|
Deserializer = __decorate([
|
|
122
39
|
injectable()
|
|
123
40
|
], Deserializer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserializer.js","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"deserializer.js","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAG1C,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEP,UAAU,CAAmC;IAEvD,KAAK,CAAC,kBAAkB,CAAC,UAAkB;QACjD,MAAM,MAAM,GAAe,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAE7D,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAC/C,MAAM,EACN,EAAE,EACF;gBACC,MAAM;aACN,CACD,CAAC;YAEF,IAAI,MAAM,CAAC,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC;gBACvC,OAAO,MAAM,CAAC;YACf,CAAC;QACF,CAAC;QAAC,OAAO,QAAQ,EAAE,CAAC;YACnB,MAAM,KAAK,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;YACpC,MAAM,IAAI,2BAA2B,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACpF,CAAC;QAED,MAAM,IAAI,2BAA2B,CAAC,GAAG,MAAM,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC;IACzF,CAAC;CACD,CAAA;AAxBiB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC;;gDACkB;AAFlD,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CA0BxB"}
|
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare class MessageFactory implements Contracts.Crypto.MessageFactory {
|
|
1
|
+
import type { Contracts } from "@mainsail/contracts";
|
|
2
|
+
export declare class Factory implements Contracts.Crypto.MessageFactory {
|
|
4
3
|
#private;
|
|
5
|
-
private readonly app;
|
|
6
4
|
private readonly serializer;
|
|
7
5
|
private readonly deserializer;
|
|
8
|
-
private readonly blockFactory;
|
|
9
|
-
private readonly blockDeserializer;
|
|
10
6
|
private readonly validator;
|
|
11
7
|
private readonly workerPool;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
makeProposalFromData(proposalData: Contracts.Crypto.ProposalData, serialized?: Buffer): Promise<Contracts.Crypto.Proposal>;
|
|
15
|
-
makeProposedDataFromBytes(bytes: Buffer): Promise<Contracts.Crypto.ProposedData>;
|
|
16
|
-
makePrevote(data: Contracts.Crypto.MakePrevoteData, keyPair: Contracts.Crypto.KeyPair): Promise<Contracts.Crypto.Prevote>;
|
|
17
|
-
makePrevoteFromBytes(bytes: Buffer): Promise<Contracts.Crypto.Precommit>;
|
|
18
|
-
makePrevoteFromData(data: Contracts.Crypto.PrevoteData, serialized?: Buffer): Promise<Contracts.Crypto.Prevote>;
|
|
19
|
-
makePrecommit(data: Contracts.Crypto.MakePrecommitData, keyPair: Contracts.Crypto.KeyPair): Promise<Contracts.Crypto.Precommit>;
|
|
20
|
-
makePrecommitFromBytes(bytes: Buffer): Promise<Contracts.Crypto.Precommit>;
|
|
21
|
-
makePrecommitFromData(data: Contracts.Crypto.PrecommitData, serialized?: Buffer): Promise<Contracts.Crypto.Precommit>;
|
|
8
|
+
makeMessage(data: Contracts.Crypto.MakeMessageData, keyPair: Contracts.Crypto.KeyPair, context: Contracts.Crypto.SignatureMessageContext): Promise<Contracts.Crypto.Message>;
|
|
9
|
+
makeMessageFromBytes(bytes: Buffer): Promise<Contracts.Crypto.Message>;
|
|
22
10
|
}
|
|
23
11
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAQrD,qBACa,OAAQ,YAAW,SAAS,CAAC,MAAM,CAAC,cAAc;;IAE9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsC;IAGjE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAwC;IAGrE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAGxD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA+B;IAE7C,WAAW,CACvB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,eAAe,EACtC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,OAAO,EACjC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,uBAAuB,GAC/C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC;IAUvB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC;CAgBnF"}
|
package/distribution/factory.js
CHANGED
|
@@ -7,154 +7,53 @@ 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
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
12
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
13
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
14
|
-
};
|
|
15
|
-
var _MessageFactory_instances, _MessageFactory_getBlockHeaderFromProposedData, _MessageFactory_applySchema;
|
|
10
|
+
import { Identifiers } from "@mainsail/constants";
|
|
16
11
|
import { inject, injectable } from "@mainsail/container";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const worker = await this.workerPool.getWorker();
|
|
28
|
-
const bytes = await this.serializer.serializeProposal(data, { includeSignature: false });
|
|
12
|
+
import { MessageSchemaError } from "@mainsail/exceptions";
|
|
13
|
+
import { Message } from "./message.js";
|
|
14
|
+
let Factory = class Factory {
|
|
15
|
+
serializer;
|
|
16
|
+
deserializer;
|
|
17
|
+
validator;
|
|
18
|
+
workerPool;
|
|
19
|
+
async makeMessage(data, keyPair, context) {
|
|
20
|
+
const worker = this.workerPool.getWorker();
|
|
21
|
+
const bytes = await this.serializer.serializeMessageForSignature(data, context);
|
|
29
22
|
const signature = await worker.consensusSignature("sign", bytes, Buffer.from(keyPair.privateKey, "hex"));
|
|
30
|
-
const serialized =
|
|
31
|
-
return this.
|
|
32
|
-
}
|
|
33
|
-
async
|
|
34
|
-
const data = await this.deserializer.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
if (!
|
|
41
|
-
|
|
23
|
+
const serialized = await this.serializer.serializeMessage({ ...data, signature });
|
|
24
|
+
return this.makeMessageFromBytes(serialized);
|
|
25
|
+
}
|
|
26
|
+
async makeMessageFromBytes(bytes) {
|
|
27
|
+
const data = await this.deserializer.deserializeMessage(bytes);
|
|
28
|
+
this.#applySchema("message", data);
|
|
29
|
+
return new Message({ ...data, serialized: bytes });
|
|
30
|
+
}
|
|
31
|
+
#applySchema(schema, data) {
|
|
32
|
+
const result = this.validator.validate(schema, data);
|
|
33
|
+
if (!result.error) {
|
|
34
|
+
return result.value;
|
|
42
35
|
}
|
|
43
|
-
|
|
44
|
-
...proposalData,
|
|
45
|
-
dataSerialized: proposalData.data.serialized,
|
|
46
|
-
height: header.height,
|
|
47
|
-
serialized,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
async makeProposedDataFromBytes(bytes) {
|
|
51
|
-
const buffer = ByteBuffer.fromBuffer(bytes);
|
|
52
|
-
const lockProofLength = buffer.readUint8();
|
|
53
|
-
let lockProof;
|
|
54
|
-
if (lockProofLength > 0) {
|
|
55
|
-
const lockProofBuffer = buffer.readBytes(lockProofLength);
|
|
56
|
-
lockProof = await this.deserializer.deserializeLockProof(lockProofBuffer);
|
|
57
|
-
}
|
|
58
|
-
const block = await this.blockFactory.fromBytes(buffer.getRemainder());
|
|
59
|
-
return {
|
|
60
|
-
block,
|
|
61
|
-
lockProof,
|
|
62
|
-
serialized: bytes.toString("hex"),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
async makePrevote(data, keyPair) {
|
|
66
|
-
const worker = await this.workerPool.getWorker();
|
|
67
|
-
const bytes = await this.serializer.serializePrevoteForSignature({
|
|
68
|
-
blockId: data.blockId,
|
|
69
|
-
height: data.height,
|
|
70
|
-
round: data.round,
|
|
71
|
-
type: data.type,
|
|
72
|
-
});
|
|
73
|
-
const signature = await worker.consensusSignature("sign", bytes, Buffer.from(keyPair.privateKey, "hex"));
|
|
74
|
-
const serialized = await this.serializer.serializePrevote({ ...data, signature });
|
|
75
|
-
return this.makePrevoteFromBytes(serialized);
|
|
76
|
-
}
|
|
77
|
-
async makePrevoteFromBytes(bytes) {
|
|
78
|
-
const data = await this.deserializer.deserializePrevote(bytes);
|
|
79
|
-
return this.makePrevoteFromData(data, bytes);
|
|
80
|
-
}
|
|
81
|
-
async makePrevoteFromData(data, serialized) {
|
|
82
|
-
__classPrivateFieldGet(this, _MessageFactory_instances, "m", _MessageFactory_applySchema).call(this, "prevote", data);
|
|
83
|
-
if (!serialized) {
|
|
84
|
-
serialized = await this.serializer.serializePrevote(data);
|
|
85
|
-
}
|
|
86
|
-
return new Prevote({ ...data, serialized });
|
|
87
|
-
}
|
|
88
|
-
async makePrecommit(data, keyPair) {
|
|
89
|
-
const worker = await this.workerPool.getWorker();
|
|
90
|
-
const bytes = await this.serializer.serializePrecommitForSignature({
|
|
91
|
-
blockId: data.blockId,
|
|
92
|
-
height: data.height,
|
|
93
|
-
round: data.round,
|
|
94
|
-
type: data.type,
|
|
95
|
-
});
|
|
96
|
-
const signature = await worker.consensusSignature("sign", bytes, Buffer.from(keyPair.privateKey, "hex"));
|
|
97
|
-
const serialized = await this.serializer.serializePrecommit({ ...data, signature });
|
|
98
|
-
return this.makePrecommitFromBytes(serialized);
|
|
36
|
+
throw new MessageSchemaError(schema, result.error);
|
|
99
37
|
}
|
|
100
|
-
async makePrecommitFromBytes(bytes) {
|
|
101
|
-
const data = await this.deserializer.deserializePrecommit(bytes);
|
|
102
|
-
return this.makePrecommitFromData(data, bytes);
|
|
103
|
-
}
|
|
104
|
-
async makePrecommitFromData(data, serialized) {
|
|
105
|
-
__classPrivateFieldGet(this, _MessageFactory_instances, "m", _MessageFactory_applySchema).call(this, "precommit", data);
|
|
106
|
-
if (!serialized) {
|
|
107
|
-
serialized = await this.serializer.serializePrecommit(data);
|
|
108
|
-
}
|
|
109
|
-
return new Precommit({ ...data, serialized });
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
_MessageFactory_instances = new WeakSet();
|
|
113
|
-
_MessageFactory_getBlockHeaderFromProposedData =
|
|
114
|
-
// Performance can be improved by returning only a block height
|
|
115
|
-
async function _MessageFactory_getBlockHeaderFromProposedData(bytes) {
|
|
116
|
-
const buffer = ByteBuffer.fromBuffer(bytes);
|
|
117
|
-
const lockProofLength = buffer.readUint8();
|
|
118
|
-
buffer.skip(lockProofLength);
|
|
119
|
-
return this.blockDeserializer.deserializeHeader(buffer.getRemainder());
|
|
120
|
-
};
|
|
121
|
-
_MessageFactory_applySchema = function _MessageFactory_applySchema(schema, data) {
|
|
122
|
-
const result = this.validator.validate(schema, data);
|
|
123
|
-
if (!result.error) {
|
|
124
|
-
return result.value;
|
|
125
|
-
}
|
|
126
|
-
throw new Exceptions.MessageSchemaError(schema, result.error);
|
|
127
38
|
};
|
|
128
|
-
__decorate([
|
|
129
|
-
inject(Identifiers.Application.Instance),
|
|
130
|
-
__metadata("design:type", Object)
|
|
131
|
-
], MessageFactory.prototype, "app", void 0);
|
|
132
39
|
__decorate([
|
|
133
40
|
inject(Identifiers.Cryptography.Message.Serializer),
|
|
134
41
|
__metadata("design:type", Object)
|
|
135
|
-
],
|
|
42
|
+
], Factory.prototype, "serializer", void 0);
|
|
136
43
|
__decorate([
|
|
137
44
|
inject(Identifiers.Cryptography.Message.Deserializer),
|
|
138
45
|
__metadata("design:type", Object)
|
|
139
|
-
],
|
|
140
|
-
__decorate([
|
|
141
|
-
inject(Identifiers.Cryptography.Block.Factory),
|
|
142
|
-
__metadata("design:type", Object)
|
|
143
|
-
], MessageFactory.prototype, "blockFactory", void 0);
|
|
144
|
-
__decorate([
|
|
145
|
-
inject(Identifiers.Cryptography.Block.Deserializer),
|
|
146
|
-
__metadata("design:type", Object)
|
|
147
|
-
], MessageFactory.prototype, "blockDeserializer", void 0);
|
|
46
|
+
], Factory.prototype, "deserializer", void 0);
|
|
148
47
|
__decorate([
|
|
149
48
|
inject(Identifiers.Cryptography.Validator),
|
|
150
49
|
__metadata("design:type", Object)
|
|
151
|
-
],
|
|
50
|
+
], Factory.prototype, "validator", void 0);
|
|
152
51
|
__decorate([
|
|
153
52
|
inject(Identifiers.CryptoWorker.WorkerPool),
|
|
154
53
|
__metadata("design:type", Object)
|
|
155
|
-
],
|
|
156
|
-
|
|
54
|
+
], Factory.prototype, "workerPool", void 0);
|
|
55
|
+
Factory = __decorate([
|
|
157
56
|
injectable()
|
|
158
|
-
],
|
|
159
|
-
export {
|
|
57
|
+
], Factory);
|
|
58
|
+
export { Factory };
|
|
160
59
|
//# 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":";;;;;;;;;AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGhC,IAAM,OAAO,GAAb,MAAM,OAAO;IAEF,UAAU,CAAsC;IAGhD,YAAY,CAAwC;IAGpD,SAAS,CAA8B;IAGvC,UAAU,CAA+B;IAEnD,KAAK,CAAC,WAAW,CACvB,IAAsC,EACtC,OAAiC,EACjC,OAAiD;QAEjD,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QAE3C,MAAM,KAAK,GAAG,M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C,SAAS,CAAC;;0CACa;AAGvC;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC;;2CACc;AAX9C,OAAO;IADnB,UAAU,EAAE;GACA,OAAO,CA2CnB"}
|
package/distribution/index.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export { Proposal } from "./proposal.js";
|
|
3
|
-
export declare class ServiceProvider extends Providers.ServiceProvider {
|
|
4
|
-
#private;
|
|
5
|
-
register(): Promise<void>;
|
|
6
|
-
}
|
|
1
|
+
export * from "./service-provider.js";
|
|
7
2
|
//# 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,uBAAuB,CAAC"}
|
package/distribution/index.js
CHANGED
|
@@ -1,35 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var _ServiceProvider_instances, _ServiceProvider_registerValidation;
|
|
7
|
-
import { Identifiers } from "@mainsail/contracts";
|
|
8
|
-
import { Providers } from "@mainsail/kernel";
|
|
9
|
-
import { Deserializer } from "./deserializer.js";
|
|
10
|
-
import { MessageFactory } from "./factory.js";
|
|
11
|
-
import { makeKeywords } from "./keywords.js";
|
|
12
|
-
import { schemas } from "./schemas.js";
|
|
13
|
-
import { Serializer } from "./serializer.js";
|
|
14
|
-
export { Proposal } from "./proposal.js";
|
|
15
|
-
export class ServiceProvider extends Providers.ServiceProvider {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
_ServiceProvider_instances.add(this);
|
|
19
|
-
}
|
|
20
|
-
async register() {
|
|
21
|
-
this.app.bind(Identifiers.Cryptography.Message.Serializer).to(Serializer).inSingletonScope();
|
|
22
|
-
this.app.bind(Identifiers.Cryptography.Message.Deserializer).to(Deserializer).inSingletonScope();
|
|
23
|
-
this.app.bind(Identifiers.Cryptography.Message.Factory).to(MessageFactory).inSingletonScope();
|
|
24
|
-
__classPrivateFieldGet(this, _ServiceProvider_instances, "m", _ServiceProvider_registerValidation).call(this);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
_ServiceProvider_instances = new WeakSet(), _ServiceProvider_registerValidation = function _ServiceProvider_registerValidation() {
|
|
28
|
-
for (const keyword of Object.values(makeKeywords(this.app.get(Identifiers.Cryptography.Configuration)))) {
|
|
29
|
-
this.app.get(Identifiers.Cryptography.Validator).addKeyword(keyword);
|
|
30
|
-
}
|
|
31
|
-
for (const schema of Object.values(schemas)) {
|
|
32
|
-
this.app.get(Identifiers.Cryptography.Validator).addSchema(schema);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
1
|
+
export * from "./service-provider.js";
|
|
35
2
|
//# 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,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Contracts } from "@mainsail/contracts";
|
|
2
|
+
export declare class Message implements Contracts.Crypto.Message {
|
|
3
|
+
#private;
|
|
4
|
+
constructor({ blockHash, blockNumber, round, serialized, signature, type, validatorIndex, }: Contracts.Crypto.MessageData & {
|
|
5
|
+
serialized: Buffer;
|
|
6
|
+
});
|
|
7
|
+
get type(): Contracts.Crypto.MessageType;
|
|
8
|
+
get blockNumber(): number;
|
|
9
|
+
get round(): number;
|
|
10
|
+
get blockHash(): string | undefined;
|
|
11
|
+
get validatorIndex(): number;
|
|
12
|
+
get signature(): string;
|
|
13
|
+
get serialized(): Buffer;
|
|
14
|
+
toData(): Contracts.Crypto.MessageData;
|
|
15
|
+
toString(): string;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../source/message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,qBAAa,OAAQ,YAAW,SAAS,CAAC,MAAM,CAAC,OAAO;;gBAS3C,EACX,SAAS,EACT,WAAW,EACX,KAAK,EACL,UAAU,EACV,SAAS,EACT,IAAI,EACJ,cAAc,GACd,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE;IAUxD,IAAI,IAAI,IAAI,SAAS,CAAC,MAAM,CAAC,WAAW,CAEvC;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,SAAS,IAAI,MAAM,GAAG,SAAS,CAElC;IAED,IAAI,cAAc,IAAI,MAAM,CAE3B;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,WAAW;IAWtC,QAAQ,IAAI,MAAM;CAGlB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export class Message {
|
|
2
|
+
#type;
|
|
3
|
+
#blockNumber;
|
|
4
|
+
#round;
|
|
5
|
+
#blockHash;
|
|
6
|
+
#validatorIndex;
|
|
7
|
+
#signature;
|
|
8
|
+
#serialized;
|
|
9
|
+
constructor({ blockHash, blockNumber, round, serialized, signature, type, validatorIndex, }) {
|
|
10
|
+
this.#type = type;
|
|
11
|
+
this.#blockNumber = blockNumber;
|
|
12
|
+
this.#round = round;
|
|
13
|
+
this.#blockHash = blockHash;
|
|
14
|
+
this.#validatorIndex = validatorIndex;
|
|
15
|
+
this.#signature = signature;
|
|
16
|
+
this.#serialized = serialized;
|
|
17
|
+
}
|
|
18
|
+
get type() {
|
|
19
|
+
return this.#type;
|
|
20
|
+
}
|
|
21
|
+
get blockNumber() {
|
|
22
|
+
return this.#blockNumber;
|
|
23
|
+
}
|
|
24
|
+
get round() {
|
|
25
|
+
return this.#round;
|
|
26
|
+
}
|
|
27
|
+
get blockHash() {
|
|
28
|
+
return this.#blockHash;
|
|
29
|
+
}
|
|
30
|
+
get validatorIndex() {
|
|
31
|
+
return this.#validatorIndex;
|
|
32
|
+
}
|
|
33
|
+
get signature() {
|
|
34
|
+
return this.#signature;
|
|
35
|
+
}
|
|
36
|
+
get serialized() {
|
|
37
|
+
return this.#serialized;
|
|
38
|
+
}
|
|
39
|
+
toData() {
|
|
40
|
+
return {
|
|
41
|
+
blockHash: this.#blockHash,
|
|
42
|
+
blockNumber: this.#blockNumber,
|
|
43
|
+
round: this.#round,
|
|
44
|
+
signature: this.#signature,
|
|
45
|
+
type: this.#type,
|
|
46
|
+
validatorIndex: this.#validatorIndex,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
toString() {
|
|
50
|
+
return JSON.stringify(this.toData());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../source/message.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,OAAO;IACnB,KAAK,CAA+B;IACpC,YAAY,CAAS;IACrB,MAAM,CAAS;IACf,UAAU,CAAqB;IAC/B,eAAe,CAAS;IACxB,UAAU,CAAS;IACnB,WAAW,CAAS;IAEpB,YAAY,EACX,SAAS,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1
|
-
import { AnySchemaObject } from "ajv";
|
|
2
|
-
export declare const schemas: Record<"
|
|
1
|
+
import type { AnySchemaObject } from "ajv";
|
|
2
|
+
export declare const schemas: Record<"message", AnySchemaObject>;
|
|
3
3
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AAI3C,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,eAAe,CAetD,CAAC"}
|