@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,UAAU,cAAc;IACvB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;CAC7C;AAED,eAAO,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,UAAU,cAAc;IACvB,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;CAC7C;AAED,eAAO,MAAM,SAAS,GAAI,oCAAoC,cAAc,KAAG,SAAS,CAAC,MAAM,CAAC,KAS7F,CAAC"}
|
package/distribution/block.js
CHANGED
|
@@ -3,7 +3,7 @@ export const sealBlock = ({ data, serialized, transactions }) => Object.seal({
|
|
|
3
3
|
header: data,
|
|
4
4
|
serialized,
|
|
5
5
|
transactions: transactions.map((transaction, index) => {
|
|
6
|
-
transaction.data.
|
|
6
|
+
transaction.data.transactionIndex = index;
|
|
7
7
|
return transaction;
|
|
8
8
|
}),
|
|
9
9
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.js","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAkB,EAA0B,EAAE,CACvG,MAAM,CAAC,IAAI,CAAC;IACX,IAAI;IACJ,MAAM,EAAE,IAAI;IACZ,UAAU;IACV,YAAY,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;QACrD,WAAW,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../source/block.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAkB,EAA0B,EAAE,CACvG,MAAM,CAAC,IAAI,CAAC;IACX,IAAI;IACJ,MAAM,EAAE,IAAI;IACZ,UAAU;IACV,YAAY,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;QACrD,WAAW,CAAC,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;QAC1C,OAAO,WAAW,CAAC;IACpB,CAAC,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { Contracts } from "@mainsail/contracts";
|
|
3
2
|
export declare class Deserializer implements Contracts.Crypto.BlockDeserializer {
|
|
4
3
|
#private;
|
|
5
|
-
private readonly
|
|
4
|
+
private readonly hashFactory;
|
|
6
5
|
private readonly transactionFactory;
|
|
6
|
+
private readonly transactionDeserializer;
|
|
7
7
|
private readonly serializer;
|
|
8
|
-
private readonly
|
|
8
|
+
private readonly headerSize;
|
|
9
|
+
private readonly workerPool;
|
|
9
10
|
deserializeHeader(serialized: Buffer): Promise<Contracts.Crypto.BlockHeader>;
|
|
10
11
|
deserializeWithTransactions(serialized: Buffer): Promise<Contracts.Crypto.BlockWithTransactions>;
|
|
11
12
|
}
|
|
@@ -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":"AAEA,OAAO,EAAE,SAAS,EAAkC,MAAM,qBAAqB,CAAC;AAMhF,qBACa,YAAa,YAAW,SAAS,CAAC,MAAM,CAAC,iBAAiB;;IAEtE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAG3C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAsB;IAGzD,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAA4C;IAGpF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmC;IAG9D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgB;IAI3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0C;IAExD,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC;IAU5E,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,qBAAqB,CAAC;CAmI7G"}
|
|
@@ -7,134 +7,157 @@ 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
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
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 _Deserializer_instances, _Deserializer_deserializeBufferHeader, _Deserializer_deserializeTransactions;
|
|
16
10
|
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
|
17
|
-
import { inject, injectable } from "@mainsail/container";
|
|
18
|
-
import { Contracts, Identifiers } from "@mainsail/contracts";
|
|
11
|
+
import { inject, injectable, optional } from "@mainsail/container";
|
|
12
|
+
import { Contracts, Exceptions, Identifiers } from "@mainsail/contracts";
|
|
19
13
|
import { TransactionFactory } from "@mainsail/crypto-transaction";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { IDFactory } from "./id.factory.js";
|
|
14
|
+
import { ByteBuffer, sleep } from "@mainsail/utils";
|
|
15
|
+
import { HashFactory } from "./hash.factory.js";
|
|
23
16
|
let Deserializer = class Deserializer {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
hashFactory;
|
|
18
|
+
transactionFactory;
|
|
19
|
+
transactionDeserializer;
|
|
20
|
+
serializer;
|
|
21
|
+
headerSize;
|
|
22
|
+
workerPool;
|
|
27
23
|
async deserializeHeader(serialized) {
|
|
28
24
|
const buffer = ByteBuffer.fromBuffer(serialized);
|
|
29
|
-
const header = await
|
|
30
|
-
header.
|
|
25
|
+
const header = await this.#deserializeBufferHeader(buffer);
|
|
26
|
+
header.hash = await this.hashFactory.make(header);
|
|
31
27
|
return header;
|
|
32
28
|
}
|
|
33
29
|
async deserializeWithTransactions(serialized) {
|
|
34
30
|
const buffer = ByteBuffer.fromBuffer(serialized);
|
|
35
|
-
const block = await
|
|
31
|
+
const block = await this.#deserializeBufferHeader(buffer);
|
|
36
32
|
let transactions = [];
|
|
37
33
|
if (buffer.getRemainderLength() > 0) {
|
|
38
|
-
transactions = await
|
|
34
|
+
transactions = await this.#deserializeTransactions(block, buffer);
|
|
39
35
|
}
|
|
40
|
-
block.
|
|
36
|
+
block.hash = await this.hashFactory.make(block);
|
|
41
37
|
return { data: block, transactions };
|
|
42
38
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
39
|
+
async #deserializeBufferHeader(buffer) {
|
|
40
|
+
const block = {};
|
|
41
|
+
await this.serializer.deserialize(buffer, block, {
|
|
42
|
+
length: this.headerSize(),
|
|
43
|
+
schema: {
|
|
44
|
+
version: {
|
|
45
|
+
type: "uint8",
|
|
46
|
+
},
|
|
47
|
+
timestamp: {
|
|
48
|
+
type: "uint48",
|
|
49
|
+
},
|
|
50
|
+
number: {
|
|
51
|
+
type: "uint32",
|
|
52
|
+
},
|
|
53
|
+
round: {
|
|
54
|
+
type: "uint32",
|
|
55
|
+
},
|
|
56
|
+
parentHash: {
|
|
57
|
+
type: "hash",
|
|
58
|
+
},
|
|
59
|
+
stateRoot: {
|
|
60
|
+
type: "hash",
|
|
61
|
+
},
|
|
62
|
+
logsBloom: {
|
|
63
|
+
type: "hash",
|
|
64
|
+
size: 256,
|
|
65
|
+
},
|
|
66
|
+
transactionsCount: {
|
|
67
|
+
type: "uint16",
|
|
68
|
+
},
|
|
69
|
+
gasUsed: {
|
|
70
|
+
type: "uint32",
|
|
71
|
+
},
|
|
72
|
+
fee: {
|
|
73
|
+
type: "uint256",
|
|
74
|
+
},
|
|
75
|
+
reward: {
|
|
76
|
+
type: "uint256",
|
|
77
|
+
},
|
|
78
|
+
payloadSize: {
|
|
79
|
+
type: "uint32",
|
|
80
|
+
},
|
|
81
|
+
transactionsRoot: {
|
|
82
|
+
type: "hash",
|
|
83
|
+
},
|
|
84
|
+
proposer: {
|
|
85
|
+
type: "address",
|
|
86
|
+
},
|
|
76
87
|
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
type: "hash",
|
|
88
|
-
},
|
|
89
|
-
generatorAddress: {
|
|
90
|
-
type: "address",
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
return block;
|
|
95
|
-
};
|
|
96
|
-
_Deserializer_deserializeTransactions = async function _Deserializer_deserializeTransactions(block, buf) {
|
|
97
|
-
await this.serializer.deserialize(buf, block, {
|
|
98
|
-
length: block.payloadLength,
|
|
99
|
-
schema: {
|
|
100
|
-
transactions: {
|
|
101
|
-
type: "transactions",
|
|
88
|
+
});
|
|
89
|
+
return block;
|
|
90
|
+
}
|
|
91
|
+
async #deserializeTransactions(block, buf) {
|
|
92
|
+
await this.serializer.deserialize(buf, block, {
|
|
93
|
+
length: block.payloadSize,
|
|
94
|
+
schema: {
|
|
95
|
+
transactions: {
|
|
96
|
+
type: "transactions",
|
|
97
|
+
},
|
|
102
98
|
},
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* After unpacking we need to turn the transactions into DTOs!
|
|
102
|
+
*
|
|
103
|
+
* We keep this behaviour out of the (de)serialiser because it
|
|
104
|
+
* is very specific to this bit of code in this specific class.
|
|
105
|
+
*/
|
|
106
|
+
const transactions = new Array(block.transactionsCount);
|
|
107
|
+
await Promise.all(block.transactions.map(async (serialized, index) => {
|
|
108
|
+
const transaction = await this.transactionDeserializer.deserialize(serialized);
|
|
109
|
+
if (index % 20 === 0) {
|
|
110
|
+
await sleep(0);
|
|
111
|
+
}
|
|
112
|
+
const computed = await this.#computeCryptoData(transaction.data);
|
|
113
|
+
if (computed.schemaError) {
|
|
114
|
+
throw new Exceptions.TransactionSchemaError(computed.schemaError);
|
|
115
|
+
}
|
|
116
|
+
transaction.data.data = transaction.data.data.startsWith("0x")
|
|
117
|
+
? transaction.data.data.slice(2)
|
|
118
|
+
: transaction.data.data;
|
|
119
|
+
transaction.data.hash = computed.hash;
|
|
120
|
+
transaction.data.from = computed.address;
|
|
121
|
+
transaction.data.senderPublicKey = computed.publicKey;
|
|
122
|
+
transaction.data.senderLegacyAddress = computed.legacyAddress;
|
|
123
|
+
transactions[index] = transaction;
|
|
124
|
+
block.transactions[index] = transaction.data;
|
|
125
|
+
}));
|
|
126
|
+
return transactions;
|
|
127
|
+
}
|
|
128
|
+
async #computeCryptoData(transaction) {
|
|
129
|
+
if (this.workerPool) {
|
|
130
|
+
const worker = await this.workerPool.getWorker();
|
|
131
|
+
return worker.transactionFactory("computeCryptoData", transaction);
|
|
115
132
|
}
|
|
116
|
-
|
|
117
|
-
transactions.push(transaction);
|
|
118
|
-
block.transactions[index] = transaction.data;
|
|
133
|
+
return this.transactionFactory.computeCryptoData(transaction);
|
|
119
134
|
}
|
|
120
|
-
return transactions;
|
|
121
135
|
};
|
|
122
136
|
__decorate([
|
|
123
|
-
inject(Identifiers.Cryptography.Block.
|
|
124
|
-
__metadata("design:type",
|
|
125
|
-
], Deserializer.prototype, "
|
|
137
|
+
inject(Identifiers.Cryptography.Block.HashFactory),
|
|
138
|
+
__metadata("design:type", HashFactory)
|
|
139
|
+
], Deserializer.prototype, "hashFactory", void 0);
|
|
126
140
|
__decorate([
|
|
127
141
|
inject(Identifiers.Cryptography.Transaction.Factory),
|
|
128
142
|
__metadata("design:type", TransactionFactory)
|
|
129
143
|
], Deserializer.prototype, "transactionFactory", void 0);
|
|
144
|
+
__decorate([
|
|
145
|
+
inject(Identifiers.Cryptography.Transaction.Deserializer),
|
|
146
|
+
__metadata("design:type", Object)
|
|
147
|
+
], Deserializer.prototype, "transactionDeserializer", void 0);
|
|
130
148
|
__decorate([
|
|
131
149
|
inject(Identifiers.Cryptography.Serializer),
|
|
132
150
|
__metadata("design:type", Object)
|
|
133
151
|
], Deserializer.prototype, "serializer", void 0);
|
|
134
152
|
__decorate([
|
|
135
|
-
inject(Identifiers.Cryptography.Block.
|
|
153
|
+
inject(Identifiers.Cryptography.Block.HeaderSize),
|
|
154
|
+
__metadata("design:type", Function)
|
|
155
|
+
], Deserializer.prototype, "headerSize", void 0);
|
|
156
|
+
__decorate([
|
|
157
|
+
inject(Identifiers.CryptoWorker.WorkerPool),
|
|
158
|
+
optional(),
|
|
136
159
|
__metadata("design:type", Object)
|
|
137
|
-
], Deserializer.prototype, "
|
|
160
|
+
], Deserializer.prototype, "workerPool", void 0);
|
|
138
161
|
Deserializer = __decorate([
|
|
139
162
|
injectable()
|
|
140
163
|
], 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":";;;;;;;;;AAAA,gDAAgD;AAChD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAS,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGzC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEP,WAAW,CAAe;IAG1B,kBAAkB,CAAsB;IAGxC,uBAAuB,CAA4C;IAGnE,UAAU,CAAmC;IAG7C,UAAU,CAAgB;IAI1B,UAAU,CAA0C;IAE9D,KAAK,CAAC,iBAAiB,CAAC,UAAkB;QAChD,MAAM,MAAM,GAAe,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAE7D,MAAM,MAAM,GAA8C,MAAM,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC;QAEtG,MAAM,CAAC,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAElD,OAAO,MAAM,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,2BAA2B,CAAC,UAAkB;QAC1D,MAAM,MAA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,UAAU,CAAC;;gDACkB;AAG7C;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC;;gDACP;AAI1B;IAFhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC;IAC3C,QAAQ,EAAE;;gDAC0D;AAlBzD,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CAiKxB"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { Contracts, Utils } from "@mainsail/contracts";
|
|
3
2
|
export declare class BlockFactory implements Contracts.Crypto.BlockFactory {
|
|
4
3
|
#private;
|
|
5
4
|
private readonly serializer;
|
|
6
5
|
private readonly deserializer;
|
|
7
|
-
private readonly
|
|
6
|
+
private readonly hashFactory;
|
|
8
7
|
private readonly validator;
|
|
9
8
|
make(data: Utils.Mutable<Contracts.Crypto.BlockDataSerializable>, transactions: Contracts.Crypto.Transaction[]): Promise<Contracts.Crypto.Block>;
|
|
10
9
|
fromHex(hex: string): Promise<Contracts.Crypto.Block>;
|
|
@@ -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":"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,WAAW,CAAe;IAG3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA8B;IAE3C,IAAI,CAChB,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,qBAAqB,CAAC,EAC3D,YAAY,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,GAC1C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAYrB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAIrD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAIxD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;IAgB3E,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;CA6DxF"}
|
package/distribution/factory.js
CHANGED
|
@@ -7,23 +7,18 @@ 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
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
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 _BlockFactory_instances, _BlockFactory_fromSerialized, _BlockFactory_applySchema;
|
|
16
10
|
import { inject, injectable } from "@mainsail/container";
|
|
17
11
|
import { Contracts, Exceptions, Identifiers } from "@mainsail/contracts";
|
|
18
12
|
import { BigNumber } from "@mainsail/utils";
|
|
19
13
|
import { sealBlock } from "./block.js";
|
|
20
|
-
import {
|
|
14
|
+
import { HashFactory } from "./hash.factory.js";
|
|
21
15
|
let BlockFactory = class BlockFactory {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
serializer;
|
|
17
|
+
deserializer;
|
|
18
|
+
hashFactory;
|
|
19
|
+
validator;
|
|
25
20
|
async make(data, transactions) {
|
|
26
|
-
const block = { ...data,
|
|
21
|
+
const block = { ...data, hash: await this.hashFactory.make(data) };
|
|
27
22
|
const serialized = await this.serializer.serializeWithTransactions(data);
|
|
28
23
|
return sealBlock({
|
|
29
24
|
data: block,
|
|
@@ -32,73 +27,70 @@ let BlockFactory = class BlockFactory {
|
|
|
32
27
|
});
|
|
33
28
|
}
|
|
34
29
|
async fromHex(hex) {
|
|
35
|
-
return
|
|
30
|
+
return this.#fromSerialized(Buffer.from(hex, "hex"));
|
|
36
31
|
}
|
|
37
32
|
async fromBytes(buff) {
|
|
38
|
-
return
|
|
33
|
+
return this.#fromSerialized(buff);
|
|
39
34
|
}
|
|
40
35
|
async fromJson(json) {
|
|
41
36
|
// @ts-ignore
|
|
42
37
|
const data = { ...json };
|
|
43
|
-
data.
|
|
44
|
-
data.totalFee = BigNumber.make(data.totalFee);
|
|
38
|
+
data.fee = BigNumber.make(data.fee);
|
|
45
39
|
data.reward = BigNumber.make(data.reward);
|
|
46
40
|
if (data.transactions) {
|
|
47
41
|
for (const transaction of data.transactions) {
|
|
48
|
-
transaction.
|
|
49
|
-
transaction.fee = BigNumber.make(transaction.fee);
|
|
42
|
+
transaction.value = BigNumber.make(transaction.value);
|
|
50
43
|
transaction.nonce = BigNumber.make(transaction.nonce);
|
|
51
44
|
}
|
|
52
45
|
}
|
|
53
46
|
return this.fromData(data);
|
|
54
47
|
}
|
|
55
48
|
async fromData(data) {
|
|
56
|
-
await
|
|
49
|
+
await this.#applySchema(data);
|
|
57
50
|
const serialized = await this.serializer.serializeWithTransactions(data);
|
|
58
51
|
return sealBlock({
|
|
59
52
|
...(await this.deserializer.deserializeWithTransactions(serialized)),
|
|
60
53
|
serialized: serialized.toString("hex"),
|
|
61
54
|
});
|
|
62
55
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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;
|
|
56
|
+
async #fromSerialized(serialized) {
|
|
57
|
+
const deserialized = await this.deserializer.deserializeWithTransactions(serialized);
|
|
58
|
+
const validated = await this.#applySchema(deserialized.data);
|
|
59
|
+
if (validated) {
|
|
60
|
+
deserialized.data = validated;
|
|
61
|
+
}
|
|
62
|
+
return sealBlock({
|
|
63
|
+
...deserialized,
|
|
64
|
+
serialized: serialized.toString("hex"),
|
|
65
|
+
});
|
|
80
66
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
fatal = true;
|
|
67
|
+
async #applySchema(data) {
|
|
68
|
+
const result = this.validator.validate("block", data);
|
|
69
|
+
if (!result.error) {
|
|
70
|
+
return result.value;
|
|
86
71
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
72
|
+
for (const error of result.errors ?? []) {
|
|
73
|
+
let fatal = false;
|
|
74
|
+
const match = error.instancePath.match(/\.transactions\[(\d+)]/);
|
|
75
|
+
if (match === null) {
|
|
76
|
+
fatal = true;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
if (data.transactions) {
|
|
80
|
+
const txIndex = Number(match[1]);
|
|
81
|
+
const tx = data.transactions[txIndex];
|
|
82
|
+
if (tx.hash === undefined) {
|
|
83
|
+
fatal = true;
|
|
84
|
+
}
|
|
93
85
|
}
|
|
94
86
|
}
|
|
87
|
+
if (fatal) {
|
|
88
|
+
throw new Exceptions.BlockSchemaError(data.number, `Invalid data${error.instancePath ? " at " + error.instancePath : ""}: ` +
|
|
89
|
+
`${error.message}: ${JSON.stringify(error.data)}`);
|
|
90
|
+
}
|
|
95
91
|
}
|
|
96
|
-
|
|
97
|
-
throw new Exceptions.BlockSchemaError(data.height, `Invalid data${error.instancePath ? " at " + error.instancePath : ""}: ` +
|
|
98
|
-
`${error.message}: ${JSON.stringify(error.data)}`);
|
|
99
|
-
}
|
|
92
|
+
return result.value;
|
|
100
93
|
}
|
|
101
|
-
return result.value;
|
|
102
94
|
};
|
|
103
95
|
__decorate([
|
|
104
96
|
inject(Identifiers.Cryptography.Block.Serializer),
|
|
@@ -109,9 +101,9 @@ __decorate([
|
|
|
109
101
|
__metadata("design:type", Object)
|
|
110
102
|
], BlockFactory.prototype, "deserializer", void 0);
|
|
111
103
|
__decorate([
|
|
112
|
-
inject(Identifiers.Cryptography.Block.
|
|
113
|
-
__metadata("design:type",
|
|
114
|
-
], BlockFactory.prototype, "
|
|
104
|
+
inject(Identifiers.Cryptography.Block.HashFactory),
|
|
105
|
+
__metadata("design:type", HashFactory)
|
|
106
|
+
], BlockFactory.prototype, "hashFactory", void 0);
|
|
115
107
|
__decorate([
|
|
116
108
|
inject(Identifiers.Cryptography.Validator),
|
|
117
109
|
__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../source/factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAS,MAAM,qBAAqB,CAAC;AAChF,OAA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,CAAC;;kDACe;AAGlD;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC;8BACpB,WAAW;iDAAC;AAG1B;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC;;+CACa;AAX5C,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CAiHxB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Contracts } from "@mainsail/contracts";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class HashFactory {
|
|
3
3
|
private readonly hashFactory;
|
|
4
4
|
private readonly serializer;
|
|
5
5
|
make(data: Contracts.Crypto.BlockDataSerializable): Promise<string>;
|
|
6
6
|
}
|
|
7
|
-
//# sourceMappingURL=
|
|
7
|
+
//# sourceMappingURL=hash.factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.factory.d.ts","sourceRoot":"","sources":["../source/hash.factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAE7D,qBACa,WAAW;IAEvB,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"}
|
|
@@ -9,7 +9,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
};
|
|
10
10
|
import { inject, injectable } from "@mainsail/container";
|
|
11
11
|
import { Contracts, Identifiers } from "@mainsail/contracts";
|
|
12
|
-
let
|
|
12
|
+
let HashFactory = class HashFactory {
|
|
13
|
+
hashFactory;
|
|
14
|
+
serializer;
|
|
13
15
|
async make(data) {
|
|
14
16
|
return (await this.hashFactory.sha256(await this.serializer.serializeHeader(data))).toString("hex");
|
|
15
17
|
}
|
|
@@ -17,13 +19,13 @@ let IDFactory = class IDFactory {
|
|
|
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":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGtD,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEN,WAAW,CAAgC;IAG3C,UAAU,CAAoC;IAExD,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;;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,10 +1,9 @@
|
|
|
1
1
|
import { Providers } from "@mainsail/kernel";
|
|
2
2
|
export * from "./deserializer.js";
|
|
3
3
|
export * from "./factory.js";
|
|
4
|
-
export * from "./
|
|
4
|
+
export * from "./hash.factory.js";
|
|
5
5
|
export * from "./schemas.js";
|
|
6
6
|
export * from "./serializer.js";
|
|
7
|
-
export * from "./verifier.js";
|
|
8
7
|
export declare class ServiceProvider extends Providers.ServiceProvider {
|
|
9
8
|
register(): Promise<void>;
|
|
10
9
|
}
|
|
@@ -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":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAQ7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAEhC,qBACa,eAAgB,SAAQ,SAAS,CAAC,eAAe;IAChD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAgCtC"}
|