@unicitylabs/sphere-sdk 0.1.4 → 0.1.6
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 +90 -8
- package/dist/core/index.cjs +542 -175
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +32 -6
- package/dist/core/index.d.ts +32 -6
- package/dist/core/index.js +542 -175
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +141 -122
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +143 -122
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +28 -33
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +28 -33
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +160 -123
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +11 -2
- package/dist/impl/nodejs/index.d.ts +11 -2
- package/dist/impl/nodejs/index.js +160 -123
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +584 -174
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +788 -218
- package/dist/index.d.ts +788 -218
- package/dist/index.js +575 -174
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,6 +30,62 @@ Choose your platform:
|
|
|
30
30
|
|----------|-------|----------|----------|
|
|
31
31
|
| **Browser** | [QUICKSTART-BROWSER.md](docs/QUICKSTART-BROWSER.md) | SDK only | `helia` (IPFS sync) |
|
|
32
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.
|
|
33
89
|
|
|
34
90
|
## Quick Start
|
|
35
91
|
|
|
@@ -53,8 +109,8 @@ if (created && generatedMnemonic) {
|
|
|
53
109
|
console.log('Save this mnemonic:', generatedMnemonic);
|
|
54
110
|
}
|
|
55
111
|
|
|
56
|
-
// Get identity
|
|
57
|
-
console.log('Address:', sphere.identity?.
|
|
112
|
+
// Get identity (L3 DIRECT address is primary)
|
|
113
|
+
console.log('Address:', sphere.identity?.directAddress);
|
|
58
114
|
|
|
59
115
|
// Check balance
|
|
60
116
|
const balance = await sphere.payments.getBalance();
|
|
@@ -99,6 +155,28 @@ const providers = createBrowserProviders({
|
|
|
99
155
|
});
|
|
100
156
|
```
|
|
101
157
|
|
|
158
|
+
## Testnet Faucet
|
|
159
|
+
|
|
160
|
+
To get test tokens on testnet, you **must first register a nametag**:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
// 1. Create wallet and register nametag
|
|
164
|
+
const { sphere } = await Sphere.init({
|
|
165
|
+
...createBrowserProviders({ network: 'testnet' }),
|
|
166
|
+
autoGenerate: true,
|
|
167
|
+
nametag: 'myname', // Register @myname
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// 2. Request tokens from faucet using nametag
|
|
171
|
+
const response = await fetch('https://faucet.testnet.unicity.network/api/claim', {
|
|
172
|
+
method: 'POST',
|
|
173
|
+
headers: { 'Content-Type': 'application/json' },
|
|
174
|
+
body: JSON.stringify({ nametag: '@myname' }),
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
> **Note:** The faucet requires a registered nametag. Requests without a valid nametag will fail.
|
|
179
|
+
|
|
102
180
|
## Multi-Address Support
|
|
103
181
|
|
|
104
182
|
The SDK supports HD (Hierarchical Deterministic) wallets with multiple addresses:
|
|
@@ -131,20 +209,22 @@ console.log(addr2.address, addr2.publicKey);
|
|
|
131
209
|
|
|
132
210
|
### Identity Properties
|
|
133
211
|
|
|
212
|
+
**Important:** L3 (DIRECT address) is the primary address for the Unicity network. L1 address is only used for ALPHA blockchain operations.
|
|
213
|
+
|
|
134
214
|
```typescript
|
|
135
215
|
interface Identity {
|
|
136
216
|
chainPubkey: string; // 33-byte compressed secp256k1 public key (for L3 chain)
|
|
137
|
-
|
|
138
|
-
|
|
217
|
+
directAddress?: string; // L3 DIRECT address (DIRECT://...) - PRIMARY ADDRESS
|
|
218
|
+
l1Address: string; // L1 address (alpha1...) - for ALPHA blockchain only
|
|
139
219
|
ipnsName?: string; // IPNS name for token sync
|
|
140
220
|
nametag?: string; // Registered nametag (@username)
|
|
141
221
|
}
|
|
142
222
|
|
|
143
|
-
// Access identity
|
|
144
|
-
console.log(sphere.identity?.
|
|
145
|
-
console.log(sphere.identity?.
|
|
223
|
+
// Access identity - use directAddress as primary
|
|
224
|
+
console.log(sphere.identity?.directAddress); // DIRECT://0000be36... (PRIMARY)
|
|
225
|
+
console.log(sphere.identity?.nametag); // alice (human-readable)
|
|
226
|
+
console.log(sphere.identity?.l1Address); // alpha1qw3e... (L1 only)
|
|
146
227
|
console.log(sphere.identity?.chainPubkey); // 02abc123... (33-byte compressed)
|
|
147
|
-
console.log(sphere.identity?.nametag); // alice
|
|
148
228
|
```
|
|
149
229
|
|
|
150
230
|
### Address Change Event
|
|
@@ -1001,6 +1081,8 @@ function getRelayStatuses() {
|
|
|
1001
1081
|
|
|
1002
1082
|
Nametags provide human-readable addresses (e.g., `@alice`) for receiving payments.
|
|
1003
1083
|
|
|
1084
|
+
> **Important:** Nametags are required to use the testnet faucet. Register a nametag before requesting test tokens.
|
|
1085
|
+
|
|
1004
1086
|
> **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
1087
|
|
|
1006
1088
|
### Registering a Nametag
|