@unicitylabs/sphere-sdk 0.3.0 → 0.3.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/README.md +166 -8
- package/dist/core/index.cjs +544 -19
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +240 -13
- package/dist/core/index.d.ts +240 -13
- package/dist/core/index.js +543 -19
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +543 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +240 -13
- package/dist/index.d.ts +240 -13
- package/dist/index.js +542 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ A modular TypeScript SDK for Unicity wallet operations supporting both Layer 1 (
|
|
|
8
8
|
- **L1 Payments** - ALPHA blockchain transactions via Fulcrum WebSocket
|
|
9
9
|
- **L3 Payments** - Token transfers with state transition proofs
|
|
10
10
|
- **Payment Requests** - Request payments with async response tracking
|
|
11
|
+
- **Group Chat** - NIP-29 relay-based group messaging with moderation
|
|
11
12
|
- **Nostr Transport** - P2P messaging with NIP-04 encryption
|
|
12
13
|
- **IPFS Storage** - Decentralized token backup via HTTP API (browser + Node.js)
|
|
13
14
|
- **Token Splitting** - Partial transfer amount calculations
|
|
@@ -353,6 +354,162 @@ sphere.payments.onPaymentRequest((request) => {
|
|
|
353
354
|
});
|
|
354
355
|
```
|
|
355
356
|
|
|
357
|
+
## Group Chat (NIP-29)
|
|
358
|
+
|
|
359
|
+
Relay-based group messaging using the NIP-29 protocol. The module embeds its own Nostr connection separate from the wallet transport.
|
|
360
|
+
|
|
361
|
+
### Enabling Group Chat
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
// Enable with network defaults (wss://sphere-relay.unicity.network)
|
|
365
|
+
const { sphere } = await Sphere.init({
|
|
366
|
+
...providers,
|
|
367
|
+
autoGenerate: true,
|
|
368
|
+
groupChat: true,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// Enable with custom relay
|
|
372
|
+
const { sphere } = await Sphere.init({
|
|
373
|
+
...providers,
|
|
374
|
+
autoGenerate: true,
|
|
375
|
+
groupChat: { relays: ['wss://my-nip29-relay.com'] },
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// Access the module
|
|
379
|
+
const gc = sphere.groupChat!;
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Connection
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
// Connect to the NIP-29 relay
|
|
386
|
+
await gc.connect();
|
|
387
|
+
console.log('Connected:', gc.getConnectionStatus());
|
|
388
|
+
|
|
389
|
+
// Check if current user is a relay admin
|
|
390
|
+
const isRelayAdmin = await gc.isCurrentUserRelayAdmin();
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Groups
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
import { GroupVisibility } from '@unicitylabs/sphere-sdk';
|
|
397
|
+
|
|
398
|
+
// Create a public group
|
|
399
|
+
const group = await gc.createGroup({
|
|
400
|
+
name: 'General',
|
|
401
|
+
description: 'Public discussion',
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
// Create a private group
|
|
405
|
+
const privateGroup = await gc.createGroup({
|
|
406
|
+
name: 'Team',
|
|
407
|
+
visibility: GroupVisibility.PRIVATE,
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// Discover and join
|
|
411
|
+
const available = await gc.fetchAvailableGroups(); // public groups on relay
|
|
412
|
+
await gc.joinGroup(group.id);
|
|
413
|
+
|
|
414
|
+
// Join private group with invite
|
|
415
|
+
await gc.joinGroup(privateGroup.id, inviteCode);
|
|
416
|
+
|
|
417
|
+
// List joined groups
|
|
418
|
+
const groups = gc.getGroups();
|
|
419
|
+
|
|
420
|
+
// Leave or delete
|
|
421
|
+
await gc.leaveGroup(group.id);
|
|
422
|
+
await gc.deleteGroup(group.id); // admin only
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### Messaging
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
// Send a message
|
|
429
|
+
const msg = await gc.sendMessage(group.id, 'Hello!');
|
|
430
|
+
|
|
431
|
+
// Reply to a message
|
|
432
|
+
await gc.sendMessage(group.id, 'Agreed', { replyToId: msg.id });
|
|
433
|
+
|
|
434
|
+
// Fetch messages from relay
|
|
435
|
+
const messages = await gc.fetchMessages(group.id, { limit: 50 });
|
|
436
|
+
|
|
437
|
+
// Get locally cached messages
|
|
438
|
+
const cached = gc.getMessages(group.id);
|
|
439
|
+
|
|
440
|
+
// Listen for new messages in real-time
|
|
441
|
+
const unsubscribe = gc.onMessage((message) => {
|
|
442
|
+
console.log(`[${message.groupId}] ${message.senderPubkey}: ${message.content}`);
|
|
443
|
+
});
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
### Members & Moderation
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
// Get members
|
|
450
|
+
const members = gc.getMembers(group.id);
|
|
451
|
+
|
|
452
|
+
// Check roles
|
|
453
|
+
gc.isCurrentUserAdmin(group.id); // boolean
|
|
454
|
+
gc.isCurrentUserModerator(group.id); // boolean
|
|
455
|
+
await gc.canModerateGroup(group.id); // includes relay admin check
|
|
456
|
+
|
|
457
|
+
// Moderate (requires admin/moderator role)
|
|
458
|
+
await gc.kickUser(group.id, userPubkey, 'reason');
|
|
459
|
+
await gc.deleteMessage(group.id, messageId);
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
### Invites (Private Groups)
|
|
463
|
+
|
|
464
|
+
```typescript
|
|
465
|
+
// Create invite code (admin only)
|
|
466
|
+
const invite = await gc.createInvite(group.id);
|
|
467
|
+
|
|
468
|
+
// Share invite code, recipient joins with:
|
|
469
|
+
await gc.joinGroup(group.id, invite);
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
### Unread Counts
|
|
473
|
+
|
|
474
|
+
```typescript
|
|
475
|
+
const total = gc.getTotalUnreadCount();
|
|
476
|
+
gc.markGroupAsRead(group.id);
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### Key Types
|
|
480
|
+
|
|
481
|
+
```typescript
|
|
482
|
+
interface GroupData {
|
|
483
|
+
id: string;
|
|
484
|
+
relayUrl: string;
|
|
485
|
+
name: string;
|
|
486
|
+
description?: string;
|
|
487
|
+
visibility: GroupVisibility; // 'PUBLIC' | 'PRIVATE'
|
|
488
|
+
memberCount?: number;
|
|
489
|
+
unreadCount?: number;
|
|
490
|
+
lastMessageTime?: number;
|
|
491
|
+
lastMessageText?: string;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
interface GroupMessageData {
|
|
495
|
+
id?: string;
|
|
496
|
+
groupId: string;
|
|
497
|
+
content: string;
|
|
498
|
+
timestamp: number;
|
|
499
|
+
senderPubkey: string;
|
|
500
|
+
senderNametag?: string;
|
|
501
|
+
replyToId?: string;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
interface GroupMemberData {
|
|
505
|
+
pubkey: string;
|
|
506
|
+
groupId: string;
|
|
507
|
+
role: GroupRole; // 'ADMIN' | 'MODERATOR' | 'MEMBER'
|
|
508
|
+
nametag?: string;
|
|
509
|
+
joinedAt: number;
|
|
510
|
+
}
|
|
511
|
+
```
|
|
512
|
+
|
|
356
513
|
## L1 (ALPHA Blockchain) Operations
|
|
357
514
|
|
|
358
515
|
Access L1 payments through `sphere.payments.l1`:
|
|
@@ -628,18 +785,19 @@ mnemonic → master key → BIP32 derivation → identity
|
|
|
628
785
|
│ directAddress: "DIRECT://..." (L3) │
|
|
629
786
|
└─────────────────────┬─────────────────────┘
|
|
630
787
|
↓
|
|
631
|
-
|
|
632
|
-
↓
|
|
633
|
-
L1 (ALPHA)
|
|
634
|
-
sphere.payments.l1
|
|
635
|
-
UTXOs, blockchain
|
|
788
|
+
┌──────────────────┬──────────────────┬──────────────────┐
|
|
789
|
+
↓ ↓ ↓ ↓
|
|
790
|
+
L1 (ALPHA) L3 (Unicity) Group Chat Nostr
|
|
791
|
+
sphere.payments.l1 sphere.payments sphere.groupChat sphere.communications
|
|
792
|
+
UTXOs, blockchain Tokens, aggregator NIP-29 messaging P2P messaging
|
|
636
793
|
```
|
|
637
794
|
|
|
638
795
|
```
|
|
639
796
|
Sphere (main entry point)
|
|
640
|
-
├── identity
|
|
641
|
-
├── payments
|
|
642
|
-
│ └── l1
|
|
797
|
+
├── identity - Wallet identity (address, publicKey, nametag)
|
|
798
|
+
├── payments - L3 token operations
|
|
799
|
+
│ └── l1 - L1 ALPHA transactions (via sphere.payments.l1)
|
|
800
|
+
├── groupChat - NIP-29 group messaging (via sphere.groupChat)
|
|
643
801
|
└── communications - Direct messages & broadcasts
|
|
644
802
|
|
|
645
803
|
Providers (injectable dependencies)
|