@unicitylabs/sphere-sdk 0.2.1 → 0.2.3
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 +22 -69
- package/dist/core/index.cjs +944 -465
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +127 -6
- package/dist/core/index.d.ts +127 -6
- package/dist/core/index.js +833 -351
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +115 -19
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +115 -19
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +3 -1
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +3 -1
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +85 -17
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +22 -0
- package/dist/impl/nodejs/index.d.ts +22 -0
- package/dist/impl/nodejs/index.js +85 -17
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +1083 -644
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +118 -6
- package/dist/index.d.ts +118 -6
- package/dist/index.js +993 -554
- package/dist/index.js.map +1 -1
- package/dist/l1/index.cjs +18 -0
- package/dist/l1/index.cjs.map +1 -1
- package/dist/l1/index.d.cts +4 -0
- package/dist/l1/index.d.ts +4 -0
- package/dist/l1/index.js +18 -0
- package/dist/l1/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -152,7 +152,7 @@ const providers = createBrowserProviders({
|
|
|
152
152
|
oracle: { url: 'https://custom-aggregator.example.com' }, // custom oracle
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
-
//
|
|
155
|
+
// L1 is enabled by default — customize if needed
|
|
156
156
|
const providers = createBrowserProviders({
|
|
157
157
|
network: 'testnet',
|
|
158
158
|
l1: { enableVesting: true }, // uses testnet electrum URL automatically
|
|
@@ -332,17 +332,20 @@ sphere.payments.onPaymentRequest((request) => {
|
|
|
332
332
|
Access L1 payments through `sphere.payments.l1`:
|
|
333
333
|
|
|
334
334
|
```typescript
|
|
335
|
-
// L1
|
|
335
|
+
// L1 is enabled by default with lazy Fulcrum connection.
|
|
336
|
+
// Connection to Fulcrum is deferred until first L1 operation.
|
|
336
337
|
const { sphere } = await Sphere.init({
|
|
337
338
|
...providers,
|
|
338
339
|
autoGenerate: true,
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
},
|
|
340
|
+
// L1 config is optional — defaults are applied automatically:
|
|
341
|
+
// electrumUrl: network-specific (mainnet: fulcrum.alpha.unicity.network)
|
|
342
|
+
// defaultFeeRate: 10 sat/byte
|
|
343
|
+
// enableVesting: true
|
|
344
344
|
});
|
|
345
345
|
|
|
346
|
+
// To explicitly disable L1:
|
|
347
|
+
// const { sphere } = await Sphere.init({ ...providers, l1: null });
|
|
348
|
+
|
|
346
349
|
// Get L1 balance
|
|
347
350
|
const balance = await sphere.payments.l1.getBalance();
|
|
348
351
|
console.log('L1 Balance:', balance.total);
|
|
@@ -847,14 +850,6 @@ const providers = createBrowserProviders({
|
|
|
847
850
|
},
|
|
848
851
|
});
|
|
849
852
|
|
|
850
|
-
// Enable multiple sync backends
|
|
851
|
-
const providers = createBrowserProviders({
|
|
852
|
-
network: 'mainnet',
|
|
853
|
-
tokenSync: {
|
|
854
|
-
ipfs: { enabled: true, useDht: true },
|
|
855
|
-
cloud: { enabled: true, provider: 'aws', bucket: 'my-backup' }, // future
|
|
856
|
-
},
|
|
857
|
-
});
|
|
858
853
|
```
|
|
859
854
|
|
|
860
855
|
## Token Sync Backends
|
|
@@ -864,7 +859,7 @@ The SDK supports multiple token sync backends that can be enabled independently:
|
|
|
864
859
|
| Backend | Status | Description |
|
|
865
860
|
|---------|--------|-------------|
|
|
866
861
|
| `ipfs` | ✅ Ready | Decentralized IPFS/IPNS with Helia browser DHT |
|
|
867
|
-
| `mongodb` |
|
|
862
|
+
| `mongodb` | 🚧 Planned | MongoDB for centralized token storage |
|
|
868
863
|
| `file` | 🚧 Planned | Local file system (Node.js) |
|
|
869
864
|
| `cloud` | 🚧 Planned | Cloud storage (AWS S3, GCP, Azure) |
|
|
870
865
|
|
|
@@ -880,29 +875,6 @@ const providers = createBrowserProviders({
|
|
|
880
875
|
},
|
|
881
876
|
},
|
|
882
877
|
});
|
|
883
|
-
|
|
884
|
-
// Enable MongoDB sync
|
|
885
|
-
const providers = createBrowserProviders({
|
|
886
|
-
network: 'mainnet',
|
|
887
|
-
tokenSync: {
|
|
888
|
-
mongodb: {
|
|
889
|
-
enabled: true,
|
|
890
|
-
uri: 'mongodb://localhost:27017',
|
|
891
|
-
database: 'sphere_wallet',
|
|
892
|
-
collection: 'tokens',
|
|
893
|
-
},
|
|
894
|
-
},
|
|
895
|
-
});
|
|
896
|
-
|
|
897
|
-
// Multiple backends for redundancy
|
|
898
|
-
const providers = createBrowserProviders({
|
|
899
|
-
tokenSync: {
|
|
900
|
-
ipfs: { enabled: true },
|
|
901
|
-
mongodb: { enabled: true, uri: 'mongodb://localhost:27017', database: 'wallet' },
|
|
902
|
-
file: { enabled: true, directory: './tokens', format: 'txf' },
|
|
903
|
-
cloud: { enabled: true, provider: 'aws', bucket: 'wallet-backup' },
|
|
904
|
-
},
|
|
905
|
-
});
|
|
906
878
|
```
|
|
907
879
|
|
|
908
880
|
## Custom Token Storage Provider
|
|
@@ -985,32 +957,32 @@ const { sphere } = await Sphere.init({
|
|
|
985
957
|
|
|
986
958
|
## Dynamic Provider Management (Runtime)
|
|
987
959
|
|
|
988
|
-
After `Sphere.init()` is called, you can add/remove token storage providers dynamically
|
|
960
|
+
After `Sphere.init()` is called, you can add/remove token storage providers dynamically:
|
|
989
961
|
|
|
990
962
|
```typescript
|
|
991
|
-
import {
|
|
963
|
+
import { createIpfsStorageProvider } from '@unicitylabs/sphere-sdk/impl/browser/ipfs';
|
|
992
964
|
|
|
993
|
-
// Add a new provider at runtime (e.g., user enables
|
|
994
|
-
const
|
|
995
|
-
|
|
996
|
-
|
|
965
|
+
// Add a new provider at runtime (e.g., user enables IPFS sync in settings)
|
|
966
|
+
const ipfsProvider = createIpfsStorageProvider({
|
|
967
|
+
gateways: ['https://ipfs.io'],
|
|
968
|
+
useDht: true,
|
|
997
969
|
});
|
|
998
970
|
|
|
999
|
-
await sphere.addTokenStorageProvider(
|
|
971
|
+
await sphere.addTokenStorageProvider(ipfsProvider);
|
|
1000
972
|
|
|
1001
973
|
// Provider is now active and will be used in sync operations
|
|
1002
974
|
|
|
1003
975
|
// Check if provider exists
|
|
1004
|
-
if (sphere.hasTokenStorageProvider('
|
|
1005
|
-
console.log('
|
|
976
|
+
if (sphere.hasTokenStorageProvider('ipfs-token-storage')) {
|
|
977
|
+
console.log('IPFS sync is enabled');
|
|
1006
978
|
}
|
|
1007
979
|
|
|
1008
980
|
// Get all active providers
|
|
1009
981
|
const providers = sphere.getTokenStorageProviders();
|
|
1010
982
|
console.log('Active providers:', Array.from(providers.keys()));
|
|
1011
983
|
|
|
1012
|
-
// Remove a provider (e.g., user disables
|
|
1013
|
-
await sphere.removeTokenStorageProvider('
|
|
984
|
+
// Remove a provider (e.g., user disables IPFS sync)
|
|
985
|
+
await sphere.removeTokenStorageProvider('ipfs-token-storage');
|
|
1014
986
|
|
|
1015
987
|
// Listen for per-provider sync events
|
|
1016
988
|
sphere.on('sync:provider', (event) => {
|
|
@@ -1026,25 +998,6 @@ sphere.on('sync:provider', (event) => {
|
|
|
1026
998
|
await sphere.payments.sync();
|
|
1027
999
|
```
|
|
1028
1000
|
|
|
1029
|
-
### Multiple Providers Example
|
|
1030
|
-
|
|
1031
|
-
```typescript
|
|
1032
|
-
// User configures multiple sync backends via UI
|
|
1033
|
-
const ipfsProvider = createIpfsStorageProvider({ gateways: ['https://ipfs.io'] });
|
|
1034
|
-
const mongoProvider = createMongoDbStorageProvider({ uri: 'mongodb://...' });
|
|
1035
|
-
const s3Provider = createS3StorageProvider({ bucket: 'wallet-backup' });
|
|
1036
|
-
|
|
1037
|
-
// Add all providers
|
|
1038
|
-
await sphere.addTokenStorageProvider(ipfsProvider);
|
|
1039
|
-
await sphere.addTokenStorageProvider(mongoProvider);
|
|
1040
|
-
await sphere.addTokenStorageProvider(s3Provider);
|
|
1041
|
-
|
|
1042
|
-
// Sync syncs with ALL active providers
|
|
1043
|
-
// If one fails, others continue (fault-tolerant)
|
|
1044
|
-
const result = await sphere.payments.sync();
|
|
1045
|
-
console.log(`Synced: +${result.added} -${result.removed}`);
|
|
1046
|
-
```
|
|
1047
|
-
|
|
1048
1001
|
## Dynamic Relay Management
|
|
1049
1002
|
|
|
1050
1003
|
Nostr relays can be added or removed at runtime through the transport provider:
|