@mainsail/crypto-block 0.0.1-alpha.1

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.
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _Deserializer_instances, _Deserializer_deserializeBufferHeader, _Deserializer_deserializeTransactions;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Deserializer = void 0;
19
+ /* eslint-disable sort-keys-fix/sort-keys-fix */
20
+ const container_1 = require("@mainsail/container");
21
+ const contracts_1 = require("@mainsail/contracts");
22
+ const crypto_transaction_1 = require("@mainsail/crypto-transaction");
23
+ const utils_1 = require("@mainsail/utils");
24
+ const id_factory_1 = require("./id.factory");
25
+ let Deserializer = class Deserializer {
26
+ constructor() {
27
+ _Deserializer_instances.add(this);
28
+ }
29
+ async deserializeHeader(serialized) {
30
+ const buffer = utils_1.ByteBuffer.fromBuffer(serialized);
31
+ const header = await __classPrivateFieldGet(this, _Deserializer_instances, "m", _Deserializer_deserializeBufferHeader).call(this, buffer);
32
+ header.id = await this.idFactory.make(header);
33
+ return header;
34
+ }
35
+ async deserializeWithTransactions(serialized) {
36
+ const buffer = utils_1.ByteBuffer.fromBuffer(serialized);
37
+ const block = await __classPrivateFieldGet(this, _Deserializer_instances, "m", _Deserializer_deserializeBufferHeader).call(this, buffer);
38
+ let transactions = [];
39
+ if (buffer.getRemainderLength() > 0) {
40
+ transactions = await __classPrivateFieldGet(this, _Deserializer_instances, "m", _Deserializer_deserializeTransactions).call(this, block, buffer);
41
+ }
42
+ block.id = await this.idFactory.make(block);
43
+ return { data: block, transactions };
44
+ }
45
+ };
46
+ exports.Deserializer = Deserializer;
47
+ _Deserializer_instances = new WeakSet();
48
+ _Deserializer_deserializeBufferHeader = async function _Deserializer_deserializeBufferHeader(buffer) {
49
+ const block = {};
50
+ await this.serializer.deserialize(buffer, block, {
51
+ length: this.blockSerializer.headerSize(),
52
+ schema: {
53
+ version: {
54
+ type: "uint8",
55
+ },
56
+ timestamp: {
57
+ type: "uint48",
58
+ },
59
+ height: {
60
+ type: "uint32",
61
+ },
62
+ round: {
63
+ type: "uint32",
64
+ },
65
+ previousBlock: {
66
+ type: "hash",
67
+ },
68
+ numberOfTransactions: {
69
+ type: "uint16",
70
+ },
71
+ totalAmount: {
72
+ type: "bigint",
73
+ },
74
+ totalFee: {
75
+ type: "bigint",
76
+ },
77
+ reward: {
78
+ type: "bigint",
79
+ },
80
+ payloadLength: {
81
+ type: "uint32",
82
+ },
83
+ payloadHash: {
84
+ type: "hash",
85
+ },
86
+ generatorPublicKey: {
87
+ type: "publicKey",
88
+ },
89
+ },
90
+ });
91
+ return block;
92
+ };
93
+ _Deserializer_deserializeTransactions = async function _Deserializer_deserializeTransactions(block, buf) {
94
+ await this.serializer.deserialize(buf, block, {
95
+ length: block.payloadLength,
96
+ schema: {
97
+ transactions: {
98
+ type: "transactions",
99
+ },
100
+ },
101
+ });
102
+ /**
103
+ * After unpacking we need to turn the transactions into DTOs!
104
+ *
105
+ * We keep this behaviour out of the (de)serialiser because it
106
+ * is very specific to this bit of code in this specific class.
107
+ */
108
+ const transactions = [];
109
+ for (let index = 0; index < block.transactions.length; index++) {
110
+ const transaction = await this.transactionFactory.fromBytes(block.transactions[index]);
111
+ transactions.push(transaction);
112
+ block.transactions[index] = transaction.data;
113
+ }
114
+ return transactions;
115
+ };
116
+ __decorate([
117
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Block.IDFactory),
118
+ __metadata("design:type", id_factory_1.IDFactory)
119
+ ], Deserializer.prototype, "idFactory", void 0);
120
+ __decorate([
121
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Transaction.Factory),
122
+ __metadata("design:type", crypto_transaction_1.TransactionFactory)
123
+ ], Deserializer.prototype, "transactionFactory", void 0);
124
+ __decorate([
125
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Serializer),
126
+ __metadata("design:type", Object)
127
+ ], Deserializer.prototype, "serializer", void 0);
128
+ __decorate([
129
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Block.Serializer),
130
+ __metadata("design:type", Object)
131
+ ], Deserializer.prototype, "blockSerializer", void 0);
132
+ exports.Deserializer = Deserializer = __decorate([
133
+ (0, container_1.injectable)()
134
+ ], Deserializer);
135
+ //# sourceMappingURL=deserializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deserializer.js","sourceRoot":"","sources":["../source/deserializer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,gDAAgD;AAChD,mDAAyD;AACzD,mDAAoE;AACpE,qEAAkE;AAClE,2CAA6C;AAE7C,6CAAyC;AAGlC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAAlB;;IAsHP,CAAC;IAzGO,KAAK,CAAC,iBAAiB,CAAC,UAAkB;QAChD,MAAM,MAAM,GAAe,kBAAU,CAAC,UAAU,CAAC,UAAU,C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AS;+CAAC;AAGtB;IADhB,IAAA,kBAAM,EAAC,uBAAW,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC;8BACf,uCAAkB;wDAAC;AAGxC;IADhB,IAAA,kBAAM,EAAC,uBAAW,CAAC,YAAY,CAAC,UAAU,CAAC;;gDACkB;AAG7C;IADhB,IAAA,kBAAM,EAAC,uBAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;qDACkB;uBAXxD,YAAY;IADxB,IAAA,sBAAU,GAAE;GACA,YAAY,CAsHxB"}
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ import { Contracts, Utils } from "@mainsail/contracts";
3
+ export declare class BlockFactory implements Contracts.Crypto.BlockFactory {
4
+ #private;
5
+ private readonly serializer;
6
+ private readonly deserializer;
7
+ private readonly idFactory;
8
+ private readonly validator;
9
+ make(data: Utils.Mutable<Contracts.Crypto.BlockDataSerializable>): Promise<Contracts.Crypto.Block>;
10
+ fromHex(hex: string): Promise<Contracts.Crypto.Block>;
11
+ fromBytes(buff: Buffer): Promise<Contracts.Crypto.Block>;
12
+ fromJson(json: Contracts.Crypto.BlockJson): Promise<Contracts.Crypto.Block>;
13
+ fromData(data: Contracts.Crypto.BlockData): Promise<Contracts.Crypto.Block>;
14
+ }
15
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +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,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAOlG,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;IAkB3E,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;CA8DxF"}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _BlockFactory_instances, _BlockFactory_fromSerialized, _BlockFactory_applySchema;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.BlockFactory = void 0;
19
+ const container_1 = require("@mainsail/container");
20
+ const contracts_1 = require("@mainsail/contracts");
21
+ const utils_1 = require("@mainsail/utils");
22
+ const block_1 = require("./block");
23
+ const id_factory_1 = require("./id.factory");
24
+ let BlockFactory = class BlockFactory {
25
+ constructor() {
26
+ _BlockFactory_instances.add(this);
27
+ }
28
+ async make(data) {
29
+ const block = data;
30
+ block.id = await this.idFactory.make(data);
31
+ return this.fromData(block);
32
+ }
33
+ async fromHex(hex) {
34
+ return __classPrivateFieldGet(this, _BlockFactory_instances, "m", _BlockFactory_fromSerialized).call(this, Buffer.from(hex, "hex"));
35
+ }
36
+ async fromBytes(buff) {
37
+ return __classPrivateFieldGet(this, _BlockFactory_instances, "m", _BlockFactory_fromSerialized).call(this, buff);
38
+ }
39
+ async fromJson(json) {
40
+ // @ts-ignore
41
+ const data = { ...json };
42
+ data.totalAmount = utils_1.BigNumber.make(data.totalAmount);
43
+ data.totalFee = utils_1.BigNumber.make(data.totalFee);
44
+ data.reward = utils_1.BigNumber.make(data.reward);
45
+ if (data.transactions) {
46
+ for (const transaction of data.transactions) {
47
+ transaction.amount = utils_1.BigNumber.make(transaction.amount);
48
+ transaction.fee = utils_1.BigNumber.make(transaction.fee);
49
+ transaction.nonce = utils_1.BigNumber.make(transaction.nonce);
50
+ }
51
+ }
52
+ return this.fromData(data);
53
+ }
54
+ async fromData(data) {
55
+ await __classPrivateFieldGet(this, _BlockFactory_instances, "m", _BlockFactory_applySchema).call(this, data);
56
+ const serialized = await this.serializer.serializeWithTransactions(data);
57
+ return (0, block_1.sealBlock)({
58
+ ...(await this.deserializer.deserializeWithTransactions(serialized)),
59
+ serialized: serialized.toString("hex"),
60
+ });
61
+ }
62
+ };
63
+ exports.BlockFactory = BlockFactory;
64
+ _BlockFactory_instances = new WeakSet();
65
+ _BlockFactory_fromSerialized = async function _BlockFactory_fromSerialized(serialized) {
66
+ const deserialized = await this.deserializer.deserializeWithTransactions(serialized);
67
+ const validated = await __classPrivateFieldGet(this, _BlockFactory_instances, "m", _BlockFactory_applySchema).call(this, deserialized.data);
68
+ if (validated) {
69
+ deserialized.data = validated;
70
+ }
71
+ return (0, block_1.sealBlock)({
72
+ ...deserialized,
73
+ serialized: serialized.toString("hex"),
74
+ });
75
+ };
76
+ _BlockFactory_applySchema = async function _BlockFactory_applySchema(data) {
77
+ const result = this.validator.validate("block", data);
78
+ if (!result.error) {
79
+ return result.value;
80
+ }
81
+ for (const error of result.errors ?? []) {
82
+ let fatal = false;
83
+ const match = error.instancePath.match(/\.transactions\[(\d+)]/);
84
+ if (match === null) {
85
+ fatal = true;
86
+ }
87
+ else {
88
+ const txIndex = match[1];
89
+ if (data.transactions) {
90
+ const tx = data.transactions[txIndex];
91
+ if (tx.id === undefined) {
92
+ fatal = true;
93
+ }
94
+ }
95
+ }
96
+ if (fatal) {
97
+ throw new contracts_1.Exceptions.BlockSchemaError(data.height, `Invalid data${error.instancePath ? " at " + error.instancePath : ""}: ` +
98
+ `${error.message}: ${JSON.stringify(error.data)}`);
99
+ }
100
+ }
101
+ return result.value;
102
+ };
103
+ __decorate([
104
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Block.Serializer),
105
+ __metadata("design:type", Object)
106
+ ], BlockFactory.prototype, "serializer", void 0);
107
+ __decorate([
108
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Block.Deserializer),
109
+ __metadata("design:type", Object)
110
+ ], BlockFactory.prototype, "deserializer", void 0);
111
+ __decorate([
112
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Block.IDFactory),
113
+ __metadata("design:type", id_factory_1.IDFactory)
114
+ ], BlockFactory.prototype, "idFactory", void 0);
115
+ __decorate([
116
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Validator),
117
+ __metadata("design:type", Object)
118
+ ], BlockFactory.prototype, "validator", void 0);
119
+ exports.BlockFactory = BlockFactory = __decorate([
120
+ (0, container_1.injectable)()
121
+ ], BlockFactory);
122
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,mDAAyD;AACzD,mDAAgF;AAChF,2CAA4C;AAE5C,mCAAoC;AACpC,6CAAyC;AAGlC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAAlB;;IA4GP,CAAC;IA/FO,KAAK,CAAC,IAAI,CAAC,IAA2D;QAC5E,MAAM,KAAK,GAAG,IAAiD,CAAC;QAChE,KAAK,CAAC,EAAE,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE3C,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7B,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,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,IAAgC;QACrD,aAAa;QACb,MAAM,IAAI,GAA8C,EAAE,GAAG,IAAI,EAAE,CAAC;QACpE,IAAI,CAAC,WAAW,GAAG,iBAAS,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,GAAG,iBAAS,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,iBAAS,CAAC,IAAI,CAAC,IAAI,CAA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KAAK,CAAC;AACrB,CAAC;AAzGgB;IADhB,IAAA,kBAAM,EAAC,uBAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;gDACa;AAG9C;IADhB,IAAA,kBAAM,EAAC,uBAAW,CAAC,YAAY,CAAC,KAAK,CAAC,YAAY,CAAC;;kDACe;AAGlD;IADhB,IAAA,kBAAM,EAAC,uBAAW,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC;8BACpB,sBAAS;+CAAC;AAGtB;IADhB,IAAA,kBAAM,EAAC,uBAAW,CAAC,YAAY,CAAC,SAAS,CAAC;;+CACa;uBAX5C,YAAY;IADxB,IAAA,sBAAU,GAAE;GACA,YAAY,CA4GxB"}
@@ -0,0 +1,7 @@
1
+ import { Contracts } from "@mainsail/contracts";
2
+ export declare class IDFactory {
3
+ private readonly hashFactory;
4
+ private readonly serializer;
5
+ make(data: Contracts.Crypto.BlockDataSerializable): Promise<string>;
6
+ }
7
+ //# sourceMappingURL=id.factory.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.IDFactory = void 0;
13
+ const container_1 = require("@mainsail/container");
14
+ const contracts_1 = require("@mainsail/contracts");
15
+ let IDFactory = class IDFactory {
16
+ async make(data) {
17
+ return (await this.hashFactory.sha256(await this.serializer.serializeHeader(data))).toString("hex");
18
+ }
19
+ };
20
+ exports.IDFactory = IDFactory;
21
+ __decorate([
22
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Hash.Factory),
23
+ __metadata("design:type", Object)
24
+ ], IDFactory.prototype, "hashFactory", void 0);
25
+ __decorate([
26
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Block.Serializer),
27
+ __metadata("design:type", Object)
28
+ ], IDFactory.prototype, "serializer", void 0);
29
+ exports.IDFactory = IDFactory = __decorate([
30
+ (0, container_1.injectable)()
31
+ ], IDFactory);
32
+ //# sourceMappingURL=id.factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.factory.js","sourceRoot":"","sources":["../source/id.factory.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAyD;AACzD,mDAA6D;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;AAVY,8BAAS;AAEJ;IADhB,IAAA,kBAAM,EAAC,uBAAW,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;;8CACc;AAG3C;IADhB,IAAA,kBAAM,EAAC,uBAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;6CACa;oBALnD,SAAS;IADrB,IAAA,sBAAU,GAAE;GACA,SAAS,CAUrB"}
@@ -0,0 +1,12 @@
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";
8
+ export declare class ServiceProvider extends Providers.ServiceProvider {
9
+ register(): Promise<void>;
10
+ requiredByWorker(): boolean;
11
+ }
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAE3B,qBAAa,eAAgB,SAAQ,SAAS,CAAC,eAAe;IAChD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAY/B,gBAAgB,IAAI,OAAO;CAGlC"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
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 {
33
+ async register() {
34
+ this.app.bind(contracts_1.Identifiers.Cryptography.Block.Deserializer).to(deserializer_1.Deserializer).inSingletonScope();
35
+ this.app.bind(contracts_1.Identifiers.Cryptography.Block.Factory).to(factory_1.BlockFactory).inSingletonScope();
36
+ this.app.bind(contracts_1.Identifiers.Cryptography.Block.IDFactory).to(id_factory_1.IDFactory).inSingletonScope();
37
+ this.app.bind(contracts_1.Identifiers.Cryptography.Block.Serializer).to(serializer_1.Serializer).inSingletonScope();
38
+ this.app.bind(contracts_1.Identifiers.Cryptography.Block.Verifier).to(verifier_1.Verifier).inSingletonScope();
39
+ for (const schema of Object.values(schemas_1.schemas)) {
40
+ this.app.get(contracts_1.Identifiers.Cryptography.Validator).addSchema(schema);
41
+ }
42
+ }
43
+ requiredByWorker() {
44
+ return true;
45
+ }
46
+ }
47
+ exports.ServiceProvider = ServiceProvider;
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAA6D;AAC7D,6CAA6C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AEM,gBAAgB;QACtB,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAhBD,0CAgBC"}
@@ -0,0 +1,3 @@
1
+ import { AnySchemaObject } from "ajv";
2
+ export declare const schemas: Record<"block" | "blockId" | "blockHeader", AnySchemaObject>;
3
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +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,CAAC,OAAO,GAAG,SAAS,GAAG,aAAa,EAAE,eAAe,CAqDhF,CAAC"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.schemas = void 0;
4
+ exports.schemas = {
5
+ block: {
6
+ $id: "block",
7
+ $ref: "blockHeader",
8
+ properties: {
9
+ transactions: {
10
+ $ref: "transactions",
11
+ maxItems: { $data: "1/numberOfTransactions" },
12
+ minItems: { $data: "1/numberOfTransactions" },
13
+ type: "array",
14
+ },
15
+ },
16
+ type: "object",
17
+ },
18
+ blockHeader: {
19
+ $id: "blockHeader",
20
+ properties: {
21
+ generatorPublicKey: { $ref: "publicKey" },
22
+ height: { minimum: 0, type: "integer" },
23
+ id: { $ref: "blockId" },
24
+ numberOfTransactions: { minimum: 0, type: "integer" },
25
+ payloadHash: { $ref: "hex" },
26
+ payloadLength: { minimum: 0, type: "integer" },
27
+ previousBlock: { $ref: "blockId" },
28
+ reward: { bignumber: { minimum: 0 } },
29
+ timestamp: { maximum: 2 ** 48 - 1, minimum: 0, type: "integer" },
30
+ totalAmount: { bignumber: { minimum: 0 } },
31
+ totalFee: { bignumber: { minimum: 0 } },
32
+ version: { enum: [1] },
33
+ },
34
+ required: [
35
+ "id",
36
+ "timestamp",
37
+ "previousBlock",
38
+ "height",
39
+ "totalAmount",
40
+ "totalFee",
41
+ "reward",
42
+ "generatorPublicKey",
43
+ ],
44
+ type: "object",
45
+ },
46
+ blockId: {
47
+ $id: "blockId",
48
+ allOf: [
49
+ {
50
+ $ref: "hex",
51
+ maxLength: 64,
52
+ minLength: 64,
53
+ },
54
+ ],
55
+ type: "string",
56
+ },
57
+ };
58
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../source/schemas.ts"],"names":[],"mappings":";;;AAEa,QAAA,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,kBAAkB,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YACzC,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,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,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;SACtB;QACD,QAAQ,EAAE;YACT,IAAI;YACJ,WAAW;YACX,eAAe;YACf,QAAQ;YACR,aAAa;YACb,UAAU;YACV,QAAQ;YACR,oBAAoB;SACpB;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"}
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import { Contracts } from "@mainsail/contracts";
3
+ export declare class Serializer implements Contracts.Crypto.BlockSerializer {
4
+ private readonly serializer;
5
+ private readonly hashByteLength;
6
+ private readonly generatorPublicKeyByteLength;
7
+ headerSize(): number;
8
+ totalSize(block: Contracts.Crypto.BlockDataSerializable): number;
9
+ serializeHeader(block: Contracts.Crypto.BlockDataSerializable): Promise<Buffer>;
10
+ serializeWithTransactions(block: Contracts.Crypto.BlockDataSerializable): Promise<Buffer>;
11
+ }
12
+ //# sourceMappingURL=serializer.d.ts.map
@@ -0,0 +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;IAIzC,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAAU;IAEhD,UAAU,IAAI,MAAM;IAiBpB,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;IA6C/E,yBAAyB,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;CA+CtG"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Serializer = void 0;
13
+ /* eslint-disable sort-keys-fix/sort-keys-fix */
14
+ const container_1 = require("@mainsail/container");
15
+ const contracts_1 = require("@mainsail/contracts");
16
+ let Serializer = class Serializer {
17
+ headerSize() {
18
+ return (1 + // version
19
+ 6 + // timestamp
20
+ 4 + // height
21
+ 4 + // round
22
+ this.hashByteLength + // previousBlock
23
+ 2 + // numberOfTransactions
24
+ 8 + // totalAmount
25
+ 8 + // totalFee
26
+ 8 + // reward
27
+ 4 + // payloadLength
28
+ this.hashByteLength + // payloadHash
29
+ this.generatorPublicKeyByteLength);
30
+ }
31
+ totalSize(block) {
32
+ return this.headerSize() + block.payloadLength;
33
+ }
34
+ async serializeHeader(block) {
35
+ return this.serializer.serialize(block, {
36
+ length: this.headerSize(),
37
+ skip: 0,
38
+ schema: {
39
+ version: {
40
+ type: "uint8",
41
+ },
42
+ timestamp: {
43
+ type: "uint48",
44
+ },
45
+ height: {
46
+ type: "uint32",
47
+ },
48
+ round: {
49
+ type: "uint32",
50
+ },
51
+ previousBlock: {
52
+ type: "hash",
53
+ },
54
+ numberOfTransactions: {
55
+ type: "uint16",
56
+ },
57
+ totalAmount: {
58
+ type: "bigint",
59
+ },
60
+ totalFee: {
61
+ type: "bigint",
62
+ },
63
+ reward: {
64
+ type: "bigint",
65
+ },
66
+ payloadLength: {
67
+ type: "uint32",
68
+ },
69
+ payloadHash: {
70
+ type: "hash",
71
+ },
72
+ generatorPublicKey: {
73
+ type: "publicKey",
74
+ },
75
+ },
76
+ });
77
+ }
78
+ async serializeWithTransactions(block) {
79
+ return this.serializer.serialize(block, {
80
+ length: this.totalSize(block),
81
+ skip: 0,
82
+ schema: {
83
+ version: {
84
+ type: "uint8",
85
+ },
86
+ timestamp: {
87
+ type: "uint48",
88
+ },
89
+ height: {
90
+ type: "uint32",
91
+ },
92
+ round: {
93
+ type: "uint32",
94
+ },
95
+ previousBlock: {
96
+ type: "hash",
97
+ },
98
+ numberOfTransactions: {
99
+ type: "uint16",
100
+ },
101
+ totalAmount: {
102
+ type: "bigint",
103
+ },
104
+ totalFee: {
105
+ type: "bigint",
106
+ },
107
+ reward: {
108
+ type: "bigint",
109
+ },
110
+ payloadLength: {
111
+ type: "uint32",
112
+ },
113
+ payloadHash: {
114
+ type: "hash",
115
+ },
116
+ generatorPublicKey: {
117
+ type: "publicKey",
118
+ },
119
+ transactions: {
120
+ type: "transactions",
121
+ },
122
+ },
123
+ });
124
+ }
125
+ };
126
+ exports.Serializer = Serializer;
127
+ __decorate([
128
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Serializer),
129
+ (0, container_1.tagged)("type", "wallet"),
130
+ __metadata("design:type", Object)
131
+ ], Serializer.prototype, "serializer", void 0);
132
+ __decorate([
133
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Hash.Size.SHA256),
134
+ __metadata("design:type", Number)
135
+ ], Serializer.prototype, "hashByteLength", void 0);
136
+ __decorate([
137
+ (0, container_1.inject)(contracts_1.Identifiers.Cryptography.Identity.PublicKey.Size),
138
+ (0, container_1.tagged)("type", "wallet"),
139
+ __metadata("design:type", Number)
140
+ ], Serializer.prototype, "generatorPublicKeyByteLength", void 0);
141
+ exports.Serializer = Serializer = __decorate([
142
+ (0, container_1.injectable)()
143
+ ], Serializer);
144
+ //# sourceMappingURL=serializer.js.map