@unicitylabs/sphere-sdk 0.15.0 → 0.16.0-dev.1

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.
Files changed (50) hide show
  1. package/README.md +15 -5
  2. package/dist/connect/index.cjs +14 -23
  3. package/dist/connect/index.cjs.map +1 -1
  4. package/dist/connect/index.d.cts +4 -0
  5. package/dist/connect/index.d.ts +4 -0
  6. package/dist/connect/index.js +14 -23
  7. package/dist/connect/index.js.map +1 -1
  8. package/dist/core/index.cjs +726 -225
  9. package/dist/core/index.cjs.map +1 -1
  10. package/dist/core/index.d.cts +172 -21
  11. package/dist/core/index.d.ts +172 -21
  12. package/dist/core/index.js +726 -224
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/impl/browser/connect/index.cjs +14 -23
  15. package/dist/impl/browser/connect/index.cjs.map +1 -1
  16. package/dist/impl/browser/connect/index.js +14 -23
  17. package/dist/impl/browser/connect/index.js.map +1 -1
  18. package/dist/impl/browser/index.cjs +331 -504
  19. package/dist/impl/browser/index.cjs.map +1 -1
  20. package/dist/impl/browser/index.js +331 -504
  21. package/dist/impl/browser/index.js.map +1 -1
  22. package/dist/impl/nodejs/connect/index.cjs +13 -22
  23. package/dist/impl/nodejs/connect/index.cjs.map +1 -1
  24. package/dist/impl/nodejs/connect/index.js +13 -22
  25. package/dist/impl/nodejs/connect/index.js.map +1 -1
  26. package/dist/impl/nodejs/index.cjs +298 -569
  27. package/dist/impl/nodejs/index.cjs.map +1 -1
  28. package/dist/impl/nodejs/index.d.cts +90 -13
  29. package/dist/impl/nodejs/index.d.ts +90 -13
  30. package/dist/impl/nodejs/index.js +298 -569
  31. package/dist/impl/nodejs/index.js.map +1 -1
  32. package/dist/impl/shared/wallet-api/index.d.cts +54 -2
  33. package/dist/impl/shared/wallet-api/index.d.ts +54 -2
  34. package/dist/index.cjs +728 -225
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +227 -108
  37. package/dist/index.d.ts +227 -108
  38. package/dist/index.js +728 -224
  39. package/dist/index.js.map +1 -1
  40. package/dist/modules/payments-v2/index.cjs +11 -7
  41. package/dist/modules/payments-v2/index.cjs.map +1 -1
  42. package/dist/modules/payments-v2/index.d.cts +56 -3
  43. package/dist/modules/payments-v2/index.d.ts +56 -3
  44. package/dist/modules/payments-v2/index.js +11 -7
  45. package/dist/modules/payments-v2/index.js.map +1 -1
  46. package/dist/token-engine/index.cjs +46 -0
  47. package/dist/token-engine/index.cjs.map +1 -1
  48. package/dist/token-engine/index.js +46 -0
  49. package/dist/token-engine/index.js.map +1 -1
  50. package/package.json +1 -1
@@ -58,6 +58,25 @@ interface TrackedAddressEntry {
58
58
  * All operations are async for platform flexibility
59
59
  */
60
60
  interface StorageProvider extends BaseProvider {
61
+ /**
62
+ * Stable identity of the BACKING STORE this provider addresses — not of this
63
+ * object, and not of the class (`id` is a class constant like `'file-storage'`,
64
+ * which is exactly the wrong granularity).
65
+ *
66
+ * Two providers that return the SAME value address the same data, so erasing
67
+ * through one erases through the other: `Sphere.clear({ storage })` tears down
68
+ * the live Spheres of every provider sharing this value, not merely those built
69
+ * on this object. Compose it from everything that selects the store (file path,
70
+ * database name, key prefix) behind a scheme prefix, so two kinds of store can
71
+ * never collide on one string.
72
+ *
73
+ * It must not change over the provider's lifetime — it is read again on teardown,
74
+ * and a value that moved would strand the entry it was registered under.
75
+ *
76
+ * Optional: omit it and liveness falls back to per-object identity, i.e. a
77
+ * second provider over the same data is treated as unrelated.
78
+ */
79
+ readonly backingStoreId?: string;
61
80
  /**
62
81
  * Set identity for scoped storage
63
82
  */
@@ -87,11 +106,44 @@ interface StorageProvider extends BaseProvider {
87
106
  */
88
107
  clear(prefix?: string): Promise<void>;
89
108
  /**
90
- * Save tracked addresses (only user state: index, hidden, timestamps)
109
+ * Save tracked addresses (only user state: index, hidden, timestamps).
110
+ *
111
+ * MUST MERGE, NEVER REPLACE (#766 item 5). `entries` is ONE writer's snapshot,
112
+ * not the whole truth: every Sphere sharing this storage keeps its own copy of
113
+ * the registry and persists all of it, so writing the argument verbatim is a
114
+ * lost update — A activates index 1, B (whose snapshot predates that) activates
115
+ * index 2, and B's write erases index 1 while A still reports it. This happens
116
+ * on a single network with a single provider; do NOT "fix" it by renaming or
117
+ * network-scoping the key.
118
+ *
119
+ * The contract, implemented by `storage/tracked-addresses.ts` — reuse those
120
+ * helpers rather than re-deriving this:
121
+ * - read the stored registry, union it with `entries` BY `index`;
122
+ * - on a conflicting index, the entry with the greater `updatedAt` supplies
123
+ * `hidden`, and `createdAt` keeps the earlier value;
124
+ * - serialize concurrent calls on the provider instance, so one call's read
125
+ * cannot interleave with another's write;
126
+ * - a failed write must not brick later writes, and must still reject to its
127
+ * own caller.
128
+ *
129
+ * An `index` must be a UINT32 — a BIP32 child number. `deriveKeyAtPath` parseInt()s
130
+ * that path segment, so `1.5` derives index 1's keys and the row aliases a real
131
+ * address. The ceiling matters too: `deriveChildKey` pads the child number to 8 hex
132
+ * digits, so anything above `0xffffffff` emits extra bytes and derives off-standard.
133
+ * An `entries` row that is not one must REJECT the whole call (`mergeTrackedAddresses`
134
+ * throws `VALIDATION_ERROR`); dropping it silently on a write reports a save that
135
+ * never happened. Already-stored rows are dropped on READ instead, so one bad row
136
+ * cannot brick every later write. Validate before opening the write transaction if
137
+ * your platform would otherwise replace the reason with a generic abort.
138
+ *
139
+ * A union is safe because there is no delete path: entries are only ever added,
140
+ * and wiping the wallet removes the key itself (`Sphere.clear()`). Adding a
141
+ * per-entry delete would require revisiting this contract.
91
142
  */
92
143
  saveTrackedAddresses(entries: TrackedAddressEntry[]): Promise<void>;
93
144
  /**
94
- * Load tracked addresses
145
+ * Load tracked addresses. Tolerant: unusable/corrupt storage reads as `[]`
146
+ * (see `parseTrackedAddresses` in `storage/tracked-addresses.ts`).
95
147
  */
96
148
  loadTrackedAddresses(): Promise<TrackedAddressEntry[]>;
97
149
  }
@@ -58,6 +58,25 @@ interface TrackedAddressEntry {
58
58
  * All operations are async for platform flexibility
59
59
  */
60
60
  interface StorageProvider extends BaseProvider {
61
+ /**
62
+ * Stable identity of the BACKING STORE this provider addresses — not of this
63
+ * object, and not of the class (`id` is a class constant like `'file-storage'`,
64
+ * which is exactly the wrong granularity).
65
+ *
66
+ * Two providers that return the SAME value address the same data, so erasing
67
+ * through one erases through the other: `Sphere.clear({ storage })` tears down
68
+ * the live Spheres of every provider sharing this value, not merely those built
69
+ * on this object. Compose it from everything that selects the store (file path,
70
+ * database name, key prefix) behind a scheme prefix, so two kinds of store can
71
+ * never collide on one string.
72
+ *
73
+ * It must not change over the provider's lifetime — it is read again on teardown,
74
+ * and a value that moved would strand the entry it was registered under.
75
+ *
76
+ * Optional: omit it and liveness falls back to per-object identity, i.e. a
77
+ * second provider over the same data is treated as unrelated.
78
+ */
79
+ readonly backingStoreId?: string;
61
80
  /**
62
81
  * Set identity for scoped storage
63
82
  */
@@ -87,11 +106,44 @@ interface StorageProvider extends BaseProvider {
87
106
  */
88
107
  clear(prefix?: string): Promise<void>;
89
108
  /**
90
- * Save tracked addresses (only user state: index, hidden, timestamps)
109
+ * Save tracked addresses (only user state: index, hidden, timestamps).
110
+ *
111
+ * MUST MERGE, NEVER REPLACE (#766 item 5). `entries` is ONE writer's snapshot,
112
+ * not the whole truth: every Sphere sharing this storage keeps its own copy of
113
+ * the registry and persists all of it, so writing the argument verbatim is a
114
+ * lost update — A activates index 1, B (whose snapshot predates that) activates
115
+ * index 2, and B's write erases index 1 while A still reports it. This happens
116
+ * on a single network with a single provider; do NOT "fix" it by renaming or
117
+ * network-scoping the key.
118
+ *
119
+ * The contract, implemented by `storage/tracked-addresses.ts` — reuse those
120
+ * helpers rather than re-deriving this:
121
+ * - read the stored registry, union it with `entries` BY `index`;
122
+ * - on a conflicting index, the entry with the greater `updatedAt` supplies
123
+ * `hidden`, and `createdAt` keeps the earlier value;
124
+ * - serialize concurrent calls on the provider instance, so one call's read
125
+ * cannot interleave with another's write;
126
+ * - a failed write must not brick later writes, and must still reject to its
127
+ * own caller.
128
+ *
129
+ * An `index` must be a UINT32 — a BIP32 child number. `deriveKeyAtPath` parseInt()s
130
+ * that path segment, so `1.5` derives index 1's keys and the row aliases a real
131
+ * address. The ceiling matters too: `deriveChildKey` pads the child number to 8 hex
132
+ * digits, so anything above `0xffffffff` emits extra bytes and derives off-standard.
133
+ * An `entries` row that is not one must REJECT the whole call (`mergeTrackedAddresses`
134
+ * throws `VALIDATION_ERROR`); dropping it silently on a write reports a save that
135
+ * never happened. Already-stored rows are dropped on READ instead, so one bad row
136
+ * cannot brick every later write. Validate before opening the write transaction if
137
+ * your platform would otherwise replace the reason with a generic abort.
138
+ *
139
+ * A union is safe because there is no delete path: entries are only ever added,
140
+ * and wiping the wallet removes the key itself (`Sphere.clear()`). Adding a
141
+ * per-entry delete would require revisiting this contract.
91
142
  */
92
143
  saveTrackedAddresses(entries: TrackedAddressEntry[]): Promise<void>;
93
144
  /**
94
- * Load tracked addresses
145
+ * Load tracked addresses. Tolerant: unusable/corrupt storage reads as `[]`
146
+ * (see `parseTrackedAddresses` in `storage/tracked-addresses.ts`).
95
147
  */
96
148
  loadTrackedAddresses(): Promise<TrackedAddressEntry[]>;
97
149
  }