@cello-protocol/protocol-types 0.0.21 → 0.0.22
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/dist/cbor.d.ts +5 -0
- package/dist/cbor.d.ts.map +1 -0
- package/dist/cbor.js +31 -0
- package/dist/cbor.js.map +1 -0
- package/dist/connection-package.d.ts +4 -0
- package/dist/connection-package.d.ts.map +1 -1
- package/dist/connection-package.js +5 -6
- package/dist/connection-package.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +10 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +10 -0
- package/dist/limits.js.map +1 -0
- package/dist/manifest.d.ts +2 -4
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +2 -4
- package/dist/manifest.js.map +1 -1
- package/dist/primary-transfer.d.ts +5 -7
- package/dist/primary-transfer.d.ts.map +1 -1
- package/dist/primary-transfer.js +7 -12
- package/dist/primary-transfer.js.map +1 -1
- package/dist/revocation.d.ts.map +1 -1
- package/dist/revocation.js +2 -5
- package/dist/revocation.js.map +1 -1
- package/dist/session-liveness.js +4 -4
- package/dist/session-liveness.js.map +1 -1
- package/dist/session.d.ts +26 -61
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +22 -54
- package/dist/session.js.map +1 -1
- package/dist/structure1.d.ts +16 -0
- package/dist/structure1.d.ts.map +1 -0
- package/dist/structure1.js +33 -0
- package/dist/structure1.js.map +1 -0
- package/dist/structure2.d.ts.map +1 -1
- package/dist/structure2.js +7 -8
- package/dist/structure2.js.map +1 -1
- package/package.json +2 -2
- package/dist/envelope.d.ts +0 -170
- package/dist/envelope.d.ts.map +0 -1
- package/dist/envelope.js +0 -776
- package/dist/envelope.js.map +0 -1
package/dist/envelope.d.ts
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @cello-protocol/protocol-types — CELLO-MSG-001 (v0) + CELLO-MSG-003 (v1)
|
|
3
|
-
* Envelope construction, validation, serialization, and deserialization.
|
|
4
|
-
*
|
|
5
|
-
* ──── v0 Pseudocode (CELLO-MSG-001) ────
|
|
6
|
-
*
|
|
7
|
-
* buildEnvelope(content, keyProvider, timestamp):
|
|
8
|
-
* 1. Reject if content.length > MAX_CONTENT_BYTES (1,048,576) → content_too_large
|
|
9
|
-
* 2. Compute content_hash = msgLeafHash(content) [FIPS 180-4: SHA-256(0x00||content)]
|
|
10
|
-
* 3. Fetch sender_pubkey = await keyProvider.getPublicKey()
|
|
11
|
-
* 4. Build TBS positional array: [0, content_hash, sender_pubkey, timestamp]
|
|
12
|
-
* — timestamp encoded as BigInt so cbor-x emits uint64, not float64
|
|
13
|
-
* 5. tbs_bytes = encodeTBS([0, content_hash, sender_pubkey, BigInt(timestamp)])
|
|
14
|
-
* [RFC 8949 §4.2.1: canonical CBOR, Encoder({tagUint8Array:false})]
|
|
15
|
-
* 6. sender_signature = await keyProvider.sign(tbs_bytes) [RFC 8032: Ed25519]
|
|
16
|
-
* 7. Return envelope with all six fields populated
|
|
17
|
-
*
|
|
18
|
-
* validateEnvelope(envelope):
|
|
19
|
-
* 1. Check protocol_version === 0 → unsupported_version
|
|
20
|
-
* 2. Check presence + exact byte lengths of all typed fields:
|
|
21
|
-
* sender_pubkey: 32 bytes → missing_field / invalid_field
|
|
22
|
-
* content_hash: 32 bytes → missing_field / invalid_field
|
|
23
|
-
* sender_signature: 64 bytes → missing_field / invalid_field
|
|
24
|
-
* 3. Check timestamp >= 0 → invalid_field
|
|
25
|
-
* 4. Check content.length <= MAX_CONTENT_BYTES → content_too_large
|
|
26
|
-
* 5. Recompute expected_hash = msgLeafHash(content)
|
|
27
|
-
* Compare byte-by-byte to content_hash → content_hash_mismatch (BEFORE sig check)
|
|
28
|
-
* 6. Rebuild TBS bytes (same as step 5 in build)
|
|
29
|
-
* 7. verify(sender_pubkey, tbs_bytes, sender_signature) → invalid_field('sender_signature')
|
|
30
|
-
* 8. Return ok: true
|
|
31
|
-
*
|
|
32
|
-
* ──── v1 Pseudocode (CELLO-MSG-003) ────
|
|
33
|
-
*
|
|
34
|
-
* buildEnvelopeV1(content, keyProvider, timestamp, session_id, last_seen_seq):
|
|
35
|
-
* 1. Reject if content.length > MAX_CONTENT_BYTES → content_too_large
|
|
36
|
-
* [no hash/sig computed before this check — AC-009]
|
|
37
|
-
* 2. Compute content_hash = msgLeafHash(content) [FIPS 180-4: SHA-256(0x00||content)]
|
|
38
|
-
* Caller-supplied hashes ignored — SI-001
|
|
39
|
-
* 3. Fetch sender_pubkey = await keyProvider.getPublicKey()
|
|
40
|
-
* 4. Build Structure 1 (TBS) positional 6-element array:
|
|
41
|
-
* [1, content_hash, sender_pubkey, session_id, last_seen_seq, timestamp]
|
|
42
|
-
* — protocol_version=1 (CBOR uint)
|
|
43
|
-
* — content_hash: 32-byte CBOR bstr (SHA-256(0x00||content))
|
|
44
|
-
* — sender_pubkey: 32-byte CBOR bstr (Ed25519 public key, RFC 8032)
|
|
45
|
-
* — session_id: 16-byte CBOR bstr
|
|
46
|
-
* — last_seen_seq: CBOR uint (non-negative integer)
|
|
47
|
-
* — timestamp: CBOR uint (Unix ms; BigInt when > 0xFFFFFFFF for minimal encoding
|
|
48
|
-
* per RFC 8949 §4.2.1)
|
|
49
|
-
* 5. tbs_bytes = CBOR_ENC.encode(tbs_array)
|
|
50
|
-
* [RFC 8949 §4.2.1: canonical CBOR, Encoder({tagUint8Array:false})]
|
|
51
|
-
* 6. sender_signature = await keyProvider.sign(tbs_bytes) [RFC 8032: Ed25519]
|
|
52
|
-
* 7. Return MessageEnvelopeV1 with all eight fields populated
|
|
53
|
-
*
|
|
54
|
-
* validateEnvelopeV1(envelope):
|
|
55
|
-
* 1. Check protocol_version === 1 → unsupported_version (AC-003, AC-004)
|
|
56
|
-
* Hard-reject: no v0 fallback, no negotiation (M1 drops v0)
|
|
57
|
-
* 2. Field presence + byte-length checks:
|
|
58
|
-
* sender_pubkey: 32 bytes → missing_field / invalid_field
|
|
59
|
-
* content_hash: 32 bytes → missing_field / invalid_field
|
|
60
|
-
* session_id: 16 bytes → missing_field / invalid_field
|
|
61
|
-
* sender_signature: 64 bytes → missing_field / invalid_field
|
|
62
|
-
* 3. Check last_seen_seq >= 0, integer → invalid_field
|
|
63
|
-
* 4. Check timestamp >= 0, integer → invalid_field
|
|
64
|
-
* 5. Check content.length <= MAX_CONTENT_BYTES → content_too_large
|
|
65
|
-
* 6. Recompute expected_hash = msgLeafHash(content)
|
|
66
|
-
* Compare byte-by-byte to content_hash → content_hash_mismatch (BEFORE sig check)
|
|
67
|
-
* 7. Rebuild Structure 1 TBS bytes (same as step 5 in build)
|
|
68
|
-
* 8. verify(sender_pubkey, tbs_bytes, sender_signature) → invalid_field('sender_signature')
|
|
69
|
-
* 9. Return ok: true
|
|
70
|
-
*
|
|
71
|
-
* extractStructure1(envelope: MessageEnvelopeV1) → Uint8Array:
|
|
72
|
-
* 1. Build positional 6-element array from envelope fields
|
|
73
|
-
* 2. Return CBOR_ENC.encode([1, content_hash, sender_pubkey, session_id, last_seen_seq, timestamp])
|
|
74
|
-
* This is the exact bytes the relay uses to build Structure 2 (MERKLE-002)
|
|
75
|
-
*
|
|
76
|
-
* References:
|
|
77
|
-
* RFC 8949 §4.2.1 — Core Deterministic Encoding Requirements
|
|
78
|
-
* RFC 8032 — Edwards-Curve Digital Signature Algorithm (EdDSA)
|
|
79
|
-
* FIPS 180-4 — SHA-256 (used by msgLeafHash for content_hash computation)
|
|
80
|
-
*/
|
|
81
|
-
import type { KeyProvider } from "@cello-protocol/crypto";
|
|
82
|
-
import type { MessageEnvelope, MessageEnvelopeV1, BuildResult, BuildResultV1, ValidateResult, ValidateResultV1, DeserializeResult, DeserializeResultV1 } from "./types.js";
|
|
83
|
-
/** Maximum allowed content size: 1 MiB (AC-009, AC-010, AC-011). */
|
|
84
|
-
export declare const MAX_CONTENT_BYTES = 1048576;
|
|
85
|
-
/**
|
|
86
|
-
* Build a signed MessageEnvelope.
|
|
87
|
-
*
|
|
88
|
-
* SI-001: content_hash is ALWAYS recomputed; any caller-supplied value is ignored.
|
|
89
|
-
* AC-010: content > 1 MiB → content_too_large, no hash or signature computed.
|
|
90
|
-
*
|
|
91
|
-
* @param content - Raw message bytes
|
|
92
|
-
* @param keyProvider - Signing key abstraction (K_local)
|
|
93
|
-
* @param timestamp - Unix milliseconds (non-negative)
|
|
94
|
-
*/
|
|
95
|
-
export declare function buildEnvelope(content: Uint8Array, keyProvider: KeyProvider, timestamp: number): Promise<BuildResult>;
|
|
96
|
-
/**
|
|
97
|
-
* Validate a MessageEnvelope.
|
|
98
|
-
*
|
|
99
|
-
* Validation order (fail-fast):
|
|
100
|
-
* 1. protocol_version check (AC-013, SI-004) — before any other check
|
|
101
|
-
* 2. Field presence and byte-length checks (AC-003, AC-004)
|
|
102
|
-
* 3. timestamp range check (AC-005)
|
|
103
|
-
* 4. content size check (AC-011)
|
|
104
|
-
* 5. content_hash recomputation and comparison (AC-012) — BEFORE signature check
|
|
105
|
-
* 6. Signature verification (AC-002, AC-007, SI-003)
|
|
106
|
-
*/
|
|
107
|
-
export declare function validateEnvelope(envelope: MessageEnvelope): ValidateResult;
|
|
108
|
-
/**
|
|
109
|
-
* Serialize a MessageEnvelope to canonical CBOR bytes (RFC 8949 §4.2.1).
|
|
110
|
-
*
|
|
111
|
-
* The envelope is encoded as a CBOR map with string keys.
|
|
112
|
-
* timestamp uses minimal encoding per RFC 8949 §4.2.1 — see encodeTBS comment.
|
|
113
|
-
*/
|
|
114
|
-
export declare function serializeEnvelope(envelope: MessageEnvelope): Uint8Array;
|
|
115
|
-
/**
|
|
116
|
-
* Deserialize a MessageEnvelope from CBOR bytes.
|
|
117
|
-
*
|
|
118
|
-
* Performs structural validation only (field presence, types, sizes).
|
|
119
|
-
* Does NOT re-validate the signature or content_hash — call validateEnvelope for that.
|
|
120
|
-
*/
|
|
121
|
-
export declare function deserializeEnvelope(bytes: Uint8Array): DeserializeResult;
|
|
122
|
-
/**
|
|
123
|
-
* Build a signed v1 MessageEnvelopeV1 (CELLO-MSG-003).
|
|
124
|
-
*
|
|
125
|
-
* SI-001: content_hash is ALWAYS recomputed from content; any caller-supplied value is ignored.
|
|
126
|
-
* AC-009: content > 1 MiB → content_too_large, no hash or signature computed.
|
|
127
|
-
*
|
|
128
|
-
* @param content - Raw message bytes (up to 1 MiB)
|
|
129
|
-
* @param keyProvider - Signing key abstraction (K_local)
|
|
130
|
-
* @param timestamp - Unix milliseconds (non-negative)
|
|
131
|
-
* @param session_id - 16-byte session identifier
|
|
132
|
-
* @param last_seen_seq - Highest canonical seq number seen from relay (0 for first message)
|
|
133
|
-
*/
|
|
134
|
-
export declare function buildEnvelopeV1(content: Uint8Array, keyProvider: KeyProvider, timestamp: number, session_id: Uint8Array, last_seen_seq: number): Promise<BuildResultV1>;
|
|
135
|
-
/**
|
|
136
|
-
* Validate a v1 MessageEnvelopeV1 (CELLO-MSG-003).
|
|
137
|
-
*
|
|
138
|
-
* Validation order (fail-fast):
|
|
139
|
-
* 1. protocol_version === 1 check — hard-reject v0 and any other version (AC-003, AC-004)
|
|
140
|
-
* 2. Field presence and byte-length checks
|
|
141
|
-
* 3. last_seen_seq and timestamp range checks
|
|
142
|
-
* 4. content size check
|
|
143
|
-
* 5. content_hash recomputation (BEFORE signature check) (AC-006)
|
|
144
|
-
* 6. Signature verification over Structure 1 TBS
|
|
145
|
-
*/
|
|
146
|
-
export declare function validateEnvelopeV1(envelope: MessageEnvelopeV1): ValidateResultV1;
|
|
147
|
-
/**
|
|
148
|
-
* Serialize a v1 MessageEnvelopeV1 to canonical CBOR bytes (RFC 8949 §4.2.1).
|
|
149
|
-
*
|
|
150
|
-
* The envelope is encoded as a CBOR map with string keys.
|
|
151
|
-
* timestamp uses minimal encoding per RFC 8949 §4.2.1.
|
|
152
|
-
*/
|
|
153
|
-
export declare function serializeEnvelopeV1(envelope: MessageEnvelopeV1): Uint8Array;
|
|
154
|
-
/**
|
|
155
|
-
* Deserialize a v1 MessageEnvelopeV1 from CBOR bytes.
|
|
156
|
-
*
|
|
157
|
-
* Performs structural validation only (field presence, types, sizes).
|
|
158
|
-
* Does NOT re-validate the signature or content_hash — call validateEnvelopeV1 for that.
|
|
159
|
-
*/
|
|
160
|
-
export declare function deserializeEnvelopeV1(bytes: Uint8Array): DeserializeResultV1;
|
|
161
|
-
/**
|
|
162
|
-
* Extract Structure 1 from a v1 envelope — returns the canonical CBOR bytes that were signed.
|
|
163
|
-
*
|
|
164
|
-
* Structure 1: canonical_CBOR([1, content_hash, sender_pubkey, session_id, last_seen_seq, timestamp])
|
|
165
|
-
*
|
|
166
|
-
* This is the exact bytes the relay uses to build Structure 2 (CELLO-MERKLE-002).
|
|
167
|
-
* Per RFC 8949 §4.2.1 canonical CBOR and RFC 8032 Ed25519.
|
|
168
|
-
*/
|
|
169
|
-
export declare function extractStructure1(envelope: MessageEnvelopeV1): Uint8Array;
|
|
170
|
-
//# sourceMappingURL=envelope.d.ts.map
|
package/dist/envelope.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,oEAAoE;AACpE,eAAO,MAAM,iBAAiB,UAAY,CAAC;AAsC3C;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,WAAW,CAAC,CAiCtB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,eAAe,GAAG,cAAc,CA+H1E;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,UAAU,CAUvE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,iBAAiB,CA8FxE;AA8BD;;;;;;;;;;;GAWG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,UAAU,EACnB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,aAAa,CAAC,CA+CxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,gBAAgB,CAuJhF;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,UAAU,CAY3E;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,mBAAmB,CAmH5E;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,UAAU,CAQzE"}
|