@rougechain/sdk 0.8.4 → 1.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.
- package/README.md +133 -33
- package/dist/index.cjs +115 -138
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +115 -139
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
10
|
<strong>Build quantum-safe dApps on RougeChain</strong><br />
|
|
11
|
-
Transfers · DEX · NFTs · Shielded Transactions · Bridge · Rollups · Dynamic Fees · Finality Proofs · WebSocket · Mail · Messenger
|
|
11
|
+
Transfers · DEX · NFTs · Social · Shielded Transactions · Bridge · Rollups · Dynamic Fees · Finality Proofs · WebSocket · Mail · Messenger
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
14
|
<p align="center">
|
|
@@ -62,6 +62,7 @@ const { balance } = await rc.getBalance(wallet.publicKey);
|
|
|
62
62
|
| **Shielded** | `rc.shielded` | Private transfers with zk-STARK proofs, shield/unshield XRGE |
|
|
63
63
|
| **Bridge** | `rc.bridge` | ETH ↔ qETH, USDC ↔ qUSDC, XRGE bridge (Base Mainnet/Sepolia) |
|
|
64
64
|
| **Rollup** | `rc` | zk-STARK batch proofs, rollup status, submit transfers |
|
|
65
|
+
| **Social** | `rc.social` | Posts, timeline feed, reposts, likes, follows, comments |
|
|
65
66
|
| **Mail** | `rc.mail` | On-chain encrypted email (`@rouge.quant`) |
|
|
66
67
|
| **Messenger** | `rc.messenger` | E2E encrypted messaging with self-destruct |
|
|
67
68
|
| **Address Resolution** | `rc` | O(1) rouge1↔pubkey resolution via on-chain index |
|
|
@@ -335,9 +336,82 @@ const batch = await rc.getRollupBatch(1);
|
|
|
335
336
|
// { batch_id, transfer_count, proof_size_bytes, proof_time_ms, verified, ... }
|
|
336
337
|
```
|
|
337
338
|
|
|
339
|
+
## Social (`rc.social`)
|
|
340
|
+
|
|
341
|
+
On-chain social layer with posts, threaded replies, reposts, likes, follows, and comments. All write operations require a `wallet` parameter for ML-DSA-65 signed requests.
|
|
342
|
+
|
|
343
|
+
### Posts & Timeline
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
// Create a post (max 4000 chars)
|
|
347
|
+
const { post } = await rc.social.createPost(wallet, "Hello RougeChain!");
|
|
348
|
+
|
|
349
|
+
// Reply to a post (threaded)
|
|
350
|
+
await rc.social.createPost(wallet, "Great point!", post.id);
|
|
351
|
+
|
|
352
|
+
// Delete your own post
|
|
353
|
+
await rc.social.deletePost(wallet, post.id);
|
|
354
|
+
|
|
355
|
+
// Get a single post with stats
|
|
356
|
+
const result = await rc.social.getPost(post.id, wallet.publicKey);
|
|
357
|
+
// result.post, result.stats { likes, reposts, replies, liked, reposted }
|
|
358
|
+
|
|
359
|
+
// Global timeline (all posts, newest first)
|
|
360
|
+
const timeline = await rc.social.getGlobalTimeline(50, 0);
|
|
361
|
+
|
|
362
|
+
// Following feed (posts from people you follow)
|
|
363
|
+
const feed = await rc.social.getFollowingFeed(wallet, 50, 0);
|
|
364
|
+
|
|
365
|
+
// User's posts
|
|
366
|
+
const { posts, total } = await rc.social.getUserPosts(userPubKey);
|
|
367
|
+
|
|
368
|
+
// Get replies to a post
|
|
369
|
+
const replies = await rc.social.getPostReplies(post.id);
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Likes, Reposts & Follows
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
// Like/unlike a post or track (toggle)
|
|
376
|
+
await rc.social.toggleLike(wallet, postOrTrackId);
|
|
377
|
+
|
|
378
|
+
// Repost/unrepost (toggle)
|
|
379
|
+
await rc.social.toggleRepost(wallet, post.id);
|
|
380
|
+
|
|
381
|
+
// Follow/unfollow (toggle)
|
|
382
|
+
await rc.social.toggleFollow(wallet, artistPubKey);
|
|
383
|
+
|
|
384
|
+
// Get stats
|
|
385
|
+
const stats = await rc.social.getPostStats(post.id, wallet.publicKey);
|
|
386
|
+
const artistStats = await rc.social.getArtistStats(pubkey, wallet.publicKey);
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Comments (Track-level)
|
|
390
|
+
|
|
391
|
+
```typescript
|
|
392
|
+
// Comment on a track
|
|
393
|
+
const { comment } = await rc.social.postComment(wallet, trackId, "Fire track!");
|
|
394
|
+
|
|
395
|
+
// Get comments
|
|
396
|
+
const comments = await rc.social.getComments(trackId);
|
|
397
|
+
|
|
398
|
+
// Delete your comment
|
|
399
|
+
await rc.social.deleteComment(wallet, comment.id);
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Play Counts
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
// Record a play (debounce client-side, one per session per track)
|
|
406
|
+
await rc.social.recordPlay(wallet, trackId);
|
|
407
|
+
|
|
408
|
+
// Get track stats (plays, likes, comments)
|
|
409
|
+
const trackStats = await rc.social.getTrackStats(trackId, wallet.publicKey);
|
|
410
|
+
```
|
|
411
|
+
|
|
338
412
|
## Mail (`rc.mail`)
|
|
339
413
|
|
|
340
|
-
On-chain encrypted email with `@rouge.quant` / `@qwalla.mail` addresses.
|
|
414
|
+
On-chain encrypted email with `@rouge.quant` / `@qwalla.mail` addresses. All write operations require a `wallet` parameter for ML-DSA-65 request signing — requests are authenticated via `/api/v2/` endpoints with anti-replay nonce protection.
|
|
341
415
|
|
|
342
416
|
### Name Registry
|
|
343
417
|
|
|
@@ -345,17 +419,17 @@ Register a mail name so other users can send you encrypted email. Third-party ap
|
|
|
345
419
|
|
|
346
420
|
```typescript
|
|
347
421
|
// Step 1: Register wallet on the node (required for encryption keys)
|
|
348
|
-
await rc.messenger.registerWallet({
|
|
422
|
+
await rc.messenger.registerWallet(wallet, {
|
|
349
423
|
id: wallet.publicKey,
|
|
350
424
|
displayName: "Alice",
|
|
351
425
|
signingPublicKey: wallet.publicKey,
|
|
352
426
|
encryptionPublicKey: encPubKey,
|
|
353
427
|
});
|
|
354
428
|
|
|
355
|
-
// Step 2: Register a mail name
|
|
356
|
-
await rc.mail.registerName("alice", wallet.publicKey);
|
|
429
|
+
// Step 2: Register a mail name (signed request)
|
|
430
|
+
await rc.mail.registerName(wallet, "alice", wallet.publicKey);
|
|
357
431
|
|
|
358
|
-
// Resolve a name → wallet info (includes encryption key)
|
|
432
|
+
// Resolve a name → wallet info (includes encryption key, public data only)
|
|
359
433
|
const resolved = await rc.mail.resolveName("alice");
|
|
360
434
|
// { entry: { name, wallet_id }, wallet: { id, signing_public_key, encryption_public_key } }
|
|
361
435
|
|
|
@@ -363,15 +437,15 @@ const resolved = await rc.mail.resolveName("alice");
|
|
|
363
437
|
const name = await rc.mail.reverseLookup(wallet.publicKey);
|
|
364
438
|
// "alice"
|
|
365
439
|
|
|
366
|
-
// Release a name
|
|
367
|
-
await rc.mail.releaseName("alice"
|
|
440
|
+
// Release a name (signed request)
|
|
441
|
+
await rc.mail.releaseName(wallet, "alice");
|
|
368
442
|
```
|
|
369
443
|
|
|
370
444
|
### Sending & Reading Mail
|
|
371
445
|
|
|
372
446
|
```typescript
|
|
373
|
-
// Send an encrypted email
|
|
374
|
-
await rc.mail.send({
|
|
447
|
+
// Send an encrypted email (signed, multi-recipient CEK encryption)
|
|
448
|
+
await rc.mail.send(wallet, {
|
|
375
449
|
from: wallet.publicKey,
|
|
376
450
|
to: recipientPubKey,
|
|
377
451
|
subject: "Hello",
|
|
@@ -380,52 +454,74 @@ await rc.mail.send({
|
|
|
380
454
|
encrypted_body: encryptedBody,
|
|
381
455
|
});
|
|
382
456
|
|
|
383
|
-
// Read inbox
|
|
384
|
-
const inbox = await rc.mail.getInbox(wallet
|
|
457
|
+
// Read inbox (signed request)
|
|
458
|
+
const inbox = await rc.mail.getInbox(wallet);
|
|
385
459
|
|
|
386
|
-
// Move to trash
|
|
387
|
-
await rc.mail.move(messageId, "trash");
|
|
460
|
+
// Move to trash (signed request)
|
|
461
|
+
await rc.mail.move(wallet, messageId, "trash");
|
|
388
462
|
|
|
389
|
-
// Mark as read
|
|
390
|
-
await rc.mail.markRead(messageId);
|
|
463
|
+
// Mark as read (signed request)
|
|
464
|
+
await rc.mail.markRead(wallet, messageId);
|
|
465
|
+
|
|
466
|
+
// Delete (signed request)
|
|
467
|
+
await rc.mail.delete(wallet, messageId);
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### Unread Counts
|
|
471
|
+
|
|
472
|
+
The SDK does not expose a dedicated unread-count endpoint. Derive unread totals client-side from inbox data:
|
|
473
|
+
|
|
474
|
+
```typescript
|
|
475
|
+
// Mail: count unread inbox items
|
|
476
|
+
const inbox = await rc.mail.getInbox(wallet);
|
|
477
|
+
const unreadMail = inbox.filter((m: any) => {
|
|
478
|
+
const label = m.label ?? {};
|
|
479
|
+
return !(label.is_read ?? label.isRead ?? true);
|
|
480
|
+
}).length;
|
|
481
|
+
|
|
482
|
+
// Messenger: sum unread_count across conversations
|
|
483
|
+
const convos = await rc.messenger.getConversations(wallet);
|
|
484
|
+
const unreadChats = convos.reduce((sum: number, c: any) => {
|
|
485
|
+
return sum + (c.unread_count ?? c.unreadCount ?? 0);
|
|
486
|
+
}, 0);
|
|
391
487
|
```
|
|
392
488
|
|
|
393
489
|
## Messenger (`rc.messenger`)
|
|
394
490
|
|
|
395
|
-
End-to-end encrypted messaging with media and self-destruct support.
|
|
491
|
+
End-to-end encrypted messaging with media and self-destruct support. All operations use ML-DSA-65 signed requests via `/api/v2/` endpoints with nonce-based anti-replay protection.
|
|
396
492
|
|
|
397
493
|
```typescript
|
|
398
|
-
// Register wallet for messaging
|
|
399
|
-
await rc.messenger.registerWallet({
|
|
494
|
+
// Register wallet for messaging (signed request)
|
|
495
|
+
await rc.messenger.registerWallet(wallet, {
|
|
400
496
|
id: wallet.publicKey,
|
|
401
497
|
displayName: "Alice",
|
|
402
498
|
signingPublicKey: wallet.publicKey,
|
|
403
499
|
encryptionPublicKey: encPubKey,
|
|
404
500
|
});
|
|
405
501
|
|
|
406
|
-
// Create a conversation
|
|
407
|
-
const result = await rc.messenger.createConversation([
|
|
502
|
+
// Create a conversation (signed request)
|
|
503
|
+
const result = await rc.messenger.createConversation(wallet, [
|
|
408
504
|
wallet.publicKey,
|
|
409
505
|
recipientPubKey,
|
|
410
506
|
]);
|
|
411
507
|
|
|
412
|
-
// Fetch conversations (
|
|
413
|
-
const convos = await rc.messenger.getConversations(wallet
|
|
414
|
-
signingPublicKey: wallet.publicKey,
|
|
415
|
-
encryptionPublicKey: encPubKey,
|
|
416
|
-
});
|
|
508
|
+
// Fetch conversations (signed request)
|
|
509
|
+
const convos = await rc.messenger.getConversations(wallet);
|
|
417
510
|
|
|
418
|
-
// Send an encrypted message (with optional self-destruct)
|
|
419
|
-
await rc.messenger.sendMessage(
|
|
511
|
+
// Send an encrypted message (signed, with optional self-destruct)
|
|
512
|
+
await rc.messenger.sendMessage(wallet, conversationId, encryptedContent, {
|
|
420
513
|
selfDestruct: true,
|
|
421
514
|
destructAfterSeconds: 30,
|
|
422
515
|
});
|
|
423
516
|
|
|
424
|
-
// Read messages
|
|
425
|
-
const messages = await rc.messenger.getMessages(conversationId);
|
|
517
|
+
// Read messages (signed request)
|
|
518
|
+
const messages = await rc.messenger.getMessages(wallet, conversationId);
|
|
519
|
+
|
|
520
|
+
// Delete a message (signed request)
|
|
521
|
+
await rc.messenger.deleteMessage(wallet, messageId, conversationId);
|
|
426
522
|
|
|
427
|
-
// Delete a
|
|
428
|
-
await rc.messenger.
|
|
523
|
+
// Delete a conversation (signed request)
|
|
524
|
+
await rc.messenger.deleteConversation(wallet, conversationId);
|
|
429
525
|
```
|
|
430
526
|
|
|
431
527
|
## Shielded Transactions (`rc.shielded`)
|
|
@@ -447,7 +543,7 @@ const stats = await rc.shielded.getStats();
|
|
|
447
543
|
// Check if a nullifier has been spent
|
|
448
544
|
const { spent } = await rc.shielded.isNullifierSpent(note.nullifier);
|
|
449
545
|
|
|
450
|
-
// Private transfer (
|
|
546
|
+
// Private transfer (STARK proof generated by WASM prover in browser or Rust prover on node)
|
|
451
547
|
await rc.shielded.transfer(wallet, {
|
|
452
548
|
nullifiers: [note.nullifier],
|
|
453
549
|
outputCommitments: [recipientCommitment],
|
|
@@ -545,6 +641,7 @@ import type {
|
|
|
545
641
|
ShieldedNote,
|
|
546
642
|
RollupStatus, RollupBatchResult, RollupSubmitParams, RollupSubmitResult,
|
|
547
643
|
FeeInfo, FinalityProof, MintTokenParams, VoteMessage, WsSubscribeMessage,
|
|
644
|
+
SocialPost, PostStats, TrackStats, ArtistStats, SocialComment,
|
|
548
645
|
} from "@rougechain/sdk";
|
|
549
646
|
```
|
|
550
647
|
|
|
@@ -553,6 +650,9 @@ import type {
|
|
|
553
650
|
- **Post-quantum cryptography** — All signatures use ML-DSA-65 (CRYSTALS-Dilithium), resistant to quantum computer attacks
|
|
554
651
|
- **Client-side signing** — Private keys never leave your application
|
|
555
652
|
- **No key storage** — The SDK does not store or transmit keys
|
|
653
|
+
- **Signed API requests** — All mail, messenger, and name registry operations use ML-DSA-65 signed requests with timestamp validation and nonce-based anti-replay protection
|
|
654
|
+
- **Multi-recipient CEK encryption** — Mail content is encrypted once with a random AES-256 key, KEM-wrapped individually per recipient via ML-KEM-768
|
|
655
|
+
- **TOFU key verification** — Public key fingerprints (SHA-256) are tracked for key change detection
|
|
556
656
|
|
|
557
657
|
## Links
|
|
558
658
|
|
package/dist/index.cjs
CHANGED
|
@@ -286,6 +286,9 @@ function createSignedPushUnregister(wallet) {
|
|
|
286
286
|
type: "push_unregister"
|
|
287
287
|
});
|
|
288
288
|
}
|
|
289
|
+
function signRequest(wallet, payload) {
|
|
290
|
+
return buildAndSign(wallet, payload);
|
|
291
|
+
}
|
|
289
292
|
var COMMITMENT_DOMAIN = new TextEncoder().encode("ROUGECHAIN_COMMITMENT_V1");
|
|
290
293
|
var NULLIFIER_DOMAIN = new TextEncoder().encode("ROUGECHAIN_NULLIFIER_V1");
|
|
291
294
|
function generateRandomness() {
|
|
@@ -959,17 +962,10 @@ var MailClient = class {
|
|
|
959
962
|
constructor(rc) {
|
|
960
963
|
this.rc = rc;
|
|
961
964
|
}
|
|
962
|
-
// --- Name Registry ---
|
|
963
|
-
async registerName(name, walletId) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
name,
|
|
967
|
-
walletId
|
|
968
|
-
});
|
|
969
|
-
return { success: data.success === true, error: data.error, data };
|
|
970
|
-
} catch (e) {
|
|
971
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
972
|
-
}
|
|
965
|
+
// --- Name Registry (signed) ---
|
|
966
|
+
async registerName(wallet, name, walletId) {
|
|
967
|
+
const signed = signRequest(wallet, { name, walletId });
|
|
968
|
+
return this.rc.submitTx("/v2/names/register", signed);
|
|
973
969
|
}
|
|
974
970
|
async resolveName(name) {
|
|
975
971
|
try {
|
|
@@ -992,85 +988,71 @@ var MailClient = class {
|
|
|
992
988
|
return null;
|
|
993
989
|
}
|
|
994
990
|
}
|
|
995
|
-
async releaseName(
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
}
|
|
991
|
+
async releaseName(wallet, name) {
|
|
992
|
+
const signed = signRequest(wallet, { name });
|
|
993
|
+
return this.rc.submitTx("/v2/names/release", signed);
|
|
994
|
+
}
|
|
995
|
+
// --- Mail (signed) ---
|
|
996
|
+
async send(wallet, params) {
|
|
997
|
+
const signed = signRequest(wallet, {
|
|
998
|
+
fromWalletId: params.from,
|
|
999
|
+
toWalletIds: [params.to],
|
|
1000
|
+
subjectEncrypted: params.encrypted_subject,
|
|
1001
|
+
bodyEncrypted: params.encrypted_body,
|
|
1002
|
+
contentSignature: params.body,
|
|
1003
|
+
replyToId: params.reply_to_id,
|
|
1004
|
+
hasAttachment: false
|
|
1005
|
+
});
|
|
1006
|
+
return this.rc.submitTx("/v2/mail/send", signed);
|
|
1010
1007
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1008
|
+
async getInbox(wallet) {
|
|
1009
|
+
const signed = signRequest(wallet, { folder: "inbox" });
|
|
1013
1010
|
try {
|
|
1014
|
-
const data = await this.rc.post("/mail/
|
|
1015
|
-
return
|
|
1016
|
-
} catch
|
|
1017
|
-
return
|
|
1011
|
+
const data = await this.rc.post("/v2/mail/folder", signed);
|
|
1012
|
+
return data.messages ?? [];
|
|
1013
|
+
} catch {
|
|
1014
|
+
return [];
|
|
1018
1015
|
}
|
|
1019
1016
|
}
|
|
1020
|
-
async
|
|
1021
|
-
const
|
|
1022
|
-
`/mail/inbox?walletId=${encodeURIComponent(walletId)}`
|
|
1023
|
-
);
|
|
1024
|
-
return data.messages ?? [];
|
|
1025
|
-
}
|
|
1026
|
-
async getSent(walletId) {
|
|
1027
|
-
const data = await this.rc.get(
|
|
1028
|
-
`/mail/sent?walletId=${encodeURIComponent(walletId)}`
|
|
1029
|
-
);
|
|
1030
|
-
return data.messages ?? [];
|
|
1031
|
-
}
|
|
1032
|
-
async getTrash(walletId) {
|
|
1033
|
-
const data = await this.rc.get(
|
|
1034
|
-
`/mail/trash?walletId=${encodeURIComponent(walletId)}`
|
|
1035
|
-
);
|
|
1036
|
-
return data.messages ?? [];
|
|
1037
|
-
}
|
|
1038
|
-
async getMessage(id) {
|
|
1039
|
-
return this.rc.get(`/mail/message/${encodeURIComponent(id)}`);
|
|
1040
|
-
}
|
|
1041
|
-
async move(messageId, folder) {
|
|
1017
|
+
async getSent(wallet) {
|
|
1018
|
+
const signed = signRequest(wallet, { folder: "sent" });
|
|
1042
1019
|
try {
|
|
1043
|
-
const data = await this.rc.post("/mail/
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
return { success: data.success === true, error: data.error };
|
|
1048
|
-
} catch (e) {
|
|
1049
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1020
|
+
const data = await this.rc.post("/v2/mail/folder", signed);
|
|
1021
|
+
return data.messages ?? [];
|
|
1022
|
+
} catch {
|
|
1023
|
+
return [];
|
|
1050
1024
|
}
|
|
1051
1025
|
}
|
|
1052
|
-
async
|
|
1026
|
+
async getTrash(wallet) {
|
|
1027
|
+
const signed = signRequest(wallet, { folder: "trash" });
|
|
1053
1028
|
try {
|
|
1054
|
-
const data = await this.rc.post("/mail/
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
return
|
|
1058
|
-
} catch (e) {
|
|
1059
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1029
|
+
const data = await this.rc.post("/v2/mail/folder", signed);
|
|
1030
|
+
return data.messages ?? [];
|
|
1031
|
+
} catch {
|
|
1032
|
+
return [];
|
|
1060
1033
|
}
|
|
1061
1034
|
}
|
|
1062
|
-
async
|
|
1035
|
+
async getMessage(wallet, messageId) {
|
|
1036
|
+
const signed = signRequest(wallet, { messageId });
|
|
1063
1037
|
try {
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
const data = await res.json();
|
|
1069
|
-
return { success: data.success === true, error: data.error };
|
|
1070
|
-
} catch (e) {
|
|
1071
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1038
|
+
const data = await this.rc.post("/v2/mail/message", signed);
|
|
1039
|
+
return data.message ?? null;
|
|
1040
|
+
} catch {
|
|
1041
|
+
return null;
|
|
1072
1042
|
}
|
|
1073
1043
|
}
|
|
1044
|
+
async move(wallet, messageId, folder) {
|
|
1045
|
+
const signed = signRequest(wallet, { messageId, folder });
|
|
1046
|
+
return this.rc.submitTx("/v2/mail/move", signed);
|
|
1047
|
+
}
|
|
1048
|
+
async markRead(wallet, messageId) {
|
|
1049
|
+
const signed = signRequest(wallet, { messageId });
|
|
1050
|
+
return this.rc.submitTx("/v2/mail/read", signed);
|
|
1051
|
+
}
|
|
1052
|
+
async delete(wallet, messageId) {
|
|
1053
|
+
const signed = signRequest(wallet, { messageId });
|
|
1054
|
+
return this.rc.submitTx("/v2/mail/delete", signed);
|
|
1055
|
+
}
|
|
1074
1056
|
};
|
|
1075
1057
|
var MessengerClient = class {
|
|
1076
1058
|
constructor(rc) {
|
|
@@ -1080,77 +1062,71 @@ var MessengerClient = class {
|
|
|
1080
1062
|
const data = await this.rc.get("/messenger/wallets");
|
|
1081
1063
|
return data.wallets ?? [];
|
|
1082
1064
|
}
|
|
1083
|
-
async registerWallet(opts) {
|
|
1065
|
+
async registerWallet(wallet, opts) {
|
|
1066
|
+
const signed = signRequest(wallet, {
|
|
1067
|
+
id: opts.id,
|
|
1068
|
+
displayName: opts.displayName,
|
|
1069
|
+
signingPublicKey: opts.signingPublicKey,
|
|
1070
|
+
encryptionPublicKey: opts.encryptionPublicKey,
|
|
1071
|
+
discoverable: opts.discoverable ?? true
|
|
1072
|
+
});
|
|
1073
|
+
return this.rc.submitTx("/v2/messenger/wallets/register", signed);
|
|
1074
|
+
}
|
|
1075
|
+
async getConversations(wallet) {
|
|
1076
|
+
const signed = signRequest(wallet, {});
|
|
1084
1077
|
try {
|
|
1085
|
-
const data = await this.rc.post(
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1078
|
+
const data = await this.rc.post(
|
|
1079
|
+
"/v2/messenger/conversations/list",
|
|
1080
|
+
signed
|
|
1081
|
+
);
|
|
1082
|
+
return data.conversations ?? [];
|
|
1083
|
+
} catch {
|
|
1084
|
+
return [];
|
|
1089
1085
|
}
|
|
1090
1086
|
}
|
|
1091
|
-
async
|
|
1092
|
-
const
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
);
|
|
1098
|
-
return data.conversations ?? [];
|
|
1087
|
+
async createConversation(wallet, participantIds, opts = {}) {
|
|
1088
|
+
const signed = signRequest(wallet, {
|
|
1089
|
+
participantIds,
|
|
1090
|
+
name: opts.name,
|
|
1091
|
+
isGroup: opts.isGroup ?? false
|
|
1092
|
+
});
|
|
1093
|
+
return this.rc.submitTx("/v2/messenger/conversations", signed);
|
|
1099
1094
|
}
|
|
1100
|
-
async
|
|
1095
|
+
async getMessages(wallet, conversationId) {
|
|
1096
|
+
const signed = signRequest(wallet, { conversationId });
|
|
1101
1097
|
try {
|
|
1102
|
-
const data = await this.rc.post(
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1098
|
+
const data = await this.rc.post(
|
|
1099
|
+
"/v2/messenger/messages/list",
|
|
1100
|
+
signed
|
|
1101
|
+
);
|
|
1102
|
+
return data.messages ?? [];
|
|
1103
|
+
} catch {
|
|
1104
|
+
return [];
|
|
1108
1105
|
}
|
|
1109
1106
|
}
|
|
1110
|
-
async
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1107
|
+
async sendMessage(wallet, conversationId, encryptedContent, opts = {}) {
|
|
1108
|
+
const signed = signRequest(wallet, {
|
|
1109
|
+
conversationId,
|
|
1110
|
+
encryptedContent,
|
|
1111
|
+
contentSignature: opts.contentSignature ?? "",
|
|
1112
|
+
messageType: opts.messageType ?? "text",
|
|
1113
|
+
selfDestruct: opts.selfDestruct ?? false,
|
|
1114
|
+
destructAfterSeconds: opts.destructAfterSeconds,
|
|
1115
|
+
spoiler: opts.spoiler ?? false
|
|
1116
|
+
});
|
|
1117
|
+
return this.rc.submitTx("/v2/messenger/messages", signed);
|
|
1115
1118
|
}
|
|
1116
|
-
async
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
conversationId,
|
|
1120
|
-
senderWalletId,
|
|
1121
|
-
encryptedContent,
|
|
1122
|
-
signature: opts.signature ?? "",
|
|
1123
|
-
messageType: opts.messageType ?? "text",
|
|
1124
|
-
selfDestruct: opts.selfDestruct ?? false,
|
|
1125
|
-
destructAfterSeconds: opts.destructAfterSeconds,
|
|
1126
|
-
spoiler: opts.spoiler ?? false
|
|
1127
|
-
});
|
|
1128
|
-
return { success: data.success === true, error: data.error, data };
|
|
1129
|
-
} catch (e) {
|
|
1130
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1131
|
-
}
|
|
1119
|
+
async deleteMessage(wallet, messageId, conversationId) {
|
|
1120
|
+
const signed = signRequest(wallet, { messageId, conversationId });
|
|
1121
|
+
return this.rc.submitTx("/v2/messenger/messages/delete", signed);
|
|
1132
1122
|
}
|
|
1133
|
-
async
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
`${this.rc.baseUrl}/messenger/messages/${encodeURIComponent(messageId)}`,
|
|
1137
|
-
{ method: "DELETE", headers: this.rc.headers }
|
|
1138
|
-
);
|
|
1139
|
-
const data = await res.json();
|
|
1140
|
-
return { success: data.success === true, error: data.error };
|
|
1141
|
-
} catch (e) {
|
|
1142
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1143
|
-
}
|
|
1123
|
+
async deleteConversation(wallet, conversationId) {
|
|
1124
|
+
const signed = signRequest(wallet, { conversationId });
|
|
1125
|
+
return this.rc.submitTx("/v2/messenger/conversations/delete", signed);
|
|
1144
1126
|
}
|
|
1145
|
-
async markRead(messageId) {
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
messageId
|
|
1149
|
-
});
|
|
1150
|
-
return { success: data.success === true, error: data.error };
|
|
1151
|
-
} catch (e) {
|
|
1152
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1153
|
-
}
|
|
1127
|
+
async markRead(wallet, messageId, conversationId) {
|
|
1128
|
+
const signed = signRequest(wallet, { messageId, conversationId });
|
|
1129
|
+
return this.rc.submitTx("/v2/messenger/messages/read", signed);
|
|
1154
1130
|
}
|
|
1155
1131
|
};
|
|
1156
1132
|
var ShieldedClient = class {
|
|
@@ -1486,6 +1462,7 @@ exports.keypairFromMnemonic = keypairFromMnemonic;
|
|
|
1486
1462
|
exports.mnemonicToMLDSASeed = mnemonicToMLDSASeed;
|
|
1487
1463
|
exports.pubkeyToAddress = pubkeyToAddress;
|
|
1488
1464
|
exports.serializePayload = serializePayload;
|
|
1465
|
+
exports.signRequest = signRequest;
|
|
1489
1466
|
exports.signTransaction = signTransaction;
|
|
1490
1467
|
exports.validateMnemonic = validateMnemonic;
|
|
1491
1468
|
exports.verifyTransaction = verifyTransaction;
|