@openzeppelin/miden-multisig-client 0.17.0-rc.2 → 0.17.0-rc.3

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 (278) hide show
  1. package/README.md +167 -42
  2. package/dist/account/builder.d.ts +2 -2
  3. package/dist/account/builder.d.ts.map +1 -1
  4. package/dist/account/builder.js +49 -24
  5. package/dist/account/builder.js.map +1 -1
  6. package/dist/connectivity.d.ts +2 -0
  7. package/dist/connectivity.d.ts.map +1 -1
  8. package/dist/connectivity.js +7 -4
  9. package/dist/connectivity.js.map +1 -1
  10. package/dist/index.d.ts +8 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +7 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/multisig/authArgErrors.d.ts +59 -0
  15. package/dist/multisig/authArgErrors.d.ts.map +1 -0
  16. package/dist/multisig/authArgErrors.js +115 -0
  17. package/dist/multisig/authArgErrors.js.map +1 -0
  18. package/dist/multisig/helpers.d.ts +5 -0
  19. package/dist/multisig/helpers.d.ts.map +1 -1
  20. package/dist/multisig/helpers.js +7 -2
  21. package/dist/multisig/helpers.js.map +1 -1
  22. package/dist/multisig.d.ts +140 -0
  23. package/dist/multisig.d.ts.map +1 -1
  24. package/dist/multisig.js +419 -12
  25. package/dist/multisig.js.map +1 -1
  26. package/dist/procedures.d.ts +1 -1
  27. package/dist/procedures.js +1 -1
  28. package/dist/recovery/proposalNoteImport.d.ts +173 -0
  29. package/dist/recovery/proposalNoteImport.d.ts.map +1 -0
  30. package/dist/recovery/proposalNoteImport.js +411 -0
  31. package/dist/recovery/proposalNoteImport.js.map +1 -0
  32. package/dist/recovery/publicNoteBackfill.d.ts +168 -0
  33. package/dist/recovery/publicNoteBackfill.d.ts.map +1 -0
  34. package/dist/recovery/publicNoteBackfill.js +368 -0
  35. package/dist/recovery/publicNoteBackfill.js.map +1 -0
  36. package/dist/recovery/recoverNotes.d.ts +147 -0
  37. package/dist/recovery/recoverNotes.d.ts.map +1 -0
  38. package/dist/recovery/recoverNotes.js +163 -0
  39. package/dist/recovery/recoverNotes.js.map +1 -0
  40. package/dist/recovery/transportDrain.d.ts +124 -0
  41. package/dist/recovery/transportDrain.d.ts.map +1 -0
  42. package/dist/recovery/transportDrain.js +262 -0
  43. package/dist/recovery/transportDrain.js.map +1 -0
  44. package/dist/transaction/consumeNotes.d.ts.map +1 -1
  45. package/dist/transaction/consumeNotes.js +4 -1
  46. package/dist/transaction/consumeNotes.js.map +1 -1
  47. package/dist/transaction/p2id.d.ts.map +1 -1
  48. package/dist/transaction/p2id.js +4 -1
  49. package/dist/transaction/p2id.js.map +1 -1
  50. package/dist/transaction/summary.d.ts +10 -4
  51. package/dist/transaction/summary.d.ts.map +1 -1
  52. package/dist/transaction/summary.js +13 -7
  53. package/dist/transaction/summary.js.map +1 -1
  54. package/dist/transaction/updateGuardian.js +4 -1
  55. package/dist/transaction/updateGuardian.js.map +1 -1
  56. package/dist/transaction/updateProcedureThreshold.js +4 -1
  57. package/dist/transaction/updateProcedureThreshold.js.map +1 -1
  58. package/dist/transaction/updateSigners.js +4 -1
  59. package/dist/transaction/updateSigners.js.map +1 -1
  60. package/dist/transaction.d.ts +1 -1
  61. package/dist/transaction.d.ts.map +1 -1
  62. package/dist/transaction.js +1 -1
  63. package/dist/transaction.js.map +1 -1
  64. package/package.json +14 -10
  65. package/src/account/builder.ts +87 -35
  66. package/src/connectivity.ts +9 -4
  67. package/src/index.ts +34 -1
  68. package/src/multisig/authArgErrors.ts +138 -0
  69. package/src/multisig/helpers.ts +7 -2
  70. package/src/multisig.ts +513 -20
  71. package/src/procedures.ts +1 -1
  72. package/src/recovery/proposalNoteImport.ts +548 -0
  73. package/src/recovery/publicNoteBackfill.ts +502 -0
  74. package/src/recovery/recoverNotes.ts +288 -0
  75. package/src/recovery/transportDrain.ts +330 -0
  76. package/src/transaction/consumeNotes.ts +4 -1
  77. package/src/transaction/p2id.ts +4 -1
  78. package/src/transaction/summary.ts +13 -7
  79. package/src/transaction/updateGuardian.ts +4 -1
  80. package/src/transaction/updateProcedureThreshold.ts +4 -1
  81. package/src/transaction/updateSigners.ts +4 -1
  82. package/src/transaction.ts +1 -1
  83. package/dist/account/builder.test.d.ts +0 -2
  84. package/dist/account/builder.test.d.ts.map +0 -1
  85. package/dist/account/builder.test.js +0 -166
  86. package/dist/account/builder.test.js.map +0 -1
  87. package/dist/account/masm/account-components/auth.d.ts +0 -2
  88. package/dist/account/masm/account-components/auth.d.ts.map +0 -1
  89. package/dist/account/masm/account-components/auth.js +0 -46
  90. package/dist/account/masm/account-components/auth.js.map +0 -1
  91. package/dist/account/masm/index.d.ts +0 -2
  92. package/dist/account/masm/index.d.ts.map +0 -1
  93. package/dist/account/masm/index.js +0 -4
  94. package/dist/account/masm/index.js.map +0 -1
  95. package/dist/account/masm.d.ts +0 -2
  96. package/dist/account/masm.d.ts.map +0 -1
  97. package/dist/account/masm.js +0 -4
  98. package/dist/account/masm.js.map +0 -1
  99. package/dist/account/storage.test.d.ts +0 -2
  100. package/dist/account/storage.test.d.ts.map +0 -1
  101. package/dist/account/storage.test.js +0 -73
  102. package/dist/account/storage.test.js.map +0 -1
  103. package/dist/client.test.d.ts +0 -2
  104. package/dist/client.test.d.ts.map +0 -1
  105. package/dist/client.test.js +0 -380
  106. package/dist/client.test.js.map +0 -1
  107. package/dist/connectivity.test.d.ts +0 -2
  108. package/dist/connectivity.test.d.ts.map +0 -1
  109. package/dist/connectivity.test.js +0 -61
  110. package/dist/connectivity.test.js.map +0 -1
  111. package/dist/inspector.test.d.ts +0 -2
  112. package/dist/inspector.test.d.ts.map +0 -1
  113. package/dist/inspector.test.js +0 -425
  114. package/dist/inspector.test.js.map +0 -1
  115. package/dist/lookupAuth.test.d.ts +0 -2
  116. package/dist/lookupAuth.test.d.ts.map +0 -1
  117. package/dist/lookupAuth.test.js +0 -138
  118. package/dist/lookupAuth.test.js.map +0 -1
  119. package/dist/multisig/consumeNotesErrors.test.d.ts +0 -2
  120. package/dist/multisig/consumeNotesErrors.test.d.ts.map +0 -1
  121. package/dist/multisig/consumeNotesErrors.test.js +0 -28
  122. package/dist/multisig/consumeNotesErrors.test.js.map +0 -1
  123. package/dist/multisig/helpers.test.d.ts +0 -2
  124. package/dist/multisig/helpers.test.d.ts.map +0 -1
  125. package/dist/multisig/helpers.test.js +0 -94
  126. package/dist/multisig/helpers.test.js.map +0 -1
  127. package/dist/multisig.test.d.ts +0 -2
  128. package/dist/multisig.test.d.ts.map +0 -1
  129. package/dist/multisig.test.js +0 -4112
  130. package/dist/multisig.test.js.map +0 -1
  131. package/dist/proposal/factory.test.d.ts +0 -2
  132. package/dist/proposal/factory.test.d.ts.map +0 -1
  133. package/dist/proposal/factory.test.js +0 -32
  134. package/dist/proposal/factory.test.js.map +0 -1
  135. package/dist/proposal/metadata.test.d.ts +0 -2
  136. package/dist/proposal/metadata.test.d.ts.map +0 -1
  137. package/dist/proposal/metadata.test.js +0 -193
  138. package/dist/proposal/metadata.test.js.map +0 -1
  139. package/dist/prover/config.test.d.ts +0 -2
  140. package/dist/prover/config.test.d.ts.map +0 -1
  141. package/dist/prover/config.test.js +0 -54
  142. package/dist/prover/config.test.js.map +0 -1
  143. package/dist/prover/errors.test.d.ts +0 -2
  144. package/dist/prover/errors.test.d.ts.map +0 -1
  145. package/dist/prover/errors.test.js +0 -29
  146. package/dist/prover/errors.test.js.map +0 -1
  147. package/dist/prover/retry.test.d.ts +0 -2
  148. package/dist/prover/retry.test.d.ts.map +0 -1
  149. package/dist/prover/retry.test.js +0 -20
  150. package/dist/prover/retry.test.js.map +0 -1
  151. package/dist/prover/workflow.test.d.ts +0 -2
  152. package/dist/prover/workflow.test.d.ts.map +0 -1
  153. package/dist/prover/workflow.test.js +0 -105
  154. package/dist/prover/workflow.test.js.map +0 -1
  155. package/dist/raw-client.test.d.ts +0 -2
  156. package/dist/raw-client.test.d.ts.map +0 -1
  157. package/dist/raw-client.test.js +0 -111
  158. package/dist/raw-client.test.js.map +0 -1
  159. package/dist/rpc/config.test.d.ts +0 -2
  160. package/dist/rpc/config.test.d.ts.map +0 -1
  161. package/dist/rpc/config.test.js +0 -24
  162. package/dist/rpc/config.test.js.map +0 -1
  163. package/dist/rpc/errors.test.d.ts +0 -2
  164. package/dist/rpc/errors.test.d.ts.map +0 -1
  165. package/dist/rpc/errors.test.js +0 -34
  166. package/dist/rpc/errors.test.js.map +0 -1
  167. package/dist/rpc/retry.test.d.ts +0 -2
  168. package/dist/rpc/retry.test.d.ts.map +0 -1
  169. package/dist/rpc/retry.test.js +0 -98
  170. package/dist/rpc/retry.test.js.map +0 -1
  171. package/dist/signers/ecdsa.test.d.ts +0 -2
  172. package/dist/signers/ecdsa.test.d.ts.map +0 -1
  173. package/dist/signers/ecdsa.test.js +0 -88
  174. package/dist/signers/ecdsa.test.js.map +0 -1
  175. package/dist/signers/falcon.test.d.ts +0 -2
  176. package/dist/signers/falcon.test.d.ts.map +0 -1
  177. package/dist/signers/falcon.test.js +0 -161
  178. package/dist/signers/falcon.test.js.map +0 -1
  179. package/dist/signers/miden-wallet.ecdsa-recovery.test.d.ts +0 -2
  180. package/dist/signers/miden-wallet.ecdsa-recovery.test.d.ts.map +0 -1
  181. package/dist/signers/miden-wallet.ecdsa-recovery.test.js +0 -148
  182. package/dist/signers/miden-wallet.ecdsa-recovery.test.js.map +0 -1
  183. package/dist/signers/miden-wallet.test.d.ts +0 -2
  184. package/dist/signers/miden-wallet.test.d.ts.map +0 -1
  185. package/dist/signers/miden-wallet.test.js +0 -164
  186. package/dist/signers/miden-wallet.test.js.map +0 -1
  187. package/dist/signers/para.test.d.ts +0 -2
  188. package/dist/signers/para.test.d.ts.map +0 -1
  189. package/dist/signers/para.test.js +0 -146
  190. package/dist/signers/para.test.js.map +0 -1
  191. package/dist/transaction/index.d.ts +0 -8
  192. package/dist/transaction/index.d.ts.map +0 -1
  193. package/dist/transaction/index.js +0 -7
  194. package/dist/transaction/index.js.map +0 -1
  195. package/dist/transaction/p2id.test.d.ts +0 -2
  196. package/dist/transaction/p2id.test.d.ts.map +0 -1
  197. package/dist/transaction/p2id.test.js +0 -246
  198. package/dist/transaction/p2id.test.js.map +0 -1
  199. package/dist/transaction/rpoRandomCoin.test.d.ts +0 -2
  200. package/dist/transaction/rpoRandomCoin.test.d.ts.map +0 -1
  201. package/dist/transaction/rpoRandomCoin.test.js +0 -52
  202. package/dist/transaction/rpoRandomCoin.test.js.map +0 -1
  203. package/dist/transaction/summary.test.d.ts +0 -2
  204. package/dist/transaction/summary.test.d.ts.map +0 -1
  205. package/dist/transaction/summary.test.js +0 -26
  206. package/dist/transaction/summary.test.js.map +0 -1
  207. package/dist/transaction.test.d.ts +0 -2
  208. package/dist/transaction.test.d.ts.map +0 -1
  209. package/dist/transaction.test.js +0 -122
  210. package/dist/transaction.test.js.map +0 -1
  211. package/dist/types/proposal.test.d.ts +0 -2
  212. package/dist/types/proposal.test.d.ts.map +0 -1
  213. package/dist/types/proposal.test.js +0 -56
  214. package/dist/types/proposal.test.js.map +0 -1
  215. package/dist/utils/digest.test.d.ts +0 -2
  216. package/dist/utils/digest.test.d.ts.map +0 -1
  217. package/dist/utils/digest.test.js +0 -48
  218. package/dist/utils/digest.test.js.map +0 -1
  219. package/dist/utils/ecdsa.test.d.ts +0 -2
  220. package/dist/utils/ecdsa.test.d.ts.map +0 -1
  221. package/dist/utils/ecdsa.test.js +0 -131
  222. package/dist/utils/ecdsa.test.js.map +0 -1
  223. package/dist/utils/encoding.test.d.ts +0 -2
  224. package/dist/utils/encoding.test.d.ts.map +0 -1
  225. package/dist/utils/encoding.test.js +0 -185
  226. package/dist/utils/encoding.test.js.map +0 -1
  227. package/dist/utils/key.test.d.ts +0 -2
  228. package/dist/utils/key.test.d.ts.map +0 -1
  229. package/dist/utils/key.test.js +0 -82
  230. package/dist/utils/key.test.js.map +0 -1
  231. package/dist/utils/signature.test.d.ts +0 -2
  232. package/dist/utils/signature.test.d.ts.map +0 -1
  233. package/dist/utils/signature.test.js +0 -164
  234. package/dist/utils/signature.test.js.map +0 -1
  235. package/dist/utils/word.test.d.ts +0 -2
  236. package/dist/utils/word.test.d.ts.map +0 -1
  237. package/dist/utils/word.test.js +0 -54
  238. package/dist/utils/word.test.js.map +0 -1
  239. package/masm/account_components/auth/guarded_multisig.masm +0 -42
  240. package/src/account/builder.test.ts +0 -238
  241. package/src/account/masm/account-components/auth.ts +0 -46
  242. package/src/account/masm/index.ts +0 -4
  243. package/src/account/masm.ts +0 -4
  244. package/src/account/storage.test.ts +0 -90
  245. package/src/client.test.ts +0 -473
  246. package/src/connectivity.test.ts +0 -67
  247. package/src/inspector.test.ts +0 -542
  248. package/src/lookupAuth.test.ts +0 -185
  249. package/src/multisig/consumeNotesErrors.test.ts +0 -43
  250. package/src/multisig/helpers.test.ts +0 -114
  251. package/src/multisig.test.ts +0 -5008
  252. package/src/proposal/factory.test.ts +0 -40
  253. package/src/proposal/metadata.test.ts +0 -235
  254. package/src/prover/config.test.ts +0 -90
  255. package/src/prover/errors.test.ts +0 -61
  256. package/src/prover/retry.test.ts +0 -38
  257. package/src/prover/workflow.test.ts +0 -145
  258. package/src/raw-client.test.ts +0 -171
  259. package/src/rpc/config.test.ts +0 -45
  260. package/src/rpc/errors.test.ts +0 -69
  261. package/src/rpc/retry.test.ts +0 -144
  262. package/src/signers/ecdsa.test.ts +0 -111
  263. package/src/signers/falcon.test.ts +0 -197
  264. package/src/signers/miden-wallet.ecdsa-recovery.test.ts +0 -201
  265. package/src/signers/miden-wallet.test.ts +0 -206
  266. package/src/signers/para.test.ts +0 -186
  267. package/src/transaction/index.ts +0 -13
  268. package/src/transaction/p2id.test.ts +0 -371
  269. package/src/transaction/rpoRandomCoin.test.ts +0 -64
  270. package/src/transaction/summary.test.ts +0 -32
  271. package/src/transaction.test.ts +0 -142
  272. package/src/types/proposal.test.ts +0 -68
  273. package/src/utils/digest.test.ts +0 -55
  274. package/src/utils/ecdsa.test.ts +0 -164
  275. package/src/utils/encoding.test.ts +0 -233
  276. package/src/utils/key.test.ts +0 -91
  277. package/src/utils/signature.test.ts +0 -210
  278. package/src/utils/word.test.ts +0 -64
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Wallet-facing orchestration of the note-recovery primitives.
3
+ *
4
+ * After key-based recovery the local Miden store starts empty (or, in a
5
+ * shared store, its global cursors may already be past this account's
6
+ * notes). Each recovery primitive rescans one source normal forward sync
7
+ * would skip: the private-note transport backlog, the notes embedded in
8
+ * pending consume-notes proposals, and the chain's historical public notes
9
+ * for the account's tag. `Multisig.recoverNotes` runs them as a single flow
10
+ * and finishes with a normal sync so recovered notes are verified and ready
11
+ * to consume.
12
+ *
13
+ * The TS counterpart of the Rust SDK's `MultisigClient::recover_notes`,
14
+ * with matching semantics and report shape.
15
+ */
16
+ import { errorMessage } from '../connectivity.js';
17
+ import { RecoveryCancelledError } from './proposalNoteImport.js';
18
+ import { BackfillRangeError } from './publicNoteBackfill.js';
19
+ /**
20
+ * The guardian-switch slice of {@link RecoverNotesOptions}: only the
21
+ * proposal-embedded note import runs. Internal — the public entry point is
22
+ * `Multisig.preservePreSwitchProposalNotes`, which adds the switch-specific
23
+ * safety contract (timeout, cancellation, warnings) around this slice. The
24
+ * `satisfies` clause forces every non-range option to be listed, so adding
25
+ * a recovery strategy fails to compile until the switch path decides on it.
26
+ */
27
+ export const GUARDIAN_SWITCH_RECOVERY_OPTIONS = {
28
+ transportDrain: false,
29
+ proposalImport: true,
30
+ publicBackfill: false,
31
+ syncAfter: false,
32
+ };
33
+ function countImported(outcomes) {
34
+ return outcomes.filter((o) => o.status === 'imported').length;
35
+ }
36
+ /**
37
+ * Runs the enabled recovery strategies in order — transport drain, proposal
38
+ * import, public backfill, final sync — folding each strategy-level throw
39
+ * into a {@link RecoveryStepProblem} so no step failure aborts the flow.
40
+ *
41
+ * The optional `cancelled` token makes the run cooperatively cancellable:
42
+ * the orchestrator checks it before each step, and a
43
+ * {@link RecoveryCancelledError} from inside a step is recorded as one
44
+ * non-retryable problem on the interrupted step, after which no further
45
+ * step runs — cancellation never masquerades as a GUARDIAN or node outage.
46
+ *
47
+ * Throws only for an inverted backfill range (a caller error). See
48
+ * `Multisig.recoverNotes` for the wallet-facing entry point.
49
+ */
50
+ export async function runNoteRecovery(options, steps, cancelled) {
51
+ if (options.fromBlock !== undefined &&
52
+ options.toBlock !== undefined &&
53
+ options.fromBlock > options.toBlock) {
54
+ throw new Error(`backfill range is inverted: fromBlock ${options.fromBlock} > toBlock ${options.toBlock}`);
55
+ }
56
+ const report = {
57
+ problems: [],
58
+ synced: false,
59
+ imported: 0,
60
+ retryable: false,
61
+ };
62
+ // Set once a cancellation is observed (token flipped, or a
63
+ // RecoveryCancelledError surfaced from a step): the remaining steps are
64
+ // skipped and exactly one problem records the interruption point.
65
+ let stopped = false;
66
+ const interrupted = (step, err) => {
67
+ if (!(err instanceof RecoveryCancelledError)) {
68
+ return false;
69
+ }
70
+ report.problems.push({ step, reason: errorMessage(err), retryable: false });
71
+ stopped = true;
72
+ return true;
73
+ };
74
+ const startStep = (step) => {
75
+ if (stopped) {
76
+ return false;
77
+ }
78
+ if (cancelled?.()) {
79
+ report.problems.push({
80
+ step,
81
+ reason: 'note recovery stopped before completion by its caller',
82
+ retryable: false,
83
+ });
84
+ stopped = true;
85
+ return false;
86
+ }
87
+ return true;
88
+ };
89
+ if (options.transportDrain !== false && startStep('transport-drain')) {
90
+ try {
91
+ report.transport = await steps.transportDrain();
92
+ }
93
+ catch (err) {
94
+ if (!interrupted('transport-drain', err)) {
95
+ // The drain's contract: a throw means the local store itself failed,
96
+ // which a rerun is unlikely to fix.
97
+ report.problems.push({
98
+ step: 'transport-drain',
99
+ reason: errorMessage(err),
100
+ retryable: false,
101
+ });
102
+ }
103
+ }
104
+ }
105
+ if (options.proposalImport !== false && startStep('proposal-import')) {
106
+ try {
107
+ report.proposalImport = await steps.proposalImport();
108
+ }
109
+ catch (err) {
110
+ if (!interrupted('proposal-import', err)) {
111
+ report.problems.push({
112
+ step: 'proposal-import',
113
+ reason: `failed to list pending proposals: ${errorMessage(err)}`,
114
+ retryable: true,
115
+ });
116
+ }
117
+ }
118
+ }
119
+ if (options.publicBackfill !== false && startStep('public-backfill')) {
120
+ try {
121
+ report.backfill = await steps.publicBackfill();
122
+ }
123
+ catch (err) {
124
+ if (!interrupted('public-backfill', err)) {
125
+ // With the fully-explicit range validated above, a throw here is
126
+ // normally the chain-tip lookup (a node RPC failure, worth retrying);
127
+ // an invalid range against the resolved tip is a caller error and is
128
+ // not — mirroring the Rust orchestrator's `InvalidConfig` check.
129
+ report.problems.push({
130
+ step: 'public-backfill',
131
+ reason: errorMessage(err),
132
+ retryable: !(err instanceof BackfillRangeError),
133
+ });
134
+ }
135
+ }
136
+ }
137
+ if (options.syncAfter !== false && startStep('sync')) {
138
+ try {
139
+ await steps.sync();
140
+ report.synced = true;
141
+ }
142
+ catch (err) {
143
+ if (!interrupted('sync', err)) {
144
+ report.problems.push({
145
+ step: 'sync',
146
+ reason: `recovery imports succeeded but the verifying sync failed; rerun a sync: ${errorMessage(err)}`,
147
+ retryable: true,
148
+ });
149
+ }
150
+ }
151
+ }
152
+ report.imported =
153
+ (report.transport?.imported ?? 0) +
154
+ countImported(report.proposalImport ?? []) +
155
+ countImported(report.backfill?.outcomes ?? []);
156
+ report.retryable =
157
+ report.problems.some((p) => p.retryable) ||
158
+ report.transport?.retryable === true ||
159
+ (report.proposalImport ?? []).some((o) => o.retryable) ||
160
+ report.backfill?.retryable === true;
161
+ return report;
162
+ }
163
+ //# sourceMappingURL=recoverNotes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recoverNotes.js","sourceRoot":"","sources":["../../src/recovery/recoverNotes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAA6B,MAAM,yBAAyB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,CAAC;IACH,CAAC;IAED,MAAM,CAAC,QAAQ;QACb,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,IAAI,CAAC,CAAC;YACjC,aAAa,CAAC,MAAM,CAAC,cAAc,IAAI,EAAE,CAAC;YAC1C,aAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;IACjD,MAAM,CAAC,SAAS;QACd,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;YACxC,MAAM,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI;YACpC,CAAC,MAAM,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;YACtD,MAAM,CAAC,QAAQ,EAAE,SAAS,KAAK,IAAI,CAAC;IAEtC,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Recovery primitives for restoring note state after device loss.
3
+ *
4
+ * After recovery on a fresh device the local store has no note-transport
5
+ * cursor — and in a shared dirty store another account's sync may have
6
+ * advanced the cursor past notes belonging to the newly recovered account.
7
+ * The primitives here rescan sources that normal forward sync would skip.
8
+ */
9
+ import type { MidenClient } from '@miden-sdk/miden-sdk';
10
+ /**
11
+ * Outcome class of a private-note transport backlog drain:
12
+ * - `completed` — the full transport backlog was scanned; every note the
13
+ * transport still holds for the tracked tags is now in the local store.
14
+ * - `unavailable` — the transport could not be consulted at all: it is
15
+ * disabled for the injected `MidenClient` (no `noteTransportUrl`
16
+ * configured) or unreachable before anything was imported (`imported` is
17
+ * always 0 — a connection lost mid-drain after partial progress reports
18
+ * `failed` instead). The rest of a recovery flow should proceed without
19
+ * transport notes.
20
+ * - `failed` — the drain started but did not finish; the backlog may be
21
+ * partially imported. `retryable` distinguishes transient failures (rerun
22
+ * the drain) from permanent ones.
23
+ */
24
+ export type TransportRecoveryStatus = 'completed' | 'unavailable' | 'failed';
25
+ /**
26
+ * Result of {@link drainPrivateNoteBacklog}.
27
+ *
28
+ * Transport problems are reported here rather than thrown so a transport
29
+ * failure never aborts the rest of a recovery flow.
30
+ */
31
+ export interface TransportRecoveryReport {
32
+ /** Outcome class of the drain. */
33
+ status: TransportRecoveryStatus;
34
+ /**
35
+ * Number of note records newly imported into the local store by this
36
+ * drain. Can be non-zero even on `failed`: batches imported before the
37
+ * failure stay imported.
38
+ */
39
+ imported: number;
40
+ /**
41
+ * Whether rerunning the drain can plausibly succeed (transient
42
+ * connectivity failures, the upstream pagination convergence guard).
43
+ * Always `false` on `completed`.
44
+ */
45
+ retryable: boolean;
46
+ /** Human-readable cause when the drain did not complete. */
47
+ reason?: string;
48
+ }
49
+ /**
50
+ * The WASM client surfaces the upstream transport errors as plain messages,
51
+ * so the message text is the only stable join key (same approach as
52
+ * `connectivity.ts`). These fragments come from miden-client's
53
+ * `NoteTransportError` `Display` impls.
54
+ */
55
+ /** Exported for the drift-guard test, which pins them against the shipped WASM binary. */
56
+ export declare const TRANSPORT_DISABLED_FRAGMENT = "note transport is disabled";
57
+ /** Exported for the drift-guard test, which pins them against the shipped WASM binary. */
58
+ export declare const PAGINATION_GUARD_FRAGMENT = "did not converge";
59
+ /**
60
+ * `NoteTransportError::Network`'s Display prefix — the transport service
61
+ * answered with an error. Exported for the drift-guard test.
62
+ */
63
+ export declare const TRANSPORT_NETWORK_FRAGMENT = "note transport network error";
64
+ /**
65
+ * `NoteTransportError::Connection`'s Display prefix — endpoint parsing, TLS
66
+ * configuration, and actual connect failures, indiscriminately. Exported for
67
+ * the drift-guard test.
68
+ */
69
+ export declare const TRANSPORT_CONNECTION_FRAGMENT = "connection error";
70
+ /**
71
+ * `RpcError::RequestError`'s Display prefix — a NODE RPC failure (each
72
+ * fetched batch is imported through the node, so this is a mid-drain import
73
+ * failure, not a transport outage). Exported for the drift-guard test.
74
+ */
75
+ export declare const NODE_RPC_FRAGMENT = "grpc request failed";
76
+ /**
77
+ * `RpcError::ConnectionError`'s Display text — the NODE could not be
78
+ * reached at all, which mid-drain is the same interrupted-import class as
79
+ * {@link NODE_RPC_FRAGMENT}. Exported for the drift-guard test.
80
+ */
81
+ export declare const NODE_CONNECT_FRAGMENT = "failed to connect to the Miden node";
82
+ /**
83
+ * The covered-tags bookkeeping key, mirror of miden-client's
84
+ * `NOTE_TRANSPORT_COVERED_TAGS_KEY` (the JS surface does not re-export it).
85
+ * Exported for the drift-guard test, which pins it against the shipped WASM
86
+ * binary so a silent upstream rename cannot degrade the drain to a no-op.
87
+ */
88
+ export declare const NOTE_TRANSPORT_COVERED_TAGS_KEY = "note_transport_covered_tags";
89
+ /**
90
+ * `ClientError::StoreError`'s Display prefix in the WASM error chain.
91
+ * Exported for the drift-guard test, which pins it against the shipped WASM
92
+ * binary.
93
+ */
94
+ export declare const STORE_ERROR_FRAGMENT = "storage error";
95
+ /**
96
+ * Rescans the full private-note transport backlog for every tracked note tag
97
+ * and imports what it finds, regardless of the stored transport
98
+ * cursor. Counterpart of `MultisigClient::drain_private_note_backlog`
99
+ * in the Rust SDK; the WASM boundary exposes only error message text, so
100
+ * failure classification here is message-based, keyed on the upstream
101
+ * Display prefixes pinned by the drift-guard test.
102
+ *
103
+ * Use after account recovery, passing the **same** `MidenClient` instance
104
+ * that was injected into `MultisigClient`: a fresh store has no transport
105
+ * cursor, and in a shared store another account's sync may have advanced the
106
+ * cursor past this account's notes. The drain is idempotent, tag-scoped (the
107
+ * recovered account must already be in the store so its note tag is tracked
108
+ * — `MultisigClient.load` does this), and never regresses an
109
+ * already-advanced cursor.
110
+ *
111
+ * Transport recovery is bounded by the transport service's retention:
112
+ * senders may bypass the transport entirely and relayed blobs are pruned
113
+ * after the retention window, so this is a best-effort rescan, **not** a
114
+ * backup. Transport-disabled and transport-unreachable outcomes are reported
115
+ * in the {@link TransportRecoveryReport} rather than thrown; this function
116
+ * only throws when the local store itself fails.
117
+ *
118
+ * The rescan runs as many transport syncs as the upstream per-sync tag
119
+ * backfill cap requires to cover every tracked tag, and a failed drain
120
+ * restores the pre-drain covered-tags bookkeeping so normal sync keeps
121
+ * working exactly as it did before the attempt.
122
+ */
123
+ export declare function drainPrivateNoteBacklog(midenClient: MidenClient): Promise<TransportRecoveryReport>;
124
+ //# sourceMappingURL=transportDrain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transportDrain.d.ts","sourceRoot":"","sources":["../../src/recovery/transportDrain.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIxD;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,aAAa,GAAG,QAAQ,CAAC;AAE7E;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,kCAAkC;IAClC,MAAM,EAAE,uBAAuB,CAAC;IAChC;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,SAAS,EAAE,OAAO,CAAC;IACnB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,0FAA0F;AAC1F,eAAO,MAAM,2BAA2B,+BAA+B,CAAC;AACxE,0FAA0F;AAC1F,eAAO,MAAM,yBAAyB,qBAAqB,CAAC;AAC5D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,iCAAiC,CAAC;AACzE;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,qBAAqB,CAAC;AAChE;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,wBAAwB,CAAC;AACvD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,wCAAwC,CAAC;AAC3E;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,gCAAgC,CAAC;AAgB7E;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AAoHpD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,uBAAuB,CAAC,CAqElC"}
@@ -0,0 +1,262 @@
1
+ /**
2
+ * Recovery primitives for restoring note state after device loss.
3
+ *
4
+ * After recovery on a fresh device the local store has no note-transport
5
+ * cursor — and in a shared dirty store another account's sync may have
6
+ * advanced the cursor past notes belonging to the newly recovered account.
7
+ * The primitives here rescan sources that normal forward sync would skip.
8
+ */
9
+ import { errorMessage, isLikelyNetworkError } from '../connectivity.js';
10
+ import { isTransientRpcError } from '../rpc/errors.js';
11
+ /**
12
+ * The WASM client surfaces the upstream transport errors as plain messages,
13
+ * so the message text is the only stable join key (same approach as
14
+ * `connectivity.ts`). These fragments come from miden-client's
15
+ * `NoteTransportError` `Display` impls.
16
+ */
17
+ /** Exported for the drift-guard test, which pins them against the shipped WASM binary. */
18
+ export const TRANSPORT_DISABLED_FRAGMENT = 'note transport is disabled';
19
+ /** Exported for the drift-guard test, which pins them against the shipped WASM binary. */
20
+ export const PAGINATION_GUARD_FRAGMENT = 'did not converge';
21
+ /**
22
+ * `NoteTransportError::Network`'s Display prefix — the transport service
23
+ * answered with an error. Exported for the drift-guard test.
24
+ */
25
+ export const TRANSPORT_NETWORK_FRAGMENT = 'note transport network error';
26
+ /**
27
+ * `NoteTransportError::Connection`'s Display prefix — endpoint parsing, TLS
28
+ * configuration, and actual connect failures, indiscriminately. Exported for
29
+ * the drift-guard test.
30
+ */
31
+ export const TRANSPORT_CONNECTION_FRAGMENT = 'connection error';
32
+ /**
33
+ * `RpcError::RequestError`'s Display prefix — a NODE RPC failure (each
34
+ * fetched batch is imported through the node, so this is a mid-drain import
35
+ * failure, not a transport outage). Exported for the drift-guard test.
36
+ */
37
+ export const NODE_RPC_FRAGMENT = 'grpc request failed';
38
+ /**
39
+ * `RpcError::ConnectionError`'s Display text — the NODE could not be
40
+ * reached at all, which mid-drain is the same interrupted-import class as
41
+ * {@link NODE_RPC_FRAGMENT}. Exported for the drift-guard test.
42
+ */
43
+ export const NODE_CONNECT_FRAGMENT = 'failed to connect to the Miden node';
44
+ /**
45
+ * The covered-tags bookkeeping key, mirror of miden-client's
46
+ * `NOTE_TRANSPORT_COVERED_TAGS_KEY` (the JS surface does not re-export it).
47
+ * Exported for the drift-guard test, which pins it against the shipped WASM
48
+ * binary so a silent upstream rename cannot degrade the drain to a no-op.
49
+ */
50
+ export const NOTE_TRANSPORT_COVERED_TAGS_KEY = 'note_transport_covered_tags';
51
+ /**
52
+ * Mirror of miden-client's `Client::MAX_BACKFILL_TAGS_PER_SYNC`: upstream
53
+ * backfills at most this many uncovered tags per transport sync, deferring
54
+ * the remainder to the next sync.
55
+ */
56
+ const MAX_BACKFILL_TAGS_PER_SYNC = 64;
57
+ /**
58
+ * Mirror of the Rust SDK's `CONNECT_PERMANENT_SIGNALS`: connection-failure
59
+ * wording a retry cannot fix (misconfigured endpoint, TLS/certificate
60
+ * problems). Everything else connection-shaped is the peer-still-booting
61
+ * case and stays retryable.
62
+ */
63
+ const CONNECT_PERMANENT_SIGNALS = ['certificate', 'tls', 'invalid uri', 'unsupported scheme'];
64
+ /**
65
+ * `ClientError::StoreError`'s Display prefix in the WASM error chain.
66
+ * Exported for the drift-guard test, which pins it against the shipped WASM
67
+ * binary.
68
+ */
69
+ export const STORE_ERROR_FRAGMENT = 'storage error';
70
+ /**
71
+ * IndexedDB/Dexie error names that mean the local store itself failed —
72
+ * these must reject (matching the Rust `StoreError` branch), never be folded
73
+ * into a transport report.
74
+ */
75
+ const STORE_ERROR_NAMES = ['QuotaExceededError', 'DatabaseClosedError', 'ReadOnlyError', 'TransactionInactiveError'];
76
+ /**
77
+ * Does this failure mean the local store is broken (as opposed to a
78
+ * transport/node problem)? Kept deliberately narrow: `AbortError` counts
79
+ * only when its message points at an IndexedDB transaction/database abort —
80
+ * network requests also abort, and those stay transport-classified.
81
+ */
82
+ function isLocalStoreError(err) {
83
+ const message = errorMessage(err);
84
+ const lower = message.toLowerCase();
85
+ if (lower.includes(STORE_ERROR_FRAGMENT))
86
+ return true;
87
+ const name = typeof err === 'object' && err !== null && 'name' in err && typeof err.name === 'string'
88
+ ? err.name
89
+ : undefined;
90
+ if (name !== undefined && STORE_ERROR_NAMES.includes(name))
91
+ return true;
92
+ // The WASM bridge may stringify the underlying store error into the
93
+ // message rather than preserving the name.
94
+ if (STORE_ERROR_NAMES.some((storeName) => message.includes(storeName)))
95
+ return true;
96
+ if (name === 'AbortError' && (lower.includes('transaction') || lower.includes('database'))) {
97
+ return true;
98
+ }
99
+ return false;
100
+ }
101
+ function classifyDrainFailure(err) {
102
+ const reason = errorMessage(err);
103
+ const lower = reason.toLowerCase();
104
+ // No transport configured — retrying cannot help until the MidenClient is
105
+ // rebuilt with a `noteTransportUrl`. Thrown before anything is fetched.
106
+ if (lower.includes(TRANSPORT_DISABLED_FRAGMENT)) {
107
+ return { status: 'unavailable', retryable: false, reason, scanned: false };
108
+ }
109
+ // The upstream convergence guard tripped (the server cursor kept advancing
110
+ // for 1000 iterations without an empty batch) — a server-side bug, not an
111
+ // honest backlog. Retryable in the sense that a rerun is safe (imports are
112
+ // idempotent) and succeeds once the server recovers.
113
+ if (lower.includes(PAGINATION_GUARD_FRAGMENT)) {
114
+ return { status: 'failed', retryable: true, reason, scanned: true };
115
+ }
116
+ // A NODE RPC failure: each fetched batch is imported through the node
117
+ // (inclusion-proof lookup), so this interrupted the drain mid-way — the
118
+ // transport itself was reachable. Mirrors the Rust `ClientError::RpcError`
119
+ // arm: report `failed`, with the shared RPC classifier deciding whether a
120
+ // rerun can help.
121
+ if (lower.includes(NODE_RPC_FRAGMENT) || lower.includes(NODE_CONNECT_FRAGMENT.toLowerCase())) {
122
+ return { status: 'failed', retryable: isTransientRpcError(err), reason, scanned: true };
123
+ }
124
+ // The transport answered with an error — worth retrying once the service
125
+ // recovers.
126
+ if (lower.includes(TRANSPORT_NETWORK_FRAGMENT)) {
127
+ return { status: 'unavailable', retryable: true, reason, scanned: true };
128
+ }
129
+ // `Connection` wraps endpoint parsing, TLS configuration, and actual
130
+ // connect failures indiscriminately; permanent wording (mirroring the Rust
131
+ // SDK's cause-chain classifier) must not tell a recovery flow to loop
132
+ // retrying a client that can never connect.
133
+ if (lower.includes(TRANSPORT_CONNECTION_FRAGMENT)) {
134
+ const permanent = CONNECT_PERMANENT_SIGNALS.some((signal) => lower.includes(signal));
135
+ return { status: 'unavailable', retryable: !permanent, reason, scanned: true };
136
+ }
137
+ // Remaining connectivity-shaped wording (e.g. a raw fetch failure): the
138
+ // transport could not be reached; worth retrying once connectivity
139
+ // returns.
140
+ if (isLikelyNetworkError(err)) {
141
+ return { status: 'unavailable', retryable: true, reason, scanned: true };
142
+ }
143
+ return { status: 'failed', retryable: false, reason, scanned: true };
144
+ }
145
+ /**
146
+ * Restores the covered-tags value after a failed drain: returning it to its
147
+ * pre-drain state keeps a client that synced fine before the attempt
148
+ * syncing fine after it. Unlike the Rust twin — which merges the snapshot
149
+ * with whatever the interrupted backfill re-covered — this restores the
150
+ * snapshot verbatim (the WASM surface exposes the set only as an opaque
151
+ * value); at worst the next successful drain re-covers tags the failed
152
+ * attempt already handled, which is idempotent. A failed restoring write
153
+ * throws: the store is left with its bookkeeping cleared and subsequent
154
+ * normal syncs may re-drain (and re-fail on) old history — a local-store
155
+ * environment failure the caller must not fold into a transport report.
156
+ */
157
+ async function restoreCoveredTags(midenClient, snapshot, drainReason) {
158
+ if (snapshot === null || snapshot === undefined)
159
+ return;
160
+ try {
161
+ await midenClient.settings.set(NOTE_TRANSPORT_COVERED_TAGS_KEY, snapshot);
162
+ }
163
+ catch (restoreError) {
164
+ throw new Error(`the transport drain failed (${drainReason}) and restoring the covered-tags bookkeeping also failed (${errorMessage(restoreError)}); subsequent syncs may re-drain old transport history`);
165
+ }
166
+ }
167
+ /**
168
+ * Rescans the full private-note transport backlog for every tracked note tag
169
+ * and imports what it finds, regardless of the stored transport
170
+ * cursor. Counterpart of `MultisigClient::drain_private_note_backlog`
171
+ * in the Rust SDK; the WASM boundary exposes only error message text, so
172
+ * failure classification here is message-based, keyed on the upstream
173
+ * Display prefixes pinned by the drift-guard test.
174
+ *
175
+ * Use after account recovery, passing the **same** `MidenClient` instance
176
+ * that was injected into `MultisigClient`: a fresh store has no transport
177
+ * cursor, and in a shared store another account's sync may have advanced the
178
+ * cursor past this account's notes. The drain is idempotent, tag-scoped (the
179
+ * recovered account must already be in the store so its note tag is tracked
180
+ * — `MultisigClient.load` does this), and never regresses an
181
+ * already-advanced cursor.
182
+ *
183
+ * Transport recovery is bounded by the transport service's retention:
184
+ * senders may bypass the transport entirely and relayed blobs are pruned
185
+ * after the retention window, so this is a best-effort rescan, **not** a
186
+ * backup. Transport-disabled and transport-unreachable outcomes are reported
187
+ * in the {@link TransportRecoveryReport} rather than thrown; this function
188
+ * only throws when the local store itself fails.
189
+ *
190
+ * The rescan runs as many transport syncs as the upstream per-sync tag
191
+ * backfill cap requires to cover every tracked tag, and a failed drain
192
+ * restores the pre-drain covered-tags bookkeeping so normal sync keeps
193
+ * working exactly as it did before the attempt.
194
+ */
195
+ export async function drainPrivateNoteBacklog(midenClient) {
196
+ const before = (await midenClient.notes.list()).length;
197
+ // Records are never removed by a drain, so the length delta is the count
198
+ // of newly imported records. Caveat: it is a store delta — notes imported
199
+ // by concurrent activity on the same store (a background sync, another
200
+ // tab) during the drain are attributed to it.
201
+ const importedSince = async () => Math.max((await midenClient.notes.list()).length - before, 0);
202
+ // Snapshot the covered-tags value before clearing it: the clear is
203
+ // durable, and upstream re-marks a tag covered only after its backfill
204
+ // succeeds — so without a restore, a drain that fails on a tag with a
205
+ // permanently bad relay blob would leave every tag uncovered and make
206
+ // every subsequent normal sync re-attempt (and fail) the same backfill.
207
+ // Store errors here propagate like the count above.
208
+ const coveredSnapshot = await midenClient.settings.get(NOTE_TRANSPORT_COVERED_TAGS_KEY);
209
+ let cleared = false;
210
+ try {
211
+ // The incremental fetch doubles as the transport probe: miden-sdk 0.16's
212
+ // syncNoteTransport silently no-ops when the transport is disabled, but
213
+ // this drain must report `unavailable`, and fetchPrivate still throws
214
+ // the upstream disabled error.
215
+ await midenClient.notes.fetchPrivate();
216
+ // miden-sdk 0.16 replaced the explicit full drain with covered-tag
217
+ // bookkeeping inside syncNoteTransport: every tag not yet marked covered
218
+ // is drained from the start with a local cursor (the global cursor is
219
+ // never regressed), then the steady-state fetch runs. Clearing the
220
+ // covered-tags marker first forces that full per-tag re-drain — exactly
221
+ // the recovery semantic this primitive promises. Imports dedupe, so
222
+ // re-draining already-seen history is harmless.
223
+ await midenClient.settings.remove(NOTE_TRANSPORT_COVERED_TAGS_KEY);
224
+ cleared = true;
225
+ // Upstream backfills at most `MAX_BACKFILL_TAGS_PER_SYNC` uncovered tags
226
+ // per sync, so run enough passes to cover every tracked tag before
227
+ // reporting the backlog fully scanned.
228
+ const tagCount = (await midenClient.tags.list()).length;
229
+ const passes = Math.max(1, Math.ceil(tagCount / MAX_BACKFILL_TAGS_PER_SYNC));
230
+ for (let pass = 0; pass < passes; pass += 1) {
231
+ await midenClient.syncNoteTransport();
232
+ }
233
+ }
234
+ catch (err) {
235
+ // A broken local store is an environment failure, not a transport
236
+ // outcome: the whole recovery flow needs to know, so it propagates
237
+ // (matching the Rust `StoreError` branch) instead of being folded into
238
+ // the report.
239
+ if (isLocalStoreError(err)) {
240
+ throw err;
241
+ }
242
+ const { status, retryable, reason, scanned } = classifyDrainFailure(err);
243
+ if (cleared) {
244
+ await restoreCoveredTags(midenClient, coveredSnapshot, reason);
245
+ }
246
+ // Count even when the drain failed: each fetched batch is imported as it
247
+ // arrives, so notes recovered before the failure stay in the store. A
248
+ // disabled transport throws before fetching anything, so skip the
249
+ // re-count entirely.
250
+ const imported = scanned ? await importedSince() : 0;
251
+ if (status === 'unavailable' && imported > 0) {
252
+ // `unavailable` promises "nothing was imported"; a connection lost
253
+ // mid-drain after partial progress is an interrupted drain, so report
254
+ // it as a failure — keeping the classified retryability, like the
255
+ // Rust twin.
256
+ return { status: 'failed', imported, retryable, reason };
257
+ }
258
+ return { status, imported, retryable, reason };
259
+ }
260
+ return { status: 'completed', imported: await importedSince(), retryable: false };
261
+ }
262
+ //# sourceMappingURL=transportDrain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transportDrain.js","sourceRoot":"","sources":["../../src/recovery/transportDrain.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AA2CvD;;;;;GAKG;AACH,0FAA0F;AAC1F,MAAM,CAAC,MAAM,2BAA2B,GAAG,4BAA4B,CAAC;AACxE,0FAA0F;AAC1F,MAAM,CAAC,MAAM,yBAAyB,GAAG,kBAAkB,CAAC;AAC5D;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,8BAA8B,CAAC;AACzE;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,kBAAkB,CAAC;AAChE;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AACvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,qCAAqC,CAAC;AAC3E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,6BAA6B,CAAC;AAE7E;;;;GAIG;AACH,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,yBAAyB,GAAG,CAAC,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,oBAAoB,CAAC,CAAC;AAC9F;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAEpD;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,CAAC,oBAAoB,EAAE,qBAAqB,EAAE,eAAe,EAAE,0BAA0B,CAAC,CAAC;AAErH;;;;;GAKG;AACH,SAAS,iBAAiB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IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC;AACxD,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC"}
1
+ {"version":3,"file":"consumeNotes.d.ts","sourceRoot":"","sources":["../../src/transaction/consumeNotes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,IAAI,EACJ,kBAAkB,EAClB,aAAa,EACb,IAAI,EACL,MAAM,sBAAsB,CAAC;AAW9B,OAAO,KAAK,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAElF;;;GAGG;AACH,wBAAgB,4CAA4C,CAC1D,KAAK,EAAE,IAAI,EAAE,EACb,OAAO,GAAE,gBAAqB,GAC7B;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CA8B7C;AAED;;;GAGG;AACH,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC;AACxD,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC"}
@@ -19,7 +19,10 @@ export function buildConsumeNotesTransactionRequestFromNotes(notes, options = {}
19
19
  const authSaltForBuilder = WordType.fromHex(normalizeHexWord(authSaltHex));
20
20
  let txBuilder = new TransactionRequestBuilder();
21
21
  txBuilder = txBuilder.withInputNotes(noteAndArgsArray);
22
- txBuilder = txBuilder.withAuthArg(authSaltForBuilder);
22
+ txBuilder = txBuilder.withFeeConversionSalt(authSaltForBuilder);
23
+ // Borrows rather than consumes: the glue passes `__wbg_ptr` without taking it,
24
+ // so the handle stays ours to release once the builder has read it.
25
+ authSaltForBuilder.free?.();
23
26
  if (options.signatureAdviceMap) {
24
27
  txBuilder = txBuilder.extendAdviceMap(options.signatureAdviceMap);
25
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"consumeNotes.js","sourceRoot":"","sources":["../../src/transaction/consumeNotes.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,yBAAyB,EACzB,IAAI,IAAI,QAAQ,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kCAAkC,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD;;;GAGG;AACH,MAAM,UAAU,4CAA4C,CAC1D,KAAa,EACb,UAA4B,EAAE;IAE9B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAChD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,gBAAgB,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,U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AM,EACd,OAAO,GAAE,sBAA2B,GACnC;IAAE,OAAO,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAkC7C"}
@@ -76,7 +76,10 @@ export function buildP2idTransactionRequest(senderId, recipientId, faucetId, amo
76
76
  const authSaltForBuilder = WordType.fromHex(normalizeHexWord(authSaltHex));
77
77
  let txBuilder = new TransactionRequestBuilder();
78
78
  txBuilder = txBuilder.withOwnOutputNotes(outputNotes);
79
- txBuilder = txBuilder.withAuthArg(authSaltForBuilder);
79
+ txBuilder = txBuilder.withFeeConversionSalt(authSaltForBuilder);
80
+ // Borrows rather than consumes: the glue passes `__wbg_ptr` without taking it,
81
+ // so the handle stays ours to release once the builder has read it.
82
+ authSaltForBuilder.free?.();
80
83
  if (options.signatureAdviceMap) {
81
84
  txBuilder = txBuilder.extendAdviceMap(options.signatureAdviceMap);
82
85
  }