@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 +54 -15
- package/dist/core/index.cjs +310 -88
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +300 -204
- package/dist/core/index.d.ts +300 -204
- package/dist/core/index.js +310 -88
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +1234 -920
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +1234 -926
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +1112 -0
- package/dist/impl/browser/ipfs.cjs.map +1 -0
- package/dist/impl/browser/ipfs.js +1079 -0
- package/dist/impl/browser/ipfs.js.map +1 -0
- package/dist/impl/nodejs/index.cjs +1081 -222
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +131 -55
- package/dist/impl/nodejs/index.d.ts +131 -55
- package/dist/impl/nodejs/index.js +1088 -225
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +310 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +663 -345
- package/dist/index.d.ts +663 -345
- package/dist/index.js +310 -88
- package/dist/index.js.map +1 -1
- package/package.json +16 -2
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?.
|
|
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?.
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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?.
|
|
136
|
-
console.log(sphere.identity?.
|
|
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.
|
|
147
|
-
console.log('L3 address:', event.data.
|
|
148
|
-
console.log('
|
|
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?.
|
|
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:
|
|
457
|
-
│
|
|
458
|
-
│
|
|
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?.
|
|
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:
|