@leofcoin/messages 1.6.4 → 2.0.0

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.
Files changed (67) hide show
  1. package/exports/binary-format.d.ts +22 -0
  2. package/exports/binary-format.js +121 -0
  3. package/exports/block.js +52 -0
  4. package/exports/bw-request.js +17 -0
  5. package/exports/bw.js +20 -0
  6. package/exports/contract.js +20 -0
  7. package/exports/index.d.ts +1 -0
  8. package/exports/index.js +1 -0
  9. package/exports/last-block-request.js +17 -0
  10. package/exports/last-block.js +20 -0
  11. package/exports/messages/beacon-activation.d.ts +1 -1
  12. package/exports/messages/beacon-activation.js +1 -1
  13. package/exports/messages/beacon-commitment.d.ts +1 -1
  14. package/exports/messages/beacon-commitment.js +1 -1
  15. package/exports/messages/beacon-share.d.ts +1 -1
  16. package/exports/messages/beacon-share.js +1 -1
  17. package/exports/messages/block.d.ts +1 -1
  18. package/exports/messages/block.js +3 -4
  19. package/exports/messages/bw-request.d.ts +1 -1
  20. package/exports/messages/bw-request.js +1 -1
  21. package/exports/messages/bw.d.ts +1 -1
  22. package/exports/messages/bw.js +1 -1
  23. package/exports/messages/contract.d.ts +1 -1
  24. package/exports/messages/contract.js +3 -1
  25. package/exports/messages/last-block-request.d.ts +1 -1
  26. package/exports/messages/last-block-request.js +1 -1
  27. package/exports/messages/last-block.d.ts +1 -1
  28. package/exports/messages/last-block.js +1 -1
  29. package/exports/messages/precommit.d.ts +1 -1
  30. package/exports/messages/precommit.js +1 -1
  31. package/exports/messages/prevote.d.ts +1 -1
  32. package/exports/messages/prevote.js +1 -1
  33. package/exports/messages/proposal.d.ts +1 -1
  34. package/exports/messages/proposal.js +1 -1
  35. package/exports/messages/publish.d.ts +1 -1
  36. package/exports/messages/publish.js +1 -1
  37. package/exports/messages/raw-transaction.d.ts +1 -1
  38. package/exports/messages/raw-transaction.js +1 -1
  39. package/exports/messages/state.d.ts +1 -1
  40. package/exports/messages/state.js +1 -1
  41. package/exports/messages/transaction.d.ts +1 -1
  42. package/exports/messages/transaction.js +1 -1
  43. package/exports/messages/validator.d.ts +1 -1
  44. package/exports/messages/validator.js +1 -1
  45. package/exports/protos/beacon-activation.proto.js +3 -2
  46. package/exports/protos/beacon-commitment.proto.js +3 -2
  47. package/exports/protos/beacon-share.proto.js +3 -2
  48. package/exports/protos/block.proto.js +3 -2
  49. package/exports/protos/bw-request.proto.js +2 -1
  50. package/exports/protos/bw.proto.js +3 -2
  51. package/exports/protos/contract.proto.js +3 -2
  52. package/exports/protos/last-block-request.proto.js +2 -1
  53. package/exports/protos/last-block.proto.js +3 -2
  54. package/exports/protos/precommit.proto.js +3 -2
  55. package/exports/protos/prevote.proto.js +3 -2
  56. package/exports/protos/proposal.proto.js +3 -2
  57. package/exports/protos/publish.proto.js +3 -2
  58. package/exports/protos/raw-transaction.proto.js +3 -2
  59. package/exports/protos/state.proto.js +3 -2
  60. package/exports/protos/transaction.proto.js +3 -2
  61. package/exports/protos/validator.proto.js +3 -2
  62. package/exports/schema.d.ts +2 -0
  63. package/exports/schema.js +2 -0
  64. package/exports/state.js +20 -0
  65. package/exports/transaction.js +34 -0
  66. package/exports/validator.js +20 -0
  67. package/package.json +5 -5
@@ -0,0 +1,22 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ type Kind = 'any' | 'bytes' | 'array' | 'bigint' | 'string' | 'number' | 'boolean' | 'object' | 'function' | 'symbol';
3
+ type Field = {
4
+ key: string;
5
+ name: string;
6
+ kind: Kind;
7
+ };
8
+ /** Codec prefix + versioned binary tuple, in declared schema order. No proto-array JSON. */
9
+ export declare class BinaryFormat extends FormatInterface {
10
+ protected field(key: string, value: any, kind?: Kind): any;
11
+ create(value: any): void;
12
+ protected tuple(value: any, fields: readonly Field[]): any[];
13
+ protoEncode(value: any): Uint8Array<ArrayBufferLike>;
14
+ encode(value?: any): Uint8Array;
15
+ protoDecode(bytes: Uint8Array): {
16
+ [k: string]: any;
17
+ };
18
+ decode(bytes?: Uint8Array): object;
19
+ fromUint8Array(bytes: Uint8Array): object;
20
+ fromArrayBuffer(buffer: ArrayBuffer): object;
21
+ }
22
+ export {};
@@ -0,0 +1,121 @@
1
+ import { FormatInterface, Codec } from '@leofcoin/codec-format-interface';
2
+ import { encodeValue, encodeValueWithPrefix, decodeValue } from '@leofcoin/binary';
3
+ const schemas = new WeakMap();
4
+ const kindOf = (value) => value === undefined ? 'any'
5
+ : value instanceof Uint8Array ? 'bytes' : Array.isArray(value) ? 'array' : typeof value;
6
+ function schemaFor(proto) {
7
+ const cached = schemas.get(proto);
8
+ if (cached)
9
+ return cached;
10
+ const keys = Object.keys(proto);
11
+ const schema = {
12
+ fields: keys.map(key => ({
13
+ key, name: key.endsWith('?') ? key.slice(0, -1) : key, kind: kindOf(proto[key])
14
+ })),
15
+ prefixes: new Map()
16
+ };
17
+ // Only immutable declarations can safely reuse keys, types and codec framing.
18
+ // Caller-defined mutable schemas remain supported and are recompiled per operation.
19
+ if (Object.isFrozen(proto) && keys.every(key => 'value' in Object.getOwnPropertyDescriptor(proto, key)))
20
+ schemas.set(proto, schema);
21
+ return schema;
22
+ }
23
+ function codecPrefix(schema, name) {
24
+ let prefix = schema.prefixes.get(name);
25
+ if (!prefix) {
26
+ const codec = new Codec(name);
27
+ if (!codec.codecBuffer)
28
+ throw new Error('invalid codec');
29
+ prefix = new Uint8Array(codec.codecBuffer);
30
+ schema.prefixes.set(name, prefix);
31
+ }
32
+ return prefix;
33
+ }
34
+ /** Codec prefix + versioned binary tuple, in declared schema order. No proto-array JSON. */
35
+ export class BinaryFormat extends FormatInterface {
36
+ field(key, value, kind) {
37
+ if (value === undefined)
38
+ return value;
39
+ kind ??= kindOf(this.proto[key]);
40
+ if (kind === 'any')
41
+ return value;
42
+ if (kind === 'bigint') {
43
+ if (typeof value === 'number' && !Number.isSafeInteger(value))
44
+ throw new TypeError('Unsafe integer message field');
45
+ if (!['number', 'string', 'bigint'].includes(typeof value))
46
+ throw new TypeError('Invalid BigInt message field');
47
+ return BigInt(value);
48
+ }
49
+ if (kind === 'bytes') {
50
+ if (!(value instanceof Uint8Array))
51
+ throw new TypeError('Message byte field must be Uint8Array');
52
+ }
53
+ else if (kind === 'array') {
54
+ if (!Array.isArray(value))
55
+ throw new TypeError('Message array field must be an array');
56
+ }
57
+ else if (typeof value !== kind || value === null)
58
+ throw new TypeError('Message field type mismatch');
59
+ return value;
60
+ }
61
+ create(value) {
62
+ const { fields } = schemaFor(this.proto);
63
+ // Content hashes are derived, never trusted from a caller-supplied cache field.
64
+ this.decoded = Object.fromEntries(fields.map(field => {
65
+ const input = value?.[field.name];
66
+ return [field.name, field.kind === 'bigint' ? this.field(field.key, input, field.kind) : input];
67
+ }));
68
+ }
69
+ tuple(value, fields) {
70
+ const tuple = new Array(fields.length);
71
+ for (let index = 0; index < fields.length; index++) {
72
+ const field = fields[index];
73
+ tuple[index] = this.field(field.key, value[field.name], field.kind);
74
+ }
75
+ return tuple;
76
+ }
77
+ protoEncode(value) {
78
+ return encodeValue(this.tuple(value, schemaFor(this.proto).fields));
79
+ }
80
+ encode(value) {
81
+ value = value || this.decoded;
82
+ const schema = schemaFor(this.proto);
83
+ const prefix = codecPrefix(schema, this.name);
84
+ if (value instanceof Uint8Array) {
85
+ // Preserve the base interface's already-encoded-content path.
86
+ const output = new Uint8Array(prefix.length + value.length);
87
+ output.set(prefix);
88
+ output.set(value, prefix.length);
89
+ this.encoded = output;
90
+ }
91
+ else {
92
+ this.encoded = encodeValueWithPrefix(this.tuple(value, schema.fields), prefix);
93
+ }
94
+ return this.encoded;
95
+ }
96
+ protoDecode(bytes) {
97
+ const values = decodeValue(bytes);
98
+ const { fields } = schemaFor(this.proto);
99
+ if (!Array.isArray(values) || values.length !== fields.length)
100
+ throw new TypeError('Binary message schema mismatch');
101
+ return Object.fromEntries(fields.map((field, index) => {
102
+ const value = this.field(field.key, values[index], field.kind);
103
+ if (typeof value !== typeof values[index])
104
+ throw new TypeError('Non-canonical message field type');
105
+ return [field.name, value];
106
+ }));
107
+ }
108
+ decode(bytes) {
109
+ bytes ??= this.encoded;
110
+ if (!(bytes instanceof Uint8Array))
111
+ throw new TypeError('Message payload must be Uint8Array');
112
+ const codec = new Codec(bytes);
113
+ if (codec.name !== this.name)
114
+ throw new TypeError('Wrong binary message codec');
115
+ // Parse the codec once and borrow its content view; decoded byte fields still own copies.
116
+ this.decoded = this.protoDecode(bytes.subarray(codec.codecBuffer.length));
117
+ return this.decoded;
118
+ }
119
+ fromUint8Array(bytes) { this.encoded = bytes; return this.decode(bytes); }
120
+ fromArrayBuffer(buffer) { return this.fromUint8Array(new Uint8Array(buffer)); }
121
+ }
@@ -0,0 +1,52 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import ValidatorMessage from './validator.js';
3
+ import smartConcat from '@vandeurenglenn/typed-array-smart-concat';
4
+ import smartDeconcat from '@vandeurenglenn/typed-array-smart-deconcat';
5
+
6
+ var proto = {
7
+ index: BigInt(0),
8
+ previousHash: String(),
9
+ timestamp: Number(),
10
+ reward: BigInt(0),
11
+ fees: BigInt(0),
12
+ transactions: Array(),
13
+ validators: new Uint8Array(),
14
+ producer: String(),
15
+ producerProof: String(),
16
+ protocolVersion: String()
17
+ };
18
+
19
+ class BlockMessage extends FormatInterface {
20
+ get messageName() {
21
+ return 'BlockMessage';
22
+ }
23
+ constructor(buffer) {
24
+ if (buffer instanceof BlockMessage)
25
+ return buffer;
26
+ const name = 'block-message';
27
+ super(buffer, proto, { name });
28
+ }
29
+ encode(decoded) {
30
+ decoded = decoded || this.decoded;
31
+ const validators = [];
32
+ for (const validator of decoded.validators) {
33
+ if (validator instanceof ValidatorMessage)
34
+ validators.push(validator.encode());
35
+ else
36
+ validators.push(new ValidatorMessage(validator).encode());
37
+ }
38
+ return super.encode({
39
+ ...decoded,
40
+ validators: smartConcat(validators)
41
+ });
42
+ }
43
+ decode(encoded) {
44
+ encoded = encoded || this.encoded;
45
+ super.decode(encoded);
46
+ // @ts-ignore
47
+ this.decoded.validators = smartDeconcat(this.decoded.validators).map((validator) => new ValidatorMessage(validator).decoded);
48
+ return this.decoded;
49
+ }
50
+ }
51
+
52
+ export { BlockMessage as default };
@@ -0,0 +1,17 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {};
4
+
5
+ class BWRequestMessage extends FormatInterface {
6
+ get messageName() {
7
+ return 'BWRequestMessage';
8
+ }
9
+ constructor(buffer) {
10
+ if (buffer instanceof BWRequestMessage)
11
+ return buffer;
12
+ const name = 'bw-request-message';
13
+ super(buffer, proto, { name });
14
+ }
15
+ }
16
+
17
+ export { BWRequestMessage as default };
package/exports/bw.js ADDED
@@ -0,0 +1,20 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ up: Number(),
5
+ down: Number()
6
+ };
7
+
8
+ class BWMessage extends FormatInterface {
9
+ get messageName() {
10
+ return 'BWMessage';
11
+ }
12
+ constructor(buffer) {
13
+ if (buffer instanceof BWMessage)
14
+ return buffer;
15
+ const name = 'bw-message';
16
+ super(buffer, proto, { name });
17
+ }
18
+ }
19
+
20
+ export { BWMessage as default };
@@ -0,0 +1,20 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ creator: String(),
5
+ contract: new Uint8Array(),
6
+ constructorParameters: Array()
7
+ };
8
+
9
+ class ContractMessage extends FormatInterface {
10
+ get messageName() {
11
+ return 'ContractMessage';
12
+ }
13
+ constructor(buffer) {
14
+ if (buffer instanceof ContractMessage)
15
+ return buffer;
16
+ super(buffer, proto, { name: 'contract-message' });
17
+ }
18
+ }
19
+
20
+ export { ContractMessage as default };
@@ -14,3 +14,4 @@ export { default as StateMessage } from './messages/state.js';
14
14
  export { default as PrevoteMessage } from './messages/prevote.js';
15
15
  export { default as PrecommitMessage } from './messages/precommit.js';
16
16
  export { default as ProposalMessage } from './messages/proposal.js';
17
+ export { BinaryFormat } from './binary-format.js';
package/exports/index.js CHANGED
@@ -14,3 +14,4 @@ export { default as StateMessage } from './messages/state.js';
14
14
  export { default as PrevoteMessage } from './messages/prevote.js';
15
15
  export { default as PrecommitMessage } from './messages/precommit.js';
16
16
  export { default as ProposalMessage } from './messages/proposal.js';
17
+ export { BinaryFormat } from './binary-format.js';
@@ -0,0 +1,17 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {};
4
+
5
+ class LastBlockRequestMessage extends FormatInterface {
6
+ get messageName() {
7
+ return 'LastBlockRequestMessage';
8
+ }
9
+ constructor(buffer) {
10
+ if (buffer instanceof LastBlockRequestMessage)
11
+ return buffer;
12
+ const name = 'last-block-request-message';
13
+ super(buffer, proto, { name });
14
+ }
15
+ }
16
+
17
+ export { LastBlockRequestMessage as default };
@@ -0,0 +1,20 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ hash: String(),
5
+ index: BigInt(0)
6
+ };
7
+
8
+ class LastBlockMessage extends FormatInterface {
9
+ get messageName() {
10
+ return 'LastBlockMessage';
11
+ }
12
+ constructor(buffer) {
13
+ if (buffer instanceof LastBlockMessage)
14
+ return buffer;
15
+ const name = 'last-block-message';
16
+ super(buffer, proto, { name });
17
+ }
18
+ }
19
+
20
+ export { LastBlockMessage as default };
@@ -1,4 +1,4 @@
1
- import { FormatInterface } from '@leofcoin/codec-format-interface';
1
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
2
2
  import proto from '../protos/beacon-activation.proto.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class BeaconActivationMessage extends FormatInterface {
@@ -1,4 +1,4 @@
1
- import { FormatInterface } from '@leofcoin/codec-format-interface';
1
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
2
2
  import proto from '../protos/beacon-activation.proto.js';
3
3
  export default class BeaconActivationMessage extends FormatInterface {
4
4
  get messageName() {
@@ -1,4 +1,4 @@
1
- import { FormatInterface } from '@leofcoin/codec-format-interface';
1
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
2
2
  import proto from '../protos/beacon-commitment.proto.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class BeaconCommitmentMessage extends FormatInterface {
@@ -1,4 +1,4 @@
1
- import { FormatInterface } from '@leofcoin/codec-format-interface';
1
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
2
2
  import proto from '../protos/beacon-commitment.proto.js';
3
3
  export default class BeaconCommitmentMessage extends FormatInterface {
4
4
  get messageName() {
@@ -1,4 +1,4 @@
1
- import { FormatInterface } from '@leofcoin/codec-format-interface';
1
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
2
2
  import proto from '../protos/beacon-share.proto.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class BeaconShareMessage extends FormatInterface {
@@ -1,4 +1,4 @@
1
- import { FormatInterface } from '@leofcoin/codec-format-interface';
1
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
2
2
  import proto from '../protos/beacon-share.proto.js';
3
3
  export default class BeaconShareMessage extends FormatInterface {
4
4
  get messageName() {
@@ -1,4 +1,4 @@
1
- import { FormatInterface } from '@leofcoin/codec-format-interface';
1
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
2
2
  import TransactionMessage from './transaction.js';
3
3
  import ValidatorMessage from './validator.js';
4
4
  import { messageInput } from '../types.js';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/block.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import ValidatorMessage from './validator.js';
4
4
  import { encodeFrames, decodeFrames } from '@leofcoin/binary';
5
5
  export default class BlockMessage extends FormatInterface {
@@ -30,9 +30,8 @@ export default class BlockMessage extends FormatInterface {
30
30
  encoded = encoded || this.encoded;
31
31
  super.decode(encoded);
32
32
  // @ts-ignore
33
- // Preserve historical acceptance of padded length prefixes. Tightening
34
- // canonical protocol validation is a separate, versioned decision.
35
- this.decoded.validators = decodeFrames(this.decoded.validators, 0, { canonical: false }).map((validator) => new ValidatorMessage(validator).decoded);
33
+ // Binary-only protocol also requires canonical validator frame lengths.
34
+ this.decoded.validators = decodeFrames(this.decoded.validators).map((validator) => new ValidatorMessage(validator).decoded);
36
35
  return this.decoded;
37
36
  }
38
37
  }
@@ -1,5 +1,5 @@
1
1
  import proto from './../protos/bw-request.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class BWRequestMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from './../protos/bw-request.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class BWRequestMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'BWRequestMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/bw.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class BWMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/bw.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class BWMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'BWMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/contract.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class ContractMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/contract.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class ContractMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'ContractMessage';
@@ -7,6 +7,8 @@ export default class ContractMessage extends FormatInterface {
7
7
  constructor(buffer) {
8
8
  if (buffer instanceof ContractMessage)
9
9
  return buffer;
10
+ if (buffer && typeof buffer === 'object' && !(buffer instanceof Uint8Array) && typeof buffer.contract === 'string')
11
+ buffer = { ...buffer, contract: new TextEncoder().encode(buffer.contract) };
10
12
  super(buffer, proto, { name: 'contract-message' });
11
13
  }
12
14
  }
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/last-block-request.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class LastBlockRequestMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/last-block-request.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class LastBlockRequestMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'LastBlockRequestMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/last-block.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class LastBlockMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/last-block.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class LastBlockMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'LastBlockMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/precommit.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class PrecommitMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/precommit.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class PrecommitMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'PrecommitMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/prevote.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class PrevoteMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/prevote.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class PrevoteMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'PrevoteMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/proposal.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class ProposalMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/proposal.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class ProposalMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'ProposalMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/publish.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class publishMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/publish.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class publishMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'PublishMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/raw-transaction.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class RawTransactionMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/raw-transaction.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class RawTransactionMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'RawTransactionMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/state.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class StateMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/state.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class StateMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'StateMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from './../protos/transaction.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class TransactionMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from './../protos/transaction.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class TransactionMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'TransactionMessage';
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/validator.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  import type { messageInput } from '../types.js';
4
4
  export default class ValidatorMessage extends FormatInterface {
5
5
  decoded: typeof proto;
@@ -1,5 +1,5 @@
1
1
  import proto from '../protos/validator.proto.js';
2
- import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+ import { BinaryFormat as FormatInterface } from '../binary-format.js';
3
3
  export default class ValidatorMessage extends FormatInterface {
4
4
  get messageName() {
5
5
  return 'ValidatorMessage';
@@ -1,6 +1,7 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  epoch: BigInt(0),
3
4
  configDigest: String(),
4
5
  from: String(),
5
6
  signature: String()
6
- };
7
+ });
@@ -1,8 +1,9 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  epoch: BigInt(0),
3
4
  threshold: BigInt(0),
4
5
  participant: BigInt(0),
5
6
  from: String(),
6
7
  commitments: Array(),
7
8
  signature: String()
8
- };
9
+ });
@@ -1,8 +1,9 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  epoch: BigInt(0),
3
4
  round: BigInt(0),
4
5
  participant: BigInt(0),
5
6
  from: String(),
6
7
  signatureShare: String(),
7
8
  signature: String()
8
- };
9
+ });
@@ -1,4 +1,5 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  index: BigInt(0),
3
4
  previousHash: String(),
4
5
  timestamp: Number(),
@@ -9,4 +10,4 @@ export default {
9
10
  producer: String(),
10
11
  producerProof: String(),
11
12
  protocolVersion: String()
12
- };
13
+ });
@@ -1 +1,2 @@
1
- export default {};
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({});
@@ -1,4 +1,5 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  up: Number(),
3
4
  down: Number()
4
- };
5
+ });
@@ -1,5 +1,6 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  creator: String(),
3
4
  contract: new Uint8Array(),
4
5
  constructorParameters: Array()
5
- };
6
+ });
@@ -1 +1,2 @@
1
- export default {};
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({});
@@ -1,4 +1,5 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  hash: String(),
3
4
  index: BigInt(0)
4
- };
5
+ });
@@ -1,7 +1,8 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  blockHash: String(),
3
4
  index: BigInt(0),
4
5
  round: BigInt(0),
5
6
  from: String(),
6
7
  signature: String()
7
- };
8
+ });
@@ -1,7 +1,8 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  blockHash: String(),
3
4
  index: BigInt(0),
4
5
  round: BigInt(0),
5
6
  from: String(),
6
7
  signature: String()
7
- };
8
+ });
@@ -1,7 +1,8 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  blockHash: String(),
3
4
  index: BigInt(0),
4
5
  round: BigInt(0),
5
6
  from: String(),
6
7
  signature: String()
7
- };
8
+ });
@@ -1,7 +1,8 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  name: String(),
3
4
  version: Number(),
4
5
  publisher: String(),
5
6
  entry: String(),
6
7
  files: new Uint8Array()
7
- };
8
+ });
@@ -1,8 +1,9 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  timestamp: Number(),
3
4
  from: String(),
4
5
  to: String(),
5
6
  method: String(),
6
7
  params: Array(),
7
8
  'nonce?': Number()
8
- };
9
+ });
@@ -1,4 +1,5 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  lastblock: Object(),
3
4
  values: Object()
4
- };
5
+ });
@@ -1,4 +1,5 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  timestamp: Number(),
3
4
  from: String(),
4
5
  to: String(),
@@ -8,4 +9,4 @@ export default {
8
9
  'nonce?': Number(),
9
10
  'dependsOn?': Array(),
10
11
  'priority?': Boolean()
11
- };
12
+ });
@@ -1,4 +1,5 @@
1
- export default {
1
+ import { defineSchema } from '../schema.js';
2
+ export default defineSchema({
2
3
  address: String(),
3
4
  reward: BigInt(0)
4
- };
5
+ });
@@ -0,0 +1,2 @@
1
+ /** Freeze declarations, not decoded messages. Keep existing consumer field types mutable. */
2
+ export declare const defineSchema: <T extends object>(proto: T) => T;
@@ -0,0 +1,2 @@
1
+ /** Freeze declarations, not decoded messages. Keep existing consumer field types mutable. */
2
+ export const defineSchema = (proto) => Object.freeze(proto);
@@ -0,0 +1,20 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ lastblock: Object(),
5
+ values: Object()
6
+ };
7
+
8
+ class StateMessage extends FormatInterface {
9
+ get messageName() {
10
+ return 'StateMessage';
11
+ }
12
+ constructor(buffer) {
13
+ if (buffer instanceof StateMessage)
14
+ return buffer;
15
+ const name = 'state-message';
16
+ super(buffer, proto, { name });
17
+ }
18
+ }
19
+
20
+ export { StateMessage as default };
@@ -0,0 +1,34 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ timestamp: Number(),
5
+ from: String(),
6
+ to: String(),
7
+ method: String(),
8
+ params: Array(),
9
+ signature: String(),
10
+ 'nonce?': Number(),
11
+ 'dependsOn?': Array(),
12
+ 'priority?': Boolean()
13
+ };
14
+
15
+ class TransactionMessage extends FormatInterface {
16
+ get messageName() {
17
+ return 'TransactionMessage';
18
+ }
19
+ constructor(buffer) {
20
+ if (buffer instanceof TransactionMessage)
21
+ return buffer;
22
+ const name = 'transaction-message';
23
+ super(buffer, proto, { name });
24
+ }
25
+ beforeHashing(decoded) {
26
+ decoded = super.beforeHashing(decoded);
27
+ delete decoded.signature;
28
+ delete decoded.priority;
29
+ delete decoded.dependsOn;
30
+ return decoded;
31
+ }
32
+ }
33
+
34
+ export { TransactionMessage as default };
@@ -0,0 +1,20 @@
1
+ import { FormatInterface } from '@leofcoin/codec-format-interface';
2
+
3
+ var proto = {
4
+ address: String(),
5
+ reward: BigInt(0)
6
+ };
7
+
8
+ class ValidatorMessage extends FormatInterface {
9
+ get messageName() {
10
+ return 'ValidatorMessage';
11
+ }
12
+ constructor(buffer) {
13
+ if (buffer instanceof ValidatorMessage)
14
+ return buffer;
15
+ const name = 'validator-message';
16
+ super(buffer, proto, { name });
17
+ }
18
+ }
19
+
20
+ export { ValidatorMessage as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/messages",
3
- "version": "1.6.4",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "private": false,
6
6
  "exports": {
@@ -272,16 +272,16 @@
272
272
  "license": "MIT",
273
273
  "devDependencies": {
274
274
  "@leofcoin/types": "^1.0.26",
275
- "@rollup/plugin-typescript": "^12.3.0",
275
+ "@rollup/plugin-typescript": "^12.3.1",
276
276
  "@typescript/native": "npm:typescript@^7.0.2",
277
- "rollup": "^4.62.4",
277
+ "rollup": "^4.66.0",
278
278
  "rollup-plugin-auto-exports": "^1.1.1",
279
279
  "tslib": "^2.8.1",
280
280
  "typescript": "npm:@typescript/typescript6@^6.0.2"
281
281
  },
282
282
  "dependencies": {
283
- "@leofcoin/binary": "^1.0.1",
284
- "@leofcoin/codec-format-interface": "^1.8.2",
283
+ "@leofcoin/binary": "^1.1.0",
284
+ "@leofcoin/codec-format-interface": "^2.0.0",
285
285
  "@leofcoin/utils": "^1.1.45"
286
286
  },
287
287
  "repository": {