@meshwhisper/sdk 0.1.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.
- package/README.md +138 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +19 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/chaff/index.d.ts +91 -0
- package/dist/chaff/index.d.ts.map +1 -0
- package/dist/chaff/index.js +268 -0
- package/dist/chaff/index.js.map +1 -0
- package/dist/cluster/index.d.ts +159 -0
- package/dist/cluster/index.d.ts.map +1 -0
- package/dist/cluster/index.js +393 -0
- package/dist/cluster/index.js.map +1 -0
- package/dist/compliance/index.d.ts +129 -0
- package/dist/compliance/index.d.ts.map +1 -0
- package/dist/compliance/index.js +315 -0
- package/dist/compliance/index.js.map +1 -0
- package/dist/crypto/index.d.ts +65 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +146 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/group/index.d.ts +155 -0
- package/dist/group/index.d.ts.map +1 -0
- package/dist/group/index.js +560 -0
- package/dist/group/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/namespace/index.d.ts +155 -0
- package/dist/namespace/index.d.ts.map +1 -0
- package/dist/namespace/index.js +278 -0
- package/dist/namespace/index.js.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +19 -0
- package/dist/node/index.js.map +1 -0
- package/dist/packet/index.d.ts +63 -0
- package/dist/packet/index.d.ts.map +1 -0
- package/dist/packet/index.js +244 -0
- package/dist/packet/index.js.map +1 -0
- package/dist/permissions/index.d.ts +107 -0
- package/dist/permissions/index.d.ts.map +1 -0
- package/dist/permissions/index.js +282 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/persistence/idb-storage.d.ts +27 -0
- package/dist/persistence/idb-storage.d.ts.map +1 -0
- package/dist/persistence/idb-storage.js +75 -0
- package/dist/persistence/idb-storage.js.map +1 -0
- package/dist/persistence/index.d.ts +4 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +3 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/node-storage.d.ts +33 -0
- package/dist/persistence/node-storage.d.ts.map +1 -0
- package/dist/persistence/node-storage.js +90 -0
- package/dist/persistence/node-storage.js.map +1 -0
- package/dist/persistence/serialization.d.ts +4 -0
- package/dist/persistence/serialization.d.ts.map +1 -0
- package/dist/persistence/serialization.js +49 -0
- package/dist/persistence/serialization.js.map +1 -0
- package/dist/persistence/types.d.ts +29 -0
- package/dist/persistence/types.d.ts.map +1 -0
- package/dist/persistence/types.js +5 -0
- package/dist/persistence/types.js.map +1 -0
- package/dist/ratchet/index.d.ts +80 -0
- package/dist/ratchet/index.d.ts.map +1 -0
- package/dist/ratchet/index.js +259 -0
- package/dist/ratchet/index.js.map +1 -0
- package/dist/reciprocity/index.d.ts +109 -0
- package/dist/reciprocity/index.d.ts.map +1 -0
- package/dist/reciprocity/index.js +311 -0
- package/dist/reciprocity/index.js.map +1 -0
- package/dist/relay/index.d.ts +87 -0
- package/dist/relay/index.d.ts.map +1 -0
- package/dist/relay/index.js +286 -0
- package/dist/relay/index.js.map +1 -0
- package/dist/routing/index.d.ts +136 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +478 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/sdk/index.d.ts +322 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +1530 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sybil/index.d.ts +123 -0
- package/dist/sybil/index.d.ts.map +1 -0
- package/dist/sybil/index.js +491 -0
- package/dist/sybil/index.js.map +1 -0
- package/dist/transport/browser/index.d.ts +34 -0
- package/dist/transport/browser/index.d.ts.map +1 -0
- package/dist/transport/browser/index.js +176 -0
- package/dist/transport/browser/index.js.map +1 -0
- package/dist/transport/local/index.d.ts +57 -0
- package/dist/transport/local/index.d.ts.map +1 -0
- package/dist/transport/local/index.js +442 -0
- package/dist/transport/local/index.js.map +1 -0
- package/dist/transport/negotiator/index.d.ts +79 -0
- package/dist/transport/negotiator/index.d.ts.map +1 -0
- package/dist/transport/negotiator/index.js +289 -0
- package/dist/transport/negotiator/index.js.map +1 -0
- package/dist/transport/node/index.d.ts +56 -0
- package/dist/transport/node/index.d.ts.map +1 -0
- package/dist/transport/node/index.js +209 -0
- package/dist/transport/node/index.js.map +1 -0
- package/dist/transport/noop/index.d.ts +11 -0
- package/dist/transport/noop/index.d.ts.map +1 -0
- package/dist/transport/noop/index.js +20 -0
- package/dist/transport/noop/index.js.map +1 -0
- package/dist/transport/p2p/index.d.ts +109 -0
- package/dist/transport/p2p/index.d.ts.map +1 -0
- package/dist/transport/p2p/index.js +237 -0
- package/dist/transport/p2p/index.js.map +1 -0
- package/dist/transport/websocket/index.d.ts +89 -0
- package/dist/transport/websocket/index.d.ts.map +1 -0
- package/dist/transport/websocket/index.js +498 -0
- package/dist/transport/websocket/index.js.map +1 -0
- package/dist/transport/websocket/serialize.d.ts +5 -0
- package/dist/transport/websocket/serialize.d.ts.map +1 -0
- package/dist/transport/websocket/serialize.js +55 -0
- package/dist/transport/websocket/serialize.js.map +1 -0
- package/dist/types.d.ts +215 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/dist/x3dh/index.d.ts +120 -0
- package/dist/x3dh/index.d.ts.map +1 -0
- package/dist/x3dh/index.js +290 -0
- package/dist/x3dh/index.js.map +1 -0
- package/package.json +59 -0
- package/src/browser/index.ts +19 -0
- package/src/chaff/index.ts +340 -0
- package/src/cluster/index.ts +482 -0
- package/src/compliance/index.ts +407 -0
- package/src/crypto/index.ts +193 -0
- package/src/group/index.ts +719 -0
- package/src/index.ts +87 -0
- package/src/lz4js.d.ts +58 -0
- package/src/namespace/index.ts +336 -0
- package/src/node/index.ts +19 -0
- package/src/packet/index.ts +326 -0
- package/src/permissions/index.ts +405 -0
- package/src/persistence/idb-storage.ts +83 -0
- package/src/persistence/index.ts +3 -0
- package/src/persistence/node-storage.ts +96 -0
- package/src/persistence/serialization.ts +75 -0
- package/src/persistence/types.ts +33 -0
- package/src/ratchet/index.ts +363 -0
- package/src/reciprocity/index.ts +371 -0
- package/src/relay/index.ts +382 -0
- package/src/routing/index.ts +577 -0
- package/src/sdk/index.ts +1994 -0
- package/src/sybil/index.ts +661 -0
- package/src/transport/browser/index.ts +201 -0
- package/src/transport/local/index.ts +540 -0
- package/src/transport/negotiator/index.ts +397 -0
- package/src/transport/node/index.ts +234 -0
- package/src/transport/noop/index.ts +22 -0
- package/src/transport/p2p/index.ts +345 -0
- package/src/transport/websocket/index.ts +660 -0
- package/src/transport/websocket/serialize.ts +68 -0
- package/src/types.ts +275 -0
- package/src/x3dh/index.ts +388 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// MeshWhisper SDK — Packet Wire Serialization
|
|
3
|
+
// Pure functions with no platform-specific dependencies.
|
|
4
|
+
// Shared by WebSocketTransport (Node.js) and BrowserTransport.
|
|
5
|
+
//
|
|
6
|
+
// Binary layout (all big-endian):
|
|
7
|
+
// [0] version u8
|
|
8
|
+
// [1] flags u8
|
|
9
|
+
// [2..9] destHash 8 bytes
|
|
10
|
+
// [10..25] senderEphId 16 bytes
|
|
11
|
+
// [26] ttl u8
|
|
12
|
+
// [27..30] payloadLen u32
|
|
13
|
+
// [31..] encrypted payload
|
|
14
|
+
//
|
|
15
|
+
// Total header = 31 bytes.
|
|
16
|
+
// ============================================================
|
|
17
|
+
export const HEADER_SIZE = 31;
|
|
18
|
+
export function serializePacket(packet) {
|
|
19
|
+
const buf = new Uint8Array(HEADER_SIZE + packet.encryptedPayload.length);
|
|
20
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
21
|
+
buf[0] = packet.version;
|
|
22
|
+
buf[1] = packet.flags;
|
|
23
|
+
buf.set(packet.destHash.subarray(0, 8), 2);
|
|
24
|
+
buf.set(packet.senderEphemeralId.subarray(0, 16), 10);
|
|
25
|
+
buf[26] = packet.ttl;
|
|
26
|
+
view.setUint32(27, packet.payloadLength, false);
|
|
27
|
+
buf.set(packet.encryptedPayload, HEADER_SIZE);
|
|
28
|
+
return buf;
|
|
29
|
+
}
|
|
30
|
+
export function deserializePacket(data) {
|
|
31
|
+
if (data.length < HEADER_SIZE) {
|
|
32
|
+
throw new Error(`Packet too small: ${data.length} bytes (min ${HEADER_SIZE})`);
|
|
33
|
+
}
|
|
34
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
35
|
+
const version = data[0];
|
|
36
|
+
const flags = data[1];
|
|
37
|
+
const destHash = data.slice(2, 10);
|
|
38
|
+
const senderEphemeralId = data.slice(10, 26);
|
|
39
|
+
const ttl = data[26];
|
|
40
|
+
const payloadLength = view.getUint32(27, false);
|
|
41
|
+
const encryptedPayload = data.slice(HEADER_SIZE, HEADER_SIZE + payloadLength);
|
|
42
|
+
if (encryptedPayload.length !== payloadLength) {
|
|
43
|
+
throw new Error(`Payload length mismatch: header says ${payloadLength}, got ${encryptedPayload.length}`);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
version,
|
|
47
|
+
flags,
|
|
48
|
+
destHash,
|
|
49
|
+
senderEphemeralId,
|
|
50
|
+
ttl,
|
|
51
|
+
payloadLength,
|
|
52
|
+
encryptedPayload,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=serialize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.js","sourceRoot":"","sources":["../../../src/transport/websocket/serialize.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,8CAA8C;AAC9C,yDAAyD;AACzD,+DAA+D;AAC/D,EAAE;AACF,k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AW,GAAG,CAAC,CAAC;IACjF,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAEzE,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAgB,CAAC;IACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACnC,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IACrB,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IAEhD,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,GAAG,aAAa,CAAC,CAAC;IAE9E,IAAI,gBAAgB,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CACb,wCAAwC,aAAa,SAAS,gBAAgB,CAAC,MAAM,EAAE,CACxF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO;QACP,KAAK;QACL,QAAQ;QACR,iBAAiB;QACjB,GAAG;QACH,aAAa;QACb,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
export interface KeyPair {
|
|
2
|
+
publicKey: Uint8Array;
|
|
3
|
+
privateKey: Uint8Array;
|
|
4
|
+
}
|
|
5
|
+
export interface PreKeyBundle {
|
|
6
|
+
identityKey: Uint8Array;
|
|
7
|
+
signedPreKey: Uint8Array;
|
|
8
|
+
signedPreKeySignature: Uint8Array;
|
|
9
|
+
oneTimePreKey?: Uint8Array;
|
|
10
|
+
}
|
|
11
|
+
export interface EncryptedPayload {
|
|
12
|
+
ciphertext: Uint8Array;
|
|
13
|
+
nonce: Uint8Array;
|
|
14
|
+
tag: Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
export declare enum PacketFlags {
|
|
17
|
+
DATA = 1,
|
|
18
|
+
ACK = 2,
|
|
19
|
+
CHAFF = 3,
|
|
20
|
+
HANDSHAKE = 4,
|
|
21
|
+
ROUTE_REQUEST = 5,
|
|
22
|
+
ROUTE_OFFER = 6
|
|
23
|
+
}
|
|
24
|
+
export interface Packet {
|
|
25
|
+
version: number;
|
|
26
|
+
flags: PacketFlags;
|
|
27
|
+
destHash: Uint8Array;
|
|
28
|
+
senderEphemeralId: Uint8Array;
|
|
29
|
+
ttl: number;
|
|
30
|
+
payloadLength: number;
|
|
31
|
+
encryptedPayload: Uint8Array;
|
|
32
|
+
}
|
|
33
|
+
export type BearerType = 'platform_p2p' | 'local_net' | 'internet';
|
|
34
|
+
export type BatteryState = 'charging' | 'high' | 'medium' | 'low' | 'critical';
|
|
35
|
+
export type RelayWillingness = 'eager' | 'willing' | 'reluctant' | 'unavailable';
|
|
36
|
+
export interface DeviceCapability {
|
|
37
|
+
bearerPlatformP2P: boolean;
|
|
38
|
+
bearerLocalNet: boolean;
|
|
39
|
+
bearerInternet: boolean;
|
|
40
|
+
inboundConnectable: boolean;
|
|
41
|
+
batteryState: BatteryState;
|
|
42
|
+
relayWillingness: RelayWillingness;
|
|
43
|
+
}
|
|
44
|
+
export interface Transport {
|
|
45
|
+
readonly type: BearerType;
|
|
46
|
+
send(packet: Packet, destination: string): Promise<void>;
|
|
47
|
+
onReceive(callback: (packet: Packet, source: string) => void): void;
|
|
48
|
+
start(): Promise<void>;
|
|
49
|
+
stop(): Promise<void>;
|
|
50
|
+
isAvailable(): Promise<boolean>;
|
|
51
|
+
}
|
|
52
|
+
export interface PeerProximityEntry {
|
|
53
|
+
peerId: string;
|
|
54
|
+
destHash: Uint8Array;
|
|
55
|
+
lastSeen: number;
|
|
56
|
+
hopCount: number;
|
|
57
|
+
latency: number;
|
|
58
|
+
relayPath: string[];
|
|
59
|
+
}
|
|
60
|
+
export interface RouteRequest {
|
|
61
|
+
destHash: Uint8Array;
|
|
62
|
+
requestId: Uint8Array;
|
|
63
|
+
ttl: number;
|
|
64
|
+
timestamp: number;
|
|
65
|
+
}
|
|
66
|
+
export interface RouteOffer {
|
|
67
|
+
requestId: Uint8Array;
|
|
68
|
+
hopCount: number;
|
|
69
|
+
estimatedLatency: number;
|
|
70
|
+
offeredBy: string;
|
|
71
|
+
}
|
|
72
|
+
export type PermissionModel = 'open' | 'mutual' | 'introduction' | 'transactional' | 'custom';
|
|
73
|
+
export interface Session {
|
|
74
|
+
peerId: string;
|
|
75
|
+
namespaceId: Uint8Array;
|
|
76
|
+
sharedSecret: Uint8Array;
|
|
77
|
+
established: number;
|
|
78
|
+
lastActivity: number;
|
|
79
|
+
}
|
|
80
|
+
export type MessageUrgency = 'background' | 'normal' | 'urgent' | 'critical';
|
|
81
|
+
export type PresenceStatus = 'online' | 'recently_seen' | 'offline' | 'unknown';
|
|
82
|
+
export interface Message {
|
|
83
|
+
id: string;
|
|
84
|
+
senderId: string;
|
|
85
|
+
recipientId: string;
|
|
86
|
+
payload: Uint8Array;
|
|
87
|
+
timestamp: number;
|
|
88
|
+
urgency: MessageUrgency;
|
|
89
|
+
expiry?: number;
|
|
90
|
+
}
|
|
91
|
+
export interface GroupMember {
|
|
92
|
+
id: string;
|
|
93
|
+
senderKey: Uint8Array;
|
|
94
|
+
role: 'admin' | 'member';
|
|
95
|
+
joinedAt: number;
|
|
96
|
+
}
|
|
97
|
+
export interface Group {
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
100
|
+
members: Map<string, GroupMember>;
|
|
101
|
+
treeRoot: string;
|
|
102
|
+
permissionModel: PermissionModel;
|
|
103
|
+
createdAt: number;
|
|
104
|
+
}
|
|
105
|
+
export interface RelayLedgerEntry {
|
|
106
|
+
peerId: string;
|
|
107
|
+
bytesRelayedForThem: number;
|
|
108
|
+
bytesTheyRelayedForUs: number;
|
|
109
|
+
lastUpdated: number;
|
|
110
|
+
}
|
|
111
|
+
export type ReciprocityTier = 'contributor' | 'balanced' | 'consumer' | 'freerider';
|
|
112
|
+
export interface ClusterDevice {
|
|
113
|
+
deviceId: string;
|
|
114
|
+
clusterKey: Uint8Array;
|
|
115
|
+
capabilities: DeviceCapability;
|
|
116
|
+
isPrimary: boolean;
|
|
117
|
+
lastSync: number;
|
|
118
|
+
}
|
|
119
|
+
export interface StoredBlob {
|
|
120
|
+
id: string;
|
|
121
|
+
destHash: Uint8Array;
|
|
122
|
+
encryptedPayload: Uint8Array;
|
|
123
|
+
receivedAt: number;
|
|
124
|
+
ttlHours: number;
|
|
125
|
+
hopsRemaining: number;
|
|
126
|
+
}
|
|
127
|
+
export type EntropySensorType = 'accelerometer' | 'gyroscope' | 'magnetometer';
|
|
128
|
+
export interface EntropyChallenge {
|
|
129
|
+
challengeId: Uint8Array;
|
|
130
|
+
sensorType: EntropySensorType;
|
|
131
|
+
durationMs: number;
|
|
132
|
+
timestamp: number;
|
|
133
|
+
}
|
|
134
|
+
export interface EntropyResponse {
|
|
135
|
+
challengeId: Uint8Array;
|
|
136
|
+
sensorData: Float64Array;
|
|
137
|
+
deviceSignature: Uint8Array;
|
|
138
|
+
}
|
|
139
|
+
export type ChaffRate = 'low' | 'normal' | 'high';
|
|
140
|
+
export type AuditExportMode = 'plaintext' | 'encrypted';
|
|
141
|
+
export interface ComplianceConfig {
|
|
142
|
+
logging?: boolean;
|
|
143
|
+
auditExport?: AuditExportMode;
|
|
144
|
+
retentionDays?: number;
|
|
145
|
+
contentScanning?: (msg: Message) => {
|
|
146
|
+
approved: boolean;
|
|
147
|
+
reason?: string;
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export type MessageHook = (message: Message) => boolean | Promise<boolean>;
|
|
151
|
+
export type { StorageBackend, StoredMessage } from './persistence/types.js';
|
|
152
|
+
/** Web Push subscription object (serialisable form of PushSubscription). */
|
|
153
|
+
export interface WebPushSubscription {
|
|
154
|
+
endpoint: string;
|
|
155
|
+
expirationTime?: number | null;
|
|
156
|
+
keys: {
|
|
157
|
+
p256dh: string;
|
|
158
|
+
auth: string;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export type PushConfig = {
|
|
162
|
+
platform: 'apns';
|
|
163
|
+
token: string;
|
|
164
|
+
topic?: string;
|
|
165
|
+
} | {
|
|
166
|
+
platform: 'fcm';
|
|
167
|
+
token: string;
|
|
168
|
+
} | {
|
|
169
|
+
platform: 'webpush';
|
|
170
|
+
subscription: WebPushSubscription;
|
|
171
|
+
};
|
|
172
|
+
export interface MeshWhisperConfig {
|
|
173
|
+
namespace: string;
|
|
174
|
+
/** MeshWhisper Node endpoint(s). Use "mesh" for Foundation-hosted nodes,
|
|
175
|
+
* a wss:// URL for self-hosted, or an array for hybrid mode. Defaults to "mesh". */
|
|
176
|
+
node?: string | string[];
|
|
177
|
+
/** Optional developer key (base64 public key). If omitted a random key is used,
|
|
178
|
+
* which is fine for development and single-tenant deployments. */
|
|
179
|
+
developerKey?: string;
|
|
180
|
+
/** Default: "open". */
|
|
181
|
+
permissionModel?: PermissionModel;
|
|
182
|
+
/** Push notification token. When set the Node stores the token alongside
|
|
183
|
+
* the device's destination hashes and sends a wake signal via the configured
|
|
184
|
+
* push webhook when a message arrives while the device is offline. */
|
|
185
|
+
push?: PushConfig;
|
|
186
|
+
/**
|
|
187
|
+
* Persistent storage backend. Provide this to survive process restarts:
|
|
188
|
+
* sessions, message history, identity, and contacts are all persisted.
|
|
189
|
+
*
|
|
190
|
+
* For Node.js: `import { NodeStorage } from '@meshwhisper/sdk/persistence/node'`
|
|
191
|
+
* For React Native: wrap AsyncStorage or SQLCipher.
|
|
192
|
+
*/
|
|
193
|
+
storage?: import('./persistence/types.js').StorageBackend;
|
|
194
|
+
onMessage?: (message: Message) => void;
|
|
195
|
+
onPresence?: (peerId: string, status: PresenceStatus) => void;
|
|
196
|
+
/** Called when the delivery status of an outbound message changes. */
|
|
197
|
+
onMessageStatus?: (messageId: string, status: import('./persistence/types.js').StoredMessage['status']) => void;
|
|
198
|
+
config?: {
|
|
199
|
+
relayWillingness?: 'auto' | RelayWillingness;
|
|
200
|
+
chaffRate?: ChaffRate;
|
|
201
|
+
storeTTL?: number;
|
|
202
|
+
clusterEnabled?: boolean;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export interface NamespaceConfig {
|
|
206
|
+
appBundleId: string;
|
|
207
|
+
developerPublicKey: Uint8Array;
|
|
208
|
+
salt: Uint8Array;
|
|
209
|
+
}
|
|
210
|
+
export interface EventEmitter<T extends Record<string, unknown>> {
|
|
211
|
+
on<K extends keyof T>(event: K, handler: (data: T[K]) => void): void;
|
|
212
|
+
off<K extends keyof T>(event: K, handler: (data: T[K]) => void): void;
|
|
213
|
+
emit<K extends keyof T>(event: K, data: T[K]): void;
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,UAAU,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,UAAU,CAAC;IACxB,YAAY,EAAE,UAAU,CAAC;IACzB,qBAAqB,EAAE,UAAU,CAAC;IAClC,aAAa,CAAC,EAAE,UAAU,CAAC;CAC5B;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE,UAAU,CAAC;IAClB,GAAG,EAAE,UAAU,CAAC;CACjB;AAID,oBAAY,WAAW;IACrB,IAAI,IAAO;IACX,GAAG,IAAO;IACV,KAAK,IAAO;IACZ,SAAS,IAAO;IAChB,aAAa,IAAO;IACpB,WAA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K,IAAI,GAAG,IAAI,CAAC;IACtE,IAAI,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CACrD"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// MeshWhisper SDK — Shared Types & Interfaces
|
|
3
|
+
// All modules code against these types.
|
|
4
|
+
// ============================================================
|
|
5
|
+
// --- Packet Types ---
|
|
6
|
+
export var PacketFlags;
|
|
7
|
+
(function (PacketFlags) {
|
|
8
|
+
PacketFlags[PacketFlags["DATA"] = 1] = "DATA";
|
|
9
|
+
PacketFlags[PacketFlags["ACK"] = 2] = "ACK";
|
|
10
|
+
PacketFlags[PacketFlags["CHAFF"] = 3] = "CHAFF";
|
|
11
|
+
PacketFlags[PacketFlags["HANDSHAKE"] = 4] = "HANDSHAKE";
|
|
12
|
+
PacketFlags[PacketFlags["ROUTE_REQUEST"] = 5] = "ROUTE_REQUEST";
|
|
13
|
+
PacketFlags[PacketFlags["ROUTE_OFFER"] = 6] = "ROUTE_OFFER";
|
|
14
|
+
})(PacketFlags || (PacketFlags = {}));
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,8CAA8C;AAC9C,wCAAwC;AACxC,+DAA+D;AAsB/D,uBAAuB;AAEvB,MAAM,CAAN,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,6CAAW,CAAA;IACX,2CAAU,CAAA;IACV,+CAAY,CAAA;IACZ,uDAAgB,CAAA;IAChB,+DAAoB,CAAA;IACpB,2DAAkB,CAAA;AACpB,CAAC,EAPW,WAAW,KAAX,WAAW,QAOtB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { KeyPair, PreKeyBundle } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The result of generating a pre-key bundle. The bundle is the public
|
|
4
|
+
* portion distributed to peers; the key pairs must be stored locally
|
|
5
|
+
* so that X3DH can be completed on the responder side.
|
|
6
|
+
*/
|
|
7
|
+
export interface GeneratedPreKeyBundle {
|
|
8
|
+
/** The public bundle to distribute (gossip or directory). */
|
|
9
|
+
bundle: PreKeyBundle;
|
|
10
|
+
/** The X25519 signed pre-key pair. Store the private key. */
|
|
11
|
+
signedPreKeyPair: KeyPair;
|
|
12
|
+
/** The X25519 one-time pre-key pair. Store the private key. */
|
|
13
|
+
oneTimePreKeyPair: KeyPair;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generates a full PreKeyBundle for distribution to peers.
|
|
17
|
+
*
|
|
18
|
+
* The bundle contains:
|
|
19
|
+
* - Identity key (Ed25519 public key from the provided key pair)
|
|
20
|
+
* - Signed pre-key (X25519, signed by the identity key)
|
|
21
|
+
* - One-time pre-key (X25519, single-use)
|
|
22
|
+
*
|
|
23
|
+
* The returned `signedPreKeyPair` and `oneTimePreKeyPair` private keys
|
|
24
|
+
* must be stored by the caller — they are required to complete X3DH on
|
|
25
|
+
* the responder side when a handshake arrives.
|
|
26
|
+
*
|
|
27
|
+
* @param identityKeyPair - Ed25519 identity key pair
|
|
28
|
+
* @returns Bundle (public) plus the key pairs (private keys must be stored)
|
|
29
|
+
*/
|
|
30
|
+
export declare function generatePreKeyBundle(identityKeyPair: KeyPair): GeneratedPreKeyBundle;
|
|
31
|
+
/**
|
|
32
|
+
* Generates a batch of one-time pre-keys for replenishment.
|
|
33
|
+
*
|
|
34
|
+
* Returns full KeyPairs — the caller must store the private keys.
|
|
35
|
+
* Only public keys are distributed in the prekey bundle; private keys
|
|
36
|
+
* are required locally to complete X3DH when a matching handshake arrives.
|
|
37
|
+
*
|
|
38
|
+
* @param _identityKeyPair - Unused; kept for API consistency
|
|
39
|
+
* @param count - Number of one-time pre-keys to generate
|
|
40
|
+
* @returns Array of X25519 key pairs
|
|
41
|
+
*/
|
|
42
|
+
export declare function generateOneTimePreKeys(_identityKeyPair: KeyPair, count: number): KeyPair[];
|
|
43
|
+
export interface KeyExchangeResult {
|
|
44
|
+
/** Derived shared secret (BLAKE3 hash of concatenated DH outputs). */
|
|
45
|
+
sharedSecret: Uint8Array;
|
|
46
|
+
/** Ephemeral X25519 public key Alice used — must be sent to Bob. */
|
|
47
|
+
ephemeralPublicKey: Uint8Array;
|
|
48
|
+
/** Whether a one-time pre-key was consumed in the exchange. */
|
|
49
|
+
usedOneTimePreKey: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Performs the initiator side (Alice) of the X3DH key exchange.
|
|
53
|
+
*
|
|
54
|
+
* Executes 3 or 4 DH operations:
|
|
55
|
+
* DH1 = DH(IK_A, SPK_B) — Alice's identity key with Bob's signed pre-key
|
|
56
|
+
* DH2 = DH(EK_A, IK_B) — Alice's ephemeral key with Bob's identity key
|
|
57
|
+
* DH3 = DH(EK_A, SPK_B) — Alice's ephemeral key with Bob's signed pre-key
|
|
58
|
+
* DH4 = DH(EK_A, OPK_B) — Alice's ephemeral key with Bob's one-time pre-key (optional)
|
|
59
|
+
*
|
|
60
|
+
* The shared secret is derived as BLAKE3(DH1 || DH2 || DH3 [|| DH4]).
|
|
61
|
+
*
|
|
62
|
+
* @param aliceIdentity - Alice's Ed25519 identity key pair
|
|
63
|
+
* @param bobPreKeyBundle - Bob's published PreKeyBundle
|
|
64
|
+
* @returns The derived shared secret, ephemeral public key, and OPK usage flag
|
|
65
|
+
* @throws If the pre-key bundle signature is invalid
|
|
66
|
+
*/
|
|
67
|
+
export declare function initiateKeyExchange(aliceIdentity: KeyPair, bobPreKeyBundle: PreKeyBundle): KeyExchangeResult;
|
|
68
|
+
/**
|
|
69
|
+
* Performs the responder side (Bob) of the X3DH key exchange.
|
|
70
|
+
*
|
|
71
|
+
* Mirrors the initiator's DH operations to derive the same shared secret:
|
|
72
|
+
* DH1 = DH(SPK_B, IK_A) — Bob's signed pre-key with Alice's identity key
|
|
73
|
+
* DH2 = DH(IK_B, EK_A) — Bob's identity key with Alice's ephemeral key
|
|
74
|
+
* DH3 = DH(SPK_B, EK_A) — Bob's signed pre-key with Alice's ephemeral key
|
|
75
|
+
* DH4 = DH(OPK_B, EK_A) — Bob's one-time pre-key with Alice's ephemeral key (optional)
|
|
76
|
+
*
|
|
77
|
+
* @param bobIdentity - Bob's Ed25519 identity key pair
|
|
78
|
+
* @param bobSignedPreKey - Bob's X25519 signed pre-key pair
|
|
79
|
+
* @param bobOneTimePreKey - Bob's X25519 one-time pre-key pair (null if not used)
|
|
80
|
+
* @param aliceIdentityKey - Alice's Ed25519 identity public key
|
|
81
|
+
* @param aliceEphemeralKey - Alice's X25519 ephemeral public key
|
|
82
|
+
* @returns The derived shared secret (same as Alice's if inputs are correct)
|
|
83
|
+
*/
|
|
84
|
+
export declare function completeKeyExchange(bobIdentity: KeyPair, bobSignedPreKey: KeyPair, bobOneTimePreKey: KeyPair | null, aliceIdentityKey: Uint8Array, aliceEphemeralKey: Uint8Array): Uint8Array;
|
|
85
|
+
/**
|
|
86
|
+
* Verifies the signed pre-key signature in a PreKeyBundle.
|
|
87
|
+
*
|
|
88
|
+
* Checks that the signedPreKey was signed by the holder of the identityKey
|
|
89
|
+
* using Ed25519.
|
|
90
|
+
*
|
|
91
|
+
* @param bundle - The PreKeyBundle to verify
|
|
92
|
+
* @returns true if the signature is valid, false otherwise
|
|
93
|
+
*/
|
|
94
|
+
export declare function verifyPreKeyBundle(bundle: PreKeyBundle): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Serializes a PreKeyBundle to a compact binary format for gossip distribution.
|
|
97
|
+
*
|
|
98
|
+
* Wire format:
|
|
99
|
+
* [version: 1 byte]
|
|
100
|
+
* [flags: 1 byte] — bit 0: hasOneTimePreKey
|
|
101
|
+
* [identityKey: 32 bytes]
|
|
102
|
+
* [signedPreKey: 32 bytes]
|
|
103
|
+
* [signedPreKeySignature: 64 bytes]
|
|
104
|
+
* [oneTimePreKey: 32 bytes] — optional, present if flags bit 0 is set
|
|
105
|
+
*
|
|
106
|
+
* Total: 130 bytes without OPK, 162 bytes with OPK.
|
|
107
|
+
*
|
|
108
|
+
* @param bundle - The PreKeyBundle to serialize
|
|
109
|
+
* @returns Serialized binary representation
|
|
110
|
+
*/
|
|
111
|
+
export declare function serializePreKeyBundle(bundle: PreKeyBundle): Uint8Array;
|
|
112
|
+
/**
|
|
113
|
+
* Deserializes a PreKeyBundle from its binary representation.
|
|
114
|
+
*
|
|
115
|
+
* @param data - Serialized PreKeyBundle bytes
|
|
116
|
+
* @returns The deserialized PreKeyBundle
|
|
117
|
+
* @throws If the data is malformed or has an unsupported version
|
|
118
|
+
*/
|
|
119
|
+
export declare function deserializePreKeyBundle(data: Uint8Array): PreKeyBundle;
|
|
120
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/x3dh/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAezD;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,6DAA6D;IAC7D,MAAM,EAAE,YAAY,CAAC;IACrB,6DAA6D;IAC7D,gBAAgB,EAAE,OAAO,CAAC;IAC1B,+DAA+D;IAC/D,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,OAAO,GAAG,qBAAqB,CA4BpF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,OAAO,EACzB,KAAK,EAAE,MAAM,GACZ,OAAO,EAAE,CAWX;AAID,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,YAAY,EAAE,UAAU,CAAC;IACzB,oEAAoE;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