@unicitylabs/sphere-sdk 0.12.0 → 0.13.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.
@@ -286,7 +286,7 @@ var SPHERE_NETWORKS = {
286
286
 
287
287
  // connect/protocol.ts
288
288
  var SPHERE_CONNECT_NAMESPACE = "sphere-connect";
289
- var SPHERE_CONNECT_VERSION = "2.0";
289
+ var SPHERE_CONNECT_VERSION = "2.1";
290
290
  var RPC_METHODS = {
291
291
  GET_IDENTITY: "sphere_getIdentity",
292
292
  GET_BALANCE: "sphere_getBalance",
@@ -322,6 +322,75 @@ var INTENT_ACTIONS = {
322
322
  SET_AUTO_RETURN: "set_auto_return",
323
323
  MINT: "mint"
324
324
  };
325
+ var ERROR_CODES = {
326
+ // Standard JSON-RPC
327
+ PARSE_ERROR: -32700,
328
+ INVALID_REQUEST: -32600,
329
+ METHOD_NOT_FOUND: -32601,
330
+ INVALID_PARAMS: -32602,
331
+ INTERNAL_ERROR: -32603,
332
+ // Sphere Connect (4xxx)
333
+ NOT_CONNECTED: 4001,
334
+ PERMISSION_DENIED: 4002,
335
+ USER_REJECTED: 4003,
336
+ SESSION_EXPIRED: 4004,
337
+ ORIGIN_BLOCKED: 4005,
338
+ RATE_LIMITED: 4006,
339
+ UNSUPPORTED_PROTOCOL_VERSION: 4007,
340
+ // Connect MAJOR mismatch (incompatible era)
341
+ INCOMPATIBLE_NETWORK: 4008,
342
+ // dApp targets a different network than the wallet
343
+ // Wallet locked; THE SESSION IS STILL ALIVE. A QUERY may be retried after wallet:unlocked.
344
+ // An INTENT already delegated to the wallet is NEVER answered with this code — it gets
345
+ // INTENT_OUTCOME_UNKNOWN (4201) instead, because a retry could double-spend.
346
+ WALLET_LOCKED: 4009,
347
+ INSUFFICIENT_BALANCE: 4100,
348
+ INVALID_RECIPIENT: 4101,
349
+ TRANSFER_FAILED: 4102,
350
+ INTENT_CANCELLED: 4200,
351
+ /**
352
+ * The intent was DELEGATED to the wallet and the host lost track of the answer — a host
353
+ * deadline fired, or the wallet locked / logged out mid-flight. **The outcome is UNKNOWN:
354
+ * the money may or may not have moved.**
355
+ *
356
+ * A dApp MUST NOT retry on this code. Reconcile out of band (poll the recipient, the
357
+ * aggregator, or your own backend) and only then decide.
358
+ *
359
+ * This code exists because every other answer would be a lie. `INTENT_CANCELLED` (4200)
360
+ * asserts the user declined and nothing happened; `WALLET_LOCKED` (4009) invites a retry
361
+ * after the unlock. Sending either for an intent the wallet had already submitted is how a
362
+ * paid-but-not-credited order — and then a double spend on retry — happens.
363
+ */
364
+ INTENT_OUTCOME_UNKNOWN: 4201
365
+ };
366
+ var WALLET_EVENTS = {
367
+ /** Wallet is LOCKED — the session is STILL ALIVE. Requests are answered
368
+ * WALLET_LOCKED (4009) until `wallet:unlocked`. The dApp must NOT disconnect,
369
+ * must NOT clear its sessionId, and must NOT re-handshake.
370
+ * Payload: {@link WalletLockedPayload}. Pushed by ConnectHost.setLocked() and
371
+ * immediately after a handshake response carrying `locked: true`. */
372
+ LOCKED: "wallet:locked",
373
+ /** Wallet was unlocked — the SAME session continues: no re-handshake, no re-approval,
374
+ * no re-subscribe (the host re-arms the dApp's subscriptions before pushing this).
375
+ * Payload: {@link WalletUnlockedPayload} — carries the CURRENT identity, which may
376
+ * differ from the one the dApp connected with. Pushed by ConnectHost.updateSphere()
377
+ * on the locked -> live edge only. */
378
+ UNLOCKED: "wallet:unlocked",
379
+ /** The session is GONE (logout, wallet deleted, dApp sphere_disconnect, expiry seen at
380
+ * unlock, a different seed behind the lock screen, host destroy).
381
+ * The dApp must clear its session and re-handshake to continue. Unlocking does not cure it.
382
+ * Payload: {@link WalletDisconnectedPayload}. Pushed by ConnectHost.revokeSession(). */
383
+ DISCONNECTED: "wallet:disconnected",
384
+ /** Active wallet address changed. dApp should update displayed identity.
385
+ * Pushed automatically by ConnectHost — no sphere_subscribe needed. */
386
+ IDENTITY_CHANGED: "identity:changed"
387
+ };
388
+ var AUTO_PUSHED_EVENTS = [
389
+ WALLET_EVENTS.LOCKED,
390
+ WALLET_EVENTS.UNLOCKED,
391
+ WALLET_EVENTS.DISCONNECTED,
392
+ WALLET_EVENTS.IDENTITY_CHANGED
393
+ ];
325
394
  function isSphereConnectMessage(msg) {
326
395
  if (!msg || typeof msg !== "object") return false;
327
396
  const m = msg;
@@ -388,6 +457,37 @@ var INTENT_PERMISSIONS = {
388
457
  [INTENT_ACTIONS.MINT]: PERMISSION_SCOPES.MINT_REQUEST
389
458
  };
390
459
 
460
+ // connect/host/host-state.ts
461
+ var WALLET_LOCKED_MESSAGE = "Wallet is locked";
462
+ var NOT_CONNECTED_MESSAGE = "Not connected";
463
+ var LOCKED_ALLOWLIST = /* @__PURE__ */ new Set([
464
+ RPC_METHODS.GET_IDENTITY,
465
+ RPC_METHODS.SUBSCRIBE,
466
+ RPC_METHODS.UNSUBSCRIBE,
467
+ RPC_METHODS.DISCONNECT
468
+ ]);
469
+ var REFUSE_NOT_CONNECTED = {
470
+ kind: "refuse",
471
+ error: { code: ERROR_CODES.NOT_CONNECTED, message: NOT_CONNECTED_MESSAGE }
472
+ };
473
+ var REFUSE_LOCKED = {
474
+ kind: "refuse",
475
+ error: {
476
+ code: ERROR_CODES.WALLET_LOCKED,
477
+ message: WALLET_LOCKED_MESSAGE,
478
+ data: { reason: "locked" }
479
+ }
480
+ };
481
+
482
+ // connect/host/WalletSnapshot.ts
483
+ var EMPTY_WALLET_SNAPSHOT = Object.freeze({ capturedAt: 0 });
484
+
485
+ // connect/host/ConnectHost.ts
486
+ var CHANNEL_ONLY_CODES = /* @__PURE__ */ new Set([
487
+ ERROR_CODES.WALLET_LOCKED,
488
+ ERROR_CODES.NOT_CONNECTED
489
+ ]);
490
+
391
491
  // transport/websocket.ts
392
492
  var WebSocketReadyState = {
393
493
  CONNECTING: 0,