@cello-protocol/protocol-types 0.0.2
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/connection-package.d.ts +362 -0
- package/dist/connection-package.d.ts.map +1 -0
- package/dist/connection-package.js +426 -0
- package/dist/connection-package.js.map +1 -0
- package/dist/connection-request.d.ts +271 -0
- package/dist/connection-request.d.ts.map +1 -0
- package/dist/connection-request.js +91 -0
- package/dist/connection-request.js.map +1 -0
- package/dist/envelope.d.ts +170 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +776 -0
- package/dist/envelope.js.map +1 -0
- package/dist/frost-dkg.d.ts +145 -0
- package/dist/frost-dkg.d.ts.map +1 -0
- package/dist/frost-dkg.js +28 -0
- package/dist/frost-dkg.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/registration.d.ts +155 -0
- package/dist/registration.d.ts.map +1 -0
- package/dist/registration.js +55 -0
- package/dist/registration.js.map +1 -0
- package/dist/session.d.ts +239 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +198 -0
- package/dist/session.js.map +1 -0
- package/dist/structure2.d.ts +75 -0
- package/dist/structure2.d.ts.map +1 -0
- package/dist/structure2.js +138 -0
- package/dist/structure2.js.map +1 -0
- package/dist/types.d.ts +144 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CELLO-MERKLE-002 — Structure 2 wire type and codec.
|
|
3
|
+
*
|
|
4
|
+
* Structure 2 is the relay-built Merkle leaf:
|
|
5
|
+
* [sequence_number, sender_pubkey, content_hash, sender_signature, scan_result, prev_root]
|
|
6
|
+
*
|
|
7
|
+
* scan_result in M1 is a sentinel placeholder: {score: null, verdict: "unscanned", model_hash: <32 zero bytes>}.
|
|
8
|
+
* The field is present to keep the wire layout stable for future scanner integration (M4+).
|
|
9
|
+
*
|
|
10
|
+
* Canonical CBOR per RFC 8949 §4.2.1.
|
|
11
|
+
* Ed25519 verification per RFC 8032.
|
|
12
|
+
*
|
|
13
|
+
* Structure 1 TBS (for signature verification):
|
|
14
|
+
* [1, content_hash, sender_pubkey, session_id, last_seen_seq, timestamp]
|
|
15
|
+
* This is what the sender signs; verifyStructure2Signature reconstructs it from Structure 2 fields
|
|
16
|
+
* plus the session_id, last_seen_seq, and timestamp carried through the relay path.
|
|
17
|
+
*/
|
|
18
|
+
import { Encoder } from "cbor-x";
|
|
19
|
+
import { verify } from "@cello-protocol/crypto";
|
|
20
|
+
const CBOR_ENC = new Encoder({ tagUint8Array: false });
|
|
21
|
+
// ─── Sentinel ─────────────────────────────────────────────────────────────────
|
|
22
|
+
/** M1 placeholder scan_result sentinel. The scanner field is stable but unset until M4+. */
|
|
23
|
+
export const SCAN_RESULT_SENTINEL = Object.freeze({
|
|
24
|
+
score: null,
|
|
25
|
+
verdict: "unscanned",
|
|
26
|
+
model_hash: new Uint8Array(32),
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Encodes the scan_result sentinel as canonical CBOR (RFC 8949 §4.2.1).
|
|
30
|
+
*
|
|
31
|
+
* Keys are sorted by byte length per RFC 8949 §4.2.1 core deterministic encoding:
|
|
32
|
+
* "score" (5) < "verdict" (7) < "model_hash" (10)
|
|
33
|
+
*
|
|
34
|
+
* cbor-x's default POJO encoding uses non-canonical map-size encoding (uint16 length prefix).
|
|
35
|
+
* We construct the canonical bytes manually to guarantee RFC 8949 §4.2.1 compliance.
|
|
36
|
+
*/
|
|
37
|
+
export function encodeScanResultSentinel() {
|
|
38
|
+
// a3 = 3-item CBOR map (major type 5, additional info 3)
|
|
39
|
+
// Keys sorted by length: "score"(5) < "verdict"(7) < "model_hash"(10)
|
|
40
|
+
return new Uint8Array(Buffer.concat([
|
|
41
|
+
Buffer.from([0xa3]),
|
|
42
|
+
// "score": null
|
|
43
|
+
Buffer.from([0x65]), Buffer.from("score"),
|
|
44
|
+
Buffer.from([0xf6]),
|
|
45
|
+
// "verdict": "unscanned"
|
|
46
|
+
Buffer.from([0x67]), Buffer.from("verdict"),
|
|
47
|
+
Buffer.from([0x69]), Buffer.from("unscanned"),
|
|
48
|
+
// "model_hash": 32-byte zero byte string
|
|
49
|
+
Buffer.from([0x6a]), Buffer.from("model_hash"),
|
|
50
|
+
Buffer.from([0x58, 0x20]), Buffer.alloc(32),
|
|
51
|
+
]));
|
|
52
|
+
}
|
|
53
|
+
// ─── Build ────────────────────────────────────────────────────────────────────
|
|
54
|
+
/**
|
|
55
|
+
* Constructs a Structure 2 object after validating all field lengths.
|
|
56
|
+
* scan_result is always the M1 sentinel — callers do not supply it.
|
|
57
|
+
*/
|
|
58
|
+
export function buildStructure2(sequence_number, sender_pubkey, content_hash, sender_signature, prev_root) {
|
|
59
|
+
if (sender_pubkey.length !== 32) {
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
error: { reason: "invalid_field", field: "sender_pubkey", message: `sender_pubkey must be 32 bytes, got ${sender_pubkey.length}` },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (content_hash.length !== 32) {
|
|
66
|
+
return {
|
|
67
|
+
ok: false,
|
|
68
|
+
error: { reason: "invalid_field", field: "content_hash", message: `content_hash must be 32 bytes, got ${content_hash.length}` },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (sender_signature.length !== 64) {
|
|
72
|
+
return {
|
|
73
|
+
ok: false,
|
|
74
|
+
error: { reason: "invalid_field", field: "sender_signature", message: `sender_signature must be 64 bytes, got ${sender_signature.length}` },
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (prev_root.length !== 32) {
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
error: { reason: "invalid_field", field: "prev_root", message: `prev_root must be 32 bytes, got ${prev_root.length}` },
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
ok: true,
|
|
85
|
+
structure2: {
|
|
86
|
+
sequence_number,
|
|
87
|
+
sender_pubkey,
|
|
88
|
+
content_hash,
|
|
89
|
+
sender_signature,
|
|
90
|
+
scan_result: SCAN_RESULT_SENTINEL,
|
|
91
|
+
prev_root,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// ─── Encode ───────────────────────────────────────────────────────────────────
|
|
96
|
+
/**
|
|
97
|
+
* Encodes Structure 2 as canonical CBOR (RFC 8949 §4.2.1).
|
|
98
|
+
* Wire format: [sequence_number, sender_pubkey, content_hash, sender_signature, scan_result, prev_root]
|
|
99
|
+
*/
|
|
100
|
+
export function encodeStructure2(s2) {
|
|
101
|
+
const sentinelBytes = encodeScanResultSentinel();
|
|
102
|
+
// We must embed the pre-encoded sentinel bytes as raw CBOR, not re-encode the object.
|
|
103
|
+
// Construct the 6-element array manually to preserve canonical byte representation.
|
|
104
|
+
const arrayHeader = new Uint8Array([0x86]); // 6-element CBOR array
|
|
105
|
+
const seqBytes = CBOR_ENC.encode(s2.sequence_number);
|
|
106
|
+
const pubBytes = CBOR_ENC.encode(s2.sender_pubkey);
|
|
107
|
+
const hashBytes = CBOR_ENC.encode(s2.content_hash);
|
|
108
|
+
const sigBytes = CBOR_ENC.encode(s2.sender_signature);
|
|
109
|
+
const prevBytes = CBOR_ENC.encode(s2.prev_root);
|
|
110
|
+
return new Uint8Array(Buffer.concat([arrayHeader, seqBytes, pubBytes, hashBytes, sigBytes, sentinelBytes, prevBytes]));
|
|
111
|
+
}
|
|
112
|
+
// ─── Verify ───────────────────────────────────────────────────────────────────
|
|
113
|
+
/**
|
|
114
|
+
* Reconstructs canonical CBOR of Structure 1 from Structure 2 fields plus the
|
|
115
|
+
* session_id, last_seen_seq, and timestamp carried through the relay path,
|
|
116
|
+
* then verifies the sender's Ed25519 signature.
|
|
117
|
+
*
|
|
118
|
+
* Structure 1 TBS: [1, content_hash, sender_pubkey, session_id, last_seen_seq, timestamp]
|
|
119
|
+
* Per RFC 8032 (Ed25519) and RFC 8949 §4.2.1 (canonical CBOR).
|
|
120
|
+
*
|
|
121
|
+
* @param timestamp - Unix milliseconds. May be number or bigint. cbor-x decodes uint64
|
|
122
|
+
* timestamps as bigint; relay callers that deserialize Structure 1 CBOR must pass the
|
|
123
|
+
* decoded value directly here rather than converting to number (which is lossy above
|
|
124
|
+
* Number.MAX_SAFE_INTEGER).
|
|
125
|
+
*/
|
|
126
|
+
export function verifyStructure2Signature(s2, session_id, last_seen_seq, timestamp) {
|
|
127
|
+
const tsEncoded = typeof timestamp === "bigint" ? timestamp : timestamp > 0xffffffff ? BigInt(timestamp) : timestamp;
|
|
128
|
+
const tbs = CBOR_ENC.encode([
|
|
129
|
+
1,
|
|
130
|
+
s2.content_hash,
|
|
131
|
+
s2.sender_pubkey,
|
|
132
|
+
session_id,
|
|
133
|
+
last_seen_seq,
|
|
134
|
+
tsEncoded,
|
|
135
|
+
]);
|
|
136
|
+
return verify(s2.sender_pubkey, tbs, s2.sender_signature);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=structure2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"structure2.js","sourceRoot":"","sources":["../src/structure2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGhD,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;AAuBvD,iFAAiF;AAEjF,4FAA4F;AAC5F,MAAM,CAAC,MAAM,oBAAoB,GAAuB,MAAM,CAAC,MAAM,CAAC;IACpE,KAAK,EAAE,IAAI;IACX,OAAO,EAAE,WAAoB;IAC7B,UAAU,EAAE,IA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4.2.1 canonical CBOR):
|
|
7
|
+
* [protocol_version, content_hash, sender_pubkey, timestamp]
|
|
8
|
+
*
|
|
9
|
+
* v1 TBS layout (Structure 1, RFC 8949 §4.2.1 canonical CBOR):
|
|
10
|
+
* [protocol_version, content_hash, sender_pubkey, session_id, last_seen_seq, timestamp]
|
|
11
|
+
*
|
|
12
|
+
* Wire format (canonical CBOR, RFC 8949 §4.2.1):
|
|
13
|
+
* Full envelope is a CBOR map with the fields below.
|
|
14
|
+
*
|
|
15
|
+
* Ed25519 reference: RFC 8032
|
|
16
|
+
* CBOR reference: RFC 8949
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* A signed, tamper-evident message envelope (v0, M0).
|
|
20
|
+
*
|
|
21
|
+
* All byte arrays are bare Uint8Array values — no CBOR tag.
|
|
22
|
+
* The timestamp is stored as a JS number (milliseconds since Unix epoch).
|
|
23
|
+
*/
|
|
24
|
+
export interface MessageEnvelope {
|
|
25
|
+
/** CBOR unsigned integer, always 0 in M0. */
|
|
26
|
+
protocol_version: 0;
|
|
27
|
+
/** 32-byte Ed25519 K_local public key of the sender. */
|
|
28
|
+
sender_pubkey: Uint8Array;
|
|
29
|
+
/** Raw message content, up to 1 MiB. */
|
|
30
|
+
content: Uint8Array;
|
|
31
|
+
/**
|
|
32
|
+
* SHA-256(0x00 || content) — computed by msgLeafHash from @cello-protocol/crypto.
|
|
33
|
+
* ALWAYS recomputed by buildEnvelope; any caller-supplied value is ignored.
|
|
34
|
+
*/
|
|
35
|
+
content_hash: Uint8Array;
|
|
36
|
+
/** Unix milliseconds, non-negative. */
|
|
37
|
+
timestamp: number;
|
|
38
|
+
/** 64-byte Ed25519 signature over canonical CBOR of TBS. */
|
|
39
|
+
sender_signature: Uint8Array;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A signed, tamper-evident message envelope (v1, M1).
|
|
43
|
+
*
|
|
44
|
+
* Adds session_id and last_seen_seq to the TBS array (Structure 1).
|
|
45
|
+
* protocol_version is always 1. M1 hard-cuts v0 — these are never interoperable.
|
|
46
|
+
*
|
|
47
|
+
* TBS (Structure 1): [1, content_hash, sender_pubkey, session_id, last_seen_seq, timestamp]
|
|
48
|
+
* All byte arrays are bare Uint8Array values — no CBOR tag.
|
|
49
|
+
*
|
|
50
|
+
* Ed25519 reference: RFC 8032
|
|
51
|
+
* CBOR reference: RFC 8949 §4.2.1
|
|
52
|
+
*/
|
|
53
|
+
export interface MessageEnvelopeV1 {
|
|
54
|
+
/** CBOR unsigned integer, always 1 in M1. */
|
|
55
|
+
protocol_version: 1;
|
|
56
|
+
/** 32-byte Ed25519 K_local public key of the sender. */
|
|
57
|
+
sender_pubkey: Uint8Array;
|
|
58
|
+
/** Raw message content, up to 1 MiB. */
|
|
59
|
+
content: Uint8Array;
|
|
60
|
+
/**
|
|
61
|
+
* SHA-256(0x00 || content) — computed by msgLeafHash from @cello-protocol/crypto.
|
|
62
|
+
* ALWAYS recomputed by buildEnvelopeV1; any caller-supplied value is ignored.
|
|
63
|
+
*/
|
|
64
|
+
content_hash: Uint8Array;
|
|
65
|
+
/** 16-byte session identifier. */
|
|
66
|
+
session_id: Uint8Array;
|
|
67
|
+
/**
|
|
68
|
+
* Highest canonical sequence number seen from relay on this session.
|
|
69
|
+
* 0 for the first message on a session.
|
|
70
|
+
* CBOR unsigned integer, non-negative.
|
|
71
|
+
*/
|
|
72
|
+
last_seen_seq: number;
|
|
73
|
+
/** Unix milliseconds, non-negative. */
|
|
74
|
+
timestamp: number;
|
|
75
|
+
/**
|
|
76
|
+
* 64-byte Ed25519 signature over canonical CBOR of Structure 1:
|
|
77
|
+
* [1, content_hash, sender_pubkey, session_id, last_seen_seq, timestamp]
|
|
78
|
+
*/
|
|
79
|
+
sender_signature: Uint8Array;
|
|
80
|
+
}
|
|
81
|
+
export interface ContentTooLargeError {
|
|
82
|
+
reason: "content_too_large";
|
|
83
|
+
message: string;
|
|
84
|
+
}
|
|
85
|
+
export interface ContentHashMismatchError {
|
|
86
|
+
reason: "content_hash_mismatch";
|
|
87
|
+
message: string;
|
|
88
|
+
}
|
|
89
|
+
export interface UnsupportedVersionError {
|
|
90
|
+
reason: "unsupported_version";
|
|
91
|
+
message: string;
|
|
92
|
+
}
|
|
93
|
+
export interface InvalidFieldError {
|
|
94
|
+
reason: "invalid_field";
|
|
95
|
+
field: string;
|
|
96
|
+
message: string;
|
|
97
|
+
}
|
|
98
|
+
export interface MissingFieldError {
|
|
99
|
+
reason: "missing_field";
|
|
100
|
+
field: string;
|
|
101
|
+
message: string;
|
|
102
|
+
}
|
|
103
|
+
export type EnvelopeError = ContentTooLargeError | ContentHashMismatchError | UnsupportedVersionError | InvalidFieldError | MissingFieldError;
|
|
104
|
+
export type BuildResult = {
|
|
105
|
+
ok: true;
|
|
106
|
+
envelope: MessageEnvelope;
|
|
107
|
+
} | {
|
|
108
|
+
ok: false;
|
|
109
|
+
error: EnvelopeError;
|
|
110
|
+
};
|
|
111
|
+
export type ValidateResult = {
|
|
112
|
+
ok: true;
|
|
113
|
+
} | {
|
|
114
|
+
ok: false;
|
|
115
|
+
error: EnvelopeError;
|
|
116
|
+
};
|
|
117
|
+
export type DeserializeResult = {
|
|
118
|
+
ok: true;
|
|
119
|
+
envelope: MessageEnvelope;
|
|
120
|
+
} | {
|
|
121
|
+
ok: false;
|
|
122
|
+
error: EnvelopeError;
|
|
123
|
+
};
|
|
124
|
+
export type BuildResultV1 = {
|
|
125
|
+
ok: true;
|
|
126
|
+
envelope: MessageEnvelopeV1;
|
|
127
|
+
} | {
|
|
128
|
+
ok: false;
|
|
129
|
+
error: EnvelopeError;
|
|
130
|
+
};
|
|
131
|
+
export type ValidateResultV1 = {
|
|
132
|
+
ok: true;
|
|
133
|
+
} | {
|
|
134
|
+
ok: false;
|
|
135
|
+
error: EnvelopeError;
|
|
136
|
+
};
|
|
137
|
+
export type DeserializeResultV1 = {
|
|
138
|
+
ok: true;
|
|
139
|
+
envelope: MessageEnvelopeV1;
|
|
140
|
+
} | {
|
|
141
|
+
ok: false;
|
|
142
|
+
error: EnvelopeError;
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,6CAA6C;IAC7C,gBAAgB,EAAE,CAAC,CAAC;IAEpB,wDAAwD;IACxD,aAAa,EAAE,UAAU,CAAC;IAE1B,wCAAwC;IACxC,OAAO,EAAE,UAAU,CAAC;IAEpB;;;OAGG;IACH,YAAY,EAAE,UAAU,CAAC;IAEzB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAElB,4DAA4D;IAC5D,gBAAgB,EAAE,UAAU,CAAC;CAC9B;AAID;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,gBAAgB,EAAE,CAAC,CAAC;IAEpB,wDAAwD;IACxD,aAAa,EAAE,UAAU,CAAC;IAE1B,wCAAwC;IACxC,OAAO,EAAE,UAAU,CAAC;IAEpB;;;OAGG;IACH,YAAY,EAAE,UAAU,CAAC;IAEzB,kCAAkC;IAClC,UAAU,EAAE,UAAU,CAAC;IAEvB;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,gBAAgB,EAAE,UAAU,CAAC;CAC9B;AAID,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,uBAAuB,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,OAAO,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AE,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,iBAAiB,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @cello-protocol/protocol-types — CELLO-MSG-001 (v0) + CELLO-MSG-003 (v1)
|
|
3
|
+
*
|
|
4
|
+
* Wire types for the MessageEnvelope.
|
|
5
|
+
*
|
|
6
|
+
* v0 TBS layout (positional, RFC 8949 §4.2.1 canonical CBOR):
|
|
7
|
+
* [protocol_version, content_hash, sender_pubkey, timestamp]
|
|
8
|
+
*
|
|
9
|
+
* v1 TBS layout (Structure 1, RFC 8949 §4.2.1 canonical CBOR):
|
|
10
|
+
* [protocol_version, content_hash, sender_pubkey, session_id, last_seen_seq, timestamp]
|
|
11
|
+
*
|
|
12
|
+
* Wire format (canonical CBOR, RFC 8949 §4.2.1):
|
|
13
|
+
* Full envelope is a CBOR map with the fields below.
|
|
14
|
+
*
|
|
15
|
+
* Ed25519 reference: RFC 8032
|
|
16
|
+
* CBOR reference: RFC 8949
|
|
17
|
+
*/
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cello-protocol/protocol-types",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=24"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/",
|
|
22
|
+
"package.json"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"cbor-x": "^1.6.4",
|
|
26
|
+
"@cello-protocol/crypto": "0.0.2"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@claude-flow/testing": "3.0.0-alpha.6",
|
|
30
|
+
"@types/node": "^25.6.2",
|
|
31
|
+
"@cello-protocol/test-fixtures": "0.0.2"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"typecheck": "tsc --build",
|
|
35
|
+
"test": "vitest run"
|
|
36
|
+
}
|
|
37
|
+
}
|