@fairmint/canton-node-sdk 0.0.278 → 0.0.279

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 (56) hide show
  1. package/README.md +137 -17
  2. package/build/src/utils/external-signing/index.d.ts +1 -0
  3. package/build/src/utils/external-signing/index.d.ts.map +1 -1
  4. package/build/src/utils/external-signing/index.js +1 -0
  5. package/build/src/utils/external-signing/index.js.map +1 -1
  6. package/build/src/utils/external-signing/wallet-ownership-challenger.d.ts +93 -0
  7. package/build/src/utils/external-signing/wallet-ownership-challenger.d.ts.map +1 -0
  8. package/build/src/utils/external-signing/wallet-ownership-challenger.js +253 -0
  9. package/build/src/utils/external-signing/wallet-ownership-challenger.js.map +1 -0
  10. package/build/src/utils/external-signing/wallet-ownership.d.ts +3 -24
  11. package/build/src/utils/external-signing/wallet-ownership.d.ts.map +1 -1
  12. package/build/src/utils/external-signing/wallet-ownership.js.map +1 -1
  13. package/build/src/wallets/cip103.d.ts +17 -1
  14. package/build/src/wallets/cip103.d.ts.map +1 -1
  15. package/build/src/wallets/cip103.js +8 -0
  16. package/build/src/wallets/cip103.js.map +1 -1
  17. package/build/src/wallets/errors.d.ts +33 -0
  18. package/build/src/wallets/errors.d.ts.map +1 -1
  19. package/build/src/wallets/errors.js +53 -0
  20. package/build/src/wallets/errors.js.map +1 -1
  21. package/build/src/wallets/holdings.d.ts +25 -0
  22. package/build/src/wallets/holdings.d.ts.map +1 -1
  23. package/build/src/wallets/holdings.js +44 -0
  24. package/build/src/wallets/holdings.js.map +1 -1
  25. package/build/src/wallets/index.d.ts +14 -10
  26. package/build/src/wallets/index.d.ts.map +1 -1
  27. package/build/src/wallets/index.js +17 -5
  28. package/build/src/wallets/index.js.map +1 -1
  29. package/build/src/wallets/notify.d.ts +7 -0
  30. package/build/src/wallets/notify.d.ts.map +1 -0
  31. package/build/src/wallets/notify.js +21 -0
  32. package/build/src/wallets/notify.js.map +1 -0
  33. package/build/src/wallets/ownership.d.ts +77 -0
  34. package/build/src/wallets/ownership.d.ts.map +1 -1
  35. package/build/src/wallets/ownership.js +72 -5
  36. package/build/src/wallets/ownership.js.map +1 -1
  37. package/build/src/wallets/session.d.ts +107 -0
  38. package/build/src/wallets/session.d.ts.map +1 -0
  39. package/build/src/wallets/session.js +371 -0
  40. package/build/src/wallets/session.js.map +1 -0
  41. package/build/src/wallets/store.d.ts +138 -0
  42. package/build/src/wallets/store.d.ts.map +1 -0
  43. package/build/src/wallets/store.js +262 -0
  44. package/build/src/wallets/store.js.map +1 -0
  45. package/build/src/wallets/token-registry.d.ts +4 -2
  46. package/build/src/wallets/token-registry.d.ts.map +1 -1
  47. package/build/src/wallets/token-registry.js.map +1 -1
  48. package/build/src/wallets/token-standard-wallet.d.ts +48 -4
  49. package/build/src/wallets/token-standard-wallet.d.ts.map +1 -1
  50. package/build/src/wallets/token-standard-wallet.js +71 -6
  51. package/build/src/wallets/token-standard-wallet.js.map +1 -1
  52. package/build/src/wallets/token-wallet.d.ts +31 -6
  53. package/build/src/wallets/token-wallet.d.ts.map +1 -1
  54. package/build/src/wallets/token-wallet.js +74 -6
  55. package/build/src/wallets/token-wallet.js.map +1 -1
  56. package/package.json +1 -1
@@ -0,0 +1,371 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCip103Session = createCip103Session;
4
+ /**
5
+ * A CIP-0103 wallet session for a dApp: which wallet is connected, as which party, and whether a reply still belongs to
6
+ * the session that asked. It works with any CIP-0103 provider and holds no wallet SDK: the dApp obtains the provider
7
+ * (Loop's `loop.getCip103Provider()`, `window.canton`, …) and reports the wallet's own callbacks to it.
8
+ *
9
+ * Observable for any UI framework: `subscribe` and `getSnapshot` (React: `useSyncExternalStore`).
10
+ */
11
+ const notify_1 = require("./notify");
12
+ const cip103_1 = require("./cip103");
13
+ const errors_1 = require("./errors");
14
+ const json_1 = require("./json");
15
+ /** How long after an `end('user')` disconnect was sent a `connect()` to the same provider still waits for it. */
16
+ const DISCONNECT_WAIT_MS = 3000;
17
+ const NEVER_CONNECTED = { status: 'disconnected', endedBy: null, error: null };
18
+ const CONNECTING = { status: 'connecting' };
19
+ /** Whether a CIP-0103 `isConnected` answer or `statusChanged` connection says connected (`undefined`: it says nothing). */
20
+ function connectionFlag(connection) {
21
+ const flag = (0, json_1.isRecord)(connection) ? connection['isConnected'] : undefined;
22
+ return typeof flag === 'boolean' ? flag : undefined;
23
+ }
24
+ /** A failed CIP-0103 `connect`, for the user. */
25
+ function connectError(error) {
26
+ const code = (0, cip103_1.cip103ErrorCode)(error);
27
+ if (code === cip103_1.CIP103_ERROR_CODES.userRejected) {
28
+ return { kind: 'declined', message: 'You declined to connect in the wallet.', code };
29
+ }
30
+ const message = `The wallet did not connect: ${(0, cip103_1.describeError)(error)}`;
31
+ return code === undefined ? { kind: 'other', message } : { kind: 'other', message, code };
32
+ }
33
+ /** A failed primary-account read, for the user. */
34
+ function lookupError(error) {
35
+ if (error instanceof errors_1.WalletReadError && error.code === cip103_1.CIP103_ERROR_CODES.unauthorized) {
36
+ const message = `The wallet has no signed-in account: connect again. Details: ${error.message}`;
37
+ return { kind: 'read-failed', message, code: error.code };
38
+ }
39
+ return (0, errors_1.describeWalletError)(error);
40
+ }
41
+ /**
42
+ * A CIP-0103 wallet session. While connected it listens on the provider: `accountsChanged` reads the primary account
43
+ * again (another party becomes a new `ConnectedWallet`), and a `statusChanged` whose `connection.isConnected` is false
44
+ * ends the session (`wallet`). A wallet that never emits these events loses nothing.
45
+ */
46
+ function createCip103Session() {
47
+ const listeners = new Set();
48
+ let state = NEVER_CONNECTED;
49
+ // Every party lookup, and every interrupt(), takes the next number. A reply counts only while its number is at least
50
+ // `floor`: an interrupt() or a connect() or accountsChanged lookup raises the floor when it starts, a connected()
51
+ // lookup only when it acts on its answer, so a callback whose failure is ignored supersedes nothing.
52
+ let lookups = 0;
53
+ let floor = 0;
54
+ // Every connected(..., { ifConnected: true }) takes a new number: only the latest restore may start its lookup.
55
+ let restores = 0;
56
+ // Bumped by connect(), end(), fail() and dispose(): a connect() whose epoch is no longer current stops.
57
+ let epoch = 0;
58
+ // Set by end(): connected() is ignored until the user connects again.
59
+ let closed = false;
60
+ let disposed = false;
61
+ // Numbers each ConnectedWallet's `key`.
62
+ let connections = 0;
63
+ // The provider the pending connect() signs in to, until that connect() settles or is superseded, whatever state is
64
+ // published meanwhile (a failed callback may publish an error while it waits), for end('user')'s disconnect.
65
+ let signingIn = null;
66
+ // Whether that connect() has sent CIP-0103 `connect` (only then has the wallet anything to sign out of).
67
+ let signInSent = false;
68
+ // end('user')'s disconnects in flight, per provider: a connect() to that provider waits for them until `deadline`.
69
+ const disconnecting = new Map();
70
+ let attachment = null;
71
+ function publish(next) {
72
+ if (disposed || next === state)
73
+ return;
74
+ state = next;
75
+ (0, notify_1.notifyListeners)(listeners);
76
+ }
77
+ function detach() {
78
+ const current = attachment;
79
+ attachment = null;
80
+ if (current === null)
81
+ return;
82
+ current.provider.removeListener('accountsChanged', current.onAccountsChanged);
83
+ current.provider.removeListener('statusChanged', current.onStatusChanged);
84
+ }
85
+ function attach(provider) {
86
+ if (attachment?.provider === provider)
87
+ return;
88
+ detach();
89
+ const own = {
90
+ provider,
91
+ onAccountsChanged: () => {
92
+ // Only for this provider's own published wallet, whose network it reads again: a provider that answers a new
93
+ // listener at once (a sticky event) does so before its wallet is published, while `state` is still the
94
+ // previous wallet's (the lookup that attaches it has just read the account anyway).
95
+ if (attachment !== own || state.status !== 'connected' || state.wallet.provider !== provider)
96
+ return;
97
+ const { network } = state.wallet;
98
+ void lookup(provider, network === undefined ? {} : { network });
99
+ },
100
+ onStatusChanged: (status) => {
101
+ if (attachment !== own || !(0, json_1.isRecord)(status))
102
+ return;
103
+ if (connectionFlag(status['connection']) === false)
104
+ end('wallet');
105
+ },
106
+ };
107
+ attachment = own;
108
+ provider.on('accountsChanged', own.onAccountsChanged);
109
+ provider.on('statusChanged', own.onStatusChanged);
110
+ }
111
+ /**
112
+ * Read the primary account and connect as its party, unless a newer lookup or session change superseded it.
113
+ * `passive`: a wallet callback (`connected()`). It supersedes pending lookups only once it acts on its answer, and
114
+ * its failure leaves an already connected session alone (unless that wallet itself reports the other network), and
115
+ * never interrupts a pending connect(). `stillWanted`: false once whatever started it no longer wants its answer (a
116
+ * restore's lookup, once a newer restore started).
117
+ */
118
+ async function lookup(provider, context, passive = false, stillWanted = () => true) {
119
+ const attempt = ++lookups;
120
+ if (!passive)
121
+ floor = attempt;
122
+ const current = () => attempt >= floor && !disposed && stillWanted();
123
+ const failed = (error, otherNetwork) => {
124
+ // A stale callback, or another wallet that cannot be read, does not drop a healthy session, nor does it cancel a
125
+ // pending lookup. The connected wallet reporting the other network is no stale callback: the session ends.
126
+ // While a connect() is pending, its own lookup decides (it always reads the account again), so a callback's
127
+ // failure must not flash an error over `connecting`.
128
+ const ownWallet = state.status === 'connected' && state.wallet.provider === provider;
129
+ if (passive && state.status === 'connecting')
130
+ return;
131
+ if (passive && state.status === 'connected' && !(otherNetwork && ownWallet))
132
+ return;
133
+ floor = attempt;
134
+ detach();
135
+ publish({ status: 'disconnected', endedBy: null, error });
136
+ };
137
+ let account;
138
+ try {
139
+ account = await (0, cip103_1.primaryAccount)(provider);
140
+ }
141
+ catch (error) {
142
+ if (current())
143
+ failed(lookupError(error), false);
144
+ return;
145
+ }
146
+ if (!current())
147
+ return;
148
+ const { network } = context;
149
+ const { partyId, networkId } = account;
150
+ if (network !== undefined && networkId !== undefined && reportsOtherNetwork(networkId, network)) {
151
+ // DA's registry and ledger for `network` would refuse every call of a wallet on another network.
152
+ const message = `The wallet is on ${networkId}, not ${(0, cip103_1.cip103NetworkId)(network)}: switch networks in the wallet, then connect again.`;
153
+ failed({ kind: 'other', message }, true);
154
+ return;
155
+ }
156
+ floor = attempt;
157
+ if (state.status === 'connected' &&
158
+ state.wallet.provider === provider &&
159
+ state.wallet.partyId === partyId &&
160
+ state.wallet.network === network) {
161
+ return; // the same session: keep its object
162
+ }
163
+ const key = String(++connections);
164
+ const wallet = { provider, partyId, key, ...(network !== undefined && { network }) };
165
+ attach(provider);
166
+ // A provider may answer a new listener at once (a sticky `statusChanged`), and that may have ended the session:
167
+ // then this lookup was superseded and publishes nothing.
168
+ if (!current() || closed)
169
+ return;
170
+ publish({ status: 'connected', wallet });
171
+ }
172
+ /** Whether connected() is followed: not disposed, and not ended since the last connect(). Read after an await. */
173
+ function armed() {
174
+ return !disposed && !closed;
175
+ }
176
+ /** Supersede every pending reply and pending connect(), and stop following the provider. */
177
+ function interrupt() {
178
+ epoch += 1;
179
+ floor = ++lookups;
180
+ signingIn = null;
181
+ signInSent = false;
182
+ detach();
183
+ }
184
+ /** The providers the session is on: the connected wallet's, and the one a pending connect() signs in to. */
185
+ function sessionProviders() {
186
+ const providers = new Set();
187
+ if (state.status === 'connected')
188
+ providers.add(state.wallet.provider);
189
+ if (signingIn !== null && signInSent)
190
+ providers.add(signingIn);
191
+ return providers;
192
+ }
193
+ /** `entry` settled, or its deadline passed: never later than its deadline, however long it goes unanswered. */
194
+ async function settledOrDue(entry) {
195
+ let timer;
196
+ const due = new Promise((resolve) => {
197
+ timer = setTimeout(resolve, entry.deadline - Date.now());
198
+ });
199
+ return Promise.race([entry.settled, due]).finally(() => {
200
+ clearTimeout(timer);
201
+ });
202
+ }
203
+ /**
204
+ * Record a CIP-0103 `disconnect` of `provider`, so a `connect()` to it waits for it, and return the function that
205
+ * sends it (best-effort). Recorded before anything is sent: a `connect()` that sending sets off (a wallet that calls
206
+ * back synchronously) finds it.
207
+ */
208
+ function recordDisconnect(provider) {
209
+ let answered = () => undefined;
210
+ const sent = new Promise((resolve) => {
211
+ answered = resolve;
212
+ });
213
+ // An earlier disconnect of the same provider still in flight must settle too, but only until its own deadline: one
214
+ // that never answers must not delay later connect() calls past it, even when chained to this one.
215
+ const found = disconnecting.get(provider);
216
+ const earlier = found !== undefined && found.deadline > Date.now() ? found : undefined;
217
+ const settled = earlier === undefined ? sent : Promise.all([settledOrDue(earlier), sent]).then(() => undefined);
218
+ const own = { settled, deadline: Date.now() + DISCONNECT_WAIT_MS };
219
+ disconnecting.set(provider, own);
220
+ void settled.then(() => {
221
+ if (disconnecting.get(provider) === own)
222
+ disconnecting.delete(provider);
223
+ });
224
+ return () => {
225
+ void (async () => provider.request({ method: 'disconnect' }))().then(answered, answered);
226
+ };
227
+ }
228
+ function end(by) {
229
+ if (disposed)
230
+ return;
231
+ const providers = by === 'user' ? sessionProviders() : new Set();
232
+ interrupt();
233
+ const own = epoch;
234
+ closed = true;
235
+ // Before publishing: a listener that connects again in response must find the disconnect in flight. Every
236
+ // disconnect is recorded before the first is sent, so a connect() that sending sets off waits for each.
237
+ const sends = [...providers].map(recordDisconnect);
238
+ for (const send of sends)
239
+ send();
240
+ // A connect() that sending set off owns the state now (it is signing in). A nested end() or fail() does not (it
241
+ // cleared `signingIn`): this end() still publishes, so a user's disconnect is never reported as the wallet's. (A
242
+ // nested dispose() leaves nothing to publish.)
243
+ if (epoch !== own && signingIn !== null)
244
+ return;
245
+ publish({ status: 'disconnected', endedBy: by, error: null });
246
+ }
247
+ /**
248
+ * An in-flight disconnect of `provider`, settled or past its deadline; `null` when there is none (or its deadline
249
+ * passed), so `connect()` then sends `connect` in the same tick (inside the user's click, where a wallet may open a
250
+ * popup).
251
+ */
252
+ function disconnectSettled(provider) {
253
+ const pending = disconnecting.get(provider);
254
+ if (pending === undefined)
255
+ return null;
256
+ if (pending.deadline <= Date.now()) {
257
+ // It never answered in time: never wait for it again.
258
+ disconnecting.delete(provider);
259
+ return null;
260
+ }
261
+ return settledOrDue(pending);
262
+ }
263
+ return {
264
+ subscribe(listener) {
265
+ listeners.add(listener);
266
+ return () => {
267
+ listeners.delete(listener);
268
+ };
269
+ },
270
+ getSnapshot: () => state,
271
+ async connected(provider, context = {}) {
272
+ if (disposed || closed)
273
+ return;
274
+ const { network } = context;
275
+ if (context.ifConnected === true) {
276
+ // Dropped when a newer restore started, or anything started a lookup or changed the session meanwhile (that
277
+ // newer call decides). Taking a restore number rather than a lookup number supersedes no pending lookup while
278
+ // `isConnected` is in flight, so a restore that finds no session cannot strand a `connect()` in `connecting`.
279
+ const restore = ++restores;
280
+ const seen = lookups;
281
+ let answer = null;
282
+ try {
283
+ answer = await provider.request({ method: 'isConnected' });
284
+ }
285
+ catch {
286
+ // 4200 or any other failure: not connected.
287
+ }
288
+ if (restore !== restores || seen !== lookups || !armed() || connectionFlag(answer) !== true)
289
+ return;
290
+ // The lookup stays the latest restore's: a newer restore (one that finds no session included) drops it.
291
+ await lookup(provider, network === undefined ? {} : { network }, true, () => restore === restores);
292
+ return;
293
+ }
294
+ await lookup(provider, network === undefined ? {} : { network }, true);
295
+ },
296
+ async connect(provider, context = {}) {
297
+ if (disposed)
298
+ return;
299
+ // Another wallet the session is on (connected, or signing in) is signed out: the user switched wallets.
300
+ const previous = [...sessionProviders()].filter((other) => other !== provider);
301
+ interrupt();
302
+ const own = epoch;
303
+ const current = () => own === epoch && !disposed;
304
+ // connected() stays ignored until `connect` is sent: a stale callback must not connect while this one waits.
305
+ closed = true;
306
+ signingIn = provider;
307
+ const sends = previous.map(recordDisconnect);
308
+ for (const send of sends)
309
+ send();
310
+ if (!current())
311
+ return; // sending set off an end(), fail(), dispose() or another connect()
312
+ publish(CONNECTING);
313
+ // A listener of that publish may have ended, superseded or disposed the session: send nothing to the wallet then.
314
+ if (!current())
315
+ return;
316
+ try {
317
+ try {
318
+ // A disconnect the user sent this wallet just before must not land after the new sign-in.
319
+ const disconnected = disconnectSettled(provider);
320
+ if (disconnected !== null) {
321
+ await disconnected;
322
+ if (!current())
323
+ return;
324
+ }
325
+ closed = false;
326
+ signInSent = true;
327
+ await provider.request({ method: 'connect' });
328
+ }
329
+ catch (error) {
330
+ if (current()) {
331
+ // The wallet's accept callback may have connected meanwhile: drop its pending lookup and stop following it.
332
+ interrupt();
333
+ publish({ status: 'disconnected', endedBy: null, error: connectError(error) });
334
+ }
335
+ return;
336
+ }
337
+ if (!current())
338
+ return;
339
+ // Always read the account again, even when the wallet was already connected and sends no new accept callback.
340
+ await lookup(provider, context.network === undefined ? {} : { network: context.network });
341
+ }
342
+ finally {
343
+ if (own === epoch) {
344
+ signingIn = null;
345
+ signInSent = false;
346
+ }
347
+ }
348
+ },
349
+ end,
350
+ fail(error) {
351
+ if (disposed)
352
+ return;
353
+ interrupt();
354
+ publish({ status: 'disconnected', endedBy: null, error: (0, errors_1.describeWalletError)(error) });
355
+ },
356
+ isCurrent: (wallet) => !disposed && state.status === 'connected' && state.wallet === wallet,
357
+ dispose() {
358
+ if (disposed)
359
+ return;
360
+ interrupt();
361
+ disposed = true;
362
+ listeners.clear();
363
+ },
364
+ };
365
+ }
366
+ const DA_NETWORKS = ['devnet', 'mainnet'];
367
+ /** Whether `networkId` is the CIP-0103 id of a DA network other than `network`. */
368
+ function reportsOtherNetwork(networkId, network) {
369
+ return DA_NETWORKS.some((other) => other !== network && networkId === (0, cip103_1.cip103NetworkId)(other));
370
+ }
371
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/wallets/session.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,qCAA2C;AAC3C,qCAQkB;AAElB,qCAA6F;AAC7F,iCAAkC;AAsGlC,iHAAiH;AACjH,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC,MAAM,eAAe,GAAuB,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACnG,MAAM,UAAU,GAAuB,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;AAEhE,2HAA2H;AAC3H,SAAS,cAAc,CAAC,UAAmB;IACzC,MAAM,IAAI,GAAG,IAAA,eAAQ,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1E,OAAO,OAAO,IAAI,KAAK,SAA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,CAAC,MAAM,KAAK,MAAM;QAE3F,OAAO;YACL,IAAI,QAAQ;gBAAE,OAAO;YACrB,SAAS,EAAE,CAAC;YACZ,QAAQ,GAAG,IAAI,CAAC;YAChB,SAAS,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,WAAW,GAAyB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEhE,mFAAmF;AACnF,SAAS,mBAAmB,CAAC,SAAiB,EAAE,OAAkB;IAChE,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,OAAO,IAAI,SAAS,KAAK,IAAA,wBAAe,EAAC,KAAK,CAAC,CAAC,CAAC;AAChG,CAAC"}
@@ -0,0 +1,138 @@
1
+ import { type WalletErrorDescription } from './errors';
2
+ import type { Cip103Session, Cip103SessionState, ConnectedWallet } from './session';
3
+ import type { TokenStandardWallet } from './token-standard-wallet';
4
+ import { type TokenWallet, type TokenWalletState } from './token-wallet';
5
+ /** How the last action ended, for the party it ran as. */
6
+ export type ActionOutcome = {
7
+ readonly id: string;
8
+ readonly partyId: string;
9
+ readonly status: 'succeeded';
10
+ readonly message: string | null;
11
+ } | {
12
+ readonly id: string;
13
+ readonly partyId: string;
14
+ readonly status: 'failed';
15
+ readonly error: WalletErrorDescription;
16
+ }
17
+ /**
18
+ * The session ended (disconnect, wallet end, account switch) before the action settled: whether it committed is
19
+ * unknown.
20
+ */
21
+ | {
22
+ readonly id: string;
23
+ readonly partyId: string;
24
+ readonly status: 'interrupted';
25
+ };
26
+ export interface TokenWalletView<S = TokenWalletState> {
27
+ readonly session: Cip103SessionState;
28
+ /** The connected wallet the state belongs to (null when disconnected). */
29
+ readonly wallet: ConnectedWallet | null;
30
+ /**
31
+ * Ledger state from one snapshot. Null until the first load answers, and cleared when a load fails or the wallet
32
+ * changes.
33
+ */
34
+ readonly state: S | null;
35
+ /**
36
+ * A load for the current wallet is in flight, or queued behind the wallet call in flight (an action of this wallet or
37
+ * a previous one, the previous wallet's load, or the load before a Retry).
38
+ */
39
+ readonly loading: boolean;
40
+ /** The last load's failure. A rate limit has kind `rate-limited`, so offer `refresh()` after a moment. */
41
+ readonly loadError: WalletErrorDescription | null;
42
+ /** The running action's id. */
43
+ readonly running: string | null;
44
+ /**
45
+ * True while any wallet call is in flight or a load is queued: an action, or a load (the first one, a Retry, the
46
+ * reload after an action), for the current wallet or a previous one. Disable every action button. `run()` refuses
47
+ * meanwhile, so only one wallet call is ever in flight.
48
+ */
49
+ readonly busy: boolean;
50
+ /**
51
+ * The last action's outcome. A wallet change clears it, except when whether it committed is unknown (`interrupted`,
52
+ * or `failed` with kind `outcome-unknown`).
53
+ */
54
+ readonly outcome: ActionOutcome | null;
55
+ /**
56
+ * The party of a write whose outcome is unknown and is not shown as the current wallet's failure: still running for
57
+ * an ended session, `interrupted`, or an `outcome-unknown` failure of a wallet that is no longer connected.
58
+ */
59
+ readonly unknownOutcomeParty: string | null;
60
+ }
61
+ export interface WalletActionContext<W> {
62
+ /** The token wallet of `wallet`. */
63
+ readonly tokens: W;
64
+ /** The connected wallet the action runs for. */
65
+ readonly wallet: ConnectedWallet;
66
+ }
67
+ export interface TokenWalletStore<W extends TokenStandardWallet = TokenWallet> {
68
+ subscribe(listener: () => void): () => void;
69
+ /** The current view; the same object until it changes (for `useSyncExternalStore`). */
70
+ getSnapshot(): TokenWalletView<Awaited<ReturnType<W['loadState']>>>;
71
+ /**
72
+ * Reload the snapshot (the Retry button). Starts at once when no wallet call is in flight; otherwise it is queued and
73
+ * runs once that call settles (the load in flight may have read before what prompted the refresh). Queued loads are
74
+ * coalesced into one, so a refresh during a write is the reload after it. Ignored while disconnected.
75
+ */
76
+ refresh(): void;
77
+ /**
78
+ * Run one wallet call (a write, a preview, `signMessage`). Resolves false without calling `action` while busy (any
79
+ * wallet call in flight or load queued) or disconnected; the check is synchronous, so a double click is refused at
80
+ * once. Afterwards it reloads the snapshot, even when the action failed, because a failed write may have committed,
81
+ * and stays busy until that reload answers. A write that settles after its session ended records `interrupted`, never
82
+ * `succeeded` (or nothing when it was refused unsent, below). Resolves true when the action succeeded for a session
83
+ * that is still current. `action` resolves with a message to show, or nothing.
84
+ *
85
+ * `readOnly: true` marks a call that commits nothing (a preview, `signMessage`): no reload follows, and one that
86
+ * settles after its session ended records no outcome instead of `interrupted`.
87
+ *
88
+ * A `TransferPlan`, or any token wallet kept from an earlier run, is bound to the wallet session that made it: submit
89
+ * it only in a run of that same `wallet`. A token wallet the store opened (with the default `open`, or a custom one
90
+ * that passes `isActive` on) refuses every write once its `ConnectedWallet` is no longer the session's, with
91
+ * `invalid-input` and before anything is read or signed, so a plan made for one account is never submitted after the
92
+ * session switched to another. A run that is still current records that refusal as a `failed` outcome. A run whose
93
+ * session ended while it ran, and whose action rejected with a refusal (`TokenWalletError`, `describeWalletError`
94
+ * kind `refused`: nothing was submitted), records no outcome rather than `interrupted`.
95
+ */
96
+ run(id: string, action: (context: WalletActionContext<W>) => Promise<string | void>, options?: {
97
+ readonly readOnly?: boolean;
98
+ }): Promise<boolean>;
99
+ /**
100
+ * Stop following the session; pending replies are dropped, a queued load never starts and no further view is
101
+ * published.
102
+ */
103
+ dispose(): void;
104
+ }
105
+ /** What `open` gets besides the connected wallet. */
106
+ export interface OpenTokenWalletContext {
107
+ /**
108
+ * Whether `wallet` is still the session's connected wallet (`session.isCurrent(wallet)`). Pass it as the token
109
+ * wallet's `isActive`, so its writes, and the `TransferPlan`s it made, are refused once the session left `wallet`.
110
+ */
111
+ readonly isActive: () => boolean;
112
+ }
113
+ export interface TokenWalletStoreOptions<W extends TokenStandardWallet> {
114
+ readonly session: Cip103Session;
115
+ /**
116
+ * Builds the token wallet of each connected wallet. Default: `createTokenWallet({ provider, partyId, network,
117
+ * isActive })`, which needs `wallet.network` (a wallet without one gets a `refused` load error). Pass
118
+ * `context.isActive` on as the token wallet's `isActive`, as the default does, or a plan made for one wallet can
119
+ * still be submitted after the session switched to another.
120
+ */
121
+ readonly open?: (wallet: ConnectedWallet, context: OpenTokenWalletContext) => W;
122
+ }
123
+ /**
124
+ * The observable state and actions of a token wallet page over `session`. The store follows the session: each new
125
+ * `ConnectedWallet` gets its own token wallet (from `open`) and a fresh load, and its state is cleared.
126
+ *
127
+ * One wallet call at a time: an execution latch counts every call in flight (actions and loads, of the current wallet
128
+ * or a previous one, since a dropped reply does not cancel its request). `run()` refuses while it is held. A load asked
129
+ * for meanwhile (a new wallet's first load, a Retry, the reload after a write) is queued; queued loads coalesce into
130
+ * one, which runs for the wallet current when the latch frees. Ending the session drops the queued load, and so does
131
+ * `dispose()`. A wallet call that never settles holds the latch, since it cannot be cancelled. The token wallet's own
132
+ * write latch (`busy`) stays as the inner guard.
133
+ */
134
+ export declare function createTokenWalletStore(options: TokenWalletStoreOptions<TokenWallet>): TokenWalletStore<TokenWallet>;
135
+ export declare function createTokenWalletStore<W extends TokenStandardWallet>(options: TokenWalletStoreOptions<W> & {
136
+ readonly open: (wallet: ConnectedWallet, context: OpenTokenWalletContext) => W;
137
+ }): TokenWalletStore<W>;
138
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/wallets/store.ts"],"names":[],"mappings":"AASA,OAAO,EAAyC,KAAK,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACpF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAqB,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE5F,0DAA0D;AAC1D,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAA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