@unicitylabs/sphere-sdk 0.2.3 → 0.3.0
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 +61 -20
- package/dist/core/index.cjs +5764 -3576
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +648 -256
- package/dist/core/index.d.ts +648 -256
- package/dist/core/index.js +5767 -3576
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +2118 -185
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +2118 -185
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +1823 -513
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +1823 -513
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +2110 -183
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +86 -23
- package/dist/impl/nodejs/index.d.ts +86 -23
- package/dist/impl/nodejs/index.js +2110 -183
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +5782 -3603
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +719 -105
- package/dist/index.d.ts +719 -105
- package/dist/index.js +5780 -3603
- package/dist/index.js.map +1 -1
- package/package.json +28 -6
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ A modular TypeScript SDK for Unicity wallet operations supporting both Layer 1 (
|
|
|
9
9
|
- **L3 Payments** - Token transfers with state transition proofs
|
|
10
10
|
- **Payment Requests** - Request payments with async response tracking
|
|
11
11
|
- **Nostr Transport** - P2P messaging with NIP-04 encryption
|
|
12
|
-
- **IPFS Storage** - Decentralized token backup
|
|
12
|
+
- **IPFS Storage** - Decentralized token backup via HTTP API (browser + Node.js)
|
|
13
13
|
- **Token Splitting** - Partial transfer amount calculations
|
|
14
14
|
- **Multi-Address** - HD address derivation (BIP32/BIP44)
|
|
15
15
|
- **TXF Serialization** - Token eXchange Format for storage and transfer
|
|
@@ -28,8 +28,8 @@ Choose your platform:
|
|
|
28
28
|
|
|
29
29
|
| Platform | Guide | Required | Optional |
|
|
30
30
|
|----------|-------|----------|----------|
|
|
31
|
-
| **Browser** | [QUICKSTART-BROWSER.md](docs/QUICKSTART-BROWSER.md) | SDK only |
|
|
32
|
-
| **Node.js** | [QUICKSTART-NODEJS.md](docs/QUICKSTART-NODEJS.md) | SDK + `ws` | - |
|
|
31
|
+
| **Browser** | [QUICKSTART-BROWSER.md](docs/QUICKSTART-BROWSER.md) | SDK only | IPFS sync (built-in) |
|
|
32
|
+
| **Node.js** | [QUICKSTART-NODEJS.md](docs/QUICKSTART-NODEJS.md) | SDK + `ws` | IPFS sync (built-in) |
|
|
33
33
|
| **CLI** | See below | SDK + `tsx` | - |
|
|
34
34
|
|
|
35
35
|
## CLI (Command Line Interface)
|
|
@@ -43,6 +43,9 @@ npm run cli -- --help
|
|
|
43
43
|
# Initialize new wallet on testnet
|
|
44
44
|
npm run cli -- init --network testnet
|
|
45
45
|
|
|
46
|
+
# Initialize with nametag (mints token on-chain)
|
|
47
|
+
npm run cli -- init --network testnet --nametag alice
|
|
48
|
+
|
|
46
49
|
# Import existing wallet
|
|
47
50
|
npm run cli -- init --mnemonic "your 24 words here"
|
|
48
51
|
|
|
@@ -52,35 +55,58 @@ npm run cli -- status
|
|
|
52
55
|
# Check balance
|
|
53
56
|
npm run cli -- balance
|
|
54
57
|
|
|
55
|
-
#
|
|
58
|
+
# Fetch pending transfers and finalize unconfirmed tokens
|
|
59
|
+
npm run cli -- balance --finalize
|
|
60
|
+
|
|
61
|
+
# Check for incoming transfers
|
|
56
62
|
npm run cli -- receive
|
|
57
63
|
|
|
58
|
-
#
|
|
59
|
-
npm run cli --
|
|
64
|
+
# Check for incoming transfers and finalize unconfirmed tokens
|
|
65
|
+
npm run cli -- receive --finalize
|
|
66
|
+
|
|
67
|
+
# Send tokens (instant mode, default)
|
|
68
|
+
npm run cli -- send @alice 1 --coin UCT --instant
|
|
69
|
+
|
|
70
|
+
# Send tokens (conservative mode — collect all proofs first)
|
|
71
|
+
npm run cli -- send @alice 1 --coin UCT --conservative
|
|
72
|
+
|
|
73
|
+
# Request test tokens from faucet
|
|
74
|
+
npm run cli -- topup
|
|
60
75
|
|
|
61
76
|
# Register nametag
|
|
62
77
|
npm run cli -- nametag myname
|
|
63
78
|
|
|
64
79
|
# Show transaction history
|
|
65
80
|
npm run cli -- history 10
|
|
81
|
+
|
|
82
|
+
# Verify tokens against aggregator (detect spent tokens)
|
|
83
|
+
npm run cli -- verify-balance
|
|
66
84
|
```
|
|
67
85
|
|
|
68
86
|
### Available CLI Commands
|
|
69
87
|
|
|
70
88
|
| Category | Command | Description |
|
|
71
89
|
|----------|---------|-------------|
|
|
72
|
-
| **Wallet** | `init [--network <net>] [--mnemonic "<words>"]` | Create or import wallet |
|
|
90
|
+
| **Wallet** | `init [--network <net>] [--mnemonic "<words>"] [--nametag <name>]` | Create or import wallet |
|
|
73
91
|
| | `status` | Show wallet identity |
|
|
74
92
|
| | `config` | Show/set configuration |
|
|
75
|
-
| **
|
|
76
|
-
| | `
|
|
93
|
+
| **Profiles** | `wallet list` | List all wallet profiles |
|
|
94
|
+
| | `wallet use <name>` | Switch to a wallet profile |
|
|
95
|
+
| | `wallet create <name> [--network <net>]` | Create a new wallet profile |
|
|
96
|
+
| | `wallet delete <name>` | Delete a wallet profile |
|
|
97
|
+
| | `wallet current` | Show current wallet profile |
|
|
98
|
+
| **Balance** | `balance [--finalize]` | Show L3 token balance (--finalize: fetch pending + resolve) |
|
|
99
|
+
| | `tokens` | List all tokens with details |
|
|
77
100
|
| | `l1-balance` | Show L1 (ALPHA) balance |
|
|
78
|
-
|
|
|
79
|
-
| | `
|
|
101
|
+
| | `topup [coin] [amount]` | Request test tokens from faucet |
|
|
102
|
+
| | `verify-balance [--remove] [-v]` | Verify tokens against aggregator |
|
|
103
|
+
| **Transfers** | `send <to> <amount> [--coin SYM] [--instant\|--conservative]` | Send tokens |
|
|
104
|
+
| | `receive [--finalize]` | Check for incoming transfers |
|
|
80
105
|
| | `history [limit]` | Show transaction history |
|
|
81
106
|
| **Nametags** | `nametag <name>` | Register a nametag |
|
|
82
107
|
| | `nametag-info <name>` | Lookup nametag info |
|
|
83
108
|
| | `my-nametag` | Show current nametag |
|
|
109
|
+
| | `nametag-sync` | Re-publish nametag with chainPubkey |
|
|
84
110
|
| **Utils** | `generate-key` | Generate random key |
|
|
85
111
|
| | `to-human <amount>` | Convert to human readable |
|
|
86
112
|
| | `parse-wallet <file>` | Parse wallet file |
|
|
@@ -709,7 +735,7 @@ The SDK includes browser-ready provider implementations:
|
|
|
709
735
|
| `LocalStorageProvider` | Browser localStorage with SSR fallback |
|
|
710
736
|
| `NostrTransportProvider` | Nostr relay messaging with NIP-04 |
|
|
711
737
|
| `UnicityAggregatorProvider` | Unicity aggregator for state proofs |
|
|
712
|
-
| `IpfsStorageProvider` |
|
|
738
|
+
| `IpfsStorageProvider` | HTTP-based IPFS/IPNS storage (cross-platform) |
|
|
713
739
|
|
|
714
740
|
## Node.js Providers
|
|
715
741
|
|
|
@@ -858,20 +884,31 @@ The SDK supports multiple token sync backends that can be enabled independently:
|
|
|
858
884
|
|
|
859
885
|
| Backend | Status | Description |
|
|
860
886
|
|---------|--------|-------------|
|
|
861
|
-
| `ipfs` | ✅ Ready |
|
|
887
|
+
| `ipfs` | ✅ Ready | HTTP-based IPFS/IPNS storage (browser + Node.js) |
|
|
862
888
|
| `mongodb` | 🚧 Planned | MongoDB for centralized token storage |
|
|
863
889
|
| `file` | 🚧 Planned | Local file system (Node.js) |
|
|
864
890
|
| `cloud` | 🚧 Planned | Cloud storage (AWS S3, GCP, Azure) |
|
|
865
891
|
|
|
866
892
|
```typescript
|
|
867
|
-
//
|
|
893
|
+
// Browser: enable IPFS sync
|
|
868
894
|
const providers = createBrowserProviders({
|
|
869
895
|
network: 'testnet',
|
|
870
896
|
tokenSync: {
|
|
871
897
|
ipfs: {
|
|
872
898
|
enabled: true,
|
|
873
899
|
additionalGateways: ['https://my-gateway.com'],
|
|
874
|
-
|
|
900
|
+
},
|
|
901
|
+
},
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
// Node.js: enable IPFS sync
|
|
905
|
+
const providers = createNodeProviders({
|
|
906
|
+
network: 'testnet',
|
|
907
|
+
dataDir: './wallet-data',
|
|
908
|
+
tokensDir: './tokens-data',
|
|
909
|
+
tokenSync: {
|
|
910
|
+
ipfs: {
|
|
911
|
+
enabled: true,
|
|
875
912
|
},
|
|
876
913
|
},
|
|
877
914
|
});
|
|
@@ -960,12 +997,12 @@ const { sphere } = await Sphere.init({
|
|
|
960
997
|
After `Sphere.init()` is called, you can add/remove token storage providers dynamically:
|
|
961
998
|
|
|
962
999
|
```typescript
|
|
963
|
-
import {
|
|
1000
|
+
import { createBrowserIpfsStorageProvider } from '@unicitylabs/sphere-sdk/impl/browser/ipfs';
|
|
1001
|
+
// For Node.js: import { createNodeIpfsStorageProvider } from '@unicitylabs/sphere-sdk/impl/nodejs/ipfs';
|
|
964
1002
|
|
|
965
1003
|
// Add a new provider at runtime (e.g., user enables IPFS sync in settings)
|
|
966
|
-
const ipfsProvider =
|
|
967
|
-
gateways: ['https://ipfs.
|
|
968
|
-
useDht: true,
|
|
1004
|
+
const ipfsProvider = createBrowserIpfsStorageProvider({
|
|
1005
|
+
gateways: ['https://my-ipfs-node.com'],
|
|
969
1006
|
});
|
|
970
1007
|
|
|
971
1008
|
await sphere.addTokenStorageProvider(ipfsProvider);
|
|
@@ -1077,7 +1114,7 @@ function getRelayStatuses() {
|
|
|
1077
1114
|
|
|
1078
1115
|
## Nametags
|
|
1079
1116
|
|
|
1080
|
-
Nametags provide human-readable addresses (e.g., `@alice`) for receiving payments.
|
|
1117
|
+
Nametags provide human-readable addresses (e.g., `@alice`) for receiving payments. Valid formats: lowercase alphanumeric with `_` or `-` (3–20 chars), or E.164 phone numbers (e.g., `+14155552671`). Input is normalized to lowercase automatically.
|
|
1081
1118
|
|
|
1082
1119
|
> **Important:** Nametags are required to use the testnet faucet. Register a nametag before requesting test tokens.
|
|
1083
1120
|
|
|
@@ -1211,6 +1248,10 @@ const bobTag = sphere.getNametagForAddress(1); // 'bob'
|
|
|
1211
1248
|
|
|
1212
1249
|
---
|
|
1213
1250
|
|
|
1251
|
+
See [IPFS Storage Guide](docs/IPFS-STORAGE.md) for complete IPFS/IPNS documentation including configuration, caching, merge rules, and troubleshooting.
|
|
1252
|
+
|
|
1253
|
+
---
|
|
1254
|
+
|
|
1214
1255
|
## Known Limitations / TODO
|
|
1215
1256
|
|
|
1216
1257
|
### Wallet Encryption
|