@unicitylabs/sphere-sdk 0.12.0-dev.1 → 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.
@@ -324,7 +324,7 @@ var SPHERE_NETWORKS = {
324
324
 
325
325
  // connect/protocol.ts
326
326
  var SPHERE_CONNECT_NAMESPACE = "sphere-connect";
327
- var SPHERE_CONNECT_VERSION = "2.0";
327
+ var SPHERE_CONNECT_VERSION = "2.1";
328
328
  var RPC_METHODS = {
329
329
  GET_IDENTITY: "sphere_getIdentity",
330
330
  GET_BALANCE: "sphere_getBalance",
@@ -360,6 +360,75 @@ var INTENT_ACTIONS = {
360
360
  SET_AUTO_RETURN: "set_auto_return",
361
361
  MINT: "mint"
362
362
  };
363
+ var ERROR_CODES = {
364
+ // Standard JSON-RPC
365
+ PARSE_ERROR: -32700,
366
+ INVALID_REQUEST: -32600,
367
+ METHOD_NOT_FOUND: -32601,
368
+ INVALID_PARAMS: -32602,
369
+ INTERNAL_ERROR: -32603,
370
+ // Sphere Connect (4xxx)
371
+ NOT_CONNECTED: 4001,
372
+ PERMISSION_DENIED: 4002,
373
+ USER_REJECTED: 4003,
374
+ SESSION_EXPIRED: 4004,
375
+ ORIGIN_BLOCKED: 4005,
376
+ RATE_LIMITED: 4006,
377
+ UNSUPPORTED_PROTOCOL_VERSION: 4007,
378
+ // Connect MAJOR mismatch (incompatible era)
379
+ INCOMPATIBLE_NETWORK: 4008,
380
+ // dApp targets a different network than the wallet
381
+ // Wallet locked; THE SESSION IS STILL ALIVE. A QUERY may be retried after wallet:unlocked.
382
+ // An INTENT already delegated to the wallet is NEVER answered with this code — it gets
383
+ // INTENT_OUTCOME_UNKNOWN (4201) instead, because a retry could double-spend.
384
+ WALLET_LOCKED: 4009,
385
+ INSUFFICIENT_BALANCE: 4100,
386
+ INVALID_RECIPIENT: 4101,
387
+ TRANSFER_FAILED: 4102,
388
+ INTENT_CANCELLED: 4200,
389
+ /**
390
+ * The intent was DELEGATED to the wallet and the host lost track of the answer — a host
391
+ * deadline fired, or the wallet locked / logged out mid-flight. **The outcome is UNKNOWN:
392
+ * the money may or may not have moved.**
393
+ *
394
+ * A dApp MUST NOT retry on this code. Reconcile out of band (poll the recipient, the
395
+ * aggregator, or your own backend) and only then decide.
396
+ *
397
+ * This code exists because every other answer would be a lie. `INTENT_CANCELLED` (4200)
398
+ * asserts the user declined and nothing happened; `WALLET_LOCKED` (4009) invites a retry
399
+ * after the unlock. Sending either for an intent the wallet had already submitted is how a
400
+ * paid-but-not-credited order — and then a double spend on retry — happens.
401
+ */
402
+ INTENT_OUTCOME_UNKNOWN: 4201
403
+ };
404
+ var WALLET_EVENTS = {
405
+ /** Wallet is LOCKED — the session is STILL ALIVE. Requests are answered
406
+ * WALLET_LOCKED (4009) until `wallet:unlocked`. The dApp must NOT disconnect,
407
+ * must NOT clear its sessionId, and must NOT re-handshake.
408
+ * Payload: {@link WalletLockedPayload}. Pushed by ConnectHost.setLocked() and
409
+ * immediately after a handshake response carrying `locked: true`. */
410
+ LOCKED: "wallet:locked",
411
+ /** Wallet was unlocked — the SAME session continues: no re-handshake, no re-approval,
412
+ * no re-subscribe (the host re-arms the dApp's subscriptions before pushing this).
413
+ * Payload: {@link WalletUnlockedPayload} — carries the CURRENT identity, which may
414
+ * differ from the one the dApp connected with. Pushed by ConnectHost.updateSphere()
415
+ * on the locked -> live edge only. */
416
+ UNLOCKED: "wallet:unlocked",
417
+ /** The session is GONE (logout, wallet deleted, dApp sphere_disconnect, expiry seen at
418
+ * unlock, a different seed behind the lock screen, host destroy).
419
+ * The dApp must clear its session and re-handshake to continue. Unlocking does not cure it.
420
+ * Payload: {@link WalletDisconnectedPayload}. Pushed by ConnectHost.revokeSession(). */
421
+ DISCONNECTED: "wallet:disconnected",
422
+ /** Active wallet address changed. dApp should update displayed identity.
423
+ * Pushed automatically by ConnectHost — no sphere_subscribe needed. */
424
+ IDENTITY_CHANGED: "identity:changed"
425
+ };
426
+ var AUTO_PUSHED_EVENTS = [
427
+ WALLET_EVENTS.LOCKED,
428
+ WALLET_EVENTS.UNLOCKED,
429
+ WALLET_EVENTS.DISCONNECTED,
430
+ WALLET_EVENTS.IDENTITY_CHANGED
431
+ ];
363
432
  function isSphereConnectMessage(msg) {
364
433
  if (!msg || typeof msg !== "object") return false;
365
434
  const m = msg;
@@ -426,6 +495,37 @@ var INTENT_PERMISSIONS = {
426
495
  [INTENT_ACTIONS.MINT]: PERMISSION_SCOPES.MINT_REQUEST
427
496
  };
428
497
 
498
+ // connect/host/host-state.ts
499
+ var WALLET_LOCKED_MESSAGE = "Wallet is locked";
500
+ var NOT_CONNECTED_MESSAGE = "Not connected";
501
+ var LOCKED_ALLOWLIST = /* @__PURE__ */ new Set([
502
+ RPC_METHODS.GET_IDENTITY,
503
+ RPC_METHODS.SUBSCRIBE,
504
+ RPC_METHODS.UNSUBSCRIBE,
505
+ RPC_METHODS.DISCONNECT
506
+ ]);
507
+ var REFUSE_NOT_CONNECTED = {
508
+ kind: "refuse",
509
+ error: { code: ERROR_CODES.NOT_CONNECTED, message: NOT_CONNECTED_MESSAGE }
510
+ };
511
+ var REFUSE_LOCKED = {
512
+ kind: "refuse",
513
+ error: {
514
+ code: ERROR_CODES.WALLET_LOCKED,
515
+ message: WALLET_LOCKED_MESSAGE,
516
+ data: { reason: "locked" }
517
+ }
518
+ };
519
+
520
+ // connect/host/WalletSnapshot.ts
521
+ var EMPTY_WALLET_SNAPSHOT = Object.freeze({ capturedAt: 0 });
522
+
523
+ // connect/host/ConnectHost.ts
524
+ var CHANNEL_ONLY_CODES = /* @__PURE__ */ new Set([
525
+ ERROR_CODES.WALLET_LOCKED,
526
+ ERROR_CODES.NOT_CONNECTED
527
+ ]);
528
+
429
529
  // transport/websocket.ts
430
530
  var WebSocketReadyState = {
431
531
  CONNECTING: 0,