@unicitylabs/sphere-sdk 0.1.2 → 0.1.4

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 CHANGED
@@ -22,6 +22,15 @@ A modular TypeScript SDK for Unicity wallet operations supporting both Layer 1 (
22
22
  npm install @unicitylabs/sphere-sdk
23
23
  ```
24
24
 
25
+ ## Quick Start Guides
26
+
27
+ Choose your platform:
28
+
29
+ | Platform | Guide | Required | Optional |
30
+ |----------|-------|----------|----------|
31
+ | **Browser** | [QUICKSTART-BROWSER.md](docs/QUICKSTART-BROWSER.md) | SDK only | `helia` (IPFS sync) |
32
+ | **Node.js** | [QUICKSTART-NODEJS.md](docs/QUICKSTART-NODEJS.md) | SDK + `ws` | - |
33
+
25
34
  ## Quick Start
26
35
 
27
36
  ```typescript
@@ -45,7 +54,7 @@ if (created && generatedMnemonic) {
45
54
  }
46
55
 
47
56
  // Get identity
48
- console.log('Address:', sphere.identity?.address);
57
+ console.log('Address:', sphere.identity?.l1Address);
49
58
 
50
59
  // Check balance
51
60
  const balance = await sphere.payments.getBalance();
@@ -100,7 +109,7 @@ const currentIndex = sphere.getCurrentAddressIndex(); // 0
100
109
 
101
110
  // Switch to a different address
102
111
  await sphere.switchToAddress(1);
103
- console.log(sphere.identity?.address); // alpha1... (address at index 1)
112
+ console.log(sphere.identity?.l1Address); // alpha1... (address at index 1)
104
113
 
105
114
  // Register nametag for this address (independent per address)
106
115
  await sphere.registerNametag('bob');
@@ -124,16 +133,17 @@ console.log(addr2.address, addr2.publicKey);
124
133
 
125
134
  ```typescript
126
135
  interface Identity {
127
- publicKey: string; // secp256k1 public key (hex)
128
- address: string; // L1 address (alpha1...)
129
- predicateAddress?: string; // L3 address (DIRECT://...)
136
+ chainPubkey: string; // 33-byte compressed secp256k1 public key (for L3 chain)
137
+ l1Address: string; // L1 address (alpha1...)
138
+ directAddress?: string; // L3 DIRECT address (DIRECT://...)
130
139
  ipnsName?: string; // IPNS name for token sync
131
140
  nametag?: string; // Registered nametag (@username)
132
141
  }
133
142
 
134
143
  // Access identity
135
- console.log(sphere.identity?.address); // alpha1qw3e...
136
- console.log(sphere.identity?.predicateAddress); // DIRECT://0000be36...
144
+ console.log(sphere.identity?.l1Address); // alpha1qw3e...
145
+ console.log(sphere.identity?.directAddress); // DIRECT://0000be36...
146
+ console.log(sphere.identity?.chainPubkey); // 02abc123... (33-byte compressed)
137
147
  console.log(sphere.identity?.nametag); // alice
138
148
  ```
139
149
 
@@ -143,11 +153,16 @@ console.log(sphere.identity?.nametag); // alice
143
153
  // Listen for address switches
144
154
  sphere.on('identity:changed', (event) => {
145
155
  console.log('Switched to address index:', event.data.addressIndex);
146
- console.log('L1 address:', event.data.address);
147
- console.log('L3 address:', event.data.predicateAddress);
148
- console.log('Public key:', event.data.publicKey);
156
+ console.log('L1 address:', event.data.l1Address);
157
+ console.log('L3 address:', event.data.directAddress);
158
+ console.log('Chain pubkey:', event.data.chainPubkey);
149
159
  console.log('Nametag:', event.data.nametag);
150
160
  });
161
+
162
+ // Listen for nametag recovery (when importing wallet)
163
+ sphere.on('nametag:recovered', (event) => {
164
+ console.log('Recovered nametag from Nostr:', event.data.nametag);
165
+ });
151
166
  ```
152
167
 
153
168
  ## Payment Requests
@@ -345,7 +360,7 @@ if (result.needsPassword) {
345
360
 
346
361
  if (result.success) {
347
362
  const sphere = result.sphere;
348
- console.log('Imported wallet:', sphere.identity?.address);
363
+ console.log('Imported wallet:', sphere.identity?.l1Address);
349
364
  }
350
365
 
351
366
  // Import from text backup file
@@ -453,9 +468,10 @@ mnemonic → master key → BIP32 derivation → identity
453
468
 
454
469
  ┌─────────────────────┴─────────────────────┐
455
470
  │ shared keys │
456
- │ privateKey: "abc..." (hex secp256k1)
457
- publicKey: "02def..." (compressed)
458
- address: "alpha1..." (bech32)
471
+ │ privateKey: "abc..." (hex secp256k1)
472
+ chainPubkey: "02def..." (33-byte comp.)
473
+ l1Address: "alpha1..." (bech32)
474
+ │ directAddress: "DIRECT://..." (L3) │
459
475
  └─────────────────────┬─────────────────────┘
460
476
 
461
477
  ┌───────────────────────────────┼───────────────────────────────┐
@@ -814,7 +830,7 @@ class MyCustomStorageProvider implements TokenStorageProvider<TxfStorageDataBase
814
830
  // Load tokens from your storage
815
831
  return {
816
832
  success: true,
817
- data: { _meta: { version: 1, address: this.identity?.address ?? '', formatVersion: '2.0', updatedAt: Date.now() } },
833
+ data: { _meta: { version: 1, address: this.identity?.l1Address ?? '', formatVersion: '2.0', updatedAt: Date.now() } },
818
834
  source: 'remote',
819
835
  timestamp: Date.now(),
820
836
  };
@@ -985,6 +1001,8 @@ function getRelayStatuses() {
985
1001
 
986
1002
  Nametags provide human-readable addresses (e.g., `@alice`) for receiving payments.
987
1003
 
1004
+ > **Note:** Nametag minting requires an aggregator API key for proof verification. Configure it via the `oracle.apiKey` option when creating providers. Contact Unicity to obtain an API key.
1005
+
988
1006
  ### Registering a Nametag
989
1007
 
990
1008
  ```typescript
@@ -1069,6 +1087,27 @@ console.log('Wallet exists:', exists); // Should be true after first run
1069
1087
  // If false - storage is not persisting properly
1070
1088
  ```
1071
1089
 
1090
+ ### Nametag Recovery on Import
1091
+
1092
+ When importing a wallet (from mnemonic or file), the SDK automatically attempts to recover the nametag from Nostr:
1093
+
1094
+ ```typescript
1095
+ // Import wallet - nametag will be recovered automatically if found on Nostr
1096
+ const { sphere } = await Sphere.init({
1097
+ ...providers,
1098
+ mnemonic: 'your twelve words...',
1099
+ // No nametag specified - will try to recover from Nostr
1100
+ });
1101
+
1102
+ // Listen for recovery event
1103
+ sphere.on('nametag:recovered', (event) => {
1104
+ console.log('Recovered nametag:', event.data.nametag); // e.g., 'alice'
1105
+ });
1106
+
1107
+ // After init, check if nametag was recovered
1108
+ console.log(sphere.identity?.nametag); // 'alice' (if found on Nostr)
1109
+ ```
1110
+
1072
1111
  ### Multi-Address Nametags
1073
1112
 
1074
1113
  Each derived address can have its own independent nametag: