@unicitylabs/sphere-sdk 0.1.3 → 0.1.5
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 +110 -15
- package/dist/core/index.cjs +829 -236
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +332 -210
- package/dist/core/index.d.ts +332 -210
- package/dist/core/index.js +829 -236
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +1224 -339
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +1221 -342
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +471 -37
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +470 -36
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +1238 -345
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +142 -57
- package/dist/impl/nodejs/index.d.ts +142 -57
- package/dist/impl/nodejs/index.js +1245 -348
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +871 -235
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1395 -503
- package/dist/index.d.ts +1395 -503
- package/dist/index.js +862 -235
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -22,6 +22,71 @@ 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
|
+
| **CLI** | See below | SDK + `tsx` | - |
|
|
34
|
+
|
|
35
|
+
## CLI (Command Line Interface)
|
|
36
|
+
|
|
37
|
+
The SDK includes a CLI for quick testing and development:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Show help
|
|
41
|
+
npm run cli -- --help
|
|
42
|
+
|
|
43
|
+
# Initialize new wallet on testnet
|
|
44
|
+
npm run cli -- init --network testnet
|
|
45
|
+
|
|
46
|
+
# Import existing wallet
|
|
47
|
+
npm run cli -- init --mnemonic "your 24 words here"
|
|
48
|
+
|
|
49
|
+
# Check wallet status
|
|
50
|
+
npm run cli -- status
|
|
51
|
+
|
|
52
|
+
# Check balance
|
|
53
|
+
npm run cli -- balance
|
|
54
|
+
|
|
55
|
+
# Show receive address
|
|
56
|
+
npm run cli -- receive
|
|
57
|
+
|
|
58
|
+
# Send tokens
|
|
59
|
+
npm run cli -- send @alice 1000000
|
|
60
|
+
|
|
61
|
+
# Register nametag
|
|
62
|
+
npm run cli -- nametag myname
|
|
63
|
+
|
|
64
|
+
# Show transaction history
|
|
65
|
+
npm run cli -- history 10
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Available CLI Commands
|
|
69
|
+
|
|
70
|
+
| Category | Command | Description |
|
|
71
|
+
|----------|---------|-------------|
|
|
72
|
+
| **Wallet** | `init [--network <net>] [--mnemonic "<words>"]` | Create or import wallet |
|
|
73
|
+
| | `status` | Show wallet identity |
|
|
74
|
+
| | `config` | Show/set configuration |
|
|
75
|
+
| **Balance** | `balance` | Show L3 token balance |
|
|
76
|
+
| | `tokens` | List all tokens |
|
|
77
|
+
| | `l1-balance` | Show L1 (ALPHA) balance |
|
|
78
|
+
| **Transfers** | `send <recipient> <amount>` | Send tokens |
|
|
79
|
+
| | `receive` | Show address for receiving |
|
|
80
|
+
| | `history [limit]` | Show transaction history |
|
|
81
|
+
| **Nametags** | `nametag <name>` | Register a nametag |
|
|
82
|
+
| | `nametag-info <name>` | Lookup nametag info |
|
|
83
|
+
| | `my-nametag` | Show current nametag |
|
|
84
|
+
| **Utils** | `generate-key` | Generate random key |
|
|
85
|
+
| | `to-human <amount>` | Convert to human readable |
|
|
86
|
+
| | `parse-wallet <file>` | Parse wallet file |
|
|
87
|
+
|
|
88
|
+
CLI data is stored in `./.sphere-cli/` directory.
|
|
89
|
+
|
|
25
90
|
## Quick Start
|
|
26
91
|
|
|
27
92
|
```typescript
|
|
@@ -45,7 +110,7 @@ if (created && generatedMnemonic) {
|
|
|
45
110
|
}
|
|
46
111
|
|
|
47
112
|
// Get identity
|
|
48
|
-
console.log('Address:', sphere.identity?.
|
|
113
|
+
console.log('Address:', sphere.identity?.l1Address);
|
|
49
114
|
|
|
50
115
|
// Check balance
|
|
51
116
|
const balance = await sphere.payments.getBalance();
|
|
@@ -100,7 +165,7 @@ const currentIndex = sphere.getCurrentAddressIndex(); // 0
|
|
|
100
165
|
|
|
101
166
|
// Switch to a different address
|
|
102
167
|
await sphere.switchToAddress(1);
|
|
103
|
-
console.log(sphere.identity?.
|
|
168
|
+
console.log(sphere.identity?.l1Address); // alpha1... (address at index 1)
|
|
104
169
|
|
|
105
170
|
// Register nametag for this address (independent per address)
|
|
106
171
|
await sphere.registerNametag('bob');
|
|
@@ -124,16 +189,17 @@ console.log(addr2.address, addr2.publicKey);
|
|
|
124
189
|
|
|
125
190
|
```typescript
|
|
126
191
|
interface Identity {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
192
|
+
chainPubkey: string; // 33-byte compressed secp256k1 public key (for L3 chain)
|
|
193
|
+
l1Address: string; // L1 address (alpha1...)
|
|
194
|
+
directAddress?: string; // L3 DIRECT address (DIRECT://...)
|
|
130
195
|
ipnsName?: string; // IPNS name for token sync
|
|
131
196
|
nametag?: string; // Registered nametag (@username)
|
|
132
197
|
}
|
|
133
198
|
|
|
134
199
|
// Access identity
|
|
135
|
-
console.log(sphere.identity?.
|
|
136
|
-
console.log(sphere.identity?.
|
|
200
|
+
console.log(sphere.identity?.l1Address); // alpha1qw3e...
|
|
201
|
+
console.log(sphere.identity?.directAddress); // DIRECT://0000be36...
|
|
202
|
+
console.log(sphere.identity?.chainPubkey); // 02abc123... (33-byte compressed)
|
|
137
203
|
console.log(sphere.identity?.nametag); // alice
|
|
138
204
|
```
|
|
139
205
|
|
|
@@ -143,11 +209,16 @@ console.log(sphere.identity?.nametag); // alice
|
|
|
143
209
|
// Listen for address switches
|
|
144
210
|
sphere.on('identity:changed', (event) => {
|
|
145
211
|
console.log('Switched to address index:', event.data.addressIndex);
|
|
146
|
-
console.log('L1 address:', event.data.
|
|
147
|
-
console.log('L3 address:', event.data.
|
|
148
|
-
console.log('
|
|
212
|
+
console.log('L1 address:', event.data.l1Address);
|
|
213
|
+
console.log('L3 address:', event.data.directAddress);
|
|
214
|
+
console.log('Chain pubkey:', event.data.chainPubkey);
|
|
149
215
|
console.log('Nametag:', event.data.nametag);
|
|
150
216
|
});
|
|
217
|
+
|
|
218
|
+
// Listen for nametag recovery (when importing wallet)
|
|
219
|
+
sphere.on('nametag:recovered', (event) => {
|
|
220
|
+
console.log('Recovered nametag from Nostr:', event.data.nametag);
|
|
221
|
+
});
|
|
151
222
|
```
|
|
152
223
|
|
|
153
224
|
## Payment Requests
|
|
@@ -345,7 +416,7 @@ if (result.needsPassword) {
|
|
|
345
416
|
|
|
346
417
|
if (result.success) {
|
|
347
418
|
const sphere = result.sphere;
|
|
348
|
-
console.log('Imported wallet:', sphere.identity?.
|
|
419
|
+
console.log('Imported wallet:', sphere.identity?.l1Address);
|
|
349
420
|
}
|
|
350
421
|
|
|
351
422
|
// Import from text backup file
|
|
@@ -453,9 +524,10 @@ mnemonic → master key → BIP32 derivation → identity
|
|
|
453
524
|
↓
|
|
454
525
|
┌─────────────────────┴─────────────────────┐
|
|
455
526
|
│ shared keys │
|
|
456
|
-
│ privateKey:
|
|
457
|
-
│
|
|
458
|
-
│
|
|
527
|
+
│ privateKey: "abc..." (hex secp256k1) │
|
|
528
|
+
│ chainPubkey: "02def..." (33-byte comp.) │
|
|
529
|
+
│ l1Address: "alpha1..." (bech32) │
|
|
530
|
+
│ directAddress: "DIRECT://..." (L3) │
|
|
459
531
|
└─────────────────────┬─────────────────────┘
|
|
460
532
|
↓
|
|
461
533
|
┌───────────────────────────────┼───────────────────────────────┐
|
|
@@ -814,7 +886,7 @@ class MyCustomStorageProvider implements TokenStorageProvider<TxfStorageDataBase
|
|
|
814
886
|
// Load tokens from your storage
|
|
815
887
|
return {
|
|
816
888
|
success: true,
|
|
817
|
-
data: { _meta: { version: 1, address: this.identity?.
|
|
889
|
+
data: { _meta: { version: 1, address: this.identity?.l1Address ?? '', formatVersion: '2.0', updatedAt: Date.now() } },
|
|
818
890
|
source: 'remote',
|
|
819
891
|
timestamp: Date.now(),
|
|
820
892
|
};
|
|
@@ -985,6 +1057,8 @@ function getRelayStatuses() {
|
|
|
985
1057
|
|
|
986
1058
|
Nametags provide human-readable addresses (e.g., `@alice`) for receiving payments.
|
|
987
1059
|
|
|
1060
|
+
> **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.
|
|
1061
|
+
|
|
988
1062
|
### Registering a Nametag
|
|
989
1063
|
|
|
990
1064
|
```typescript
|
|
@@ -1069,6 +1143,27 @@ console.log('Wallet exists:', exists); // Should be true after first run
|
|
|
1069
1143
|
// If false - storage is not persisting properly
|
|
1070
1144
|
```
|
|
1071
1145
|
|
|
1146
|
+
### Nametag Recovery on Import
|
|
1147
|
+
|
|
1148
|
+
When importing a wallet (from mnemonic or file), the SDK automatically attempts to recover the nametag from Nostr:
|
|
1149
|
+
|
|
1150
|
+
```typescript
|
|
1151
|
+
// Import wallet - nametag will be recovered automatically if found on Nostr
|
|
1152
|
+
const { sphere } = await Sphere.init({
|
|
1153
|
+
...providers,
|
|
1154
|
+
mnemonic: 'your twelve words...',
|
|
1155
|
+
// No nametag specified - will try to recover from Nostr
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
// Listen for recovery event
|
|
1159
|
+
sphere.on('nametag:recovered', (event) => {
|
|
1160
|
+
console.log('Recovered nametag:', event.data.nametag); // e.g., 'alice'
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
// After init, check if nametag was recovered
|
|
1164
|
+
console.log(sphere.identity?.nametag); // 'alice' (if found on Nostr)
|
|
1165
|
+
```
|
|
1166
|
+
|
|
1072
1167
|
### Multi-Address Nametags
|
|
1073
1168
|
|
|
1074
1169
|
Each derived address can have its own independent nametag:
|