@unicitylabs/sphere-sdk 0.1.5 → 0.1.7

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 CHANGED
@@ -109,8 +109,8 @@ if (created && generatedMnemonic) {
109
109
  console.log('Save this mnemonic:', generatedMnemonic);
110
110
  }
111
111
 
112
- // Get identity
113
- console.log('Address:', sphere.identity?.l1Address);
112
+ // Get identity (L3 DIRECT address is primary)
113
+ console.log('Address:', sphere.identity?.directAddress);
114
114
 
115
115
  // Check balance
116
116
  const balance = await sphere.payments.getBalance();
@@ -155,6 +155,28 @@ const providers = createBrowserProviders({
155
155
  });
156
156
  ```
157
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.unicity.network/api/v1/faucet/request', {
172
+ method: 'POST',
173
+ headers: { 'Content-Type': 'application/json' },
174
+ body: JSON.stringify({ unicityId: 'myname', coin: 'unicity', amount: 100 }),
175
+ });
176
+ ```
177
+
178
+ > **Note:** The faucet requires a registered nametag. Requests without a valid nametag will fail.
179
+
158
180
  ## Multi-Address Support
159
181
 
160
182
  The SDK supports HD (Hierarchical Deterministic) wallets with multiple addresses:
@@ -187,20 +209,22 @@ console.log(addr2.address, addr2.publicKey);
187
209
 
188
210
  ### Identity Properties
189
211
 
212
+ **Important:** L3 (DIRECT address) is the primary address for the Unicity network. L1 address is only used for ALPHA blockchain operations.
213
+
190
214
  ```typescript
191
215
  interface Identity {
192
216
  chainPubkey: string; // 33-byte compressed secp256k1 public key (for L3 chain)
193
- l1Address: string; // L1 address (alpha1...)
194
- directAddress?: string; // L3 DIRECT address (DIRECT://...)
217
+ directAddress?: string; // L3 DIRECT address (DIRECT://...) - PRIMARY ADDRESS
218
+ l1Address: string; // L1 address (alpha1...) - for ALPHA blockchain only
195
219
  ipnsName?: string; // IPNS name for token sync
196
220
  nametag?: string; // Registered nametag (@username)
197
221
  }
198
222
 
199
- // Access identity
200
- console.log(sphere.identity?.l1Address); // alpha1qw3e...
201
- console.log(sphere.identity?.directAddress); // DIRECT://0000be36...
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)
202
227
  console.log(sphere.identity?.chainPubkey); // 02abc123... (33-byte compressed)
203
- console.log(sphere.identity?.nametag); // alice
204
228
  ```
205
229
 
206
230
  ### Address Change Event
@@ -1057,6 +1081,8 @@ function getRelayStatuses() {
1057
1081
 
1058
1082
  Nametags provide human-readable addresses (e.g., `@alice`) for receiving payments.
1059
1083
 
1084
+ > **Important:** Nametags are required to use the testnet faucet. Register a nametag before requesting test tokens.
1085
+
1060
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.
1061
1087
 
1062
1088
  ### Registering a Nametag
@@ -2312,7 +2312,7 @@ var LIMITS = {
2312
2312
  };
2313
2313
 
2314
2314
  // types/txf.ts
2315
- var ARCHIVED_PREFIX = "_archived_";
2315
+ var ARCHIVED_PREFIX = "archived-";
2316
2316
  var FORKED_PREFIX = "_forked_";
2317
2317
  var RESERVED_KEYS = ["_meta", "_nametag", "_tombstones", "_invalidatedNametags", "_outbox", "_mintOutbox", "_sent", "_invalid", "_integrity"];
2318
2318
  function isTokenKey(key) {
@@ -3261,16 +3261,14 @@ var PaymentsModule = class {
3261
3261
  const result = await provider.load();
3262
3262
  if (result.success && result.data) {
3263
3263
  this.loadFromStorageData(result.data);
3264
- this.log(`Loaded from provider ${id}: ${this.tokens.size} tokens`);
3264
+ this.log(`Loaded metadata from provider ${id}`);
3265
3265
  break;
3266
3266
  }
3267
3267
  } catch (err) {
3268
3268
  console.error(`[Payments] Failed to load from provider ${id}:`, err);
3269
3269
  }
3270
3270
  }
3271
- if (this.tokens.size === 0) {
3272
- await this.loadTokensFromFileStorage();
3273
- }
3271
+ await this.loadTokensFromFileStorage();
3274
3272
  await this.loadNametagFromFileStorage();
3275
3273
  const historyData = await this.deps.storage.get(STORAGE_KEYS_ADDRESS.TRANSACTION_HISTORY);
3276
3274
  if (historyData) {
@@ -3908,7 +3906,8 @@ var PaymentsModule = class {
3908
3906
  for (const [providerId, provider] of providers) {
3909
3907
  if (!provider.listTokenIds || !provider.getToken) continue;
3910
3908
  try {
3911
- const tokenIds = await provider.listTokenIds();
3909
+ const allIds = await provider.listTokenIds();
3910
+ const tokenIds = allIds.filter((id) => id.startsWith("token-"));
3912
3911
  this.log(`Found ${tokenIds.length} token files in ${providerId}`);
3913
3912
  for (const tokenId of tokenIds) {
3914
3913
  try {
@@ -3959,9 +3958,7 @@ var PaymentsModule = class {
3959
3958
  console.warn(`[Payments] Failed to load tokens from ${providerId}:`, error);
3960
3959
  }
3961
3960
  }
3962
- if (this.tokens.size > 0) {
3963
- await this.save();
3964
- }
3961
+ this.log(`Loaded ${this.tokens.size} tokens from file storage`);
3965
3962
  }
3966
3963
  /**
3967
3964
  * Update an existing token
@@ -4822,9 +4819,9 @@ var PaymentsModule = class {
4822
4819
  return data ? JSON.parse(data) : [];
4823
4820
  }
4824
4821
  async createStorageData() {
4825
- const tokens = Array.from(this.tokens.values());
4826
4822
  return await buildTxfStorageData(
4827
- tokens,
4823
+ [],
4824
+ // Empty - active tokens stored as token-xxx files
4828
4825
  {
4829
4826
  version: 1,
4830
4827
  address: this.deps.identity.l1Address,